PDA

View Full Version : player port



tronied
06-03-2003, 03:57 PM
Currently, I have a grid with the player being drawn on with movement at about 110fps standing still and 60-70fps moving. What I was wanting to do was to make it like my last effort and re-create the player porting which I could do with the component based version. I created a procedure which I could call when the player stepped into a tile causing him to be ported to another tile reference. Currently it looks like this...

procedure DoMove (XRef, YRef : Integer);
for RowCount := 1 to 256 do
for ColCount := 1 to 256 do
begin
if XRef < PlayerX then
Sprite[RowCount.ColCount].X := Sprite[RowCount,ColCount].X -
(PlayerX * XRef);
end;

This seems to port me in the wrong place

This maybe wrong as I am in a rush and it is only for one of the XReferences and if statements... If you dont understand it... Dont worry about it... I will post again later

Useless Hacker
06-03-2003, 07:54 PM
What exactly do XRef and YRef represent?

tronied
06-03-2003, 08:55 PM
Urgh... What was I thinking earlier... Although I was being hassled by a girl so I will excuse myself :P

Anyway... Basically I have a class with an X, Y and Walkable variable which can be set to each of these. I also have created a 2D Array which stores which then uses this class as its base so I can have the following:

with Sprite[MyY,MyX] do
begin
X := 5;
Y := 5;
Walkable := 1; //1 = true, 0 = false
end;

Currently I am trying to make it so I can port the player to a particular location on the Grid. The X and Y parameters set where the player is supposed to go to. PlayerX and PlayerY are the current location of the players location on the grid. So if I use the following:

procedure TGame.PlayerPort (PosY,PosX : Integer);
var
ColCount, RowCount : Integer;
begin
for RowCount := 1 to 256 do
for ColCount := 1 to 256 do
begin
if PosX > PlayerX then
Sprite[RowCount,ColCount].X := (Sprite[RowCount,ColCount].X -
(GameTiles.Items[0].Width * (PosX - PlayerX)))
else if PosX < PlayerX then
Sprite[RowCount,ColCount].X := (Sprite[RowCount,ColCount].X +
(GameTiles.Items[0].Width * (PlayerX - PosX)));
if PosY > PlayerY then
Sprite[RowCount,ColCount].Y := (Sprite[RowCount,ColCount].Y -
(GameTiles.Items[0].Height * (PosY - PlayerY)))
else if PosY < PlayerY then
Sprite[RowCount,ColCount].Y := (Sprite[RowCount,ColCount].Y +
(GameTiles.Items[0].Height * (PlayerY - PosY)));
end;

GameSurface.Flip;
end;

This can then be called via the following :

PlayerPort (7, 7);

Therefore the main procedure is supposed to set each of the grid tiles to the distance which each of them are away from the DestinationX and Y. A flip would then be made and updated on the screen showing the new area for the player to walk around. However, this method appears to be working fine for actually placing the player in another location... it just isnt in the right place. For example if I want to port the user to X : 26, Y : 8 it sends me to X : 15, Y : 34. Another example is if I try to go to X : 13, Y : 13 it goes to X : 20, Y : 21... Is there a pattern to this?

Can anyone see anything wrong with what I am doing? I am not really worried about it being slow because it is only called once when I step on a tile which uses it. If not then it must be something else in the program altering the co-ordinates.

Thanks

Useless Hacker
07-03-2003, 09:54 AM
You don't need to check whether PosX < PlayerX, this should work the same as your code:

procedure TGame.PlayerPort (PosY,PosX : Integer);
var
ColCount, RowCount : Integer;
begin
for RowCount := 1 to 256 do
for ColCount := 1 to 256 do
begin
Sprite[RowCount,ColCount].X := (Sprite[RowCount,ColCount].X -
(GameTiles.Items[0].Width * (PosX - PlayerX)));
Sprite[RowCount,ColCount].Y := (Sprite[RowCount,ColCount].Y -
(GameTiles.Items[0].Height * (PosY - PlayerY)));
end;

GameSurface.Flip;
end;

tronied
07-03-2003, 10:02 AM
Thanks, I will give it a try...