Grid in game

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
RezReb
Prole
Posts: 1
Joined: Wed Mar 01, 2023 7:15 pm

Grid in game

Post by RezReb »

How to make all objects in the game act on a grid? :o:
User avatar
darkfrei
Party member
Posts: 1197
Joined: Sat Feb 08, 2020 11:09 pm

Re: Grid in game

Post by darkfrei »

Make the metods for your objects and send the grid to them as object:update (grid, dt)
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
dusoft
Party member
Posts: 635
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Grid in game

Post by dusoft »

RezReb wrote: Wed Mar 01, 2023 7:23 pm How to make all objects in the game act on a grid? :o:
Each object (player, enemy, etc.) will have their position initialized using x and y coordinates. Then you can easily update it based on your algo and interaction and draw it.

E.g.:

Code: Select all

passengers[i] = {location = {x = start_x, y = start_y}, destination = {x = end_x, y = end_y}, walking = true, at_stop = false, waiting_for = false, on_board = false, dwell_time = dwell_time}
User avatar
togFox
Party member
Posts: 828
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Grid in game

Post by togFox »

Or

Code: Select all

local person = {}
person[1].x = 50
person[1].y = 50
person[2].x = 100
person[2].y = 20
...
you then have to translate that information to a grid in love.draw()
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
User avatar
darkfrei
Party member
Posts: 1197
Joined: Sat Feb 08, 2020 11:09 pm

Re: Grid in game

Post by darkfrei »

Actually the Bump.lua principle: one chunk (some bigger type of tile) can have multiple objects and one object can be in several chunks simultaneously.
https://github.com/kikito/bump.lua

Image
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
dusoft
Party member
Posts: 635
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Grid in game

Post by dusoft »

darkfrei wrote: Thu Mar 02, 2023 8:06 am Actually the Bump.lua principle: one chunk (some bigger type of tile) can have multiple objects and one object can be in several chunks simultaneously.
https://github.com/kikito/bump.lua
Sure, if you want something more complicated. If you just simply need to attach objects to a grid, both examples above will work.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests