handle cross socket message passing
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
use macroquad::{
|
||||
color::{BLACK, WHITE},
|
||||
text::draw_text,
|
||||
window::{clear_background, screen_height, screen_width},
|
||||
};
|
||||
use macroquad::prelude::*;
|
||||
|
||||
use crate::screen::Screen;
|
||||
use crate::{model::ClientMessage, screen::Screen};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct HostScreen {}
|
||||
|
||||
impl Screen for HostScreen {
|
||||
fn handle_frame(&mut self, _ctx: &mut crate::context::Context) {
|
||||
fn handle_frame(&mut self, ctx: &mut crate::context::Context) {
|
||||
clear_background(WHITE);
|
||||
|
||||
draw_text(
|
||||
@@ -20,6 +16,25 @@ impl Screen for HostScreen {
|
||||
100.0,
|
||||
BLACK,
|
||||
);
|
||||
|
||||
let button_size = screen_width() * 0.01;
|
||||
let button_location = Vec2::new(screen_width() * 0.50, screen_height() * 0.70);
|
||||
|
||||
draw_circle(
|
||||
button_location.x,
|
||||
button_location.y,
|
||||
button_size * 1.1,
|
||||
DARKBROWN,
|
||||
);
|
||||
draw_circle(button_location.x, button_location.y, button_size, RED);
|
||||
if is_mouse_button_pressed(MouseButton::Left) {
|
||||
let loc = Vec2::from(mouse_position());
|
||||
let normalize = loc - button_location;
|
||||
|
||||
if normalize.length() < button_size {
|
||||
ctx.send_msg(&ClientMessage::ResetBuzzers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_messages(
|
||||
|
||||
@@ -11,6 +11,7 @@ pub enum ClientMessage {
|
||||
BuzzIn(BuzzIn),
|
||||
Register(Register),
|
||||
CreateRoom(Register),
|
||||
ResetBuzzers,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
|
||||
Reference in New Issue
Block a user