Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Character Movement Restrictions
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jamonathin




PostPosted: Wed Mar 23, 2005 6:33 pm   Post subject: Character Movement Restrictions

This Tutorial explains how to make a character walk around on a good looking map, without walking on water/through buildings/mountains or whatever, and also without sitting there and calculation every coordinate of everywhere you dont want him to go.

Like everyone says, we have to use whatdotcolor, which i think is the easiest way to do it. What you first have to do is take your map, and make a second copy of it. Now what you do with the copy, is open it up in paint (personal fav.) or w/e, and find an easy color (yellow) to mark up all the places you want him to walk on, or not walk on, pick one.
Your finished copy should look like the regular map only with the yellow brick road.

Now lets say your map has a small tunnel or something where your character should be walking underneath it, mark that area with a different color, such as brightred (turing color 12).

Now make you new file, set the appropriate limits on it, and set and array of int's to the pictures. DON'T use Pic.ScreenLoad, that means every time you draw the pic, turing has to load it from its source file, and that'll take forever, use Pic.FileNew. While you're there, var your character pic (this one is obviously just very basic) as well the player co-ordiate vars, button variable, and a boolean variable if you have an area where the character goes underneath something.
code:
setscreen ("graphics:263;365,nobuttonbar,position:center;center,offscreenonly")
var map : array 1 .. 2 of int
map (1) := Pic.FileNew ("map1c.bmp")
map (2) := Pic.FileNew ("map1e.bmp")
var mrhappy : int := Pic.FileNew ("mrhappy.bmp")
var x, y : int := 50
var show : boolean := true
var key : array char of boolean

Now that you have that done, make a procedure. What you're going to want to do in that procedure is Draw the Edited picture and check where the player is (yellow, red, neither) before you draw the good pic.
code:

cls
    Pic.Draw (map (2), 0, 0, picCopy)
    if key (KEY_LEFT_ARROW) and x > 10 and whatdotcolor (x - 10, y) = yellow then
...... blah blah blah
end if
    Pic.Draw (map (1), 0, 0, picCopy)

Now that you have checked the location of the player and drawn the good pic, it's time to draw mrhappy.
Since earlier we var'd " show : boolean ", we need to use that for when we decide to draw mrhappy. Now in our If statements, that is where we would determine if "show" was false/true. Which leads us to this.
code:

if show then
        Pic.Draw (mrhappy, x - 8, y, picMerge)
    end if
    View.Update
end refresh

And we end off the procedure with View.Update because we are using "offscreenonly" in our setscreen command for smooth animation.
If you're going to add anything else into the picture, just make sure it's after the good copy is drawn.
Now our loop is very small, which is good, because that means it's more organized Wink .
code:

loop
    Input.KeyDown (key)
    refresh
    delay (10)
end loop

and obviously the delay is just there so mrhappy doesn't run around like a speed addict.Scramble

Now the one downside to doing this is that drawing the edited picture may take some time, and it will take twice as long to load, but it's not that bad, because you can then make your program look pro by puting a REAL loading sign, rather than a lame fake one.

Here's the Finished product . . . Enjoy! Smile



restriction tutorial.zip
 Description:
Press Download '_' ->

Download
 Filename:  restriction tutorial.zip
 Filesize:  58.73 KB
 Downloaded:  656 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
ssr




PostPosted: Wed Mar 23, 2005 10:59 pm   Post subject: (No subject)

lol thats a nice tutorial
Very Happy
a nice way for restrictions
gjgjgj
Mazer




PostPosted: Thu Mar 24, 2005 9:46 am   Post subject: Re: Character Movement Restrictions

jamonathin wrote:
Like everyone says, we have to use whatdotcolor, which i think is the easiest way to do it.

I've really got to disagree with you there. Not only with the claim that everyone sees you have to use whatdotcolour (Honestly, I don't know if even dodge will go on preaching about using it), but also with the claim that it's easier.
If you were making pong, then sure it'd be easier. In something like this you've got too many colours to do whatdotcolor simply, which is why you've had to make another collision image with walkable areas masked in yellow. What's wrong with this?
1) You have to load two images for your map. You have to draw two images for your map each frame.
2) Your map is just an image file. Are you going to make a whole game by taking screenshots of Final Fantasy 3?

