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! / Urgent: Making a Platform game Step by Step , ala Super Mario Bros. 1

Author
Message
Dextro
21
Years of Service
User Offline
Joined: 26th Feb 2005
Location:
Posted: 10th Mar 2005 02:04 Edited at: 10th Mar 2005 02:06
Hi.
Im new to the forums, and it has come to my attention that most of the tutorials presented in the forums, are quite vague, in the sense that they only show the algorithm and sometimes, code that only the author can understand.
What I feel that is needed, is a complete tutorial, focused on newbies, step by step on making a 2d platform game.
One good example would be a remake of Super Mario Bros. 1, keeping it simple.
The layout for such a tutorial should cover not the principles, but the "techniques", fully expalined for the new programmer.
For example:
1- How do I make maps? (data statements explained, with some basic code (fully explained) on how to load it, and how to scroll it. And remember, keep it simple)
2- How do I detect if my sprite has collided with a tile? (expalin some techniques used, the most common, the easiest, and the most understandable. If using the "multiple layers" approach, explain the very basics of it (what it is, how it works, how can i make it work, and of course basic code, fully commented and understandable for tne newbie programmer), and remember, KEEP it Simple.

You get the idea.
The thing is, lets keep all in just one thread.
What do you think?
So if anyone
zy_to ge_ry
21
Years of Service
User Offline
Joined: 20th Nov 2004
Location: Canada
Posted: 10th Mar 2005 11:20
Well, I'm new to this as well, and agree this kind of a topic would help alot, especially since the tutorial that was supposed to cover this hasn't been updated in months.

Here is a program I made for making 2D scrolling maps. First you make the bitmaps of 32 bit tiles in paint, use the get image command to put them into memory. If you know anything about for loops, then it should be easy to understand what to do, if not, see the "walking sprite tutorial" included in darkbasic. Anyway, when you exe the program, "from the editor ussually", just input the text to set up the map, then use the mouse to paint the tiles onto the screen and into memblocks. To change images, you hit the spacekey, input the image number, then hit enter. Then, when you're done, you hit the numpad '1' to save it to the previously specified filename, then hit q to exit.

The actual code may be hard to understand if you are new, but the program itself works quite well.
Dextro
21
Years of Service
User Offline
Joined: 26th Feb 2005
Location:
Posted: 10th Mar 2005 12:43
It would be nice to see the code
I have a similar code, but i have to keep the backgrounds in 16 colors (not 16 bit) so i dont overload the cpu.
Any ideas?
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 15th Mar 2005 11:56 Edited at: 21st Mar 2005 20:42
I agree that the forums don't always cover the details of 2D game design. I am currently developing a 2D game. Although my game is not complete, I would like to share some of my technics employed so far.

Some of my example source might seem trival to some, but I hope it will be useful to those of you that are new to DarkBASIC Professional. Keep in mind that the game is not finished and there will probably be many revisions before its final. Constructive criticism is welcome. If you have a better way of doing something, please post it here.

Dextro, I know you wanted to cover topics involving side scrolling, but I figured that I would start with basic character control. The first three levels of my game only use a static background. I don't have side scrolling in use yet.

The source code I provided here is only a part of my current game code. It controls my game charcter via keyboard. The controls will be later modified so they can be user definable, otherwise they will remain pretty much the same.

sync rate = 80
display mode = 1024x768x32
current image size per frame= 192x256
set sprite 1,0,1 (backsave state off, transparency on)

Variables that are used in this subroutine:

frame = sprite images for animation (1-30 walk, 31-70 idle, 71+ misc.)
x = x position of sprite
y = y position of sprite
aflag = sprite mirror flag for movement right or left (default = 1)

lockout = flag that toggles character control and update on/off
jump = flag that locks controls until character finishes jumping
slide = flag that locks controls until character finishes sliding

The last three variables lockout, jump, and slide are very important. These variables are used in conjuction with a collision handling subroutine. Jump and slide are used to determine what to do as a result of a collision with another sprite. This gives you a wider range of possibilites for collision results. Lockout is used to temporarily disable the controls and let an alternate animation sequence happen with sprite #1 as a result of a collision.

Example Logic For collision:

if jump=0 and slide=0 then collision_result(1):rem walking
if jump=1 then collision_result(2):rem jumping
if slide=1 then collision_result(3):rem sliding

Note: The above code is only and example of a possible collision logic. You would obviously need to check for actual sprite collision first. (e.i. If sprite collision(1,sprite number)>0)

In order for someone to use the source code that I have provided, they would need the images for the sprite and define the above variables. I am not going to provide the images as of yet. I might do so later when I have more of the game finished. You must supply your own images. You can use less images in the subroutine, but just make sure that you modify the CASE Statements accordingly.

I will post more of my code after some feedback.

Type the following into the editor and then paste the subroutine after it. You will have to make the images and image loader routine yourself.
Oh, I almost forgot about the sound. This example uses sound. If you have no sounds to load, just delete all PLAY SOUND commands in the sub.

sync on:sync rate 80

disable escapekey
set display mode 1024,768,32
hide mouse

Rem Your Image Loader Routine Goes Here
Rem Optional Sound Loading Goes Here

Rem Initialize Variables

frame=1
x=416
y-512
aflag=1
lockout=0
jump=0
slide=0

Rem Main Program Loop

repeat

cls
gosub character_controls

until escapekey()=1
end

Rem My Subroutine Goes Here
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 2nd Apr 2005 13:22 Edited at: 2nd Apr 2005 13:23
Gee, don't everyone respond all at once! I thought there would be some kind of activity here. I hope this thread doesn't die.
They Killed Kenny
21
Years of Service
User Offline
Joined: 18th Jul 2004
Location: FL, USA
Posted: 3rd Apr 2005 05:20
Hm... maybe you should post it with the
tags so it wll be easier to read... and I hope it doesnt Die either... that would suck, since I'm Thinking of making a Platformer :/

Stan: OH MY GOD! THEY KILLED KENNY
Stan's Grandpa: You Bastards!
Kyle: HEY! ><
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 5th Apr 2005 05:07 Edited at: 5th Apr 2005 05:43
Rem Setup Program
sync on:sync rate 80

disable escapekey
set display mode 1024,768,32
hide mouse
cls

Rem Image And Sound Loaders Here

set sprite 1,0,1

Rem Initialize Game Variables
x=416
y=512
aflag=1
lockout=0
jump=0
slide=0
frame=1

Rem Main Game Loop
repeat

cls
gosub character_controls
sync

until spacekey()=1
end



Does this help?
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 6th Apr 2005 09:30 Edited at: 6th Apr 2005 09:36
I decided to post another code snippet from my game. I made a function that creates the static 2D backgrounds for the first 3 levels of my game. I employed a gradient style shading technic to give the scene a more 3D appearance. The function is called before my main game loop. The code is fairly simple and shouldn't be hard for anyone to understand.

The function basically checks to see what level the game is on and draws the scene with 3 walls, a floor, and up to 3 shelves across the top of the room; a shelf per level. I won't reveal what the shelves are used for right now.

Feel free to use and modify the code, but I ask you to please mention my name as the orginal author in your program.

Enjoy!

If you wish to add this to my code above, you must insert this function some where at the end. Make sure you put the function call before then main game loop.

Example:

Rem Setup Program
sync on:sync rate 80

disable escapekey
set display mode 1024,768,32
hide mouse
cls

Rem Media Loaders Here

Rem Intialize Game Variables Here
level=1:rem new variable (value of 3 max.)

Rem Create Scene Based On Level
makescene(level)

repeat

copy bitmap 1,0
gosub character_controls
sync

until escapekey()=1
end

Rem Character Control Subroutine

Rem Scene Maker Function

Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 6th Apr 2005 10:53
Is this based on using DARK basic Pro or classic or both? I currently have classic and am working on 2D games. I have a post above this thread but maybe you could include some things about it in this one. Also, what would be better to use for 2D games?

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
Tapewormz
23
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 6th Apr 2005 20:41
There's plenty of tutorials that show you how to scroll in all directions using a tile based system.

D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 7th Apr 2005 08:41 Edited at: 7th Apr 2005 10:51
Hey, Professor. I read your post about making a sprite character walk using keyboard controls. Did you look at my first message here about my character control subroutine?

I will try to explain how it works here a little bit. First, You will need multiple images to animate your sprites. While writing your game, think of movie film. There are many programs available to help you with the art. MS Paint is good for doing some of this, and it comes with the OS on your computer. Creating the images takes time and some expertise to pull off really good animation. You must keep in mind what you want the character to do while drawing the sequence of images (walk right, walk left, run, or jump, ect., ect.). If you are making the character do the actions mentioned above, you need to make one set of images each, and only in one direction because you can mirror the sprite in your code. I usually make my images right-handed, but left-handed will work too. Make sure you make each image the same size, unless that is part of your animation.

Secondly, now that you got your images, you need to get them into your game. There are a couple of ways to do this. You can load each image in separately, or you can use sprite sheets. I would recommend the later because it is not as messy. There are many examples here in the forums for using sprite sheets. I think DarkBASIC Classic has a sprite animation tutorial that uses this.

If you are testing your graphics, and you have individual images, you could do something like this:



The LOAD IMAGE command sees this:

walk_0001.bmp
walk_0002.bmp
walk_0003.bmp
ect.
ect.

If you are using DBC, get ride of the 1 at the end of the load image command. This lets DBPro use the image pixel perfectly and not as a texture.

This is an example from my temporary image loader from my game. It makes it easier for me to edit the animation sequences for my characters during game development. Later, I will turn them into sprite sheets.

Lastly, you need to setup your code to use your sprite animations. You will need to keep track of what images are used for what actions for game play.

1-30 Walking (right-handed)
31-70 Idle (facing game player)
15 Jumping (right-handed)

Check out my code snippet for character control. The character can jump, slide, look up, stand idle, and walk right or left. The animation is kind of like Mortal Kombat, Earth Worm Jim, and Super Mario Bros put together. I plan on having the main character do funny things if you leave him standing idle too long.

I suppose you could utilize my code above in either DBC or DBPro. As far as which would be better for 2D games, well, I guess its really up to you to decide what works better. Each one has their strengths and weaknesses. I orginally wrote my code snippets here in DBC and later I ported it to DBPro. My personal opinion is I would go with DBPro, its a current game engine.

Post any questions you may have here in this thread.
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 8th Apr 2005 06:32
Thanks, that makes it more understandable. But how do you make the animation actually happen?

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 8th Apr 2005 07:45 Edited at: 12th Apr 2005 11:29
To animate your sprite with the images, you will have to use the SPRITE SpriteNumber,Xpos,YPos,ImageNumber command.

Example:



Each time the FOR/NEXT loop is executed, the frame number is incremented from 1 to 10. Now you have animation!

This code works in either DBC or DBPro. There is a command in DBPro called PLAY SPRITE SpriteNumber,StartFrame,EndFrame,Delay that can be used to achieve the same purpose.

Does this explain how you animate a sprite?
They Killed Kenny
21
Years of Service
User Offline
Joined: 18th Jul 2004
Location: FL, USA
Posted: 8th Apr 2005 08:08
You could also make a sprite sheet, and put all the frames on one image. This way, it takes up less loading time. I used to have a snippet that taught how to do it (it involved the FOR...NEXT loop also). Somehow I lost the snippet. I will Try to re-create it and will even put some media up and the code. I may not be able to do much than animate it though, since I'm A total N00b, but everyone starts from somwhere right?

Stan: OH MY GOD! THEY KILLED KENNY
Stan's Grandpa: You Bastards!
Kyle: HEY! ><
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 8th Apr 2005 09:02
Thanks a lot, this is really helping. There is a small problem with moving sprites that i have found. Since to move the figure i have the background scroll, all the other sprites move to. I've tried subtracting from the xpos variable but it just doesn't work!

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 8th Apr 2005 09:17
I'm not quite following you on your problem with moving sprites, Professor. Are you using side scrolling? You will have to be more specific. Explain exactly what you are trying to do.
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 8th Apr 2005 10:12
What I have is the key input if leftkey()=1 then x=x+3 and if rightkey()=1 then x=x-3. This moves the background sprite right or left. So I guess it is a side scroller. Any ways, since the inputs move the background and not the player and other sprites, all of the sprites move along with the player. For example if the player is at x=50 and an AI is at x=100, when I press the right arrow they both increase by three. This is a problem because they could never collide or even stay in place!

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 9th Apr 2005 06:02
I figured out the problem. I have found a new one, however. How do you make program realise the 'a' key for instance is being pressed?

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 9th Apr 2005 06:20 Edited at: 9th Apr 2005 06:48
Okay, now your making more since. You are saying that you're trying to move the background with the keyboard controls and not the characters.

Alright, I would place the character in the center of the screen on both X and Y. Set the Limits for each axis to about one tile space from the edges of the screen. When your character tries to exceed those limits, hold character at that position, and update your tile array for your background. Make sure you don't exceed your tile array limits.

NOTE:I wouldn't use a sprite for the background. That's a real performance hit and your game will slow down. Use the PASTE IMAGE commmand with a tile matrix.

Example:



This code snippet is only a portion of the code needed, but it could be adapted to work.

I used X and Y for the character, XTILE and YTILE for the background tile array, and X_MAXIZE and Y_MAXSIZE for the total tile array size. FRAME IS used to animate your character sprite.

Your enemies would be set up in a similar manner, except you would actually let them go off the screen, when the tiles update or when they actually move. You would probably want to make and array to remember where they are on the tile map for when they come back into view.

The positions of the enemies update in the same direction of the scroll tile update with an offset which is the same as the tile size.
Your characters movement should be far less than the tile size offset.

Remember, if the enemy leaves the screen, store their last tile position and location within that tile in an array. If you happen to scroll back the other way, you can retrieve the position for re-display.

Obviously, there is more to it than this, but this should give you a better idea on the subject.

There are many ways of doing things, and this is only one way. If you want a more in depth look at a 2D Scroller Tutorial, I have a link for you to go to: http://forum.thegamecreators.com/?m=forum_view&t=45867&b=4
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 9th Apr 2005 07:23
To get other keys you can use:

Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 10th Apr 2005 01:17
Oh okay, thanks!

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 11th Apr 2005 01:38
Over the next few weeks my schedule will be a busy one, I may not get to post anything new, or answer any questions you may have. I will try to drop a line or two now and then, if I can. I think there is enough knowledgable people here on the forums that your questions can be answered (hopefully timely).

Once I get enough time, I would like to cover a really, really simple AI and collision for my game that's in development. I don't know if I should actually call it an AI, but more like a random action generator at this point.
Cryptoman
22
Years of Service
User Offline
Joined: 24th Nov 2003
Location: Utah Mountains
Posted: 12th Apr 2005 02:03
I'm releasing the source code to Stuper Plumber Bros. as I would like to see it finished by someone. Its my first project in DBPro(over 3 years ago) and only worked on it for a month. It was for a competition and I didn't make the deadline(lost the source). Havn't worked on it since, and its kinda messy. I have recently recovered the source off that hardrive.

Its in the download button.

Contact me on MSN if you would also like the media that was prepared for it.


Baggers
22
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 12th Apr 2005 07:26 Edited at: 12th Apr 2005 07:28
<edit> sorry missinformed post !
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 14th Apr 2005 05:51
With my game, it's not exactly a platform game yet (partly based on the fact that I'm having trouble with making a sprite jump). But anyways, the character, named Valiant Warrior, has a sword ,that when you press 'w'. I do this by making a sprite that is the character sticking the sword out. How can I make code that will tell the program to delete the enemy sprite if hit by the character or damage the character when the sword sprite isn't used?

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 14th Apr 2005 09:52 Edited at: 14th Apr 2005 11:07
Hi, I managed to drop in this evening. I will try my best to stay with it here over the next couple weeks.

