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
Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 11th Mar 2004 17:34 Edited at: 28th Mar 2004 04:34
While I have been on this board, I have noticed that many “noobs� are struggling to come to grips with the powerful language within DarkBasic and so I have written this simple tutorial based on 2D sprites.

Its not for those of us who know the language but it should help some of the newcomers.

Type of game

This tutorial will focus on making a “bare bones� program for a scrolling shoot em up game.

Please note that when you type in this program, you do NOT put the line numbers in. So where you see something like this:

20 goto flibble

You type in:

Goto flibble

The line numbers are only here to help me point out which line we are looking at.



Getting Started

The first thing we must do is to set up the system.

This is done by typing in the following lines:

1 sync on
2 sync rate 30
3 hide mouse

Line 1 sets the program up so that you, the programmer, have to tell the system when to refresh (or re-draw) the screen and update everything. Darkbasic does do this automatically by using SYNC OFF but in a program like this, it causes the game to run slowly. So it is always better to control the refresh yourself.

Line 2 sets the speed that the program will work at in Frames Per Second (FPS). If you have an old system that runs slowly you can change this setting to speed up your game. SYNC RATE 0 will set the program to run at the fastest the computer can handle. If you need to change it, try setting it to SYNC RATE 60 before you set it to zero.

Line 3 simply hides the mouse as we don’t want a mouse pointer on the screen when your playing.

The next thing to do is to load in the graphics for the game.
Darkbasic has several ways to do this, and there are also several different ways using programming to load the graphics in, but I have chosen to keep it simple.

Type in the following:


4 load image "yourship.bmp",1
5 load image "alienship.bmp",2
6 load image "orb.bmp",3
7 load image "greenlazer.bmp",4
8 load image "yellowlazer.bmp",5
9 load image "exp1.bmp",6
10 load image "exp2.bmp",7
11 load image "exp3.bmp",8
12 load image "exp4.bmp",9
13 load image "exp5.bmp",10
14 load image "exp6.bmp",11
15 load image "stars.bmp",50
16 load image "title.bmp",9999

What we are doing is this…….

Line 4 loads the image of our ship, called “yourship.bmp� in to an empty bank in memory, which is bank 1 in this case.

All the other lines are doing exactly the same thing but with different graphics and different banks.

Ok, so now your program sets itself up and loads in all the graphics. Now you are going to make a star field that moves from right to left to give the impression of movement.
In games such as this there are many ways to achieve the effect of scrolling stars. Some people use sprites for this, while others use animations or pre-calculated data. We are going to use a simple and fast routine that does not take up pages of programming to do, and can be controlled using a single variable.

(In fact, my daughter, Dragon3, used a routine that was similar to this in her Evolution Intro).

You start off by making a 3d object.

17 MAKE OBJECT PLAIN 4,600,56

Then you position it on the screen.

18 POSITION OBJECT 4,0,-4,80

Next you use the graphic held in bank 50 (which is the stars.bmp picture) and “texture� the blank 3d object with it. In other words your Stars.bmp picture is stretched out over the 3D object so that you see the stars.

19 TEXTURE OBJECT 4,50

Finally you lock the object on to the screen so that it is positioned correctly.
(If you want to know what would happen if you did not do this, then REM out Line 19 and 20 and later on when you run the program you will be able to see what happens.)

20 LOCK OBJECT ON 4

Ok, so now just colour the screen in black and you have your stars in space.

21 color backdrop rgb(0,0,0)

If you want to see the program so far, add the following lines:

29 do
44 sync
45 loop

Ok…. Well done.

However, lets set up some variables now that will help us control the program later.

22 pf=0:score=0:Level=1:lives=3
23 ysx=50:ysy=200

These variables set the score, lives, level and also if you have fired your weapon (pf=Pressed Fire). They also store the position of your ship (ysx=Your Ships X…. ysy=Your Ships Y). This will be used for moving your ship sprite when you press the up or down arrow key.

The next thing we do is to put your ship on the screen at the coordinated specified by the ysx and ysy variables.
24 sprite 1,ysx,ysy,1

We then set up the position of where the lazer beam is going to shoot from. This is done by these two lines:

