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 sidescroller tutorial trouble

Author
Message
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 16th Mar 2007 08:05
Yeah, I'm using the general tutorial, and I'm trying to edit to something new, basically like a game where there are different waves of enemies. Anyways, my first problem is when I shoot the asteroid object, the laser disappears and everything fine, but when I try to shoot again, it appears at the x coordinate of the asteroid and the y coordinate of the ship and freezes there. Any tips on to how to stop that?

Also, any tips on how to create different levels with different setups with enemies (and how to detect hitting each different one, since I ran into a snag when trying to do that) or direction to a specific thread would help a lot.

I have some experience with programming (not in Dark Basic), but I'm still running into some walls on this code. Thanks for any help, I know I'm a super n00b.

Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 16th Mar 2007 15:33
First of all, I would suggest you indent your code, in order to make it more readable and help in the debugging process. As to the laser coordinates, you should update the lx and ly coordinates in the SHOOT subroutine, like this:




The asteroid needs to move. I would suggest you decide how many asteroids you want to have in each level. You could declare an array for this. At minimum, you should store the x and y coordinates (since you are using sprites and not objects), the status of the asteroid, the moving speed of both vertical and horizontal planes (these could be randomly chosen) and the current image. You could use the animation commands to make the asteroids appear to tumble through space. I would make some different asteroids and I would use scaling to make them different sizes.

You could also have the asteroid blow apart into smaller asteroids or your could have certain ones that require more than one hit to destroy them.

In subsequent levels, you could put in an alien ship that fires at the player, a comet, space mines, tie fighters, etc. (i.e. whatever you can think of). You could put in powerups that scroll and if the player's ship runs into it, the guns, ammo, ship, etc. is upgraded. It goes without saying that the game should progressively get harder and more challenging.

You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 16th Mar 2007 22:41
Sorry about the lack of indentation, I have to edit my code outside of dark basic for the most part, since if I leave it on too long while doing other things, my computer likes to go reboot.

I edited my code as to what you suggested (for getting the laser to move) but now it just fires from where the ship is, and freezes there. I'm about to start trying to set up arrays and such for asteroids/enemy ships and etc., but I've got to figure out this laser thing first. I tried getting it to go to the 'moveall' code to hopefully move the laser, but that didn't work. Here's the code, which so far (not changed much from the last time, which should be indented).

Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 17th Mar 2007 01:33
I couldn't figure out what was wrong because the code worked fine for me. I did not realize you were using DBC, as I thought you were using DBP. When I tried it in DBC, I got the same error as you did.

Anyway, I've found that sprite exist() sometimes does not work in DBC, so I made a way around it. I added an array called laser that keeps track of the laser. Here's the code:



I made a few other edits to the code.

You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 17th Mar 2007 02:53
Oh, ok, that works great, thanks!

Do you think it'd be better to basically declare arrays for each specific level, and then just read in the specified array, based on the level? Or is that possible to do?

Of course, I'm working on getting the whole thing of making asteroids approach the ship now, and then hopefully moving on to implementing multiple objects approaching the ship. Gotta take one step at a time.
Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 17th Mar 2007 15:40
First of all, you should determine what elements of your game will make it increasingly more difficult. For example:
- More asteroids to avoid/destroy in total and on screen at one
time.
- Asteroid speed increases.
- Asteroids split into 2, 3 or 4 smaller asteroids.
- Different asteroids that take more than one shot to destroy.
- Maybe a homing missile of sorts that is difficult to avoid.
- An alien ship that shoots at the player - higher levels could
include a homing missile, a laser or a bomb or whatever you think.
- You could put in a life force or health points or whatever you
would call it that if the player is shot that the level
decreases and when it reaches zero, the player dies. In upper
levels, you could make this decrease more significant.
- You could put in a shield of some sort that protects the player
from harm and have it be depleted more easily in upper levels.

Once you have decided what it is that will make your game harder, you could store the elements in an array by reading them from data statements.

An example:



You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 17th Mar 2007 20:34
Yeah, I was thinking of starting out simple, by first increasing asteroids to avoid/destroy, then start putting in enemy ships that fire at the player.

I'm still working around getting things to move and then of course loop the exploding images at the point the sprite is at. Like if I had two asteroids and it moved, cue the explosion there. Guess I'll have to do a few if loops and then go to that specific sprite and generate it there.