Okay Professor, I am going to make this a two part answer to your last message posted above.

You say your having trouble with making a sprite jump. My character control subroutine I wrote handles this. It use a little bit of trig. to calculate the arc for the jump. The code doesn't do collision with the background or use gravity, but it could employ this with a little modification. I condensed the code below.



This code works with a 192x256 sprite on a 1024x768 screen. In order to use the subroutine with different sprite and screen resolutions you will have to modify the X and Y character limits.

To calculate the limits use:

X max. = SCREEN WIDTH()-SPRITE WIDTH(SpriteNumber)
Y max. = SCREEN HEIGHT()-SPRITE HEIGHT(SpriteNumber)

As I said before, the routines uses trig. to create a jumping arc for the character. Here is the breakdown:

x=(sx+150)+150*sin(a):y=512+125*cos(a) jumping right
x=(sx-150)+150*sin(a):y=512+125*cos(a) jumping left

variables usage:

sx = current location of sprite at the start of the jump.
a = angle in degrees from center of arc.
150 = x eliptical value (radius) and offset for x.
125 = y eliptical value (radius) for y.
512 = center of arc at y and current character position at y.

This code is designed to work at the bottom of the screen. Play with the code and change some of the values to see how it works. Try to make it work all over the screen on the Y axis...

Now, I will briefly cover your collision. I am not going into it in depth right now. I will release some source code for this later on.

