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.

Dark GDK / I just don't get levels at all

Author
Message
Brandon Heat
15
Years of Service
User Offline
Joined: 28th Nov 2008
Location:
Posted: 1st Dec 2008 09:57
You guys are gonna hate me but just don't get how to make 2d levels in dark gdk.

Trust me i have searched on google and here and just tried to understand but i'm just to stupid.

Heres what need answered and if at all posible some source code examples.

1. Lets make this basic say i'm making a platformer, and i have 3 tiles (i understand this is not the norm but tying to just get the basics) lets say that i have a green one called grass, a blue one called sky and black one called hole and their 32 x 32 pixels. What do i have to do to make a level from them? I've been reading and see alot of things like

data 11111111
data 11111111
data 22222333

is that using the image number say sky is 1 and grass is 2 and hole is 3 to construct a map? If so or if not can anyone give me some syntax for this.

2. Say someone can help me with that and sees past the question being asked everywhere and that i'm just dumb, how would i make the screen actually move across say left x amount when player walks x amount or up y amount when player jumps. This is something i don't seem to grasp.

3. Lastly i've done some reading and it would seem that tiles make it easier to find out if your players is on a collison point to say grass or has landed in a hole and dies or something. That all sounds really good, but what i'm worried about is like say you have a moving platform (like something that moves up and down the screen and you have to jump on it) would this be made with a tile if so how could this be done?

Lastly is it a good standed to have a seperate class for each level in the game that would have that levels enemies or would it be better to have a seperate enemies class for each class? (Not releated 100% but i wanna know what the standard is).

Anyway i understand that these questions must be fustrating to answer over and over again, but really i'm just trying to learn and i appologize for my stupidity.

Anyway thankyou all for reading i hope i haven't annoyed anyone to much.
CheatCat
17
Years of Service
User Offline
Joined: 7th Mar 2007
Location: Sweden
Posted: 1st Dec 2008 11:47
1. Well, I call a create function 130 times instead of using memblocks, so I don't really know how to use memblocks. I think "data" is a sort of memblock however...

You can do like me, make your own function and then call it for every sprite you want draw, or just use dbSprite().

2. You must move the world objects in the opposite direction of the player.

3. First you should move the platform, like this:

Then check if the player collide with the platform and the player's y position is larger then the platform's. If so, set the players yspeed to th platform's. An example:



There is no standard how to split the code into classes what I know. Do whatever you think is readable. The only one rule is when it takes too much energy to scroll, you need split the code into a new class.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 1st Dec 2008 18:45 Edited at: 1st Dec 2008 18:46
Just tackling #1.


Creates a two dimensional array declaring three rows (indexed 0-2) and eight columns (indexed 0-7).



Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 2nd Dec 2008 03:52
Since Lilith tackled #1 beautifully, I'll try my hand as #2.

There is a fairly simple way to create this effect. Each time the player "moves" in a given direction, the updated sprites for the tiles are moved, rather than the player. This makes it seem like the player is moving.



So, every time you update the loop and reposition the level, the level moves itself to create the illusion of the player moving.

I would also consider an alternative methods. For instance, you could create an old "Zelda-esque" style instead of the above "mario-esque" type movement.

In this zelda-type movement, the player would move around the screen independent of the environment, but when he hits the edge, the screen slides to a new set of tiled.

So, on screen may look like this;
11111111
11122211
11111111
22223332

and when the final edge is touched by the player, the whole screen changes to a different tile set like this;
11111112
22211112
11111112
22233322

Which would have a wall at the right side.

Consider all your options before you pick one =) There may be a different movement style available then what you're looking at.

Cheers,
Bishop


Tux is my guildmaster.
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 2nd Dec 2008 07:57
Out of total boredom, I threw together a basic demo to show you what I'm trying to say =D Go ahead and download it...use the code however you want, but it's very, very basic and cumbersome. Mostly there for the idea, not the code itself.

Move with 'A' and 'D'

Cheers!


Tux is my guildmaster.

Attachments

Login to view attachments
Brandon Heat
15
Years of Service
User Offline
Joined: 28th Nov 2008
Location:
Posted: 2nd Dec 2008 08:44
Ahh so rather than more the player you move the level very interesting!

Firstly big thankyou to CheatCat, Lilith and Bishop.

However i'm still having some trouble this is what i tried



Now i know this is worng but you help tell me why? Thanks guys.

Also if i'm being to annoying what bishop posted is exactly what i'm after is there anyway i could get the source code for that, if i can i think i could would it out.

Thanks again guys really i'd be stuffed without your help!
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 3rd Dec 2008 00:40
Sure. Here's the source =P I intended to include it, but accidentally deleted it with the other release crap =P


Tux is my guildmaster.

Attachments

Login to view attachments
Brandon Heat
15
Years of Service
User Offline
Joined: 28th Nov 2008
Location:
Posted: 3rd Dec 2008 06:29
Ok very cool i got that working now thank you very much for all your help it all makes good sense now apart from a few things...

