Coordinate System aproach?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
PowerCreek
Prole
Posts: 2
Joined: Tue Jun 14, 2016 9:57 am

Coordinate System aproach?

Post by PowerCreek »

Hey what's up guys. I'm working on a game.

This game involves a world with game objects in a top down perspective. Rotation is applied to the view of the world.

I want to know if there is a better way to do what I am doing...

Currently I am doing this:

-> Instantiate a data structure that holds grid points as keys. Keys hold a set of values per key IE: "[0,0]" : {Game Object 1,2..11}
This data structure is a Set Map of grid point that are determined by the "CELL_SIZE" constant of my world.
For example, I take the X and Y of the game object and do CELL_X,CELLY = math.floor(x/CELL_SIZE),math.floor(y/CELL_SIZE)

-> Instantiate a data structure that holds grid points as keys, the difference between this object and the previous Set Map is that I rotate the game object position and THEN floor the x,y as grid cell coordinates. This makes sure that the cells in the Set Map aren't just the top left corner of the object. If it covers 6 cells, and it only gets placed into 1, the drawing execution won't know it's supposed to be one of those 6 cells to be drawn in, since it didn't get placed where it is telling the screen it is visible.

-> Instantiate Game object "GO"
-> Apply World_Position to "GO", place into the first Set Map.

The game object applies itself into the Set Map with a function that the user defines how the object overlaps into the grid space's cells based on offsets and such.

-> Apply rotated Screen_Position to "GO", place into the second Set Map.

Set Map #2 is used to be iterated over when drawing what is supposed to be in the screen. (I believe this is the most efficient way to find what should be in the screen without checking every single object's rotation, and then drawing)

Now, is it wise to iterate through everything on the screen and compile into a layer object and then draw all of the objects at once?


ISSUES-
#1 Is there another way to determine how many cells in the grid an object can cover with a polygon?

#2 If an object rotates at its position, how do I deal with that? lol

#3 Every time an object moves, it has to remove all instances of its position from the grid maps, and then place itself back in. (It doesn't really matter since my game won't involve constantly adding and removing game objects, but still.

Image

I have mouse targeting working 100%. It uses the object's hitbox to determine if it has been picked in the world.
It involves rotating in the opposite angle of the game screen rotation, and then using the non-rotated grid Set Map to loop over the objects in the cell that the mouse resides in. I do this so the game object hitbox doesn't have to perform rotation

pastebinned code
http://pastebin.com/rGGSuaEn

Am I headed in the right direction?
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Coordinate System aproach?

Post by ivan »

Hello.
Am I headed in the right direction?
I'm not sure to be honest, it's not very clear what type of game you are trying to make.
Instantiate a data structure that holds grid points as keys. Keys hold a set of values per key IE: "[0,0]"
I will assume that by "grid point" you really mean "tile" or "cell".
There are two common ways to implement a grid of cells:
1.two dimensional table, ex: map[x][y] = cell
2.one dimensional table, ex: map[index] = cell, where index = (y - 1)*MAP_WIDTH + x
Is there another way to determine how many cells in the grid an object can cover with a polygon?
The maximum can be determined if your objects have a bounding box or radius.
If an object rotates at its position, how do I deal with that? lol
My suggestion is to avoid rotating your game objects using math.
Use the rotation when drawing your moving object, but don't rotate its hitbox (it shouldn't matter much if it's a circle or a square).
Every time an object moves, it has to remove all instances of its position from the grid maps, and then place itself back in. (It doesn't really matter since my game won't involve constantly adding and removing game objects, but still
If your objects can only move one tile/cell at a time it's ok.
If your objects move continuously then don't keep them in a grid.
PowerCreek
Prole
Posts: 2
Joined: Tue Jun 14, 2016 9:57 am

Re: Coordinate System aproach?

Post by PowerCreek »

It's a top down isometric game.
I'm not even sure why I made what I made. I think for rendering efficiently but now it doesn't seem so.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests