png支持

This commit is contained in:
ArchZer0
2026-08-17 10:26:27 +08:00
parent 07aeced2e4
commit 63d97f058a
25 changed files with 893 additions and 261 deletions
+7 -14
View File
@@ -2,29 +2,22 @@
"window": {
"width": 800,
"height": 600,
"title": "OpenCGE - Square Example"
"title": "Boundard - Square Example"
},
"input": [
{ "action": "quit", "keys": ["Escape"] },
{ "action": "reset", "mouse_buttons": ["Left"] },
{ "action": "switch_scene", "keys": ["Tab"] },
{ "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 }
}
}
"start_scene": "square",
"scenes": [
{ "name": "square", "path": "scenes/square.json" },
{ "name": "square_alt", "path": "scenes/square_alt.json" }
]
}
+41
View File
@@ -38,6 +38,47 @@ void register_square_behaviors() {
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);
if (input.is_action_just_pressed("switch_scene")) {
boundard::Game::getInstance().switch_scene("square_alt");
}
});
behaviors.register_init("square_alt_init", [](boundard::Actor& actor) {
actor.set_position({0.0F, 0.0F});
actor.set_facing({0.0F, 1.0F});
if (actor.mesh() != nullptr) {
actor.mesh()->set_color({0.9F, 0.3F, 0.2F, 1.0F});
}
});
behaviors.register_tick(
"square_alt_tick",
[](boundard::Actor& actor, float dt, const boundard::render::InputMap& input) {
const float t = actor.age();
actor.set_facing({
std::sin(t * 1.3F),
std::cos(t * 1.3F),
});
if (actor.mesh() != nullptr) {
actor.mesh()->set_color({
0.5F + 0.5F * std::sin(t * 2.0F + 4.189F),
0.5F + 0.5F * std::sin(t * 2.0F),
0.5F + 0.5F * std::sin(t * 2.0F + 2.094F),
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);
if (input.is_action_just_pressed("switch_scene")) {
boundard::Game::getInstance().switch_scene("square");
}
});
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

+21
View File
@@ -0,0 +1,21 @@
{
"actors": [
{
"name": "square",
"init": "square_init",
"tick": "square_tick",
"position": {
"x": 0,
"y": 0
},
"facing": {
"x": 1,
"y": 0
},
"mesh": {
"shape": "quad",
"texture": "Dank.png"
}
}
]
}
+15
View File
@@ -0,0 +1,15 @@
{
"actors": [
{
"name": "square_alt",
"init": "square_alt_init",
"tick": "square_alt_tick",
"position": { "x": 0, "y": 0 },
"facing": { "x": 0, "y": 1 },
"mesh": {
"shape": "quad",
"color": { "r": 0.9, "g": 0.3, "b": 0.2, "a": 1.0 }
}
}
]
}