25 lx=SPRITE X(1)+20
26 ly=SPRITE Y(1)+10

The lines set lx (lx=lazers X: ly=lazers Y) and ly to where the top left point is on your ships sprite and then it moves it 20 pixels forward and 10 pixels downward…Which put the firing point roughly at the front middle of your ship. Later on, when you have typed in this listing, try altering the +20 and the +10 to see what it does.

Next we put the title on the screen, which is stored in sprite 9999. I used a high number to make it clear within the listing what it was.

28 sprite 9999,10,10,9999

Right…. After line 29 you need to type in this:

30 set cursor 200,400: Print "SCORE:";score; " LEVEL:";level;" LIVES:";lives

This will set up a simple print command to display score, level and lives. We don’t use this within this tutorial, but hopefully some of you new programmers will take this code from the tutorial and will add to it and make it in to a mini game. If you want to use a score, level and lives counter then you would only need to ADD an amount to the “score� variable every time you shot an alien and then your main loop would just display the updated score via line 30 when it loops. You could of cause remove or replace line 30 should you wish to….It is totally up to you.

Next we get the players ship to respond to an input from the player.
To keep it simple, your ship can only move UP and DOWN and FIRE.

The routine to move the ship UP is this:

31 if UPKEY()=1 and ysy>100
32 dec ysy,10
33 endif

This small routine is basically saying: “If the user presses the UPKEY (arrow key) AND the players ship is LOWER that 100 pixels from the top of the screen, then take away 1 from the Y position of the ship…But do it 10 times, so your really taking -10 from it�

The routine for moving the ship down is much the same except it checks to make sure that the ship if higher that 350 pixels.

34 if DOWNKEY()=1 and ysy<350
35 inc ysy,10
36 endif



The fire a lazer routine checks to see if you are pressing the “Z� key and if you are AND if the variable pf=0 (in other words, you have NOT fired a lazer) then it jumps (gosub) to the shoot a lazer routine and then sets pf to 1 to make sure that the routine cannot be used again until the lazer you have just fired has been removed from the screen.

37 if inkey$()="z" and pf=0 then gosub shoot:pf=1


We then put the ship on the screen again:

38 sprite 1,ysx,ysy,1

And jump to 2 routines that move the stars and also the lazer:

39 gosub moveall
40 gosub movestars

To move the stars is simplicity itself. All you have to do is to make the star pattern scroll across the 3D object. To do this use the following:

41 movestars:
42 SCROLL OBJECT TEXTURE 4,0.01,0.0
43 return

If you want to speed up or slow down the stars just alter the 0.01 to another amount…. You will be able to have them any speed at all.


Shooting the lazer is easy too. Just put the lazer (which is sprite 2) on the screen and also play a sound to let everyone know that its been fired. Like this:

44 shoot:
45 sprite 2,lx,ly,4
46 PLAY SOUND 1
47 return

To move the lazer we first check to make sure that it is on the screen by the command : “if SPRITE EXIST(2)=1� (Line 49). If the sprite was NOT on screen, then this would return a “0�.
Provided that it IS on screen, the next thing to do is to make sure its not gone off the right side of the screen by checking that its X coordinate is LESS than 640 (line 50) (the screen is a 640 by 480 size by default).
If it is less that 640 then we move the lazer to the right by 45 pixels (line 51), which is the same as the length of the lazer.

48 moveall:
49 if SPRITE EXIST(2)=1
50 If sprite X(2)<640
51 lx=lx+45
52 sprite 2,lx,ly,4
53 endif
54 endif

What is the sprite IS GREATER than 640? Well we don’t move it any more and we reset the pf variable to 0 to make sure we can re-fire the lazer.

Here is that routine….See if you can figure out yourself how this little part works.

55 if SPRITE EXIST(2)=1
56 If sprite X(2)>640
57 pf=0
58 lx=SPRITE X(1)+20
59 ly=SPRITE Y(1)+10
60 endif
61 endif
62 return

Ok so there you have it. A bare bones for a side shoot em up game. A lot simpler than you thought eh?

