Fixed the “sword” and another small bug

After spending about 3.5 hours yesterday banging my head against the wall trying to figure out how to make the sword work I fixed it completely in about 20 minutes. Not only that, but my solution involves a lot less trigonometry compared to the original. I realized that the issue was that I needed to get the center of the image in the right spot, and not worry about the corners.

New Math:               //extremely simple compared to my previous trig heavy approach

atk.x = collBox.x – 17.5;
atk.y = collBox.y – 32.5;
atk.x+=sin(angle/57.2957795)*40;
atk.y-=cos(angle/57.2957795)*40;

The first two lines are just setting the center on the player character’s center. Necessary, since the two images are different sizes. The third and fourth lines are where we “push” the image center to the right spot from the PC image. BTW, the /57.29… is to convert from degrees to radians, and the 40 is the distance that we must push the image.

There was also a small bug where pressing any of the movement keys (wasd, or updownleftright), threw the angle of my images off. It was weird, but I quickly caught it using some command line debugging.
I was previously using eventQueue.motion.x to get the x coordinate of the mouse and the equivalent for y. That doesn’t work surprisingly, but SDL_GetMouseState(&mouseX, &mouseY) works perfectly. Go figure.

I’d highly recommend making this video full screen.

This entry was posted in Monochrome, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s