Collision is a probably the hardest part of doing your game. I will give you a basic list of this that you need to consider.

1 - what is your character's attack and how many types?
2 - What is your enemies attack and how many types?
3 - What is the result of collision? (explosion, sound effects, points,
alternate animation for death and damage)

Use collision logic like:

if sprite collision(sprite1,sprite2)>0 and frame = 8

*** collision code goes here ***

endif

Lets say that your character thrusts his sword out by pressing the ENTER key. The animation for this attack finishes at FRAME number 8.
The IF/ENDIF would check to see if your character had collided with an enemy. It also checks to see if the animation frame of your character is 8. If this is the case, then do something as the result. The result might be to add points to your game score, make a sticking noise, and make the enemy die a blood splatted death.

I can't tell you exactly how to do this because I don't know how you want the end result to be. There are just to many variables that have to be considered. Like I said, I will release some more of my game code that shows what I did for my collision later.
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 15th Apr 2005 05:33
That makes sense. The collison part has a problem with my code though. I've been doing "animation" by using this code and not by frame:

(The variables are used to increase the position of other sprites so they don't move out of place.) It has worked so far for me but I have just gotten to the part in my game that involves player vs. Ai characters (kind of like a Mario battle type) and so I might run into problems. I'll let you know how the jump code works out.

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 15th Apr 2005 05:38 Edited at: 15th Apr 2005 05:42
Oh as some background information, the game is called Dungeons and Dragoons II. (The first Dungeons and Dragoons game was a hastily thrown together text adventure). It's kind of a spoof on Dungeons and Dragons. Also, I've created another better text adventure called Super Squid Squad: Text Adventure. The second one is a 2D game, which I have stopped working on for the moment to do DND II since it is a platform game and I guess harder to make.

Game Company(three man company that is): Rook Takes Pawn Productions

EDIT:Ignore the download, it's an accident

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 18th Apr 2005 08:35
Hmmm... Very interesting?!? That code actually works for animation, Professor? Any time you update something drawn which is the same thing within any given pass of a loop, the last thing done to that entity will be updated at the SYNC command. That is if you are using SYNC.

For example:

Let's say I wanted to move and object 6 pixels intervals on the X axis with a delay everytime I hit the right key. I wouldn't do this.


Once you press the right key inside this loop, you would see that the sprite moved 6 pixels with a slight pause before doing so. That is a waste of code. Try to write your code to be optimal or in other words use the least amount of code needed to do the job. This saves memory, increases FPS and the program will run faster, and it also makes things easier to read. I would write the code as follows.



I am not trying to be critical. I am just trying to point out that you are making things more difficult than they have to be. Keep in mind that you are telling the computer to draw something a frame at a time. If you want something to dissappear and then reappear when you hit a key, will have to draw it to the screen first, keep it on the screen until user hits a key, make it disappear, then reappear again if another key is pressed.

Example:



If you try to do the next snippet, you will never see your sprite.



The last thing that has to do with drawing something to the screen was the HIDE SPRITE command. When the screen is updated with SYNC, the sprite was hidden.

If your not using SYNC in your code, you are just crippling your program. It may work fine on your computer, but what if you're running it on a much faster or slower machine? You want your program to run at optimal frame rate on any machine, that's why you should use SYNC.
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 20th Apr 2005 23:40
Two things on the character animation. First, I do have SYNC on but don't put it after the SPRITE command like you did. I only have it right before my last LOOP. So would I have to type SYNC after each updated sprite or what? Also, since I am moving all of the sprites when the character moves since the background is the thing that actually moves, I have to do a similar x=x+3 for each one. Not just the sprite. And, with the enemy SPRITEs or AIs, how can you maek them move without interrupting the game and LOOP commands?

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 21st Apr 2005 12:16 Edited at: 21st Apr 2005 12:48
The SYNC command is used to update the screen after you draw or make changes to your graphics. This is done at a constant frame rate specified by the SYNC RATE command. Just think of it as quickly drawing something off screen and then instantly displaying the results to the screen. This way you don't actually see the computer drawing the graphics pixel by pixel. This depends on the speed of the system of course.

Yes, there are occasions where you might need to use more than one SYNC command to update the screen. However, most of the time you only need to do this once at the end of your loop. When setting up your code for your characters, AI, and other graphics, you will finish up by using the SYNC command.

Timing is literally the key to orchestrating your graphics in the game. There are many ways of doing this. I'll explain one possible way here.

Example:

Let's say you want your character to stay on the screen for 5 seconds and then dissappear while allowing everything else to continue on in the program execution.

DarkBASIC has a handy function call the TIMER() function. You could use this to check against a know duration of time instead of using the SLEEP or WAIT commands. This can be done without interrupting the program for a given period of time.

Well, here is the snippet...



If you need a time delay to reset itself, you will have to grab the current time from the TIMER() function and stuff it into the delay variable again with the duration of time added to it. This process would have to be repeated for everything else that way too.

Example:

This will make the sprite appear to flash on the screen.

Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 23rd Apr 2005 04:09 Edited at: 23rd Apr 2005 04:10
Okay, that makes sense. But, how do you have other sprites move at the same time, while having the ability to move the character sprite?

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 23rd Apr 2005 08:00 Edited at: 23rd Apr 2005 08:06
Professor, I would like to give you a word of advice to help you out. Try to write your programs as a series of self contained blocks of code. The blocks of code could be in the form of a subroutine, a function, or possibly both. Call each of the code blocks from your main program loop. Writing your code this way provides a good foundation for debugging, modularity, expandability, and upgradablity to your games.

Generic examples:

1 - Program variable initialization
2 - Loading game media
3 - Title sequence
4 - User Interface (load/save game, music On/Off, difficulty, ect.)
5 - Background display/updates for the game
6 - Game player controls
7 - Enemy AI
8 - Collision
9 - Program cleanup and exiting

----------------------------------------------------------------------

Okay, you want to know how to move other sprites with your player sprite. What kind of movement are we talking about here? You mean like actual enemy AI? Give me an actual senerio that way I can better examplify and explanation. Don't be vague with your descriptions and try to provide some code snippets if possible. I don't want to confuse you or others that might be reading this.
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 23rd Apr 2005 08:13 Edited at: 23rd Apr 2005 08:14
Sorry about the confusion. Pretty much what i need is a way to have enemies moving back and forth within an area. For example:

Here is the AI---> *^*
Now when I say movement
I mean this--------------> *^*-->*^*-->*^*-->*^*-)
*^*<--*^*<--*^*<--*^*<--
It moves back and forth in, say, a three inch area automaticly.

