mirror of
https://github.com/NoelFB/tiny_link.git
synced 2025-02-20 13:48:28 +08:00
adding gameplay buffer
This commit is contained in:
parent
7d917a98a2
commit
8db43ce18e
@ -10,8 +10,10 @@ add_subdirectory(libs/blah)
|
|||||||
|
|
||||||
# add our source
|
# add our source
|
||||||
add_executable(game
|
add_executable(game
|
||||||
|
src/main.cpp
|
||||||
src/world.cpp
|
src/world.cpp
|
||||||
|
src/game.cpp
|
||||||
|
src/content.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Reference blah
|
# Reference blah
|
||||||
|
40
src/content.cpp
Normal file
40
src/content.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include "content.h"
|
||||||
|
|
||||||
|
using namespace TL;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
FilePath root;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpriteFont Content::font;
|
||||||
|
|
||||||
|
FilePath Content::path()
|
||||||
|
{
|
||||||
|
if (root.length() <= 0)
|
||||||
|
{
|
||||||
|
FilePath up = "";
|
||||||
|
do
|
||||||
|
{
|
||||||
|
root = Path::normalize(FilePath::fmt("%s/%scontent/", App::path(), up.cstr()));
|
||||||
|
up.append("../");
|
||||||
|
} while (!Directory::exists(root) && up.length() < 30);
|
||||||
|
|
||||||
|
if (!Directory::exists(root))
|
||||||
|
BLAH_ERROR("Unable to find content directory!");
|
||||||
|
|
||||||
|
Log::print("Content Path: %s", root.cstr());
|
||||||
|
}
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Content::load()
|
||||||
|
{
|
||||||
|
font = SpriteFont(path() + "fonts/dogica.ttf", 8, SpriteFont::ASCII);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Content::unload()
|
||||||
|
{
|
||||||
|
font.dispose();
|
||||||
|
}
|
17
src/content.h
Normal file
17
src/content.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <blah.h>
|
||||||
|
|
||||||
|
using namespace Blah;
|
||||||
|
|
||||||
|
namespace TL
|
||||||
|
{
|
||||||
|
class Content
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static SpriteFont font;
|
||||||
|
|
||||||
|
static FilePath path();
|
||||||
|
static void load();
|
||||||
|
static void unload();
|
||||||
|
};
|
||||||
|
}
|
55
src/game.cpp
Normal file
55
src/game.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include "game.h"
|
||||||
|
#include "content.h"
|
||||||
|
|
||||||
|
using namespace TL;
|
||||||
|
|
||||||
|
void Game::startup()
|
||||||
|
{
|
||||||
|
// load our content
|
||||||
|
Content::load();
|
||||||
|
|
||||||
|
// framebuffer for the game
|
||||||
|
buffer = FrameBuffer::create(320, 180);
|
||||||
|
|
||||||
|
// set batcher to use Nearest Filter
|
||||||
|
batch.default_sampler = TextureSampler(TextureFilter::Nearest);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::shutdown()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::render()
|
||||||
|
{
|
||||||
|
// draw gameplay stuff
|
||||||
|
{
|
||||||
|
buffer->clear(Color::red);
|
||||||
|
|
||||||
|
batch.str(Content::font, "Hello World", Vec2(32, 32), Color::white);
|
||||||
|
batch.render(buffer);
|
||||||
|
batch.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw buffer to the screen
|
||||||
|
{
|
||||||
|
float scale = Calc::min(
|
||||||
|
App::backbuffer->width() / (float)buffer->width(),
|
||||||
|
App::backbuffer->height() / (float)buffer->height());
|
||||||
|
|
||||||
|
Vec2 screen_center = Vec2(App::backbuffer->width(), App::backbuffer->height()) / 2;
|
||||||
|
Vec2 buffer_center = Vec2(buffer->width(), buffer->height()) / 2;
|
||||||
|
|
||||||
|
App::backbuffer->clear(Color::black);
|
||||||
|
batch.push_matrix(Mat3x2::create_transform(screen_center, buffer_center, Vec2::one * scale, 0));
|
||||||
|
batch.tex(buffer->attachment(0), Vec2::zero, Color::white);
|
||||||
|
batch.pop_matrix();
|
||||||
|
batch.render(App::backbuffer);
|
||||||
|
batch.clear();
|
||||||
|
}
|
||||||
|
}
|
21
src/game.h
Normal file
21
src/game.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <blah.h>
|
||||||
|
#include "world.h"
|
||||||
|
|
||||||
|
using namespace Blah;
|
||||||
|
|
||||||
|
namespace TL
|
||||||
|
{
|
||||||
|
class Game
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
World world;
|
||||||
|
FrameBufferRef buffer;
|
||||||
|
Batch batch;
|
||||||
|
|
||||||
|
void startup();
|
||||||
|
void shutdown();
|
||||||
|
void update();
|
||||||
|
void render();
|
||||||
|
};
|
||||||
|
}
|
45
src/main.cpp
Normal file
45
src/main.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include <blah.h>
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
using namespace Blah;
|
||||||
|
using namespace TL;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
Game game;
|
||||||
|
|
||||||
|
void startup()
|
||||||
|
{
|
||||||
|
game.startup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void shutdown()
|
||||||
|
{
|
||||||
|
game.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void update()
|
||||||
|
{
|
||||||
|
game.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void render()
|
||||||
|
{
|
||||||
|
game.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Config config;
|
||||||
|
config.name = "Tiny Link";
|
||||||
|
config.width = 1280;
|
||||||
|
config.height = 720;
|
||||||
|
|
||||||
|
config.on_startup = startup;
|
||||||
|
config.on_shutdown = shutdown;
|
||||||
|
config.on_update = update;
|
||||||
|
config.on_render = render;
|
||||||
|
|
||||||
|
App::run(&config);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user