Skip to content

Commit

Permalink
更新地图事件
Browse files Browse the repository at this point in the history
好消息:飞机大战现已加入彩蛋,且场景会显示号码
  • Loading branch information
TsXor committed May 13, 2024
1 parent cf1b354 commit 0088d77
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 38 deletions.
1 change: 1 addition & 0 deletions src/main/activities/avg_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ void avg_scene::render() {
auto offset = ent->hbox.offset / spr.scalev;
spr.render(parent, glut::coord{int(offset.x), int(offset.y)} - camera_pos);
}
if (cust_render) { cust_render(); }
}
1 change: 1 addition & 0 deletions src/main/activities/avg_scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class avg_scene : public sf::base_activity {
entity_comp_t sprites_sorter = default_sprites_sorter();
std::optional<map_render_data> bound_map;
eng::basics::vec2 velocity_direction = {0, 0};
std::function<void()> cust_render;
std::any script_data;


Expand Down
5 changes: 5 additions & 0 deletions src/main/activities/avg_scripts/dorm_balcony.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../avg_scripts.hpp"
#include "./utils.hpp"
#include "activities/render_utils.hpp"
#include "static_sprites.hpp"
#include "static_maps.hpp"

Expand All @@ -19,6 +20,10 @@ void acts::avg_scripts::dorm_balcony(avg_scene& self, const std::optional<eng::b
self.bound_map.emplace(&maps::dorm_balcony(), 4.0);
self.bound_sprites[person.ptr()] = {&sprites::container_small(), 4.0, {0, -36}};

self.cust_render = [&, room_number]() {
render_number(self.parent, room_number, {24, 48, 24, 72});
};

// 地图边界固定阻挡物
simulator::entity_node_t obstacles[] = {
{basics::aabb{0, 128, 0, 352}},
Expand Down
5 changes: 5 additions & 0 deletions src/main/activities/avg_scripts/dorm_corridor_left.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../avg_scripts.hpp"
#include "./utils.hpp"
#include "activities/render_utils.hpp"
#include "static_sprites.hpp"
#include "static_maps.hpp"

Expand All @@ -19,6 +20,10 @@ void acts::avg_scripts::dorm_corridor_left(avg_scene& self, const std::optional<
self.bound_map.emplace(&maps::dorm_corridor_left(), 4.0);
self.bound_sprites[person.ptr()] = {&sprites::container_small(), 4.0, {0, -36}};

self.cust_render = [&, floor_number]() {
render_number(self.parent, floor_number, {24, 48, 24, 72});
};

// 地图边界固定阻挡物
simulator::entity_node_t obstacles[] = {
{basics::aabb{128, 384, 0, 128}},
Expand Down
5 changes: 5 additions & 0 deletions src/main/activities/avg_scripts/dorm_corridor_middle.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../avg_scripts.hpp"
#include "./utils.hpp"
#include "activities/render_utils.hpp"
#include "static_sprites.hpp"
#include "static_maps.hpp"

Expand All @@ -19,6 +20,10 @@ void acts::avg_scripts::dorm_corridor_middle(avg_scene& self, const std::optiona
self.bound_map.emplace(&maps::dorm_corridor_middle(), 4.0);
self.bound_sprites[person.ptr()] = {&sprites::container_small(), 4.0, {0, -36}};

self.cust_render = [&, floor_number]() {
render_number(self.parent, floor_number, {24, 48, 24, 72});
};

// 地图边界固定阻挡物
simulator::entity_node_t obstacles[] = {
{basics::aabb{0, 1024, 0, 240}},
Expand Down
5 changes: 5 additions & 0 deletions src/main/activities/avg_scripts/dorm_corridor_right.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../avg_scripts.hpp"
#include "./utils.hpp"
#include "activities/render_utils.hpp"
#include "static_sprites.hpp"
#include "static_maps.hpp"

Expand All @@ -19,6 +20,10 @@ void acts::avg_scripts::dorm_corridor_right(avg_scene& self, const std::optional
self.bound_map.emplace(&maps::dorm_corridor_right(), 4.0);
self.bound_sprites[person.ptr()] = {&sprites::container_small(), 4.0, {0, -36}};

self.cust_render = [&, floor_number]() {
render_number(self.parent, floor_number, {24, 48, 24, 72});
};

// 地图边界固定阻挡物
simulator::entity_node_t obstacles[] = {
{basics::aabb{128, 384, 0, 128}},
Expand Down
13 changes: 13 additions & 0 deletions src/main/activities/avg_scripts/dorm_room.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "../avg_scripts.hpp"
#include "./utils.hpp"
#include "activities/render_utils.hpp"
#include "activities/plane_battle_scene.hpp"
#include "static_sprites.hpp"
#include "static_maps.hpp"

Expand Down Expand Up @@ -46,6 +48,10 @@ void acts::avg_scripts::dorm_room(avg_scene& self, const std::optional<eng::basi
self.bound_map.emplace(&maps::dorm_room(), 4.0);
self.bound_sprites[person.ptr()] = {&sprites::container_small(), 4.0, {0, -36}};

self.cust_render = [&, room_number]() {
render_number(self.parent, room_number, {24, 48, 24, 72});
};

// 地图边界固定阻挡物
simulator::entity_node_t obstacles[] = {
{basics::aabb{0, 128, 0, 1056}},
Expand Down Expand Up @@ -75,6 +81,13 @@ void acts::avg_scripts::dorm_room(avg_scene& self, const std::optional<eng::basi
colls[{person.ptr(), table_2.ptr()}] = [&](){ self.next<acts::avg_scene>("black_jack_entry", points.black_jack_entry_left); };
colls[{person.ptr(), table_3.ptr()}] = [&](){ self.next<acts::avg_scene>("dorm_room", std::nullopt, "508"); };
}
if (room_number == 238) {
colls[{person.ptr(), table_2.ptr()}] = [&](){
person.data.velocity = {0, 0};
self.simu->teleport_entity_center(person.ptr(), points.dorm_room_default);
self.call<acts::plane_battle_scene>();
};
}

while (true) {
auto [_, evt_data] = co_await self.cohost.wait_event({simu_coro_host::EVT_COLLISION});
Expand Down
5 changes: 5 additions & 0 deletions src/main/activities/avg_scripts/dorm_stairs.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../avg_scripts.hpp"
#include "./utils.hpp"
#include "activities/render_utils.hpp"
#include "static_sprites.hpp"
#include "static_maps.hpp"

Expand All @@ -19,6 +20,10 @@ void acts::avg_scripts::dorm_stairs(avg_scene& self, const std::optional<eng::ba
self.bound_map.emplace(&maps::dorm_stairs(), 4.0);
self.bound_sprites[person.ptr()] = {&sprites::container_small(), 4.0, {0, -36}};

self.cust_render = [&, floor_number]() {
render_number(self.parent, floor_number, {24, 48, 24, 72});
};

// 地图边界固定阻挡物
simulator::entity_node_t obstacles[] = {
{basics::aabb{0, 128, 0, 384}},
Expand Down
24 changes: 7 additions & 17 deletions src/main/activities/black_jack.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <algorithm>
#include <random>
#include "./black_jack.hpp"
#include "activities/render_utils.hpp"

using namespace acts;
using namespace silly_framework;
Expand Down Expand Up @@ -148,28 +149,17 @@ black_jack_scene::black_jack_scene(game_window &window) : base_activity(window)

black_jack_scene::~black_jack_scene() {}

void black_jack_scene::render_img(const std::string& path, const glut::position& pos) {
auto&& [vs_w, vs_h] = parent.renman.vs_size();
auto img = parent.texman.get_texture(path);
if (img != nullptr) { parent.renman.blit(img->tex, glut::xy_trans(pos, vs_w, vs_h, glut::eye4), glut::full_uv); }
}

void black_jack_scene::render_bg(const std::string& path) {
auto img = parent.texman.get_texture(path);
if (img != nullptr) { parent.renman.blit(img->tex, glut::full_xy, glut::full_uv); }
}

void black_jack_scene::render() {
render_bg("black_jack_table.png");
render_bg(parent, "black_jack_table.png");
if (state) {
auto render_poker = [&](size_t card_id, const glut::position& pos) {
render_img(std::format("pokers/{}.png", card_id), pos);
render_img(parent, std::format("pokers/{}.png", card_id), pos);
};
auto render_number = [&](ssize_t n, const glut::position& pos) {
auto ns = std::to_string(n);
auto rpos = pos;
for (auto&& nc : ns) {
render_img(std::format("power_numbers/{}.png", nc), rpos);
render_img(parent, std::format("power_numbers/{}.png", nc), rpos);
rpos += glut::coord(pos.width(), 0);
}
};
Expand All @@ -186,7 +176,7 @@ void black_jack_scene::render() {
render_poker(state->player_cards[i], poker_pos);
}
bool btn_selected = select_cursor == state->player_cards.size();
render_img(btn_selected ? "go_button_focus.png" : "go_button_idle.png", {886, 992, 598, 662});
render_img(parent, btn_selected ? "go_button_focus.png" : "go_button_idle.png", {886, 992, 598, 662});

render_number(state->opponent_success, {640, 688, 64, 160});
render_number(state->player_success, {900, 948, 480, 576});
Expand All @@ -205,8 +195,8 @@ void black_jack_scene::render() {
if (state->finished()) {
using enum black_jack_state::result_code;
auto result = state->status();
if (result == LOSE || result == TIE) { render_img("trophy.png", {288, 416, 32, 160}); }
if (result == WIN || result == TIE) { render_img("trophy.png", {32, 160, 512, 640}); }
if (result == LOSE || result == TIE) { render_img(parent, "trophy.png", {288, 416, 32, 160}); }
if (result == WIN || result == TIE) { render_img(parent, "trophy.png", {32, 160, 512, 640}); }
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/activities/black_jack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ class black_jack_scene : public sf::base_activity {

black_jack_scene(sf::game_window& window);
~black_jack_scene();

void render_bg(const std::string& path);
void render_img(const std::string& path, const sf::glut::position& pos);

void render() override;
void on_key_change() override;
Expand Down
16 changes: 1 addition & 15 deletions src/main/activities/plane_battle_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <random>
#include <format>
#include "./plane_battle_scene.hpp"
#include "activities/render_utils.hpp"
#include "static_sprites.hpp"
#include "static_maps.hpp"

Expand Down Expand Up @@ -213,21 +214,6 @@ void plane_battle_scene::on_tick(double this_time, double last_time) {
}
}

static inline void render_img(game_window& wnd, const std::string& path, const glut::position& pos) {
auto&& [vs_w, vs_h] = wnd.renman.vs_size();
auto img = wnd.texman.get_texture(path);
if (img != nullptr) { wnd.renman.blit(img->tex, glut::xy_trans(pos, vs_w, vs_h, glut::eye4), glut::full_uv); }
}

static inline void render_number(game_window& wnd, ssize_t n, const glut::position& pos) {
auto ns = std::to_string(n);
auto rpos = pos;
for (auto&& nc : ns) {
render_img(wnd, std::format("power_numbers/{}.png", nc), rpos);
rpos += glut::coord(pos.width(), 0);
}
};

void plane_battle_scene::render() {
gl::ClearColor(0, 0, 0, 0);

Expand Down
33 changes: 33 additions & 0 deletions src/main/activities/render_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once
#ifndef __ACTS_RENDER_UTILS__
#define __ACTS_RENDER_UTILS__

#include <silly_framework.hpp>

namespace acts {

namespace sf = silly_framework;

static inline void render_bg(sf::game_window& wnd, const std::string& path) {
auto img = wnd.texman.get_texture(path);
if (img != nullptr) { wnd.renman.blit(img->tex, sf::glut::full_xy, sf::glut::full_uv); }
}

static inline void render_img(sf::game_window& wnd, const std::string& path, const sf::glut::position& pos) {
auto&& [vs_w, vs_h] = wnd.renman.vs_size();
auto img = wnd.texman.get_texture(path);
if (img != nullptr) { wnd.renman.blit(img->tex, sf::glut::xy_trans(pos, vs_w, vs_h, sf::glut::eye4), sf::glut::full_uv); }
}

static inline void render_number(sf::game_window& wnd, ssize_t n, const sf::glut::position& pos) {
auto ns = std::to_string(n);
auto rpos = pos;
for (auto&& nc : ns) {
render_img(wnd, std::format("power_numbers/{}.png", nc), rpos);
rpos += sf::glut::coord(pos.width(), 0);
}
};

} // namespace acts

#endif // __ACTS_RENDER_UTILS__
4 changes: 1 addition & 3 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "silly_framework/rewheel/os_misc.hpp"
#include "silly_framework/settings/logger.hpp"
#include "activities/avg_scene.hpp"
#include "activities/plane_battle_scene.hpp"

namespace sf = silly_framework;

Expand All @@ -24,8 +23,7 @@ int main(int argc, char** argv) {
sf::logger::make(project_name, logfile_path.string());
// 启动主窗口
sf::game_window(project_name.c_str(), 60, std::chrono::milliseconds(10))
//.run<acts::avg_scene>("dorm_room", std::nullopt, "311");
.run<acts::plane_battle_scene>();
.run<acts::avg_scene>("dorm_room", std::nullopt, "508");
// 再见...
return 0;
}

0 comments on commit 0088d77

Please sign in to comment.