mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-16 12:25:02 +01:00
Initial commit
Basic skeleton
This commit is contained in:
commit
d5c9e24201
6 changed files with 514 additions and 0 deletions
45
src/app.rs
Normal file
45
src/app.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use sfml::{
|
||||
graphics::{Color, RenderTarget, RenderWindow},
|
||||
window::Event,
|
||||
};
|
||||
|
||||
use crate::graphics;
|
||||
|
||||
/// Application level state (includes game and ui state, etc.)
|
||||
pub struct App {
|
||||
rw: RenderWindow,
|
||||
should_quit: bool,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
rw: graphics::make_window(),
|
||||
should_quit: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn do_game_loop(&mut self) {
|
||||
while !self.should_quit {
|
||||
self.do_event_handling();
|
||||
self.do_update();
|
||||
self.do_rendering();
|
||||
}
|
||||
}
|
||||
|
||||
fn do_event_handling(&mut self) {
|
||||
while let Some(ev) = self.rw.poll_event() {
|
||||
match ev {
|
||||
Event::Closed => self.should_quit = true,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn do_update(&mut self) {}
|
||||
|
||||
fn do_rendering(&mut self) {
|
||||
self.rw.clear(Color::BLACK);
|
||||
self.rw.display();
|
||||
}
|
||||
}
|
||||
32
src/graphics.rs
Normal file
32
src/graphics.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use sfml::{
|
||||
graphics::RenderWindow,
|
||||
window::{ContextSettings, Style, VideoMode},
|
||||
};
|
||||
|
||||
struct ScreenRes {
|
||||
w: u16,
|
||||
h: u16,
|
||||
}
|
||||
|
||||
impl ScreenRes {
|
||||
fn to_sf(&self) -> VideoMode {
|
||||
VideoMode {
|
||||
width: self.w.into(),
|
||||
height: self.h.into(),
|
||||
bits_per_pixel: 32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const NATIVE_RESOLUTION: ScreenRes = ScreenRes { w: 640, h: 360 };
|
||||
|
||||
pub fn make_window() -> RenderWindow {
|
||||
let mut rw = RenderWindow::new(
|
||||
NATIVE_RESOLUTION.to_sf(),
|
||||
"Mantle Diver",
|
||||
Style::CLOSE,
|
||||
&ContextSettings::default(),
|
||||
);
|
||||
rw.set_framerate_limit(60);
|
||||
rw
|
||||
}
|
||||
9
src/main.rs
Normal file
9
src/main.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
mod app;
|
||||
mod graphics;
|
||||
|
||||
use app::App;
|
||||
|
||||
fn main() {
|
||||
let mut app = App::new();
|
||||
app.do_game_loop();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue