From 6112da2e6f7a4d695c8df483f5c207f452917f0c Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Fri, 27 Jan 2023 03:32:07 +0100 Subject: [PATCH] lib/game: Start working on game internals Btw: I lost the game. --- src/lib/game/block.cpp | 0 src/lib/game/block.hpp | 103 ++++++++++++++++++++++++++++++++++++++++ src/lib/game/entity.cpp | 0 src/lib/game/entity.hpp | 0 4 files changed, 103 insertions(+) create mode 100644 src/lib/game/block.cpp create mode 100644 src/lib/game/block.hpp create mode 100644 src/lib/game/entity.cpp create mode 100644 src/lib/game/entity.hpp diff --git a/src/lib/game/block.cpp b/src/lib/game/block.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/game/block.hpp b/src/lib/game/block.hpp new file mode 100644 index 0000000..7938846 --- /dev/null +++ b/src/lib/game/block.hpp @@ -0,0 +1,103 @@ +#pragma once + +#include + +namespace block { + + // For internal use only. These are examples, we will probably need + // a different way of assigning IDs in the future but a list should + // be fine for now, I guess. + // I don’t know how Minecraft assigns its IDs or if it even matters + // given that it has used string IDs for a while now. We just need an + // internal way to distinguish between classes. + namespace ids { + const uint16_t AIR = 0; + const uint16_t STONE = 1; + } + + // These are intended to be combined using bitwise OR. + namespace collisionBehavior { + // Let the block handle it. + // A function on the relevant block class will deal with it. + const uint8_t UNKNOWN = 0b00000000; + + // Collision box inhibits movement? + // (stone or stone slab) + const uint8_t SOLID = 0b00000001; + + // Does collision box fill entire block? + // (stone or grass block) + // + // The shape of the collision box is part of the relevant block class + // when this bit is unset. + const uint8_t FULL_BLOCK = 0b00000010; + + const uint8_t SOLID_FULL_BLOCK = SOLID | FULL_BLOCK; + + // Slow down entities when inside the block? + // (vines or soulsand) + // + // Entities are considered to be inside a given block when rounding + // their coordinates results in the coordinates of the block. + // + // The amount of slowdown is controlled by a function on the relevant + // block class. + const uint8_t SLOWDOWN = 0b00000100; + + // Slow down entities when touching the collision box of the block? + // (honey block) + // + // The amount of slowdown is controlled by a function on the relevant + // block class. + const uint8_t SURFACE_SLOWDOWN = 0b00001000; + + // Deal damage when entities are inside it? + // (berry bush) + // + // Entities are considered to be inside a given block when rounding + // their coordinates results in the coordinates of the block. + // + // The amount of damage is controlled by a function on the relevant + // block class. + const uint8_t DAMAGE = 0b00010000; + + // Deal damage when entities touch the collision box? + // (magma block) + // + // The amount of damage is controlled by a function on the relevant + // block class. + const uint8_t SURFACE_DAMAGE = 0b00010000; + + // Is the block bouncy? + // (bed or slime block) + // + // The bounciness of the block is handled by the relevant block class. + const uint8_t BOUNCY = 0b00100000; + } + + class Generic { + private: + public: + virtual uint16_t id() = 0; + virtual uint8_t collisionBehavior() = 0; + + //TODO: (not pure) virtual functions for collision box, slowdown, damage, bounciness, etc. + + //TODO: (not pure) virtual function for hitbox (defaults to full block) + } + + class Air { + public: + uint16_t id() { + return ids::AIR; + } + uint8_t collisionBehavior() { + // is a full block but doesn't collide or anything else + return collisionBehavior::FULL_BLOCK; + } + } + + BlockGeneric* getNewBlockFromID(uint16_t id) { + //TODO + } +} diff --git a/src/lib/game/entity.cpp b/src/lib/game/entity.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/game/entity.hpp b/src/lib/game/entity.hpp new file mode 100644 index 0000000..e69de29