Here is the full listing for you to copy and paste in to DarkBasic.
I have included a shoot the alien and blow it up routine too..But remember... This tutorial is NOT a finished program. Its now up to you to mess about with it and to make it in to a mini game.

Learn from it and when you have used it ( and maybe made something from it) post it here so that we all can see it. Even if you don’t use it at all, please post and tell me if this kind of tutorial helped you.

Also, go HERE...
http://www.cybcity.com/dolphinsoft/html/untitled2.html

And download the graphics you will need for this tutorial. Just unpack them into the SAME directory you save this program in and everything will work fine.

Have fun.


sync on
sync rate 30
color backdrop 0
hide mouse
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
MAKE OBJECT PLAIN 4,600,56
ghost object on 4
POSITION OBJECT 4,0,-4,80
TEXTURE OBJECT 4,50
LOCK OBJECT ON 4
color backdrop rgb(0,0,0)
pf=0:score=0:Level=1:lives=3
ysx=50:ysy=200
sprite 1,ysx,ysy,1
lx=SPRITE X(1)+20
ly=SPRITE Y(1)+10
sprite 3,500,200,2
sprite 9999,10,10,9999
do
set cursor 200,400: Print "SCORE:";score; " LEVEL:";level;" LIVES:";lives
if UPKEY()=1 and ysy>100
dec ysy,10
endif
if DOWNKEY()=1 and ysy<350
inc ysy,10
endif
if inkey$()="z" and pf=0 then gosub shoot:pf=1
if SPRITE EXIST(2)=1
if SPRITE HIT(2,3)=1 then gosub blowitup
endif
sprite 1,ysx,ysy,1
gosub moveall
gosub movestars
sync
loop
movestars:
SCROLL OBJECT TEXTURE 4,0.01,0.0
return
shoot:
sprite 2,lx,ly,4
PLAY SOUND 1
return
moveall:
if SPRITE EXIST(2)=1
If sprite X(2)<640
lx=lx+45
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
return
blowitup:
delete sprite 2
PLAY SOUND 2
for t=6 to 11
sprite 3,500,200,t
wait 1
next t
delete sprite 3
end
return
Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 11th Mar 2004 17:54
Oh....before I forget.

If newcomer needs help, please post and I will do my best. Tho I am sure others will also help with questions if needed.
tayete
21
Years of Service
User Offline
Joined: 20th Nov 2002
Location:
Posted: 12th Mar 2004 12:29
Thanks for the tutorial! A short game is always the best to teach!

__________________________
http://www.tayete.com
Zero Blitzt
20
Years of Service
User Offline
Joined: 18th Jan 2004
Location: Different Stages
Posted: 12th Mar 2004 13:36
Great! I could never understand 2D really, even though its quite simple, and this helps a lot! Thanks a bunch.

http://www.t4e0.4cybiko.com- GameXaero Forums
http://www.t4e0.4cybiko.com/gxstudios - GX Studios
Tapewormz
21
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 13th Mar 2004 03:53
Simple, but it does what it's supposed to do. Teach by example. I like it.
UnderLord
20
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 13th Mar 2004 07:18
tomorrow when i wake up i'll read it =)

The search continues.

Current project - A space game
Tapewormz
21
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 14th Mar 2004 01:31
I've got a quick question:

In the past I've used a method that tracks mouse movement while the mousekey is depressed and stores the tracked data to an array that I used to create attack waves. Is there a more efficient method? This works well, but it seems like more overhead (processing) than needed.

Thanks
Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 14th Mar 2004 03:14 Edited at: 14th Mar 2004 03:26
In the past I've used a method that tracks mouse movement while the mousekey is depressed and stores the tracked data to an array that I used to create attack waves. Is there a more efficient method? This works well, but it seems like more overhead (processing) than needed.

Making attack waves can be as complex or as easy as you want.

You can use data stored within arrays, or you can use it stored in DATA statements. Most commercial games have pre-defined waves, or a mixture of some random elements and pre-defined. A simple way to do it is to pick a random number and if that number equals a specified amount, then place a ship off the screen (at a random X and Y coordinate) and then move it on to the screen.

You can also use Sin and Cos routines to move your alien ship about a bit.

Save the following program in to the same directory as you saved the shoot-em-up graphics and then run it.




