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

[SOLVED]Melee Attacks to Charging an attack

Build Man

Member
So, next thing I want to do is melee attacks. Unfortunately, all GM Classic platformer tutorials only explained how to do shooty-bang-bangs in platformers. Even then, there's very little GMStudio platformer tutorials that actually teach you how to code melee attacks.

The melee attack works mostly the same as Castlevania one(first three iterations), except protagonist can move during it.

Also, in case you ask me how is the soundtrack comes along... No, I am not able to make music. Sorry. You may help with that one too, if you want.
The next thing I want to know is how to setup a custom caption that shows not score, not health, not lives, but, for instance, a coins that let you earn 1up if you collect 100 of them. I already settled melee issue, so this is my next stop.

HUD Sketch.png

Here, along with Health Bar, Life Counter, and Score Caption, I also want to implement Gem Counter, as well as indicators in the right, of which special weapon is currently equipped and which powerup protagonist is currently holding.
I have set up the custom caption for gems. However, if gems are any value other than 0, they are reset to 0 when changing or restarting the room. I need to know how to keep gems the same value as before.
HUD where are you going.png

I can't compute an explanation for that. What I want is the solution of this problem. I want HUD to stay on the same position on screen.
Now what I want is to code protagonist's projectiles in way they will be destroyed when they fly off the view. It should be possible to code it in GML of Classic 8.
I am now doing a shot that can be charged to increase it's power. What is the best way to implement charging?
All problems solved, this thread is now dismissed.
 
Last edited:

NightFrost

Member
A basic melee attack is about launching the player into a melee animation and spawning an invisible hitbox that covers the area where damage dealing is supposed to happen. Collision masks still work even if an object is not set visible, so they can check for overlap with enemies as usual. The interaction bewteen the hitbox and targets would largely be the same as with bullets (kill outright or decrease health, depending on the game). If attacking can be done on the move and the damaging effect is supposed to last over several animation steps (they usually do) you have the hitbox sync its position with the player in step event.
 

Build Man

Member
A basic melee attack is about launching the player into a melee animation and spawning an invisible hitbox that covers the area where damage dealing is supposed to happen. Collision masks still work even if an object is not set visible, so they can check for overlap with enemies as usual. The interaction bewteen the hitbox and targets would largely be the same as with bullets (kill outright or decrease health, depending on the game). If attacking can be done on the move and the damaging effect is supposed to last over several animation steps (they usually do) you have the hitbox sync its position with the player in step event.
Alright, so I got a 3-strip of swinging a weapon, called Proto_Attack. I want to implement it that when goes from last frame in the strip to first, it instead goes to Proto_Attack_Finish. How do I implement that?

Also, how do I make Attack sprites have a priority over every other sprites, but without that "if sprite_index != this or that" thing?
 
Last edited:

Mick

Member
Animation End Event? But it doesn't specify which animation. I don't want the protagonist to transit into Proto_Attack_Finish from things like Proto_Walk, or basically any other animation ever.
That's your task, you can do something like:
Code:
if(sprite_index == Proto_Attack)
  sprite_index = Proto_Attack_Finish;
 

Yal

🐧 *penguin noises*
GMC Elder
Indeed, check the sprite in Animation End and then select the new sprite based on that. Or you could have a state machine, have a next_sprite variable, and set that based on the state... in Animation End simply change sprite to next_sprite. Means you don't need to adjust code in two places whenever you need to change something.

