Check a tile's value before player moves to it?

0 favourites
  • 5 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • Hi,

    As you can see below, I want my player unit to move up on my tilemap. It does it successfully. However, now I would like to figure out a way to identify which type of tile the one-up is before the player goes there.

    For example, let's say the tile up from the player is a tree, and I want the player to chop the tree each time it tries to move up and the tree is in that tile up.

    I believe I have it set correctly except for being able to check before the player moves to the tile:

    tilemap.tileat(tilemap.positiontotilex(OverlandMapPlayer.x),tilemap.positiontotiley(OverlandMapPlayer.y))

    I assume I would need to add a condition that checks for the tile up from the player and then a sub-event or otherwise that will move the player if it is an open tile OR if it is a tree tile. I can then use my tree-chopping function/mechanic.

    Can you help me identify what I need to check? I assume I need to do tileID - 1 or tileID - Column, etc..., or is there something built in?

    The other idea I have is to move the player UP, then check what tile it is ON, run a checker function to see if it's a tree tile and then knockback the player to the original tile, while also completing a chop at the tree. Then rinse and repeat assuming AP > cost and tree hp > 0.

    Thanks!

  • tilemap.tileat(positiontotilex(player.x),position.tiley(player.y)) will get you the tile id at the player's current position.

    If you change that to positiontotilex(player.x)+1 or -1, that will get you right and left, while positiontotileY(player.y)+1 and -1 get you below and above (I think? if tiles increment right and down).

    Check the tile contents on key pressed, before moving. If it's a valid move, then move, otherwise, do whatever else.

  • Thanks. I understand what you're saying. I'll give it a whirl. Tilemap reminds me of Microsoft Excel spreadsheets but no offset() function here - well, unless I build one. :-)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Does what I need!

  • Function:

    TileAtOffset(x0,y0,dx,dy)

    Return Tilemap.tileat(tilemap.positiontotilex(x0)+dx,tilemap.positiontotiley(y0)+dy)

    Where x0 and y0 are your original coordinates in pixels (mouse.x,y or player.x,y) and dx and dy is the offset in tile index, which can be any integer -1, 0, 1, 2, ect.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)