If you need any other help, please be specific on what you need your program to do and how your program works, and I will see what I can do.
Tapewormz
21
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 14th Mar 2004 05:26
Hey Reaperman,

Thanks for the info. I kind of figured it would come down to combonations of math formulas.

I really appreciate your post. I haven't tried it yet, as I'm always at work when I read these forums, but I will try it when I get home.

Thanks for taking time out to provide some quality guidence.
UnderLord
20
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 22nd Mar 2004 20:11
woohoo this should do well for learning to code shooting for my 2d game i got down the movement the way i want it and now move onto shooting and AI

The search continues.

Current project - A space game
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Mar 2004 20:53
There is some shooting in there, press z.

Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 27th Mar 2004 16:37 Edited at: 28th Mar 2004 04:20
Yes...you can press Z.... But please change the key to anything you want.
John H
Retired Moderator
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 28th Mar 2004 00:25
[brings out the cyber glue rifle]

BAM BAM BAM

/me is covered with glue, but so is this thread.


We need help! Email us! join@eternaldestinyonline.com
Arkheii
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 29th Mar 2004 04:27
Wow, you can do a bare bones shooter in this little amount of code? I fell into the tarpit of functionizing everything. Too much encapsulation I guess.


"Story in a game is like story in a porn movie. It's expected to be there, but it's not that important." - John Carmack
Tapewormz
21
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 31st Mar 2004 03:25
Quote: "Wow, you can do a bare bones shooter in this little amount of code? I fell into the tarpit of functionizing everything. Too much encapsulation I guess."


Ah, but the nice thing about breaking the code up into functions is the abillity to upgrade your source easilly. Also, the abillity to call a function, and exit the function before it's ended is an easy optimisation over using gosub/return.

This sample code is great for beginners though.

Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
Arkheii
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 31st Mar 2004 03:41
I'm trying to do a Raystorm kinda thing. So far I'm working on the entity editor, so there is one base model that can have multiple variants of weapons and submodels. If I hard code everything I could probably finish faster, but I don't feel like getting messy and this is a long project (plus, I'm lazy). I think there should be a 3d extension of this tutorial, where it teaches how to make the 3d coordinates seem like 2d for the AI.


"Story in a game is like story in a porn movie. It's expected to be there, but it's not that important." - John Carmack
Tapewormz
21
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 1st Apr 2004 03:19
If you're a compitent programmer, then I would suggest you stick to your guns and use functions.

Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 4th Apr 2004 20:02 Edited at: 4th Apr 2004 20:14
Ok, as I promised some of you, I have updated the tutorial to try and help some who are a bit lost as to how to go about using the code in their own programs.



The code is, of cause, simple and un-compressed, which should make it easy for newcomers to understand.

While the program is fully remarked, I will post a brief outline tutorial of the changes I made to the original code so that you can all see what I did to it.

My suggestions to anyone who wants to take this further is the following:

1. Make the turrets shoot. This is easy to do really. All you need to do is to check the “X� coordinate of the turret, and when it is within a defined area (say, when it is past half way on the screen…EG: LESS than 300) then it can start to fire.

2. Add some enemy sprites that fly about and shoot.

3. Add a title screen, and an end screen.

4. Add a big boss at the end of the level.

5. Let your ship “catch� a power up, and then change the sprite from a green lazer to a yellow one that does not blow up when it hits something but carry’s on regardless (In other words…It “Powers up� the lazer).

Basically... Just mess about and have fun.

I hope this helps those of you who have asked me to do this.

I will post an updated tutorial tonight.

The download can be found here:
http://www.cybcity.com/dolphinsoft/html/untitled2.html

(NOTE: Please give it a few mins before trying to download....I am correcting a fault with the zip file and it will be ready to download within the next 10 mins from the time of this posting)
Tapewormz
21
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 8th Apr 2004 07:21 Edited at: 8th Apr 2004 07:25
What resolution is that? I can't download the code (i'm at work), I'm just looking at the screenshot.

Quote: " Timesoft - Your wife is death. How? NO idea.
But it is murder. REVENGE!!!!!!!!!"

