add field and themeing
This commit is contained in:
parent
c2cb73fbc7
commit
b8d27eb909
2 changed files with 49 additions and 8 deletions
|
@ -1,4 +1,7 @@
|
|||
const GAME_SIZE: (u32, u32) = (1200, 800);
|
||||
const BORDER_WIDTH: u32 = 10;
|
||||
const FG: u32 = 0xebdbb2;
|
||||
const BG: u32 = 0x282828;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
num::NonZeroU32,
|
||||
|
@ -81,6 +84,44 @@ impl Engine {
|
|||
Event::NewEvents(StartCause::ResumeTimeReached { .. }) => {
|
||||
window.request_redraw();
|
||||
}
|
||||
Event::WindowEvent {
|
||||
window_id,
|
||||
event: WindowEvent::Resized(PhysicalSize { width, height }),
|
||||
} => {
|
||||
if window_id == window.id() {
|
||||
if let (Some(width), Some(height)) =
|
||||
(NonZeroU32::new(width), NonZeroU32::new(height))
|
||||
{
|
||||
surface.resize(width, height).unwrap();
|
||||
let mut buffer = surface.buffer_mut().unwrap();
|
||||
buffer.fill(BG);
|
||||
|
||||
let mut ctx =
|
||||
render::RenderCtx::new(buffer, (width, height), GAME_SIZE);
|
||||
|
||||
// top
|
||||
ctx.rect(0, 0, GAME_SIZE.0, BORDER_WIDTH, FG);
|
||||
// left
|
||||
ctx.rect(
|
||||
0,
|
||||
BORDER_WIDTH,
|
||||
BORDER_WIDTH,
|
||||
GAME_SIZE.1 - BORDER_WIDTH * 2,
|
||||
FG,
|
||||
);
|
||||
// right
|
||||
ctx.rect(
|
||||
GAME_SIZE.0 - BORDER_WIDTH,
|
||||
BORDER_WIDTH,
|
||||
BORDER_WIDTH,
|
||||
GAME_SIZE.1 - BORDER_WIDTH * 2,
|
||||
FG,
|
||||
);
|
||||
// bottom
|
||||
ctx.rect(0, GAME_SIZE.1 - BORDER_WIDTH, GAME_SIZE.0, 10, FG);
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::WindowEvent {
|
||||
window_id,
|
||||
event: WindowEvent::RedrawRequested,
|
||||
|
@ -182,7 +223,7 @@ mod render;
|
|||
pub mod objs {
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::render::RenderCtx;
|
||||
use super::{render::RenderCtx, BG, FG};
|
||||
|
||||
pub struct World {
|
||||
objects: Vec<Rc<dyn MovingObject>>,
|
||||
|
@ -318,7 +359,7 @@ pub mod objs {
|
|||
fn display(&self, ctx: &mut RenderCtx<'_, '_>) {
|
||||
let Position { x, y } = self.position();
|
||||
let Size { width, height } = self.size();
|
||||
ctx.rect(x, y, width, height, 0xffffff);
|
||||
ctx.rect(x, y, width, height, FG);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,7 +383,7 @@ pub mod objs {
|
|||
} = self.previous_pos();
|
||||
let Size { width, height } = self.size();
|
||||
|
||||
ctx.rect(prev_x, prev_y, width, height, 0x000000);
|
||||
ctx.rect(prev_x, prev_y, width, height, BG);
|
||||
self.display(ctx);
|
||||
}
|
||||
}
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -7,13 +7,13 @@ use engine::{
|
|||
|
||||
fn main() {
|
||||
let mut engine = Engine::new();
|
||||
let _ = engine.insert_into_world(Rc::new(MovingRect::new(0, 0, 50, 100)));
|
||||
// let _ = engine.insert_into_world(Rc::new(MovingRect::new(0, 0, 50, 100)));
|
||||
engine
|
||||
.set_render_fn(|ctx, world, timer| {
|
||||
println!("t: {}", timer.game_time_passed());
|
||||
let obj = Rc::get_mut(world.get_mut(0)).unwrap();
|
||||
obj.move_obj(1, 0);
|
||||
obj.draw_move(ctx)
|
||||
// println!("t: {}", timer.game_time_passed());
|
||||
// let obj = Rc::get_mut(world.get_mut(0)).unwrap();
|
||||
// obj.move_obj(1, 0);
|
||||
// obj.draw_move(ctx)
|
||||
// Rect::square((timer.game_time_passed() * 20.) as u32, 0, 200).display(ctx);
|
||||
})
|
||||
.run();
|
||||
|
|
Loading…
Reference in a new issue