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.

Newcomers DBPro Corner / Climb rope, move upstairs

Author
Message
Tattered brush
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location:
Posted: 12th Dec 2008 17:38
Hi guys

I am creating a 2d platform like adventure game. The screen does not scroll, the background image is just replaced when the sprite walks off screen.
I have come to a point where I want my character to climb a rope or move up some stairs and I am not sure how I would code this.
I just want the character to be able to "jump" up the rope, so every jump takes him further up the rope. Any advice on how I would do this?
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 12th Dec 2008 23:41 Edited at: 12th Dec 2008 23:56
Well since you have no scrolling going on you could literally hardcode your jump/climbing areas. But If you don't want to do it that way you could, use a second bitmap image (that is not seen) to draw your collision/climbing zones. I might have to draw up something in paint to have this make sense. But anyway, you use the second image to test what should occur.

(Forgive me for the ugly example I am about to post)
The first image is the level the player sees. The second is a collision map of the level. You just check the sprites position against the collision map, and depending on the color you code the action.

Red=Player collides
Green=Player moves through
Yellow=Player Climbs

visible level


invisible collision map for level


~Zenassem
Tattered brush
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location:
Posted: 13th Dec 2008 14:25
Thanks for taking the time to illustrate my problem, it is much clearer and it seems this is just what i am looking for.
Would it be possible for you show this in code please? Are there any examples of collision maps out there?
I want the player to be able to move through the stairs until the sprite jumps, making the player land on the first stair etc.
Thanks for your help so far.
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 13th Dec 2008 15:28
If you want to make your life easier, you should work on a level editor. You could program it to allow you to import your background image, then draw collision boxes ontop of it and set the boxe's properties (stop the user, allow them to climb up, etc). Using this method you could go one step further and set collision boxes to hurt the user and place them over something like lava, boxes to win the game when entered so you could program doors easily by drawing a enter collision box overtop of it, etc.

The level editor wouldn't be too hard to make since it's 2D. Id recommend you get familiar with user-defined types and arrays if you're not already. You could save the collision boxes in an array, and store their properties in a UDT. For example;

And then to check for collision you could easily loop through every box and react accordingly;


You'll need to familiarize yourself with the file commands as well so you can load the collision maps into your game. Its a little more work but once you have a decent level editor you can make maps easily, and improve it to allow you to place spawn points, weapons, etc.

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 13th Dec 2008 22:28
I can write some code later, but the idea is to make a memblock from the collision image. Then just create a function that grabs the right pixel info based on the sprites X,Y position on the actual background.

Here is a tutorial on how the make memblock from image works. You can sink your brain into that until i can code an example later.

~Zenassem
Tattered brush
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location:
Posted: 15th Dec 2008 10:22
Thanks for the support guys. Looks like there's alot to learn. I like the idea of creating collision boxes just need to understand UDTs and arrays more thoroughly.
Can a UDT hold a sprite image. For example if I define an array for objects, can one of the properties be the sprite that represents that object in the game world?
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 15th Dec 2008 10:43
Sorry I totally dropped the ball on you. Didn't mean to do that. I will provide that sample code when I get back this morning.

as for your question... In a way the answer is yes.

One of the indexes of the array could store the sprite number, which would refer to the sprite. You could aslo store a pointer to the beginning of the memblock containing the image data.

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 16th Dec 2008 21:10 Edited at: 17th Dec 2008 02:49
I'll have this finished tonight. The example will cover 3 methods.

1. Hard coded collision boxes
2. Using an image as a collision map
3. Building the world out of tiles and using one layer as a collision map

preview:


EDIT:
Here is the Media for 3. (Srym photobucket converted them to .jpg so you may need to re flood fill the black. I'll try to fix it later)
man

block

ladder


Here is 3. (It's a crude as can be)


=====================
Next I'll do 1. and 2. and edit them in

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 17th Dec 2008 21:08
He was reffering to UDTs Zen.

The answer is yes. UDTs allow you to create named locations within arrays. So yes you could have a UDT that stored the sprite number. Look them up and you'll figure out how useful they are.

Login to post a reply

Server time is: 2024-09-27 22:30:24
Your offset time is: 2024-09-27 22:30:24