CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

lua la derniere touche appuyé

right_snake
right_snake
Niveau 6
14 août 2009 à 03:14:53

code:
if pad:up() == false then
joueur.marchehaut=0
joueur.img = snakestandhaut
end

j'aimerais dire apres false "et si la derniere touche enfoncée est haut alors"qqn a t'il une idée svp?

punky_dookie
punky_dookie
Niveau 10
14 août 2009 à 09:16:48

Je connais pas du tout LUA, mais peut être un algo différent pourrait répondre à ta question
pourquoi ne pas gérer ça un peu autrement ?

en algo :

si haut ou bas ou gauche ou droite appuyé :
si haut :
direction = haut

si bas :
direction = bas

si gauche :
direction = gauche

si droite :
direction = droite

avancer()
sinon
stand()
fin si

Sachant que avancer() et stand() produiront un résultat différent selon la dernière direction enregistrée

zebdal69
zebdal69
Niveau 8
14 août 2009 à 11:19:16

en gros si la dernière touche enfoncée est haut, ca veut dire que direction = haut, donc suffit juste tester la variable direction.

right_snake
right_snake
Niveau 6
14 août 2009 à 15:24:23

sa marche pas mais merci a vous deux!
code:
snakestanddroite = Image.load("snake stand.png")
courirdroite = Image.load("courir droite.png")
courirdroite2= Image.load("courir droite 2.png")
courirdroite3= Image.load("courir droite 3.png")
courirdroite4= Image.load("courir droite 4.png")
courirdroite5= Image.load("courir droite 5.png")
courirdroite6= Image.load("courir droite 6.png")
courirdroite7= Image.load("courir droite 7.png")
courirdroite8= Image.load("courir droite 8.png")

snakestandbas = Image.load("snakestandbas.png")
courirbas= Image.load("courirbas.png")
courirbas2= Image.load("courirbas2.png")
courirbas3= Image.load("courirbas3.png")
courirbas4= Image.load("courirbas4.png")
courirbas5= Image.load("courirbas5.png")
courirbas6= Image.load("courirbas6.png")
courirbas7= Image.load("courirbas7.png")
courirbas8= Image.load("courirbas8.png")

snakestandhaut = Image.load("snakestandhaut.png")
courirhaut= Image.load("courirhaut.png")
courirhaut2= Image.load("courirhaut2.png")
courirhaut3= Image.load("courirhaut3.png")
courirhaut4= Image.load("courirhaut4.png")
courirhaut5= Image.load("courirhaut5.png")
courirhaut6= Image.load("courirhaut6.png")
courirhaut7= Image.load("courirhaut7.png")
courirhaut8= Image.load("courirhaut8.png")

snakestandgauche = Image.load("snakestandgauche.png")
courirgauche= Image.load("courirgauche.png")
courirgauche2= Image.load("courirgauche2.png")
courirgauche3= Image.load("courirgauche3.png")
courirgauche4= Image.load("courirgauche4.png")
courirgauche5= Image.load("courirgauche5.png")
courirgauche6= Image.load("courirgauche6.png")
courirgauche7= Image.load("courirgauche7.png")
courirgauche8= Image.load("courirgauche8.png")

joueur = {
x = 0; -- c'est la position en X de départ
y = 188; --c'est la position en Y de départ
marche = 0;
marchegauche=0;
marchehaut=0;
marchebas=0;
img = snakestanddroite; --c'est l'image de départ du joueur
}
System.usbDiskModeActivate()
while true do
screen:clear() -- on nettoie l'écran
pad = Controls.read() -- on déclare la pression sur les touches

if pad:right() then
joueur.x = joueur.x + 2.25
joueur.marche = joueur.marche + 1.1333
end
if pad:right() == false then
joueur.marche=0
joueur.img = snakestanddroite
end

if joueur.marche>0 and joueur.marche<=5 then joueur.img = courirdroite end
if joueur.marche>=5 and joueur.marche<=10 then joueur.img = courirdroite2 end
if joueur.marche>=10 and joueur.marche<=15 then joueur.img = courirdroite3 end
if joueur.marche>=15 and joueur.marche<=20 then joueur.img = courirdroite4 end
if joueur.marche>=20 and joueur.marche<=25 then joueur.img = courirdroite5 end
if joueur.marche>=25 and joueur.marche<=30 then joueur.img = courirdroite6 end
if joueur.marche>=30 and joueur.marche<=35 then joueur.img = courirdroite7 end
if joueur.marche>=35 and joueur.marche<=40 then joueur.img = courirdroite8 end
if joueur.marche>40 then joueur.marche= 0 end

if pad:left() then
joueur.x = joueur.x - 2.25
joueur.marchegauche = joueur.marchegauche + 1.3333
end
if pad:left() == false then
joueur.marchegauche=0
joueur.img = snakestandgauche
end

if joueur.marchegauche>0 and joueur.marchegauche<=5 then joueur.img = courirgauche end
if joueur.marchegauche>=5 and joueur.marchegauche<=10 then joueur.img = courirgauche2 end
if joueur.marchegauche>=10 and joueur.marchegauche<=15 then joueur.img = courirgauche3 end
if joueur.marchegauche>=15 and joueur.marchegauche<=20 then joueur.img = courirgauche4 end
if joueur.marchegauche>=20 and joueur.marchegauche<=25 then joueur.img = courirgauche5 end
if joueur.marchegauche>=25 and joueur.marchegauche<=30 then joueur.img = courirgauche6 end
if joueur.marchegauche>=30 and joueur.marchegauche<=35 then joueur.img = courirgauche7 end
if joueur.marchegauche>=35 and joueur.marchegauche<=40 then joueur.img = courirgauche8 end
if joueur.marchegauche>40 then joueur.marchegauche= 0 end

