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 Discussion / 2D Side Scroller - Terrain and AI questions - DBC

Author
Message
Garfield1983
22
Years of Service
User Offline
Joined: 13th Nov 2002
Location:
Posted: 7th Feb 2007 23:59
Hi folks,

I'm trying to create a 2D side-scrolling game where the player controls a ship that flies along shooting down waves of enemies. It's in the early stages but after reading up alot on the db forums i've managed to get the ship moving and firing.

- Scrolling -

I've read various tutorials on scrolling the background - I currently have an image of some terrain as a sprite with the X position changed until a certain point using an IF THEN statement and the DEC command.

The terrain image is currently not very large (2048 pixels in diameter) and since I want the player to have to fly for a considerable time before the end of the level, I am looking for the best way to scroll the terrain - I don't think making the image larger would work as it's already slightly jittery.

Q - 1) Is it best to 'loop' this sprite and how would this be acheived?

Q - 2) How would I go about having an efficient but large varied landscape? ie not a looping image

I may be answering my own questions but i've been considering (1) tiling the background and updating the edge tile as in rpgs (not really my strong point atm!), (2) texturing a plain and scrolling the texture (3) Having a looping background with additonal sprites for the individual foreground graphics to make the terrain appear varied.

I'm not sure which of the above is the norm?

- Artificial Intelligence -

Again I've been reading up on AI in games - I'm still looking into waypoints as a way to have enemies follow a pattern, but the tutorials I've found are for 3D games - However, my main question is how to display these enemies?

I'm planning on having the player encounter enemies as they progress through the level - a bit like Cloud Master on the Master System if anyone remembers?

Q - 3) How would I space these enemies out so that the player encounters them at specific points throughout the level? This would also apply to any foreground clutter that the player might crash into

Any help would be greatly appreciated and I apologise if this has been covered elsewhere - I did look but I may have missed it
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 8th Feb 2007 01:31 Edited at: 8th Feb 2007 01:41
With regards to the scrolling, tiling is by far the most efficient (and fastest) way to do it.

The tiles used to make up the screen would be placed in an array and as such a screen could be hundreds of thousands of tiles wide before repeating.

I've not done it myself, but I would imagine that if your screen was 800x600 and made up from a 25x18 grid of 32x32 pixel tiles and you were scrolling the screen left (ship is moving right) then it would be a case of:

* Using the array/tiles to build the screen on a second bitmap
* Grabbing part of that screen into an image
* Pasting the image 1 pixel to the left on the main screen
* Updating the rightmost column of tiles from the array when required
* Doing the Sync

This shouldn't cause jittering even in DBC. This interests me, so I'm experimenting with this at the moment!


AI:

I'm not familiar with Cloud Master so I'll leave it to someone who has to comment on that aspect.

Q3:

This would be tied into the tiling aspect. You would be advised to create a separate program (level editor) for generating the data which goes into the screen tile array.

This same program would also allow you to have a second object array the same size as the tile array. You give it the ability to drop a tile onto the grid or an object.

In your program, when you update the tiles from the tile array, you also update from the objects array before doing the Sync.

TDK_Man

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 8th Feb 2007 03:11
Here's a small scrolling example I came up with.



It creates it's own media randomly and you use the left and right cursor keys to scroll.

It's not 100% glitch-free on my system because I have inexpensive TFT monitors with fairly slow refresh rates. It should be fine on a proper monitor. Try it and let me know.

It creates random coloured tiles and simply stores them randomly in an array. You would need to create a level editor so you decide where to place the tiles you create yourself, but the scrolling would be the same.

TDK_Man

Garfield1983
22
Years of Service
User Offline
Joined: 13th Nov 2002
Location:
Posted: 10th Feb 2007 12:53
Hi TDK, thanks for the help!!

Your code works perfectly on my system. I still need to go through it line by line to see how it works as i've only had a preliminary read (I've been ill with flu this week), i'll let you know if I get stuck. The theory behind it makes sense though.

I'm not sure I have the knowledge to take on such a big project as making a level editor, although this would be a good feature to include in the finished game itself.

I know there are already level editors out there but I want to create as much of this game as possible myself - I'm the kind of person who hates the idea of simply copying other peoples code and calling it my own, where's the learning in that?

I may use a 3rd party level editor, atleast to get something working and get some ideas for my own editor. I've been exploring the idea of creating a textured matrix in your exellent program MatEdit and pointing the camera at it to give the illusion of 2D, then moving the matrix or camera when the cursor keys are pressed. I'm not sure how I would place the enemy/player sprites etc - I need to look into if these can be put onto 3D plains, I think I read something about that. This would probably be quite taxing on system resources though.

Another idea i've explored before is data statements. I need to study these again as I never quite got the code working on my last attempt (admittedly some time ago!). I need to brush up on arrays in general but perhaps data statements will allow me to create 'levels' (possibly as external notepad files to allow additional levels to be added easily) and perhaps a seperate one for the starting points of the enemies.

Anyway, I need to go away and look into all this, as well as study your code in more detail, but I wanted to let you know I'm still around and say thank you for the detailed response - you are legendary around here for the help you so kindly give.

Cheers!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 11th Feb 2007 02:57
Quote: "Another idea i've explored before is data statements"


They would work, but I'd advise against using them.

The main problem is that your levels are built into the final exe and adding more (or modifying existing ones) requires supplying a new exe - and re-writing the program to cater for the difference in levels.

No, the best way is to store the data for each level in the game as a separate data file.

Your program can look at these files and know how many there are in total, so adding more levels isn't a problem.

And, if you tweak a couple of levels, you only need to supply the new data files for those levels - not everything.

As for the level editor side of things, it sounds a lot more complicated than it actually is.

In the example code I posted above, all it does is create 20 random coloured 32x32 pixel tiles. They are all stored in images numbered 1 to 20. In your game, you would create your own tiles.

It creates an array (tile grid) of size 10001 tiles across and 18 tiles down (don't forget element 0). This equates to a screen playing area 320032 pixels wide and 576 pixels high. The array is actually dimensioned with Dim Tiles(50000,17), but you don't need to use all elements.

Likewise, use a number bigger than 50000 to create even bigger levels.

It then randomly fills the the array with the 20 tile numbers.

All a level editor needs to do is allow you to select which of your manually created tiles goes where on the grid, then write out the resulting numbers to a file.

Obviously this program can be as complicated or as basic as you want it to be, but essentially needs to be able to:

* display the tiles available
* show you a section of the grid
* select what section you want to work on
* Allow you to place the tiles
* save a data file
* load a data file
* test what you have already done

You could also give it the ability to add 'spawn points' for enemies, creatures or objects and save this data to the level data file.

It sounds like an interesting project and if you need any help with the editor side of things just shout.

TDK_Man

Login to post a reply

Server time is: 2025-05-26 03:00:03
Your offset time is: 2025-05-26 03:00:03