Hands down the funniest synopsis for a game ever. All your base are belong to us!
lokatsis
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location: greece
Posted: 8th Apr 2004 23:42
hello i'd like to ask something about bare bones game. i have make the alien ship to move but lets say now that i want to have 5 alienships
to move in the same time in the game what is the right method to make this effect? i tried of course the if then commands but only the first alienship was moving. what should i do?

THE AOOS
Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 9th Apr 2004 00:15
Quote: "What resolution is that?"


Its a 640 by 480 screen Tapewormz.

Quote: "hello i'd like to ask something about bare bones game. i have make the alien ship to move but lets say now that i want to have 5 alienships
to move in the same time in the game what is the right method to make this effect? i tried of course the if then commands but only the first alienship was moving. what should i do?"


Post your code and I will take a look.

However, you can use the same type of routine as I did for the D-Type game level when placing and moving the walls.

By the way... Sorry to everyone who was waiting for the tutorial update. I had to go away for a few days, but now I am back I will post the code and update before the end of the week.
lokatsis
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location: greece
Posted: 9th Apr 2004 00:59
here is my code shall i use for next commands? anyway i dont have the
source code of d type only a standalone. ihave only the source code of the tutorial. pls help

THE AOOS
Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 9th Apr 2004 16:02
Ok here is the listing for the D-Type game.

I thought about it...but I am not going to post a detailed explanation over it as its quite easy to read. IF any newcomer has a question over it, then I will answer.


Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 9th Apr 2004 16:11
lokatsis.........

You have done well so far. All you have to do is to put the other 4 aliens on the screen and change your movement routine.

moveall:
if SPRITE EXIST(2)=1 <------ You could change the "2" to a variable so that you can re-use the routine to check all 5 of your aliens.
You need to change all the other "2"s to the variable too however.

So your loop would look something like this:

moveall:
For Alien=2 to 6
if SPRITE EXIST(Alien)=1
If sprite y(Alien)>(-35)
ly=ly-45
sprite Alien,lx,ly,4
endif
endif
if SPRITE EXIST(Alien)=1
If sprite y(Alien)<(-35)
pf=0
hide sprite Alien
lx=SPRITE X(1)+20
ly=SPRITE Y(1)-10
endif
endif
next Alien
return

OR.....you could just duplicate the routine for each alien you want to move.

Your choice.
Weegi
20
Years of Service
User Offline
Joined: 6th Apr 2004
Location:
Posted: 9th Apr 2004 16:24
Ive just tried to implement the game using the code in Reaperman's first message on here and it tells me the there is a runtime warning at line 19, that the sound could not be loaded. Could anyone help me overcome this problem?

Life's not a wheel, with chains made of steel, so bless me, come the dawn
Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 9th Apr 2004 19:00 Edited at: 9th Apr 2004 19:33
Weegi.......

I take it you mean the first tutorial and not the second one?

If so, then you need to download the files.

Go here to do that.....
http://www.cybcity.com/dolphinsoft/html/untitled2.html

If you mean the D-Type game, then you can go to the above address within the next hour and download the music and all wall graphics as I am placing them up there too.

EDIT: Ok the files for D-Type are now on-line.
Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 10th Apr 2004 06:43
Weegi....... did that help or not?
lokatsis
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location: greece
Posted: 12th Apr 2004 20:20
thanks a lot, i will tried now

THE AOOS
Truth Of Seafood
20
Years of Service
User Offline
Joined: 26th Dec 2003
Location: US of A
Posted: 23rd Apr 2004 18:37
Wow this help me sooo much. Im only 13 and it makes sence to me *finally!* it makes it so much easier for me to see the codeing and then have someone explain what it is doing. This is one of the best tutorials I have come across.

If Hansen's Soda is an "All Natural Soda" then why does it contain no real fruit juice?
BigC
20
Years of Service
User Offline
Joined: 17th Apr 2004
Location:
Posted: 24th Apr 2004 00:57
this code wont work

whatup
BigC
20
Years of Service
User Offline
Joined: 17th Apr 2004
Location:
Posted: 24th Apr 2004 01:17
nvm i did something stupid

