Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | IHate |
I’m trying to implement interactions between tiles but I’m not quite sure how to handle the data.
Every tile have very specific interactions with other tiles that no other tile shares.
Right now I have a resource shared among all the tiles with the basic information every tile needs. I load all the resources into an Array and every resource index matches their tile_id.
And now I’m thinking how to add these very specific behaviours and conditions for every tile.
Should I add a variable for every resource in which I add a script with that tile’s specific behaviour? Is there a problem having multiple small scripts loaded all at once? Should these scripts be resources too because they are reference-counted?
Edit: The game is turn based so this conditions only need to be tested once per turn.
If anyone knows of a better way of handling the data for the tiles please let me know.
This seems like a problem that would end up like yandere dev’s code if not dealt properly, if i were to do something like this i’d use a switch statement but gdscript doesnt have that and using multiple if else statements would really affect performance So i dont really have an answer
Kurotsuki | 2021-03-13 07:37
Godot has the switch statement, it’s called a match if I remember correctly. What is that yandere?
estebanmolca | 2021-03-13 08:41
Table of Contents · Game Programming Patterns
estebanmolca | 2021-03-13 08:54
Just as estebanmoica said Godot has match
and I use it sometimes for example to check the type of tile and other things the godot documentation says its even has extra functionality over switches match doc:
match card_type:
TYPE.PATH:
path_tiles.append(mouse_tile)
continue
TYPE.ACTIVATION:
is_spell = true
removed_tile_id = map.get_cellv(mouse_tile)
if path_tiles.has(mouse_tile):
map.set_cellv(mouse_tile,0)
else:
map.set_cellv(mouse_tile,-1)
for dir in DIRECTIONS:
var neighbor_id = map.get_cellv(mouse_tile+dir)
if DB_tiles[neighbor_id] == null:
continue
elif neighbor_id != DBase.TILES.PATH && DB_tiles[neighbor_id].adjacent_effect:
adjacent_tile_effect("Remove",removed_tile_id,neighbor_id)
_:
if !is_spell:
map.set_cellv(mouse_tile,card_tile_id)
IHate | 2021-03-13 09:29
Thanks for the link it has a lot of concepts I didn’t know about
IHate | 2021-03-13 10:57