heres my code:
Code: Select all
System.usbDiskModeActivate()
red = Color.new(225,0,0)
player = Image.load("player.png")
background = Image.load("background.png")
pic1 = Image.load("pic1.png")
pic2 = Image.load("pic2.png")
Pic = { }
Pic[1] = { x= 80, y = 95, height = pic1:height(), width = pic1:width() }
Player = { }
Player[1] = { x = 50, y = 107 }
screenwidth = 480 - player:width()
screenheight = 272 - player:width()
playerHeight = 90
playerWidth = 90
function collisionCheck(Pic)
if (Player[1].x + playerWidth > Pic[1].x) and (Player[1].x < Pic[1].x + Pic[1].width) and (Player[1].y + playerHeight > Pic[1].y) and (Player[1].y < Pic[1].y + Pic[1].height) then
Player[1].x = oldx
Player[1].y = oldy
end
end
function movePlayer()
pad = Controls.read()
if pad:left() then
Player[1].x = Player[1].x - 1
end
if pad:right() then
Player[1].x = Player[1].x + 1
end
if pad:up() then
Player[1].y = Player[1].y - 1
end
if pad:down() then
Player[1].y = Player[1].y + 1
end
end
while true do
pad = Controls.read()
oldx = Player[1].x
oldy = Player[1].y
screen:clear()
collisionCheck(Pic[1])
screen:blit(0,0,background)
screen:blit(Pic[1].x,Pic1.y,pic1)
screen:blit(140,107,pic2)
screen:blit(Player[1].x,Player[1].y,player)
if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end
if pad:right() and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 2
end
if pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 2
end
if pad:down() and Player[1].y < screenheight then
Player[1].y = Player[1].y + 2
end
screen.waitVblankStart()
screen.flip()
end
i you want to know the actual error it says:
attempt to index global field '?' a nil value