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 and guidance needed a the start

Author
Message
Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 21st Mar 2004 23:15
Hi all

Ive just got hold of dbc and working through all the tutorials but need a little help.

I thought id start off trying to do a simple point and shoot arcade game. ie stationary background with enemies pooping up which you shoot via crosshairs with the mouse. so..

1. how do i go about setting up the enemies and their animation. I presume the will be on one tiled bmp or png?

2. how do i know if the cross hairs are over the enemy (especially if some of them are animated?

3. what would you say is the best way to control the order the enemy appears (some sort of data string ie x,y . enemy type. level)

4. are there any global settings i need to worry about? ie sync?

5. theres hundreds more questions i could ask but answers to these will get me kick started.

many thanks in advance

Morloc

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Mar 2004 23:36 Edited at: 21st Mar 2004 23:38
Quote: "1. how do i go about setting up the enemies and their animation. I presume the will be on one tiled bmp or png?

2. how do i know if the cross hairs are over the enemy (especially if some of them are animated?

3. what would you say is the best way to control the order the enemy appears (some sort of data string ie x,y . enemy type. level)

4. are there any global settings i need to worry about? ie sync?

5. theres hundreds more questions i could ask but answers to these will get me kick started.
"



1/ Just....... load bitmap "Background.bmp",1
Then....... Load Image "Sprite1.bmp",1 .........2,3,4,5,6 etc.
Use the image numbers on the end of the sprite numbers.
Position them with the x/y positions.

2/ You make a sprite that is just 1 pixel in size, and you move it with the mouse x/y coordinates. You make another crosshair sprite, and move that the same way. You need to offset the sprites, to position them from their centre. Offset sprite Sprite Width /2, Sprite Height /2. You check for collision with the single pixel.

3/ Use the Timer() to time their appearance, but use some random timing.

T = Timer() + rnd(8000)
Do
If T <= Timer()
show sprite ? or make it run on the screen..whatever.
T = Timer() + rnd(8000)
endif
Loop

4/ If you put Sync on at the beginning of your code, you need Sync at the end of the Do Loop. This is better than using Sync Off.

5/ OK


Pincho.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 22nd Mar 2004 00:13
Hi Pincho

thanks for the quick reply. I think i understand what youre saying but it now raises a few more questions.

re:1. I understand loading each sprite in ie 1,2,3.. if the enemy was animated with say 5 sprites (moving up from behind something) how do i get it to animate do i just set up a loop to place then replace with next frame) if thats the case how do i control speed etc. (apologies if this is wrong)

2: i understand the single pixel crosshair with the added actual crosshair but i dont understand the offsetting. Do mean like an invisable hit box area? would this move with the enemy popping up?

3: good point about the timer. I presume like you say it to then decide what enemy to display and where (which could be taken from a data string.

thanks again

Morloc

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Mar 2004 00:50
Quote: "re:1. I understand loading each sprite in ie 1,2,3.. if the enemy was animated with say 5 sprites (moving up from behind something) how do i get it to animate do i just set up a loop to place then replace with next frame) if thats the case how do i control speed etc. (apologies if this is wrong)

2: i understand the single pixel crosshair with the added actual crosshair but i dont understand the offsetting. Do mean like an invisable hit box area? would this move with the enemy popping up?

3: good point about the timer. I presume like you say it to then decide what enemy to display and where (which could be taken from a data string.
"



1/ You have to be careful about this. If your people move up from behind a rock, and the rock is part of their animation, then the rock will register a hit when you shoot it. This means that your people will be shot even if you hit the rock. If there are 3 people, they all die if any of them is hit. What you need to do is create images of each person as an individual, and without the rock. Then draw the rock, and load it seperately. If the people animate (Moving upwards is not an animation, you could just move the sprite up.) if they point guns at you, then you just change the image number at the end of the sprite command....

Sprite 1,x,y,frame
inc frame
if frame = lastframe then frame = 1.

2/ Sprite x/y is taken from the top left corner of the image. That's no good for a crosshair. A crosshair works from the centre of the image.

3/ It could be taken from a rnd(). Or whatever you want. Don't think Data is much good for this example.

Pincho.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 22nd Mar 2004 01:08
many thanks again.

Ive been reading alot of post re sprites/ animation etc and think im at the stage where i need to just start coding. If i get a real basic code done in the next few days hopefully it will show up some further problems.

btw is there a hard copy of the index of commands and what they do?

I find it easier to read and take in when its hard copy, plus i can read it anywhere then

Morloc

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Mar 2004 01:24
Well don't tell people that you don't have a manual, else they will get suspicious. Anyway, there is the help menu. Also you can type in a command and press F1 to see how it works, but this doesn't work with Dark Edit.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 22nd Mar 2004 01:34
ive got the little user manual but that doesnt break things down like the online index. I was given it by a friend and as far as i know he gave me evrrything. should there have been another manual as if thats the case i will pester him as i bought it off him. :E

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Mar 2004 01:41
Well the F1 key combined with the manual, will give you everything, including a demo of every command used in a program.

Scouseknight
21
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 23rd Mar 2004 02:10
I find the help to be a little lacking to be honest - but then these forums more than make up for that

Seriously though the help is functional at best - the showcase examples are so generic they are unreal - the same example covering several items - it's okay if you have an idea where to look or just need a refresher on what parameters a command takes but as for explaining to someone who is new what something does in a way that can be fully understood, then it's falling short of the mark - at least, it was for me.

No disrespect intended to the makers of DarkBasic as the language itself I am exrememely pleased with.
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Mar 2004 14:16
I think the helps great! I learned most of the language from that in a couple of days. I wrote a quick flight sim almost as soon as I loaded DB for the first time, but I did edit one of the help files to make it.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 23rd Mar 2004 16:14
re: the animation of the sprites. hopefully you get the idea of wat im trying to do by now ie a shooting gallery. do you think i could get all of the "enemies" animating in one loop(like you said in the other thread) and then hide the sprites and use some sort of number sequence to display them? would this work. obviously for collison i would have a flag so that it wouldnt check if a particular sprite wasnt currently being shown .

Morloc

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Mar 2004 17:17
You only need to change the image number to display different frames of an animation. You still use the same sprite.

sprite 1,50,50,frame
inc frame
if frame = 6 then frame = 1


If you are only showing 1 sprite at a time you can just use this sprite for all of the enemies. If you show 2 sprites at the same time you only need two sprites etc.

You can move a sprite off the screen to prevent collision problems.
x = 1000

Then you can change its image to a different enemy, and put it back on the screen in a different place.

It looks like you have lots of sprites, but it is just 1 or 2 sprites, with differnt images, and they are being moved all over the place.

Pincho.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 23rd Mar 2004 17:23
thanks Pincho

I reckon i could pick your brains all day Im beginning to understand the sprite/animation side of things.

If i didnt want the sprites to appear in a random order, but in a set order and in set locations what would you suggest from experience in being the best way to set up these patterns.?

Morly

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Mar 2004 17:43
To set up 6 different enemies you could


Frame = 1

for Enemy = rnd(6)



If Enemy = 1 then Numberofframes = 5 : x = 50 : y = 50 : Framestart = 20
If Enemy = 2 then NumberOfFrames = 9 : x = 20 : y = 100 : Framestart = 10

etc

sprite 1,x,y,framestart + frame

inc frame

if frame = NumberofFrames + 1 then frame = 1

Everything seems easy to follow apart from Framestart which is the number of your first image stored with Load Image.

Load Image "Enemy9Frame1" , 48
Load Image "Enemy9Frame2" , 49
Load Image "Enemy9Frame3" , 50
Load Image "Enemy9Frame4" , 51
Load Image "Enemy9Frame5" , 52

So framestart = 48 for Enemy 9

Pincho.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 23rd Mar 2004 18:33
good explanation. I totally understand that.

Can DBC handle different layers? ie background, sprite, sprite(ie fog/rain) over one another. what dictates their order over each other.

similar if say i wanted an animated background with the skyline cut out and a cloudy sky slowly scrolling behind it?

I hope you dont mind me asking these questions but I like to get as much info straight in my head before i get down to the hard coding.

Morly

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Mar 2004 21:57 Edited at: 23rd Mar 2004 22:00
Hmm you are getting close to a 3D game with those extra options. Those things are easy to do in 3D, but sprites for everthing can be slow. You could have a few clouds, rain might slow your game. The best way to do rain in 2D might be to have 5 or more different backgrounds with a rain animation on them. So that the rain just moves 5 pixels before it loops back to the beginning. You would paste this as an Image, and not use it as a sprite. It could be just a 4 colour image that you paste over an existing background. 4 colour images are faster to paste. You have to make sure that you save them as 4 colour images.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 24th Mar 2004 11:12
hmm i dont really want to get involved in 3d atm.I think i will just animate the background ie have say 8 background that animated after each sync frame by frame.

As for sprites. if i place a sprite say 1 and then another 2 and they over lap , which one will be on top?

also the term "paste" can you explain this a little please

thanks

Morloc

Morloc
Code Stealer
21
Years of Service
User Offline
Joined: 12th Feb 2004
Location:
Posted: 24th Mar 2004 11:42
use set "sprite priority" to say which is on top. The higher the number the later its drawn. I dont think there is a limit to the number you can use either. Im using a priority of 10000 for my cursor in the program Im working on. Ill never have 1000 sprites drawing, but it means that I have more numbers to play with!

GIve me more power!
Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 24th Mar 2004 14:43
thanks

I'll look into that. Im just trying to get a feel of what you can and cant do. So with that all out the way the coding begins.

thanks again to all

Morloc

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 24th Mar 2004 17:26
DBC doesn't have set sprite priority. I think it draws them in order, with the last sprite drawn on top of the others.

Paste image means that the image becomes part of the screen, and is glued on it, you can't move it. It's fast.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 29th Mar 2004 15:35
Hi Pincho

Ive started to look at the code atlast. Ive taken what youve said but seem to get problesm



it doesnt seem to increment the frames and my cursor sprite is now stuck (it was moving with the mouse)

i did notive that the start point for the frames isnt quite right as it increments straight away but i can probably sort this bit out

any ideas?

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 29th Mar 2004 15:55
do
frame = 1..............should not be reset every loop.
sync.......You have two of these, you only need 1 in DB. I like them at the end.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 29th Mar 2004 15:56
ive just sorted it. I had the initial frame value inside the loop so it was always reseting.

Now ive got something work ive got the problem of speed . the frames loop way to fast. Ive put a wait 30 command in there but is there another way to slow things down but still keep a smooth flow to things?

Morloc
Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 29th Mar 2004 16:06
lol thanks Pincho

you posted 1 sec before me. Ive also sorted the speed issue out by putting another increment in the loop. works much better than a wait.

thanks

Morloc

Morloc
Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 11th Apr 2004 02:30
i have a slight problem and its late and i cant get my brain around it at them moment. I find it helps if i post what im trying to do and sometimes i end up answering my own question.

anyway, im trying to work out how to display more than one enemy at the same time. The actually enemy code isnt a problem but it the frames trigger. if i have say three enemies but all have different frame lengths how do monitor these lengths and tell the loop not to display an enemy if its already showing. heres my code at the moment:
I like the enemy gosubs and enmy code as it works well. Im not sure if its worth making them functions that way i could in theory have just one bi of code to do multiple enemies. The two i have at the moment are a stationary one and a flying one.

any suggestions welcome

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Apr 2004 03:00
Maybe you have never used DIM before.


Dim EnemyFrame(10)......Anim Frame Number
Dim EnemyPos(10,2)....X/Y

EnemyFrame(1) = EnemyFrame(1) + 1 .....Inc the animframe for enemy 1

EnemyPos(1,1) = 50...............Enemy1 X = 50
EnemyPos(1,2) = 50...............Enemy1 Y = 50


When you have lots of anything you can use DIM to make more than 1. You use it the same as any other variable...ie X..Y...Animframe
But you put a number in brackets to show which enemy you mean. Sometimes you put two numbers in brackets, and the second number means change its X or its Y or anything else you want to change.

DIM is short for Dimension, and it means change more than 1 object.

DIM Map(50,50)..You might have seen this before. 50X,50Y are map coordinates. You can use DIM for lots of things.

Pincho.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 11th Apr 2004 03:10
hiya i have looked at dims but like you said ive not really used them before (not for a long long time)

I think im gona have a tinker with the code and get it straight in my head 1st. Do you think its worth having say 10 enemies looping off screen and when they need to be displayed just reset their frame to beginning and move them onto screen? at least i dont need to stop and start them all the time?

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Apr 2004 03:36
I think it's worth doing that. Hopefully, sprites offscreen don't take much speed away from the computer. But if they do, you will need to do what I said before, and when you shoot an enemy you move it offscreen, then change it's image for a new enemy, and put it back onscreen again. So now you don't make 10 sprites, you just make about 2 of them, and keep using those two sprites for all of the enemy. I mean for your game you need to think how big the enemy are, and if they are popping up behind rocks then they are probably quite big. Space shooters use small images, so you could use 10 in DBClassic, but no more. Sprites are slow, and I hardly ever use more than 3. I know lots of other ways to avoid sprites, but then you have to do more coding.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 11th Apr 2004 14:02
i think i would have atleast 3 or more enemies on screen at once and each may have about 7 frames of animation. What alternatives are there than sprites?

Also re: the dim I presume i could have a 3d array ie dim enemies (10,7,5) if i wanted to have say 5 stages to the game.

I still havent really got my head around handly different frames per sync as some enemies will be displayed at staggered intervals. I presume im gonna need seperate frame variables for each enemy and inc /dec them on mass (if you know what i mean).

Oh and Happy Easter to all btw

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Apr 2004 18:22
Quote: "i think i would have atleast 3 or more enemies on screen at once and each may have about 7 frames of animation. What alternatives are there than sprites?

Also re: the dim I presume i could have a 3d array ie dim enemies (10,7,5) if i wanted to have say 5 stages to the game.

I still havent really got my head around handly different frames per sync as some enemies will be displayed at staggered intervals. I presume im gonna need seperate frame variables for each enemy and inc /dec them on mass (if you know what i mean).
"


3 enemies on screen at once means just 3 sprites needed for your game.

5 stages in the game has nothing to do with DIM, you don't need seperate variables for 5 stages, just overwrite the old numbers with new numbers.

Different staggered stages of animation are covered in my previous example with EnemyFrame(10).

EnemyFrame(1) = 5
EnemyFrame(2) = 2
Enemyframe(3) = 7

So Enemy 1 is on frame 5 of his animation.
Enemy 2 is on frame 2 of his animation
Enemy 3 is on frame 7 of his animation.

EnemyFrame(1) = EnemyFrame(1) + 1

Now enemy 1 is on frame 6 of his animation

If EnemyFrame(1) = 6 then EnemyFrame(1) = 1

Now enemy 1 has looped back to the beginning of his animation.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 12th Apr 2004 02:28
ok i understand the dims and setting different frames etc.

The problem i just cant seem to think around at the moment is this:

If for example i have a variable enemy=rnd(10)

if enemy = 4 then gosub enemy4 code.

thing is once its looped enemy may not be equal to 4 so it wont loop that code so youll only see once frame of code. (i hope this makes sense)

So what im trying to say is how to

1) pick the running order of enemies appearance (data string?)

and once an enemy begins to run keeping ti running until its finished its frames oe pop up and then pop back.

Im sure ill get it eventually but atm im struggle (prolly too much chocolate )
Morly

Morloc
Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 12th Apr 2004 02:46 Edited at: 12th Apr 2004 02:47
as usual i think having a dim for enemy alive, dead or dying will work. see code


solve one problem get another. after the animation reaches 7th frame (or whatever its max frame is) id like it to reverse. (dont want to double up on loaded images)
at the moment it just dies once it reaches frame 7.

so i need some way to inc frames upto 7 then dec back to 0 .

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Apr 2004 03:08
If forward(1) = 1 and enemyalive(1) = 1
enemyframe(1) = enemyframe(1) + 1
else
enemyframe(1) = enemyframe(1) - 1
endif

if enemyframe(1) = 7 then forward(1) = 0
if enemyframe(1) = 0 then enemyframe(1) = 1: forward(1) = 1

You can do this in a for next loop..

For n = 1 to 10



next n


Then replace all of the 1's with n's

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 12th Apr 2004 03:41
hiya thanks for the reply.

Ive been doing something very similar. it seems to work all ive got to do now is to kill off the enemy when it reaches frame 0 again

Morloc
Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 12th Apr 2004 04:44 Edited at: 13th Apr 2004 22:52
very late so im gonna end with 2 weird problems


the 1st is that ive just temporarily set up so button 3 on the mouse triggers the enemy. problem is that sometimes it displays sprites b4 the initial start sprite (cant see why)

2nd is that the enemy appears in front of the crosshair even though the sprite is loaded after the enemey sprite (this was working b4)

besides that the next loops work fine so i can display 10 enemies when ever i want to -thanks pincho

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Apr 2004 13:43
Quote: "problem is that sometimes it displays sprites b4 the initial start sprite (cant see why)
"


Do you set enemyframe(b) back to the beginning when a enemy is killed?

Quote: "2nd is that the enemy appears in front of the crosshair even though the sprite is loaded after the enemey sprite (this was working b4)
"


Well, I can't find that problem, I don't know the crosshair number or anything. Just experiment until you find the bug.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 12th Apr 2004 19:36
ive found the sprite error. using your example code to explain :

If forward(1) = 1 and enemyalive(1) = 1
enemyframe(1) = enemyframe(1) + 1
else
enemyframe(1) = enemyframe(1) - 1
endif

if the enemy isnt alive then it stil decrements his frame (does a countdown into minus figures)

so it needed to be: if enemyalive(n) = alive then enemyframe(n) = enemyframe(n) - 1 ...which works fine.

still cant get the crosshairs sprite to be on top but as you say it just a case of trial and error.

thanks again pincho.. gonna have to start repaying these favours

Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Apr 2004 20:09
Yeah I can see that error now. Actually I hardly ever use else. I think that when you post an example, you try to save typing by doing something slightly different than you would normally do it.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 12th Apr 2004 23:26
sorted out the crosshair problem. because the enemy may or may not appear straight away it ment that the crosshair sprite was already on screen and so ended up behind.

the quick solution is to preplace all enemy sprite off screen ready to be used

thought id just let you know.


Morloc
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Apr 2004 23:33
Hey that games looking pretty good! I didn't know you could draw the graphics so well.

Morloc
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location: UK
Posted: 13th Apr 2004 00:51
thanks. Its so hard not get carried away with the graphics and neglect the code. especially for me as I do alot of Gfx design etc for my job.

Atleast ive got the skeleton of the code done now so its a case of tweaking etc.

I must admit is my only worry is speed. i noticed that when the bat flies across the screen and the other enemy appears it slightly slows a little. something i might have to keep an eye on.

Morloc

Login to post a reply

Server time is: 2025-08-09 02:12:41
Your offset time is: 2025-08-09 02:12:41