Results 1 to 5 of 5

Thread: player port

  1. #1

    player port

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

    [pascal]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;[/pascal]

    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

  2. #2

    player port

    What exactly do XRef and YRef represent?
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

  3. #3

    player port

    Urgh... What was I thinking earlier... Although I was being hassled by a girl so I will excuse myself

    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:

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

    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:

    [pascal]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;[/pascal]

    This can then be called via the following :

    [pascal]PlayerPort (7, 7);[/pascal]

    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

  4. #4

    player port

    You don't need to check whether PosX < PlayerX, this should work the same as your code:

    [pascal]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;[/pascal]
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

  5. #5

    player port

    Thanks, I will give it a try...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •