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 / Changing Levels

Author
Message
Flaming Ghost
20
Years of Service
User Offline
Joined: 29th Apr 2005
Location: Um...Right here
Posted: 1st May 2005 03:02
Im making a puzzle game where you push blocks around and try to direct a ball into a hole. I want to know how you can change levels, so after the ball collides with the hole... you go to the same world, but all of the objects are in a different position.

Am I dead yet?
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 1st May 2005 13:04
Flaming Ghost,

You should place objects' positions for each level within some .dat file(s) or as data within your program. When it is time to go to another level, simply read the information from the file, in a certain sequential order that you have placed the information in, and re-position the objects using the values read.

Down below is a code snippet for you which reads a .dat file and draws boxes on the screen according to the values read. Then, the repeat until loop continues until the spacekey is pressed, and it then reads the file again, and all over again. Also, below the first code snippet is another code snippet which is .dat file values I made which includes x and y positions. (Copy and paste this information into a text editor and save it as a .dat file named changelevel.dat. Save both the .dba and .dat files in one folder together.)

The first box's x position being the first line in the file, the second line being it's y position and the next lines for the rest of the boxes. There are two levels of data within the .dat file, which includes twenty lines of values each, giving a total of fourty lines of values. There are two lines of values for each box in each level, and there are ten boxes per level.

The code


The .dat file values



+NanoBrain+
HWT
20
Years of Service
User Offline
Joined: 1st Apr 2005
Location: Earth
Posted: 5th May 2005 23:28
Hi there

All you have to do is follow these steps:
STEP 1: Store the positions (x, y, and z) for each level in a file (any standard data storage extension will do like .txt or .dat).
STEP 2: In your game, when the level is over, add a subroutine that does these things:
a) make array (any name, just has to be integer type)
b) load the data values into the array using Load Array Filename,Arrayname
c) make a For-Next loop like this example

d) in the above loop, just after the For statement, add this line

STEP 3: In the main program loop, go to this routine when you want to change levels (i.e. when the ball is in the hole).

That's all there is to it Remember though that since this is an example, the values for the For-next loop will be different. E.g. 1 to 20 instead of 1 to 10.

I'll be happy to explain anything you don't understand. Good Luck

HelloWorld Tommorrow

Login to post a reply

Server time is: 2025-05-22 23:58:45
Your offset time is: 2025-05-22 23:58:45