I know how to do this individually, meaning having on sprite move in a loop. But, when I want to have multiple sprites move, or if I want to move my character, it doesn't work.
Here is the code:

This is my entire game at the moment. If you notice that there are two very similar parts, that is because at the beginning, you move a bit and then when you collide with the sword, it stops, does dialoug, and then continues.
Some how, I want to encorroperate the movement of multiple sprites in this code

EDIT: sorry, it's a really bad diagram.

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 23rd Apr 2005 09:01 Edited at: 25th Apr 2005 10:40
Here is what I would do.



Although, I have not actually tested this out, it should work for you.
Let me know if your having trouble with it.
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 25th Apr 2005 09:30 Edited at: 25th Apr 2005 10:44
Here I go again... I am going to be busy this week. My work is got me working over time again. I also have some projects that are house related as well as some spring cleaning to do. I probably won't be able to post any replies or new code snippets here. I hate to do this, but I need to prioritize my things to do list. Sorry.

To The Professor:

Hopefully, I will be able to pick up where I left off the first part of next week. Please be patient with me over the next week or so. There are some really good people here in the forums that can help you in the mean time.

P.S. I fixed the code snippet I supplied for you above. I tested the code and found many errors in its construction. A lot of dumb mistakes! The new code actually works now. I hope this helps you with your project.

