# 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.

### 2D All the way! / Movement in a 2D Adventure game

Message
Posted: 11th Jun 2003 14:31
Hey, I have ripped some information/images from a game (SoMI, The Secret of Monkey Island (Monkey Island 1)).

I want to do what the guys at LEC did, that is use boxes/lines to determine where the player can actually walk/move to, but I'm not sure how to do it/go about doing it.

You might see and get a better understanding of what I am on about by viewing the below images.

This is the background.

This is the box/lines of where the player can actually walk/move to.

This is them overlapping (N.B. This actually isn't taken from the game, I edited the two images in psp7 so you can get a better idea).
I hear and I forget. I see and I remember. I do and I understand.
Posted: 11th Jun 2003 22:54 Edited at: 11th Jun 2003 22:58
You could do it something like this.

Set up a structure containing the top left and bottom coords. of each line and box. Something like:

TYPE coordinates
topleftx as INTEGER
toplefty as INTEGER
bottomrightx as INTEGER
bottomrighty as INTEGER

Now, create an array for all those boxes and lines
DIM boxes(5) as coordinates
where the coordinates are the top left and bottom right coordinates of the box
DIM lines(3) as coordinates
where the coordinates are the end points of the lines.

If the player is currently in a box:
When the player moves, you now need to check that their intended new position (let's call it newx, newy) is legal. If it isn't, stop them moving in that direction.

So, for the box the player is current inside, see if newx is between the values topleftx and bottomrightx, AND newy is between the values toplefty and bottomrighty. If it is, the place the player wants to move to must be legal (ie. inside the box) and you can let them do it. If it is outside, don't allow them to move to the new coordinate.

The lines are slightly more complicated. The lines are like "rails" that the player moves along, and you want them to "stick" on to them. This involves knowing the equation for the line, which I think looks something like this:

y=mx+c

Stay with me.

To calculate m, the gradient of the line, you need to work out the distance between the two y coordinates - which is basically, m#=abs(bottomrighty-toplefty). (Make sure to set m to a floating point with the #.)

Now you know m, c can be calculated from rearranging the equation to: c=y-mx for either of the two coordinates, so c#=toplefty - (m*topleftx) (c needs to be floating point as well.)

Almost there.
If the player moved the joystick left/right, you need to make sure that the y-coordinate changes accordingly, so the player "sticks" to the line. You can do this by making newy = (m#*newx)+c#.

If they are moving their joystick up/down, you need to make x stick to the line: newx = (newy-c#)/m# (I think.)

I'm guessing there's probably an easier way, but I think that should work.

You would also need to have "junctions" betweens lines and boxes, so a player could move from one box to another, or from one box to a line. This isn't much harder than checking the player hasn't hit a coordinate where a line ends and meets a box. You'd probably have to check a "zone" rather than an individual pixel though; the chances of a player hitting a certain pixel on a 800x600 (or higher) screen is pretty slim.

Hope this wasn't too long winded. If any of this is wrong, feel free to abuse me, shoot me down in flames etc.
Posted: 12th Jun 2003 01:37 Edited at: 12th Jun 2003 01:38
Wow highly appreciated, I don't usually reply to people's help unless I have tried what they have said, however, this time it seems highly rude to do so, so thankyou; I will try it all in different stages, and consult you for help if and when I need it (if you don't mind that is?).

Any other people got any other methods that they have in theory or have used before/are using?

I hear and I forget. I see and I remember. I do and I understand.
Posted: 12th Jun 2003 11:42 Edited at: 12th Jun 2003 11:44
I was planning on doing a little demo with a sorta map mask, with the valid locations on a bitmap like a mask. It'd probably look like your lines and boxes, only a little thicker. I'd have this in memory, and everytime the player clicks a location, it'd find the end location and move the player there. If you click on a wall and the floor is directly underneath, I'd move the end position down til it hits the floor, then move the character there.

This would allow much more detailed collision - but would use more memory. Also, by using different colours, you could specify the scale of the character on the screen, so you could walk away into the distance.

Van-B

My cats breath smells of cat food.
Posted: 12th Jun 2003 12:27
Wow, I talked you before on MSN didn't I Van, though you use DB, damn, because all of what you said would be cool, really cool.

So far with no background or detecting of collision I've got a sprite moving on a black screen, I have no idea how to get him to move diagnolly, instead of down/up then left/right, I know the gradient stuff but don't know how to impliment it, my code is below:

I hear and I forget. I see and I remember. I do and I understand.
Posted: 12th Jun 2003 15:20
I'll take a look tonight, but what I'd do is calculate the angle between the start and end point (using Atanfull and a distance function), then this can be used to calculate the X and Y speed, even the sprite set to use (if you have say, 8 directions that your character can face).

I don't think I'll have time tonight, but tommorow I'll take a look (assuming you don't sort it out before then).

Van-B

My cats breath smells of cat food.
Posted: 12th Jun 2003 19:27
Sorry - made a slight mistake. The gradient should be m#=(bottomrighty-toplefty) / (bottomrightx-topleftx).

My apologies. Typed all that in after a long day at work. Mongoose hands his head.

Don't mind you getting in touch if you're stuck.
Posted: 13th Jun 2003 01:10
Hey Nilrem, just sent you a pretty sweet little demo.

Van-B

My cats breath smells of cat food.
Posted: 18th Jun 2003 17:20 Edited at: 18th Jun 2003 17:20
Sorry for the late reply I'll have a look at it now.
Though I think I already did and it was cool, I don't know though, my head is in a haze, all these exams I've been doing heh.

Did you send it to merlin@accessroot.com or jammysa@hotmail.com Van?

I think I already saw it, was it the cool (small) looking Guybrush walking around on the screen, and he walks up the stairs?

If so, then many many thanks.

I hear and I forget. I see and I remember. I do and I understand.
Posted: 18th Jun 2003 18:44
Yeah, the cute little zelda style Guybrush dude - found him by accident through google!.

You can send him up the ladder as well. Let me know if there's anything you don't understand about it - it is fairly straightforward though - but you can do some neat tricks with the collision bitmap, like using it for item clicking etc. Also, it would'nt be too hard to make it scroll left and right with a bigger screen.

To properly see how the collision bitmap works, you should have it on the backdrop as a semi-transparent layer, that's how I made it, took all of 5 minutes to make up that scene.

Van-B

My cats breath smells of cat food.
Posted: 20th Jun 2003 01:50
Aye, cheers once again Van.

I hear and I forget. I see and I remember. I do and I understand.
Posted: 20th Jun 2003 20:05
Hi guys , One of you two wouldnt mind sending me a copy would youse? I too am interested in this effect.
If youse can be bothered my email is:

cut_me_own_throat_dibbler@hotmail.com

T.A.F.K.A.C.M.O.T.D
The Artist Formally Known As Cut_Me_Own_Throat_Dibbler
Posted: 21st Jun 2003 03:05
Thanks for emailing so quickly Van B

T.A.F.K.A.C.M.O.T.D
The Artist Formally Known As Cut_Me_Own_Throat_Dibbler
Posted: 21st Jun 2003 13:50
I am also interested in this. Could someone e-mail me a copy at :
william.paul.harper@ic.24.net

Thanks
RED GENERAL

My computer melts regulary - perhaps it likes being fondue
Posted: 22nd Jun 2003 15:36
http://www.grinders.withernsea.com/ar/pointnclick.zip

Click the above link to get the source file and media that Van has mentioned/emailed.

P.S. Saves you having to email loads of people Van, hope you don't mind, if you do, just say so and I'll take it down.

I hear and I forget. I see and I remember. I do and I understand.
Posted: 22nd Jun 2003 15:42
Thanks, as you said, much easier

RED GENERAL

My computer melts regulary - perhaps it likes being fondue
Posted: 22nd Jun 2003 16:05
Cheers Nilrem,

I'll be updating it next week sometime for items, scrolling, and scene changes/doors - but I'll upload it somewhere and post a link.

Van-B

My cats breath smells of cat food.
Posted: 24th Jun 2003 20:15 Edited at: 24th Jun 2003 20:23
Unfortuenatively there is a flaw in it at the moment, if you are downstairs and you click on an area upstairs, it gets stuck. Also somethimes it gets stuck anyway (probably becasue the white/black areas are not smooth.

Otherwise so far it is very good

thanks for it
RED GENERAL

My computer melts regulary - perhaps it likes being fondue
Posted: 25th Jun 2003 17:52
By the way, I am currently perfecting my menu system (designed to use less memory than anything else used for menu systmes). When it is complete (I am updating the version at the moment), I will donate the coding to include witht he download so that it has a working menu.

RED GENERAL

My computer melts regulary - perhaps it likes being fondue
Posted: 26th Jun 2003 02:14
Cool Van and Redgeneral, I'm looking forward to seeing both of them.

I hear and I forget. I see and I remember. I do and I understand.
Posted: 6th Jul 2003 14:39
I've been out of the loop for about a week, is the updated version up on the net yet?

RED GENERAL

My computer melts regulary - perhaps it likes being fondue
Posted: 6th Jul 2003 17:43
Not as far as I know, Van?

I hear and I forget. I see and I remember. I do and I understand.
Posted: 7th Jul 2003 00:51
The menu system has just been completed. The instruction manual is being written at the moment. Initial tests show it is very powerful with low memory drain - version 2 seems a success. Will update code onto forum as soon as pos.

Will upload demo soon onto my own website as soon as I can actuallymake the website.

RED GENERAL

My computer melts regulary - perhaps it likes being fondue
Posted: 7th Jul 2003 22:14
Cool, thanks for the info update Redgeneral.

I hear and I forget. I see and I remember. I do and I understand.
Posted: 10th Jul 2003 17:51
Developement of the website has begun, with a tutorial being included. Source files and examples will be able to be downloaded.

All images shoudl be very small in size - 22KB (greyscale) so it will be fast (hopefully!) to access.

Estamated time of completion: 1 - 2 weeks

RED GENERAL

My computer melts regulary - perhaps it likes being fondue
Posted: 10th Jul 2003 18:00
Sorry guys, I got sorta side-tracked. I will get a decent demo together this weekend. Anyone got some backdrops I could use to make a mini-adventure with?

Van-B

My cats breath smells of cat food.
Posted: 11th Jul 2003 13:40
I would make some, but I am currently putting up my website, so I don't have the time.

When I am done, I will send you all the details of my menu system Van B, including the parts of my website that tells you how it works. Hope to see the demo soon

RED GENERAL

My computer melts regulary - perhaps it likes being fondue
Posted: 14th Jul 2003 05:23
exactly what kind of mini-adventur backdrops do you need?

if you needed some quick you could make some like in george lucas' THX, just simple scenes, like a desert or somthing.
what resolution should they be?

Do or do not, there is no try. -Yoda
Posted: 19th Jul 2003 10:39
Why don't you just rip them from mi or mi2?

I hear and I forget. I see and I remember. I do and I understand.
Posted: 19th Jul 2003 16:40
Ripping is bad. Shows unoriginality.

~Morph/Kanzure
CodeNation
Posted: 19th Jul 2003 19:56
Licifer X,

That would be great, 3 or 4 screens that link together would be ideal, maybe a desert screen that scrolls too. 640x400 is a good resolution, but bigger if the screen scrolls.

Van-B

My cats breath smells of cat food.
Posted: 22nd Jul 2003 23:03
Is there a new version up yet? Sorry about the lateness of my menu system, but I am still putting up my website(http://leviathan_software0.tripod.com/) and I am also increasing my system to include a menu bar and sub menus.

Might take a little longer than expected

RED GENERAL

My computer melts regulary - perhaps it likes being fondue
Posted: 23rd Jul 2003 11:40
Nope, sorry guys - I don't want to even start it until I get some graphics together (the whole idea relies so heavily on the bitmaps), I can't draw to well - so I'm hoping somebody will donate some for me. Once I have the graphics it's only a few hours work.

Van-B

My cats breath smells of cat food.
Posted: 30th Jul 2003 21:06
how come whenever i goto a tripod site i get a ad that says 'your the thousanth person to visit this site', even if ive gotten the ad from that site 4 times?

Learn as if youll live forever, and give as if youll die tomorrow.
Posted: 30th Jul 2003 21:28
you mean i'm not the lucky one????????? damn!!! (-:

i think its cause tripod can't count?

Login to post a reply

Server time is: 2024-03-02 19:34:15
Your offset time is: 2024-03-02 19:34:15