parent
8d4e2f1c1e
commit
2dac8912e4
@ -0,0 +1,4 @@
|
||||
player 200 200
|
||||
enemy 100 100
|
||||
enemy 150 100
|
||||
enemy 200 100
|
@ -0,0 +1,88 @@
|
||||
use std::collections::HashMap;
|
||||
use sfml::graphics::Texture;
|
||||
use crate::util;
|
||||
use crate::EntState;
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use std::io::BufRead;
|
||||
use sfml::graphics::Sprite;
|
||||
use sfml::graphics::Transformable;
|
||||
|
||||
pub struct Loader<'a> {
|
||||
|
||||
spritesheet_desc : HashMap<String, HashMap<String, i32>>,
|
||||
spritesheet_text : Texture
|
||||
|
||||
}
|
||||
|
||||
impl<'a> Loader<'a> {
|
||||
|
||||
pub fn new() -> Loader<'a> {
|
||||
Loader{
|
||||
spritesheet_desc: util::read_spritesheet(String::from("spritesheet_complete.xml")),
|
||||
spritesheet_text: Texture::from_file("spritesheet_complete.png").expect("Couldn't load texture")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn read_static_entities(&self, filename: String, entities: &EntState) {
|
||||
|
||||
let file = File::open(filename).expect("Could not open file");
|
||||
|
||||
let mut first_line: bool = true;
|
||||
let mut w: f32 = 0.0;
|
||||
let mut h: f32 = 0.0;
|
||||
|
||||
let mut x: i32 = 0;
|
||||
let mut y: i32 = 0;
|
||||
|
||||
|
||||
for line in BufReader::new(file).lines() {
|
||||
|
||||
if first_line {
|
||||
|
||||
first_line = !first_line;
|
||||
let val = line.unwrap();
|
||||
let arr : Vec<&str> = val.split_whitespace().collect();
|
||||
|
||||
w = arr.get(0).unwrap().parse::<f32>().unwrap();
|
||||
h = arr.get(1).unwrap().parse::<f32>().unwrap();
|
||||
|
||||
} else {
|
||||
|
||||
y += 1;
|
||||
x = 0;
|
||||
|
||||
let val = line.unwrap();
|
||||
for i in val.split_whitespace() {
|
||||
|
||||
x += 1;
|
||||
match i.parse::<i32>().unwrap() {
|
||||
0 => {
|
||||
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);
|
||||
}
|
||||
_ => {
|
||||
panic!("ahhhhhh");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_dynamic_entities(filename: String, entities: &EntState) {
|
||||
let file = File::open(filename).expect("Could not open file");
|
||||
for line in BufReader::new(file).lines() {
|
||||
|
||||
}
|
||||
|
||||
let mut sprite1 = Sprite::new();
|
||||
entities.dynamic_entities.borrow_mut().push(sprite1);
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
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
|
Loading…
Reference in new issue