master
MitchellHansen 7 years ago
parent 2dac8912e4
commit 3eda84210d

@ -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<String, HashMap<String, i32>>,
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::<i32>().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;
}
}
}

@ -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<f64>)> = 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);

@ -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
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
Loading…
Cancel
Save