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.

DarkBASIC Professional Discussion / Streets of Rage type walking?

Author
Message
Confused1612
14
Years of Service
User Offline
Joined: 9th Feb 2012
Location:
Posted: 25th Mar 2012 07:34
So, I am in a class learning the basics of Dark Basic Pro. We started small, and haven't really come that far. We made a number guessing game, a tic tac toe game, and most recently a music player application. This week (due Tuesday by midnight) we have to make a "simple" Streets of Rage type game where you have a background and a sprite walking (he can stay in the middle of the screen or actually move it doesn't matter) but the background has to move to make it look like the sprite is actually going somewhere.

To prepare us for this...she gave us a 5 slide PowerPoint presentation that didn't even come close to providing enough information. She gave us a ZIP file with a few different starting places, which I have attached. I know I am cutting it close, but I am so busy being a full time student on top of working full time that I just barely get done with one weeks assignments just in time to start working on the next weeks. Anyway, I would really appreciate any help anyone could give.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 25th Mar 2012 15:33 Edited at: 25th Mar 2012 15:33
Where to begin...

Well first off I think it's important to understand how the background works. Most games use a system known as a Tile-Based system. The following code will paste an image at the mouse's position:



Now the way a Tile-Based system works is you have this grid of tiles defined by an array. Think of a chess board and imagine that every square is it's own image. We can store these images in an array like this:



So far so good. TileWidth and TileHeight are the dimensions of the single tile images. So if your grass image is 40x55 for example, change those values respectively.

So let's look at how we store the map data. For every "chess" tile, we have a separate image right? So what we're going to do with the array is store the image index. Let's load 3 images just as an example. Empty, dirt, and grass.



Alright. Next step is to store how the map actually looks into that array. For the sake of simplicity, I'll just make everything grass, and then randomly place dirt and empty on top of it:



The final step is to draw everything to screen in the main loop. Here's the code:



Now our next problem is to be able to scroll around on this map. This is achieved by using global offsets on the tiles. I'll use the arrow keys to control this, but really, you can use anything you want. This would be the updated code for the drawing routine:



And that's the basics of Tile-Based maps. I hope this gave you some insight and helps you

The player is really simple now, you just paste a player image at the center of the screen and he will appear to be moving when you scroll the map around.

TheComet

Confused1612
14
Years of Service
User Offline
Joined: 9th Feb 2012
Location:
Posted: 27th Mar 2012 03:08
Thanks! That helped a ton. I managed to tweak it and make it do exactly what I wanted. Now, could I possibly ask for more help? We are really gearing up and building up more and more advanced working towards a big final project in the middle of May. Anyway, this week we have to take the program we just made and add sprites to interact with. After seeing my program my teacher suggested (and I agreed it would be a good idea) to have one kind of rock when I run into it it should increment a counter of "Geological Samples" and the other kind of rock to act as like a battery so every step I take uses battery and when I hit the second kind of rock it will recharge my battery. Preferably, both should disappear afterward because they have been used up.

I am not sure if it would work but I thought maybe I could paste them as sprites instead of images and do a collide to detect when you hit one but I am not 100% sure how to do that. Any help you can give will be greatly appreciated.

I have attached a ZIP file containing my pictures and executable, etc so you can see what I have and a better understanding of what I need.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Mar 2012 12:17 Edited at: 27th Mar 2012 12:21
The great thing about Tile-Based games is it's really easy to figure out what tile you're currently on without much collision detection going on, and if you followed what I did above, it will be extremely easy to change the tiles at real time. Here's how to find out where the player is (based off the code I wrote above):



TheComet

Confused1612
14
Years of Service
User Offline
Joined: 9th Feb 2012
Location:
Posted: 20th Apr 2012 05:21
Hey, I am sorry it has been so long but I have been too busy to implement this until today and it doesn't seem to recognize hitting the rocks. Here is my code and I have attached the ZIP of my whole project folder:


Really what I want is to take what I have and add a few things. First, I want to set a variable such as "battery = 1000" when the program starts and have each movement reduce battery by one. When battery hits zero, I will have a picture or video showing that you died and ask if you want to play again. I would like to keep a battery percentage in the upper right corner. To recharge your battery you will gather crystals (Rock2 in the code).

The purpose of the game is to collect a set amount of samples (Rock1 in the code) before your battery dies. I would also like to have a running counter of samples collected in the top left corner. If you reach the designated number of samples before your battery dying I will play a victory video and then end the game.

If you can see why it isn't recognizing when I pass right over either type of rock please let me know and I would greatly appreciate it if you could help with the rest as well.
Confused1612
14
Years of Service
User Offline
Joined: 9th Feb 2012
Location:
Posted: 20th Apr 2012 05:56
Forgot to attach it, sorry!
New World Order
21
Years of Service
User Offline
Joined: 31st Oct 2004
Location:
Posted: 20th Apr 2012 20:02
hey mate!
That's a very nice game you have going there!

I didn't really understand how your game checked for whether the robot is in the tile, so I wrote an alternative way which works -- and it was such fun that I added a sketch of the whole battery-thingy, too! I hope you didn't mind xD



To be honest, though, I'm not sure if it's the most elegant way..
I hope the annotations are somewhat clea... if you have any questions about the code or anything else, just shout
Confused1612
14
Years of Service
User Offline
Joined: 9th Feb 2012
Location:
Posted: 20th Apr 2012 20:52
Thanks that helped a TON! You wouldn't by any chance know how to fix the "problem" with the map being messed up if you try to go left or up from the starting point?
New World Order
21
Years of Service
User Offline
Joined: 31st Oct 2004
Location:
Posted: 20th Apr 2012 21:00
glad to hear that I could help
the easiest solution to get rid of the messed up graphics beyond the map boundaries is to make another image of resolution 640*480 (so it fills the entire window), load it and "paste" it at the beginning of the do-loop, at x= 0 and y = 0. That way it is pasted first and all other images are pasted on top of it...
This will get rid of the graphics glitches, but note that it wont look pretty, as the image won't scroll along with the "camera".. Maybe the best thing would be just to just use a solid black...
I'll see if I can come up with something better

Login to post a reply

Server time is: 2026-07-09 00:08:10
Your offset time is: 2026-07-09 00:08:10