From 3eda84210d9c9cd26444089f92df81c1abca2220 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Tue, 30 Jan 2018 21:00:00 +0700 Subject: [PATCH] message --- src/loader.rs | 18 ++++++++++-------- src/main.rs | 30 +++++++++++++----------------- static_entities.txt | 16 ++++++++-------- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/loader.rs b/src/loader.rs index bf3dae56..95b764c5 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -8,16 +8,16 @@ use std::io::BufRead; use sfml::graphics::Sprite; use sfml::graphics::Transformable; -pub struct Loader<'a> { +pub struct Loader { spritesheet_desc : HashMap>, spritesheet_text : Texture } -impl<'a> Loader<'a> { +impl Loader { - pub fn new() -> Loader<'a> { + pub fn new() -> Loader { Loader{ spritesheet_desc: util::read_spritesheet(String::from("spritesheet_complete.xml")), spritesheet_text: Texture::from_file("spritesheet_complete.png").expect("Couldn't load texture") @@ -25,7 +25,7 @@ impl<'a> Loader<'a> { } - pub fn read_static_entities(&self, filename: String, entities: &EntState) { + pub fn read_static_entities<'a>(&'a self, filename: String, entities: &EntState<'a>) { let file = File::open(filename).expect("Could not open file"); @@ -50,27 +50,29 @@ impl<'a> Loader<'a> { } else { - y += 1; x = 0; let val = line.unwrap(); for i in val.split_whitespace() { - - x += 1; match i.parse::().unwrap() { 0 => { + // Do nothing for now + } + 1 => { let mut sprite = Sprite::new(); sprite.set_texture(&self.spritesheet_text, false); sprite.set_texture_rect(&util::grab_sheet_rec(String::from("blockBrown.png"), &self.spritesheet_desc)); sprite.set_position((x as f32 * w, y as f32 * h)); - entities.dynamic_entities.borrow_mut().push(sprite); + entities.static_entities.borrow_mut().push(sprite); } _ => { panic!("ahhhhhh"); } } + x += 1; } + y += 1; } } } diff --git a/src/main.rs b/src/main.rs index 03692745..58b70930 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,27 +42,18 @@ pub struct EntState<'a> { fn main() { - let loader = Loader::new(); + + let loader = Loader::new(); let mut state = EntState { dynamic_entities: Rc::new(RefCell::new(Vec::new())), - static_entities : Rc::new(RefCell::new(Vec::new())) + static_entities: Rc::new(RefCell::new(Vec::new())) }; + { - loader.read_static_entities(String::from("static_entities.txt"), &state); - - - state.dynamic_entities.borrow_mut().push(Sprite::new()); - -// sp.set_texture(&spritesheet_text, false); -// sp.set_texture_rect(&util::grab_sheet_rec(String::from("blockBrown.png"), &spritesheet_desc)); -// sp.set_position((64.0, 64.0)); - - return; -// let mut block_sprite2 = Sprite::new(); -// block_sprite2.set_texture(&spritesheet_text, false); -// block_sprite2.set_texture_rect(&util::grab_sheet_rec(String::from("blockBrown.png"), &spritesheet_desc)); -// block_sprite2.set_position((128.0, 64.0)); + let mut state_borrow = &state; + loader.read_static_entities(String::from("static_entities.txt"), state_borrow); + } let static_sprites: Vec<(&Sprite, AABB)> = vec![ // ( @@ -101,7 +92,7 @@ fn main() { // sprite.set_texture_rect(&util::grab_sheet_rec(String::from("playerBlue_stand.png"), &spritesheet_desc)); let mut window = RenderWindow::new( - (500, 500), + (512, 512), "Custom drawable", Style::CLOSE, &Default::default(), @@ -183,6 +174,11 @@ fn main() { window.draw(&player); window.draw(&collision_sprite); + + for ent in state.static_entities.borrow().iter() { + window.draw(ent); + } + if interferences.len() == 0 { // window.draw(&block_sprite); // window.draw(&block_sprite2); diff --git a/static_entities.txt b/static_entities.txt index 4da3a3a7..fd9b1e2b 100644 --- a/static_entities.txt +++ b/static_entities.txt @@ -1,9 +1,9 @@ 64 64 -0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 -0 0 1 1 1 1 1 1 1 0 -0 0 0 0 0 0 0 0 0 0 \ No newline at end of file +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +1 1 1 0 0 0 0 0 +0 0 1 0 0 0 0 0 +0 0 1 0 0 0 0 0 +0 0 1 1 1 1 1 1 +0 0 0 0 0 0 0 0 \ No newline at end of file