Is there a simple algorithm as to moving the asteroids/enemy ships, like something small I can test and then expand upon, or is it more complicated than it should be, because I got one asteroid to be moving, and I had to scrap that code because it would eventually just bounce through the borders and go off. And would it be simpler to start off all the sprites I'm going to use and make them off screen somehow to come in at specific waves, or is there another method to have multiple things ready to go?
Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 18th Mar 2007 01:50
It would help if you could post the media for the game, that way it can be run and tested.

I would suggest using arrays to track the asteroids and whatever else that you want to put in.

I made some edits to your code for you to consider. It moves the asteroids with an array.



There is no collision detection with the ship, so the asteroids will simply move right through it. Also, the game waits while the asteroid explodes - you will need to program it so that the game keeps moving while the asteroid(s) explode.

You will have to tell the program when each level is over and put in a subroutine that will take you to the next level.

You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 18th Mar 2007 02:36
Sorry about that, here's the media I have so far, playership/laser, asteroid, enemy ship, and enemy laser.

Yeah, I think I know what you mean about the game stopping during an asteroid explosion. I think I saw the method to handle the game stopping during that, so I'm going to try and find it and put it in there.
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 18th Mar 2007 05:24
Sorry about that, here's the media (I'm not sure if this is double posting, my other post with it still hasn't shown up. But the media, both sounds and graphics I have currently, should be there.

I now put in a sort of collision thing for when something hits the ship, though it doesn't reappear on screen until I actually move it. Probably a tiny kink in it.

Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 18th Mar 2007 14:48
The reason why player1 is not showing up until you move (after being destroyed) is that you are deleting the player1 sprite after your subroutine call to killplayer.

Also, I think it would be more efficient to do the collision check with the asteroids and player1 from the MOVE_ASTEROIDS subroutine.

One note of caution worth mentioning is that when you call another subroutine from within a subroutine, you have to make sure that none of the variables used to control the first subroutine are changed. For example, if you gosub killplayer and change the variable k, it will mess up the MOVE_ASTEROIDS subroutine.

I would recommend that you animate the asteroid sprite itself, and not sprite #3, when you shoot it with the laser. This way, you won't have problems when you have more than one asteroid on the screen at a time.

The game_over text was not showing up on the screen; I made some tweaks to it. It still needs a little work, because the asteroid and the still exploding ship need to be deleted.



