From dead36fb811244c920a2f1246174cf15a32f0cf8 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Sun, 7 Aug 2022 11:31:02 +0600 Subject: [PATCH 01/26] birch log and leaves loading --- include/images.h | 2 ++ source/block.cpp | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/images.h b/include/images.h index f251bc68..ac224d36 100644 --- a/include/images.h +++ b/include/images.h @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include #include #include #include diff --git a/source/block.cpp b/source/block.cpp index e2cf8f74..7feb0989 100644 --- a/source/block.cpp +++ b/source/block.cpp @@ -5,7 +5,9 @@ glImage sprSnowyGrass[1]; glImage sprDirt[1]; glImage sprStone[1]; glImage sprWood[1]; +glImage sprBirchWood[1]; glImage sprLeaves[1]; +glImage sprBirchLeaves[1]; glImage sprSand[1]; glImage sprSandstone[1]; glImage sprCactus[1]; @@ -37,7 +39,9 @@ void loadBlockTextures(void) loadImage(sprDirt, 16, 16, dirtBitmap); loadImage(sprStone, 16, 16, stoneBitmap); loadImage(sprWood, 16, 16, oak_logBitmap); + loadImage(sprBirchWood, 16, 16, birch_logBitmap); loadImage(sprLeaves, 16, 16, oak_leavesBitmap); + loadImage(sprBirchLeaves, 16, 16, birch_leavesBitmap); loadImage(sprSand, 16, 16, sandBitmap); loadImage(sprSandstone, 16, 16, sandstoneBitmap); loadImage(sprPlanks, 16, 16, planksBitmap); @@ -159,8 +163,7 @@ FlowerBlock::FlowerBlock(s16 x, s16 y, FlowerType type) : Block(x, y) void FlowerBlock::draw(Camera camera) { - glSprite(x - camera.x, y - camera.y, GL_FLIP_NONE, type == FlowerType::Dandelion ? - sprDandelion : sprPoppy); + glSprite(x - camera.x, y - camera.y, GL_FLIP_NONE, type == FlowerType::Dandelion ? sprDandelion : sprPoppy); } bool FlowerBlock::solid(void) @@ -174,7 +177,7 @@ std::string FlowerBlock::id(void) { default: return ""; - + case FlowerType::Poppy: return "poppy"; case FlowerType::Dandelion: From e3c423536ae8e1bbfbaeaf3f8099915f9758076d Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 17:45:04 +0600 Subject: [PATCH 02/26] update world_label_select.png --- gfx/world_label_select.png | Bin 209 -> 209 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/gfx/world_label_select.png b/gfx/world_label_select.png index 8f50ee5818cf80c27d6ee62726af1caf8ca0e92d..9cc9349c86382fa6b14587feca3f06505a27f430 100644 GIT binary patch delta 38 rcmcb}c#&~}kBqLauG+GI2nGfQ&H|6fVg?4jgCNYfV`BE(i5Zyy(?tu% delta 38 rcmcb}c#&~}j|>kF&;9$AMhpxLoCO|{#S9F5hd`K7RKu%bVn!wa*)R&h From bed9f2ad28f0c2c603695d226a17ac8dd01f40ce Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 18:01:29 +0600 Subject: [PATCH 03/26] birch added --- .vscode/c_cpp_properties.json | 9 +- include/block.hpp | 99 ++++++------ include/player.hpp | 9 +- source/block.cpp | 18 ++- source/entity.cpp | 20 ++- source/main.cpp | 103 ++++++------ source/player.cpp | 284 +++++++++++++++++++--------------- source/save.cpp | 31 +++- source/terrain.cpp | 157 +++++++++++-------- 9 files changed, 432 insertions(+), 298 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 6dcbbdbe..982e5338 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -11,9 +11,14 @@ "/mnt/d/devkitPro/devkitARM/arm-none-eabi/include/**", "D:/devkitPro/libnds/include/", "D:/devkitPro/libnds/include/**", - "D:/devkitPro/devkitARM/arm-none-eabi/include/" + "D:/devkitPro/devkitARM/arm-none-eabi/include/", + "E:/devkitPro/libnds/include/", + "E:/devkitPro/libnds/include/**", + "E:/devkitPro/devkitARM/arm-none-eabi/include/" + ], + "defines": [ + "ARM9" ], - "defines": ["ARM9"], "compilerPath": "/usr/bin/gcc", "cStandard": "gnu17", "cppStandard": "gnu++14", diff --git a/include/block.hpp b/include/block.hpp index a4307a47..6036ea2a 100644 --- a/include/block.hpp +++ b/include/block.hpp @@ -15,57 +15,57 @@ // don't have anything really special. // They are used to save a lot of typing when // adding a new block. -#define GENERIC_BLOCK_IMPL(block, spr, id_) \ - block::block(s16 x, s16 y) : Block(x, y) \ - { \ - } \ - void block::draw(Camera camera) \ - { \ +#define GENERIC_BLOCK_IMPL(block, spr, id_) \ + block::block(s16 x, s16 y) : Block(x, y) \ + { \ + } \ + void block::draw(Camera camera) \ + { \ glSprite(x - camera.x, y - camera.y, GL_FLIP_NONE, spr); \ - } \ - std::string block::id(void) \ - { \ - return id_; \ - } \ - Rect block::getRect(void) const \ - { \ - return Rect(x, y, 16, 16); \ - } \ - bool block::solid(void) \ - { \ - return true; \ + } \ + std::string block::id(void) \ + { \ + return id_; \ + } \ + Rect block::getRect(void) const \ + { \ + return Rect(x, y, 16, 16); \ + } \ + bool block::solid(void) \ + { \ + return true; \ } -#define NONSOLID_BLOCK_IMPL(block, spr, id_) \ - block::block(s16 x, s16 y) : Block(x, y) \ - { \ - } \ - void block::draw(Camera camera) \ - { \ +#define NONSOLID_BLOCK_IMPL(block, spr, id_) \ + block::block(s16 x, s16 y) : Block(x, y) \ + { \ + } \ + void block::draw(Camera camera) \ + { \ glSprite(x - camera.x, y - camera.y, GL_FLIP_NONE, spr); \ - } \ - std::string block::id(void) \ - { \ - return id_; \ - } \ - Rect block::getRect(void) const \ - { \ - return Rect(x, y, 16, 16); \ - } \ - bool block::solid(void) \ - { \ - return false; \ + } \ + std::string block::id(void) \ + { \ + return id_; \ + } \ + Rect block::getRect(void) const \ + { \ + return Rect(x, y, 16, 16); \ + } \ + bool block::solid(void) \ + { \ + return false; \ } // Same thing as above except for declarations. -#define GENERIC_BLOCK_DECL(block) \ - class block : public Block \ - { \ - public: \ - block(s16 x, s16 y); \ +#define GENERIC_BLOCK_DECL(block) \ + class block : public Block \ + { \ + public: \ + block(s16 x, s16 y); \ void draw(Camera camera) override; \ - std::string id(void) override; \ + std::string id(void) override; \ Rect getRect(void) const override; \ - bool solid(void) override; \ + bool solid(void) override; \ }; void loadBlockTextures(void); @@ -77,6 +77,12 @@ enum class FlowerType Poppy, }; +enum class LeavesType +{ + Oak, + Birch, +}; + class Block { public: @@ -99,6 +105,7 @@ GENERIC_BLOCK_DECL(SnowyGrassBlock) GENERIC_BLOCK_DECL(DirtBlock) GENERIC_BLOCK_DECL(StoneBlock) GENERIC_BLOCK_DECL(WoodBlock) +GENERIC_BLOCK_DECL(BirchWoodBlock) GENERIC_BLOCK_DECL(SandBlock) GENERIC_BLOCK_DECL(SandstoneBlock) GENERIC_BLOCK_DECL(CactusBlock) @@ -117,7 +124,9 @@ class LeavesBlock : public Block bool natural; // true if grown from sapling or if generated by world public: - LeavesBlock(s16 x, s16 y, bool natural = true); + LeavesType type; + + LeavesBlock(s16 x, s16 y, LeavesType type, bool natural = true); void draw(Camera camera) override; bool solid(void) override; @@ -168,7 +177,7 @@ class SaplingBlock : public Block public: SaplingBlock(s16 x, s16 y); - + void draw(Camera camera) override; bool solid(void) override; void interact(void) override; diff --git a/include/player.hpp b/include/player.hpp index fd40def3..5f0c66a4 100644 --- a/include/player.hpp +++ b/include/player.hpp @@ -13,7 +13,10 @@ #include #include #include -#define NULLITEM {InventoryItemID::None, 0} +#define NULLITEM \ + { \ + InventoryItemID::None, 0 \ + } #define PLAYER_WIDTH 12 #define PLAYER_HEIGHT 32 @@ -24,7 +27,9 @@ enum class InventoryItemID Dirt, Stone, Wood, + BirchWood, Leaves, + BirchLeaves, Sand, Sandstone, Cactus, @@ -81,7 +86,7 @@ class Player void setHealth(s16 health); void restoreHealth(void); void resetInventory(void); - + bool moving(s16 oldX); bool dead(void); bool isInventoryFull(void); diff --git a/source/block.cpp b/source/block.cpp index 7feb0989..2add4461 100644 --- a/source/block.cpp +++ b/source/block.cpp @@ -111,21 +111,31 @@ GENERIC_BLOCK_IMPL(CoalOreBlock, sprCoalOre, "coal ore") GENERIC_BLOCK_IMPL(CoalBlock, sprCoalBlock, "coal block") NONSOLID_BLOCK_IMPL(WoodBlock, sprWood, "wood") +NONSOLID_BLOCK_IMPL(BirchWoodBlock, sprBirchWood, "birch wood") NONSOLID_BLOCK_IMPL(CactusBlock, sprCactus, "cactus") NONSOLID_BLOCK_IMPL(DeadBushBlock, sprDeadBush, "dead bush"); // non-generic implementations -LeavesBlock::LeavesBlock(s16 x, s16 y, bool natural) : Block(x, y) +LeavesBlock::LeavesBlock(s16 x, s16 y, LeavesType type, bool natural) : Block(x, y) { this->natural = natural; + this->type = type; } void LeavesBlock::draw(Camera camera) { - // draw leaves in dark green - glColor(RGB15(0, 22, 0)); - glSprite(x - camera.x, y - camera.y, GL_FLIP_NONE, sprLeaves); + switch (type) + { + case LeavesType::Oak: + glColor(RGB15(0, 22, 0)); + glSprite(x - camera.x, y - camera.y, GL_FLIP_NONE, sprLeaves); + break; + case LeavesType::Birch: + glColor(RGB15(20, 26, 19)); + glSprite(x - camera.x, y - camera.y, GL_FLIP_NONE, sprBirchLeaves); + break; + } glColor(RGB15(31, 31, 31)); // reset color } diff --git a/source/entity.cpp b/source/entity.cpp index 52fc7441..1700ca1f 100644 --- a/source/entity.cpp +++ b/source/entity.cpp @@ -7,7 +7,9 @@ extern glImage sprGrass[1]; extern glImage sprDirt[1]; extern glImage sprStone[1]; extern glImage sprWood[1]; +extern glImage sprBirchWood[1]; extern glImage sprLeaves[1]; +extern glImage sprBirchLeaves[1]; extern glImage sprSand[1]; extern glImage sprSandstone[1]; extern glImage sprCactus[1]; @@ -78,14 +80,12 @@ PigEntity::PigEntity(s16 x, s16 y) : Entity(x, y), damageOverlayTimer(255) void PigEntity::draw(Camera camera) { glSpriteScale(x - camera.x - (facing == Facing::Left ? 17 : 0), y - camera.y, - (1 << 12) * 1.25f, facing == Facing::Right ? GL_FLIP_NONE : - GL_FLIP_H, sprPig); + (1 << 12) * 1.25f, facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H, sprPig); if (damageOverlayTimer != 255) { glPolyFmt(POLY_ALPHA(15) | POLY_CULL_NONE | POLY_ID(9)); glSpriteScale(x - camera.x - (facing == Facing::Left ? 17 : 0), y - camera.y, - (1 << 12) * 1.25f, facing == Facing::Right ? GL_FLIP_NONE : - GL_FLIP_H, sprPigDamage); + (1 << 12) * 1.25f, facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H, sprPigDamage); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE | POLY_ID(9)); } } @@ -238,12 +238,20 @@ void DropEntity::draw(Camera camera) glSpriteScale(x + 4 - camera.x, y + 4 - camera.y, HALFSIZE, GL_FLIP_NONE, sprStone); else if (blockid == "wood") glSpriteScale(x + 4 - camera.x, y + 4 - camera.y, HALFSIZE, GL_FLIP_NONE, sprWood); + else if (blockid == "birchwood") + glSpriteScale(x + 4 - camera.x, y + 4 - camera.y, HALFSIZE, GL_FLIP_NONE, sprBirchWood); else if (blockid == "leaves") { glColor(RGB15(0, 22, 0)); glSpriteScale(x + 4 - camera.x, y + 4 - camera.y, HALFSIZE, GL_FLIP_NONE, sprLeaves); glColor(RGB15(31, 31, 31)); } + else if (blockid == "birchleaves") + { + glColor(RGB15(0, 22, 0)); + glSpriteScale(x + 4 - camera.x, y + 4 - camera.y, HALFSIZE, GL_FLIP_NONE, sprBirchLeaves); + glColor(RGB15(31, 31, 31)); + } else if (blockid == "sand") glSpriteScale(x + 4 - camera.x, y + 4 - camera.y, HALFSIZE, GL_FLIP_NONE, sprSand); else if (blockid == "sandstone") @@ -285,7 +293,7 @@ void DropEntity::update(BlockList &blocks, Camera camera, u16 frames) y - camera.y < -40 || y - camera.y > SCREEN_HEIGHT + 32) return; - + y += velY; if (falling) { @@ -307,7 +315,7 @@ void DropEntity::update(BlockList &blocks, Camera camera, u16 frames) if (!block->solid()) continue; - + if (block->getRect().intersects(getRect())) { velY = 0; diff --git a/source/main.cpp b/source/main.cpp index 03ad9e27..954fb11e 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -161,9 +161,9 @@ int main(int argc, char **argv) 256, font_smallPal, reinterpret_cast(font_smallBitmap)); fontSmallRu.load(fontSmallRuImg, FONT_SI_NUM_IMAGES, font_si_texcoords, GL_RGB256, - TEXTURE_SIZE_64, TEXTURE_SIZE_128, - GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF | GL_TEXTURE_COLOR0_TRANSPARENT, - 256, font_small_ru1Pal, reinterpret_cast(font_small_ru1Bitmap)); + TEXTURE_SIZE_64, TEXTURE_SIZE_128, + GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF | GL_TEXTURE_COLOR0_TRANSPARENT, + 256, font_small_ru1Pal, reinterpret_cast(font_small_ru1Bitmap)); fontRu.load(font16x16RuImg, FONT_16X16_NUM_IMAGES, font_16x16_texcoords, GL_RGB256, TEXTURE_SIZE_64, TEXTURE_SIZE_512, GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF | GL_TEXTURE_COLOR0_TRANSPARENT, @@ -209,28 +209,28 @@ int main(int argc, char **argv) loadImage(direntGames, 64, 64, dirent_gamesBitmap); - GameState gameState = + GameState gameState = #if SKIP_SPLASH_SCREEN fsFileExists("config/lang.cfg") ? GameState::Menu : GameState::LanguageSelect #else GameState::SplashScreen #endif ; - Camera camera = {0, 0}; // camera - u16 frames = 0; // frames (wraps around to 0 when hits 65535) - u8 saveTextTimer = 0; // save text timer when it hides + Camera camera = {0, 0}; // camera + u16 frames = 0; // frames (wraps around to 0 when hits 65535) + u8 saveTextTimer = 0; // save text timer when it hides s16 direntx = SCREEN_WIDTH / 2 - 32; // splash screen dirent logo x pos - s16 direnty = -64; // splash screen dirent logo y pos - u8 direntColor = 31; // splash screen dirent logo darkness factor - u8 wsSelected = 0; // selected world - u8 lsSelected = 0; // selected language - std::vector wsWorlds; // worlds in world select - bool saveTextShow = false; // should we show the text that we saved? - bool paused = false; // is the game paused - std::string worldName = ""; // world name - std::string createWorldName = ""; // world name (for create world) - bool createWorldDuplError = false; // show duplicate world name error in create world? - u8 settingsSelect = 0; // selected sttting + s16 direnty = -64; // splash screen dirent logo y pos + u8 direntColor = 31; // splash screen dirent logo darkness factor + u8 wsSelected = 0; // selected world + u8 lsSelected = 0; // selected language + std::vector wsWorlds; // worlds in world select + bool saveTextShow = false; // should we show the text that we saved? + bool paused = false; // is the game paused + std::string worldName = ""; // world name + std::string createWorldName = ""; // world name (for create world) + bool createWorldDuplError = false; // show duplicate world name error in create world? + u8 settingsSelect = 0; // selected sttting while (true) { // scan keys @@ -298,7 +298,7 @@ int main(int argc, char **argv) // magic for converting block into sapling Block *b = block.get(); SaplingBlock *sapling = (SaplingBlock *)b; // here i dont use reinterpret_cast - // because it makes the game break + // because it makes the game break sapling->update(); if (sapling->hasGrown()) { @@ -309,17 +309,17 @@ int main(int argc, char **argv) blocks.emplace_back(new WoodBlock(x, y)); blocks.emplace_back(new WoodBlock(x, y - 16)); blocks.emplace_back(new WoodBlock(x, y - 32)); - blocks.emplace_back(new LeavesBlock(x, y - 48)); - blocks.emplace_back(new LeavesBlock(x - 16, y - 48)); - blocks.emplace_back(new LeavesBlock(x - 32, y - 48)); - blocks.emplace_back(new LeavesBlock(x + 16, y - 48)); - blocks.emplace_back(new LeavesBlock(x + 32, y - 48)); - blocks.emplace_back(new LeavesBlock(x, y - 64)); - blocks.emplace_back(new LeavesBlock(x - 16, y - 64)); - blocks.emplace_back(new LeavesBlock(x + 16, y - 64)); - blocks.emplace_back(new LeavesBlock(x, y - 80)); - blocks.emplace_back(new LeavesBlock(x - 16, y - 80)); - blocks.emplace_back(new LeavesBlock(x + 16, y - 80)); + blocks.emplace_back(new LeavesBlock(x, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(x - 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(x - 32, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(x + 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(x + 32, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(x, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(x - 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(x + 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(x, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(x - 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(x + 16, y - 80, LeavesType::Oak)); std::sort(blocks.begin(), blocks.end(), BlockCompareKey()); // sort blocks } } @@ -332,14 +332,14 @@ int main(int argc, char **argv) entity->update(blocks, camera, frames); if (entity->id().rfind("drop", 0) == 0 && Rect(player.getX(), player.getY(), 16, 24) - .intersects(entity->getRectBottom())) + .intersects(entity->getRectBottom())) { std::vector split; std::string temp; std::stringstream ss(entity->id()); while (std::getline(ss, temp, ' ')) split.push_back(temp); - + bool ok = true; std::string blockid = split[1]; if (blockid == "grass" && player.canAddItem(InventoryItemID::Grass)) @@ -350,8 +350,12 @@ int main(int argc, char **argv) player.addItem(InventoryItemID::Stone); else if (blockid == "wood" && player.canAddItem(InventoryItemID::Wood)) player.addItem(InventoryItemID::Wood); + else if (blockid == "birchwood" && player.canAddItem(InventoryItemID::BirchWood)) + player.addItem(InventoryItemID::BirchWood); else if (blockid == "leaves" && player.canAddItem(InventoryItemID::Leaves)) player.addItem(InventoryItemID::Leaves); + else if (blockid == "birchleaves" && player.canAddItem(InventoryItemID::BirchLeaves)) + player.addItem(InventoryItemID::BirchLeaves); else if (blockid == "sand" && player.canAddItem(InventoryItemID::Sand)) player.addItem(InventoryItemID::Sand); else if (blockid == "sandstone" && player.canAddItem(InventoryItemID::Sandstone)) @@ -386,7 +390,7 @@ int main(int argc, char **argv) player.addItem(InventoryItemID::Stick); else ok = false; - + if (ok) { mmEffectEx(&sndPop); @@ -412,12 +416,16 @@ int main(int argc, char **argv) camera.y = lerp(camera.y, player.getY() - SCREEN_HEIGHT / 2, 0.1f); // camera clamping - if (camera.x < 0) camera.x = 0; - else if (camera.x > 1024 - SCREEN_WIDTH) camera.x = 1024 - SCREEN_WIDTH; + if (camera.x < 0) + camera.x = 0; + else if (camera.x > 1024 - SCREEN_WIDTH) + camera.x = 1024 - SCREEN_WIDTH; // player pos clamping - if (player.getX() < 0) player.setX(0); - if (player.getX() > 1024 - 16) player.setX(1024 - 16); + if (player.getX() < 0) + player.setX(0); + if (player.getX() > 1024 - 16) + player.setX(1024 - 16); } else if (player.dead()) { @@ -526,7 +534,8 @@ int main(int argc, char **argv) --wsSelected; } break; - case GameState::CreateWorld: { + case GameState::CreateWorld: + { if (down & KEY_B) { createWorldDuplError = false; @@ -538,13 +547,15 @@ int main(int argc, char **argv) { // trim the string createWorldName.erase(createWorldName.begin(), std::find_if(createWorldName.begin(), - createWorldName.end(), [](unsigned char ch) { - return !std::isspace(ch); - })); + createWorldName.end(), [](unsigned char ch) + { return !std::isspace(ch); })); createWorldName.erase(std::find_if(createWorldName.rbegin(), createWorldName.rend(), - [](unsigned char ch) { - return !std::isspace(ch); - }).base(), createWorldName.end()); + [](unsigned char ch) + { + return !std::isspace(ch); + }) + .base(), + createWorldName.end()); if (fsFileExists(std::string("worlds/" + createWorldName + ".wld").c_str())) createWorldDuplError = true; @@ -792,7 +803,7 @@ int main(int argc, char **argv) fontRu.printCentered(0, 16, "Tkus\""); break; } - + fontSmall.printCentered(0, 70, "Textures by Mojang"); fontSmall.printCentered(0, 120, "(C) 2022 dirent games"); fontSmall.printCentered(0, 129, "Built with devkitARM"); @@ -982,7 +993,7 @@ int main(int argc, char **argv) glSprite(2, SCREEN_HEIGHT - 30, GL_FLIP_NONE, selectbtn); fontSmall.print(30, SCREEN_HEIGHT - 28, "Select ("); fontSmallRu.print(97, SCREEN_HEIGHT - 28, "C\"csbu#)"); - + glSprite(2, SCREEN_HEIGHT - 17, GL_FLIP_NONE, abtn); fontSmall.print(15, SCREEN_HEIGHT - 15, "OK"); diff --git a/source/player.cpp b/source/player.cpp index 2e8aa012..a5b5eb0e 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -24,7 +24,9 @@ extern glImage sprGrass[1]; extern glImage sprDirt[1]; extern glImage sprStone[1]; extern glImage sprWood[1]; +extern glImage sprBirchWood[1]; extern glImage sprLeaves[1]; +extern glImage sprBirchLeaves[1]; extern glImage sprSand[1]; extern glImage sprSandstone[1]; extern glImage sprCactus[1]; @@ -334,7 +336,7 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo glSprite(x - 1 - camera.x - (facing == Facing::Right ? 0 : 3), y - camera.y, (facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H), sprPlayer); glSprite(x - camera.x - (facing == Facing::Right ? 0 : 5), y - camera.y, - (facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H), sprPlayerHead); + (facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H), sprPlayerHead); glPolyFmt(POLY_ALPHA(20) | POLY_CULL_NONE | POLY_ID(3)); // draw inventory background @@ -474,7 +476,7 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo glColor(RGB15(0, 31, 0)); // draw the slot glSprite(xx, yy, GL_FLIP_NONE, - (inventoryFullSelect == i ? sprInventorySlotSelect : sprInventorySlot)); + (inventoryFullSelect == i ? sprInventorySlotSelect : sprInventorySlot)); // reset color glColor(RGB15(31, 31, 31)); @@ -500,11 +502,19 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo case InventoryItemID::Wood: glSpriteScale(xx + 4, yy + 4, HALFSIZE, GL_FLIP_NONE, sprWood); break; + case InventoryItemID::BirchWood: + glSpriteScale(xx + 4, yy + 4, HALFSIZE, GL_FLIP_NONE, sprBirchWood); + break; case InventoryItemID::Leaves: glColor(RGB15(0, 22, 0)); glSpriteScale(xx + 4, yy + 4, HALFSIZE, GL_FLIP_NONE, sprLeaves); glColor(RGB15(31, 31, 31)); break; + case InventoryItemID::BirchLeaves: + glColor(RGB15(0, 22, 0)); + glSpriteScale(xx + 4, yy + 4, HALFSIZE, GL_FLIP_NONE, sprBirchLeaves); + glColor(RGB15(31, 31, 31)); + break; case InventoryItemID::Sand: glSpriteScale(xx + 4, yy + 4, HALFSIZE, GL_FLIP_NONE, sprSand); break; @@ -583,7 +593,7 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo // draw the player int angle = atan2(y + 6 - camera.y - aimY, x + 5 - camera.x - aimX) * 180 / M_PI * 40; glSprite(x - 1 - camera.x - (facing == Facing::Right ? 0 : 3), y - camera.y, - (facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H), sprPlayer); + (facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H), sprPlayer); glSpriteRotate(x + 5 - camera.x, y + 6 - camera.y, angle, (facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H), sprPlayerHead); @@ -596,71 +606,83 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo { default: glBoxFilled(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, - getRectAim(camera).x - camera.x + 15, getRectAim(camera).y - camera.y + 15, RGB15(0, 31, 0)); + getRectAim(camera).x - camera.x + 15, getRectAim(camera).y - camera.y + 15, RGB15(0, 31, 0)); break; - + case InventoryItemID::Grass: glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprGrass); break; - + case InventoryItemID::Dirt: glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprDirt); break; - + case InventoryItemID::Stone: glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprStone); break; - + case InventoryItemID::Wood: glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprWood); break; - + + case InventoryItemID::BirchWood: + glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, + GL_FLIP_NONE, sprBirchWood); + break; + case InventoryItemID::Leaves: glColor(RGB15(0, 22, 0)); glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprLeaves); glColor(RGB15(31, 31, 31)); break; - + + case InventoryItemID::BirchLeaves: + glColor(RGB15(0, 22, 0)); + glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, + GL_FLIP_NONE, sprBirchLeaves); + glColor(RGB15(31, 31, 31)); + break; + case InventoryItemID::Sand: glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprSand); break; - + case InventoryItemID::Sandstone: glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprSandstone); break; - + case InventoryItemID::Cactus: glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprCactus); break; - + case InventoryItemID::DeadBush: glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprDeadBush); break; - + case InventoryItemID::Poppy: glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprPoppy); break; - + case InventoryItemID::Dandelion: glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprDandelion); break; - + case InventoryItemID::Door: glSprite(getRectAim(camera).x - camera.x - 1, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprDoor); break; - + case InventoryItemID::Planks: glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprPlanks); @@ -712,93 +734,103 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo { case InventoryItemID::Grass: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprGrass); + HALFSIZE, GL_FLIP_NONE, sprGrass); break; case InventoryItemID::Dirt: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprDirt); + HALFSIZE, GL_FLIP_NONE, sprDirt); break; case InventoryItemID::Stone: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprStone); + HALFSIZE, GL_FLIP_NONE, sprStone); break; case InventoryItemID::Wood: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprWood); + HALFSIZE, GL_FLIP_NONE, sprWood); + break; + case InventoryItemID::BirchWood: + glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, + HALFSIZE, GL_FLIP_NONE, sprBirchWood); break; case InventoryItemID::Leaves: glColor(RGB15(0, 22, 0)); glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprLeaves); + HALFSIZE, GL_FLIP_NONE, sprLeaves); + glColor(RGB15(31, 31, 31)); + break; + case InventoryItemID::BirchLeaves: + glColor(RGB15(0, 22, 0)); + glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, + HALFSIZE, GL_FLIP_NONE, sprLeaves); glColor(RGB15(31, 31, 31)); break; case InventoryItemID::Sand: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprSand); + HALFSIZE, GL_FLIP_NONE, sprSand); break; case InventoryItemID::Sandstone: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprSandstone); + HALFSIZE, GL_FLIP_NONE, sprSandstone); break; case InventoryItemID::Cactus: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprCactus); + HALFSIZE, GL_FLIP_NONE, sprCactus); break; case InventoryItemID::DeadBush: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprDeadBush); + HALFSIZE, GL_FLIP_NONE, sprDeadBush); break; case InventoryItemID::Poppy: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprPoppy); + HALFSIZE, GL_FLIP_NONE, sprPoppy); break; case InventoryItemID::Dandelion: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprDandelion); + HALFSIZE, GL_FLIP_NONE, sprDandelion); break; case InventoryItemID::Door: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 5, SCREEN_HEIGHT - 16 + 4, - (1 << 12) / 4, GL_FLIP_NONE, sprDoor); + (1 << 12) / 4, GL_FLIP_NONE, sprDoor); break; case InventoryItemID::Planks: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprPlanks); + HALFSIZE, GL_FLIP_NONE, sprPlanks); break; case InventoryItemID::Stick: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprStick); + HALFSIZE, GL_FLIP_NONE, sprStick); break; case InventoryItemID::SnowyGrass: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprSnowyGrass); + HALFSIZE, GL_FLIP_NONE, sprSnowyGrass); break; case InventoryItemID::Sapling: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprSapling); + HALFSIZE, GL_FLIP_NONE, sprSapling); break; case InventoryItemID::Cobblestone: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprCobblestone); + HALFSIZE, GL_FLIP_NONE, sprCobblestone); break; case InventoryItemID::CoalOre: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprCoalOre); + HALFSIZE, GL_FLIP_NONE, sprCoalOre); break; case InventoryItemID::Coal: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprCoal); + HALFSIZE, GL_FLIP_NONE, sprCoal); break; case InventoryItemID::CoalBlock: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprCoalBlock); + HALFSIZE, GL_FLIP_NONE, sprCoalBlock); break; case InventoryItemID::RawPorkchop: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprRawPorkchop); + HALFSIZE, GL_FLIP_NONE, sprRawPorkchop); break; case InventoryItemID::CookedPorkchop: glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprCookedPorkchop); + HALFSIZE, GL_FLIP_NONE, sprCookedPorkchop); break; } @@ -909,8 +941,7 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con crafted = true; } // cooked porkchop recipe - else if (craftingSelect == 5 && hasItem({InventoryItemID::RawPorkchop, 1}) - && hasItem({InventoryItemID::Coal, 1})) + else if (craftingSelect == 5 && hasItem({InventoryItemID::RawPorkchop, 1}) && hasItem({InventoryItemID::Coal, 1})) { removeItem(InventoryItemID::RawPorkchop); removeItem(InventoryItemID::Coal); @@ -918,7 +949,8 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con crafted = true; } - if (crafted) mmEffectEx(&sndClick); + if (crafted) + mmEffectEx(&sndClick); } if (kdown & KEY_R) { @@ -1132,7 +1164,7 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con // if there is block at aim if (Rect(getRectAim(*camera).x + 1, getRectAim(*camera).y + 1, 14, 14) - .intersects(block->getRect())) + .intersects(block->getRect())) { // interact interact = true; @@ -1152,59 +1184,60 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con if (inventory[inventorySelect].amount > 0) { InventoryItemID id = inventory[inventorySelect].id; // id - u8 effect = rand() % 4; // sound effect 2 play - bool canPlace = true; // can place block????? + u8 effect = rand() % 4; // sound effect 2 play + bool canPlace = true; // can place block????? switch (id) { case InventoryItemID::Grass: blocks->emplace_back(new GrassBlock(snapToGrid(camera->x + aimX), snapToGrid(camera->y + aimY))); - playsfx(effect, sndGrass1, sndGrass2, sndGrass3, sndGrass4) - break; + playsfx(effect, sndGrass1, sndGrass2, sndGrass3, sndGrass4) break; case InventoryItemID::Dirt: blocks->emplace_back(new DirtBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY))); - playsfx(effect, sndDirt1, sndDirt2, sndDirt3, sndDirt4) - break; + snapToGrid(camera->y + aimY))); + playsfx(effect, sndDirt1, sndDirt2, sndDirt3, sndDirt4) break; case InventoryItemID::Stone: blocks->emplace_back(new StoneBlock(snapToGrid(camera->x + aimX), snapToGrid(camera->y + aimY))); - playsfx(effect, sndStone1, sndStone2, sndStone3, sndStone4) - break; + playsfx(effect, sndStone1, sndStone2, sndStone3, sndStone4) break; case InventoryItemID::Wood: blocks->emplace_back(new WoodBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY))); - playsfx(effect, sndWood1, sndWood2, sndWood3, sndWood4) - break; + snapToGrid(camera->y + aimY))); + playsfx(effect, sndWood1, sndWood2, sndWood3, sndWood4) break; + case InventoryItemID::BirchWood: + blocks->emplace_back(new BirchWoodBlock(snapToGrid(camera->x + aimX), + snapToGrid(camera->y + aimY))); + playsfx(effect, sndWood1, sndWood2, sndWood3, sndWood4) break; case InventoryItemID::Leaves: blocks->emplace_back(new LeavesBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY), false)); - playsfx(effect, sndGrass1, sndGrass2, sndGrass3, sndGrass4) - break; + snapToGrid(camera->y + aimY), + LeavesType::Oak, false)); + playsfx(effect, sndGrass1, sndGrass2, sndGrass3, sndGrass4) break; + case InventoryItemID::BirchLeaves: + blocks->emplace_back(new LeavesBlock(snapToGrid(camera->x + aimX), + snapToGrid(camera->y + aimY), + LeavesType::Birch, false)); + playsfx(effect, sndGrass1, sndGrass2, sndGrass3, sndGrass4) break; case InventoryItemID::Sand: blocks->emplace_back(new SandBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY))); - playsfx(effect, sndSand1, sndSand2, sndSand3, sndSand4) - break; + snapToGrid(camera->y + aimY))); + playsfx(effect, sndSand1, sndSand2, sndSand3, sndSand4) break; case InventoryItemID::Sandstone: blocks->emplace_back(new SandstoneBlock(snapToGrid(camera->x + aimX), snapToGrid(camera->y + aimY))); - playsfx(effect, sndStone1, sndStone2, sndStone3, sndStone4) - break; + playsfx(effect, sndStone1, sndStone2, sndStone3, sndStone4) break; case InventoryItemID::Cactus: canPlace = false; for (size_t i = 0; i < blocks->size(); ++i) { if (blocks->at(i)->y == getRectAim(*camera).y + 16 && - blocks->at(i)->x == getRectAim(*camera).x && ( - blocks->at(i)->id() == "sand" || - blocks->at(i)->id() == "cactus")) + blocks->at(i)->x == getRectAim(*camera).x && (blocks->at(i)->id() == "sand" || blocks->at(i)->id() == "cactus")) canPlace = true; } if (canPlace) { blocks->emplace_back(new CactusBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY))); + snapToGrid(camera->y + aimY))); playsfx(effect, sndCloth1, sndCloth2, sndCloth3, sndCloth4) } break; @@ -1213,14 +1246,13 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con for (size_t i = 0; i < blocks->size(); ++i) { if (blocks->at(i)->y == getRectAim(*camera).y + 16 && - blocks->at(i)->x == getRectAim(*camera).x && ( - blocks->at(i)->id() == "sand")) + blocks->at(i)->x == getRectAim(*camera).x && (blocks->at(i)->id() == "sand")) canPlace = true; } if (canPlace) { blocks->emplace_back(new DeadBushBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY))); + snapToGrid(camera->y + aimY))); playsfx(effect, sndGrass1, sndGrass2, sndGrass3, sndGrass4) } break; @@ -1229,16 +1261,13 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con for (size_t i = 0; i < blocks->size(); ++i) { if (blocks->at(i)->y == getRectAim(*camera).y + 16 && - blocks->at(i)->x == getRectAim(*camera).x && ( - blocks->at(i)->id() == "grass" || - blocks->at(i)->id() == "dirt" || - blocks->at(i)->id() == "snowy grass")) + blocks->at(i)->x == getRectAim(*camera).x && (blocks->at(i)->id() == "grass" || blocks->at(i)->id() == "dirt" || blocks->at(i)->id() == "snowy grass")) canPlace = true; } if (canPlace) { blocks->emplace_back(new FlowerBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY), FlowerType::Poppy)); + snapToGrid(camera->y + aimY), FlowerType::Poppy)); playsfx(effect, sndGrass1, sndGrass2, sndGrass3, sndGrass4) } break; @@ -1247,68 +1276,56 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con for (size_t i = 0; i < blocks->size(); ++i) { if (blocks->at(i)->y == getRectAim(*camera).y + 16 && - blocks->at(i)->x == getRectAim(*camera).x && ( - blocks->at(i)->id() == "grass" || - blocks->at(i)->id() == "dirt" || - blocks->at(i)->id() == "snowy grass")) + blocks->at(i)->x == getRectAim(*camera).x && (blocks->at(i)->id() == "grass" || blocks->at(i)->id() == "dirt" || blocks->at(i)->id() == "snowy grass")) canPlace = true; } if (canPlace) { blocks->emplace_back(new FlowerBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY), - FlowerType::Dandelion)); + snapToGrid(camera->y + aimY), + FlowerType::Dandelion)); playsfx(effect, sndGrass1, sndGrass2, sndGrass3, sndGrass4) } break; case InventoryItemID::Door: blocks->emplace_back(new DoorBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY), x)); - playsfx(effect, sndWood1, sndWood2, sndWood3, sndWood4) - break; + snapToGrid(camera->y + aimY), x)); + playsfx(effect, sndWood1, sndWood2, sndWood3, sndWood4) break; case InventoryItemID::Planks: blocks->emplace_back(new PlanksBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY))); - playsfx(effect, sndWood1, sndWood2, sndWood3, sndWood4) - break; + snapToGrid(camera->y + aimY))); + playsfx(effect, sndWood1, sndWood2, sndWood3, sndWood4) break; case InventoryItemID::SnowyGrass: blocks->emplace_back(new SnowyGrassBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY))); - playsfx(effect, sndSnow1, sndSnow2, sndSnow3, sndSnow4) - break; + snapToGrid(camera->y + aimY))); + playsfx(effect, sndSnow1, sndSnow2, sndSnow3, sndSnow4) break; case InventoryItemID::Sapling: canPlace = false; for (size_t i = 0; i < blocks->size(); ++i) { if (blocks->at(i)->y == getRectAim(*camera).y + 16 && - blocks->at(i)->x == getRectAim(*camera).x && ( - blocks->at(i)->id() == "grass" || - blocks->at(i)->id() == "dirt" || - blocks->at(i)->id() == "snowy grass")) + blocks->at(i)->x == getRectAim(*camera).x && (blocks->at(i)->id() == "grass" || blocks->at(i)->id() == "dirt" || blocks->at(i)->id() == "snowy grass")) canPlace = true; } if (canPlace) { blocks->emplace_back(new SaplingBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY))); + snapToGrid(camera->y + aimY))); playsfx(effect, sndGrass1, sndGrass2, sndGrass3, sndGrass4) } break; - case InventoryItemID::Cobblestone: + case InventoryItemID::Cobblestone: blocks->emplace_back(new CobblestoneBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY))); - playsfx(effect, sndStone1, sndStone2, sndStone3, sndStone4) - break; + snapToGrid(camera->y + aimY))); + playsfx(effect, sndStone1, sndStone2, sndStone3, sndStone4) break; case InventoryItemID::CoalOre: blocks->emplace_back(new CoalOreBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY))); - playsfx(effect, sndStone1, sndStone2, sndStone3, sndStone4) - break; + snapToGrid(camera->y + aimY))); + playsfx(effect, sndStone1, sndStone2, sndStone3, sndStone4) break; case InventoryItemID::CoalBlock: blocks->emplace_back(new CoalBlock(snapToGrid(camera->x + aimX), - snapToGrid(camera->y + aimY))); - playsfx(effect, sndStone1, sndStone2, sndStone3, sndStone4) - break; + snapToGrid(camera->y + aimY))); + playsfx(effect, sndStone1, sndStone2, sndStone3, sndStone4) break; } if (canPlace) { @@ -1336,8 +1353,8 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con } // breaking blocks - size_t removei = 0; // remove index - size_t i = 0; // index + size_t removei = 0; // remove index + size_t i = 0; // index bool remove = false; // do we remove or not for (auto &block : *blocks) { @@ -1356,7 +1373,8 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con // if block touch aim then block break (if b is pressed that is) // and we cant brea bedrock if (Rect(getRectAim(*camera).x + 1, getRectAim(*camera).y + 1, 14, 14) - .intersects(block->getRect()) && block->id() != "bedrock") + .intersects(block->getRect()) && + block->id() != "bedrock") { std::string bid = block->id(); u8 effect = rand() % 4; @@ -1380,16 +1398,31 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con entities->emplace_back(new DropEntity(block->x, block->y, "wood")); playsfx(effect, sndWood1, sndWood2, sndWood3, sndWood4) } + else if (bid == "birch wood") + { + entities->emplace_back(new DropEntity(block->x, block->y, "birchwood")); + playsfx(effect, sndWood1, sndWood2, sndWood3, sndWood4) + } else if (bid == "leaves") { - entities->emplace_back(new DropEntity(block->x, block->y, "leaves")); - playsfx(effect, sndGrass1, sndGrass2, sndGrass3, sndGrass4) + Block *b = block.get(); + LeavesBlock *l = reinterpret_cast(b); + switch (l->type) + { + case LeavesType::Oak: + entities->emplace_back(new DropEntity(block->x, block->y, "leaves")); + break; + case LeavesType::Birch: + entities->emplace_back(new DropEntity(block->x, block->y, "birchleaves")); + break; + } + // here i add semicolon because my formatter places + // the if on the same line + playsfx(effect, sndGrass1, sndGrass2, sndGrass3, sndGrass4); if (chance(10)) { // get a spling eith 10% chance if leaves werent // placed by player - Block *b = block.get(); - LeavesBlock *l = reinterpret_cast(b); if (l->isNatural()) entities->emplace_back(new DropEntity(block->x, block->y, "sapling")); } @@ -1488,7 +1521,7 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con falling = jumping = false; velY = 0; y = block->getRect().y - 32; - //printf("%u\n", airY); + // printf("%u\n", airY); if (airY >= 44) // if we fall too much { s16 damage = airY / 44; @@ -1544,18 +1577,14 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con u8 effect = rand() % 4; std::string id = block->id(); if (id == "grass") - playsfx(effect, sndStepGrass1, sndStepGrass2, sndStepGrass3, sndStepGrass4) - else if (id == "dirt") - playsfx(effect, sndStepGravel1, sndStepGravel2, sndStepGravel3, sndStepGravel4) - else if (id == "stone" || id == "sandstone" || id == "cobblestone" || - id == "coal ore" || id == "coal block" || id == "bedrock") - playsfx(effect, sndStepStone1, sndStepStone2, sndStepStone3, sndStepStone4) - else if (id == "sand") - playsfx(effect, sndStepSand1, sndStepSand2, sndStepSand3, sndStepSand4) - else if (id == "snowy grass") - playsfx(effect, sndStepSnow1, sndStepSnow2, sndStepSnow3, sndStepSnow4) - else if (id == "planks" || id == "door") - playsfx(effect, sndStepWood1, sndStepWood2, sndStepWood3, sndStepWood4) + // omg my formatter is going crazy + playsfx(effect, sndStepGrass1, sndStepGrass2, sndStepGrass3, sndStepGrass4) else if (id == "dirt") + playsfx(effect, sndStepGravel1, sndStepGravel2, sndStepGravel3, sndStepGravel4) else if (id == "stone" || id == "sandstone" || id == "cobblestone" || + id == "coal ore" || id == "coal block" || id == "bedrock") + playsfx(effect, sndStepStone1, sndStepStone2, sndStepStone3, sndStepStone4) else if (id == "sand") + playsfx(effect, sndStepSand1, sndStepSand2, sndStepSand3, sndStepSand4) else if (id == "snowy grass") + playsfx(effect, sndStepSnow1, sndStepSnow2, sndStepSnow3, sndStepSnow4) else if (id == "planks" || id == "door") + playsfx(effect, sndStepWood1, sndStepWood2, sndStepWood3, sndStepWood4) } } @@ -1744,7 +1773,7 @@ bool Player::canAddItem(InventoryItemID item) { if (inventory[i].id == InventoryItemID::None && inventory[i].amount == 0) return true; - + if (inventory[i].id == item && inventory[i].amount < 64) return true; } @@ -1771,7 +1800,8 @@ u16 Player::countItems(InventoryItemID item) { u16 count = 0; for (u8 i = 0; i < 20; ++i) - if (inventory[i].id == item) count += inventory[i].amount; + if (inventory[i].id == item) + count += inventory[i].amount; return count; } diff --git a/source/save.cpp b/source/save.cpp index db84533d..f44d612c 100644 --- a/source/save.cpp +++ b/source/save.cpp @@ -14,7 +14,7 @@ void saveWorld(const std::string &name, BlockList &blocks, EntityList &entities, // create file fsCreateFile(std::string("worlds/" + name + ".wld").c_str()); std::string wld; - + // save player wld += "player " + std::to_string(player.getX()) + " " + std::to_string(player.getY()) + " " + std::to_string(player.getHealth()) + "\n"; @@ -131,6 +131,21 @@ void saveWorld(const std::string &name, BlockList &blocks, EntityList &entities, { wld += "block " + std::to_string(block->x) + " " + std::to_string(block->y) + " coalblock\n"; } + else if (id == "birch wood") + { + wld += "block " + std::to_string(block->x) + " " + std::to_string(block->y) + " birchwood\n"; + } + // leaves + else if (id == "leaves") + { + std::string lid = "leaves"; + Block *b = block.get(); + LeavesBlock *leaves = (LeavesBlock *)b; + if (leaves->type == LeavesType::Birch) + lid = "birchleaves"; + + wld += "block " + std::to_string(block->x) + " " + std::to_string(block->y) + " " + lid + "\n"; + } // every other block else { @@ -177,7 +192,7 @@ void loadWorld(const std::string &name, BlockList &blocks, EntityList &entities, { split.push_back(line2); } - + if (split[0] == "player") // key player (player ) { player.setX(atoi(split[1].c_str())); @@ -214,9 +229,17 @@ void loadWorld(const std::string &name, BlockList &blocks, EntityList &entities, { blocks.emplace_back(new WoodBlock(x, y)); } + else if (id == "birchwood") + { + blocks.emplace_back(new BirchWoodBlock(x, y)); + } else if (id == "leaves") { - blocks.emplace_back(new LeavesBlock(x, y)); + blocks.emplace_back(new LeavesBlock(x, y, LeavesType::Oak)); + } + else if (id == "birchleaves") + { + blocks.emplace_back(new LeavesBlock(x, y, LeavesType::Birch)); } else if (id == "sand") { @@ -370,7 +393,7 @@ void loadWorld(const std::string &name, BlockList &blocks, EntityList &entities, { id = InventoryItemID::CookedPorkchop; } - + player.setItem(i, {id, amount}); } if (split[0] == "entity") // key entity (entity ) diff --git a/source/terrain.cpp b/source/terrain.cpp index b045e066..bac801da 100644 --- a/source/terrain.cpp +++ b/source/terrain.cpp @@ -16,7 +16,7 @@ void generateTerrain(BlockList &blocks, EntityList &entities, Player &player) // 1 = desert // 2 = plains // 3 = snow - u8 biome = randomRange(0, 3); + u8 biome = /*randomRange(0, 3)*/ 0; if (biome == 0) { for (u16 i = k * SCREEN_WIDTH * 2 / 16; i < k * SCREEN_WIDTH * 2 / 16 + SCREEN_WIDTH * 2 / 16; ++i) @@ -49,38 +49,71 @@ void generateTerrain(BlockList &blocks, EntityList &entities, Player &player) if (sinceLastTree > treeInterval) { placedTree = true; - u8 tree = chance(50) ? 1 : 0; // tree variant + u8 tree = randomRange(0, 3); // tree variant if (tree == 0) { blocks.emplace_back(new WoodBlock(i * 16, y - 16)); blocks.emplace_back(new WoodBlock(i * 16, y - 32)); blocks.emplace_back(new WoodBlock(i * 16, y - 48)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 - 32, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 + 32, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 96)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 96)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 96)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 32, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 32, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 96, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 96, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 96, LeavesType::Oak)); treeInterval = 5; } else if (tree == 1) { blocks.emplace_back(new WoodBlock(i * 16, y - 16)); blocks.emplace_back(new WoodBlock(i * 16, y - 32)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 48)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 48)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 48)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Oak)); + treeInterval = 3; + } + else if (tree == 2) + { + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 16)); + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 32)); + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 48)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 32, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 32, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 96, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 96, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 96, LeavesType::Birch)); + treeInterval = 5; + } + else if (tree == 3) + { + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 16)); + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 32)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 48, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 48, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 48, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Birch)); treeInterval = 3; } sinceLastTree = 0; @@ -175,32 +208,32 @@ void generateTerrain(BlockList &blocks, EntityList &entities, Player &player) blocks.emplace_back(new WoodBlock(i, y - 16)); blocks.emplace_back(new WoodBlock(i, y - 32)); blocks.emplace_back(new WoodBlock(i, y - 48)); - blocks.emplace_back(new LeavesBlock(i, y - 64)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i - 32, y - 64)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i + 32, y - 64)); - blocks.emplace_back(new LeavesBlock(i, y - 80)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i, y - 96)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 96)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 96)); + blocks.emplace_back(new LeavesBlock(i, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i - 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i - 32, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i + 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i + 32, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i - 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i + 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i, y - 96, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i - 16, y - 96, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i + 16, y - 96, LeavesType::Oak)); treeInterval = 5; } else if (tree == 1) { blocks.emplace_back(new WoodBlock(i, y - 16)); blocks.emplace_back(new WoodBlock(i, y - 32)); - blocks.emplace_back(new LeavesBlock(i, y - 48)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 48)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 48)); - blocks.emplace_back(new LeavesBlock(i, y - 64)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i, y - 80)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 80)); + blocks.emplace_back(new LeavesBlock(i, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i - 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i + 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i - 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i + 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i - 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i + 16, y - 80, LeavesType::Oak)); treeInterval = 3; } sinceLastTree = 0; @@ -247,32 +280,32 @@ void generateTerrain(BlockList &blocks, EntityList &entities, Player &player) blocks.emplace_back(new WoodBlock(i * 16, y - 16)); blocks.emplace_back(new WoodBlock(i * 16, y - 32)); blocks.emplace_back(new WoodBlock(i * 16, y - 48)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 - 32, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 + 32, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 96)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 96)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 96)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 32, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 32, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 96, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 96, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 96, LeavesType::Oak)); treeInterval = 5; } else if (tree == 1) { blocks.emplace_back(new WoodBlock(i * 16, y - 16)); blocks.emplace_back(new WoodBlock(i * 16, y - 32)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 48)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 48)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 48)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64)); - blocks.emplace_back(new LeavesBlock(i * 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80)); - blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Oak)); treeInterval = 3; } sinceLastTree = 0; From 57884fae622f22ab4b5a232e0c8c11b3525dcd9e Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 18:14:32 +0600 Subject: [PATCH 04/26] remove isPointInside from rect --- include/rect.hpp | 1 - source/rect.cpp | 8 +------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/include/rect.hpp b/include/rect.hpp index 4cebb24e..86a643da 100644 --- a/include/rect.hpp +++ b/include/rect.hpp @@ -11,6 +11,5 @@ class Rect Rect(s16 x, s16 y, s16 w, s16 h); bool intersects(Rect other); - bool isPointInside(int x, int y); void draw(Camera camera, int color); }; \ No newline at end of file diff --git a/source/rect.cpp b/source/rect.cpp index afa7f959..d7e0a81c 100644 --- a/source/rect.cpp +++ b/source/rect.cpp @@ -14,13 +14,7 @@ bool Rect::intersects(Rect other) other.x > x + w || other.x + other.w < x || other.y > y + h || - other.y + other.h < y - ); -} - -bool Rect::isPointInside(int _x, int _y) -{ - return Rect(_x, _y, 1, 1).intersects(*this); + other.y + other.h < y); } void Rect::draw(Camera camera, int color) From f777a668d98db0f4359ef71665bae9b43c70e3d1 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 18:20:31 +0600 Subject: [PATCH 05/26] reinterpret cast in save.cpp --- source/save.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/save.cpp b/source/save.cpp index f44d612c..220c4f3e 100644 --- a/source/save.cpp +++ b/source/save.cpp @@ -140,8 +140,8 @@ void saveWorld(const std::string &name, BlockList &blocks, EntityList &entities, { std::string lid = "leaves"; Block *b = block.get(); - LeavesBlock *leaves = (LeavesBlock *)b; - if (leaves->type == LeavesType::Birch) + LeavesBlock *l = reinterpret_cast(b); + if (l->type == LeavesType::Birch) lid = "birchleaves"; wld += "block " + std::to_string(block->x) + " " + std::to_string(block->y) + " " + lid + "\n"; From 7c2d7764aaf12b34b83b08bba09ffb0526099b61 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 18:56:23 +0600 Subject: [PATCH 06/26] birch items save and load --- source/save.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/save.cpp b/source/save.cpp index 220c4f3e..93c19afa 100644 --- a/source/save.cpp +++ b/source/save.cpp @@ -41,9 +41,15 @@ void saveWorld(const std::string &name, BlockList &blocks, EntityList &entities, case InventoryItemID::Wood: id = "wood"; break; + case InventoryItemID::BirchWood: + id = "birchwood"; + break; case InventoryItemID::Leaves: id = "leaves"; break; + case InventoryItemID::BirchLeaves: + id = "birchleaves"; + break; case InventoryItemID::Sand: id = "sand"; break; @@ -321,10 +327,18 @@ void loadWorld(const std::string &name, BlockList &blocks, EntityList &entities, { id = InventoryItemID::Wood; } + else if (sid == "birchwood") + { + id = InventoryItemID::BirchWood; + } else if (sid == "leaves") { id = InventoryItemID::Leaves; } + else if (sid == "birchleaves") + { + id = InventoryItemID::BirchLeaves; + } else if (sid == "sand") { id = InventoryItemID::Sand; From 2ec8d9250d35b3839886868e9b830e1aa6a0e123 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 18:58:44 +0600 Subject: [PATCH 07/26] birch leaves draw properly in hotbar --- source/player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/player.cpp b/source/player.cpp index a5b5eb0e..e4385cba 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -761,7 +761,7 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo case InventoryItemID::BirchLeaves: glColor(RGB15(0, 22, 0)); glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, - HALFSIZE, GL_FLIP_NONE, sprLeaves); + HALFSIZE, GL_FLIP_NONE, sprBirchLeaves); glColor(RGB15(31, 31, 31)); break; case InventoryItemID::Sand: From 85147c0b7ce0347b86bc5e4b153afe93043115bf Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 19:00:57 +0600 Subject: [PATCH 08/26] format fs.c --- source/fs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/fs.c b/source/fs.c index 5bc2453d..c4b5e318 100644 --- a/source/fs.c +++ b/source/fs.c @@ -10,7 +10,8 @@ void fsInit(void) printf("FAT init failed! :(\n"); printf("This error is most likely caused by:\n"); printf(" - ROM is not patched\n - SD card is missing."); - while (true); + while (true) + ; } } @@ -64,7 +65,7 @@ char *fsReadFile(const char *name) fseek(fp, 0, SEEK_END); ssize = ftell(fp); rewind(fp); - buf = (char*)malloc(sizeof(char) * (ssize + 1)); + buf = (char *)malloc(sizeof(char) * (ssize + 1)); rsize = fread(buf, sizeof(char), ssize, fp); buf[ssize] = '\0'; @@ -95,7 +96,10 @@ char *fsHumanreadFileSize(double size) char *buf = (char *)malloc(10 * sizeof(char)); int i = 0; static const char *units[] = { - "B", "KB", "MB", "GB", + "B", + "KB", + "MB", + "GB", }; while (size > 1024) { From 1439a2ef159f8c95281dbc7795fd397f378a6683 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 19:01:31 +0600 Subject: [PATCH 09/26] disable fs error messages and format ig --- include/defines.h | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/include/defines.h b/include/defines.h index bab3a75f..e79a135e 100644 --- a/include/defines.h +++ b/include/defines.h @@ -1,32 +1,35 @@ #pragma once #ifdef __cplusplus - #define loadImage(spr, w, h, bitmap) glLoadTileSet(spr, w, h, w, h, GL_RGB, TEXTURE_SIZE_##w, TEXTURE_SIZE_##h, GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF, 0, 0, const_cast(reinterpret_cast(bitmap))) - #define loadImageAlpha(spr, w, h, pal, bitmap) glLoadTileSet(spr, w, h, w, h, GL_RGB16, TEXTURE_SIZE_##w, TEXTURE_SIZE_##h, GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF | GL_TEXTURE_COLOR0_TRANSPARENT, 16, pal, const_cast(reinterpret_cast(bitmap))) +#define loadImage(spr, w, h, bitmap) glLoadTileSet(spr, w, h, w, h, GL_RGB, TEXTURE_SIZE_##w, TEXTURE_SIZE_##h, GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF, 0, 0, const_cast(reinterpret_cast(bitmap))) +#define loadImageAlpha(spr, w, h, pal, bitmap) glLoadTileSet(spr, w, h, w, h, GL_RGB16, TEXTURE_SIZE_##w, TEXTURE_SIZE_##h, GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF | GL_TEXTURE_COLOR0_TRANSPARENT, 16, pal, const_cast(reinterpret_cast(bitmap))) #else - #define loadImage(spr, w, h, bitmap) glLoadTileSet(spr, w, h, w, h, GL_RGB, TEXTURE_SIZE_##w, TEXTURE_SIZE_##h, GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF, 0, 0, (u8 *)bitmap) - #define loadImageAlpha(spr, w, h, pal, bitmap) glLoadTileSet(spr, w, h, w, h, GL_RGB16, TEXTURE_SIZE_##w, TEXTURE_SIZE_##h, GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF | GL_TEXTURE_COLOR0_TRANSPARENT, 16, pal, (u8 *)bitmap) +#define loadImage(spr, w, h, bitmap) glLoadTileSet(spr, w, h, w, h, GL_RGB, TEXTURE_SIZE_##w, TEXTURE_SIZE_##h, GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF, 0, 0, (u8 *)bitmap) +#define loadImageAlpha(spr, w, h, pal, bitmap) glLoadTileSet(spr, w, h, w, h, GL_RGB16, TEXTURE_SIZE_##w, TEXTURE_SIZE_##h, GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF | GL_TEXTURE_COLOR0_TRANSPARENT, 16, pal, (u8 *)bitmap) #endif #define randomRange(a, b) ((a) + rand() % (((b) + 1) - (a))) #define chance(percent) (rand() % 100 <= (percent)) #define lerp(a, b, t) ((a) + (t) * ((b) - (a))) #define snapToGrid(x) (round((x) / 16) * 16) -#define soundEffect(id) {{id}, (int)(1.0f * (1<<10)), 0, 255, 0} +#define soundEffect(id) \ + { \ + {id}, (int)(1.0f * (1 << 10)), 0, 255, 0 \ + } #define playsfx(effect, sfx1, sfx2, sfx3, sfx4) \ - switch (effect) \ - { \ - case 0: \ - mmEffectEx(&sfx1); \ - break; \ - case 1: \ - mmEffectEx(&sfx2); \ - break; \ - case 2: \ - mmEffectEx(&sfx3); \ - break; \ - case 3: \ - mmEffectEx(&sfx4); \ - break; \ + switch (effect) \ + { \ + case 0: \ + mmEffectEx(&sfx1); \ + break; \ + case 1: \ + mmEffectEx(&sfx2); \ + break; \ + case 2: \ + mmEffectEx(&sfx3); \ + break; \ + case 3: \ + mmEffectEx(&sfx4); \ + break; \ } #define VERSION_PREFIX "alpha" @@ -34,7 +37,7 @@ #define VERSION_MINOR 0 #define VERSION_PATCH 0 #define SKIP_SPLASH_SCREEN 0 -#define FS_ERROR_MESSAGES 1 +#define FS_ERROR_MESSAGES 0 #define HALFSIZE ((1 << 12) / 2) From 118b02d539f0a0b9fa67eb3621cffde051c07d5a Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 19:03:30 +0600 Subject: [PATCH 10/26] formatting --- include/PerlinNoise.hpp | 241 +++++++++++++++-------------------- include/fs.h | 21 +-- include/glext.h | 5 +- include/uvcoord_font_16x16.h | 208 +++++++++++++++--------------- include/uvcoord_font_si.h | 208 +++++++++++++++--------------- source/font.cpp | 2 +- 6 files changed, 317 insertions(+), 368 deletions(-) diff --git a/include/PerlinNoise.hpp b/include/PerlinNoise.hpp index e2a9341c..f8d73ba4 100644 --- a/include/PerlinNoise.hpp +++ b/include/PerlinNoise.hpp @@ -11,10 +11,10 @@ // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions : -// +// // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE @@ -25,61 +25,56 @@ // //---------------------------------------------------------------------------------------- -# pragma once -# include -# include -# include -# include -# include -# include -# include - -# if __has_include("concepts") && defined(__cpp_concepts) -# include "concepts" -# endif +#pragma once +#include +#include +#include +#include +#include +#include +#include +#if __has_include("concepts") && defined(__cpp_concepts) +#include "concepts" +#endif // Library major version -# define SIVPERLIN_VERSION_MAJOR 3 +#define SIVPERLIN_VERSION_MAJOR 3 // Library minor version -# define SIVPERLIN_VERSION_MINOR 0 +#define SIVPERLIN_VERSION_MINOR 0 // Library revision version -# define SIVPERLIN_VERSION_REVISION 0 +#define SIVPERLIN_VERSION_REVISION 0 // Library version -# define SIVPERLIN_VERSION ((SIVPERLIN_VERSION_MAJOR * 100 * 100) + (SIVPERLIN_VERSION_MINOR * 100) + (SIVPERLIN_VERSION_REVISION)) - +#define SIVPERLIN_VERSION ((SIVPERLIN_VERSION_MAJOR * 100 * 100) + (SIVPERLIN_VERSION_MINOR * 100) + (SIVPERLIN_VERSION_REVISION)) // [[nodiscard]] for constructors -# if (201907L <= __has_cpp_attribute(nodiscard)) -# define SIVPERLIN_NODISCARD_CXX20 [[nodiscard]] -# else -# define SIVPERLIN_NODISCARD_CXX20 -# endif - +#if (201907L <= __has_cpp_attribute(nodiscard)) +#define SIVPERLIN_NODISCARD_CXX20 [[nodiscard]] +#else +#define SIVPERLIN_NODISCARD_CXX20 +#endif // std::uniform_random_bit_generator concept -# if __cpp_lib_concepts -# define SIVPERLIN_CONCEPT_URBG template -# define SIVPERLIN_CONCEPT_URBG_ template -# else -# define SIVPERLIN_CONCEPT_URBG template , std::is_unsigned>>>* = nullptr> -# define SIVPERLIN_CONCEPT_URBG_ template , std::is_unsigned>>>*> -# endif - +#if __cpp_lib_concepts +#define SIVPERLIN_CONCEPT_URBG template +#define SIVPERLIN_CONCEPT_URBG_ template +#else +#define SIVPERLIN_CONCEPT_URBG template , std::is_unsigned>>> * = nullptr> +#define SIVPERLIN_CONCEPT_URBG_ template , std::is_unsigned>>> *> +#endif // arbitrary value for increasing entropy -# ifndef SIVPERLIN_DEFAULT_Y -# define SIVPERLIN_DEFAULT_Y (0.12345) -# endif +#ifndef SIVPERLIN_DEFAULT_Y +#define SIVPERLIN_DEFAULT_Y (0.12345) +#endif // arbitrary value for increasing entropy -# ifndef SIVPERLIN_DEFAULT_Z -# define SIVPERLIN_DEFAULT_Z (0.34567) -# endif - +#ifndef SIVPERLIN_DEFAULT_Z +#define SIVPERLIN_DEFAULT_Z (0.34567) +#endif namespace siv { @@ -87,7 +82,6 @@ namespace siv class BasicPerlinNoise { public: - static_assert(std::is_floating_point_v); /////////////////////////////////////// @@ -116,7 +110,7 @@ namespace siv SIVPERLIN_CONCEPT_URBG SIVPERLIN_NODISCARD_CXX20 - explicit BasicPerlinNoise(URBG&& urbg); + explicit BasicPerlinNoise(URBG &&urbg); /////////////////////////////////////// // @@ -126,118 +120,95 @@ namespace siv void reseed(seed_type seed); SIVPERLIN_CONCEPT_URBG - void reseed(URBG&& urbg); + void reseed(URBG &&urbg); /////////////////////////////////////// // // Serialization // - [[nodiscard]] - constexpr const state_type& serialize() const noexcept; + [[nodiscard]] constexpr const state_type &serialize() const noexcept; - constexpr void deserialize(const state_type& state) noexcept; + constexpr void deserialize(const state_type &state) noexcept; /////////////////////////////////////// // // Noise (The result is in the range [-1, 1]) // - [[nodiscard]] - value_type noise1D(value_type x) const noexcept; + [[nodiscard]] value_type noise1D(value_type x) const noexcept; - [[nodiscard]] - value_type noise2D(value_type x, value_type y) const noexcept; + [[nodiscard]] value_type noise2D(value_type x, value_type y) const noexcept; - [[nodiscard]] - value_type noise3D(value_type x, value_type y, value_type z) const noexcept; + [[nodiscard]] value_type noise3D(value_type x, value_type y, value_type z) const noexcept; /////////////////////////////////////// // // Noise (The result is remapped to the range [0, 1]) // - [[nodiscard]] - value_type noise1D_01(value_type x) const noexcept; + [[nodiscard]] value_type noise1D_01(value_type x) const noexcept; - [[nodiscard]] - value_type noise2D_01(value_type x, value_type y) const noexcept; + [[nodiscard]] value_type noise2D_01(value_type x, value_type y) const noexcept; - [[nodiscard]] - value_type noise3D_01(value_type x, value_type y, value_type z) const noexcept; + [[nodiscard]] value_type noise3D_01(value_type x, value_type y, value_type z) const noexcept; /////////////////////////////////////// // // Octave noise (The result can be out of the range [-1, 1]) // - [[nodiscard]] - value_type octave1D(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type octave1D(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; - [[nodiscard]] - value_type octave2D(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type octave2D(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; - [[nodiscard]] - value_type octave3D(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type octave3D(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; /////////////////////////////////////// // // Octave noise (The result is clamped to the range [-1, 1]) // - [[nodiscard]] - value_type octave1D_11(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type octave1D_11(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; - [[nodiscard]] - value_type octave2D_11(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type octave2D_11(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; - [[nodiscard]] - value_type octave3D_11(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type octave3D_11(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; /////////////////////////////////////// // // Octave noise (The result is clamped and remapped to the range [0, 1]) // - [[nodiscard]] - value_type octave1D_01(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type octave1D_01(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; - [[nodiscard]] - value_type octave2D_01(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type octave2D_01(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; - [[nodiscard]] - value_type octave3D_01(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type octave3D_01(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; /////////////////////////////////////// // // Octave noise (The result is normalized to the range [-1, 1]) // - [[nodiscard]] - value_type normalizedOctave1D(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type normalizedOctave1D(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; - [[nodiscard]] - value_type normalizedOctave2D(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type normalizedOctave2D(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; - [[nodiscard]] - value_type normalizedOctave3D(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type normalizedOctave3D(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; /////////////////////////////////////// // // Octave noise (The result is normalized and remapped to the range [0, 1]) // - [[nodiscard]] - value_type normalizedOctave1D_01(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type normalizedOctave1D_01(value_type x, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; - [[nodiscard]] - value_type normalizedOctave2D_01(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type normalizedOctave2D_01(value_type x, value_type y, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; - [[nodiscard]] - value_type normalizedOctave3D_01(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; + [[nodiscard]] value_type normalizedOctave3D_01(value_type x, value_type y, value_type z, std::int32_t octaves, value_type persistence = value_type(0.5)) const noexcept; private: - state_type m_permutation; }; @@ -251,14 +222,13 @@ namespace siv // You may get different results from std::shuffle() with different standard library implementations. // SIVPERLIN_CONCEPT_URBG - [[nodiscard]] - inline std::uint64_t Random(const std::uint64_t max, URBG&& urbg) + [[nodiscard]] inline std::uint64_t Random(const std::uint64_t max, URBG &&urbg) { return (urbg() % (max + 1)); } template - inline void Shuffle(RandomIt first, RandomIt last, URBG&& urbg) + inline void Shuffle(RandomIt first, RandomIt last, URBG &&urbg) { if (first == last) { @@ -277,46 +247,41 @@ namespace siv //////////////////////////////////////////////// template - [[nodiscard]] - inline constexpr Float Fade(const Float t) noexcept + [[nodiscard]] inline constexpr Float Fade(const Float t) noexcept { return t * t * t * (t * (t * 6 - 15) + 10); } template - [[nodiscard]] - inline constexpr Float Lerp(const Float a, const Float b, const Float t) noexcept + [[nodiscard]] inline constexpr Float Lerp(const Float a, const Float b, const Float t) noexcept { return (a + (b - a) * t); } template - [[nodiscard]] - inline constexpr Float Grad(const std::uint8_t hash, const Float x, const Float y, const Float z) noexcept + [[nodiscard]] inline constexpr Float Grad(const std::uint8_t hash, const Float x, const Float y, const Float z) noexcept { const std::uint8_t h = hash & 15; const Float u = h < 8 ? x : y; - const Float v = h < 4 ? y : h == 12 || h == 14 ? x : z; + const Float v = h < 4 ? y : h == 12 || h == 14 ? x + : z; return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v); } template - [[nodiscard]] - inline constexpr Float Remap_01(const Float x) noexcept + [[nodiscard]] inline constexpr Float Remap_01(const Float x) noexcept { return (x * Float(0.5) + Float(0.5)); } template - [[nodiscard]] - inline constexpr Float Clamp_11(const Float x) noexcept + [[nodiscard]] inline constexpr Float Clamp_11(const Float x) noexcept { return std::clamp(x, Float(-1.0), Float(1.0)); } template - [[nodiscard]] - inline constexpr Float RemapClamp_01(const Float x) noexcept + [[nodiscard]] inline constexpr Float RemapClamp_01(const Float x) noexcept { if (x <= Float(-1.0)) { @@ -331,8 +296,7 @@ namespace siv } template - [[nodiscard]] - inline auto Octave1D(const Noise& noise, Float x, const std::int32_t octaves, const Float persistence) noexcept + [[nodiscard]] inline auto Octave1D(const Noise &noise, Float x, const std::int32_t octaves, const Float persistence) noexcept { using value_type = Float; value_type result = 0; @@ -349,8 +313,7 @@ namespace siv } template - [[nodiscard]] - inline auto Octave2D(const Noise& noise, Float x, Float y, const std::int32_t octaves, const Float persistence) noexcept + [[nodiscard]] inline auto Octave2D(const Noise &noise, Float x, Float y, const std::int32_t octaves, const Float persistence) noexcept { using value_type = Float; value_type result = 0; @@ -368,8 +331,7 @@ namespace siv } template - [[nodiscard]] - inline auto Octave3D(const Noise& noise, Float x, Float y, Float z, const std::int32_t octaves, const Float persistence) noexcept + [[nodiscard]] inline auto Octave3D(const Noise &noise, Float x, Float y, Float z, const std::int32_t octaves, const Float persistence) noexcept { using value_type = Float; value_type result = 0; @@ -388,8 +350,7 @@ namespace siv } template - [[nodiscard]] - inline constexpr Float MaxAmplitude(const std::int32_t octaves, const Float persistence) noexcept + [[nodiscard]] inline constexpr Float MaxAmplitude(const std::int32_t octaves, const Float persistence) noexcept { using value_type = Float; value_type result = 0; @@ -409,19 +370,19 @@ namespace siv template inline constexpr BasicPerlinNoise::BasicPerlinNoise() noexcept - : m_permutation{ 151,160,137,91,90,15, - 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, - 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, - 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, - 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, - 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, - 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, - 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, - 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, - 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, - 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, - 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, - 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 } {} + : m_permutation{151, 160, 137, 91, 90, 15, + 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, + 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, + 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, + 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, + 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, + 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, + 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, + 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, + 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, + 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, + 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, + 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180} {} template inline BasicPerlinNoise::BasicPerlinNoise(const seed_type seed) @@ -430,8 +391,7 @@ namespace siv } template - SIVPERLIN_CONCEPT_URBG_ - inline BasicPerlinNoise::BasicPerlinNoise(URBG&& urbg) + SIVPERLIN_CONCEPT_URBG_ inline BasicPerlinNoise::BasicPerlinNoise(URBG &&urbg) { reseed(std::forward(urbg)); } @@ -441,14 +401,13 @@ namespace siv template inline void BasicPerlinNoise::reseed(const seed_type seed) { - reseed(default_random_engine{ seed }); + reseed(default_random_engine{seed}); } template - SIVPERLIN_CONCEPT_URBG_ - inline void BasicPerlinNoise::reseed(URBG&& urbg) + SIVPERLIN_CONCEPT_URBG_ inline void BasicPerlinNoise::reseed(URBG &&urbg) { - std::iota(m_permutation.begin(), m_permutation.end(), uint8_t{ 0 }); + std::iota(m_permutation.begin(), m_permutation.end(), uint8_t{0}); perlin_detail::Shuffle(m_permutation.begin(), m_permutation.end(), std::forward(urbg)); } @@ -456,13 +415,13 @@ namespace siv /////////////////////////////////////// template - inline constexpr const typename BasicPerlinNoise::state_type& BasicPerlinNoise::serialize() const noexcept + inline constexpr const typename BasicPerlinNoise::state_type &BasicPerlinNoise::serialize() const noexcept { return m_permutation; } template - inline constexpr void BasicPerlinNoise::deserialize(const state_type& state) noexcept + inline constexpr void BasicPerlinNoise::deserialize(const state_type &state) noexcept { m_permutation = state; } @@ -473,16 +432,16 @@ namespace siv inline typename BasicPerlinNoise::value_type BasicPerlinNoise::noise1D(const value_type x) const noexcept { return noise3D(x, - static_cast(SIVPERLIN_DEFAULT_Y), - static_cast(SIVPERLIN_DEFAULT_Z)); + static_cast(SIVPERLIN_DEFAULT_Y), + static_cast(SIVPERLIN_DEFAULT_Z)); } template inline typename BasicPerlinNoise::value_type BasicPerlinNoise::noise2D(const value_type x, const value_type y) const noexcept { return noise3D(x, - y, - static_cast(SIVPERLIN_DEFAULT_Z)); + y, + static_cast(SIVPERLIN_DEFAULT_Z)); } template @@ -654,6 +613,6 @@ namespace siv } } -# undef SIVPERLIN_NODISCARD_CXX20 -# undef SIVPERLIN_CONCEPT_URBG -# undef SIVPERLIN_CONCEPT_URBG_ +#undef SIVPERLIN_NODISCARD_CXX20 +#undef SIVPERLIN_CONCEPT_URBG +#undef SIVPERLIN_CONCEPT_URBG_ diff --git a/include/fs.h b/include/fs.h index a5df3892..691a9997 100644 --- a/include/fs.h +++ b/include/fs.h @@ -1,7 +1,8 @@ #pragma once #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #include @@ -13,15 +14,15 @@ extern "C" { #include #include -void fsInit(void); -void fsCreateDir(const char *name); -void fsCreateFile(const char *name); -void fsWrite(const char *file, const char *data); -void fsDeleteFile(const char *name); -bool fsFileExists(const char *name); -char *fsReadFile(const char *name); -int fsGetFileSize(const char *name); // in bytes -char *fsHumanreadFileSize(double size); + void fsInit(void); + void fsCreateDir(const char *name); + void fsCreateFile(const char *name); + void fsWrite(const char *file, const char *data); + void fsDeleteFile(const char *name); + bool fsFileExists(const char *name); + char *fsReadFile(const char *name); + int fsGetFileSize(const char *name); // in bytes + char *fsHumanreadFileSize(double size); #ifdef __cplusplus } diff --git a/include/glext.h b/include/glext.h index 4866e2f8..1e06224a 100644 --- a/include/glext.h +++ b/include/glext.h @@ -2,11 +2,12 @@ #pragma once #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #include -void glBoxStroke(int x, int y, int w, int h, int color); + void glBoxStroke(int x, int y, int w, int h, int color); #ifdef __cplusplus } diff --git a/include/uvcoord_font_16x16.h b/include/uvcoord_font_16x16.h index 8e740668..2be11815 100644 --- a/include/uvcoord_font_16x16.h +++ b/include/uvcoord_font_16x16.h @@ -6,119 +6,113 @@ ======================================================================*/ - #ifndef FONT_16X16__H #define FONT_16X16__H +#define FONT_16X16_BITMAP_WIDTH 64 +#define FONT_16X16_BITMAP_HEIGHT 512 +#define FONT_16X16_NUM_IMAGES 96 -#define FONT_16X16_BITMAP_WIDTH 64 -#define FONT_16X16_BITMAP_HEIGHT 512 -#define FONT_16X16_NUM_IMAGES 96 - - - // Format: - // U,V,Width,Height - - +// Format: +// U,V,Width,Height extern const unsigned int font_16x16_texcoords[] = { - 0, 0, 16, 16, // 0 - 16, 0, 16, 16, // 1 - 32, 0, 16, 16, // 2 - 48, 0, 16, 16, // 3 - 0, 16, 16, 16, // 4 - 16, 16, 16, 16, // 5 - 32, 16, 16, 16, // 6 - 48, 16, 16, 16, // 7 - 0, 32, 16, 16, // 8 - 16, 32, 16, 16, // 9 - 32, 32, 16, 16, // 10 - 48, 32, 16, 16, // 11 - 0, 48, 16, 16, // 12 - 16, 48, 16, 16, // 13 - 32, 48, 16, 16, // 14 - 48, 48, 16, 16, // 15 - 0, 64, 16, 16, // 16 - 16, 64, 16, 16, // 17 - 32, 64, 16, 16, // 18 - 48, 64, 16, 16, // 19 - 0, 80, 16, 16, // 20 - 16, 80, 16, 16, // 21 - 32, 80, 16, 16, // 22 - 48, 80, 16, 16, // 23 - 0, 96, 16, 16, // 24 - 16, 96, 16, 16, // 25 - 32, 96, 16, 16, // 26 - 48, 96, 16, 16, // 27 - 0, 112, 16, 16, // 28 - 16, 112, 16, 16, // 29 - 32, 112, 16, 16, // 30 - 48, 112, 16, 16, // 31 - 0, 128, 16, 16, // 32 - 16, 128, 16, 16, // 33 - 32, 128, 16, 16, // 34 - 48, 128, 16, 16, // 35 - 0, 144, 16, 16, // 36 - 16, 144, 16, 16, // 37 - 32, 144, 16, 16, // 38 - 48, 144, 16, 16, // 39 - 0, 160, 16, 16, // 40 - 16, 160, 16, 16, // 41 - 32, 160, 16, 16, // 42 - 48, 160, 16, 16, // 43 - 0, 176, 16, 16, // 44 - 16, 176, 16, 16, // 45 - 32, 176, 16, 16, // 46 - 48, 176, 16, 16, // 47 - 0, 192, 16, 16, // 48 - 16, 192, 16, 16, // 49 - 32, 192, 16, 16, // 50 - 48, 192, 16, 16, // 51 - 0, 208, 16, 16, // 52 - 16, 208, 16, 16, // 53 - 32, 208, 16, 16, // 54 - 48, 208, 16, 16, // 55 - 0, 224, 16, 16, // 56 - 16, 224, 16, 16, // 57 - 32, 224, 16, 16, // 58 - 48, 224, 16, 16, // 59 - 0, 240, 16, 16, // 60 - 16, 240, 16, 16, // 61 - 32, 240, 16, 16, // 62 - 48, 240, 16, 16, // 63 - 0, 256, 16, 16, // 64 - 16, 256, 16, 16, // 65 - 32, 256, 16, 16, // 66 - 48, 256, 16, 16, // 67 - 0, 272, 16, 16, // 68 - 16, 272, 16, 16, // 69 - 32, 272, 16, 16, // 70 - 48, 272, 16, 16, // 71 - 0, 288, 16, 16, // 72 - 16, 288, 16, 16, // 73 - 32, 288, 16, 16, // 74 - 48, 288, 16, 16, // 75 - 0, 304, 16, 16, // 76 - 16, 304, 16, 16, // 77 - 32, 304, 16, 16, // 78 - 48, 304, 16, 16, // 79 - 0, 320, 16, 16, // 80 - 16, 320, 16, 16, // 81 - 32, 320, 16, 16, // 82 - 48, 320, 16, 16, // 83 - 0, 336, 16, 16, // 84 - 16, 336, 16, 16, // 85 - 32, 336, 16, 16, // 86 - 48, 336, 16, 16, // 87 - 0, 352, 16, 16, // 88 - 16, 352, 16, 16, // 89 - 32, 352, 16, 16, // 90 - 48, 352, 16, 16, // 91 - 0, 368, 16, 16, // 92 - 16, 368, 16, 16, // 93 - 32, 368, 16, 16, // 94 - 48, 368, 16, 16, // 95 + 0, 0, 16, 16, // 0 + 16, 0, 16, 16, // 1 + 32, 0, 16, 16, // 2 + 48, 0, 16, 16, // 3 + 0, 16, 16, 16, // 4 + 16, 16, 16, 16, // 5 + 32, 16, 16, 16, // 6 + 48, 16, 16, 16, // 7 + 0, 32, 16, 16, // 8 + 16, 32, 16, 16, // 9 + 32, 32, 16, 16, // 10 + 48, 32, 16, 16, // 11 + 0, 48, 16, 16, // 12 + 16, 48, 16, 16, // 13 + 32, 48, 16, 16, // 14 + 48, 48, 16, 16, // 15 + 0, 64, 16, 16, // 16 + 16, 64, 16, 16, // 17 + 32, 64, 16, 16, // 18 + 48, 64, 16, 16, // 19 + 0, 80, 16, 16, // 20 + 16, 80, 16, 16, // 21 + 32, 80, 16, 16, // 22 + 48, 80, 16, 16, // 23 + 0, 96, 16, 16, // 24 + 16, 96, 16, 16, // 25 + 32, 96, 16, 16, // 26 + 48, 96, 16, 16, // 27 + 0, 112, 16, 16, // 28 + 16, 112, 16, 16, // 29 + 32, 112, 16, 16, // 30 + 48, 112, 16, 16, // 31 + 0, 128, 16, 16, // 32 + 16, 128, 16, 16, // 33 + 32, 128, 16, 16, // 34 + 48, 128, 16, 16, // 35 + 0, 144, 16, 16, // 36 + 16, 144, 16, 16, // 37 + 32, 144, 16, 16, // 38 + 48, 144, 16, 16, // 39 + 0, 160, 16, 16, // 40 + 16, 160, 16, 16, // 41 + 32, 160, 16, 16, // 42 + 48, 160, 16, 16, // 43 + 0, 176, 16, 16, // 44 + 16, 176, 16, 16, // 45 + 32, 176, 16, 16, // 46 + 48, 176, 16, 16, // 47 + 0, 192, 16, 16, // 48 + 16, 192, 16, 16, // 49 + 32, 192, 16, 16, // 50 + 48, 192, 16, 16, // 51 + 0, 208, 16, 16, // 52 + 16, 208, 16, 16, // 53 + 32, 208, 16, 16, // 54 + 48, 208, 16, 16, // 55 + 0, 224, 16, 16, // 56 + 16, 224, 16, 16, // 57 + 32, 224, 16, 16, // 58 + 48, 224, 16, 16, // 59 + 0, 240, 16, 16, // 60 + 16, 240, 16, 16, // 61 + 32, 240, 16, 16, // 62 + 48, 240, 16, 16, // 63 + 0, 256, 16, 16, // 64 + 16, 256, 16, 16, // 65 + 32, 256, 16, 16, // 66 + 48, 256, 16, 16, // 67 + 0, 272, 16, 16, // 68 + 16, 272, 16, 16, // 69 + 32, 272, 16, 16, // 70 + 48, 272, 16, 16, // 71 + 0, 288, 16, 16, // 72 + 16, 288, 16, 16, // 73 + 32, 288, 16, 16, // 74 + 48, 288, 16, 16, // 75 + 0, 304, 16, 16, // 76 + 16, 304, 16, 16, // 77 + 32, 304, 16, 16, // 78 + 48, 304, 16, 16, // 79 + 0, 320, 16, 16, // 80 + 16, 320, 16, 16, // 81 + 32, 320, 16, 16, // 82 + 48, 320, 16, 16, // 83 + 0, 336, 16, 16, // 84 + 16, 336, 16, 16, // 85 + 32, 336, 16, 16, // 86 + 48, 336, 16, 16, // 87 + 0, 352, 16, 16, // 88 + 16, 352, 16, 16, // 89 + 32, 352, 16, 16, // 90 + 48, 352, 16, 16, // 91 + 0, 368, 16, 16, // 92 + 16, 368, 16, 16, // 93 + 32, 368, 16, 16, // 94 + 48, 368, 16, 16, // 95 }; - #endif diff --git a/include/uvcoord_font_si.h b/include/uvcoord_font_si.h index 11e700ce..39ca6a31 100644 --- a/include/uvcoord_font_si.h +++ b/include/uvcoord_font_si.h @@ -6,119 +6,113 @@ ======================================================================*/ - #ifndef FONT_SI__H #define FONT_SI__H +#define FONT_SI_BITMAP_WIDTH 64 +#define FONT_SI_BITMAP_HEIGHT 128 +#define FONT_SI_NUM_IMAGES 96 -#define FONT_SI_BITMAP_WIDTH 64 -#define FONT_SI_BITMAP_HEIGHT 128 -#define FONT_SI_NUM_IMAGES 96 - - - // Format: - // U,V,Width,Height - - +// Format: +// U,V,Width,Height extern const unsigned int font_si_texcoords[] = { - 0, 0, 8, 9, // 0 - 8, 0, 8, 9, // 1 - 16, 0, 8, 9, // 2 - 24, 0, 8, 9, // 3 - 32, 0, 8, 9, // 4 - 40, 0, 8, 9, // 5 - 48, 0, 8, 9, // 6 - 56, 0, 8, 9, // 7 - 0, 9, 8, 9, // 8 - 8, 9, 8, 9, // 9 - 16, 9, 8, 9, // 10 - 24, 9, 8, 9, // 11 - 24, 117, 4, 9, // 12 - 32, 9, 8, 9, // 13 - 40, 9, 8, 9, // 14 - 48, 9, 8, 9, // 15 - 56, 9, 8, 9, // 16 - 0, 18, 8, 9, // 17 - 8, 18, 8, 9, // 18 - 16, 18, 8, 9, // 19 - 24, 18, 8, 9, // 20 - 32, 18, 8, 9, // 21 - 40, 18, 8, 9, // 22 - 48, 18, 8, 9, // 23 - 56, 18, 8, 9, // 24 - 0, 27, 8, 9, // 25 - 8, 27, 8, 9, // 26 - 16, 27, 8, 9, // 27 - 24, 27, 8, 9, // 28 - 32, 27, 8, 9, // 29 - 40, 27, 8, 9, // 30 - 48, 27, 8, 9, // 31 - 56, 27, 8, 9, // 32 - 0, 36, 8, 9, // 33 - 8, 36, 8, 9, // 34 - 16, 36, 8, 9, // 35 - 24, 36, 8, 9, // 36 - 32, 36, 8, 9, // 37 - 40, 36, 8, 9, // 38 - 48, 36, 8, 9, // 39 - 56, 36, 8, 9, // 40 - 0, 45, 8, 9, // 41 - 8, 45, 8, 9, // 42 - 16, 45, 8, 9, // 43 - 24, 45, 8, 9, // 44 - 32, 45, 8, 9, // 45 - 40, 45, 8, 9, // 46 - 48, 45, 8, 9, // 47 - 56, 45, 8, 9, // 48 - 0, 54, 8, 9, // 49 - 8, 54, 8, 9, // 50 - 16, 54, 8, 9, // 51 - 24, 54, 8, 9, // 52 - 32, 54, 8, 9, // 53 - 40, 54, 8, 9, // 54 - 48, 54, 8, 9, // 55 - 56, 54, 8, 9, // 56 - 0, 63, 8, 9, // 57 - 8, 63, 8, 9, // 58 - 16, 63, 8, 9, // 59 - 24, 63, 8, 9, // 60 - 32, 63, 8, 9, // 61 - 40, 63, 8, 9, // 62 - 48, 63, 8, 9, // 63 - 56, 63, 8, 9, // 64 - 0, 72, 8, 9, // 65 - 0, 81, 8, 9, // 66 - 0, 90, 8, 9, // 67 - 0, 99, 8, 9, // 68 - 0, 108, 8, 9, // 69 - 0, 117, 8, 9, // 70 - 8, 72, 8, 9, // 71 - 8, 81, 8, 9, // 72 - 8, 90, 8, 9, // 73 - 8, 99, 8, 9, // 74 - 8, 108, 8, 9, // 75 - 8, 117, 8, 9, // 76 - 16, 72, 8, 9, // 77 - 24, 72, 8, 9, // 78 - 32, 72, 8, 9, // 79 - 40, 72, 8, 9, // 80 - 48, 72, 8, 9, // 81 - 56, 72, 8, 9, // 82 - 16, 81, 8, 9, // 83 - 16, 90, 8, 9, // 84 - 16, 99, 8, 9, // 85 - 16, 108, 8, 9, // 86 - 16, 117, 8, 9, // 87 - 24, 81, 8, 9, // 88 - 32, 81, 8, 9, // 89 - 40, 81, 8, 9, // 90 - 48, 81, 8, 9, // 91 - 56, 81, 8, 9, // 92 - 24, 90, 8, 9, // 93 - 24, 99, 8, 9, // 94 - 24, 108, 8, 9, // 95 + 0, 0, 8, 9, // 0 + 8, 0, 8, 9, // 1 + 16, 0, 8, 9, // 2 + 24, 0, 8, 9, // 3 + 32, 0, 8, 9, // 4 + 40, 0, 8, 9, // 5 + 48, 0, 8, 9, // 6 + 56, 0, 8, 9, // 7 + 0, 9, 8, 9, // 8 + 8, 9, 8, 9, // 9 + 16, 9, 8, 9, // 10 + 24, 9, 8, 9, // 11 + 24, 117, 4, 9, // 12 + 32, 9, 8, 9, // 13 + 40, 9, 8, 9, // 14 + 48, 9, 8, 9, // 15 + 56, 9, 8, 9, // 16 + 0, 18, 8, 9, // 17 + 8, 18, 8, 9, // 18 + 16, 18, 8, 9, // 19 + 24, 18, 8, 9, // 20 + 32, 18, 8, 9, // 21 + 40, 18, 8, 9, // 22 + 48, 18, 8, 9, // 23 + 56, 18, 8, 9, // 24 + 0, 27, 8, 9, // 25 + 8, 27, 8, 9, // 26 + 16, 27, 8, 9, // 27 + 24, 27, 8, 9, // 28 + 32, 27, 8, 9, // 29 + 40, 27, 8, 9, // 30 + 48, 27, 8, 9, // 31 + 56, 27, 8, 9, // 32 + 0, 36, 8, 9, // 33 + 8, 36, 8, 9, // 34 + 16, 36, 8, 9, // 35 + 24, 36, 8, 9, // 36 + 32, 36, 8, 9, // 37 + 40, 36, 8, 9, // 38 + 48, 36, 8, 9, // 39 + 56, 36, 8, 9, // 40 + 0, 45, 8, 9, // 41 + 8, 45, 8, 9, // 42 + 16, 45, 8, 9, // 43 + 24, 45, 8, 9, // 44 + 32, 45, 8, 9, // 45 + 40, 45, 8, 9, // 46 + 48, 45, 8, 9, // 47 + 56, 45, 8, 9, // 48 + 0, 54, 8, 9, // 49 + 8, 54, 8, 9, // 50 + 16, 54, 8, 9, // 51 + 24, 54, 8, 9, // 52 + 32, 54, 8, 9, // 53 + 40, 54, 8, 9, // 54 + 48, 54, 8, 9, // 55 + 56, 54, 8, 9, // 56 + 0, 63, 8, 9, // 57 + 8, 63, 8, 9, // 58 + 16, 63, 8, 9, // 59 + 24, 63, 8, 9, // 60 + 32, 63, 8, 9, // 61 + 40, 63, 8, 9, // 62 + 48, 63, 8, 9, // 63 + 56, 63, 8, 9, // 64 + 0, 72, 8, 9, // 65 + 0, 81, 8, 9, // 66 + 0, 90, 8, 9, // 67 + 0, 99, 8, 9, // 68 + 0, 108, 8, 9, // 69 + 0, 117, 8, 9, // 70 + 8, 72, 8, 9, // 71 + 8, 81, 8, 9, // 72 + 8, 90, 8, 9, // 73 + 8, 99, 8, 9, // 74 + 8, 108, 8, 9, // 75 + 8, 117, 8, 9, // 76 + 16, 72, 8, 9, // 77 + 24, 72, 8, 9, // 78 + 32, 72, 8, 9, // 79 + 40, 72, 8, 9, // 80 + 48, 72, 8, 9, // 81 + 56, 72, 8, 9, // 82 + 16, 81, 8, 9, // 83 + 16, 90, 8, 9, // 84 + 16, 99, 8, 9, // 85 + 16, 108, 8, 9, // 86 + 16, 117, 8, 9, // 87 + 24, 81, 8, 9, // 88 + 32, 81, 8, 9, // 89 + 40, 81, 8, 9, // 90 + 48, 81, 8, 9, // 91 + 56, 81, 8, 9, // 92 + 24, 90, 8, 9, // 93 + 24, 99, 8, 9, // 94 + 24, 108, 8, 9, // 95 }; - #endif diff --git a/source/font.cpp b/source/font.cpp index 42af16f9..d80f1f12 100644 --- a/source/font.cpp +++ b/source/font.cpp @@ -17,7 +17,7 @@ void Font::print(int x, int y, const char *str) u8 ch; while (*str) // iterate through string { - ch = (*str++) - 32; // get the subimage index + ch = (*str++) - 32; // get the subimage index glSprite(x, y, GL_FLIP_NONE, &spr[ch]); // draw the image x += spr[ch].width; } From 5174252574429185ca514732beebc37dccfc00a2 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 19:05:59 +0600 Subject: [PATCH 11/26] proper birch leaves coloring --- source/entity.cpp | 2 +- source/player.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/entity.cpp b/source/entity.cpp index 1700ca1f..f0c56f69 100644 --- a/source/entity.cpp +++ b/source/entity.cpp @@ -248,7 +248,7 @@ void DropEntity::draw(Camera camera) } else if (blockid == "birchleaves") { - glColor(RGB15(0, 22, 0)); + glColor(RGB15(20, 26, 19)); glSpriteScale(x + 4 - camera.x, y + 4 - camera.y, HALFSIZE, GL_FLIP_NONE, sprBirchLeaves); glColor(RGB15(31, 31, 31)); } diff --git a/source/player.cpp b/source/player.cpp index e4385cba..e76465ba 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -511,7 +511,7 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo glColor(RGB15(31, 31, 31)); break; case InventoryItemID::BirchLeaves: - glColor(RGB15(0, 22, 0)); + glColor(RGB15(20, 26, 19)); glSpriteScale(xx + 4, yy + 4, HALFSIZE, GL_FLIP_NONE, sprBirchLeaves); glColor(RGB15(31, 31, 31)); break; @@ -642,7 +642,7 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo break; case InventoryItemID::BirchLeaves: - glColor(RGB15(0, 22, 0)); + glColor(RGB15(20, 26, 19)); glSprite(getRectAim(camera).x - camera.x, getRectAim(camera).y - camera.y, GL_FLIP_NONE, sprBirchLeaves); glColor(RGB15(31, 31, 31)); @@ -759,7 +759,7 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo glColor(RGB15(31, 31, 31)); break; case InventoryItemID::BirchLeaves: - glColor(RGB15(0, 22, 0)); + glColor(RGB15(20, 26, 19)); glSpriteScale(i * 16 + (SCREEN_WIDTH / 2 - (5 * 16 / 2)) + 4, SCREEN_HEIGHT - 16 + 4, HALFSIZE, GL_FLIP_NONE, sprBirchLeaves); glColor(RGB15(31, 31, 31)); From ceb46ffc81b52f35353ec4b60c035a6efcb33f40 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 19:10:25 +0600 Subject: [PATCH 12/26] setting language to russian works from settings menu --- source/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/main.cpp b/source/main.cpp index 954fb11e..338b2607 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -605,13 +605,16 @@ int main(int argc, char **argv) if (down & KEY_A) { - if (!lsSelected) + if (lsSelected == 0) { lang = Language::English; fsWrite("config/lang.cfg", "0"); } else + { + lang = Language::Russian; fsWrite("config/lang.cfg", "1"); + } mmEffectEx(&sndClick); gameState = GameState::Menu; From 109c027021e92932a1c9968fb6b7e6997a74e66a Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 19:29:54 +0600 Subject: [PATCH 13/26] update world_label_select.png --- gfx/world_label_select.png | Bin 209 -> 209 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/gfx/world_label_select.png b/gfx/world_label_select.png index 9cc9349c86382fa6b14587feca3f06505a27f430..c2b5e48b9813c8825b4bfdd125bb89c33dea5dfe 100644 GIT binary patch delta 17 Ycmcb}c#&~}54((v%#@xR5{<05tFg Date: Mon, 8 Aug 2022 19:30:07 +0600 Subject: [PATCH 14/26] main has access to leaves textures --- source/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 338b2607..19f8fd57 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -23,9 +23,11 @@ #include #include -extern glImage sprDirt[1]; // from block.cpp +extern glImage sprDirt[1]; +extern glImage sprLeaves[1]; +extern glImage sprBirchLeaves[1]; -extern mm_sound_effect sndClick; // from player.cpp +extern mm_sound_effect sndClick; static mm_sound_effect sndPop; From 1e50c488bc00d6ff1dcb877e2df6f9d338cebba1 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 19:30:56 +0600 Subject: [PATCH 15/26] simplify conversion --- source/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/main.cpp b/source/main.cpp index 19f8fd57..55ea6293 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -527,7 +527,7 @@ int main(int argc, char **argv) } else if (down & KEY_DOWN) { - if ((std::vector::size_type)(wsSelected + 1) < wsWorlds.size()) + if ((size_t)(wsSelected + 1) < wsWorlds.size()) ++wsSelected; } else if (down & KEY_UP) From 07ee94b2873b86181f38d77eb27bf6d987cabe26 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 19:31:26 +0600 Subject: [PATCH 16/26] formatting change --- source/main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 55ea6293..f5c50eed 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -548,9 +548,10 @@ int main(int argc, char **argv) else if (down & KEY_A) { // trim the string - createWorldName.erase(createWorldName.begin(), std::find_if(createWorldName.begin(), - createWorldName.end(), [](unsigned char ch) - { return !std::isspace(ch); })); + createWorldName.erase(createWorldName.begin(), + std::find_if(createWorldName.begin(), + createWorldName.end(), [](unsigned char ch) + { return !std::isspace(ch); })); createWorldName.erase(std::find_if(createWorldName.rbegin(), createWorldName.rend(), [](unsigned char ch) { From 4458103ea4ca0c9ccee9bd0b759de55cd31e6dad Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 19:35:04 +0600 Subject: [PATCH 17/26] add transparent versions of leaves --- gfx/birch_leaves_a.grit | 3 +++ gfx/birch_leaves_a.png | Bin 0 -> 231 bytes gfx/oak_leaves_a.grit | 3 +++ gfx/oak_leaves_a.png | Bin 0 -> 256 bytes 4 files changed, 6 insertions(+) create mode 100644 gfx/birch_leaves_a.grit create mode 100644 gfx/birch_leaves_a.png create mode 100644 gfx/oak_leaves_a.grit create mode 100644 gfx/oak_leaves_a.png diff --git a/gfx/birch_leaves_a.grit b/gfx/birch_leaves_a.grit new file mode 100644 index 00000000..b9e298f2 --- /dev/null +++ b/gfx/birch_leaves_a.grit @@ -0,0 +1,3 @@ +-W3 +-gb +-gB4 diff --git a/gfx/birch_leaves_a.png b/gfx/birch_leaves_a.png new file mode 100644 index 0000000000000000000000000000000000000000..6a75c99edd70bf35c6cab072e09ee85e62fc630f GIT binary patch literal 231 zcmV^e%@zrZRJ=UA!}n1$!x>2a|66MML2<|CZPBh6)JL7PN}#@ z4``I^YD>Wl%|*+znCEn|t`#S^{k5D#*k!9BghJYywVK7N_h7nbs~Jhf1D{TH(pfv) h%A%xMyDObtxDT$oYWFZ_Te<)M002ovPDHLkV1hy2V6*@L literal 0 HcmV?d00001 diff --git a/gfx/oak_leaves_a.grit b/gfx/oak_leaves_a.grit new file mode 100644 index 00000000..b9e298f2 --- /dev/null +++ b/gfx/oak_leaves_a.grit @@ -0,0 +1,3 @@ +-W3 +-gb +-gB4 diff --git a/gfx/oak_leaves_a.png b/gfx/oak_leaves_a.png new file mode 100644 index 0000000000000000000000000000000000000000..02e8b865de71c5cf078066f6ff273d4b4c20206f GIT binary patch literal 256 zcmV+b0ssDqP)~pOAjZO_es6(G==3bYzcEZL?M4&xUF}tlXL(*{;`#3I_Jv-n6@kfvPw1k@i84(er zJ_~mp5_(pm)TiQ3fvTz);n*{igY6@NEajwK33b;Ce3Xfo&NG#Ny)a9eie~`Jxv0+$ zB!aASC8m92W`;X7q{RwM3JI48*aPK9qN>XWDJqh*boT?!UCs}=mvJ}%0000 Date: Mon, 8 Aug 2022 19:39:41 +0600 Subject: [PATCH 18/26] leaves are now transparent (not for long) --- include/images.h | 2 ++ source/main.cpp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/include/images.h b/include/images.h index ac224d36..8c5cc15d 100644 --- a/include/images.h +++ b/include/images.h @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include #include #include #include diff --git a/source/main.cpp b/source/main.cpp index f5c50eed..5ad2d054 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -211,6 +211,9 @@ int main(int argc, char **argv) loadImage(direntGames, 64, 64, dirent_gamesBitmap); + loadImageAlpha(sprBirchLeaves, 16, 16, birch_leaves_aPal, birch_leaves_aBitmap); + loadImageAlpha(sprLeaves, 16, 16, oak_leaves_aPal, oak_leaves_aBitmap); + GameState gameState = #if SKIP_SPLASH_SCREEN fsFileExists("config/lang.cfg") ? GameState::Menu : GameState::LanguageSelect From 6d35e8dd603fe5f2c9004d288a1fe2dfe7702ee1 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:41:32 +0600 Subject: [PATCH 19/26] transparent leaves in settings --- source/main.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 5ad2d054..7b5705ca 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -31,6 +31,8 @@ extern mm_sound_effect sndClick; static mm_sound_effect sndPop; +static bool transparentLeaves = false; + BlockList blocks; EntityList entities; Player player; @@ -141,15 +143,33 @@ int main(int argc, char **argv) char *data = fsReadFile("config/lang.cfg"); if (data[0] == '1') lang = Language::Russian; + else if (data[0] != '0') // invalid lang + { + printf("invalid language code %c ", data[0]); + while (true) + ; + } + } + + transparentLeaves = false; + if (fsFileExists("config/trleaves.cfg")) + { + char *data = fsReadFile("config/trleaves.cfg"); + transparentLeaves = data[0] == '1'; + if (data[0] != '0') + fsWrite("config/trleaves.cfg", "0"); } + else + fsWrite("config/trleaves.cfg", "0"); - // fonts english + // fonts english iumages glImage font16x16Img[FONT_16X16_NUM_IMAGES]; glImage fontSmallImg[FONT_SI_NUM_IMAGES]; - // fonts russian + // fonts russian images glImage fontSmallRuImg[FONT_SI_NUM_IMAGES]; glImage font16x16RuImg[FONT_16X16_NUM_IMAGES]; + Font font, fontSmall, fontSmallRu, fontRu; // load fonts @@ -211,8 +231,11 @@ int main(int argc, char **argv) loadImage(direntGames, 64, 64, dirent_gamesBitmap); - loadImageAlpha(sprBirchLeaves, 16, 16, birch_leaves_aPal, birch_leaves_aBitmap); - loadImageAlpha(sprLeaves, 16, 16, oak_leaves_aPal, oak_leaves_aBitmap); + if (transparentLeaves) + { + loadImageAlpha(sprBirchLeaves, 16, 16, birch_leaves_aPal, birch_leaves_aBitmap); + loadImageAlpha(sprLeaves, 16, 16, oak_leaves_aPal, oak_leaves_aBitmap); + } GameState gameState = #if SKIP_SPLASH_SCREEN @@ -647,12 +670,26 @@ int main(int argc, char **argv) case 0: gameState = GameState::LanguageSelect; break; + case 1: + transparentLeaves = !transparentLeaves; + if (transparentLeaves) + { + loadImageAlpha(sprBirchLeaves, 16, 16, birch_leaves_aPal, birch_leaves_aBitmap); + loadImageAlpha(sprLeaves, 16, 16, oak_leaves_aPal, oak_leaves_aBitmap); + } + else + { + loadImage(sprLeaves, 16, 16, oak_leavesBitmap); + loadImage(sprBirchLeaves, 16, 16, birch_leavesBitmap); + } + fsWrite("config/trleaves.cfg", transparentLeaves ? "1" : "0"); + break; } mmEffectEx(&sndClick); } else if (down & KEY_SELECT) { - if (++settingsSelect > 0) + if (++settingsSelect > 1) { settingsSelect = 0; } @@ -1039,9 +1076,7 @@ int main(int argc, char **argv) drawMovingBackground(sprDirt, frames); if (settingsSelect == 0) - { glColor(RGB15(0, 31, 0)); - } switch (lang) { case Language::English: @@ -1053,6 +1088,25 @@ int main(int argc, char **argv) } glColor(RGB15(31, 31, 31)); + if (settingsSelect == 1) + glColor(RGB15(0, 31, 0)); + switch (lang) + { + case Language::English: + if (transparentLeaves) + fontSmall.printCentered(0, 59, "Transparent leaves ON"); + else + fontSmall.printCentered(0, 59, "Transparent leaves OFF"); + break; + case Language::Russian: + if (transparentLeaves) + fontSmallRu.printCentered(0, 59, "Qsqjsbzp\"g nktu#& CLM"); + else + fontSmallRu.printCentered(0, 59, "Qsqjsbzp\"g nktu#& C]LM"); + break; + } + glColor(RGB15(31, 31, 31)); + glSprite(2, SCREEN_HEIGHT - 17, GL_FLIP_NONE, bbtn); glSprite(2, SCREEN_HEIGHT - 30, GL_FLIP_NONE, abtn); switch (lang) From 6319b26696573fc79b93cc85b1ec112844bcf375 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:45:49 +0600 Subject: [PATCH 20/26] update xbtn.png --- gfx/xbtn.png | Bin 188 -> 190 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/gfx/xbtn.png b/gfx/xbtn.png index 54b47e5bb46895734e34a197244eda8561b630af..4fc6662cddb16524c138e9572d5cc84358b8bb88 100644 GIT binary patch delta 73 zcmdnPxQ}r{BHsZ92EGG~S=Tx_85kI>C+5o=7&xEwkW^Z_BxgyB8dLHC(ZgF0^Rz@e d3K$qLFtBuSH0lX#jR2};@O1TaS?83{1OQ=C7LEV_ delta 71 zcmdnTxQB5ZlEcw>ilzPrP$h$>tDnm{r-UW|T~Zdo From 38f9d44df844e4f608cff9d250528d6df3256c34 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:47:42 +0600 Subject: [PATCH 21/26] birch trees in all biomes --- source/terrain.cpp | 122 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 94 insertions(+), 28 deletions(-) diff --git a/source/terrain.cpp b/source/terrain.cpp index bac801da..1b9cdec6 100644 --- a/source/terrain.cpp +++ b/source/terrain.cpp @@ -16,7 +16,7 @@ void generateTerrain(BlockList &blocks, EntityList &entities, Player &player) // 1 = desert // 2 = plains // 3 = snow - u8 biome = /*randomRange(0, 3)*/ 0; + u8 biome = randomRange(0, 3); if (biome == 0) { for (u16 i = k * SCREEN_WIDTH * 2 / 16; i < k * SCREEN_WIDTH * 2 / 16 + SCREEN_WIDTH * 2 / 16; ++i) @@ -202,38 +202,71 @@ void generateTerrain(BlockList &blocks, EntityList &entities, Player &player) if (chance(9) && sinceLastTree > treeInterval) { placedTree = true; - u8 tree = chance(50) ? 1 : 0; + u8 tree = randomRange(0, 3); // tree variant if (tree == 0) { - blocks.emplace_back(new WoodBlock(i, y - 16)); - blocks.emplace_back(new WoodBlock(i, y - 32)); - blocks.emplace_back(new WoodBlock(i, y - 48)); - blocks.emplace_back(new LeavesBlock(i, y - 64, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 64, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i - 32, y - 64, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 64, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i + 32, y - 64, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i, y - 80, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 80, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 80, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i, y - 96, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 96, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 96, LeavesType::Oak)); + blocks.emplace_back(new WoodBlock(i * 16, y - 16)); + blocks.emplace_back(new WoodBlock(i * 16, y - 32)); + blocks.emplace_back(new WoodBlock(i * 16, y - 48)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 32, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 32, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 96, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 96, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 96, LeavesType::Oak)); treeInterval = 5; } else if (tree == 1) { - blocks.emplace_back(new WoodBlock(i, y - 16)); - blocks.emplace_back(new WoodBlock(i, y - 32)); - blocks.emplace_back(new LeavesBlock(i, y - 48, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 48, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 48, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i, y - 64, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 64, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 64, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i, y - 80, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i - 16, y - 80, LeavesType::Oak)); - blocks.emplace_back(new LeavesBlock(i + 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new WoodBlock(i * 16, y - 16)); + blocks.emplace_back(new WoodBlock(i * 16, y - 32)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 48, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Oak)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Oak)); + treeInterval = 3; + } + else if (tree == 2) + { + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 16)); + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 32)); + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 48)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 32, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 32, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 96, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 96, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 96, LeavesType::Birch)); + treeInterval = 5; + } + else if (tree == 3) + { + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 16)); + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 32)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 48, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 48, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 48, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Birch)); treeInterval = 3; } sinceLastTree = 0; @@ -274,7 +307,7 @@ void generateTerrain(BlockList &blocks, EntityList &entities, Player &player) if (chance(20) && sinceLastTree > treeInterval) { - u8 tree = chance(50) ? 1 : 0; + u8 tree = randomRange(0, 3); // tree variant if (tree == 0) { blocks.emplace_back(new WoodBlock(i * 16, y - 16)); @@ -308,6 +341,39 @@ void generateTerrain(BlockList &blocks, EntityList &entities, Player &player) blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Oak)); treeInterval = 3; } + else if (tree == 2) + { + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 16)); + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 32)); + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 48)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 32, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 32, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 96, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 96, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 96, LeavesType::Birch)); + treeInterval = 5; + } + else if (tree == 3) + { + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 16)); + blocks.emplace_back(new BirchWoodBlock(i * 16, y - 32)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 48, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 48, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 48, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 64, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 - 16, y - 80, LeavesType::Birch)); + blocks.emplace_back(new LeavesBlock(i * 16 + 16, y - 80, LeavesType::Birch)); + treeInterval = 3; + } sinceLastTree = 0; } } From 16d24a725febea05c62696829e2f824f905b43f5 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:49:14 +0600 Subject: [PATCH 22/26] update xbtn again --- gfx/xbtn.png | Bin 190 -> 190 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/gfx/xbtn.png b/gfx/xbtn.png index 4fc6662cddb16524c138e9572d5cc84358b8bb88..b07ba1f5418b59f60bb327e0a0ad4e8262b5a778 100644 GIT binary patch delta 44 zcmdnTxQ}tdOjRwWaOU&_TMzTJL^}!?7%(ufEdYA6WAKT00f?{elF{r5}E)+s0~;E From 8d9a8d90bac714965e04c7e34b1d8c0e2a5c2581 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:52:29 +0600 Subject: [PATCH 23/26] fix my formatter --- source/player.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/source/player.cpp b/source/player.cpp index e76465ba..feab1e52 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -1577,14 +1577,31 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con u8 effect = rand() % 4; std::string id = block->id(); if (id == "grass") + { // omg my formatter is going crazy - playsfx(effect, sndStepGrass1, sndStepGrass2, sndStepGrass3, sndStepGrass4) else if (id == "dirt") - playsfx(effect, sndStepGravel1, sndStepGravel2, sndStepGravel3, sndStepGravel4) else if (id == "stone" || id == "sandstone" || id == "cobblestone" || - id == "coal ore" || id == "coal block" || id == "bedrock") - playsfx(effect, sndStepStone1, sndStepStone2, sndStepStone3, sndStepStone4) else if (id == "sand") - playsfx(effect, sndStepSand1, sndStepSand2, sndStepSand3, sndStepSand4) else if (id == "snowy grass") - playsfx(effect, sndStepSnow1, sndStepSnow2, sndStepSnow3, sndStepSnow4) else if (id == "planks" || id == "door") - playsfx(effect, sndStepWood1, sndStepWood2, sndStepWood3, sndStepWood4) + playsfx(effect, sndStepGrass1, sndStepGrass2, sndStepGrass3, sndStepGrass4); + } + else if (id == "dirt") + { + playsfx(effect, sndStepGravel1, sndStepGravel2, sndStepGravel3, sndStepGravel4); + } + else if (id == "stone" || id == "sandstone" || id == "cobblestone" || + id == "coal ore" || id == "coal block" || id == "bedrock") + { + playsfx(effect, sndStepStone1, sndStepStone2, sndStepStone3, sndStepStone4); + } + else if (id == "sand") + { + playsfx(effect, sndStepSand1, sndStepSand2, sndStepSand3, sndStepSand4); + } + else if (id == "snowy grass") + { + playsfx(effect, sndStepSnow1, sndStepSnow2, sndStepSnow3, sndStepSnow4); + } + else if (id == "planks" || id == "door") + { + playsfx(effect, sndStepWood1, sndStepWood2, sndStepWood3, sndStepWood4); + } } } From 955dae8a0012ef7b810b6a04edb83f190d3809fa Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:52:48 +0600 Subject: [PATCH 24/26] message --- source/player.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/source/player.cpp b/source/player.cpp index feab1e52..e0b26391 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -1578,7 +1578,6 @@ bool Player::update(Camera *camera, BlockList *blocks, EntityList *entities, con std::string id = block->id(); if (id == "grass") { - // omg my formatter is going crazy playsfx(effect, sndStepGrass1, sndStepGrass2, sndStepGrass3, sndStepGrass4); } else if (id == "dirt") From 1b6be50d3e69b7b445ecd00905060f3988fb4f1e Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 21:36:26 +0600 Subject: [PATCH 25/26] fix head rotation --- source/player.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/source/player.cpp b/source/player.cpp index e0b26391..8566bf30 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -591,14 +591,31 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo else { // draw the player - int angle = atan2(y + 6 - camera.y - aimY, x + 5 - camera.x - aimX) * 180 / M_PI * 40; + double angleRad = atan2(y + 6 - camera.y - aimY, x + 5 - camera.x - aimX); + if (facing == Facing::Right) + { + if (aimY > SCREEN_HEIGHT / 2) + { + angleRad += 3.14; + } + else + { + angleRad -= 3.14; + } + } + int angle = angleRad * 180 / M_PI * 40; glSprite(x - 1 - camera.x - (facing == Facing::Right ? 0 : 3), y - camera.y, (facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H), sprPlayer); - glSpriteRotate(x + 5 - camera.x, y + 6 - camera.y, - angle, - (facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H), sprPlayerHead); + if (aimY >= 97 && aimY <= 102 && facing == Facing::Right) + glSprite(x - 2 - camera.x, y - 1 - camera.y, GL_FLIP_NONE, sprPlayerHead); + else + glSpriteRotate(x + 5 - camera.x, y + 6 - camera.y, + angle, + (facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H), sprPlayerHead); glPolyFmt(POLY_ALPHA(15) | POLY_CULL_NONE | POLY_ID(1)); + printf("%d\n", aimY); + // draw the aim as green square or a half-transparent // version of the block InventoryItemID currid = inventory[inventorySelect].id; From e3ebd2a555514b80c3612454a43c55def0d959d4 Mon Sep 17 00:00:00 2001 From: lispy2010 <79205601+lispy2010@users.noreply.github.com> Date: Mon, 8 Aug 2022 21:37:01 +0600 Subject: [PATCH 26/26] remove debug printf --- source/player.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/player.cpp b/source/player.cpp index 8566bf30..a4742a69 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -614,8 +614,6 @@ void Player::draw(Camera camera, Font fontSmall, Font font, Font fontSmallRu, Fo (facing == Facing::Right ? GL_FLIP_NONE : GL_FLIP_H), sprPlayerHead); glPolyFmt(POLY_ALPHA(15) | POLY_CULL_NONE | POLY_ID(1)); - printf("%d\n", aimY); - // draw the aim as green square or a half-transparent // version of the block InventoryItemID currid = inventory[inventorySelect].id;