Skip to content
Snippets Groups Projects
Commit d76851eb authored by radow's avatar radow
Browse files

simple smarttile

parent 0418c657
No related branches found
No related tags found
No related merge requests found
resources/cross.png

2.11 KiB

resources/empty.png

1.96 KiB

resources/hor.png

1.99 KiB

resources/vert.png

1.99 KiB

......@@ -8,13 +8,14 @@ mod tile;
mod combat_log;
use tetra::{Context, State};
use tetra::graphics::{self, Color, DrawParams};
use tetra::graphics::{self, Color, DrawParams, Texture};
use tetra::input::{self, Key};
use run::Run;
use textures::Textures;
use crate::game_state::tile::Tile;
use tetra::math::Vec2;
use std::cmp::{min, max};
use std::usize;
use rand::{thread_rng, Rng};
use tetra::graphics::text::{VectorFontBuilder, Font, Text};
use crate::game_state::combat_log::PlayerAction;
......@@ -341,7 +342,7 @@ impl GameState {
let draw_y = y + 1;
match tile {
Tile::Empty => GameState::draw_tile(self, Color::WHITE, draw_x, draw_y, ctx),
Tile::Wall => GameState::draw_tile(self, Color::BLACK, draw_x, draw_y, ctx),
Tile::Wall => GameState::draw_wall(self, Color::WHITE, draw_x, draw_y, ctx),
Tile::Player => GameState::draw_player(self, draw_x, draw_y, ctx),
Tile::Enemy(_) => GameState::draw_enemy(self, draw_x, draw_y, ctx),
Tile::Exit => GameState::draw_tile(self, Color::RED, draw_x, draw_y, ctx),
......@@ -361,6 +362,66 @@ impl GameState {
})
}
fn draw_wall(&mut self, color: Color, x: usize, y: usize, ctx: &mut Context) {
let val = self.calc_walltype(x-1, y-1);
let mut tex :Texture = self.textures.cross.clone();
match val{
1|11110001|10000|11111|10000001|11|10000011|110000|111000|11000|10001|10011|11001|110001|10010001|11011|110011|10010011|111001|10011001|10110001|111011|10011011|10110011|10111001|10111011 => tex = self.textures.hor.clone(),
1000000|100|1000100|11000111|1111100|11000000|1100000|11100000|110|1100|1110|1000110|1001100|1100100|11000100|1001110|1100110|11000110|1101100|11001100|11100100|1101110|11001110|11100110|11101100|11101110 => tex = self.textures.vert.clone(),
11111111 => tex = self.textures.tile.clone(),
_ => {}
}
tex.draw(ctx, DrawParams {
position: Vec2::new(x as f32 * 33.0, y as f32 * 33.0),
scale: Vec2::new(1.0, 1.0),
origin: Vec2::new(0.0, 0.0),
rotation: 0.0,
color,
})
}
fn calc_walltype(&self, x:usize,y:usize)->u32{
if x == 0 || x>=config::BOARD_WIDTH-1||y==0||y>=config::BOARD_HEIGHT-1{
return 0;
}
let board = self.current_run.level.board;
let mut result:u32 = 0;
match board[x-1][y-1]{
Tile::Wall => result += 10000000,
_ => {},
}
match board[x][y-1]{
Tile::Wall => result += 1000000,
_ => {},
}
match board[x+1][y-1]{
Tile::Wall => result += 100000,
_ => {},
}
match board[x+1][y]{
Tile::Wall => result += 10000,
_ => {},
}
match board[x+1][y+1]{
Tile::Wall => result += 1000,
_ => {},
}
match board[x][y+1]{
Tile::Wall => result += 100,
_ => {},
}
match board[x-1][y+1]{
Tile::Wall => result += 10,
_ => {},
}
match board[x-1][y]{
Tile::Wall => result += 1,
_ => {},
}
result
}
fn draw_player(&mut self, x: usize, y: usize, ctx: &mut Context) {
GameState::draw_tile(self, Color::WHITE, x, y, ctx);
......
......@@ -3,6 +3,9 @@ use tetra::graphics::{Texture};
pub struct Textures {
pub tile: Texture,
pub hor: Texture,
pub vert: Texture,
pub cross: Texture,
pub player: Texture,
pub enemy: Texture,
}
......@@ -10,7 +13,10 @@ pub struct Textures {
impl Textures {
pub fn init(ctx: &mut Context) -> tetra::Result<Textures> {
Ok(Textures {
tile: Texture::new(ctx, "./resources/tile.png")?,
tile: Texture::new(ctx, "./resources/empty.png")?,
hor: Texture::new(ctx, "./resources/hor.png")?,
vert: Texture::new(ctx, "./resources/vert.png")?,
cross: Texture::new(ctx, "./resources/cross.png")?,
player: Texture::new(ctx, "./resources/player_new.png")?,
enemy: Texture::new(ctx, "./resources/foe.png")?,
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment