First prototype of the work computer.

main
Zed A. Shaw 5 days ago
parent 061889cfa9
commit ac24f2cc36
  1. 5
      assets/config.json
  2. BIN
      assets/work_computer-1024.png
  3. 83
      main.cpp

@ -16,6 +16,11 @@
"frame_width": 1024, "frame_width": 1024,
"frame_height": 1024 "frame_height": 1024
}, },
"work_computer":
{"path": "assets/work_computer-1024.png",
"frame_width": 1024,
"frame_height": 1024
},
"clicker_treat_bone": "clicker_treat_bone":
{"path": "assets/clicker_treat_bone.png", {"path": "assets/clicker_treat_bone.png",
"frame_width": 256, "frame_width": 256,

Binary file not shown.

After

Width:  |  Height:  |  Size: 409 KiB

@ -5,10 +5,11 @@
#include <deque> #include <deque>
#include <iostream> #include <iostream>
constexpr const int WINDOW_WIDTH=1280; constexpr const int SCREEN_WIDTH=1280;
constexpr const int WINDOW_HEIGHT=720; constexpr const int SCREEN_HEIGHT=720;
constexpr const int FRAME_LIMIT=60; constexpr const int FRAME_LIMIT=60;
constexpr const bool VSYNC=true; constexpr const bool VSYNC=true;
bool GO_TO_WORK = false;
using std::string, std::wstring; using std::string, std::wstring;
@ -71,13 +72,13 @@ struct ClickerUI {
guecs::Entity $clicker; guecs::Entity $clicker;
ClickerUI() { ClickerUI() {
$gui.position(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); $gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
$gui.layout( $gui.layout(
"[_|*%(300,400)clicker|_|_|_]" "[FoodBowl|_|*%(300,400)clicker|_|_|_]"
"[_|_ |_|_|_]" "[WaterBowl|_|_ |_|_|_]"
"[_|_ |_|_|_]" "[Mood|_|_ |_|_|_]"
"[_|_ |_|_|_]" "[_|_|_ |_|_|_]"
"[a1|a2|a3|a4|a5]"); "[Treat|Food|Water|Pet|Work]");
} }
void init() { void init() {
@ -88,11 +89,18 @@ struct ClickerUI {
if(name != "clicker") { if(name != "clicker") {
$gui.set<guecs::Rectangle>(id, {}); $gui.set<guecs::Rectangle>(id, {});
$gui.set<guecs::Effect>(id, {}); $gui.set<guecs::Effect>(id, {});
$gui.set<guecs::Sprite>(id, { "clicker_treat_bone" }); $gui.set<guecs::Label>(id, { guecs::to_wstring(name) });
fmt::println("button dim: {},{}", cell.w, cell.h);
$gui.set<guecs::Clickable>(id, { if(name == "Work") {
[&](auto, auto) { handle_button(Event::A_BUTTON); } $gui.set<guecs::Clickable>(id, { [&](auto, auto) {
}); GO_TO_WORK = true;
fmt::println("Going to Work!");
} });
} else {
$gui.set<guecs::Clickable>(id, {
[&](auto, auto) { handle_button(Event::A_BUTTON); }
});
}
} }
} }
@ -146,17 +154,51 @@ struct ClickerUI {
} }
}; };
struct WorkComputerUI {
guecs::UI $gui;
WorkComputerUI() {
$gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
$gui.layout("[_|*%(300)computer|_|_|_]");
}
void init() {
auto computer = $gui.entity("computer");
$gui.set<guecs::Sprite>(computer, {"work_computer"});
$gui.set<guecs::Label>(computer, {L"Work Computer"});
$gui.set<guecs::Clickable>(computer, { [&](auto, auto) {
GO_TO_WORK = false;
fmt::println("Leaving Work!");
} });
$gui.init();
}
void render(sf::RenderWindow& window) {
$gui.render(window);
}
void mouse(float x, float y, bool hover) {
$gui.mouse(x, y, hover);
}
};
int main() { int main() {
sfml::Backend backend; sfml::Backend backend;
guecs::init(&backend); guecs::init(&backend);
sf::RenderWindow window(sf::VideoMode({WINDOW_WIDTH, WINDOW_HEIGHT}), "Clicker the Dog"); sf::RenderWindow window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Clicker the Dog");
window.setFramerateLimit(FRAME_LIMIT); window.setFramerateLimit(FRAME_LIMIT);
window.setVerticalSyncEnabled(VSYNC); window.setVerticalSyncEnabled(VSYNC);
ClickerUI clicker; ClickerUI clicker;
clicker.init(); clicker.init();
WorkComputerUI computer;
computer.init();
while(window.isOpen()) { while(window.isOpen()) {
while (const auto event = window.pollEvent()) { while (const auto event = window.pollEvent()) {
if(event->is<sf::Event::Closed>()) { if(event->is<sf::Event::Closed>()) {
@ -166,12 +208,21 @@ int main() {
if(const auto* mouse = event->getIf<sf::Event::MouseButtonPressed>()) { if(const auto* mouse = event->getIf<sf::Event::MouseButtonPressed>()) {
if(mouse->button == sf::Mouse::Button::Left) { if(mouse->button == sf::Mouse::Button::Left) {
sf::Vector2f pos = window.mapPixelToCoords(mouse->position); sf::Vector2f pos = window.mapPixelToCoords(mouse->position);
clicker.mouse(pos.x, pos.y, false); if(GO_TO_WORK) {
computer.mouse(pos.x, pos.y, false);
} else {
clicker.mouse(pos.x, pos.y, false);
}
} }
} }
} }
clicker.render(window); if(GO_TO_WORK) {
window.clear();
computer.render(window);
} else {
clicker.render(window);
}
window.display(); window.display();
} }
} }

Loading…
Cancel
Save