check for win
This commit is contained in:
parent
eb3c12fc58
commit
5d89880e3c
4 changed files with 23 additions and 9 deletions
|
@ -14,7 +14,6 @@
|
|||
{
|
||||
"movable": true,
|
||||
"orientation": 1,
|
||||
"position": [1, 3],
|
||||
"color": [255, 10, 100],
|
||||
"segments": [
|
||||
[1, 3, 0, 0],
|
||||
|
@ -24,7 +23,6 @@
|
|||
{
|
||||
"movable": true,
|
||||
"orientation": 2,
|
||||
"position": [2, 4],
|
||||
"color": [105, 210, 50],
|
||||
"segments": [
|
||||
[2, 4, 2, 0],
|
||||
|
@ -34,7 +32,6 @@
|
|||
{
|
||||
"movable": true,
|
||||
"orientation": 2,
|
||||
"position": [0, 4],
|
||||
"color": [35, 150, 100],
|
||||
"segments": [
|
||||
[0, 4, 1, 1],
|
||||
|
@ -44,7 +41,6 @@
|
|||
{
|
||||
"movable": true,
|
||||
"orientation": 1,
|
||||
"position": [0, 3],
|
||||
"color": [25, 120, 10],
|
||||
"segments": [
|
||||
[0, 3, 3, 1],
|
||||
|
@ -54,7 +50,6 @@
|
|||
{
|
||||
"movable": false,
|
||||
"orientation": 0,
|
||||
"position": [0, 2],
|
||||
"color": [15, 15, 15],
|
||||
"segments": [
|
||||
[0, 2, 0, 0],
|
||||
|
@ -63,7 +58,6 @@
|
|||
{
|
||||
"movable": false,
|
||||
"orientation": 0,
|
||||
"position": [2, 2],
|
||||
"color": [15, 15, 15],
|
||||
"segments": [
|
||||
[2, 2, 0, 1],
|
||||
|
|
|
@ -8,7 +8,6 @@ pub struct PlayerData {
|
|||
pub struct BlockData {
|
||||
pub movable: bool,
|
||||
pub orientation: u32,
|
||||
pub position: (i32, i32),
|
||||
pub color: (u32, u32, u32),
|
||||
pub segments: Vec<[i32; 4]>,
|
||||
}
|
||||
|
@ -18,7 +17,7 @@ pub struct LevelData {
|
|||
pub dimensions: [u32; 2],
|
||||
pub player1: PlayerData,
|
||||
pub player2: PlayerData,
|
||||
pub goal1: [u32; 2],
|
||||
pub goal2: [u32; 2],
|
||||
pub goal1: (u32, u32),
|
||||
pub goal2: (u32, u32),
|
||||
pub blocks: Vec<BlockData>,
|
||||
}
|
||||
|
|
|
@ -119,6 +119,7 @@ impl<'a> Game<'a> {
|
|||
if let Some(change_set) = change_set {
|
||||
let level = self.get_current_level_mut();
|
||||
level.apply_change_set(change_set.clone());
|
||||
self.check_win_condition();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -134,6 +135,14 @@ impl<'a> Game<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_win_condition(&mut self) {
|
||||
let level = self.get_current_level();
|
||||
if level.check_win_condition() {
|
||||
// go on to the next level
|
||||
self.current_level += 1;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&self, renderer: &mut Renderer) {
|
||||
let level = self.get_current_level();
|
||||
level.render(renderer, &self.animations);
|
||||
|
|
|
@ -20,6 +20,8 @@ pub struct Level {
|
|||
blocks: Vec<Block>,
|
||||
player1: Player,
|
||||
player2: Player,
|
||||
goal1: (u32, u32),
|
||||
goal2: (u32, u32),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
|
||||
|
@ -66,9 +68,19 @@ impl Level {
|
|||
blocks,
|
||||
player1,
|
||||
player2,
|
||||
goal1: data.goal1,
|
||||
goal2: data.goal2,
|
||||
}
|
||||
}
|
||||
|
||||
// check if we won
|
||||
pub fn check_win_condition(&self) -> bool {
|
||||
self.player1.position.0 as u32 == self.goal1.0
|
||||
&& self.player1.position.1 as u32 == self.goal1.1
|
||||
&& self.player2.position.0 as u32 == self.goal2.0
|
||||
&& self.player2.position.1 as u32 == self.goal2.1
|
||||
}
|
||||
|
||||
pub fn apply_change_set(&mut self, change_set: ChangeSet) {
|
||||
for (entity, direction) in change_set {
|
||||
let direction = direction.as_pair();
|
||||
|
|
Loading…
Reference in a new issue