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! / [STICKY] Tutorial On 2D Shoot Em Ups.

Author
Message
Hells Messenger
12
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: War Torn Froozen Waste Land
Posted: 4th Jul 2004 06:13 Edited at: 4th Jul 2004 10:02
Hey, Right i've started working on a space shooter and i used your first tutorial to help me, but i've altered it to how i want it (bad....mistake im a newcomer to DBP) as i want a vertical scrolling space shooter not side shooter anyway i've mess up somewhere at the end of your code and when i compile the code its comes up with this error #100012: Could not close nest at line 160, do you think you could take a look at the code and tell me where i've gone wrong? please. Chris

Goverment... is just another way to say Better, Than, You!
Xatnys
12
Years of Service
User Offline
Joined: 8th Jul 2004
Location:
Posted: 8th Jul 2004 11:34
Hi there, I'm new to posting so I hope I've done this right. Actually I'm new to DarkBasic, and have only been trying to learn it for 5 days now. I have put my version of this tutorial below. I was hoping to get some advice on how I can correct the following problems:

1. After making modifications to the original code, my sprite based collision detection is no longer functioning and I have no idea why or how to fix it.

2. The actual fire weapons method I have setup, seems to be cumbersome, with jumping from Playerfire to Shoot, for basically a very similar function. Any thoughts on the proper way to address this?

3.I had the hardest time figuring out how to get this program(the original to loop), while I think I have it looping well now, I'd like to know the best way to do so, as I'm really trying to learn as much as I can.

Thank you for your help!

Nathan

sync on
sync rate 30
color backdrop 0
hide mouse

rem this are the graphics the game will be using
load image "yourship.bmp",1
load image "alienship.bmp",2
load image "orb.bmp",3
load image "greenlazer.bmp",4
load image "yellowlazer.bmp",5
load image "exp1.bmp",6
load image "exp2.bmp",7
load image "exp3.bmp",8
load image "exp4.bmp",9
load image "exp5.bmp",10
load image "exp6.bmp",11
load image "stars.bmp",50
load image "title.bmp",9999

load sound "phaser03.wav",1
load sound "boom2.wav",2

rem this makes an object for use as a background
Make Object Plain 4,600,56

rem this makes the object semi-transparent
ghost object on 4

rem this positions the above object
Position Object 4,0,-4,80

rem this puts stars.jpg image onto the object
Texture Object 4,50

rem then lock the object (although not exactly sure why) I'm learning
Lock Object on 4



rem now make background black to create starfield.
color backdrop rgb(0,0,0)



pf=0:score=0:Levels=1:Lives=3
ysx=50:ysy=200


rem this should put playership into starting position
Sprite 1,ysx,ysy,1

rem these are used to position the laser fire sprites
lx=sprite x(1)+20
ly=sprite y(1)+10

rem display's the sprite of the enemy ship
Sprite 3,500,200,2

rem this sets the title to the screen
Sprite 9999,10,10,9999



do
rem this sets up the Game score and info fields
set cursor 200,400: Print "SCORE:";score; " LEVEL:";level;" LIVES:";lives



rem this checks to make sure you are not closer than 100 pixels to the top of screen then moves you 10 units
IF upkey()=1 and ysy>100
dec ysy,5
endif

rem this checks if you are closer than 420 to the bottom of screen, if not it moves you down 10 units
IF downkey()=1 and ysy<420
inc ysy,5
endif
rem greenlazer.bmp's variables
lx=sprite x(1)+20
ly=sprite y(1)+10

rem re-draws the ship to the screen
Sprite 1,ysx,ysy,1
Sprite 3,500,200,2

rem function call to MoveAll()
MoveAll()

rem function call to MoveStars()
MoveStars()

rem Function Call to Shoot()
Shoot()

rem Function Call to Playerfire
Playerfire()

rem Refreshes the screen
sync
rem end of Do Loop
loop




rem If spacebar is pressed, go to function Shoot()
Function Playerfire()
If Spacekey()=1
shoot()
endif
endfunction

