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! / Vertical Shooter Laser/Bullet Question/Problem

Author
Message
magus57
18
Years of Service
User Offline
Joined: 30th Jan 2007
Location: TI-Basic and DarkBasic Pro
Posted: 4th Feb 2007 20:19
I'm kind of new to DarkBasic programming, and I'm starting a vertical 2D shooter, but I'm having a problem with the bullets/laser. Here is my current code:



The only problem is, that when I press spacebar, the laser automatically appears at the top of the screen, and stays there until I let go of spacebar (where it disappears to the original location). I've looked at all the tutorials on this topic, but I couldn't understand or use the code, and it just froze my game when I thought I put it in correctly. I'm looking for help with the following:

1. Make the laser slowly go from the bottom of the screen to the top of the screen (and then disappear going into the top)
2. Make it so you can't fire again until the first laser leaves the screen
3. Make it so you can fire while moving diagonally (so far I can only fire when going up, down, left, right, or up-right, but I can't shoot during the other diagonal directions.

Thanks in advance.

If history is to change, let it change. If the world is to be destroyed, so be it. If my fate is to die, I must simply laugh.
Zergei
20
Years of Service
User Offline
Joined: 9th Feb 2005
Location: Everywhere
Posted: 5th Feb 2007 03:57


This your problem with the laser. When using a Repeat loop, it won't refresh the screen, thus exiting when the laser reaches the top of the screen and then refreshing (sync). What you should do is on each iteration of the program change the lasers position and then sync.
Something like this...



I think that should solve your laser problem, i can't test the code because im having problems with my pc... but just ask if any problem arrises.
Regarding the diagonal moving issue, i can't figure out why it won't work. The only reason that comes to mind is that the keyboard won't recognize those 3 keys, and i think thats it, as my pc starts bipping when those keys are pressed simultanously.
You could solve this problem by changing the keys, for example the spacebar, or using I J K L or W A S D instead of UP DOWN RIGHT LEFT.

Further on my stuff at...
magus57
18
Years of Service
User Offline
Joined: 30th Jan 2007
Location: TI-Basic and DarkBasic Pro
Posted: 5th Feb 2007 15:12
I'm sorry to say, but that didn't work. I understand what you were trying to do, but the problem was that the laser didn't even appear on the screen. After some thinking, I came made some code that did exactly what I wanted (I even optimized it a bit):



So now, every time I press spacebar, the y coordinate of the laser is decreased by 3, and then syncs, and then updates everything else (I included the other sprite and the background to not get weird blue screens or missing sprites).

My only problem is this: while the laser is going up the screen, the ship can go almost twice as fast than it normally can in any direction. Any way to prevent this from happening?

And another question: how do I get started on enemy AI?

If history is to change, let it change. If the world is to be destroyed, so be it. If my fate is to die, I must simply laugh.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 5th Feb 2007 19:59 Edited at: 5th Feb 2007 20:01
Your code is pretty messy and un-structured.
I've written your code in a more oragnised way:



I've used text commands as I don't have your media, you can easily change that though.

The main loop looks like this:



Now if you want to add something new like say enemyships just add the function eg



now add the function into the loop like so:



Now code that function at your leisure.


The word "Gullible" cannot be found in any English Dictionary.
magus57
18
Years of Service
User Offline
Joined: 30th Jan 2007
Location: TI-Basic and DarkBasic Pro
Posted: 5th Feb 2007 22:07
Thanks, but I think I'll stick to my old code because I barely understood what was going on in your code (no offense, I'm just not that good at programming yet). I like to try to keep my work as original (and understandable) as possible (besides, I don't even know where to put/replace the stuff with sprites and images in your code). Anyway, where can I find out how to do enemy AI for this type of game?

If history is to change, let it change. If the world is to be destroyed, so be it. If my fate is to die, I must simply laugh.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 6th Feb 2007 10:08
My code does pretty much what your code was attempting to do, just my code is better structured. As for changing the text to sprites you just gotta change TEXT ship.x,ship.y,"X" to SPRITE 1,ship.x,ship.y,shipimage - same with laser.

I do believe this:

is quite easy to read.

If you want to use your own code then look at how the laser sub-routine works. It's got a repeat-until loop with a sync in it.
Everything should move once per loop and only 1 sync when everything is done is needed. Think of it like those Wallace & Gromit movies. You move everything a bit, take a picture, move everything a bit, take a picture.... and so on.
In a game you move everything a bit, sync, move everything a bit, sync, and so on.

If you want I can re-post my code and heavily comment it to help you understand, just let me know.


The word "Gullible" cannot be found in any English Dictionary.
magus57
18
Years of Service
User Offline
Joined: 30th Jan 2007
Location: TI-Basic and DarkBasic Pro
Posted: 8th Feb 2007 00:19
I'd like that, please. And was the repeat-until loop with a sync a good or bad thing? And does your way of optimization actually speed things up?

If history is to change, let it change. If the world is to be destroyed, so be it. If my fate is to die, I must simply laugh.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 8th Feb 2007 14:35 Edited at: 8th Feb 2007 14:38
Quote: "And was the repeat-until loop with a sync a good or bad thing?"


Bad sorry - 1 sync per loop.

I've re-written my code and dropped the use of udt's (user defined types). But realy you should be using them. When you've got to grips with this code I'd highly recomend reading up on the use of types and arrays.

Anyway here's the code highly commented and sticking to your variable names as much as possible (just copy and paste):


And just to show udt's and arrays in action here is a ship that can fire lots of lasers - each laser has its own data and can be individualy checked for collisions etc (again just copy & paste):




The word "Gullible" cannot be found in any English Dictionary.
magus57
18
Years of Service
User Offline
Joined: 30th Jan 2007
Location: TI-Basic and DarkBasic Pro
Posted: 10th Feb 2007 04:13
I tried your code, but I had some problems (after writing the "load image" code and replaced the text commands with "sprite" commands:

1. The ship moved slower than normal
2. The laser was stuck at the upper-left corner of the screen
3. Nothing happened when I pressed spacebar

If history is to change, let it change. If the world is to be destroyed, so be it. If my fate is to die, I must simply laugh.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 10th Feb 2007 12:26
1 - That'll be because the code is set to 60fps and yours was unlimeted fps. Just alter how much you add to the ships x+y in the moveship function.

2&3 - Sounds like some small error probably a variable typo when replacing the text commands with the sprite command. Have a look at any lines you have changed, especialy looking at variable spellings. If you can't find the error then post your code and I'll have a look.


The word "Gullible" cannot be found in any English Dictionary.
magus57
18
Years of Service
User Offline
Joined: 30th Jan 2007
Location: TI-Basic and DarkBasic Pro
Posted: 10th Feb 2007 23:29
Actually, I just gave up on that because I still prefer my own code (no offense). So can you help me with the AI?

If history is to change, let it change. If the world is to be destroyed, so be it. If my fate is to die, I must simply laugh.

Login to post a reply

Server time is: 2025-05-16 05:30:31
Your offset time is: 2025-05-16 05:30:31