Sunday, October 30, 2011

Back in Action 4

Hey, after a long hiatus, I'm back!

Last time I was working on adding the boss in, specifically I had the animation in, could make him show up, and make the other enemies stop spawning then. The problem was making him move up and down once he showed up, specifically the movements I had for the boss had him moving off screen immediately . I also still need to add collision detection in for him so he can actually be hit by the player.

Now, originally my code to make the boss move up and down was as follows:

if (Position.Y <= 800 && Position.Y > 10)
{
for (; Position.Y <= 800 && Position.Y > 10; Position.Y -= enemyMoveSpeed2)
{
}
}

if (Position.Y <= 10)
{
for (; Position.Y <= 700; Position.Y += enemyMoveSpeed2)
{
}
}

I know my for loops are done oddly, using pre-existing variables instead of i or whatever and incrementing them in the condition part of the loop instead of in the loop. I assume there is some reason one shouldn't do that? Probably with a name attached to it and doing it causes teachers to frown and very strictly tell you why you are wrong and dumb for doing it? I do have the X positioning ok, it comes in and then stops when I tell it and doesn't move on the X axis.

I did it with a new variable i and j (and setting them equal to Position.Y but that didn't do it. I feel like I am missing something very basic here.

Wow. I WAS missing something basic. I didn't even need a for loop, but what was REALLY throwing me off was I didn't need to specify in the if statements the positions. I ended up making a bool called Check that was set to true (I had experimented with using a bool before but was using it in combination with the Y position in the if statement). If Check is true it would go down until it got to a certain Position.Y point and then it would change Check to false and the other if statement would look for that and make it go up until it hit a certain Position.Y value and it would change Check to true again. Such a simple solution and it took so long to figure out. I feel like anytime I get stuck programming it is becase I am overthinking something and making it too complicated.

That is gonna be all for today cause that took a long time, tomorrow I add in collision!

No comments:

Post a Comment