Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Refactoring

Name: Anonymous 2018-07-09 20:23

I am working on a game engine right now, and I want to redo the tile system so that every tile is an instance of a class, and each tile object maintains its own individual properties, like the image(s) that get displayed (there can be multiple layers), whether it's a blocking or non-blocking tile (for collision detection), any events (such as enemy encounters, NPCs, or moving the player to another map), etc. Then all I have to do is create a 2d array of these objects for the map.

But right now, my game has similar functionality (from the end user's standpoint), but the code base is a bunch of spaghetti. It's not modularized, not using the object stuff I was talking about, and the collision detection is a big if statement with a bunch of ORs to check for individual tiles instead of a boolean property within a tile object (like tileObj.isBlocking or something).

So should I start from the ground up, since I would have to redo so many things, or should I just refactor what I currently have? Or should I just try to add additional functionality on top of the spaghetti code?

Name: Anonymous 2018-07-10 20:37

>>3
It's not brainwashing. One of my collision detection checks happens when you press a button to move the character and it's kind of like this (I don't wanna be doxxed so I'm not gonna post the exact source):
if (tile.type = "blockingType1" || tile.type = "blockingType2" || tile.type = "blockingType3" || tile.type = "blockingType4")
instead of something like if (tileObj.isBlocking)
and there's a bunch of other bullshit too, like graphics aren't tied to the collision, when in reality, if you want to place a rock on the map, it should contain the graphics, the collision, the position, etc all in a single object instead of strewn across multiple primitive data type 2d arrays and images that have no relation to each other. It technically works, but not in a good way. I currently have graphics, collision detection, movement, and menus. But I want to make it better before making more things, like the combat system.

Right now, you have to edit a lot of shit in order to add just one more kind of tile or event that you can put on the map, but I want to make it easy to have n kinds of unique tiles without having n or statements when checking for collision, and there are a lot of other issues with scalability/extensibility that don't matter if you don't have much content, but matter a lot if you want to add more types of maps instead of just super basic floor and walls

There's also a memory leak in the level editor (if you use it for an extended period of time and replace tiles with other tiles multiple times) because I made it so it just adds new stuff at a set position but because I don't have proper classes I don't have good destructors and the memory management is overly complicated and doesn't properly delete everything at the moment.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List