whatup
Computer Geek
19
Years of Service
User Offline
Joined: 28th Apr 2004
Location:
Posted: 28th Apr 2004 18:45
Hey,
I probably would have liked this tutorial a while back but I have already spent a bunch of time on my space shooter game. I have one question however. How can you display the score, level, or lives with sprites? I can't figure out how to change from a number to a string or vice versa. If I could do that then I could use the string and convert them to numbers.
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 29th Apr 2004 18:34 Edited at: 29th Apr 2004 18:34
if you want to convert a number to a string just use
and to convert a string to a number use



Formerly known as "DarkWing Duck"
hoopsdraw
20
Years of Service
User Offline
Joined: 25th Nov 2003
Location: Dallas, TX
Posted: 13th May 2004 00:47
Reaperman,


Fantastic tutorial. Thank you for taking the time to do it to teach us newbies!

Question for you, how to you write the code so that when you hold the direction arrow you get a smooth, instead of a jittery, movement? Right now if you hold the up or down arrow down (instead of just tapping them), the ship looks jittery. In a game like Galaga, when you hold down the button to move the ship left or right, it is very smooth. How do you get that same effect using DarkBasic? Thank you for your help!
Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 13th May 2004 16:32 Edited at: 13th May 2004 16:33
Quote: "Question for you, how to you write the code so that when you hold the direction arrow you get a smooth, instead of a jittery, movement? Right now if you hold the up or down arrow down (instead of just tapping them), the ship looks jittery. In a game like Galaga, when you hold down the button to move the ship left or right, it is very smooth. How do you get that same effect using DarkBasic?"


Glad it helped you Hoopsdraw.

All you have to do to get it to move smooth is to change these:
"dec ysy,10" & "inc ysy,10"
To:
"dec ysy" & "inc ysy"

This will slow down the ship but will make it move just 1 pixel at a time. The other way was moving it 10 pixels at a time. You can experiment with different values (like putting a 5 instead of a 10).

Also.....You can change the sync rate of the game.

It is set to sync rate 30 within the game, but you can change it to anything you like...

Using a combination of these will give you a smoother looking ship and speed.
hoopsdraw
20
Years of Service
User Offline
Joined: 25th Nov 2003
Location: Dallas, TX
Posted: 13th May 2004 18:29
Reaperman,

Thank you for taking the time to answer my question!
lokatsis
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location: greece
Posted: 13th May 2004 21:08
hi reaperman ,
i'd like to ask you something, if i want in the game to use many alienships
to fight (20,30 or more)what should i do? i think that it needs varabies or dim commands as i have saw in other tutorials that
have many enemies but i cannot understant how it works, can you help me?

THE AOOS
2D Analyst
AGK Developer
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 14th May 2004 00:26 Edited at: 14th May 2004 00:28
My question is similiar to lokatsis, "how would you display multiples enemies?" I used a for loop to display. This code does display the enemy, but it's not being display as a sprite. So, how would I display all the enemy as a sprite?

for row=100 to 400 step 50
for spr=10 to 18:for ax=50 to 800 step 100
sprite spr,ax,row,4
paste sprite spr,ax,row
next spr:next ax
next row

eatfishy
Reaperman
20
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Kent, England
Posted: 16th May 2004 18:32 Edited at: 16th May 2004 18:35
Quote: "Lokatsis:
hi reaperman ,i'd like to ask you something, if i want in the game to use many alienships to fight (20,30 or more)what should i do? i think that it needs varabies or dim commands as i have saw in other tutorials that have many enemies but i cannot understant how it works, can you help me?"


Using a Dim command is very helpful in some (not all) games, as you can easily store the position, size, colour, properties etc etc etc of your sprites. it’s a bit like cross-referencing a table that you have set up to store the variables…But I cannot help you much unless you can show me the program. You see Lokatsis, sometimes you can get away with a lot less sprites if you have designed your level well. Think of some of the arcade games you have played. Most of them don’t use any more that 250 sprites (that’s everything) while some use only 5 or 6.…. It depends on the style of game. Post your program or a section of it and I will try and help you with it.

Quote: "Eatfishy:
My question is similiar to lokatsis, "how would you display multiples enemies?" I used a for loop to display. This code does display the enemy, but it's not being display as a sprite. So, how would I display all the enemy as a sprite?"


