Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added bin/resources/levels/levelTest_buttons.bmp
Binary file not shown.
2 changes: 2 additions & 0 deletions src/lib-tempo/include/tempo/component/ComponentStage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ struct ComponentStage
ComponentID getId();
};

void loadButtons(anax::World &world, const char *tile_map);

} // namespace tempo

#endif
77 changes: 75 additions & 2 deletions src/lib-tempo/src/component/ComponentStage.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#include <tempo/component/ComponentStage.hpp>

#include <glm/gtx/string_cast.hpp>
#include <glm/vec2.hpp>

#include <anax/World.hpp>

#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.hpp>

#include <stdint.h>
#include <cstdio>
#include <iostream>
#include <map>

#include <tempo/entity/EntityCreationServer.hpp>

namespace tempo
{

std::vector<stage_tile> _global_stage;
std::string _global_stage_loaded("None");

Expand Down Expand Up @@ -51,7 +56,7 @@ void ComponentStage::loadLevel(const char *stage_file)
}
}
}
tiles = &_global_stage;
tiles = &_global_stage;
_global_stage_loaded = std::string(stage_file);

stbi_image_free(pixel_data);
Expand Down Expand Up @@ -132,4 +137,72 @@ sf::Packet ComponentStage::dumpComponent()
return p;
}


void fake_createButtonGroup(anax::World & world,
std::vector<glm::ivec2> positions,
std::vector<glm::ivec2> tiles)
{
std::cout << "positions = {";
for (int i = 0; i < positions.size() - 1; i++) {
std::cout << glm::to_string(positions[i]) << ",";
}
std::cout << glm::to_string(positions.back()) << "}" << std::endl;

std::cout << "tiles = {";
for (int i = 0; i < tiles.size() - 1; i++) {
std::cout << glm::to_string(tiles[i]) << ",";
}
std::cout << glm::to_string(tiles.back()) << "}" << std::endl;
}

void loadButtons(anax::World &world, const char *tile_map)
{

int width, height, components;

uint8_t *pixel_data = (uint8_t *) stbi_load(tile_map, &width, &height, &components, 4);
if (pixel_data == NULL || width < 0 || height < 0 || components < 0) {
printf("Failed to load level '%s', pixels: %p, width: %i, height: %i, components: %i\n",
tile_map, pixel_data, width, height, components);
return;
}

std::vector<std::vector<glm::ivec2>> buttons(256);
std::vector<std::vector<glm::ivec2>> walls(256);

// Load the new tiles
for (int y = 0; y < height; y++) {
int base = width * y * 4;
for (int x = 0; x < width; x++) {
uint8_t *pixel = &pixel_data[base + x * 4];

uint8_t r = pixel[0];
uint8_t g = pixel[1];
uint8_t b = pixel[2];

if (b == 0 && r != 0) {
// this is a button
// r = index
// g = level
buttons[r].push_back(glm::ivec2(y, x));
} else if (r == 0 && g != 0) {
// this is a wall
// g = index
// b = height
walls[g].push_back(glm::ivec2(y, x));
}
}
}
stbi_image_free(pixel_data);

for (int i = 0; i < 256; i++) {
if (buttons[i].empty() || walls[i].empty()) {
continue;
}

// fake_createButtonGroup(world, buttons[i], walls[i]);
createButtonGroup(world, buttons[i], walls[i]);
}
}

} // namespace tempo
2 changes: 1 addition & 1 deletion src/lib-tempo/src/entity/EntityCreationServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ anax::Entity createButtonGroup(anax::World & world,
std::vector<glm::ivec2> positions,
std::vector<glm::ivec2> tiles)
{
printf("Creating button\n");
// printf("Creating button\n");
anax::Entity entity_button = world.createEntity();
entity_button.addComponent<tempo::ComponentButtonGroup>(positions, tiles);
entity_button.addComponent<tempo::ComponentStage>("resources/levels/levelTest.bmp");
Expand Down
1 change: 1 addition & 0 deletions src/lib-tempo/src/song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Song::Song(std::string path)

void Song::start()
{
//sound.setLoop(true);
sound.play();
}

Expand Down
45 changes: 13 additions & 32 deletions src/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ int main(int argc, const char **argv)
anax::World world;

// Create Systems
server::SystemAI system_ai;
server::SystemAI system_ai;
server::SystemAttack system_attack(world);
server::SystemCombo system_combo;
server::SystemCombo system_combo;
server::SystemMovement system_movement;
tempo::SystemHealth system_health;
tempo::SystemTrigger system_trigger(world);
tempo::SystemHealth system_health;
tempo::SystemTrigger system_trigger(world);

world.addSystem(system_ai);
world.addSystem(system_attack);
Expand All @@ -66,44 +66,26 @@ int main(int argc, const char **argv)
world.refresh();

// Create some Test Entities

tempo::createMobStill(world, glm::ivec2(36, 42));
tempo::createMobStill(world, glm::ivec2(40, 42));
tempo::createMobStill(world, glm::ivec2(44, 42));

tempo::createMobCreeper(world, glm::ivec2(40, 64));

std::deque<glm::ivec2> path {glm::ivec2(64, 68),
glm::ivec2(64, 72),
glm::ivec2(68, 72),
glm::ivec2(68, 68)};
std::deque<glm::ivec2> path{glm::ivec2(64, 68), glm::ivec2(64, 72), glm::ivec2(68, 72),
glm::ivec2(68, 68)};
tempo::createMobPatroller(world, path[0], path);

std::deque<glm::ivec2> path2 {glm::ivec2(11, 67),
glm::ivec2(11, 73),
glm::ivec2(15, 73),
glm::ivec2(15, 67)};
std::deque<glm::ivec2> path2{glm::ivec2(11, 67), glm::ivec2(11, 73), glm::ivec2(15, 73),
glm::ivec2(15, 67)};
tempo::createMobPatroller(world, path2[0], path2);

// tempo::createMobCreeper(world, glm::ivec2(12, 12));
// tempo::createMobCreeper(world, glm::ivec2(14, 14));
// tempo::createMobAntiSnail(world, glm::ivec2(4, 4));

std::vector<glm::ivec2> wall = {{37,17},{38,17},{39,17},{40,17},{41,17},{42,17},{43,17},{44,17}, {45,17}};
tempo::createButtonGroup(world, {{40, 12}}, wall);

std::vector<glm::ivec2> wall1 = {{37,48},{38,48},{39,48},{40,48},{41,48},{42,48},{43,48},{44,48},};
tempo::createButtonGroup(world, {{40, 43},{44,43},{36,43}}, wall1);

std::vector<glm::ivec2> wall2 = {{36,62},{36,63},{36,64},{36,65},{36,66},{36,67},{36,68},
{50,62},{50,63},{50,64},{50,65},{50,66},{50,67},{50,68}};
tempo::createButtonGroup(world, {{40, 65}}, wall2);

std::vector<glm::ivec2> wall3 = {{37,69},{38,69},{39,69},{40,69},{41,69},{42,69},{43,69}};
tempo::createButtonGroup(world, {{66,70},{13,69}}, wall3);

std::vector<glm::ivec2> wall4 = {{40,132},{41,132},{42,132}};
tempo::createButtonGroup(world, {{41,110},{26,128},{57,128}}, wall4);
tempo::loadButtons(world, "resources/levels/levelTest_buttons.bmp");

world.refresh();

Expand Down Expand Up @@ -142,8 +124,7 @@ int main(int argc, const char **argv)
system_health.broadcastHealth();
}

if (clock.passed_antibeat())
{
if (clock.passed_antibeat()) {
}

////////////////
Expand Down