1. When i do dbPlaySprite() and play my attack animation the level disapears and reapears when the animation is over, i can't see a reason for this though.

2. What is dbCLS()?

3. Why do you multiply the title by 32?

4. Now this is to do with coding games in general, i've been making classes like how you do in a business app and its own methods like void Level1::setUp(); with its constructor ect but don't think thats correct now after looking over your code (bishop) and also the tutorails where they don't make classes and use extern varibles. Which is better or which is the standard?

Thanks for all your help.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 3rd Dec 2008 07:11
Quote: "4. Now this is to do with coding games in general, i've been making classes like how you do in a business app and its own methods like void Level1::setUp(); with its constructor ect but don't think thats correct now after looking over your code (bishop) and also the tutorails where they don't make classes and use extern varibles. Which is better or which is the standard?
"


I'm not sure what your approach is and I don't have time to apply my stuff to yours since I don't work with the same type of game. However, I will suggest that you define a class called Level and then have different Level objects for each level.

class Level {.......

Level level1;
Level level2;
etc.

Initializing the level data itself may be difficult and you might prefer to use structs for your levels instead since they're easier to initialize when they're declared.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Brandon Heat
15
Years of Service
User Offline
Joined: 28th Nov 2008
Location:
Posted: 3rd Dec 2008 11:01
I worked out why it was disappearing it was how i had it set up i had a loop in my player class called attack, which was something like


without putting the draw level into the loop

@Lilth
Ahh right so i basically have a datastore class of levels and make them the levels from structs that would help with initializing the 2d arrays actually yeah thats good idea thanks!

I'm thinking of not having my player class deal with attacks or jumping and making it just load the images and setting it up at the start, would that be a better way of having player, this would mean that i would have a pretty big loop at in the main.cpp where it checks for different things like if the user hit attack or jumped and then call a method that would have access to things like drawLevel and other important methods like enemy functions later when i get up to playing around with that.

I'm not sure if my post got deleted or not from before, so i'll just hold off on re-asking any of those questions again incase mods are looking over it.

Thanks again Lilth and bishop it may not seem like it from posts on here but i'm actually starting to get the idea of this alot more! Thank you!
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 3rd Dec 2008 14:38 Edited at: 3rd Dec 2008 14:43
Well, me and Lilith are pretty good at tag teaming here =P
Quote: "
2. What is dbCLS()?

3. Why do you multiply the title by 32?"


2. dbCLS( ) clears the screen to black. The reason for putting it in is because without it there would be a blur added the the levels. Pasted images do not go away, so with that system you need to clear the images before you paste new ones or there could be problems.

3. My drawScene( ... ) function was kinda hacked up because I was doing it quickly. It's certainly not the most elegant, which is the reason the second and third scenes are drawn with basic value like +640/1280. A little more work could be done to make it better, but I just wanted to convey the basic idea.

The reason for multiplying by 32 is because way the data is read is exactly the way the level is laid out. If you look at the data sections;



So, if going across the first data section is the top of the screen, the first 20 values Y are multiplied by 32, but since the loop is still y == 0, it gets a 0 returned for position. The X loop, however, is still getting incremented, so each loop iteration is spitting out 0, then 1, then 2, etc. When these values are multiplied by 32, it generates the proper coordinates for the images.

Thus, the first data value coordinates are 0,0, the seconds are 32,0, the third are 64,0 etc based on the loop iteration.

The next 20 values will have had their Y loop iteration increased, so while the X values will follow the same pattern( 0, 32, 64, etc ), the Y loop, now at value 1, will generate 32.

Hope i explained it well enough, let me know =P

Quote: "4. Now this is to do with coding games in general, i've been making classes like how you do in a business app and its own methods like void Level1::setUp(); with its constructor ect but don't think thats correct now after looking over your code (bishop) and also the tutorails where they don't make classes and use extern varibles. Which is better or which is the standard?
"


I am a huge proponent of classes, the reason I didn't use them in my code was because classes require extensive testing to make sure they're being coded properly. The example I made up only took 15 minutes, so I didn't take the time to make a player or level class.

I would certainly suggest you do, however, or use structs. They would both work.

Cheers!


Tux is my guildmaster.
Brandon Heat
15
Years of Service
User Offline
Joined: 28th Nov 2008
Location:
Posted: 5th Dec 2008 04:09 Edited at: 5th Dec 2008 10:54
Ok i have made a few small levels and they work i think i understand it now for the most part anyway which is all thanks to you guys!

One last question hopefully,

How do i detect what tile the sprite is on top off i've tried a few ideas but can't quite get it working right.

Thanks again for your help its been fantastic!
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 6th Dec 2008 02:08
For that, you're going to need a 2D collision Library. There may be some built-in commands in DarkGDK, read over the "Basic 2D" command list.

2D is not my forte, but someone else might be able to help you on the collision side of things.

Good luck!
Bishop


Tux is my guildmaster.

Login to post a reply

Server time is: 2024-11-25 07:22:00
Your offset time is: 2024-11-25 07:22:00