Road to ECS
Intro
This is about teaching myself Entity-Component-System (ECS) pattern. My current goal is to implement a few basic features one by one to build a code snippet library, starting from just drawing things on screen. Code will be in my GitHub/road-to-ecs and also as cartridges in this blog thread.
Some personal background: [hidden]I'm a software engineer, professional coding background is a bit of data comms in C and lot of Java starting from 1.4, some Android and mostly Java EE for enterprise systems with web fronts. For the last 5 or so years I haven't really coded except shell or other script/configuration languages for automating configuration management, CI/CD and so on (nowadays they call it devops).
I've been interested in PICO-8 for some time, but finally got it as a part of the great itch.io Black Lives Matter bundle. To me gamedev is previously unknown territory and it's fun to learn how games differ from other applications.
Also playing around with PICO-8 on my summer vacation revealed how much brain capacity my dayjob takes. On work days there is no chance that I could do anything productive with PICO in the evening. Scary.
I'm used to (and like) working within frameworks. I got a bit of blank paper syndrome with PICO-8 initially :) First I tried to apply traditional OOP but it didn't feel like a good fit for games. Browsing this BBS I found about ECS and it feels like a better fit for game applications. Now I just have to bend my mindset to it!
Hi, I'm practicing how to do object oriented programming in PICO-8 but struggling a bit to map things in my head between OO design and actual game code. My practice project is doing MBoffin's top-down game tutorial with an OO approach but my long term goal is to do either a top-down adventure/rpg (=Zelda) or turn-based strategy (=UFO X-COM).
The reason I want to do OOP is my Java dev background and also personally I don't like procedural code, it feels so messy and cluttered. I'd like to have the behaviour and presentation of an entity in its class instead of spread around the application but that's the difficult part for me at the moment.
Bunch of questions:
- Is there any point of doing a class for a singleton entity, eg. player actor? As my player1 object will be the only instance I could as well have that and not bother with the prototype. Now I have something like this:
-- prototype player = {} function player:new(o) local o = o or {} setmetatable(o, self) [ [size=16][color=#ffaabb] [ Continue Reading.. ] [/color][/size] ](/bbs/?pid=79575#p) |
Woohoo I made my first game! Quite ugly (both graphics and code) but correctly working 3x3 tic-tac-toe for 2 players, no computer opponent. Also available at GitHub.
Hello world!
How can I make my code more like a library or a self-contained independent module/component? Here's a text scroller by me (my first published cart yay!). Currently you need to call three functions to use it:
function _init() scroller = init_scroller("lorem ipsum dolor sit amet, consectetur... ", 30, 5/30) end function _update() update_scroller() end function _draw() cls(0) draw_scroller(4, 60, 7) end |
I tried to write it more like an component but couldn't make it work. My idea was that init_scroller() would return "an object" which would contain everything. Then you'd call object.update() and object.draw() to use it and could create as many instances as needed. However my return object had just pointer to global functions and later instances overwrote earlier ones.