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! / Fire Problem

Author
Message
Punisher
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location:
Posted: 20th Mar 2004 16:27
I am creating a 2d side scrolling Shoot'em up and having trouble with the firing aspect of the game.

First of all when I move the ship before firing, the bullet or laser will only appear from the location of the coordinates of the initialised ship.

Seconly, when I fire the bullet and do not continue to hold down the fire button, the sprite only appear at that location of the ship and will not continue to travell across the screen, unless I continue to hold down the fire button.

What am I missing? Please help.

Frank Castle is Dead
PowerFang
21
Years of Service
User Offline
Joined: 6th Feb 2004
Location: Australia (But currently in the USA)
Posted: 20th Mar 2004 16:57
You havent shown any mevement code in this source so i cant help you their.

You have a "repeat until" loop when you fire weapon one. This means that after you fire, the computer is ONLY moving the bullet accross the screen while EVERYTHING else just waits for the loop to finish. Also, since the loop only increments "c" and doesnt redraw the sprite, you actually wont see it move across the screen. Put the sprite command in that loop and it will move across the screen BUT nothing else will move whiole this is happening.

With the other weapons, it only increments the bullet accross the screen when you press the fire button. So the bullet will only move when you hold the fire button down.

What you need is a function/gosub routine that moves the bullets and you keep track of which bullets are alive and what their move speed is, then put this function/gosub in your main loop.

As for the sprite firing from the initialised position, i need to see the movement code to tell you whats up.
Punisher
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location:
Posted: 20th Mar 2004 17:19
Bellow is more of my code. I have somewhat fixed the problem of firing, well for the missile, so it fires when you press the space bar and continues to go across the screen when you don't press the spacebar, but it still fires from the previous position of the ship when i move it.

please help

Frank Castle is Dead
Punisher
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location:
Posted: 20th Mar 2004 17:33
no more help?? pweety pwease?

Frank Castle is Dead
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 20th Mar 2004 18:10
sprite 2,c+44,d+25,2....You need to add your ship movement to c and d.

a = a + 5

So you need to add 5 to c as well.

Punisher
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location:
Posted: 20th Mar 2004 18:46
I have tried to add 5 to c as well, but the sprite of the bullet moves when i move the ship, what am i doing wrong?

Frank Castle is Dead
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 20th Mar 2004 19:21
Oh yeah, I didn't really look at your code for very long, and I'm a bit confused as to how your ship can move when you fire weapon 1? It's in a loop, so is this your latest code? Because what you are explaining, doesn't seem to match the code. Is it weapon 1 that you are trying to get working?

PowerFang
21
Years of Service
User Offline
Joined: 6th Feb 2004
Location: Australia (But currently in the USA)
Posted: 21st Mar 2004 12:11
if weapon=1

if spacekey()=1
rem for count=1 to 800
sprite 2,c+44,d+25,2
rem show sprite 2
repeat
show sprite 2
c=c+10
until c=>800
rem next count
endif

if c=>800
hide sprite 2
c=a
d=b
endif



endif



show sprite 2 - this doesnt redraw the sprite it just means its not invisible. You need to add the complete sprite code:

Sprite num,x,y,image

Add that to the loop but like i said before, when you fire weapon 1 its stuck in a loop until the bullet sprite is off the screen.....this means the whole screen will pause while the bullet fires.

Also i still cant see where you draw the sprite......but from what i see you do this:

Sprite num,Ship's start x position + a, Ship's start y position + b, Image


that will work, so when you draw your bullets you have to use:

for x : Ship's start x position + a
for y : Ship's start y position + b
Punisher
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location:
Posted: 21st Mar 2004 18:50
Could someone tell me how i go about coding the game so that the missile homes in on the nearest target?

Frank Castle is Dead
Punisher
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location:
Posted: 21st Mar 2004 19:14


Frank Castle is Dead
UnderLord
22
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 21st Mar 2004 21:08
lol punisher i have the same idea i want to get a homing missle too but i think there is one in the code base so go search...but for now im working on small things like movement and basic shooting hehe

The search continues.

Current project - A space game
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 22nd Mar 2004 12:52
Use your atan command to get the rotation , use trigonometry that updates to move the missile. very simple, very simple.

GIve me more power!
Punisher
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location:
Posted: 25th Mar 2004 12:25
Ok, but how would I make it target the nearest enemy ship?

Frank Castle is Dead
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 25th Mar 2004 13:27
I have written a very simple routine that does homing missiles, and I feed in the current position and the target position, and it updates both every cycle, so it moves towards the target point, even if the target is moving. So you need to write a routine that checks which is the nearest enemy sprite and use the position of that sprite to be the target location of the missile. You can work out the exact distance of the target using the same pice of code that handles the homing missile. You want to know the hypoteneuse(spelling?) of the triangle that is formed with the xy of the missile launcher, the target x and the target y.

So player x - target x and player y- target y, then use sin() and then ask which is the smallest number. Then target that sprite!

ps if you want my homing missile code email me and Ill send it out to you!

GIve me more power!
Punisher
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location:
Posted: 25th Mar 2004 14:52
I would appreciateit if you could e-mail me your homing missile code at [email protected]

Thanks

Frank Castle is Dead
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 25th Mar 2004 16:15
Ill try to remember when I get home. If you send me a reminder email to [email protected] it will remind me!

GIve me more power!

Login to post a reply

Server time is: 2025-08-09 02:12:19
Your offset time is: 2025-08-09 02:12:19