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 / need help 2d scrolling platform

Author
Message
stevemcd
13
Years of Service
User Offline
Joined: 29th Jun 2011
Location:
Posted: 29th Jun 2011 16:48 Edited at: 29th Jun 2011 22:41
Hi im trying to make a simple 2d scrolling platform game.
This is my first game and im having trouble with getting it to scroll
through the level




Attachments

Login to view attachments
stevemcd
13
Years of Service
User Offline
Joined: 29th Jun 2011
Location:
Posted: 30th Jun 2011 00:20
im having a problem getting it to follow the player through the level
please help if you can
thanks
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 30th Jun 2011 01:00
Don't move your "mario" (or don't let him move around the actual scene very much. Move the scene around him. If you are trying to make a Mario clone, the "camera" will follow him left/right until he gets to the edge and when he jumps, there's a small amount of up/down movement that the camera will just let him move freely. The actual trick is the movement of the scene instead of the character. If you are doing a true 2D, you will have to do this method since the "camera" doesn't actually exist. I hope this helps.

The fastest code is the code never written.
stevemcd
13
Years of Service
User Offline
Joined: 29th Jun 2011
Location:
Posted: 30th Jun 2011 01:58
thanks hawkblood that worked great but now i have another problem.
my mario wont fall when there is no ground below him (in the ground.bmp). I think the problem is in the player.h

float ground=171;

i was just wondering if there was a way to use the ground.bmp picture
instead of just setting the ground height.

i tried jus doing

float ground="ground.bmp"

but it didnt work
i also tried using collisions but could only get it to work if only used one collision

for example this worked fine


but when i tried putting it on another sprite it didnt work




thanks
stevemcd
13
Years of Service
User Offline
Joined: 29th Jun 2011
Location:
Posted: 30th Jun 2011 21:51
can any 1 help me i need to get my mario to fall when dot touching any of the objects, but i can only get it to work for the ground i cant get it to work for platforms aswell is there a way to put multiple sprites in the if statement
if


i tried using



but it leaves a gap inbetween the 2 sprites. i cant figure out why it puts a gap in between the 2 sprites

any help will be appreciated

thanks
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 30th Jun 2011 23:18
There are different ways of doing the whole "ground collision" routine. You could simply make the ground using segments of sprites and do a collision detection like you've been doing, or you can do the math yourself. The second method is not easy for a novice, but it opens up a great deal of possibilities-- the detail of your ground can be greater than just blocks.

I have to go for now, but I'll check on this post when I get home.

The fastest code is the code never written.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 1st Jul 2011 01:59
Ok. I'm home. On second thought, simply do the blocky collision with sprites. Each sprite of the ground can be rotated to various angles to give your player a bit more detail without killing you with math. To make your level, you will first need to decide how you want store the data. One way is to make an editor. Another is to simply write them in manually and tweek them into place by visual inspection and coming out of your program for adjustment. I prefer the previous since it makes level making faster and the repetition of making levels won't drag you down.

First let's deal with your other problems
dbMoveSprite (1, 5); will move the sprite in the direction the sprite is facing 5 units. I'm not sure what you are wanting....

As far as checking sprite collisions, you are stuck with looping through them and dealing with them individually.

Now for that editor. You can make it part of your game, but it's a hidden interface that you can activate. When you activate it, the player interface is suspended and the editor interface takes over. I would have it like a menu bar at the top with objects, monsters, and special objects. Clicking on "objects" would bring up a choice of "blocks" that you have pre-created for use. Remember each block is the same size left-to-right. If you make them something like 50 pixils or 100 pixils or whatever you want as long as they are all the same, then placement of them is like laying bricks. The angled ones will be different than the flat ones, because they are turned at some angle so that the collision works correctly. These will need to actually be larger than the others so there are no gaps-- I think you can figure out what I mean and make it work for you.

All this is kinda vague, but if you have trouble with it, let me know and I'll help more.

The fastest code is the code never written.
stevemcd
13
Years of Service
User Offline
Joined: 29th Jun 2011
Location:
Posted: 2nd Jul 2011 18:12
With the dbMoveSprite (1,5); i just moved my gravity into main, and the 5 just cancels out the gravity when mario colides with ground
(i moved the gravity to main because i didnt write the player.h file and not sure how to cancel gravity in it when mario colides with sprite.)

by blocky collision do you mean do the ground as a tileset.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 2nd Jul 2011 18:33
Quote: "by blocky collision do you mean do the ground as a tileset"

The "blocky" term is in reference to simple sprite collision. There is a way to do pixil collision with sprites and even doing a "line barrier" for the ground. All that takes quite a bit of math, so I would stick tiwh the default sprite collision and make an interface to create the levels.

The fastest code is the code never written.
stevemcd
13
Years of Service
User Offline
Joined: 29th Jun 2011
Location:
Posted: 3rd Jul 2011 21:18
ok soz took a while to reply
i havent had chance been a busy weekend
so for ground do you mean i should split ground into seperate images and and place them next to each other with gaps where i want them
e.g.


