I started off the class thinking of how I can make the attack work, and I came up with the idea to make a separate object that gets created when you attack and does the damage (a hitbox). I made the object and called it obj_hitbox and I made the sprite a red box. Inside I made Step event and said
if place_meeting(x, y, obj_goblin)
{
goblin.hp -= global.weapondamage;
alarm[0] = 1;
}
Pretty much what this code does is that checks if the object (obj_hitbox) is colliding with the goblin (obj_goblin) and if so, then remove the weapondamage's amount from goblin's hp, then in 1 frame run the code that is inside alarm 0 which is instance_destory(), this code destroys the object (obj_hitbox).
I tested it and it worked but there was one problem, the hitbox kept getting created inside the same place no matter in which direction you were attacking. So I came up with the idea that I would make multiple hitboxes for every direction that I'm attacking.
So i started by duplicating the current attack sprites (up, down, left, right)
and then deleting all the frames only the one that actually attacks. Then I would make a red square over the hitbox then delete the rest of the player.
Like This
I did this to all the directions of attacking and then I made different hitbox objects for all the directions with the same code. Then in my attacking code I added instance_create(x,y,obj_hitbox_<direction>).
This is the result
The red hitbox just shows the hitbox of my attack but I can make it non visible whenever I want to
Tomorrow I will work on some bug fixes on the goblin and maybe my player.
No comments:
Post a Comment