Hey Leute,
gestern habe ich schon 2h über den Code gebrütet um den Fehler zu finden, aber irgendwie erschliesst sich mir das Problem nicht!
Ich habe eine Gun programmiert, die dem Spieler folgt und in gewissen Abständen auch auf ihn schiesst.
Ich benutze dafür einen Switch mit 9 Fällen. Der erste Fall (180) und der letzte (0) funktionieren einwandfrei, dies bedeutet die Animation (alle 8 Frames) werden korrekt abgespielt.
Um das zu erkennen lasse ich die Animation sehr langsam abspielen und zähle die Frames mit, die Gun soll sozusagen 4x schiessen und muss somit auch 4x aufleuchten.
Nun ist es so, das in Case 2(202.5°) und 3(225°) die Animation nur noch 3x abspielt, in Case 4 und 5 nur noch 2x abspielt, in Case 6 und 7 nur noch 1x abspielt, in Fall 8 garnicht mehr abspielt und wie erwähnt im letzten 9. Fall wird wieder alles korrekt abgespielt.
Und während ich das hier schreibe, was einem ja oft schon hilft einen Fehler zu entdecken, erkenne ich auch ein Muster 4,3,2,1,0,4. Aber anfangen kann ich mit dem Muster im Hinblick auf die Fehlersuche nicht wirklich was.
Die Sprites die ich dafür nutze habe ich schon ein paar mal kontrolliert, sind soweit identisch und ich habe unten mal 3 Beispiele angehängt.
Jemand eine Idee wo da der Denkfehler ist?
Hier der Code dazu:
Quellcode
- ///allin
- //Activity
- if (obj_player.y > y-20 && obj_player.y < y+250)
- {
- if (obj_player.x > x-400 && obj_player.x < x +400)
- {
- gun_active = true;
- }
- }
- else
- {
- gun_active = false;
- sprite_index = spr_gun180_top;
- }
- //Targeting
- if gun_active = true
- {
- var target_angle = point_direction(x,y,obj_player.x,obj_player.y)
- target_angle = round(target_angle/22.5)*22.5;
- //image_index = round((target_angle-180)/22.5)
- switch(target_angle)
- {
- case 180:
- if gun_shooting = true
- {
- sprite_index = spr_gun180_top_shooting_0;
- image_speed = 0.05;
- if image_index >= 7
- {
- gun_shooting = false;
- }
- }
- else
- {
- sprite_index = spr_gun180_top;
- image_index = 0;
- image_speed = 0;
- if gun_delay = false
- {
- gun_delay = true;
- alarm[0] = 60;
- }
- }
- break;
- case 202.5:
- if gun_shooting = true
- {
- sprite_index = spr_gun180_top_shooting_1;
- image_speed = 0.05;
- if image_index >= 7
- {
- gun_shooting = false;
- }
- }
- else
- {
- sprite_index = spr_gun180_top;
- image_index = 1;
- image_speed = 0;
- if gun_delay = false
- {
- gun_delay = true;
- alarm[0] = 60;
- }
- }
- break;
- case 225:
- if gun_shooting = true
- {
- sprite_index = spr_gun180_top_shooting_2;
- image_speed = 0.05;
- if image_index >= 7
- {
- gun_shooting = false;
- }
- }
- else
- {
- sprite_index = spr_gun180_top;
- image_index = 2;
- image_speed = 0;
- if gun_delay = false
- {
- gun_delay = true;
- alarm[0] = 60;
- }
- }
- break;
- case 247.5:
- if gun_shooting = true
- {
- sprite_index = spr_gun180_top_shooting_3;
- image_speed = 0.05;
- if image_index >= 7
- {
- gun_shooting = false;
- }
- }
- else
- {
- sprite_index = spr_gun180_top;
- image_index = 3;
- image_speed = 0;
- if gun_delay = false
- {
- gun_delay = true;
- alarm[0] = 60;
- }
- }
- break;
- case 270:
- if gun_shooting = true
- {
- sprite_index = spr_gun180_top_shooting_4;
- image_speed = 0.05;
- if image_index >= 7
- {
- gun_shooting = false;
- }
- }
- else
- {
- sprite_index = spr_gun180_top;
- image_index = 4;
- image_speed = 0;
- if gun_delay = false
- {
- gun_delay = true;
- alarm[0] = 60;
- }
- }
- break;
- case 292.5:
- if gun_shooting = true
- {
- sprite_index = spr_gun180_top_shooting_5;
- image_speed = 0.05;
- if image_index >= 7
- {
- gun_shooting = false;
- }
- }
- else
- {
- sprite_index = spr_gun180_top;
- image_index = 5;
- image_speed = 0;
- if gun_delay = false
- {
- gun_delay = true;
- alarm[0] = 60;
- }
- }
- break;
- case 315:
- if gun_shooting = true
- {
- sprite_index = spr_gun180_top_shooting_6;
- image_speed = 0.05;
- if image_index >= 7
- {
- gun_shooting = false;
- }
- }
- else
- {
- sprite_index = spr_gun180_top;
- image_index = 6;
- image_speed = 0;
- if gun_delay = false
- {
- gun_delay = true;
- alarm[0] = 60;
- }
- }
- break;
- case 337.5:
- if gun_shooting = true
- {
- sprite_index = spr_gun180_top_shooting_7;
- image_speed = 0.05;
- if image_index >= 7
- {
- gun_shooting = false;
- }
- }
- else
- {
- sprite_index = spr_gun180_top;
- image_index = 7;
- image_speed = 0;
- if gun_delay = false
- {
- gun_delay = true;
- alarm[0] = 60;
- }
- }
- break;
- case 0:
- if gun_shooting = true
- {
- sprite_index = spr_gun180_top_shooting_8;
- image_speed = 0.05;
- if image_index >= 7
- {
- gun_shooting = false;
- }
- }
- else
- {
- sprite_index = spr_gun180_top;
- image_index = 8;
- image_speed = 0;
- if gun_delay = false
- {
- gun_delay = true;
- alarm[0] = 60;
- }
- }
- break;
- }
- }
lg Zhe
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von zhe73 ()