You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 19th Mar 2007 23:21
I'm about to work on it more now, but also, another question. Is there some kind of limit as to what kind of music can be played in the game? I tried to play and loop a short MIDI file, and I did everything correctly, but it keeps saying the music could not be loaded.
Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 20th Mar 2007 01:36
MIDI (*.mid) files can be loaded and run by DBC. It sounds like there is something in the path or filename that is incorrect. Make sure it is in the correct folder and if you have a path listed that it is spelled correctly and has delimeters (i.e. "\") between the file names.

You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 21st Mar 2007 20:32
Well, I put it in the folder, and it has the correct name. Odd. And I'm trying to implement a sort of thing where multiple asteroids will start appearing (rather than just one at a time), and then at least for something to start on, it would be like Asteroids for the first level, then enemy ships for the second, then maybe a combination of both for the third. Not sure if that's possible though.
Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 22nd Mar 2007 01:23
Ortega - As to the midi problem, please post the code and media.

As to more asteroids appearing at one time, it is a piece of cake! Just change the second number in the data statement, which is for 'asteroids_on_screen'. If you change it to 3, for example, three asteroids will appear on the screen at once. The program is set up to where you could have 15 at a time if you want. I have listed what each number stands for in the data statements:
rem 1=total_asteroids, 2=asteroids_on_screen, 3=asteroid_max_speed
rem 4=asteroid_split, 5=asteroid_type, 6=homing_missile, 7=alien_ship, 8=alien_ship_missile, 9=shield_hit
So in the code: rem level 1
data 50,1,8,0,1,0,0,0,5
The 50 equals total_asteroids, 1=asteroids_on_screen, 8=asteroid_max_speed, etc.
You could set up alien ships by setting the seventh number>0. Of course, you will have to put in the code to handle the ship, but you can easily set what you want for each level.

You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 23rd Mar 2007 15:34
My other media should be on another post, as far as the other images and sounds, I'm attaching the midi file I'm using.

Also, is it possible to change the amount of asteroids that appears on screen dynamically during the game itself, or does it have to be preset?

And that stupid freezing problem during explosions is still present, I thought putting a sort of timer on it would fix it, but guess not.

Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 24th Mar 2007 04:44
I downloaded the midi file, put it in the same folder with the program, and it worked fine.

I usually put the music and sound effects in last, because when you play-test the game 50 times it gets a little monotonous plus it takes a little longer to load. Or at least I will REM out the statements that access the sound/music. To each his own.

You could easily change the amount of asteroids on the screen at a time while the game is running. All you would have to do is change the 'asteroids_on_screen' variable.

I have updated the code to allow for smooth animation when you shoot the asteroids and when they collide with the player's ship.



To keep the program from stopping to animate one thing, you have to code it so that the program still flows and checks for this condition and then has the code to handle that condition. It takes more than just putting a timer in. You can compare this to the previous code to see what I did.

The code could use a little cleaning up, but I'll leave that to you.

You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 26th Mar 2007 20:15
Thanks a lot for the help, I really appreciate it.
Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 26th Mar 2007 21:52
You're welcome.

You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 28th Mar 2007 08:27
One more quick question

I wasn't completely sure how to change levels from the data statements, so I tried to do an incrementing thing for more asteroids. Unfortunately, eventually the asteroids just run out, and there's nothing left. Is there a way to alleviate this problem? I'm not sure if there's a way to make it where the asteroids are infinite, or jump to another level without causing an error. Here's the code I have so far, with lots of stuff kind of repeated in the blowitup routine:

Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 28th Mar 2007 15:10
The idea of having the asteroids 'run out' was to give the user a little bit of a break in between levels. It is no problem to take it out of the program and just have it progressively get harder. The revised code:



It does indeed get a lot harder fairly quickly, in fact I had to take out the gosub to the LOSE_LIFE subroutine in order to test it. You may want to think about a few things:
1. Is the hardness factor progressing too quickly?
2. Do you need more than one shot at a time on the screen? (Maybe you could put in a powerup as the game progresses to allow for additional player shots.)
3. What about a rapid fire option if the fire button is simply held down? (powerup?)
4. Is the level indicated on the screen correct? It did not seem to update correctly.
5. Do you need more lives to start with?
6. What about a one-up powerup?
7. How about an option to pause the game?

You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 28th Mar 2007 19:47
Well, I was just trying to see if it work, I'm going to twink it a bit as to not have the difficulty ramp up so fast. Yeah, I may increase lives and stuff.

Would pausing it just be something like if the user presses a certain key, then do the suspend command or something?
Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 28th Mar 2007 21:46 Edited at: 30th Mar 2007 02:49
There are several ways you could put in a pause. I would suggest the following:

1. You will need to let the user know how to pause the game. At some point, I assume you will have a title screen, which you could use for this task. You could list it along with your score update, but I would not recommend it.
2. In your do - loop, put in a check for a certain keypress to intiate a pause.
3. After the keypress, you could gosub to a subroutine to handle the pause. The subroutine could simply have a box come up that states the game is in pause and what the user has to do to return to the game. I would suggest saving bitmap 0 prior to executing the pause subroutine.
4. The pause subroutine should have repeat - until loop or a do - loop that keeps checking for the condition to return from the subroutine. Be sure you have a sync command in your loop.
5. Once the condition has been met for exiting the pause subroutine, simply copy the saved bitmap to bitmap 0 and return to the program.





You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 30th Mar 2007 06:32
Hmm, I'm taking a look at that now.

Also, as a quick note, is there a small routine I can add to somehow make it where the player can try the game again if they lose all their lives, like hit y/n to dictate whether they will try again?
Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 30th Mar 2007 15:46
Coding for a game over subroutine could be done in a similar way.



I had to put in something so that you could make the lives go to zero, hence the use of the 'L' key.

You idiots! You've captured their stunt doubles!
Ortega
19
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 30th Mar 2007 19:52 Edited at: 30th Mar 2007 19:58
Would initializing everything include loading all the images/backgrounds/etc? I'm just trying to edit in all the code and not sure where to draw a dividing line or something.
Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 30th Mar 2007 21:09
A good general rule of thumb is to make your program as readable as possible. You can overdo this, so make it reasonable. Readability has many advantages, including making your code easier to go back and edit or debug in the future. Plus, no one wants to wade through messy code to help you with a problem.

I would suggest that you place code that sets variables that affect your game (lives, score, arrays, etc.)in one subroutine and put graphics oriented (screen setup, loading and grabbing images, backgrounds, etc.) initializing into a separate subroutine.

You idiots! You've captured their stunt doubles!

Login to post a reply

Server time is: 2026-07-05 00:29:09
Your offset time is: 2026-07-05 00:29:09