Commits

mcc committed 3e32d86

Refactored/renamed things a little

Comments (0)

Files changed (1)

 end
 
 function BrokenAsteroids:makeBullet()
-		shape = ScreenShape(SHAPE_RECT, 5,5)
+		local shape = ScreenShape(SHAPE_RECT, 5,5)
 		shape.type = 3
 		local cpos = self.player:getPosition()
 		local crot = math.rad(self.player:getRotation()) - math.pi/2
 		table.insert(wrappers, shape)
 end
 
+function BrokenAsteroids:makePlayer()
+	local shape = ScreenImage("ship.png")
+	shape:setPositionMode(POSITION_CENTER)
+	shape:setPosition(640/2, 400)
+	shape.type = 1
+	screen:addPhysicsChild(shape, ENTITY_RECT, false)
+	self.player = shape
+end
 screen = PhysicsScreen(10, 60)
 screen:setGravity( Vector2( 0,0 ) )
-shape = ScreenImage("ship.png")
-shape:setPositionMode(POSITION_CENTER)
-shape:setPosition(640/2, 400)
-shape.type = 1
-screen:addPhysicsChild(shape, ENTITY_RECT, false)
 
 wrappers = {}
 dyingbullet = {}
 deadbullet = {}
 table.insert(wrappers, shape)
 
-brokenAsteroids = BrokenAsteroids(shape)
+brokenAsteroids = BrokenAsteroids()
 
+brokenAsteroids:makePlayer()
 for i=0,4 do
         brokenAsteroids:makeAsteroid()
 end
 function Update(elapsed)
         brokenAsteroids:movePlayer(elapsed)
 		for i,wrapper in ipairs(wrappers) do
-			local v = wrapper:getPosition()
+			local p = wrapper:getPosition()
 			local changed = false;
-			if v.x < 0 then v.x = v.x + 640; changed=true end
-			if v.x > 640 then v.x = v.x - 640; changed=true end
-			if v.y < 0 then v.y = v.y + 480; changed=true end
-			if v.y > 480 then v.y = v.y - 480; changed=true end
-			if changed then screen:setTransform(wrapper,v,wrapper:getRotation()) end
+			if p.x < 0 then p.x = p.x + 640; changed=true end
+			if p.x > 640 then p.x = p.x - 640; changed=true end
+			if p.y < 0 then p.y = p.y + 480; changed=true end
+			if p.y > 480 then p.y = p.y - 480; changed=true end
+			if changed then screen:setTransform(wrapper,p,wrapper:getRotation()) end
 		end
 		for i,bullet in ipairs(dyingbullet) do
-			local v = bullet:getPosition()
-			v.x = 1000
-			v.y = 1000
-			screen:setTransform(bullet, v, 0)
+			local p = bullet:getPosition()
+			p.x = 1000
+			p.y = 1000
+			screen:setTransform(bullet, p, 0)
 			screen:setVelocity(bullet, 0, 0)
 			table.insert(deadbullet,bullet)
 		end