diff --git a/src/main/activities/avg_scene.cpp b/src/main/activities/avg_scene.cpp index 17914d2..0e47d9d 100644 --- a/src/main/activities/avg_scene.cpp +++ b/src/main/activities/avg_scene.cpp @@ -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(); } } diff --git a/src/main/activities/avg_scene.hpp b/src/main/activities/avg_scene.hpp index dfa8070..64f9bca 100644 --- a/src/main/activities/avg_scene.hpp +++ b/src/main/activities/avg_scene.hpp @@ -60,6 +60,7 @@ class avg_scene : public sf::base_activity { entity_comp_t sprites_sorter = default_sprites_sorter(); std::optional bound_map; eng::basics::vec2 velocity_direction = {0, 0}; + std::function cust_render; std::any script_data; diff --git a/src/main/activities/avg_scripts/dorm_balcony.cpp b/src/main/activities/avg_scripts/dorm_balcony.cpp index 673b7bd..207c5d0 100644 --- a/src/main/activities/avg_scripts/dorm_balcony.cpp +++ b/src/main/activities/avg_scripts/dorm_balcony.cpp @@ -1,5 +1,6 @@ #include "../avg_scripts.hpp" #include "./utils.hpp" +#include "activities/render_utils.hpp" #include "static_sprites.hpp" #include "static_maps.hpp" @@ -19,6 +20,10 @@ void acts::avg_scripts::dorm_balcony(avg_scene& self, const std::optional("black_jack_entry", points.black_jack_entry_left); }; colls[{person.ptr(), table_3.ptr()}] = [&](){ self.next("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(); + }; + } while (true) { auto [_, evt_data] = co_await self.cohost.wait_event({simu_coro_host::EVT_COLLISION}); diff --git a/src/main/activities/avg_scripts/dorm_stairs.cpp b/src/main/activities/avg_scripts/dorm_stairs.cpp index 2fcc538..5f6c305 100644 --- a/src/main/activities/avg_scripts/dorm_stairs.cpp +++ b/src/main/activities/avg_scripts/dorm_stairs.cpp @@ -1,5 +1,6 @@ #include "../avg_scripts.hpp" #include "./utils.hpp" +#include "activities/render_utils.hpp" #include "static_sprites.hpp" #include "static_maps.hpp" @@ -19,6 +20,10 @@ void acts::avg_scripts::dorm_stairs(avg_scene& self, const std::optional #include #include "./black_jack.hpp" +#include "activities/render_utils.hpp" using namespace acts; using namespace silly_framework; @@ -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); } }; @@ -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}); @@ -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}); } } } } diff --git a/src/main/activities/black_jack.hpp b/src/main/activities/black_jack.hpp index 8ec6381..2cf0c46 100644 --- a/src/main/activities/black_jack.hpp +++ b/src/main/activities/black_jack.hpp @@ -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; diff --git a/src/main/activities/plane_battle_scene.cpp b/src/main/activities/plane_battle_scene.cpp index fd3c745..d2a2be7 100644 --- a/src/main/activities/plane_battle_scene.cpp +++ b/src/main/activities/plane_battle_scene.cpp @@ -2,6 +2,7 @@ #include #include #include "./plane_battle_scene.hpp" +#include "activities/render_utils.hpp" #include "static_sprites.hpp" #include "static_maps.hpp" @@ -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); diff --git a/src/main/activities/render_utils.hpp b/src/main/activities/render_utils.hpp new file mode 100644 index 0000000..cbc1940 --- /dev/null +++ b/src/main/activities/render_utils.hpp @@ -0,0 +1,33 @@ +#pragma once +#ifndef __ACTS_RENDER_UTILS__ +#define __ACTS_RENDER_UTILS__ + +#include + +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__ diff --git a/src/main/main.cpp b/src/main/main.cpp index c623f99..6a2ec60 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -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; @@ -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("dorm_room", std::nullopt, "311"); - .run(); + .run("dorm_room", std::nullopt, "508"); // 再见... return 0; }