hello everyone,
today i will be showing you how to use arrays.
i will upload an example but first i must explain.
single arrays and double arrays are two different things and are kind of hard to explain.
anyway im going to show an example of a double array that im using in my games.
in my rocket create event:
can_shoot = 1
energy = 100
hp = 100
//beam 0
beam[0,0] = lazer1; //name
beam[0,1] = 1; //energy
beam[0,2] = 7; //speed
beam[0,3] = 5; //power
beam[0,4] = 25; //time
//beam 1
beam[1,0] = lazer2;
beam[1,1] = 2;
beam[1,2] = 4;
beam[1,3] = 10;
beam[1,4] = 50;
//beam 2
beam[2,0] = lazer3;
beam[2,1] = 5;
beam[2,2] = 15;
beam[2,3] = 2;
beam[2,4] = 15;
what this explains is that for all three beams i have their power, speed, energy cost, and time for another one.
in it's attack event (space) i used a switch statement to do everything.
if (energy <1)
{energy = 0}
if (energy = 0)
{exit}
switch(global.current_beam)
{
case 0:
if (energy > 0)
{
instance_create(x,y,beam[global.current_beam,0])
alarm[0]=beam[global.current_beam,4]
can_shoot = 0
}
else
{exit}
break;
case 1:
if (energy > 1)
{
instance_create(x,y,beam[global.current_beam,0])
alarm[0]=beam[global.current_beam,4]
can_shoot = 0
}
else
{exit}
break;
case 2:
if (energy > 2)
{
instance_create(x,y,beam[global.current_beam,0])
alarm[0]=beam[global.current_beam,4]
can_shoot = 0
}
else
{exit}
break;
}
to test it i made the three lazers made in the array into objects.
color them differently and play the game.
oh almost forgot to test all three beams i put a mouse left pressed
and mouse right pressed to deduct the global.current_beam values enjoy
.
Users logged in:
Comments
Loading comments...