I need help

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Craigspaz
Posts: 33
Joined: June 9th, 2012, 12:23 am

I need help

Post by Craigspaz » June 25th, 2012, 12:46 am

In my game the missile when enter is pressed moves from where the fighter is, to the top of the screen in one frame and I can't get it to go any slower and the missile won't fire from a new position when the fighter is moved left or right . Also the red enemy moves extremely fast from the top of the screen to the bottom. :? :oops:
Attachments
MyGame.zip
(667.34 KiB) Downloaded 146 times
CraigSpaz

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: I need help

Post by LuX » June 25th, 2012, 9:22 am

Code: Select all

if( kbd.EnterIsPressed() )
	{
		for(DrawFighterMissile( FighterMissileX, FighterMissileY ); FighterMissileY > 5; FighterMissileY-- );
	}
That's not how the "for" loop works. First of all, the for loop doesn't reduce -1 each frame, but it reduces all that in one frame as long as its less than 5. So your code makes the missile move to the top in one frame no matter how small or large the step is.

What I suggest is, that you make a boolean for the missile to see if it has been launched. then, separate from "enter is pressed" you check if the missile launched is true and make the Y position move up once eg.:

Code: Select all

    if( kbd.EnterIsPressed() )
    {
        if (BoolMissile == false) {BoolMissile = true;}
    }

    if (BoolMissile == true) {if (FighterMissileY > 5) {FighterMissileY -= 5;} else {BoolMissile = false; FighterMissileY = 550;}}
With this code pressing enter will simply tell your program that you have launched a missile. Then it checks if the missile has been launched. Next it will see if the missile position is less than 5 and add +5 if it is, but if it isn't, it will place the missile back on the bottom and set its launched state to false, making it reusable again.
ʕ •ᴥ•ʔ

Craigspaz
Posts: 33
Joined: June 9th, 2012, 12:23 am

Re: I need help

Post by Craigspaz » June 26th, 2012, 12:47 am

Thanks for the help.
CraigSpaz

Post Reply