Day 63

Today I worked on the attacking more. I finally fixed the attacking because I found the problem was that I made the image_index (which tells which frame of the sprite to use) for my spr_player (which has all the frames for up, down, left, right, inside of it) also somehow apply to my attack animation which was individually up,down,left,right. So I had to rewrite both the normal movement and the attack by adding individual sprites for every direction.

And I got my attacking to work :) (the GIF doesn't show the full attack animation, trust me it looks better in real life)

Then after this I worked on making it that so when the player stops moving, the sprite will stop moving and be set to the idle sprite. It wasn't that hard i just had to make 4 different individual sprites and set them to one frame that is the idle image for that direction. Then I had to make a variable that checks if the player is currently moving by saying if the horizontal speed or vertical speed is greater than 0 then moving equals true. Then I made it so that when moving equals to false, then set the object to the idle sprite in the current direction its facing.

Here is the result of the coding

At the end of class I thought of an amazing idea. I said that the player should face in the direction of the mouse and attack in that direction. So I had to change what the variable "dir" comes up as. And using the point_direction(x1,y1,x2,y2) made it so that it finds the X and Y of the mouse. Then I made it change depending on where the mouse is on a 360 degrees scale

if(dir > 45 && dir <= 135){ // Up }else if(dir > 135 && dir <= 225){ // Left }else if(dir > 225 && dir <= 315){ // Down }else if(dir > 315 || dir <= 45){ // Right }

This is the basic format of the code and I did the same thing with the attack.

Here is the result

Whew that was a lot of writing but it pays off XD

Tomorrow I will work on actually doing damage when the sword hits the enemy/goblin.


No comments:

Post a Comment