initial commit
This commit is contained in:
commit
5817fea9ad
10 changed files with 465 additions and 0 deletions
43
src/main.rs
Normal file
43
src/main.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
use crate::command_queue::PacketQueue;
|
||||
use bar::Bar;
|
||||
use game_state::GameState;
|
||||
use servicepoint::{ClearCommand, Origin, UdpSocketExt};
|
||||
use std::net::UdpSocket;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
mod bar;
|
||||
mod command_queue;
|
||||
mod game_state;
|
||||
mod label;
|
||||
|
||||
type Currency = f64;
|
||||
|
||||
trait Progressable: Sized {
|
||||
#[must_use]
|
||||
fn progress(&self, delta: Duration) -> (Self, Currency);
|
||||
}
|
||||
|
||||
trait GenerateCommands {
|
||||
fn generate_commands(&self, queue: &mut impl PacketQueue);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut state = GameState {
|
||||
currency: 0f64,
|
||||
first_step: Bar::new(1f64, Origin::new(0, 1)),
|
||||
};
|
||||
|
||||
let mut connection = UdpSocket::bind_connect("127.0.0.1:2342").unwrap();
|
||||
|
||||
let mut last_refresh = Instant::now();
|
||||
loop {
|
||||
let current_time = Instant::now();
|
||||
let delta = current_time - last_refresh;
|
||||
last_refresh = current_time;
|
||||
|
||||
(state, _) = state.progress(delta);
|
||||
|
||||
connection.send_command(ClearCommand);
|
||||
state.generate_commands(&mut connection);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue