Skip to content

Commit

Permalink
Add conditional sprite creation
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Campos Nunes <[email protected]>
  • Loading branch information
rafaelcn committed May 15, 2023
1 parent dbdf1a6 commit 64990be
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions tux/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,67 @@
#include <iostream>
#include <utility>
#include <vector>

#include "core/game.hpp"
#include "core/event.hpp"
#include "core/types.hpp"
#include "core/functions.hpp"
#include "core/sound/track.hpp"
#include "core/debug/log.hpp"

#include "graphics/sdl/sprite.hpp"

int main() {
using namespace Kokiri::Core;
using namespace Kokiri;
using namespace Kokiri::Graphics::SDL;

Game game("Rafael Campos Nunes - 19/0098295", 1024, 600);

Track bgm("assets/audio/stageState.ogg");
Track effect("assets/audio/boom.wav");

auto render = [&game](){
Sprite sprite_tux(game.get_window(), "assets/img/ocean.jpg");
sprite_tux.render(0,0);
std::vector<std::pair<v2<int>, Sprite*>> assets;

Sprite background(game.get_window(), "assets/img/ocean.jpg");

// user render function
auto render = [&game, &background, &assets](){
background.render(0, 0);

for (const auto& asset : assets) {
auto p = asset.first;
auto s = asset.second;

s->render(p.x, p.y);
}
};

// user event function
auto event = [&game, &assets]() {
auto e = game.get_event();

if (e.get()->is_mouse_click(Event::Mouse::LeftButton)) {
auto p = e.get()->get_mouse_position();
auto s = new Sprite(game.get_window(), "assets/img/penguin.png");

Log::info("click: ", p.x, p.y);

assets.push_back(std::make_pair(p, s));
}
};

game.bind(FunctionType::Event, event);
game.bind(FunctionType::Render, render);

effect.play(-1);
bgm.play(1); // not working over here (linux)
bgm.play(1);

game.loop();

// clean everything
for (const auto& asset : assets) {
delete asset.second;
}

return 0;
}

0 comments on commit 64990be

Please sign in to comment.