• 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!

GML How could I make/program enemies?

G

GalGames

Guest
Hi. I'm making a Scrolling Shooter for practice and I wanna know how I could I make enemies.

upload_2018-9-7_21-10-8.png

I tried putting the same code of the obj_player in the enemy event and it didn't work. What code could work? I looked for tutorials on YT but there's only tutorials for a plataformer enemy and when I found the "perfect tutorial" it's drag and drop. :(

Need help.
 

Slyddar

Member
For the movement, look for tutorials on paths. Each wave of enemies will follow a path, and spawn in short succession in order to create the wave.

For shooting, you can run something like this in the enemy create and step.
Code:
//create
//how often to attack
attack_time_initial = room_speed;
attack_time = attack_time_initial;
bullet_speed = 10;

//step
if attack_time <= 0 {
  //get direction to player
  var dir_ = point_direction(x, y, o_player.x, o_player.y);

  //create bullet
  var inst = instance_create_depth(x, y, depth, o_bullet);
  inst.direction = dir_;
  inst.speed = bullet_speed;
 
  //reset attack
  attack_time = attack_time_initial;
} else attack_time--;
 
G

GalGames

Guest
For the movement, look for tutorials on paths. Each wave of enemies will follow a path, and spawn in short succession in order to create the wave.

For shooting, you can run something like this in the enemy create and step.
Code:
//create
//how often to attack
attack_time_initial = room_speed;
attack_time = attack_time_initial;
bullet_speed = 10;

//step
if attack_time <= 0 {
  //get direction to player
  var dir_ = point_direction(x, y, o_player.x, o_player.y);

  //create bullet
  var inst = instance_create_depth(x, y, depth, o_bullet);
  inst.direction = dir_;
  inst.speed = bullet_speed;
 
  //reset attack
  attack_time = attack_time_initial;
} else attack_time--;
Thanks you so much!:) I'll look for paths.
 
B

Bayesian

Guest
@GalGames
You'll also want to look into state machines if you want to cycle between different behaviors
 
Top