What you should do is make a map editor. You can use that to load tiles and place them easily, and then since the map is already made into a grid (a two dimensional array), you can just define each tile to be walkable or not.

PS, not to be a nuisance but it seems something was messed up a bit with the collision map. The right half appears to be shifted over by a pixel and something strange is going on with the front of the buildings by the alley.
jamonathin




PostPosted: Thu Mar 24, 2005 3:17 pm   Post subject: (No subject)

In the submissions, i had already made a program that you can use using basic squares/rectangles http://www.compsci.ca/v2/viewtopic.php?t=8051. I have a more fixed version of this, after tony helped me out. And the purpose for this tutorial is for people who want a different approach to using collision methods for an rpg or whatever, and i understand that it is not perfect, i just thought i'd show people it anyways.
TheEvilOne




PostPosted: Tue Mar 29, 2005 2:44 pm   Post subject: (No subject)

Or, if you want to do it this way, you can download Mappy Editor, or some similar editor, load the tiles, and export as a .bmp file. I find that easier than programming a tile interpreter Confused
jamonathin




PostPosted: Tue Mar 29, 2005 5:09 pm   Post subject: (No subject)

Whatever's easiest and works. If it's not broken dont fix it Smile
Cervantes




PostPosted: Tue Mar 29, 2005 5:15 pm   Post subject: (No subject)

jamonathin wrote:
Whatever's easiest and works. If it's not broken dont fix it Smile

You know, I really don't like that quote. For example, if someone built, oh, let's say a solar death ray that heated the object up to 200°C, it as a whole is definately not broken. But we could fix some aspects of it so that it heats the object up to 300°C!
TheEvilOne: thanks for the link (err, program name. A quick google will get the link though), it looks interesting. I especially like that they released the source. It must be good, then! Very Happy
jamonathin




PostPosted: Tue Mar 29, 2005 5:22 pm   Post subject: (No subject)

hmmm... that makes sense. So, how about, if it's not broken, make it better? Confused

P.S. - I've always wanted to see a solar death ray Burn
Sponsor
Sponsor
Sponsor
sponsor
TheEvilOne




PostPosted: Tue Mar 29, 2005 8:28 pm   Post subject: (No subject)

I do a lot of BlitzBasic programming and I use it Smile

With this method of collision, it works well, because... well because its just more simple Rolling Eyes

http://www.geocities.com/SiliconValley/Vista/7336/robmpy.htm for anyone whose interested

and really nice tut. I had just figured out this method, and made my own version, then I came on here and found it was on here already... after posting it myself and making a fool of myself Confused
iker




PostPosted: Mon Nov 07, 2005 5:52 pm   Post subject: (No subject)

Hey, i thought of a way to make it so that your character doesn't dissapear when under something. Have another picture with just the parts that need to be drawn ontop and have that picture drawn after the character.
for example as you said before but inclue another variable
code:

setscreen ("graphics:263;365,nobuttonbar,position:center;center,offscreenonly")
var map : array 1 .. 2 of int
map (1) := Pic.FileNew ("bottomlayer.bmp")
map (2) := Pic.FileNew ("restrictionlayer.bmp")

%the new needed line
top := Pic.FileNew ("toplayer.bmp")

var mrhappy : int := Pic.FileNew ("character.bmp")
var x, y : int := 50
var show : boolean := true
var key : array char of boolean


then when you draw the character, draw the toplayer right after

code:

if show then
    Pic.Draw (mrhappy, x - 8, y, picMerge)
    Pic.Draw (top, 0,0,picMerge)
    end if
    View.Update
end refresh


and there you go, now the character doesn't randomly dissapear after half under an object[/code]
Mr. T




PostPosted: Mon Nov 07, 2005 7:37 pm   Post subject: Alex's Opinion

You forgot to add the picture files.
Cervantes




PostPosted: Mon Nov 07, 2005 8:22 pm   Post subject: (No subject)

And why would they be necessary? Just look at the code. (Not that I have...)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: