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! / Help needed with a 2D Shooter

Author
Message
Jonty
20
Years of Service
User Offline
Joined: 26th Jul 2004
Location:
Posted: 14th Aug 2004 08:48 Edited at: 14th Aug 2004 08:49
This is my first attempt at a game using Dark Basic so I used the 2D tutorial on this forum and added a few things but now i am stuck. How do I make the enemy ships move to the other end of the screen? At the moment, the player is just shooting at stationary ships and it isn't a challenge at all.

Also, why doesn't my laser sprite delete after hitting the enemy. I have the delete command but it isn't working.

Any help would be appreciated and go easy cos I am new to all of this.
Reaperman
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 14th Aug 2004 12:56 Edited at: 14th Aug 2004 13:03
Hello Jonty.

You seem to be putting the enemy sprites on screen in formation, but you are then not moving their X/Y Co-ords.

I used "sprite 1,psx,psy,1" in the tutorial. You need something like that for each sprite.

So if you have 10 sprites on screen and you want them to move from right to left you "dec" the X co-ord of each one in turn.

If you are storing each sprites Co-ords in arrays (or in a read/write file) then you can just access each in turn. But if you know you will have no more than, say, 10 enemy on screen at the same time, you can write a routine to move a block of 10 sprites. Just put it in the main Do/Loop of the program.

EG:
sprite 1,e1x,e1y,99
sprite 1,e2x,e2y,99
sprite 1,e3x,e3y,99
etc etc etc
dex e1x
dex e2x
dex e3x
etc etc etc

You can use loops to do the above with, but if you do it one sprite at a time, while it makes your program longer, it makes it easy to see what (if anything) goes wrong and you can edit each sprite separately.

It is NOT the most elegant way of doing it, but as you said your new to it all, so it would be better for you to do it the long way and to see what each thing does.

As for why its not deleting the sprite, I think it is because you have the delete in the loop. "delete sprite spriteno" should be outside the loop. All you are doing (or should be doing) is you change the graphic of the hit enemy to the first frame of the explosion. You then run through all the explosion frames and after that you delete the sprite.

So put the "delete sprite spriteno" before the return and it should work.
Jonty
20
Years of Service
User Offline
Joined: 26th Jul 2004
Location:
Posted: 14th Aug 2004 19:48
Cheers for that. I will give it a try now.
Jonty
20
Years of Service
User Offline
Joined: 26th Jul 2004
Location:
Posted: 14th Aug 2004 21:33
Right, I had the sprites moving to the end of the screen but they sometimes wouldn't be hit by the lasers. Why is this? It realy is doing my nut in!
Reaperman
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 14th Aug 2004 23:39
Well Jonty, provided you are checking all the enemy sprites for a hit then it should work.

You could always add a little routine to your main do/loop to tell you if the program is picking up the 'Hit'.

You would need something like this:

For t=(Number of first enemy sprite) to (Number of last enemy sprite)
if SPRITE HIT(2,t)=1
Print t,“HIT”
End if
sync
Next t

What your doing is telling the program that IF the sprite is being 'HIT' by your lazer, then print out the sprite number and a "HIT" text on the screen.

Do something like that and see what it tells you. Then get back to me.
Jonty
20
Years of Service
User Offline
Joined: 26th Jul 2004
Location:
Posted: 15th Aug 2004 00:22
I added that piece of code and all of the ships get hit when they are stationary. If i start them moving, the collision doesn't work. Would it help if i posted my code?
Reaperman
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 15th Aug 2004 02:52
You could do, but I have an idea.

It may be because your moving the enemy 1 pixel but the lazer is being moved 10... Even though the human eye may see it as hitting the sprite, it could be simply that when moving, the lazer "jumps" the sprite. To rule that out make the lazer move 1 pixel at a time and then see if you can hit them all.

If you can, then you know what the problem is...if not, post your code (and an exe download would be good too) and get back to me.
Jonty
20
Years of Service
User Offline
Joined: 26th Jul 2004
Location:
Posted: 15th Aug 2004 04:03 Edited at: 15th Aug 2004 04:04
Right, here is the code. The laser would hit the ships but they wouldn't be deleted.

I apologise for the messy code.



http://www.btinternet.com/~jonty85/game.EXE
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 15th Aug 2004 07:08
Just out of curiosity, instead of using if sprite hit.. try using, if sprite collision().. see if that helps.

By the way, most commands use boolean operations, ending in either a 1 for yes, or 0 for no..

IF you just write


I dont know if this will help, but i'm using the same code making a 2d jet fighter type game.

Good luck!

Hope that helps.

- Merix

Athlon xp 2400+, 512MB Ram, Radeon 9800PRO 128mb
Reaperman
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 16th Aug 2004 05:24
Jonty....Did Merix help you or do you still need help. If so, please post the files in a zip (code and gfx) and I will dl it and see what I can do.
Jonty
20
Years of Service
User Offline
Joined: 26th Jul 2004
Location:
Posted: 18th Aug 2004 22:26 Edited at: 18th Aug 2004 22:27
Sorry about the late reply. Here is the game code and files:

http://www.btinternet.com/~jonty85/LWGame.zip
Reaperman
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 22nd Aug 2004 22:10
Jonty.

I have just downloaded it now. I will take a look and get back to you soon.
Reaperman
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 28th Aug 2004 04:12
Jonty.

I have had a good look at it and I must admit that I cannot see why your shot does not fire again after hitting an enemy. The ship did disappear ok (and so did your lazer) but I was unable to fire again after the first shot.

May be you could modify your shot/explosion routine to use my shot/explosion routine in my D-Type game? That works perfectly and is similar to yours. I am really sorry but I cant find the bug in your code.
pizzaman
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 29th Aug 2004 00:58 Edited at: 29th Aug 2004 03:37
hi Jonty

This post has been edited please re-read it

I Figured out the problem of the laser not reappearing, you were not resetting the firepress variable, also I've changed a few things, I've marked in the code where they are



enjoy
pizzaman

Login to post a reply

Server time is: 2025-05-16 12:19:20
Your offset time is: 2025-05-16 12:19:20