Putting Lolo in a Puzzle Room
We’re developing our own engine from the ground up, with only a foundational library called LibGDX to handle graphics and input for us. We are doing nearly everything ourselves for maximum control as well as maximum learning. Here’s where we will begin:
Not exactly a “puzzle” per se, but getting this far still took a lot of thinking |
If you didn’t bring a time machine, you can borrow one Credit to Jeremy from Sydney, Attributions 2.0 Generic license, cropped slightly. Original image here: https://commons.wikimedia.org/wiki/File:DeLorean_DMC-12_(15704582713).jpg |
If we make a generic "Entity" interface in our code, then each kind of Entity can implement a draw() method and we can iterate over a collection of Entities calling draw() every frame. Each Entity will implement its draw method slightly differently, for example drawing a different image onto the screen, but the important thing is that our main class doesn't have to think about the differences between each Entity in order to draw() each Entity. I think that’s a pretty good start to a solid design.
What data structure will this collection use? Arrays have a rigidly defined size at start and they don’t grow well, but LinkedList is a very flexible kind of collection that can dynamically grow to whatever size we need, so let’s use a LinkedList to store all our Entities. We can have as many Entities as we want now:
I got a bit excited, maybe a bit carried away |
- The code is private and the team is small, meaning changes to the data structure we use have a very small impact with few repercussions
- There's no rigid expectations for the code yet, meaning we have great latitude to change code ad hoc
- We're in "greenfield" development i.e. totally new code, so even those who are impacted by changes like fellow developers ACalmMind and DevNull understand that the code will change wildly
Back to heart frames, each heart frame knows its own location and how to draw itself, so we can simply add more HeartFrame objects to our LinkedList. Each Entity instance will have unique coordinates, so we may have to add that to the Entity interface. Personally, I’m a big fan of not trying to guess what we’ll need in the future, so I won’t add more stuff to the interface until we know we need it. For now, each object can keep track of its own coordinates so that its draw() method knows where to draw the Entity’s sprite.
Just so everyone’s on the same page, the Eggerland games and Adventures of Lolo games are about moving Lolo around to collect all heart frames. Once all heart frames are collected, the chest will open up and Lolo can collect the shiny treasures within. That’s the core gameplay loop, made more interesting by the addition of other obstacles. Let’s create some of those obstacles.
A very exciting puzzle containing trees, rocks, water, emerald frames, and two conspicuous creatures |
Each new creature or rock or shrubbery will be represented by a new Entity class in the code, each with its own drawing logic. I’m also seeing we’ll need to give each Entity its own logical behavior too, because Lolo will behave very differently from Snakey and Medusa. An update() method on our Entity interface will provide the structure for that behavior.
Lolo’s update() method will allow him to move around pushing emerald frames and collecting heart frames. Medusa’s update will allow it to catch and petrify (catch-rify?) Lolo when he moves past. Snakey’s update will… do nothing.
It’s easy to use LibGDX’s keyboard input stuff to detect keystrokes and move Lolo based on the arrow keys. Things will get way more complicated than that in the future, but again, I’m going to take advantage of early flexibility to avoid overengineering things until we know more about what we’ll need. A simple proof-of-concept for Lolo’s movement will do for now.
Alright, a round-up of what we’re doing here:
- Creating a static fixed board
- Creating a collection of “Entity” objects
- Iterating over the Entity collection to both draw and update each Entity
- Implementing keyboard input for Lolo’s update, to give players control
I think this is a great start. Next we can build out behaviors for the individual Entities. There’s a lot I glossed over here, like the coordinate system I use and the frame rate, but I think we’ll discuss those in due time. I also glossed over concepts like arrays and linked lists. I assume readers would either know these already or that Google could fill in any knowledge gaps. Let me know in the comments if you want me to teach more about these core programming concepts or if the audience is happy for me to get more technical. Also, start thinking about Medusa, we’ll implement its behavior in the next technical update.
Comments
Post a Comment