Created
June 19, 2012 04:45
-
-
Save dimmduh/2952322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function bullet:enterFrame(e) | |
| if (self.destroied ) then | |
| self:destroy() | |
| return true; | |
| end | |
| --check self is out of screen | |
| if ( self:isOut() ) then | |
| self.destroied = true; | |
| return true; | |
| end | |
| --check existence of target | |
| if ( not utils.existsObject( self.target ) ) then | |
| self.destroied = true; | |
| return true; | |
| end | |
| --rotate at target | |
| self.rotation = utils.getAngle( self.x, self.y, self.target.x, self.target.y ) | |
| --calculate distance between self (bullet) and target | |
| local distance = utils.getDistance( self.x, self.y, self.target.x, self.target.y ); | |
| --if it's less than bullet speed then move to point sharp | |
| if (distance <= self.speed) then | |
| self.x = self.target.x | |
| self.y = self.target.y | |
| else | |
| --calculate offset | |
| self.dx = math.cos( math.rad( self.rotation) ) * self.speed; | |
| self.dy = math.sin( math.rad( self.rotation) ) * self.speed; | |
| --move | |
| self.x = self.x + self.dx | |
| self.y = self.y + self.dy | |
| end | |
| --check collisions between self and enemies | |
| self:checkCollision() | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment