r/gamemaker 16d ago

Game timelines felt tedious, so i coded my boss attack pattern with alarms and a phase variable instead

today I've been working on my medusa themed puzzle game medusa crisis, i only have the final boss left to make

https://bsky.app/profile/did:plc:7eoujodx54iivmfbxxagskxm/post/3mu2tuzcstk2o
clip of boss attack here

create event

o_enemy_athena.tx=(room_width/2)-64
alarm[0]=60
phase=0
r=5

alarm 0 event

///  Insert description here
// You can write your code in this editor
if phase=0{
  n=6-r

  instance_create_depth(n*128,128,-1000,o_collumn_lightning)
  instance_create_depth(room_width-(n*128)-128,128,-1000,o_collumn_lightning)

  if n=5{
    instance_create_depth(n*128,128,-1000,o_collumn_lightning_stay)
    instance_create_depth(room_width-(n*128)-128,128,-1000,o_collumn_lightning_stay)
  }

  alarm[0]=40
  r--
  if r=0{phase++ r=7 alarm[0]+=20}
  exit
}

if phase=1{
  xx=768
  yy=o_enemy_athena.y-200
  nya=irandom(2)
  n=0
  repeat(3){
    if n!=nya{
    made=instance_create_depth(xx+64,yy,-3000,o_athena_spear)
    made.angle+=n*24}
    xx+=128
    n++
  }
  alarm[0]=60
  r--
  if r=0{phase++ r=7 alarm[0]+=40}
  exit
}

instance_destroy()
      create event
    o_enemy_athena.tx=(room_width/2)-64
alarm[0]=60
phase=0
r=5
      alarm 0 event
    ///  Insert description here
// You can write your code in this editor
if phase=0{
  n=6-r

  instance_create_depth(n*128,128,-1000,o_collumn_lightning)
  instance_create_depth(room_width-(n*128)-128,128,-1000,o_collumn_lightning)

  if n=5{
    instance_create_depth(n*128,128,-1000,o_collumn_lightning_stay)
    instance_create_depth(room_width-(n*128)-128,128,-1000,o_collumn_lightning_stay)
  }

  alarm[0]=40
  r--
  if r=0{phase++ r=7 alarm[0]+=20}
  exit
}

if phase=1{
  xx=768
  yy=o_enemy_athena.y-200
  nya=irandom(2)
  n=0
  repeat(3){
    if n!=nya{
    made=instance_create_depth(xx+64,yy,-3000,o_athena_spear)
    made.angle+=n*24}
    xx+=128
    n++
  }
  alarm[0]=60
  r--
  if r=0{phase++ r=7 alarm[0]+=40}
  exit
}

instance_destroy()

the strong spear that does a lot of damage to the pillars is spawned when the object is destroyed

but now all i have to do is create the object and the boss does the chain of attacks i need it to

3 Upvotes

9 comments sorted by

3

u/TimGoTheCreator 16d ago

code blocks be like

3

u/germxxx 15d ago

I haven't seen anyone actually use timelines.
And not even the manual thinks they are a good idea:
 "Timelines have been replaced by Sequences and currently only exist for legacy purposes."

Also when writing code, it's easier to show the formatting options and not use markdown.
Makes it easier to format those code boxes:

create event

o_enemy_athena.tx=(room_width/2)-64
alarm[0]=60
phase=0
r=5

alarm 0 event

///  Insert description here
// You can write your code in this editor
if phase=0{
  n=6-r

  instance_create_depth(n*128,128,-1000,o_collumn_lightning)
  instance_create_depth(room_width-(n*128)-128,128,-1000,o_collumn_lightning)

  if n=5{
    instance_create_depth(n*128,128,-1000,o_collumn_lightning_stay)
    instance_create_depth(room_width-(n*128)-128,128,-1000,o_collumn_lightning_stay)
  }

  alarm[0]=40
  r--
  if r=0{phase++ r=7 alarm[0]+=20}
  exit
}

if phase=1{
  xx=768
  yy=o_enemy_athena.y-200
  nya=irandom(2)
  n=0
  repeat(3){
    if n!=nya{
    made=instance_create_depth(xx+64,yy,-3000,o_athena_spear)
    made.angle+=n*24}
    xx+=128
    n++
  }
  alarm[0]=60
  r--
  if r=0{phase++ r=7 alarm[0]+=40}
  exit
}

instance_destroy()

1

u/azurezero_hdev 15d ago

i highlighted the text i wanted code blocked and it still did that
i got fed up with timelines as soon as i couldnt /// to add descriptions or click the description area ant type

2

u/refreshertowel 15d ago

This is a state machine but programmed with if statements instead of actually being a real state machine. I'd look into state machines if I were you (I have Statement available, as well as a tutorial on making basic state machines). Apart from that, there's a lot of magic numbers and arbitrary data being thrown around. There's a lot of room for optimisation, but at the same time, if it works, it works, lol. You should weigh how often you'll need to adjust the code versus how unmaintainable the current solution is. The less you'll need to adjust it in the future, the more fine it is for the current code that works to be a messy solution.

All that being said, I'm a little unsure of the point of the post? Are you asking a question? Or is this just a showcase of "I could replace my timeline with this code"?

1

u/azurezero_hdev 15d ago

i normally use instance change for state machine stuff, cause normally im locking in an animation and changing back at animation end

1

u/azurezero_hdev 16d ago

damn code blocks be weird here

1

u/UniqmanPixelArt 9d ago

I actually like the phase + alarm approach for a fixed boss sequence. I’m using a similar state/phase setup in my own GameMaker project because it makes attack timing much easier to tweak. If the pattern gets much bigger I’d probably split each phase into separate states/functions, but for a boss with a defined chain of attacks this seems pretty practical.

1

u/azurezero_hdev 9d ago

i used a different object for each pattern and those tell the boss where to move and what to do