dummy sample_08

This commit is contained in:
2019-12-04 10:28:25 +07:00
parent feac21cad6
commit 36cb725cc1
5 changed files with 172 additions and 0 deletions

View File

@@ -46,3 +46,4 @@ add_e2d_sample(04)
add_e2d_sample(05)
add_e2d_sample(06)
add_e2d_sample(07)
add_e2d_sample(08)

View File

@@ -0,0 +1,26 @@
{
"components" : {
"scene" : {},
"behaviour" : {
"script" : "../scripts/sample_08/sample_08.lua"
}
},
"children" : [{
"prototype" : "../prefabs/camera_prefab.json"
},{
"prototype" : "../prefabs/ship_prefab.json",
"components" : {
"actor" : {
"translation" : [0,0],
"scale" : 1
},
"behaviour" : {
"script" : "../scripts/sample_08/ship.lua"
},
"touchable" : {},
"rect_collider" : {
"size" : [66,113]
}
}
}]
}

View File

@@ -0,0 +1,22 @@
local M = {}
---@param go gobject
function M:on_start(go)
the_debug:trace("sample_08: on_start")
end
---@param go gobject
function M:on_update(go)
end
---@param go gobject
---@param type string
---@param event any
function M:on_event(go, type, event)
end
---@param go gobject
function M:on_shutdown(go)
end
return M

View File

@@ -0,0 +1,36 @@
-- -----------------------------------------------------------------------------
--
-- private
--
-- -----------------------------------------------------------------------------
---@class ship_meta
---@param meta ship_meta
---@param go gobject
local function update_ship_rotation(meta, go)
local time = the_engine.time
go.actor.node.rotation = time
end
-- -----------------------------------------------------------------------------
--
-- meta
--
-- -----------------------------------------------------------------------------
local M = {}
---@param meta ship_meta
---@param go gobject
function M.on_start(meta, go)
meta.life_time = 5
end
---@param meta ship_meta
---@param go gobject
function M.on_update(meta, go)
update_ship_rotation(meta, go)
end
return M

View File

@@ -0,0 +1,87 @@
/*******************************************************************************
* This file is part of the "Enduro2D"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#include "../common.hpp"
using namespace e2d;
namespace
{
class game_system final : public systems::update_system {
public:
void process(
ecs::registry& owner,
const systems::update_event& event) override
{
E2D_UNUSED(owner, event);
const keyboard& k = the<input>().keyboard();
if ( k.is_key_just_released(keyboard_key::f12) ) {
the<dbgui>().toggle_visible(!the<dbgui>().visible());
}
if ( k.is_key_just_released(keyboard_key::escape) ) {
the<window>().set_should_close(true);
}
if ( k.is_key_pressed(keyboard_key::lsuper) && k.is_key_just_released(keyboard_key::enter) ) {
the<window>().toggle_fullscreen(!the<window>().fullscreen());
}
}
};
class camera_system final : public systems::render_system {
public:
void process(
ecs::registry& owner,
const systems::render_event& event) override
{
E2D_UNUSED(event);
owner.for_joined_components<camera>(
[](const ecs::const_entity&, camera& cam){
if ( !cam.target() ) {
cam.viewport(
the<window>().framebuffer_size());
cam.projection(math::make_orthogonal_lh_matrix4(
the<window>().real_size().cast_to<f32>(), 0.f, 1000.f));
}
});
}
};
class game final : public starter::application {
public:
bool initialize() final {
return create_scene()
&& create_systems();
}
private:
bool create_scene() {
auto scene_prefab_res = the<library>().load_asset<prefab_asset>("scenes/sample_08.json");
auto scene_go = scene_prefab_res
? the<world>().instantiate(scene_prefab_res->content())
: gobject();
return scene_go.valid();
}
bool create_systems() {
ecs::registry_filler(the<world>().registry())
.feature<struct game_feature>(ecs::feature()
.add_system<game_system>()
.add_system<camera_system>());
return true;
}
};
}
int e2d_main(int argc, char *argv[]) {
const auto starter_params = starter::parameters(
engine::parameters("sample_08", "enduro2d")
.timer_params(engine::timer_parameters()
.maximal_framerate(100)));
modules::initialize<starter>(argc, argv, starter_params).start<game>();
modules::shutdown<starter>();
return 0;
}