Its because you were putting a sprite on screen and then pasting it. When you paste a sprite you are basically making a graphic of the sprite. Your not making a new sprite…just a graphic representation of it.
The only sprite you have is the last one in your loop…all the rest are pictures of it.

Try this code to get them all to be sprites.

load image "spaceinvader.bmp",1 <<<<Use any graphic you want here
spr=1
x=50:y=50
for dp=1 to 5
for le=1 to 10
sprite spr,x,y,1
inc spr
inc x,20
sync
next le
x=50:inc y,20
next dp
fog
20
Years of Service
User Offline
Joined: 5th Oct 2003
Location: Newcastle, England
Posted: 16th May 2004 20:46
Hi,
Nice idea Reaperman......always good to see the art of 2D gaming alive and well. Just a couple of things.....

@Eatfishy
What Reaperman says is true but your "NEXT spr" and "NEXT ax" commands are also the wrong way around.

@Reaperman
I think that SYNC in the middle of your for/next loop is a mistake


The best piece of advice I could give to anyone serious about making a shoot-em-up, or just about anything else for that matter, is use arrays. I'd never advise anyone, even beginners, to use a fixed range of numbers for sprites etc. even if you only have a few of them.

Angel Eyes
19
Years of Service
User Offline
Joined: 16th May 2004
Location:
Posted: 17th May 2004 02:05 Edited at: 17th May 2004 15:58
! ooops..wrong post!
2D Analyst
AGK Developer
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 17th May 2004 06:44
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.

eatfishy
Dragon3
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 17th May 2004 16:01
Hiya ^_^

Dads away at the mo so I will answer this for him.

Quote: "
@Reaperman
I think that SYNC in the middle of your for/next loop is a mistake
"


Yep it was But he only had a min to write the thing so hey, I forgive him!

Quote: "The best piece of advice I could give to anyone serious about making a shoot-em-up, or just about anything else for that matter, is use arrays. I'd never advise anyone, even beginners, to use a fixed range of numbers for sprites etc. even if you only have a few of them."


Wwwwweeeeeelllllllll..... I think that my Dad is doing these to help toal beginners, so he wants to keep it simple. I understand how to use Dims but not everyone does. Sides, they are not always great to use if your only dealing with 4 for 5 sprites. Too much messing about, and he wanted to keep it simple ya know


CU

Dragon 3

FF4EVA
fog
20
Years of Service
User Offline
Joined: 5th Oct 2003
Location: Newcastle, England
Posted: 17th May 2004 20:33
Hi Dragon 3,

Quote: "
Yep it was But he only had a min to write the thing so hey, I forgive him!
"

I appreciate that. I was just pointing it out so that others don't copy it......as you said yourself this is for complete beginners


Quote: "
Wwwwweeeeeelllllllll..... I think that my Dad is doing these to help toal beginners, so he wants to keep it simple.
"

Yep, as I said earlier it's a great idea and it's good to see people helping others. Especially as there are a lot more people in need of help than those willing to offer it.


Quote: "
I understand how to use Dims but not everyone does. Sides, they are not always great to use if your only dealing with 4 for 5 sprites. Too much messing about, and he wanted to keep it simple ya know
"

Well I see your point but I'd argue everyone should know the basics of arrays before attempting any sort of basic game. Also anyone that uses arrays will agree it actually makes coding easier and not harder.

Anyway as I said it's a nice tut and I was only offering an opinion

lokatsis
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location: greece
Posted: 18th May 2004 21:15
this is the code:

sync on
sync rate 30
color backdrop 0
hide mouse
load music "rainbow.mp3",1
loop music 1
load image "yourship2.bmp",1
load image "alienship2.bmp",2
load image "orb.bmp",3
load image "greenlazer2.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 "bluestars.bmp",50
load image "title.bmp",9999
LOAD SOUND "phaser03.wav",1
LOAD SOUND "boom2.wav",2
make object plain 4,400,56
scale object 4,195,950,0
position object 4,0,-40,350
TEXTURE OBJECT 4,50
lock object on 4
ghost object on 4
color backdrop rgb(0,0,0)
pf=0:score=0:Level=1:lives=3
ysx=290:ysy=420
sprite 1,ysx,ysy,1
lx=SPRITE X(1)+20
ly=SPRITE Y(1)+10
ax=300
ay=100
sprite 3,ax,ay,2
sprite 9999,10,10,9999
down = 1

