Refactoring is Not Malarkey
Hey all,
I spent a decent chunk of time the last few days lamenting over a graphical glitch. Hours spent neglecting my children, 'forgetting' to sleep and eat. Hours I would not have spent if instead, I made an earlier decision to *refactor*.
See, with most games, it's really important that your artwork is, at all times... how do I put this... drawn in the right position. Unfortunately, the engine's ability to accomplish this was sharply limited by my seemingly eternal lack of discipline.
By adding more artwork, more drawing layers, into my already overloaded 'render' method, and not having one clean, consistent way of determining WHERE to put these layers in terms of x, y coordinates, the game loop swiftly lost faith in me and began producing a result that was the engine equivalent of a middle finger in the face.
Here's how it looked when I simply panned the screen. I don't remember adding an earthquake mechanic.
Ultimately, the problem boiled down to two important facts I had overlooked before I began taking everything apart:
- I used to know what the code was doing
- I do not know what the code is doing now
Enter REFACTORING. See, in a rare moment of clarity, I had the idea to adjust how only the lighting tiles were drawn. Instead of layering pre-drawn shaded squares on the screen, I would use Java's fillRect method to draw little black squares of varying opacity. To accomplish this, I needed to DRASTICALLY simplify how the world <> screen coordinate conversions were done.
Then:
The end result: great success.
Notice as I pan the screen, the lighting tiles following my cursor oh so nicely... unlike literally everything else.
By refactoring the way tiles were shaded, I actually solved the larger problem. Naturally, you'd expect me to recognize that I had done this. Instead, I spent the entire morning agonizing over the rest of the graphics engine. Why couldn't it behave itself properly? Because, dear readers, it got a taste of that sweet, sweet refactoring, and was on the verge of open rebellion.
Ladies and gentlemen, please be disciplined as you code and REFACTOR when your methods get unwieldy. You *will* forget what they are supposed to do. Take this as a cautionary tale. My children implore you.
:sniff: I love a story with a happy ending!
Cheers,
PajamaWolf
Get This Godforsaken Rock - Combat Demo
This Godforsaken Rock - Combat Demo
Sci-fi squad-based tactical RPG
Status | In development |
Author | PajamaWolf |
Genre | Strategy |
Tags | 2D, Dark, Pixel Art, Sci-fi, Tactical RPG, Top-Down, Turn-based Strategy |
Languages | English |
More posts
- Minor Update: AI and Performance ImprovementsApr 01, 2024
- Feature-Complete version is out!Mar 01, 2024
- Penultimate Demo Update: 0.7.6.0 (My Smart is Broken)Feb 20, 2024
- Small update: 0.7.5.1 (Catch Me If You Pan) aka Swing is a Lazy JerkFeb 13, 2024
- New gameplay video, bug crushingFeb 11, 2024
- This Godforsaken Rock Update 0.7.5 (Glad, Tutorial Combat)Feb 08, 2024
- Oh Shit Moments (belated warning: profanity)Feb 03, 2024
- A Teeny Update - Sound issues, med suppliesJan 31, 2024
- This Godforsaken Rock 0.7.4 (The 'Pew Pew' Update)Jan 31, 2024
- Major update version 0.7.3 (Update loop, graphics, UI overhaul)Jan 26, 2024
Leave a comment
Log in with itch.io to leave a comment.