Can't get my sprite moving.
| Author |
Message |
Insectoid

|
Posted: Sat Feb 21, 2009 12:23 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
| is this going to be an ascii map?
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Razgriz

|
Posted: Sat Feb 21, 2009 12:45 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
What do you mean?
The example of my collision map is on page 1.
|
|
|
|
|
 |
Razgriz

|
Posted: Mon Feb 23, 2009 10:19 am Post subject: Collision detection :( |
|
|
Is anybody up to helping?
I've been trying to figure it out on my own but it's been... ... Less than successful.
|
|
|
|
|
 |
DemonWasp
|
Posted: Mon Feb 23, 2009 11:06 am Post subject: RE:Can\'t get my sprite moving. |
|
|
We need a bit more information about what you want your program to do; specifically, how does your character move?
If you want your character to move on a grid (he is in one square at a time and one square only) then you probably want to store his position (and the position of obstacles in the grid) as coordinates for your grid. Think of a grid like in Battleship, with letters on one axis and numbers on another (A9, B3, etc) except that instead of using letters, you'll need to use numbers in Turing.
If you want free movement (character isn't on a grid, which is more like real life) then that will be more complex, and you won't be able to use your ASCII map for detecting collisions very easily (it could be done, but it'd be pretty ugly).
|
|
|
|
|
 |
Razgriz

|
Posted: Mon Feb 23, 2009 11:09 am Post subject: RE:Can\'t get my sprite moving. |
|
|
In such a case, then, I would prefer the grid-type.
So, looking at the map that I drew on paint, How would I go about making the collisions?
For example, so the character doesn't go out-of-map, or through the rock, or over the water.
|
|
|
|
|
 |
DemonWasp
|
Posted: Mon Feb 23, 2009 11:52 am Post subject: RE:Can\'t get my sprite moving. |
|
|
If you're going for grid-based movement, you want something like this:
1. The location of each player, NPC and other creature in the game is given by their x and y coordinates, which refer to the column they're in. You probably want most characters to move by 1 grid unit at a time.
2. Each grid element has a different character for what it contains. You could use spaces for "passable space" and 'X' for impassable areas (map boundary, rocks, water, etc).
3. Every time a player (or other character) moves, check the grid square they want to move into - if it's a space (passable) then they can move through; if not then they stay where they are.
It looks a little like this:
| code: |
var playerX, playerY : int % These refer to the position IN THE GRID, not in pixels.
const GRID_SIZE : int := 15 % The number of pixels in each grid square. This is necessary for drawing players at the correct position on the map.
% Figure out the player's location somehow...
% Now let's make a structure to store our map (just a two-dimensional array of characters)
const MAP_PASSABLE : char := ' '
const MAP_IMPASSABLE : char := 'X'
var mapCols, mapRows : int % The size of the map
var map : array 1..mapCols, 1..mapRows of char
% Load the map from a file (see file below)
var stream : int
open, stream, "mymap", get
get : stream, mapCols
get : stream, mapRows
for r : 1..mapRows
for c : 1..mapCols
get : stream, map ( c, r )
end for
end for
% Main game loop
loop
% Get input here and determine what to do with it. This probably includes having variables "playerDestinationX", "playerDestinationY" which give the direction the player is headed in. Don't just move the player, as you still need to check against your grid (that's next).
% Check whether the player can move to their destination
if map ( playerDestinationX, playerDestinationY ) = MAP_PASSABLE then
% If they can, then move them there.
playerX := playerDestinationX
playerY := playerDestinationY
else
put "Can't move there!" % Or some more appropriate error message...
end if
% Draw stuff here as you've been doing. Don't forget to convert from grid-coordinates to pixel-coordinates (hint: this involves multiplying by the size of each grid unit - GRID_SIZE)
end loop
|
Now you need an input file that contains your map. This file is pretty simple; it just contains the number of rows in the map and the number of columns, then the map itself (X and space - I'm sure you can use find-and-replace to convert your existing map, or you can use your map and just change MAP_IMPASSABLE and MAP_PASSABLE above).
| code: |
10
5
XXXXXXXXXX
X XX X
X XX X
X XXX
XXXXXXXXXX
|
Edit: wooo 666 bits
|
|
|
|
|
 |
Razgriz

|
Posted: Mon Feb 23, 2009 1:19 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
Awesome, thanks.
I'll try this as soon as I'm able.
|
|
|
|
|
 |
Razgriz

|
Posted: Mon Feb 23, 2009 2:18 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
So okay,
'10
5 '
Presumably, the 10 and 5 are the length and width, right?
X's are where the character cannot go, and the blanks are where I can.
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
DemonWasp
|
Posted: Mon Feb 23, 2009 2:26 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
You need to know the length and the width (columns and rows) of the map. Technically you can get the size of the map other ways, but the easiest way is to just have the map-maker put it right in the file.
Essentially, you're correct.
|
|
|
|
|
 |
Razgriz

|
Posted: Mon Feb 23, 2009 2:29 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
So, logically, since I don't know the grid-dimentions on paint, how would I go about fitting it properly?
Like, the picture is 800x800 pixels, but theres not that many characters across.
Is there a different way of doing this?
|
|
|
|
|
 |
DemonWasp
|
Posted: Mon Feb 23, 2009 2:49 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
You have to decide how many pixels you want per grid square (see the GRID_SIZE constant). Your map-image's size will then have to be determined as follows:
The image will be (number of map columns) * GRID_SIZE pixels wide.
The image will be (number of map rows) * GRID_SIZE pixels tall.
|
|
|
|
|
 |
Razgriz

|
Posted: Mon Feb 23, 2009 4:35 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
Ahh. Okay, awesome stuff.
Thanks for all the help. I'm going to add your MSN, it's probably faster than this, and I'm not on this as much.
|
|
|
|
|
 |
Razgriz

|
Posted: Mon Feb 23, 2009 4:42 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
Oh, and, One more problem . . .
Not sure exactly why, but my character spawns off-map in the bottom corner, and I have to press the down and left arrow keys before I can see her.
How would I go about fixing this?
Mod Edit: No spaces in the syntax tags | code: | [syntax="turing"]Code Here[/syntax] |
|
|
|
|
|
 |
Razgriz

|
Posted: Mon Feb 23, 2009 4:55 pm Post subject: RE:Can\'t get my sprite moving. |
|
|
Eh, what if my map is now 5000 x 5000 pixels?XD;;
Would that change a great deal?
|
|
|
|
|
 |
DemonWasp
|
Posted: Mon Feb 23, 2009 10:54 pm Post subject: Re: Can't get my sprite moving. |
|
|
After an MSN session with Razgriz, the attached code and map emerged.
| Description: |
| Sample map, based in the bg.GIF file. Work-in-progress. |
|
 Download |
| Filename: |
sample.map |
| Filesize: |
1.65 KB |
| Downloaded: |
106 Time(s) |
| Description: |
| A combination of the existing Evermore code, some grid-based movement, and some code to make debugging / editing maps easier. |
|
 Download |
| Filename: |
Evermore.t |
| Filesize: |
6.77 KB |
| Downloaded: |
128 Time(s) |
|
|
|
|
|
 |
|
|