Page 1 of 1

Tiled-basic scrolling with tiles collision

Posted: Fri Jun 09, 2017 5:47 pm
by Rasmodius
Hello,
I have problem with my game. I have created a map and a character. Also I have implemented tile-based scrolling.
My question is how i implement coliicion with specified tiles. For example water-tiles.
Here is th erepo of my game and a .love file attached:
https://gitlab.spline.inf.fu-berlin.de/ ... eeFarm.git

Re: Tiled-basic scrolling with tiles collision

Posted: Tue Jun 13, 2017 9:03 pm
by drhayes
I haven't looked *too* closely at your code, but since you are declaring your map as an array of numbers then you know, for each position on your map, what kind of tile it is. For example, you know if tile (4,3) is water, grass, inside a building, whatever.

As the player moves around in the world you can check what kind of tile they are intersecting with (no physics code required!) and change the player behavior based on that.

Re: Tiled-basic scrolling with tiles collision

Posted: Fri Jun 16, 2017 10:21 pm
by artofwork
The answer is right your code.
Lets use this fragment.

Code: Select all

  if love.keyboard.isDown('up') then
		player.direction = "up"
    if player.y > center_y then
      player.y = player.y - player.speed*dt
    else
      map_y = map_y - player.speed*dt
    end
    frames = FramesUP
    changeFrame()
1st thing it checks to make sure the 'up' arrow is being pressed, then you are assigning player its direction property a string with the words "up". The next if statement asks if player's property y is greater than center_y if it is assign player's property y the value of player.y - player.speed * dt.

Right here is your solution, the question you should be asking before you assign anything to player.y is the formula on the right, you should be comparing it to whatever object on the map you consider to be a collision type object, because once you assign player.y a value you have now changed the position of player.

Re: Tiled-basic scrolling with tiles collision

Posted: Wed Jun 21, 2017 12:48 pm
by Rasmodius
Thanks. I and my friend changed the movement completely. Here ist what we have:
https://gitlab.spline.inf.fu-berlin.de/gordon/FreeFarm