Freddo@feddit.nu to Programmer Humor@programming.devEnglish · 2 days agoOOP at home:feddit.nuexternal-linkmessage-square76fedilinkarrow-up1329
arrow-up1329external-linkOOP at home:feddit.nuFreddo@feddit.nu to Programmer Humor@programming.devEnglish · 2 days agomessage-square76fedilink
minus-squareZILtoid1991@lemmy.worldlinkfedilinkarrow-up2·edit-219 hours agoNow someone needs to make it an entity component system! Attempt 1: public struct Entity { bool isDog : 1; bool isAircraftCarrier : 1; bool isFlea : 1; bool canFlyInAir : 1; ubyte opt_numOfAircrafts : 4; int entityID; int opt_parentID; static Entity createDog(int entityID) { Entity result; result.isDog = true; result.entityID = entityID; return result; } static Entity createFlea(int entityID) { Entity result; result.isFlea = true; result.canFlyInAir = true; result.entityID = entityID; return result; } void addAirCraft(ref Entity aircraft) { if (aircraft.canFlyInAir && this.isAircraftCarrier) { aircraft.opt_parentID = this.entityID; this.opt_numOfAircrafts++; } } void woof() { if (isDog) { if (isAircraftCarrier) writeln("I'm a motherfucking aircraft carrier"); else writeln("Woof!"); } } } void main() { Entity dog = Entity.createDog(1); Entity flea = Entity.createFlea(2); dog.woof(); dog.isAircraftCarrier = true; dog.addAirCraft(flea); dog.woof(); }
Now someone needs to make it an entity component system!
Attempt 1:
You forgot the component part.