voila jai commencer mon jeu mais jai un peut de male avec les collision
le vaisseau ne peut plus se "decoler" apres une colision
donc voissi le code
ps : merci de ne pas copier le code
Code :
bg = Image.load("bg.png")
yes = "yes"
no = "no"
aller = yes
bg2 = Image.load("bg2.png")
directi = nil
joueur = {}
joueur.x = 60
joueur.y = 60
trans = bg2:pixel(2,2)
persou = Image.load("persoup.png")
persol = Image.load("persoleft.png")
persod = Image.load("persodown.png")
persor = Image.load("persoright.png")
joueur.img = persou
pad = Controls.read()
oldpad = Controls.read()
screen:blit(joueur.x,joueur.y,joueur.img)
screen:blit(0,0,bg2)
screen:blit(0,0,bg)
function coli(direc)
if directi == up then
up_left = bg2:pixel(joueur.x - 2 ,joueur.y - 2)
up_right = bg2:pixel(joueur.x + 50 + 2 ,joueur.y - 2)
if up_left == trans and up_right == trans then
aller = yes
else
aller = no
end
return aller
end
if directi == down then
down_left = bg2:pixel(joueur.x - 2,joueur.y + 50 + 2 )
down_right = bg2:pixel(joueur.x + 50 + 2,joueur.y + 50 + 2)
if down_left == trans and down_right == trans then
aller = yes
else
aller = no
end
return aller
end
if directi == right then
right_up = bg2:pixel(joueur.x + 50 + 2, joueur.y - 2)
right_down = bg2:pixel(joueur.x + 50 + 2, joueur.y + 50 - 2)
if right_up == trans and right_down == trans then
aller = yes
else
aller = no
end
return aller
end
if directi == left then
left_up = bg2:pixel(joueur.x - 2, joueur.y + 2)
left_down = bg2:pixel(joueur.x - 2, joueur.y + 50 - 2)
if left_up == trans and left_down == trans then
aller = yes
else
aller = no
end
return aller
end
aller = yes
end
function movePlayer()
oldpad = Controls.read()
if pad:left() then
if coli(left) == yes and aller == yes then
joueur.x = joueur.x - 2
--else if pad:left() and not oldpad:left() then
--joueur.x = joueur.x + 2
--end
end
joueur.img = persol
end
if pad:right() then
if coli(right) == yes and aller == yes then
joueur.x = joueur.x + 2
--else if pad:right() and not oldpad:right() then
--joueur.x = joueur.x - 2
--end
end
joueur.img = persor
end
if pad:up() then
if coli(dup) == yes and aller == yes then
joueur.y = joueur.y - 2
--elseif pad:up() and not oldpad:up() then
--joueur.y = joueur.y + 2
--end
end
joueur.img = persou
end
if pad:down() then
if coli(down) == yes and aller == yes and aller == yes then
joueur.y = joueur.y + 2
--elseif pad:down() and not oldpad:down() then
--vjoueur.y = joueur.y - 2
end
joueur.img = persod
end
end
while true do
pad = Controls.read()
screen:clear()
movePlayer()
screen:blit(0,0,bg)
screen:blit(0,0,bg2)
screen:blit(joueur.x,joueur.y,joueur.img)
screen.waitVblankStart()
screen:flip()
end