| | Problème d'action du personnage | |
| | Auteur | Message |
---|
geo Débutant
Messages : 14
| Sujet: Problème d'action du personnage Mer 17 Oct 2012 - 13:01 | |
| Salut à tous, je suis de retour car j'ai un autre problème. Quand je presse une touche, mon personnage doit faire une action. La touche Q, il fouette bien, tout est ok. La touche S, il doit envoyer son arme secondaire et là, ça marche pas. J'ai beau appuyer sur la touche, rien ne se passe, mon perso ne change pas de sprite pour faire l'animation d'envoyer son couteau. J'ai testé dans le step avec "if keyboard_check_pressed mais ça fait buguer la touche Q ensuite, via l'event "key pressed" et l'event "key". Maintenant, le code est dans un script que j'appelle avec l'event "Key pressed". sous Game Maker 8.1, ça marchait mais pas sous GM Studio. (J'ai du passer sur cette version...) Mon gros problème est que le sprite ne change pas après qu'on ai pressé la touche S. Voici le code : - Code:
-
if global.weapons > 0{ if global.temps_weapon=0{ global.temps_weapon=1; global.weapons-=1;
if global.couteau=1{ attaque_couteau=1 } if global.hache=1{ attaque_hache=1 } if global.croix=1{ attaque_croix=1 } if global.fiole=1{ attaque_fiole=1 } }} //Arme secondaire //Couteau if attaque_couteau=1{ alarm[2]=12; if down=0 and ground=0 or ground=1{ sprite_index=Simon_Belmont_Attaque_Couteau_Droite; hpseed=0 image_index=1 image_speed=1; instance_create(self.x+5,self.y-14,Couteau_weapon); } if down=1 and ground=1{ sprite_index=Simon_Belmont_Accroupi_Couteau_Droit; hpseed=0 image_index=1 image_speed=1; instance_create(self.x+15,self.y,Couteau_weapon); }} //Hache if attaque_hache=1{ if right=1 && down=0{ //hspeed=0; sprite_index=Simon_Belmont_Attaque_Couteau_Droite instance_create(self.x+15,self.y-14,spr_Hache); sound_play(snd_Hache); }else if left=1 && down=0{ //hspeed=0; sprite_index=Simon_Belmont_Attaque_Couteau_Gauche instance_create(self.x-15,self.y-14,spr_Hache); sound_play(snd_Hache); }else if right=1 && down=1{ //hspeed=0; sprite_index=Simon_Belmont_Accroupi_Couteau_Droit instance_create(self.x+15,self.y,spr_Hache); sound_play(snd_Hache); }else if left=1 && down=1{ //hspeed=0; sprite_index=Simon_Belmont_Accroupi_Couteau_Gauche instance_create(self.x-15,self.y,spr_Hache); sound_play(snd_Hache); }} //Croix if attaque_croix=1{ if right=1 && down=0{ //hspeed=0; sprite_index=Simon_Belmont_Attaque_Couteau_Droite instance_create(self.x+5,self.y-14,Cross); alarm[4]=30; sound_play(Croix); }else if left=1 && down=0{ //hspeed=0; sprite_index=Simon_Belmont_Attaque_Couteau_Gauche instance_create(self.x-5,self.y-14,Cross); alarm[4]=30; sound_play(Croix); }else if right=1 && down=1{ //hspeed=0; sprite_index=Simon_Belmont_Accroupi_Couteau_Droit instance_create(self.x+15,self.y,Cross); alarm[4]=30; sound_play(Croix); }else if left=1 && down=1{ //hspeed=0; sprite_index=Simon_Belmont_Accroupi_Couteau_Gauche instance_create(self.x-15,self.y,Cross); alarm[4]=30; sound_play(Croix);}} //Fiole if attaque_fiole=1{ alarm[2]=38; if right=1{ if down=0{ sprite_index=Simon_Belmont_Attaque_Couteau_Droite instance_create(self.x+20,self.y-14,Fiole_weapon); }else{ sprite_index=Simon_Belmont_Accroupi_Couteau_Droit instance_create(self.x+15,self.y,Fiole_weapon); } }else if left=1{ if down=0{ sprite_index=Simon_Belmont_Attaque_Couteau_Gauche instance_create(self.x-20,self.y-14,Fiole_weapon); }else{ sprite_index=Simon_Belmont_Accroupi_Couteau_Gauche instance_create(self.x-15,self.y,Fiole_weapon); } }} J'espère que vous pourrez m'aider. [EDIT] Pour info, voici le code dans le step du couteau. (Sachant que toutes les armes secondaires foirent) - Code:
-
if Simon_Belmont.image_index=6{ vspeed=0; gravity=0; if Simon_Belmont.right=1{ sprite_index=Couteau_Droite; hspeed=20; direction=0; } if Simon_Belmont.left=1{ sprite_index=Couteau_Gauche; hspeed=20; direction=180; } }
/*if Simon_Belmont.image_index<6 && (Simon_Belmont.sprite_index=Simon_Belmont_Hurt_Droite || Simon_Belmont.sprite_index=Simon_Belmont_Hurt_Gauche){//Simon_Belmont.image_alpha!=1{ instance_destroy(); }
|
| | | 65c816 Très bonne participation
Messages : 148 Projet Actuel : Jeux retro Beathem'up all
| Sujet: Re: Problème d'action du personnage Mer 17 Oct 2012 - 22:57 | |
| bonsoir geo, je serai toi je commencerai par utiliser "image_xscale" afin de diviser par deux tes ressources sprite en ne gardant que les sprites face vers la droite même pour les enemy comme ceci - Code:
-
if keyboard_check(vk_left) { image_xscale = -1; //ton code }
if keyboard_check(vk_right) { image_xscale = 1; //ton code } ensuite pour les armes j'utiliserai un switch car je ne sais pas encore me servir de tableaux(il parait que les tableaux c'est mieux) - Code:
-
if (keyboard_check_pressed (ord("Q"))) { if global.coeur >= 1 { switch (global.weapon) { case couteau: //tes parametres obj_weapon = obj_couteau if down=0 && ground>=0 { sprite_index=Simon_Belmont_Attaque_Couteau; hpseed=0 image_index=1 image_speed=1; if image_xscale > 0 { weapon = instance_create(self.x+5,self.y-14,obj_weapon); weapon.hspeed = +4; } if image_xscale < 0 { weapon = instance_create(self.x-5,self.y-14,obj_weapon); weapon.hspeed = -4; } } if down=1 && ground=1 { sprite_index=Simon_Belmont_Accroupi_Couteau; hpseed=0 image_index=1 image_speed=1; if image_xscale > 0 { weapon = instance_create(self.x+15,self.y-14,obj_weapon); weapon.hspeed = +4; } if image_xscale < 0 { weapon = instance_create(self.x-15,self.y-14,obj_weapon); weapon.hspeed = -4 } } break; case hache: //tes parametres obj_weapon = obj_hache break; case croix: //tes parametres obj_weapon = obj_croix break; case fiole: //tes parametres obj_weapon = obj_fiole break; } } } les variables sont bien-sur a créer dans le create de simon et a nommer selon ta convenance |
| | | geo Débutant
Messages : 14
| Sujet: Re: Problème d'action du personnage Jeu 18 Oct 2012 - 15:15 | |
| Merci beaucoup pour ta réponse et le temps que tu as pris pour faire ces codes !
Je vais tester ça et je reviens sur le post !
Pour info, j'avais déjà les Xscale mais dans les event key left et right. Je déplace tout dans le step, je look le code et je teste !
Par contre, je ne connais pas la fonction "switch", je vais découvrir ça ! |
| | | geo Débutant
Messages : 14
| Sujet: Re: Problème d'action du personnage Jeu 18 Oct 2012 - 16:09 | |
| Après moults tests, j'ai une erreur de code qui me dit "unsure when this come from" à la ligne : if down=0 and ground >=0{ Je n'arrive pas à comprendre l'intérêt de "switch (global.weapon)". Si tu l'as marqué, je pense que c'est une bonne chose mais, je ne comprends pas le truc du switch sur une variable ? Voici le code : - Code:
-
//Arme secondaire if (keyboard_check_pressed (ord("S"))){ if global.weapons >= 1{ switch (global.weapon) { //Couteau if global.couteau=1{ global.weapons -= 1 Couteau_weapon = obj_Couteau if down=0 and ground >=0{ sprite_index=Simon_Belmont_Attaque_Couteau_Droite; hpseed=0 image_index=1; image_speed=1; if image_xscale > 0 { weapon = instance_create(self.x+5,self.y-14,Couteau_weapon); weapon.hspeed = +4; } if image_xscale < 0 { weapon = instance_create(self.x-5,self.y-14,Couteau_weapon); weapon.hspeed = -4; }} if down=1 and ground=1{ sprite_index=Simon_Belmont_Accroupi_Couteau_Droit; hpseed=0 image_index=1; image_speed=1; if image_xscale > 0 { weapon = instance_create(self.x+15,self.y,Couteau_weapon); weapon.hspeed = +4; } if image_xscale < 0 { weapon = instance_create(self.x-15,self.y,Couteau_weapon); weapon.hspeed = -4; } } } }}} Merci pour ton aide. Si tu as besoin du fichier GMX, je peux te le fournir mais c'est du GMStudio Pro. [EDIT] Ok, l'erreur vient de Couteau_weapon = obj_Couteau. Par contre, quand je lance le jeu et ensuite, j'appuie sur la touche du couteau (avec le couteau et des coeurs en réserve), sans cette ligne, j'ai une erreur à la ligne "switch (global.weapon)" Voici l'erreur : - Code:
-
___________________________________________ FATAL ERROR in action number 1 of Step Event0 for object Simon_Belmont:
############################################################################################ VMError!! Occurred - Push :: Execution Error - Variable Get weapon at gml_Object_Simon_Belmont_Step_0 (line 116) - switch (global.weapon) ############################################################################################ Self Variables : tir = 0 move = 0 jump = 0 lvl = 0 whip_level = 0 duck = 0 bas_down = 0 monte = 0 slope = 0 whipjump = 0 ledge = 0 temps_weapon = 0 attaque_couteau = 0 stairs_up_right = 0 attaque_hache = 0 stairs_up_left = 0 stairs_down_right = 0 attaque_croix = 0 stairs_down_left = 0 prev_sprite_index = 5 attaque_fiole = 0 hurt = 0 down = 0 ouch = 0 ground = 1 hpseed = 0 right = 1 left = 0 whip = 0 swing = 0 up = 0 Global Variables : weapons = 99 temps_weapon = 0 xs = 36 couteau = 1 ys = 360 hache = 0 croix = 0 fiole = 0 position = 0 timer = 495 timer_stop = 0 weapons_max = 99 level = 0 xp = 0 Simon_Belmont_Object = 1 sky_type = 0 tir_squelette = 0 temps_weapons = 0 plateforme = 0
|
| | | 65c816 Très bonne participation
Messages : 148 Projet Actuel : Jeux retro Beathem'up all
| Sujet: Re: Problème d'action du personnage Jeu 18 Oct 2012 - 19:27 | |
| dans tu mets - Code:
-
global.weapon = ""; il y a un soucis dans ton switch!! un switch doit toujours être comme ceci(avec ou sans break mais vu que ce n'est pas pour un choix multiple il faut un break par case) - Code:
-
switch (variable) { case choix1: //code break;
case choix2 : //code break; } quand ton perso touche obj_itemCouteau par exemple tu mets global.weapon = "couteau" ce qui excecutera la case couteau de ton switch en cas d'appuis sur " Q" - Code:
-
if (keyboard_check_pressed (ord("Q"))) { if global.coeur >= 1 { switch (global.weapon) { case "couteau": //tes paramètres if down=0 && ground>=0 { sprite_index=Simon_Belmont_Attaque_Couteau; hpseed=0 image_index=1 image_speed=1; if image_xscale > 0 { weapon = instance_create(self.x+5,self.y-14,obj_couteau); weapon.hspeed = +4; } if image_xscale < 0 { weapon = instance_create(self.x-5,self.y-14,obj_couteau); weapon.hspeed = -4; } } if down=1 && ground=1 { sprite_index=Simon_Belmont_Accroupi_Couteau; hpseed=0 image_index=1 image_speed=1; if image_xscale > 0 { weapon = instance_create(self.x+15,self.y-14,obj_couteau); weapon.hspeed = +4; } if image_xscale < 0 { weapon = instance_create(self.x-15,self.y-14,obj_weapon); weapon.hspeed = -4 } } break; case "hache": //tes parametres break; case "croix": //tes parametres break; case "fiole": //tes parametres break; } } } si tu le souhaites passe moi ton gmx pour que je regarde ta structure PS: pour mon projet j'ai recrée l’animation du logo konami si tu es intéressé fait le moi savoir |
| | | geo Débutant
Messages : 14
| Sujet: Re: Problème d'action du personnage Jeu 18 Oct 2012 - 19:46 | |
| Je suis intéressé par ton projet, tu fais quoi exactement ??? Si tu me dis Konami, ça doit toucher Castlevania non ?
Merci pour tes explications, je vais m'y pencher. Je t'envoie un MP pour le GMX. |
| | | 65c816 Très bonne participation
Messages : 148 Projet Actuel : Jeux retro Beathem'up all
| Sujet: Re: Problème d'action du personnage Jeu 18 Oct 2012 - 19:53 | |
| mon projet est sur TMNT4 || || || || || || || || \/ \/ \/ \/ \/ \/ \/ \/ |
| | | geo Débutant
Messages : 14
| Sujet: Re: Problème d'action du personnage Jeu 18 Oct 2012 - 20:44 | |
| Pour info, le lien page officielle redirige sur une erreur 404. |
| | | 65c816 Très bonne participation
Messages : 148 Projet Actuel : Jeux retro Beathem'up all
| Sujet: Re: Problème d'action du personnage Jeu 18 Oct 2012 - 21:00 | |
| corrigé merci |
| | | geo Débutant
Messages : 14
| Sujet: Re: Problème d'action du personnage Jeu 18 Oct 2012 - 21:51 | |
| Désolé, j'ai pas mal de soucis internet ce soir, ça ira mieux demain |
| | | Contenu sponsorisé
| Sujet: Re: Problème d'action du personnage | |
| |
| | | | Problème d'action du personnage | |
|
Sujets similaires | |
|
| Permission de ce forum: | Vous ne pouvez pas répondre aux sujets dans ce forum
| |
| |
| |