move pos to module
This commit is contained in:
parent
e22f568d2f
commit
bc4cd5ccc9
5 changed files with 67 additions and 62 deletions
|
@ -11,7 +11,8 @@ use crate::{
|
|||
draw_scaled_texture, draw_usize,
|
||||
level::Level,
|
||||
marble_engine::{
|
||||
board::{Board, Pos},
|
||||
board::Board,
|
||||
pos::Pos,
|
||||
tile::{Direction, GateType, MathOp, MirrorType, PTile, Tile, WireType},
|
||||
Machine,
|
||||
},
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use raylib::prelude::*;
|
||||
|
||||
pub mod board;
|
||||
pub mod pos;
|
||||
pub mod tile;
|
||||
use board::{Board, Pos};
|
||||
use board::Board;
|
||||
use pos::*;
|
||||
use tile::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -1,67 +1,9 @@
|
|||
use std::ops::Add;
|
||||
|
||||
use crate::{draw_scaled_texture, Textures};
|
||||
|
||||
use super::tile::*;
|
||||
use super::Pos;
|
||||
use raylib::prelude::*;
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq)]
|
||||
pub struct Pos {
|
||||
pub x: isize,
|
||||
pub y: isize,
|
||||
}
|
||||
|
||||
impl Pos {
|
||||
pub const fn to_vec(self) -> Vector2 {
|
||||
Vector2 {
|
||||
x: self.x as f32,
|
||||
y: self.y as f32,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn min(self, other: Self) -> Self {
|
||||
Self {
|
||||
x: self.x.min(other.x),
|
||||
y: self.y.min(other.y),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max(self, other: Self) -> Self {
|
||||
Self {
|
||||
x: self.x.max(other.x),
|
||||
y: self.y.max(other.y),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(usize, usize)> for Pos {
|
||||
fn from(value: (usize, usize)) -> Self {
|
||||
Self {
|
||||
x: value.0 as isize,
|
||||
y: value.1 as isize,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vector2> for Pos {
|
||||
fn from(vec: Vector2) -> Self {
|
||||
Self {
|
||||
x: vec.x as isize,
|
||||
y: vec.y as isize,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Pos {
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
x: self.x + rhs.x,
|
||||
y: self.y + rhs.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Board {
|
||||
rows: Vec<Vec<Tile>>,
|
||||
|
|
60
src/marble_engine/pos.rs
Normal file
60
src/marble_engine/pos.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
use std::ops::Add;
|
||||
|
||||
use raylib::prelude::*;
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq)]
|
||||
pub struct Pos {
|
||||
pub x: isize,
|
||||
pub y: isize,
|
||||
}
|
||||
|
||||
impl Pos {
|
||||
pub const fn to_vec(self) -> Vector2 {
|
||||
Vector2 {
|
||||
x: self.x as f32,
|
||||
y: self.y as f32,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn min(self, other: Self) -> Self {
|
||||
Self {
|
||||
x: self.x.min(other.x),
|
||||
y: self.y.min(other.y),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max(self, other: Self) -> Self {
|
||||
Self {
|
||||
x: self.x.max(other.x),
|
||||
y: self.y.max(other.y),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(usize, usize)> for Pos {
|
||||
fn from(value: (usize, usize)) -> Self {
|
||||
Self {
|
||||
x: value.0 as isize,
|
||||
y: value.1 as isize,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vector2> for Pos {
|
||||
fn from(vec: Vector2) -> Self {
|
||||
Self {
|
||||
x: vec.x as isize,
|
||||
y: vec.y as isize,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Pos {
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
x: self.x + rhs.x,
|
||||
y: self.y + rhs.y,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use super::board::Pos;
|
||||
use crate::marble_engine::Pos;
|
||||
|
||||
pub type MarbleValue = u32;
|
||||
|
||||
|
|
Loading…
Reference in a new issue