a couple of attempts at players

This commit is contained in:
2022-03-12 18:35:09 +00:00
parent 2349d7365e
commit 75ca8c84ea
4 changed files with 117 additions and 14 deletions

View File

@@ -6,7 +6,7 @@ use std::path::PathBuf;
use log::error;
use pixels::{Error, SurfaceTexture, PixelsBuilder};
use pixels::wgpu::BackendBit;
use winit::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
use winit::dpi::{LogicalPosition, LogicalSize, PhysicalSize, Size};
use winit::event::{Event, VirtualKeyCode};
use winit::event_loop::{ControlFlow, EventLoop};
use winit_input_helper::WinitInputHelper;
@@ -183,7 +183,11 @@ fn main() -> Result<(), Error> {
}
}
if input.key_pressed(VirtualKeyCode::Left) {
if
input.key_pressed(VirtualKeyCode::Left)
||
input.key_pressed(VirtualKeyCode::W)
{
let (x, y) = state.player_position;
if x > 0 {
state.player_position = (x - 1, y);
@@ -191,7 +195,11 @@ fn main() -> Result<(), Error> {
}
}
if input.key_pressed(VirtualKeyCode::Right) {
if
input.key_pressed(VirtualKeyCode::Right)
||
input.key_pressed(VirtualKeyCode::D)
{
let (x, y) = state.player_position;
if x < state.game.config.width as u8 - 1 {
state.player_position = (x + 1, y);
@@ -199,7 +207,11 @@ fn main() -> Result<(), Error> {
}
}
if input.key_pressed(VirtualKeyCode::Up) {
if
input.key_pressed(VirtualKeyCode::Up)
||
input.key_pressed(VirtualKeyCode::W)
{
let (x, y) = state.player_position;
if y > 0 {
state.player_position = (x, y - 1);
@@ -207,7 +219,11 @@ fn main() -> Result<(), Error> {
}
}
if input.key_pressed(VirtualKeyCode::Down) {
if
input.key_pressed(VirtualKeyCode::Down)
||
input.key_pressed(VirtualKeyCode::S)
{
let (x, y) = state.player_position;
if y < state.game.config.height as u8 - 1 {
state.player_position = (x, y + 1);
@@ -236,7 +252,7 @@ fn main() -> Result<(), Error> {
fn window_builder(title: &str, event_loop: &EventLoop<()>) -> winit::window::Window {
winit::window::WindowBuilder::new()
.with_visible(false)
.with_resizable(false)
// .with_resizable(false)
.with_title(title).build(&event_loop).unwrap()
}
@@ -247,7 +263,7 @@ fn window_builder(title: &str, event_loop: &EventLoop<()>) -> winit::window::Win
winit::window::WindowBuilder::new()
.with_drag_and_drop(false)
.with_visible(false)
.with_resizable(false)
// .with_resizable(false)
.with_title(title).build(&event_loop).unwrap()
}
@@ -282,21 +298,21 @@ fn create_window(
let scale = (monitor_height / height * 2.0 / 3.0).round().max(1.0);
// Resize, center, and display the window
let min_size: winit::dpi::LogicalSize<f64> =
PhysicalSize::new(width, height).to_logical(hidpi_factor);
// Resize, centre, and display the window
// let min_size: winit::dpi::LogicalSize<f64> =
// PhysicalSize::new(width, height).to_logical(hidpi_factor);
let default_size =
LogicalSize::new(width * scale, height * scale);
let center = LogicalPosition::new(
let centre = LogicalPosition::new(
(monitor_width - width * scale) / 2.0,
(monitor_height - height * scale) / 2.0,
);
window.set_inner_size(default_size);
// window.set_min_inner_size(Some(min_size));
window.set_outer_position(center);
window.set_outer_position(centre);
window.set_visible(true);
let size = default_size.to_physical::<f64>(hidpi_factor);