rem Has the texture on the object scroll to simulate motion
Function movestars()
Scroll Object Texture 4,0.01,0.0
Endfunction

rem if spacebar is pressed, display greenlazer.bmp play sound and
rem goto blowup()

Function shoot()
if Spacekey()=1
sprite 2,lx,ly,4
play Sound 1
Blowup()
endif
Endfunction


Function MoveAll()
If Sprite Exist(2)=1
If Sprite x(2)<640
LX= LX+30
Sprite 2,lx,ly,4
endif
endif

IF Sprite Exist(2)=1
IF Sprite x(2)>640
PF=0
LX= Sprite x(1)+20
LY= Sprite y(1)+10
endif
endif
EndFunction


Function blowup()
Sprite 2,lx,ly,4
If Sprite Exist(2)=1
If Sprite Hit(2,3)=1
delete sprite 3
play sound 2
for t=6 to 11
Sprite 3,500,200,t
wait 1
next t
delete sprite 3
Sprite 3,500,200,2
endif
endif
Endfunction

Hello.
Goodbye.
Izzy545
13
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 24th Aug 2004 02:12
Is it alright if I use your graphics to make and release this game, or should I make my own?
Reaperman
13
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 24th Aug 2004 04:42 Edited at: 24th Aug 2004 04:45
@Izzy545.

You can use the graphics in all the tutorials in your own games, its not a problem.

@lokatsis.

I will look at your code and post a snip for you to use.

@Plastico.

Like any tutorial for any language, it can help newcomers even if its in DBP. Though remember that this tutorial is for DBC.

@ghost.

Unless you changed the code (or maybe a file was corrupted during download?) then the program should not think a file is a music one when its not. Can you post and tell me which file and show me a small snip of the code that loads/plays it please.

@UnderLord.

I can give you a scrolling code for all directions. Just hold on a mo and I will post it for you.

@Hells Messenger.

"Could not close nest at line 160, do you think you could take a look at the code and tell me where i've gone wrong."

Sure can. But when I put your program in to DBC it only has 157 lines.
However, the problem was tracked down to not closing the DO/LOOP.
Add this:
` Weapon Fire Controls
if inkey$()="space" and pf=0 then gosub shoot:pf=1
if SPRITE EXIST(2)=1
if SPRITE HIT(2,3)=1 then gosub blowitup
endif
` Your Ship again
sprite 1,ysx,ysy,1
loop

That will solve your problem.

@Xatnys.

“1. After making modifications to the original code, my sprite based collision detection is no longer functioning and I have no idea why or how to fix it.”

It looks like your not checking if your hitting anything in your main DO/LOOP. Try putting something like this in:
If Sprite Hit(Whatever,Whatever)=1then...Jump to your blow up routine.

“2. The actual fire weapons method I have setup, seems to be cumbersome, with jumping from Playerfire to Shoot, for basically a very similar function. Any thoughts on the proper way to address this?”

Well, my advice to you is to use the fire routine I used in the D-TYPE version of the game. Sorry if that sounds like a cop-out but it would be just the same if I were to tell you what to do.

“3.I had the hardest time figuring out how to get this program(the original to loop), while I think I have it looping well now, I'd like to know the best way to do so, as I'm really trying to learn as much as I can.”

It all depends in what you want to set a loop to do. A DO/LOOP is a forever-type. It just goes round and round, at least until you use the EXIT command. A FOR/NEXT loop does something a set number of times. The rest of the types (WHILE/ENDWHILE/REPEAT/UNTIL) are set up to execute until a certain event happens. So you need to set out what your loop is trying to accomplish in what area of the program and then use the appropriate looping type.

Hope that helps. Sorry for the delay in replying.
Izzy545
13
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 24th Aug 2004 08:05
Just in case you wanted to see what has come from your tutorial take a look here:

http://forum.thegamecreators.com/?m=forum_view&t=37831&b=8
Reaperman
13
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 24th Aug 2004 13:17
Well Done Izzy545

