Skocz do zawartości

Rekomendowane odpowiedzi

Opublikowano

mam wielki priblem ze zmienianiem broni oto kod

kolision z bronią o num 1

GML
if keyboard_check(vk_enter)

kolision z bronią o num 1

{

if teraz_bron=0 and bron_mam[1]=0

{

teraz_bron=1

bron_mam[1]=1

with(other) instance_destroy()

effect_create_above(ef_ring,x,y,15,c_green)

}

else if teraz_bron=1 and bron_mam[1]=1

{

teraz_bron=1

bron_mam[1]=1

with(other) instance_destroy()

instance_create(x,y,oObrotowa)

effect_create_above(ef_ring,x,y,15,c_green)

}

else if teraz_bron=2 and bron_mam[1]=2

{

teraz_bron=1

bron_mam[1]=1

with(other) instance_destroy()

 

effect_create_above(ef_ring,x,y,15,c_green)

}

else if teraz_bron=3 and bron_mam[1]=3

{

teraz_bron=1

bron_mam[1]=1

with(other) instance_destroy()

instance_create(x,y,oSnajperka)

effect_create_above(ef_ring,x,y,15,c_green)

}

else if teraz_bron=4 and bron_mam[1]=4

{

teraz_bron=1

bron_mam[1]=1

with(other) instance_destroy()

instance_create(x,y,oBrMiotacz)

effect_create_above(ef_ring,x,y,15,c_green)

}

else if keyboard_check_pressed(vk_enter) and teraz_bron=5 and bron_mam[1]=5

{

teraz_bron=1

bron_mam[1]=1

with(other) instance_destroy()

 

effect_create_above(ef_ring,x,y,15,c_green)

}

else if teraz_bron=6 and bron_mam[1]=6

{

teraz_bron=1

bron_mam[1]=1

with(other) instance_destroy()

 

effect_create_above(ef_ring,x,y,15,c_green)

}

}

kolision z bronią o num 3

GML
if keyboard_check(vk_enter)

{

if teraz_bron=0 and bron_mam[1]=0

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

effect_create_above(ef_ring,x,y,15,c_green)

}

else if teraz_bron=1 and bron_mam[1]=1

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

instance_create(x,y,oObrotowa)

effect_create_above(ef_ring,x,y,15,c_green)

}

else if teraz_bron=2 and bron_mam[1]=2

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

 

effect_create_above(ef_ring,x,y,15,c_green)

}

else if teraz_bron=3 and bron_mam[1]=3

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

instance_create(x,y,oSnajperka)

effect_create_above(ef_ring,x,y,15,c_green)

}

else if teraz_bron=4 and bron_mam[1]=4

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

instance_create(x,y,oBrMiotacz)

effect_create_above(ef_ring,x,y,15,c_green)

}

else if keyboard_check_pressed(vk_enter) and teraz_bron=5 and bron_mam[1]=5

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

 

effect_create_above(ef_ring,x,y,15,c_green)

}

else if teraz_bron=6 and bron_mam[1]=6

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

 

effect_create_above(ef_ring,x,y,15,c_green)

}

}

glob left button

GML
if teraz_bron= 1 and ready=1

{

shAdd(5, 1)

instance_create(x,y,oMaszyn)

ready=0

alarm[0]=2

}

//else if teraz_bron= 2 and ready=1

// {

//instance_create(x,y,oPocisk)

//ready=0

//alarm[0]=2

// }

else if teraz_bron= 3 and ready=1

{

instance_create(x,y,oPocisk1)

ready=0

alarm[0]=15

}

else if teraz_bron= 4

{

xx = x + sin( degtorad( direction + 90 ) ) * 16;

yy = y + cos( degtorad( direction + 90 ) ) * 16;

instance_create(x,y,oMiotacz);

}

else if teraz_bron=0

{

 

}

 

 

 

a zresztą macie projekta

 

 

o to chodzi że jak niemam broni teraz_bron=0 to podchodze do broni nr3 klikam enter i mi się przełącza na teraz_bron=3

a jak chce jeszcze przełączyć na broń nr1 to już nie działa jakiś błąd z kolejnością kodu

Opublikowano

użyj "switch'a"

GML
switch(teraz_bron)

{

case 0:

//kod jak masz bron 0

break; //pamietaj o tym break bo inaczej lipa

case 1:

//kod jak masz bron 1

break; //i znowu...

case 2: // itd itd...

//kod

break;

 

default:

//tutaj kodzik na wypadek jak player wogóle nie będzie miał broni

//(czyli kiedy "teraz_bron" jest inna niż zdefiniowane w case warunki

break;

}

Opublikowano

czyli case 1 odpowiada mojemu bron=1

 

 

to napiszcie mi jak to zrobić z tym case

GML
if keyboard_check_pressed(vk_enter) and teraz_bron=0 and bron_mam[1]=0

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

effect_create_above(ef_ring,x,y,15,c_green)

}

else if keyboard_check_pressed(vk_enter) and teraz_bron=1 and bron_mam[1]=1

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

instance_create(x,y,oObrotowa)

effect_create_above(ef_ring,x,y,15,c_green)

}

else if keyboard_check_pressed(vk_enter) and teraz_bron=2 and bron_mam[1]=2

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

 

