|
-
Apr 8th, 2000, 09:59 PM
#1
Okay, I'm making a game that's suppose the have walls
(kind of like chip's challenge)
Say if there's a map that looks like this. Where 1 is on
the map, it's a wall on the game. Where 0 is on the map,
it's a blank space.
1111111111
1000000001
1000000001
1111000001
1000000001
1000000001
1111100001
1000000001
1000000001
1111111111
Okay, when the level is loaded, I load the pictures from
an image, creating Arrays for each box. Displaying them is
all fine and dandy but what I need to know is HOW do I
prevent the user (imgUser) from walking through the
walls? The walls are imgWall(Index).
If you do not understand the question please say so and
I will try to clear myself up.
-
Apr 8th, 2000, 10:44 PM
#2
Addicted Member
Try posting this in the games forum.
There are a lot of diffent answers to your question, but it depends on your core game play design. Can the character move freely or is it on a track (like Pacman)? Does the character move in "Pixel Steps" (ie moves only in small increments, as long as the direction is held) or does it move in "Fixed Steps" (ie for each press of a direction the character moves one whole 'block' in that direction, think of it like checkers where a piece can only move a square at a time)?
If the character moves in Fixed Steps then it as simple as checking the borders of the character's current square before an attempt to move is made. If any side is against a wall (you know the positions of the walls already) then that direction is disabled (ie you ignore control movement inputs for that direction).
If the character moves in Pixel Steps then it gets a little more complicated. You'll need to check your character's dimensions for collision detection against all available objects in the arena every time a movement is made. If there is a wall within the proposed movement then you deny the movement input.
This is only brief description of what you could do, but it should get you going though. Again, try posting this in the Game forum, there is alot more experience in this area at that forum.
Good Luck!
-
Apr 9th, 2000, 04:58 AM
#3
Yes, my character moves in Pixel Steps. Do you know
what the best method of detecting collision is?
-
Apr 9th, 2000, 08:12 AM
#4
New Member
Try something with the image top property and the left property. If the top property or so is so far to the wall then movement = false. If it is at a certain point, then movement = true. True might not be needed. Say your image name was image 1. and your place was like this:
(O being walls)
OXOOOOOOOOO
OXOOOOOOOOO
OXXXXXXXXXO
OOOOOOOOOXO
Now, as these are blocks, say, about 30 x 30 pixels each, and say your image is a 20x20.
So, 30 x 4.
120 down.
330 across.
You got that much, right?
Now, image1.top(your vertical location = 30 or less
image1.left = 60 to 30. Between there. Not equal to, I guess.
Now, I'm not sure of how your guy is gonna move(maybe key strokes..dunno), but say he goes left. Well, I suggest about 2.5 to 5 pixels per go, so, image1.left = image1.left - 2.5. If going right, + 2.5. Before that, put if image1. left > 30 and image1.left < 120(this all assuming you're starting on that X on the top). Got that much? You gotta do a little math, but other then that, it's easy. If you need more help, e-mail me([email protected])
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|