Its always nice to see someone benifit from something I have done, so thanks for posting that link, or I never would have known!
Peter H
13
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 27th Aug 2004 02:22 Edited at: 27th Aug 2004 02:22
@Reaperman- if i want to make a 2D explosion graphic...and i have a image like this(from exgen)

actually i have a individual image of each explosion but i'm just showing you this so you know what kind of explosion i'm talking about..

anyway so do i just loop through the images?(turned into sprites and positioned at the explosion's location...)

"We make the worst games in the universe."
Reaperman
13
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 27th Aug 2004 02:48
@Peter_H

"do i just loop through the images?"

Correct Peter. That is just what you would do
Peter H
13
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 27th Aug 2004 02:53 Edited at: 27th Aug 2004 09:26
arg...i'm having problems though because i'm using sprites for explosions it messed the rest of my program up...(hadn't used sprites in this program yet) so i'll probably just use my own "custom" sprites....
(I.E. store the pixels that aren't black in a array and then put them on the screen using the "dot" command......but of course using the "lock pixels" command to speed it up...)

[edit] got it to work...want to try it?
download- 1192 KBs
http://wakehosting.com/upload/files/YQudJUoS/SingedDust.zip
controls-
left click to create an explosion...
right click to toggle explosion type...

[edit2] BTW i didn't use any sprites in the program

"We make the worst games in the universe."
Qwisats Haderach
12
Years of Service
User Offline
Joined: 23rd May 2004
Location: Dune
Posted: 11th Nov 2004 01:43
can anyonve help wit this code. u can get the pics here: http://forum.thegamecreators.com/?m=forum_view&t=42224&b=7

+ Code Snippet
PowerMan
12
Years of Service
User Offline
Joined: 22nd Jan 2005
Location: Manchester
Posted: 27th Jan 2005 06:16
This Forum is great to learn about the 2D essentials

can i just ask one question.
when the game starts and you press z to fire the weapon if you move it does not fire it from the ship but from the starting point which the ship was first drawn to the screen. How can we remidy this?
PowerMan
12
Years of Service
User Offline
Joined: 22nd Jan 2005
Location: Manchester
Posted: 27th Jan 2005 06:39
how can i implement this code into the game instead of creating a 3D object for the stars (can anyone of you gurus help?).

it is a dot parralax stars loop
+ Code Snippet
Mist Walker
12
Years of Service
User Offline
Joined: 20th Mar 2005
Location:
Posted: 20th Mar 2005 14:15
Quote: "Eatfishy@
Thanks reaper man. I'm having another problem now. I could make all the enemey move like in space invader, but the sprite won't delete when fired at.I could make the sprite delete, but they won't move at all. So, it's either the spries move and can't be delete or the sprites can be deleted, but can't move."

I'm also having the same problem. Any help out there please?
Thanks in advance
RyokuMas
11
Years of Service
User Offline
Joined: 5th Jul 2005
Location:
Posted: 14th Jul 2005 22:16
Tapewormz - more efficient attack wave code:

Rather than tracking every single coordinate, fix key points - either put a mouse click check into your tracker to fix a point, or have the program generate them randomly for a game that differs every time, and have your enemies have horizontal and vertical velocities and a counter for which fixed point in the sequence is their current "target" (ie: they are moving towards) as well as X and Y corrdinates. Then check their coordinates against the current target, and modify the horizontal and vertical velocities as required (assuming they're not at max speed). Then, when they get near the target point (I find that this should be a zone about the same size as the enemy graphic around the target point), step the target counter up so they then change course for the next target - assuming that they're not at the last one). This gives nice, sweeping attack waves while only requiring about 30 pairs of target coordinates, and can also provide infinte variation in your attack waves!

"It's not the great who are strong - it's the strong who are great"

Login to post a reply

Server time is: 2017-03-29 21:56:17
Your offset time is: 2017-03-29 21:56:17