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

Speeding up melee attacks (help)

D

DonMaklesso

Guest
Hi guys! I've been making a rogue-like game and stopped on player's melee attacks (I use hitboxes which damages enemies on contact). Everythings fine until I speed up those attacks by percentage amount of player's missing health (the less health, the faster attacks). So I've added the amount of lost hp (multiplied by 100) divided by 200 to default image_speed=1 [image_speed=1+(lost_hp/200);], so that every single percent of missing health boosts attack speed by that 1%. Here's the code:
Code:
if mouse_check_button(mb_left) && (spin=false) && (grounded=true) && (hspd=0) { sprite_index=spr_barbarian_attack; if (attack=0) { image_index=1; attack=1; } image_speed=1+(lost_hp/200);//(1+blood_speed/);

    if (image_index=5)
{ with(instance_create_layer(x,y,"Hitbox",obj_barbarian_hitbox))
    {image_xscale=other.image_xscale; with(instance_place(x,y,parent_enemy)) {hp=hp-(600+floor(blood*2)); }}}

if  (image_index=8)
{ with(instance_create_layer(x,y,"Hitbox",obj_barbarian_hitbox))
    {image_xscale=other.image_xscale; with(instance_place(x,y,parent_enemy)) {hp=hp-(600+floor(blood*2)); }}}
} else attack=0;
The problem is that the hitboxes only show up when player's health is equal to his maximum health (lost_hp=0). So my question is why hitboxes doesn't show when attack speed (image_speed) is boosted?

Thanks in advance!
 
Because when lost_hp does not equal 200, you are adding a fraction to image_speed. image_index will therefore most of the time not equal a rounded number.

You are checking for image_speed = 5 for example.

Try changing = to >= instead.
 
T

Tom Jackson

Guest
Because if your image_speed is equal to 1.012 it will almost never be equal to a whole number.
Your code is looking for a round number so try looking for a range instead.
 
N

NeZvers

Guest
I'm using bit manual labor rout by having script that use collision rectangle and I manually entered regions dependent on sprite and sub_img. That way I have collision that feels true to what you see (collision only in places where it should be) plus it doesn't care what speed your animation is running. Haven't checked it but it might be also bit better in performance too.
 

TheouAegis

Member
if image_index < 8
{ if image_index < 5 && image_index + image_speed > = 5
{ with(instance_create_layer(x,y,"Hitbox",obj_barbarian_hitbox))
{image_xscale=other.image_xscale; with(instance_place(x,y,parent_enemy)) {hp=hp-(600+floor(blood*2)); }}}
else
if image_index + image_speed >= 8
{ with(instance_create_layer(x,y,"Hitbox",obj_barbarian_hitbox))
{image_xscale=other.image_xscale; with(instance_place(x,y,parent_enemy)) {hp=hp-(600+floor(blood*2)); }}}
}
}
 
Top