if pad:up() then
joueur.y = joueur.y - 2.25
joueur.marchehaut = joueur.marchehaut + 1.3333
end
if pad:up() == false then
joueur.marchehaut=0
joueur.img = snakestandhaut
end

if joueur.marchehaut>0 and joueur.marchehaut<=5 then joueur.img = courirhaut end
if joueur.marchehaut>=5 and joueur.marchehaut<=10 then joueur.img = courirhaut2 end
if joueur.marchehaut>=10 and joueur.marchehaut<=15 then joueur.img = courirhaut3 end
if joueur.marchehaut>=15 and joueur.marchehaut<=20 then joueur.img = courirhaut4 end
if joueur.marchehaut>=20 and joueur.marchehaut<=25 then joueur.img = courirhaut5 end
if joueur.marchehaut>=25 and joueur.marchehaut<=30 then joueur.img = courirhaut6 end
if joueur.marchehaut>=30 and joueur.marchehaut<=35 then joueur.img = courirhaut7 end
if joueur.marchehaut>=35 and joueur.marchehaut<=40 then joueur.img = courirhaut8 end
if joueur.marchehaut>40 then joueur.marchehaut= 0 end

if pad:down() then
joueur.y = joueur.y + 2.25
joueur.marchebas = joueur.marchebas + 1.3333
end
if pad:down() == false then
joueur.marchebas=0
joueur.img = snakestandbas
end

if joueur.marchebas>0 and joueur.marchebas<=5 then joueur.img = courirbas end
if joueur.marchebas>=5 and joueur.marchebas<=10 then joueur.img = courirbas2 end
if joueur.marchebas>=10 and joueur.marchebas<=15 then joueur.img = courirbas3 end
if joueur.marchebas>=15 and joueur.marchebas<=20 then joueur.img = courirbas4 end
if joueur.marchebas>=20 and joueur.marchebas<=25 then joueur.img = courirbas5 end
if joueur.marchebas>=25 and joueur.marchebas<=30 then joueur.img = courirbas6 end
if joueur.marchebas>=30 and joueur.marchebas<=35 then joueur.img = courirbas7 end
if joueur.marchebas>=35 and joueur.marchebas<=40 then joueur.img = courirbas8 end
if joueur.marchebas>40 then joueur.marchebas= 0 end

screen:blit(joueur.x, joueur.y,joueur.img)
screen.waitVblankStart()
screen.flip()
end

voila je vous ai donné mon code complet pour l'animation en fait je voudrais que mon perso se mette en snakestanddroite si la derniere touche pressée est droite qu'il se mette en snakestandhaut si la derniere touche pressé est haut...
le probleme c'est que quand je lance le jeu sur ma psp le personnage est tout le temps en snakestandbas ou en courirbas courirbas2...
je suis sur que c'est du au fait que quand je dis,par ex,:

if pad:right() == false then
joueur.marche=0
joueur.img = snakestanddroite
end
je dis que quand la touche droite n'est pas enfoncéé alors...
mais si la derniere touche appuyée est haut ,par ex, ma condition est quand meme vrai puisque je n'appuie pas sur droite c'est pour sa que je voudrais qqch qui vérifie la derniere touche appuyée.
voila j'espere avoir été clair

oh et dernier point je disais plus haut que quand je lancais le jeu la direction affiché était bas en fait c'est parceque c'est la derniere condition que j'ai rentrée et que le programme se dit que je n'appuie pas sur bas donc il charge la dir bas (pas clair ce dernier point mais ce n'est pas grave si vous ne comprenez pas).

right_snake
right_snake
Niveau 6
14 août 2009 à 19:39:04

si vous ne comprenez pas dite le j'essairai de mieux expliqué

zebdal69
zebdal69
Niveau 8
14 août 2009 à 19:55:16

pour dire:

"si la derniere touche enfoncée est haut alors instruction"

y a pas 36000 solutions.
soit il existe une fonction déja préexistante qui permet de connaitre la dernière touche enfoncée.
soit:
variable booléenne dans laquelle tu mets:
_true lorsque la touche en question est enfoncée
_false lorsque une touche quelconque est enfoncée, hormis la touche en question
si lorsque tu testes ta variable elle est égal à true, ca veut dire que la dernière touche appuyée est celle voulue.
sinon ca veut dire que c'est une autre touche qui a été appuyée en dernier.
il suffit de savoir gérer une évenementielle simple d'appui sur une touche du clavier.
cette méthode marche forcément (sauf ptet si genre y a 18 touches appuyées en même temps).
je ne connais pas le lua, mais c'est ce que j'aurai fait sur game maker.

Sous forums
  • Aide à l'achat Mac
  • Macintosh
  • Création de Jeux
  • Programmation
  • Création de sites web
  • Linux
  • Internet
  • Steam Deck
  • Hardware
La vidéo du moment