aa
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"window": {
|
||||
"width": 800,
|
||||
"height": 600,
|
||||
"title": "OpenCGE - Square Example"
|
||||
},
|
||||
|
||||
"input": [
|
||||
{ "action": "quit", "keys": ["Escape"] },
|
||||
{ "action": "reset", "mouse_buttons": ["Left"] },
|
||||
{ "action": "move_left", "keys": ["Left"] },
|
||||
{ "action": "move_right", "keys": ["Right"] },
|
||||
{ "action": "move_up", "keys": ["Up"] },
|
||||
{ "action": "move_down", "keys": ["Down"] }
|
||||
],
|
||||
|
||||
"actors": [
|
||||
{
|
||||
"name": "square",
|
||||
"init": "square_init",
|
||||
"tick": "square_tick",
|
||||
"position": { "x": 0, "y": 0 },
|
||||
"facing": { "x": 1, "y": 0 },
|
||||
"mesh": {
|
||||
"shape": "quad",
|
||||
"color": { "r": 0.2, "g": 0.8, "b": 0.9, "a": 1.0 }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <openceg.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
void register_square_behaviors() {
|
||||
auto& behaviors = openceg::BehaviorRegistry::getInstance();
|
||||
|
||||
behaviors.register_init("square_init", [](openceg::Actor& actor) {
|
||||
actor.set_position({0.0F, 0.0F});
|
||||
actor.set_facing({1.0F, 0.0F});
|
||||
if (actor.mesh() != nullptr) {
|
||||
actor.mesh()->set_color({0.2F, 0.8F, 0.9F, 1.0F});
|
||||
}
|
||||
});
|
||||
|
||||
behaviors.register_tick(
|
||||
"square_tick",
|
||||
[](openceg::Actor& actor, float dt, const openceg::render::InputMap& input) {
|
||||
const float t = actor.age();
|
||||
actor.set_facing({
|
||||
std::cos(t * 1.5F),
|
||||
std::sin(t * 1.5F),
|
||||
});
|
||||
|
||||
if (actor.mesh() != nullptr) {
|
||||
actor.mesh()->set_color({
|
||||
0.5F + 0.5F * std::sin(t * 2.0F),
|
||||
0.5F + 0.5F * std::sin(t * 2.0F + 2.094F),
|
||||
0.5F + 0.5F * std::sin(t * 2.0F + 4.189F),
|
||||
1.0F,
|
||||
});
|
||||
}
|
||||
|
||||
auto position = actor.position();
|
||||
const float move_speed = 0.7F;
|
||||
position[0] += input.get_axis("move_left", "move_right") * move_speed * dt;
|
||||
position[1] += input.get_axis("move_up", "move_down") * move_speed * dt;
|
||||
actor.set_position(position);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
register_square_behaviors();
|
||||
return openceg::run_engine(argc, argv, "examples/square/config.ceg");
|
||||
}
|
||||
Reference in New Issue
Block a user