Add spiders
This commit is contained in:
@@ -6,7 +6,30 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|||||||
|
|
||||||
# Option to switch real platform vs. SDL implementation...
|
# Option to switch real platform vs. SDL implementation...
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
SDL3
|
||||||
|
URL https://github.com/libsdl-org/SDL/releases/download/release-3.2.14/SDL3-3.2.14.tar.gz
|
||||||
|
OVERRIDE_FIND_PACKAGE
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(SDL3)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
SDL3_ttf
|
||||||
|
URL https://github.com/libsdl-org/SDL_ttf/releases/download/release-3.2.2/SDL3_ttf-3.2.2.tar.gz
|
||||||
|
OVERRIDE_FIND_PACKAGE
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(SDL3_ttf)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
flecs
|
||||||
|
URL https://github.com/SanderMertens/flecs/archive/refs/tags/v4.0.5.tar.gz
|
||||||
|
OVERRIDE_FIND_PACKAGE
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(flecs)
|
||||||
|
|
||||||
find_package(SDL3 CONFIG REQUIRED)
|
find_package(SDL3 CONFIG REQUIRED)
|
||||||
|
find_package(SDL3_ttf CONFIG REQUIRED)
|
||||||
find_package(flecs CONFIG REQUIRED)
|
find_package(flecs CONFIG REQUIRED)
|
||||||
find_package(spdlog CONFIG REQUIRED)
|
find_package(spdlog CONFIG REQUIRED)
|
||||||
|
|
||||||
@@ -16,6 +39,6 @@ add_executable(HansTheGatherer
|
|||||||
src/physics.cpp
|
src/physics.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(HansTheGatherer SDL3::SDL3 flecs::flecs spdlog::spdlog)
|
target_link_libraries(HansTheGatherer SDL3::SDL3 SDL3_ttf::SDL3_ttf flecs::flecs spdlog::spdlog)
|
||||||
|
|
||||||
set_property(TARGET HansTheGatherer PROPERTY CXX_STANDARD 20)
|
set_property(TARGET HansTheGatherer PROPERTY CXX_STANDARD 20)
|
||||||
|
|||||||
2
NOTICE
2
NOTICE
@@ -6,3 +6,5 @@ Assets used by this project:
|
|||||||
URL: https://trashboat93.itch.io/jungle-background-parallax
|
URL: https://trashboat93.itch.io/jungle-background-parallax
|
||||||
- "Jamaican Sunrise - Reggae" by DavidKBD
|
- "Jamaican Sunrise - Reggae" by DavidKBD
|
||||||
URL: https://davidkbd.itch.io/tropical-dreams-spring-and-summer-music-pack
|
URL: https://davidkbd.itch.io/tropical-dreams-spring-and-summer-music-pack
|
||||||
|
- "SPIDER ENEMY PIXEL ART" by camacebra
|
||||||
|
URL: https://camacebra.itch.io/spider-pixel-art-pack-16x16
|
||||||
BIN
assets/images/spiders.bmp
Normal file
BIN
assets/images/spiders.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.1 KiB |
@@ -13,6 +13,10 @@ static constexpr uint8_t FRUITS_DATA[] = {
|
|||||||
#embed "../assets/images/fruits.bmp"
|
#embed "../assets/images/fruits.bmp"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static constexpr uint8_t SPIDERS_DATA[] = {
|
||||||
|
#embed "../assets/images/spiders.bmp"
|
||||||
|
};
|
||||||
|
|
||||||
static constexpr uint8_t BASKET_DATA[] = {
|
static constexpr uint8_t BASKET_DATA[] = {
|
||||||
#embed "../assets/images/basket.bmp"
|
#embed "../assets/images/basket.bmp"
|
||||||
};
|
};
|
||||||
@@ -79,12 +83,16 @@ AssetModule::AssetModule(flecs::world& world)
|
|||||||
auto* fruits = load_texture(FRUITS_DATA, sizeof(FRUITS_DATA), renderer);
|
auto* fruits = load_texture(FRUITS_DATA, sizeof(FRUITS_DATA), renderer);
|
||||||
TextureAtlasLayout fruits_layout = {.width = 16, .height = 16, .rows = 6, .columns = 38};
|
TextureAtlasLayout fruits_layout = {.width = 16, .height = 16, .rows = 6, .columns = 38};
|
||||||
|
|
||||||
|
auto* spiders = load_texture(SPIDERS_DATA, sizeof(SPIDERS_DATA), renderer);
|
||||||
|
TextureAtlasLayout spiders_layout = {.width = 16, .height = 16, .rows = 2, .columns = 4};
|
||||||
|
|
||||||
auto* basket = load_texture(BASKET_DATA, sizeof(BASKET_DATA), renderer);
|
auto* basket = load_texture(BASKET_DATA, sizeof(BASKET_DATA), renderer);
|
||||||
TextureAtlasLayout basket_layout = {.width = 16, .height = 16, .rows = 1, .columns = 1};
|
TextureAtlasLayout basket_layout = {.width = 16, .height = 16, .rows = 1, .columns = 1};
|
||||||
|
|
||||||
world.set<TextureAssets>(TextureAssets{
|
world.set<TextureAssets>(TextureAssets{
|
||||||
.background = Texture{.sdl_texture = background, .texture_atlas_layout = background_layout},
|
.background = Texture{.sdl_texture = background, .texture_atlas_layout = background_layout},
|
||||||
.fruits = Texture{.sdl_texture = fruits, .texture_atlas_layout = fruits_layout},
|
.fruits = Texture{.sdl_texture = fruits, .texture_atlas_layout = fruits_layout},
|
||||||
|
.spiders = Texture{.sdl_texture = spiders, .texture_atlas_layout = spiders_layout},
|
||||||
.basket = Texture{.sdl_texture = basket, .texture_atlas_layout = basket_layout}});
|
.basket = Texture{.sdl_texture = basket, .texture_atlas_layout = basket_layout}});
|
||||||
|
|
||||||
auto background_music = load_audio(BACKGROUND_MUSIC_DATA, sizeof(BACKGROUND_MUSIC_DATA));
|
auto background_music = load_audio(BACKGROUND_MUSIC_DATA, sizeof(BACKGROUND_MUSIC_DATA));
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ struct TextureAssets
|
|||||||
{
|
{
|
||||||
Texture background;
|
Texture background;
|
||||||
Texture fruits;
|
Texture fruits;
|
||||||
|
Texture spiders;
|
||||||
Texture basket;
|
Texture basket;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,6 @@ struct SdlHandles
|
|||||||
struct Game
|
struct Game
|
||||||
{
|
{
|
||||||
uint32_t ticks;
|
uint32_t ticks;
|
||||||
uint32_t time;
|
int32_t time;
|
||||||
uint32_t score;
|
int32_t score;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ struct Fruit
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Spider
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
struct Basket
|
struct Basket
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
@@ -53,23 +57,44 @@ struct LevelModule
|
|||||||
Game const& game,
|
Game const& game,
|
||||||
TextureAssets const& texture_assets)
|
TextureAssets const& texture_assets)
|
||||||
{
|
{
|
||||||
if ((game.ticks % 40) == 0)
|
bool spider = std::rand() % 3 == 0;
|
||||||
|
int vel = std::rand() % 3 + 1;
|
||||||
|
|
||||||
|
if ((game.ticks % 50) == 0)
|
||||||
{
|
{
|
||||||
auto fruit =
|
flecs::entity e;
|
||||||
it.world()
|
if (!spider)
|
||||||
|
{
|
||||||
|
e = it.world()
|
||||||
.entity()
|
.entity()
|
||||||
.add<Fruit>()
|
.add<Fruit>()
|
||||||
.add<WorldPosition>()
|
.add<WorldPosition>()
|
||||||
.set<Position>(Position{.x = std::rand() % WINDOW_WIDTH, .y = -16})
|
.set<Position>(
|
||||||
.set<Velocity>(Velocity{.x = 0, .y = 2})
|
Position{.x = std::rand() % WINDOW_WIDTH, .y = -16})
|
||||||
.set<Sprite>(Sprite{.texture = &texture_assets.fruits,
|
.set<Velocity>(Velocity{.x = 0, .y = vel})
|
||||||
|
.set<Sprite>(
|
||||||
|
Sprite{.texture = &texture_assets.fruits,
|
||||||
.texture_atlas_index =
|
.texture_atlas_index =
|
||||||
static_cast<uint16_t>(game.ticks % 228)})
|
static_cast<uint16_t>(std::rand() % 228)})
|
||||||
.set<Size>(Size{.w = 32, .h = 32});
|
.set<Size>(Size{.w = 32, .h = 32});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e = it.world()
|
||||||
|
.entity()
|
||||||
|
.add<Spider>()
|
||||||
|
.add<WorldPosition>()
|
||||||
|
.set<Position>(
|
||||||
|
Position{.x = std::rand() % WINDOW_WIDTH, .y = -16})
|
||||||
|
.set<Velocity>(Velocity{.x = 0, .y = vel})
|
||||||
|
.set<Sprite>(Sprite{.texture = &texture_assets.spiders,
|
||||||
|
.texture_atlas_index =
|
||||||
|
static_cast<uint16_t>(std::rand() % 8)})
|
||||||
|
.set<Size>(Size{.w = 32, .h = 32});
|
||||||
|
}
|
||||||
it.world()
|
it.world()
|
||||||
.entity("CollisionBox")
|
.entity("CollisionBox")
|
||||||
.child_of(fruit)
|
.child_of(e)
|
||||||
.add<WorldPosition>()
|
.add<WorldPosition>()
|
||||||
.set<Position>(Position{.x = 0, .y = 0})
|
.set<Position>(Position{.x = 0, .y = 0})
|
||||||
.set<Size>(Size{.w = 32, .h = 32})
|
.set<Size>(Size{.w = 32, .h = 32})
|
||||||
@@ -86,7 +111,7 @@ struct LevelModule
|
|||||||
// e.destruct();
|
// e.destruct();
|
||||||
// });
|
// });
|
||||||
|
|
||||||
world.system<Game, Position, Fruit, Collided>("CollectItem")
|
world.system<Game, Position, Fruit, Collided>("CollectFruit")
|
||||||
.term_at(0)
|
.term_at(0)
|
||||||
.singleton()
|
.singleton()
|
||||||
.each(
|
.each(
|
||||||
@@ -96,6 +121,16 @@ struct LevelModule
|
|||||||
pos.x = 1000;
|
pos.x = 1000;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
world.system<Game, Position, Spider, Collided>("CollectSpider")
|
||||||
|
.term_at(0)
|
||||||
|
.singleton()
|
||||||
|
.each(
|
||||||
|
[](flecs::entity e, Game& game, Position& pos, Spider, Collided)
|
||||||
|
{
|
||||||
|
game.score -= 50;
|
||||||
|
pos.x = 1000;
|
||||||
|
});
|
||||||
|
|
||||||
world.system<ButtonInput const, Position, Size const, Sprite const, Basket>("MoveBasket")
|
world.system<ButtonInput const, Position, Size const, Sprite const, Basket>("MoveBasket")
|
||||||
.term_at(0)
|
.term_at(0)
|
||||||
.singleton()
|
.singleton()
|
||||||
|
|||||||
Reference in New Issue
Block a user