map generique
This commit is contained in:
parent
6cee20df8d
commit
54aab50c3b
50
src/map.rs
50
src/map.rs
|
@ -1,6 +1,6 @@
|
|||
//! Contiens tous ce qui est relatif à la carte du jeu.
|
||||
|
||||
use crate::{PlayerId, Position};
|
||||
use crate::Position;
|
||||
use bevy::prelude::{Commands, Component};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Component)]
|
||||
|
@ -76,53 +76,21 @@ pub enum Tile {
|
|||
|
||||
/// Permet de crée des entité representant les cases d'une map, sur une longueur et langueur donné.
|
||||
/// Donner une longueur impaire.
|
||||
pub fn init_map(
|
||||
longueur: u8,
|
||||
largeur: u8,
|
||||
mut commands: Commands,
|
||||
id_joueur1: PlayerId,
|
||||
id_joueur2: PlayerId,
|
||||
) {
|
||||
pub fn init_map(longueur: u8, largeur: u8, mut commands: Commands) {
|
||||
for y in 0..longueur {
|
||||
for x in 0..largeur {
|
||||
if y % 2 != 0 && x == longueur {
|
||||
} else {
|
||||
let mut curent_type = Tile::Grass;
|
||||
let mut curent_id = None;
|
||||
if x == 1 && y == 4 {
|
||||
curent_type = Tile::Castle;
|
||||
curent_id = Some(id_joueur1);
|
||||
} else if x == longueur && y == 4 {
|
||||
curent_type = Tile::Castle;
|
||||
curent_id = Some(id_joueur2);
|
||||
} else {
|
||||
match (x, y) {
|
||||
(0, 5) | (1, 5) | (2, 4) | (1, 3) | (0, 3) => {
|
||||
curent_type = Tile::Grass;
|
||||
curent_id = Some(id_joueur1)
|
||||
}
|
||||
|
||||
(9, 5) | (8, 5) | (8, 4) | (9, 3) | (8, 3) => {
|
||||
curent_type = Tile::Grass;
|
||||
curent_id = Some(id_joueur2)
|
||||
}
|
||||
|
||||
_ => {
|
||||
if rand::random() {
|
||||
if rand::random() {
|
||||
curent_type = Tile::Forest
|
||||
} else {
|
||||
curent_type = Tile::Hill
|
||||
}
|
||||
}
|
||||
}
|
||||
if rand::random() {
|
||||
if rand::random() {
|
||||
curent_type = Tile::Forest
|
||||
} else {
|
||||
curent_type = Tile::Hill
|
||||
}
|
||||
}
|
||||
if let Some(id) = curent_id {
|
||||
commands.spawn((curent_type, id, Position { x, y }));
|
||||
} else {
|
||||
commands.spawn((curent_type, Position { x, y }));
|
||||
}
|
||||
|
||||
commands.spawn((curent_type, Position { x, y }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue