Skip to content
Browse files

added ship facing and rotation

  • Loading branch information...
1 parent 805827c commit b130bb830c6e4b5bf4a70a13ee212caad3f3d298 @Textmode Textmode committed Aug 28, 2012
Showing with 15 additions and 13 deletions.
  1. +8 −7 entity.lua
  2. +7 −6 ship.lua
View
15 entity.lua
@@ -30,11 +30,12 @@ function _M.new(t)
e.id = count
- e.pos_x = t.pos_x or 0
- e.pos_y = t.pos_y or 0
- e.dir_x = t.dir_x or 0
- e.dir_y = t.dir_y or 0
- e.speed = t.speed or 0
+ e.pos_x = t.pos_x or 0
+ e.pos_y = t.pos_y or 0
+ e.dir_x = t.dir_x or 0
+ e.dir_y = t.dir_y or 0
+ e.speed = t.speed or 0
+ e.facing = t.facing or 0
-- Handles the texture, width, and height fields
_M.set_texture(e, t.texture or generic_icon)
@@ -80,7 +81,7 @@ function _M:testcollision(e)
end
function _M:draw()
- love.graphics.draw(self.texture, self.pos_x, self.pos_y)
+ love.graphics.draw(self.texture, self.pos_x, self.pos_y, self.facing )
end
-- damages the entity according to the given number,
@@ -122,7 +123,7 @@ function _M:heal(n)
end
function _M:collidewith(e, dt)
-
+ assert(e, "Can't collide with nothing!")
end
-------------------------------------------------------------------------
View
13 ship.lua
@@ -20,10 +20,10 @@ function ship.new(t)
e.speed = t.speed or 100
- e.npc = t.npc == nil and true or t.npc
- e.dir_timer = t.dir_timer or 0
- e.entities = t.entities or {}
- e.hit = false -- was hit by player?
+ e.npc = (t.npc == nil and true) or t.npc
+ e.dir_timer = t.dir_timer or 0
+ e.entities = t.entities or {}
+ e.hit = false -- was hit by player?
e.shooting = false
e.shot_rate = t.shot_rate or 0.2 -- time between shots in seconds.
@@ -43,12 +43,13 @@ end
function ship:think(dt)
if self.npc then
+ self.facing = math.atan2(self.dir_y, self.dir_x)
self.dir_timer = self.dir_timer + dt
-- turn change directions
if self.dir_timer > 1 then
self.dir_timer = 0
- self.dir_x = math.random(-1, 1)
- self.dir_y = math.random(-1, 1)
+ self.dir_x = (math.random()*2) - 1
+ self.dir_y = (math.random()*2) - 1
end
end
end

0 comments on commit b130bb8

Please sign in to comment.
Something went wrong with that request. Please try again.