Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / 2D platform shooting problems

Author
Message
hot_coder
22
Years of Service
User Offline
Joined: 11th Jun 2004
Location:
Posted: 23rd Feb 2005 04:34
I have had the same two problems for months in my 2D platform shooter

1. If my character changes direction while a bullet is being fired
or in motion. The bullet will change direction and go wherever
the character faces.

2. The sound that the bullet pruduces continously loops if the
spacebar is held.
Monsieur Mort
21
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 23rd Feb 2005 06:35
1) Post your code, but I expect your bullet is being moved by adding your player's horizontal speed * some multiplier to it's x coordinate. You need to make a variable called, I don't know, bulletxspeed, let that equal the player's horizontal speed * the multiplier and from then on use bulletxspeed instead of recalculating; that way the bullet direction shouldn't change.

2) Your program is playing the sound, hitting the end of your main loop, coming back, seeing the spacebar is still pressed and playing it again. Make a variable called spacebardown and make code a little like this:



What this does is to make your program only play the sound when spacebardown = 0, and make spacebardown = 1 immediately as the sound is played so it can only play once. Then when the space bar is released (spaceky()=0) it makes spacebardown = 0 again so the sound can be played if you press the space bar later. Hope that helped.

Why do you sink I ave zees outRAGEOUS accente?!
hot_coder
22
Years of Service
User Offline
Joined: 11th Jun 2004
Location:
Posted: 23rd Feb 2005 07:15
Sorry...

forgot to mention that I have supplied the source code below
Monsieur Mort
21
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 23rd Feb 2005 07:24
Ah, crap, sorry I missed that. I'll look at it now

Why do you sink I ave zees outRAGEOUS accente?!
Monsieur Mort
21
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 23rd Feb 2005 07:31
Ok, here goes:

1) Your program changes laser to 1 when spacekey()=1, which is all well and good. But the problem is that later on, you have it saying "if dir=0 and laser=1 then right_shoot". The problem here is that laser=1 for as long as the laser is shooting, and this line is run every loop. Therefore whenever you loop, the program is making your laser move the same direction as your player like I guessed it was.

What you need to do is set the laser direct _once_ instead of every loop, which you do by making the if spaceky()=1 and laser=0 bit an endif instead of a simple end statement, and making it check the direction then only. Look at the fixed code below if you don't understand, I'm not very good at exlaining these things.

2) Like I guessed, whenever the spacekey is down and the laser is moving the program plays the sound. You only want it to play once, so you need to use a flag like I suggested. Code below should work...



Why do you sink I ave zees outRAGEOUS accente?!

Login to post a reply

Server time is: 2026-07-14 06:04:34
Your offset time is: 2026-07-14 06:04:34