As for soundtracks, I can totally recommend my products~
(and yeah, of course I'm kinda biased =P)
 

Build Man

Member
Alright, I settled melee attacks, now I go for custom caption. This time I want to implement a caption that instead of lives, health and score, shows a number of gems collected.
 

Yal

🐧 *penguin noises*
GMC Elder
Easy-peasy, and you'd found it quickly by just searching for 'caption' in the manual:
Code:
window_set_caption("Gems collected:" + string(global.collected_gems));
 

Build Man

Member
Let me re-emphasize what I want to do.

HUD Sketch.png

Here, along with Health Bar, Life Counter, and Score Caption, I also want to implement Gem Counter, as well as indicators in the right, of which special weapon is currently equipped and which powerup protagonist is currently holding.
 

Yal

🐧 *penguin noises*
GMC Elder
Ah, then you probably want something like this.

Code:
//In the Draw GUI event
draw_sprite(spr_gemicon,0,150,0)
draw_text(170,0,"x" + string(global.player_gems))
 

Build Man

Member
Ah, then you probably want something like this.

Code:
//In the Draw GUI event
draw_sprite(spr_gemicon,0,150,0)
draw_text(170,0,"x" + string(global.player_gems))
That works. Thank you. Now to do something so the protagonist carry over gems to the next rooms or keep them over if he is knocked out and room restarts.
 

Build Man

Member
Well, here is the next problem. I have set up the custom caption for gems. However, if gems are any value other than 0, they are reset to 0 when changing or restarting the room. I need to know how to keep gems the same value as before.
 
You're gonna need a persistent "controller" object that will remain around even when you switch rooms and control all the global variables such as gems, score, etc. Otherwise, if you're just storing the players gems in the character object, whenever the character object is created in a new room, it will reset to 0.
 

Build Man

Member
You're gonna need a persistent "controller" object that will remain around even when you switch rooms and control all the global variables such as gems, score, etc. Otherwise, if you're just storing the players gems in the character object, whenever the character object is created in a new room, it will reset to 0.
Wow, I must have missed the "persistent" check box. I can't compute why my optic sensors weren't detecting that. Anyways, this thread is pending for further problems as of now.
 

Build Man

Member
HUD where are you going.png

I can't compute an explanation for that. What I want is the solution of this problem. I want HUD to stay on the same position on screen.
 
Instead of the hud object following the player (which is what I assume you're doing), simply have the hud object draw the information in the Draw GUI event and it will stay persistently on the screen.
 

Build Man

Member
Instead of the hud object following the player (which is what I assume you're doing), simply have the hud object draw the information in the Draw GUI event and it will stay persistently on the screen.
I do not understand. Please, explain.
 
Last edited:

RangerX

Member
Your problem happens because you're drawing your hud a X, Y position in the room while you need to draw it relatively to the view position.
 
Put the code that you're using to draw the HUD in your controller object's draw event, and set the x and y coordinates relative to the view your using. Right now you have them relative to the room.

Edit: For example, if you wanted to draw the word "score" and have it stay on the screen, do

-------------------------------------------------------
draw_text(view_get_xport(0) + 32,view_get_yport(0) + 32, "score");

-------------------------------------------------------
 
Last edited:

Build Man

Member
Please note that I am using GameMaker Classic 8, and thus "Draw GUI" may not be present. Or I just can't find it.
 

JackTurbo

Member
If you dont have access to draw GUI functions then you need to add the view's x/y to the hud's x/y each frame
 

RangerX

Member
Then tell me how to do it.
I strongly advise you read the manual about "views". The view is the portion of your room that you should see at once, on screen.
So basically, if you want something always displayed "on screen", you therefore use the view position to determine your HUD position. Logical right?
So there are variables for the view's position like:

view_xview = X position of the view
view_yview = Y position of the view

So given that the position 0,0 is top left of the view, if you want your HUD to be drawn 10 pixel from the left border of the view, the X position of the HUD would therefore be:

(view_xview+10)

Do you understand? So when you draw your HUD elements, in the "draw_sprite" or "draw_text" of whatever functions your use to draw it, you always position your elements like that, relatively to the view's position so its always where you want it to be on the screen.
 

Build Man

Member
I strongly advise you read the manual about "views". The view is the portion of your room that you should see at once, on screen.
So basically, if you want something always displayed "on screen", you therefore use the view position to determine your HUD position. Logical right?
So there are variables for the view's position like:

view_xview = X position of the view
view_yview = Y position of the view

So given that the position 0,0 is top left of the view, if you want your HUD to be drawn 10 pixel from the left border of the view, the X position of the HUD would therefore be:

(view_xview+10)

Do you understand? So when you draw your HUD elements, in the "draw_sprite" or "draw_text" of whatever functions your use to draw it, you always position your elements like that, relatively to the view's position so its always where you want it to be on the screen.
Now, I understand. And that works. Thank you.
Now what I want is to code protagonist's projectiles in way they will be destroyed when they fly off the view. It should be possible to code it in GML of Classic 8.
 

FrostyCat

Redemption Seeker
Now what I want is to code protagonist's projectiles in way they will be destroyed when they fly off the view. It should be possible to code it in GML of Classic 8.
Step event of projectile object:
Code:
if (bbox_right < view_xview[0] || bbox_left > view_xview[0]+view_wview[0] || bbox_bottom < view_yview[0] || bbox_top > view_yview[0]+view_hview[0]) {
  instance_destroy();
}
 

RangerX

Member
Was there an "outside view" event in GM8 ?
If yes, your bullets/projectiles could have an outside view event with "instance_destroy()" inside.
 
A

anthropus

Guest
I am now doing a shot that can be charged to increase it's power. What is the best way to implement charging?
i would make a charge "state" which means youd have to make a state machine. my time is limited so ill just link a state machine tutorial video i made.


in your charge state script u should put something like this:

set sprite index to your character's charging sprite

//(assuming the player cant move when charging)
x speed = 0
y speed = 0

if 'fully charged variable' == false (and it should be)
then set alarm to length of charge like 3 seconds or whatever, (and the alarm's code will set the 'fully charged variable' to true)


if charge button is released own && 'fully charged variable' == true
then charge attack releases

*dont forget to reset the 'fully charged variable' back to false in the appropriate place
 
Last edited by a moderator:

FrostyCat

Redemption Seeker
I should have told, I am using Game Maker Classic 8.
The finite state machine pattern works for every version of GM down to the one after Animo.

Watch that video and think critically about how it fits into your project (i.e. what states you will be using, when you will be checking or setting states). Draw a diagram similar to the one shown as the video's thumbnail. Then implement it one state at a time.

PS: Please stop reusing this topic for multiple questions. If you have a new question, open a new topic.
 
Last edited:

Build Man

Member
The finite state machine pattern works for every version of GM down to the one after Animo.

Watch that video and think critically about how it fits into your project (i.e. what states you will be using, when you will be checking or setting states). Draw a diagram similar to the one shown as the video's thumbnail. Then implement it one state at a time.

PS: Please stop reusing this topic for multiple questions. If you have a new question, open a new topic.
I will acknowledge.
Besides, I still have no clue how I will implement charge shot.(a shot that can be charged to increase it's power)
 

Build Man

Member
I rewatched anthropus' State Machine tutorial a number of times, but still do not have a clue on how to implement a charged shot. I might use a direct clue.
 

FrostyCat

Redemption Seeker
I rewatched anthropus' State Machine tutorial a number of times, but still do not have a clue on how to implement a charged shot. I might use a direct clue.
Kind of ironic you'd ask for a direct clue, given how anthropus has already handed you one face-on.
in your charge state script u should put something like this:

set sprite index to your character's charging sprite

//(assuming the player cant move when charging)
x speed = 0
y speed = 0

if 'fully charged variable' == false (and it should be)
then set alarm to length of charge like 3 seconds or whatever, (and the alarm's code will set the 'fully charged variable' to true)


if charge button is released own && 'fully charged variable' == true
then charge attack releases

*dont forget to reset the 'fully charged variable' back to false in the appropriate place
Here's what anthropus asked you to set up:
  • A create event in which fully_charged in set to false
  • An alarm event (say 7) in which fully_charged is set to true
  • A step event that transitions into the charging state and sets alarm 7 to a specified amount (e.g. 3*room_speed for 3 seconds) if the charge key is just pressed (use keyboard_check_pressed())
Here's what anthropus planned for your charge state:
  • If sprite_index is not the correct charging sprite
    • Set sprite_index to that charging sprite
  • If the charge button is just released
    • If fully_charged is true
      • Release a charged attack
      • Set fully_charged to false
    • Else
      • Release an uncharged attack (?)
    • Set alarm 7 back to -1
    • Return to normal state
I'm done with your attempts to put your homework up for people on the GMC to do, scrap this one out yourself for once. You have more than enough information this time around.
 

Build Man

Member
Kind of ironic you'd ask for a direct clue, given how anthropus has already handed you one face-on.
in your charge state script u should put something like this:

set sprite index to your character's charging sprite

//(assuming the player cant move when charging)
x speed = 0
y speed = 0

if 'fully charged variable' == false (and it should be)
then set alarm to length of charge like 3 seconds or whatever, (and the alarm's code will set the 'fully charged variable' to true)


if charge button is released own && 'fully charged variable' == true
then charge attack releases

*dont forget to reset the 'fully charged variable' back to false in the appropriate place
My optic sensors missed it. Regardless, thank you both for information. I will try that some time.
 

Build Man

Member
Thank you both again for help. I did it may way though, without resorting to scripts.

I added "charge_level = 0" to Create Event. Then:

Press X to execute code
Code:
//with Magic Bolt equipped

if HUD.weapon = 3 && action = 0 && HUD.projectiles > 0
 {
 if sprite_index != Mako_Damaged
  {
  sprite_index = Mako_Weapon
  image_index = 0
  image_speed = 1
  instance_create(Protagonist.x, Protagonist.y, MagicBolt_Small)
  }
 }
if HUD.weapon = 3
alarm[1] = 18
Hold X to charge
Code:
IN ALARM[1]
charge_level = 1
alarm[2] = 30
IN ALARM[2]
charge_level = 2
In Step Event:
Code:
if charge_level = 1
 {
 if alarm[11] < 1
 alarm[11] = 3
 }
if charge_level = 2
instance_create(random_range(x-8,x+8),random_range(y-15,y+15),Magic_Charge)

if !keyboard_check(ord('X')) && charge_level > 0
event_perform(ev_keyrelease,ord('X'))
That keyboard check is necessary in case player releases X key while Protagonist still recoiling in pain.
Release X Event
Code:
if HUD.weapon = 3 && action = 0 && sprite_index != Mako_Damaged
 {
 alarm[1] = -1
 alarm[2] = -1
 if charge_level >= 1
  {
  if charge_level = 2
   {
   sprite_index = Mako_Weapon
   image_index = 0
   image_speed = 1
   instance_create(Protagonist.x, Protagonist.y, MagicBolt_Large)
   }
  else
   {
   sprite_index = Mako_Weapon
   image_index = 0
   image_speed = 1
   instance_create(Protagonist.x, Protagonist.y, MagicBolt_Medium)
   }
  }
 charge_level = 0
 }
During charge_level = 1, Alarm 11 is called instead of Magic Charge particle directly, to create said particle every 4 steps or so, to indicate lesser bolt was charged.
Code:
IN ALARM[11]
instance_create(random_range(x-8,x+8),random_range(y-15,y+15),Magic_Charge)

I am sorry. Was easier my way anyway.
 
Top