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

tilemap update

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

2.11 KiB | W: | H:

resources/cross.png

2.07 KiB | W: | H:

resources/cross.png
resources/cross.png
resources/cross.png
resources/cross.png
  • 2-up
  • Swipe
  • Onion skin
resources/cross2.png

2.08 KiB

resources/cross3.png

2.31 KiB

resources/empty2.png

127 B

resources/floor.png

1.98 KiB

resources/hor.png

1.99 KiB | W: | H:

resources/hor.png

1.99 KiB | W: | H:

resources/hor.png
resources/hor.png
resources/hor.png
resources/hor.png
  • 2-up
  • Swipe
  • Onion skin
resources/hor2.png

1.99 KiB

resources/hor3.png

2.03 KiB

resources/player.png

1.74 KiB | W: | H:

resources/player.png

1.98 KiB | W: | H:

resources/player.png
resources/player.png
resources/player.png
resources/player.png
  • 2-up
  • Swipe
  • Onion skin
resources/vert.png

1.99 KiB | W: | H:

resources/vert.png

1.99 KiB | W: | H:

resources/vert.png
resources/vert.png
resources/vert.png
resources/vert.png
  • 2-up
  • Swipe
  • Onion skin
resources/vert2.png

1.98 KiB

resources/vert3.png

2.03 KiB

......@@ -40,7 +40,7 @@ impl GameState {
let huge = VectorFontBuilder::new("./resources/corbel.ttf")?.with_size(ctx, 50.0);
let background_music = Sound::new("./resources/music.mp3")?;
background_music.repeat(ctx);
background_music.repeat_with(ctx,0.2, 1.0);
if textures.is_ok() {
if font.is_ok() && huge.is_ok() {
......@@ -327,14 +327,23 @@ impl GameState {
let boundary_height = config::BOARD_HEIGHT + 2;
for x in 0..boundary_width {
GameState::draw_tile(self, Color::BLACK, x, 0, ctx);
GameState::draw_tile(self, Color::BLACK, x, boundary_height - 1, ctx);
GameState::draw_border_tile(self, Color::rgb(0.5, 0.5, 0.5), x, 0, ctx);
GameState::draw_border_tile(self, Color::rgb(0.5, 0.5, 0.5), x, boundary_height - 1, ctx);
}
for y in 0..boundary_height {
GameState::draw_tile(self, Color::BLACK, 0, y, ctx);
GameState::draw_tile(self, Color::BLACK, boundary_width - 1, y, ctx);
GameState::draw_border_tile(self, Color::rgb(0.5, 0.5, 0.5), 0, y, ctx);
GameState::draw_border_tile(self, Color::rgb(0.5, 0.5, 0.5), boundary_width - 1, y, ctx);
}
}
fn draw_border_tile(&mut self, color: Color, x: usize, y: usize, ctx: &mut Context) {
self.textures.cross.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 draw_tiles(&mut self, ctx: &mut Context) {
let board = self.current_run.level.board;
......@@ -349,7 +358,7 @@ impl GameState {
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),
Tile::Exit => GameState::draw_exit(self, Color::WHITE, draw_x, draw_y, ctx),
_ => {}
}
}
......@@ -366,13 +375,26 @@ impl GameState {
})
}
fn draw_wall(&mut self, color: Color, x: usize, y: usize, ctx: &mut Context) {
fn draw_exit(&mut self, color: Color, x: usize, y: usize, ctx: &mut Context) {
self.textures.stairs.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 draw_wall(&mut self, mut 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(),
11111111 => {
tex = self.textures.var_tile.clone();
color = Color::rgb(0.5,0.5,0.5);
},
_ => {}
}
tex.draw(ctx, DrawParams {
......@@ -385,44 +407,116 @@ impl GameState {
}
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,
_ => {},
if x==0|| y==0{
result += 10000000;
}
match board[x][y-1]{
Tile::Wall => result += 1000000,
_ => {},
else{
match board[x-1][y-1]{
Tile::Wall => result += 10000000,
_ => {},
}
}
match board[x+1][y-1]{
Tile::Wall => result += 100000,
_ => {},
if y==0{
result += 1000000;
}
match board[x+1][y]{
Tile::Wall => result += 10000,
_ => {},
else{
match board[x][y-1]{
Tile::Wall => result += 1000000,
_ => {},
}
}
match board[x+1][y+1]{
Tile::Wall => result += 1000,
_ => {},
if x>=config::BOARD_WIDTH-1|| y==0{
result += 100000;
}
match board[x][y+1]{
Tile::Wall => result += 100,
_ => {},
else{
match board[x+1][y-1]{
Tile::Wall => result += 100000,
_ => {},
}
}
if x>=config::BOARD_WIDTH-1{
result += 10000;
}
else{
match board[x+1][y]{
Tile::Wall => result += 10000,
_ => {},
}
}
if x>=config::BOARD_WIDTH-1||y>=config::BOARD_HEIGHT-1{
result += 1000;
}
else{
match board[x+1][y+1]{
Tile::Wall => result += 1000,
_ => {},
}
}
if y>=config::BOARD_HEIGHT-1{
result += 100;
}
else{
match board[x][y+1]{
Tile::Wall => result += 100,
_ => {},
}
}
if x==0||y>=config::BOARD_HEIGHT-1{
result += 10;
}
match board[x-1][y+1]{
Tile::Wall => result += 10,
_ => {},
else{
match board[x-1][y+1]{
Tile::Wall => result += 10,
_ => {},
}
}
match board[x-1][y]{
Tile::Wall => result += 1,
_ => {},
if x==0{
result += 1;
}
else{
match board[x-1][y]{
Tile::Wall => result += 1,
_ => {},
}
}
// 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
}
......
......@@ -3,22 +3,28 @@ use tetra::graphics::{Texture};
pub struct Textures {
pub tile: Texture,
pub var_tile: Texture,
pub hor: Texture,
pub vert: Texture,
pub cross: Texture,
pub player: Texture,
pub enemy: Texture,
pub chest: Texture,
pub stairs: Texture,
}
impl Textures {
pub fn init(ctx: &mut Context) -> tetra::Result<Textures> {
Ok(Textures {
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")?,
tile: Texture::new(ctx, "./resources/floor.png")?,
var_tile: Texture::new(ctx, "./resources/empty.png")?,
hor: Texture::new(ctx, "./resources/hor3.png")?,
vert: Texture::new(ctx, "./resources/vert3.png")?,
cross: Texture::new(ctx, "./resources/cross3.png")?,
player: Texture::new(ctx, "./resources/player_new.png")?,
enemy: Texture::new(ctx, "./resources/foe.png")?,
chest: Texture::new(ctx, "./resources/chest.png")?,
stairs: Texture::new(ctx, "./resources/stairs.png")?,
})
}
}
\ No newline at end of file
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