do
ay=ay+3

if up = 1
dec ax,10
if ax <= 50 then down = 1 : up = 0
endif


if down = 1
inc ax,10
if ax >= 450 then up = 1 : down = 0
endif
sprite 3,ax,ay,2


set cursor 200,00: Print "Â�ÈÌ�Ë�ÃÉ�:";score; " Å�É�ÅÄ�:";level;" ÆÙÅÓ:";lives
if leftKEY()=1 and ysx>60
dec ysx,10
endif
if rightKEY()=1 and ysx<530
inc ysx,10
endif
if inkey$()="z" and pf=0 then gosub shoot:pf=1
if sprite hit(1,3)=1 then gosub blowitup2:lives=lives-1

if SPRITE EXIST(2)=1
if SPRITE EXIST(1)=1
if SPRITE HIT(2,3)=1 then gosub blowitup

endif
endif
sprite 1,ysx,ysy,1
gosub moveall
gosub movestars
sync
loop
movestars:
SCROLL OBJECT TEXTURE 4,0.0,-0.03
return
shoot:
if SPRITE EXIST(2)=1
show sprite 2
endif
sprite 2,lx,ly,4
PLAY SOUND 1
return
moveall:
if SPRITE EXIST(2)=1
If sprite y(2)>(-35)
ly=ly-45
sprite 2,lx,ly,4
endif
endif
if SPRITE EXIST(2)=1
If sprite y(2)<(-35)
pf=0
hide sprite 2
lx=SPRITE X(1)+20
ly=SPRITE Y(1)-10
endif
endif
return
blowitup:
delete sprite 2
PLAY SOUND 2
for t=6 to 11
sprite 3,ax,ay,t
wait 1
next t
delete sprite 3
end
return

blowitup2:
delete sprite 1
PLAY SOUND 2
for t=6 to 11
sprite 1,ysx,ysy,t
wait 1
next t
delete sprite 3
return

this code has only one enemy sprite but i want to multiply them,
so to coming more and more
but i need to use a little piece of code for all the enemy sprites.
in other words i want with the same code to have the same properties not only in movement but also when i shoot them. you see
if i duplicate the code for each sprite my program will gonna be a mess. so, i think that the solution is to use dim, varables or arrays
but i dont know how to use them right. thats where i need your help.

THE AOOS
UnderLord
20
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 18th May 2004 23:18
i need scrolling code for scrolling in every direction i have no idea how to get it started =\ shooting code too but i think i know how to do that

The search continues.

Current project - A space game
lokatsis
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location: greece
Posted: 20th May 2004 22:27
this is the code:



this code has only one enemy sprite but i want to multiply them,
so to coming more and more
but i need to use a little piece of code for all the enemy sprites.
in other words i want with the same code to have the same properties not only in movement but also when i shoot them. you see
if i duplicate the code for each sprite my program will gonna be a mess. so, i think that the solution is to use dim, varables or arrays
but i dont know how to use them right. thats where i need your help.

THE AOOS
UnderLord
20
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 21st May 2004 05:47
i thought for-next might fix the problem without dim or arrays but i think it might be best if you used a dim read up on them if your using DBP its easy in the beginning part of the booklet i think it has away to store like a way to print a message 52 times in one or two lines of code can be used for sprites i think but im not sure =\ hehe just an idea...

The search continues.

Current project - A space game
Plastico
19
Years of Service
User Offline
Joined: 3rd May 2004
Location:
Posted: 2nd Jun 2004 17:53
will this tutorial help with DBpro?
ghost
19
Years of Service
User Offline
Joined: 12th Jun 2004
Location: you tell me
Posted: 13th Jun 2004 06:15
it doesnt work for me it thinks one of the objects is a music file?

Login to post a reply

Server time is: 2024-04-25 22:21:34
Your offset time is: 2024-04-25 22:21:34