Thanks,
D Ogre
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 28th Apr 2005 09:14
Okay, I'll try it out.

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 2nd May 2005 00:25
For everyone reading this thread:

Don't forget that I have a link here for source code by Pizzaman. It is a complete 2D side scroller demo showing how to setup a tile array system, character movement, and sprite to background box collision. The code is reasonably well documented and it should provide a good framework for your 2D game.

Look at my April 8, 2005 post here above for the link.
D Ogre
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 17th May 2005 11:11
Just in case anyone had missed what I covered in this thread. I will briefly summerize.

1 - I showed you one possible way to employ 2D character control. The code makes use of a 192x256 sprite which can walk, slide, jump, and look up. Although it is not the final build for my project, it might prove useful to some especially the jump routine.
2 - I also provided an example of using program code to generate a simple 2D background with 3D characteristics. Again, to show what's possible.

3 - Intro to 2D tile system. Briefly covered some general concepts of how to control and update a tile system. I know it wasn't complete, but I didn't want to make another tutorial out of it. There are several good examples here in the forums for that.

4 - I covered basic sprite animation for newbies. What are the commands and how to use them.

5 - Timed events. How you might use the TIMER() function.

6 - Basic keyboard control, basic sprite enemy movement (can't really call it AI), and basic collision.


I know I haven't posted for sometime. I am still caught up in other non-computer related projects. I kind of put my 2D game on hold. I don't have the time to really focus on it like I need.

I hope none of the information here was confusing to anyone. If you have any questions, comments, or whatever, like I said before, post'em. I will be dropping in here to see what's new.

I am gonna try to keep this thread going, that is, if anyone whats me to.

Login to post a reply

Server time is: 2026-06-12 09:26:14
Your offset time is: 2026-06-12 09:26:14