effect_create_above(ef_ring,x,y,15,c_green)

}

else if keyboard_check_pressed(vk_enter) and teraz_bron=3 and bron_mam[1]=3

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

instance_create(x,y,oSnajperka)

effect_create_above(ef_ring,x,y,15,c_green)

}

else if keyboard_check_pressed(vk_enter) and teraz_bron=4 and bron_mam[1]=4

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

instance_create(x,y,oBrMiotacz)

effect_create_above(ef_ring,x,y,15,c_green)

}

else if keyboard_check_pressed(vk_enter) and teraz_bron=5 and bron_mam[1]=5

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

 

effect_create_above(ef_ring,x,y,15,c_green)

}

else if keyboard_check_pressed(vk_enter) and teraz_bron=6 and bron_mam[1]=6

{

teraz_bron=3

bron_mam[1]=3

with(other) instance_destroy()

 

effect_create_above(ef_ring,x,y,15,c_green)

}

bo niewiem jak to w praktyce jest

Opublikowano

GML
if keyboard_check_pressed(vk_enter) and teraz_bron = bron_mam[1]

{

switch (teraz_bron)

{

case 0: teraz_bron=3;

bron_mam[1]=3;

with(other) instance_destroy();

effect_create_above(ef_ring,x,y,15,c_green); break;

 

case 1: teraz_bron=3;

bron_mam[1]=3;

with(other) instance_destroy();

instance_create(x,y,oObrotowa)

effect_create_above(ef_ring,x,y,15,c_green); break;

 

 

case 2: teraz_bron=3;

bron_mam[1]=3;

with(other) instance_destroy();

effect_create_above(ef_ring,x,y,15,c_green); break;

 

 

case 3: teraz_bron=3;

bron_mam[1]=3;

with(other) instance_destroy();

instance_create(x,y,oSnajperka)

effect_create_above(ef_ring,x,y,15,c_green); break;

 

case 4: teraz_bron=3;

bron_mam[1]=3;

with(other) instance_destroy();

instance_create(x,y,oBrMiotacz)

effect_create_above(ef_ring,x,y,15,c_green); break;

 

case 5: teraz_bron=3;

bron_mam[1]=3;

with(other) instance_destroy();

effect_create_above(ef_ring,x,y,15,c_green); break;

 

case 6: teraz_bron=3;

bron_mam[1]=3;

with(other) instance_destroy();

effect_create_above(ef_ring,x,y,15,c_green); break;

 

 

}

 

}

A wogóle po co sprawdzasz i "teraz_bron" i "bron_mam[1]" skoro mają taką samą wartość?

Opublikowano

bo mam przełączenie międz bron[1] a bron[2]

na 1 zmieniam na bron[1] a na 2 zmieniam na bron[2]

 

 

EDIT: dzięki ułatwiło mi to prace, ale nie skorygowało błędu

Przypominam:

podchodze do broni nr1 klik enter przełącza mi się

podchodze do broni nr2 klik enter przełącza mi się

podchodze do broni nr3 klik enter przełącza mi się

podchodze do broni nr1 klik enter nieprzełącza mi się

inny przykład

podchodze do broni nr4 klik enter przełącza mi się

podchodze do broni nr1 klik enter nieprzełącza mi się

 

 

prosze o dalsze pomysły i pomoc

  • Administratorzy
Opublikowano

Bo to wygląda tak strasznie, że nikt nawet nie czyta. Ten kod nadaje się do refaktoringu, połowa się powtarza.

Opublikowano

ostatnio bawiłem sie w zmienianie broni i zrobiłem to w ten sposób:

 

stworzyłem 2 zmienne:

posiadam[1,2,3,4] = 300 //ilość amunicji

trzymam = 0 //aktualnie trzymana bron w łapie

 

i teraz przy nacisnieciu "1" sprawdzam czy posiadam[1]>0 jeżeli tak to zmieniam trzymam na 1 i tak analogicznie z pozostałymi broniami...

 

przy nacisnieciu LPP gdziekolwiek sprawdzam "trzymam" i odpowiednio dla danego numeru wykonuje jakąś akcje...

możesz zrobić podobnie do mnie tylko że to prawdopodobnie wystarczy 1 zmienna: trzymam

tworzysz zmienną trzymam i ustawiasz np na 1

puźniej przy kolizji z jakąś bronią ustawiasz trzymam na jakiś tam numerek... i przy strzelaniu sprawdzasz jaki to numer i wykonujesz akcje...

Opublikowano

przedewszystkim dziękuje wszystkim za tak liczne posty :jezor:

dzięki kordoba tylko jest jeden problem miało być tak: bieżesz bron1 wyżucasz broń poprzednią czyli create tamta broń

dzięki kataner żeczywiście niema wszystkiego w tym przykładzie, ale dzięki przyda mi się

Opublikowano
stworzyłem 2 zmienne:

posiadam[1,2,3,4] = 300 //ilość amunicji

 

To jakiś skrót myślowy? Nawias kwadratowy jest zarezerwowany dla tablic z tym, że GML potrafi obsłużyć tylko tablice dwu wymiarowe a nie czterowymiarowe jak wynika z deklaracji "posiadam".

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Posiadasz już konto? Zaloguj się poniżej.

Zaloguj się
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...