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
Tiled-basic scrolling with tiles collision
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Tiled-basic scrolling with tiles collision
- Attachments
-
- FreeFarm.love
- (112.48 KiB) Downloaded 168 times
Re: Tiled-basic scrolling with tiles collision
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.
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
The answer is right your code.
Lets use this fragment.
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.
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()
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
Thanks. I and my friend changed the movement completely. Here ist what we have:
https://gitlab.spline.inf.fu-berlin.de/gordon/FreeFarm
https://gitlab.spline.inf.fu-berlin.de/gordon/FreeFarm
- Attachments
-
- FreeFarm.love
- (326.6 KiB) Downloaded 160 times
Who is online
Users browsing this forum: No registered users and 17 guests