Tiled-basic scrolling with tiles collision

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Rasmodius
Prole
Posts: 4
Joined: Fri Jun 09, 2017 5:43 pm

Tiled-basic scrolling with tiles collision

Post 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
Attachments
FreeFarm.love
(112.48 KiB) Downloaded 161 times
User avatar
drhayes
Prole
Posts: 5
Joined: Thu Jun 01, 2017 3:48 pm
Location: Austin, TX
Contact:

Re: Tiled-basic scrolling with tiles collision

Post 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.
User avatar
artofwork
Citizen
Posts: 91
Joined: Mon Sep 15, 2014 1:17 am
Location: East Coast USA

Re: Tiled-basic scrolling with tiles collision

Post 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.
User avatar
Rasmodius
Prole
Posts: 4
Joined: Fri Jun 09, 2017 5:43 pm

Re: Tiled-basic scrolling with tiles collision

Post 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
Attachments
FreeFarm.love
(326.6 KiB) Downloaded 149 times
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 22 guests