• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How to make a powerup that shoots two bullets at split directions?

A

Artwark

Guest
When I get a powerup, I want it so that instead of shooting one bullet, it shoots two bullets in split directions.

Here's what I did for the obj_player

bullet = instance_create(x,y, obj_bullet);
bullet.direction = image_angle;
bullet.image_angle = image_angle-2;
bullet.speed = 15;
audio_play_sound(snd_bullet,0,0);

if place_meeting(obj_player.x,obj_player.y,obj_lazerpowerup)
{
bullet1 = instance_create(x,y-16, obj_bullet);
bullet2 = instance_create(x,y, obj_bullet);
bullet1.direction = image_angle;
bullet2.image_angle = image_angle-2;
bullet1.speed = 15;
bullet2.speed = 15;
audio_play_sound(snd_bullet,0,0);
}

I did the place meeting so that when it touches the lazerpowerup, I thought that it would apply for the obj_player but the powerup instead shoots and not the player.

How to fix this?
 
T

TDSrock

Guest
Seems correct mate.

It's just only doing it while your touching the powerup.

You'll want to probably track some some stuff though.

First of I'd say make a object called obj_powerup. This will serve as a parent object for all other powerups. This will make your code simpler when adding more powerups besides the one.

Then:
Code:
//player create event:
powerUpState = 0;

//player step event:

if(place_meeting(x,y,obj_powerup)){
//if thouching a powerup
//storeing the nearest by powerup in the value inst
inst = instance_nearest(x,y,obj_powerup);
 powerUpState += inst.powerUpStrength; //apply the powerup to the character
with(inst){
//destroy the powerup
instance_destroy():
}
}
Now all thats left is to change how we shoot based on the value of powerUpState.

If you want to implement several powerups that have different effects you'll have to have a better system(using arrays). But for now this should serve you well.
 
A

Artwark

Guest
Seems correct mate.

It's just only doing it while your touching the powerup.

You'll want to probably track some some stuff though.

First of I'd say make a object called obj_powerup. This will serve as a parent object for all other powerups. This will make your code simpler when adding more powerups besides the one.

Then:
Code:
//player create event:
powerUpState = 0;

//player step event:

if(place_meeting(x,y,obj_powerup)){
//if thouching a powerup
//storeing the nearest by powerup in the value inst
inst = instance_nearest(x,y,obj_powerup);
powerUpState += inst.powerUpStrength; //apply the powerup to the character
with(inst){
//destroy the powerup
instance_destroy():
}
}
Now all thats left is to change how we shoot based on the value of powerUpState.

If you want to implement several powerups that have different effects you'll have to have a better system(using arrays). But for now this should serve you well.
Its showing an error at this point....at line 4
 
A

Artwark

Guest
I kinda fixed it...though instead of finding the issue, I used instance_change code and just duplicated the obj_player and made some small changes.
 
T

TDSrock

Guest
Why would you use instance change? Unless you are in fact replacing something with a new different object...

Show me what you are doing.

(also for readabilitys sake please use code blocks)
 
Top