not sat at computer so cant test but is that what you mean

or do you mean split ground into smaller blocks
e.g. split blocks into say 100 by 100 squares and place them next to each other and just leave gaps where i want

e.g.



so there willl bne a gap 300 to 400

if you mean either of these would it be possible for me to do it as a animated sprite and just call parts of it up when i want that part.

and if that is possible could i do all the platforms in 1 animated sprite and just call the parts of the sprite i want to displayand and
(dbSpriteCollision (1, (animated sprite here) == 0)

p.s. thanks for all help



i didnt write this code (below) and dont understand it all (thats why ive comented on each line individually when i figure out what each line does)
ive been trying to understand it all but i am realy new and this is my first game and it didnt have any comments on it.
i just found it on a google search for platformer help darkGDK



stevemcd
13
Years of Service
User Offline
Joined: 29th Jun 2011
Location:
Posted: 3rd Jul 2011 21:27
i dont muind doing a bit of math if that would be a better way of doing collision
Quote: "There is a way to do pixil collision with sprites and even doing a "line barrier" for the ground"


would that be like if mario == 0 < 300
{
grav = 0
}

not sure how it would work please give a little bit of sample code if not to much trouble


and is there a command i can use that works like OR so i can put somethin like

if (dbSpriteCollision (1, 2 == 0)
OR // would like an or command here
if (dbSpriteCollision (1, 3 == 0)

(not at computer so cant check if there is an or command.)
stevemcd
13
Years of Service
User Offline
Joined: 29th Jun 2011
Location:
Posted: 3rd Jul 2011 22:08
i also dont know what you mean by menu bar (dont know how to create a menu bar (new to c++ aswell so i would like an example if possible please))
thanks for all help
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 4th Jul 2011 06:01
This is an example of a ground sprite with a height line. The ground that is shown on the screen is represented by the green and the "height line" is the black segments. The black segments are not actually part of the sprite, but they represent where the "hight lines" will be.
With that out of the way, here is the math you will need:
Y=m*X+b
You will have to determine the "m" value which is the slope of the line. The slope of a line is:
m=(Y1-Y2)/(X1-X2)
where the X1,Y1 is the first point on the line and X2,Y2 is the second. Next you will have to determine the "b" value which is known as the "Y-intercept".
b=Y-m*X
Use either X1,Y1 or X2,Y2 to plug into the formula.
Repeat this for each of the segments of the "hight line" and put all that info into a class (hope you understand classes).

That is a quick and efficient way to make level sprites with height lines. Simply add more and more until you have all the ground sprites you want. These are repeatable and easily placed if you have all the sprites the same size. You can have gaps in a sprite to represent a pit. Just make a line going (almost) straight down and then accross then back up to the other side.

Now for the rest:
Make a loop at the beginning of you game to do the slope info:

You know how to move the ground under the player, so as you do, you will need to have something to hold the info for where the "blocks" are on the screen-- I would use a class:
class ASSIGNEDBLOCKS{
public:
int GroundNumber;//this is a reference to the GROUND class we made earlier
int X,Y;//the upper left corner of the sprite
}Blocks[]={0,0,700
,1,256,700
..... and so on....
};
This is an efficient way to place them on the level, but for a large game this may not work as well as you think. You may want to make a level and save it to disk and then start over with a fresh code for the next one.... Whatever suits you.
As you character moves, change the location of each of the sprites to be moving in the other direction.
For the collision itself (yea... a lot to prepare for this):
Determine which sprite you are over. Here is where it gets kinda weird. The "Blocks" will not move. The values you put in for them are static and you will have coordinates for you character that will move even though he doesn't. Each frame you will check the character's X value and doing a little math determine which block he is over and where on the block he is.

Once you know which block he is over, you can check the segments to see if he is beyond each of the segments.

I hope this gets you started.....

The fastest code is the code never written.

Attachments

Login to view attachments
stevemcd
13
Years of Service
User Offline
Joined: 29th Jun 2011
Location:
Posted: 4th Jul 2011 23:54
thanks for all the help
I think i might have to learn c++ first thought id be able to learn it using dark gdk but i think i should learn it first so gunna put off making game till learnt c++ first
stevemcd
13
Years of Service
User Offline
Joined: 29th Jun 2011
Location:
Posted: 4th Jul 2011 23:55
because cant ask for help with everything and i seem to find another problem every time i fix 1
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 5th Jul 2011 15:25
Quote: "... and i seem to find another problem every time i fix 1 "


Such is the life of programmers for any language of choice!

Mind if I point out that these forums have a "Programming Talk" board that you may find useful in your endeavors?

Happy Coding,


JTK
stevemcd
13
Years of Service
User Offline
Joined: 29th Jun 2011
Location:
Posted: 5th Jul 2011 19:58
thanks for help help i'll use programming talk it looks like a good place to learn

Login to post a reply

Server time is: 2024-11-19 09:38:06
Your offset time is: 2024-11-19 09:38:06