Help me?
I'm making a port of asteroids, and the code I'm using for collision won't define the ship and the Ammo at the same time
![Sad :(](./images/smilies/icon_sad.gif)
- Code:
green=Color.new(0,255,0)
white = Color.new(255,255,255)
pd = Image.load("ShipD.png")
pr = Image.load("ShipR.png")
pl = Image.load("ShipL.png")
player = Image.load("Ship.png")
pu = Image.load("Ship.png")
block = Image.createEmpty(32,32)
block:clear(green)
shot = Image.load("sht.png")
Player = { x = 30, y = 100 }
Sht = { x = 55, y = 115}
shotHeight = 5
shotWidth = 5
playerHeight = 32
playerWidth = 32
Block = {}
Block[1] = { x = 100, y = 80, height = block:height(), width = block:width() }
Block[2] = { x = 300, y = 30, height = block:height(), width = block:width() }
Block[3] = { x = 200, y = 58, height = block:height(), width = block:width() }
function movePlayer()
pad = Controls.read()
if pad:left() then
player = pl
Player.x = Player.x - 3
Sht.x = Sht.x - 3
end
if pad:right() then
player = pr
Player.x = Player.x + 3
Sht.x = Sht.x + 3
end
if pad:up() then
player = pu
Player.y = Player.y - 3
Sht.y = Sht.y - 3
end
if pad:down() then
player = pd
Player.y = Player.y + 3
Sht.y = Sht.y + 3
end
end
pad = Controls.read()
if pad:cross() then
Sht.x = oldx
Sht.y = oldy
end
if pad:cross() and player == pu then
while oldy > 0 do
shtoldy = shtoldy + 3
end
end
function collisionCheck(object)
if (Player.x + playerWidth > object.x) and (Player.x < object.x + object.width) and (Player.y + playerHeight > object.y) and (Player.y < object.y + object.height) then
Player.x = oldx
Player.y = oldy
end
end
function collisionCheck(object)
if (Sht.x + shotWidth > object.x) and (Sht.x < object.x + object.width) and (Sht.y + shotHeight > object.y) and (Sht.y < object.y + object.height) then
Sht.x = shtoldx
Sht.y = shtoldy
end
end
while true do
oldx = Player.x
oldy = Player.y
screen:clear()
shtoldx = Sht.x
shtoldy = Sht.y
screen:clear()
movePlayer()
collisionCheck(Block[1])
collisionCheck(Block[2])
collisionCheck(Block[3])
screen:blit(Sht.x,Sht.y,shot)
screen:blit(Player.x,Player.y,player)
for a = 1,3 do
screen:blit(Block[a].x,Block[a].y,block)
end
screen.waitVblankStart()
screen.flip()
end
Whats wrong with my code?
EDIT: DL the full pack here.