MitchellHansen 6 years ago
parent 3eda84210d
commit 45256f1a0e

@ -24,7 +24,6 @@ impl Loader {
}
}
pub fn read_static_entities<'a>(&'a self, filename: String, entities: &EntState<'a>) {
let file = File::open(filename).expect("Could not open file");
@ -33,7 +32,7 @@ impl Loader {
let mut w: f32 = 0.0;
let mut h: f32 = 0.0;
let mut x: i32 = 0;
let mut x: i32;
let mut y: i32 = 0;
@ -77,14 +76,40 @@ impl Loader {
}
}
pub fn read_dynamic_entities(filename: String, entities: &EntState) {
pub fn read_dynamic_entities<'a>(&'a self, filename: String, entities: &EntState<'a>) {
let file = File::open(filename).expect("Could not open file");
for line in BufReader::new(file).lines() {
}
let val = line.unwrap();
let arr : Vec<&str> = val.split_whitespace().collect();
let e = arr.get(0).unwrap();
let x = arr.get(1).unwrap().parse::<f32>().unwrap();
let y = arr.get(2).unwrap().parse::<f32>().unwrap();
match *e {
"enemy" => {
let mut sprite = Sprite::new();
sprite.set_texture(&self.spritesheet_text, false);
sprite.set_texture_rect(&util::grab_sheet_rec(String::from("enemyFloating_1.png"), &self.spritesheet_desc));
sprite.set_position((x, y));
let mut sprite1 = Sprite::new();
entities.dynamic_entities.borrow_mut().push(sprite1);
entities.dynamic_entities.borrow_mut().push(sprite);
}
"player" => {
let mut sprite = Sprite::new();
sprite.set_texture(&self.spritesheet_text, false);
sprite.set_texture_rect(&util::grab_sheet_rec(String::from("playerBlue_up3.png"), &self.spritesheet_desc));
sprite.set_position((x, y));
entities.dynamic_entities.borrow_mut().push(sprite);
}
_ => {
// Do nothing
}
}
}
}
}

@ -22,11 +22,11 @@ extern crate ncollide2d;
use sfml::graphics::{
Color, RenderTarget, RenderWindow,
Texture, Sprite, Transformable
Sprite, Transformable
};
use sfml::window::{ Event, Key, Style};
use sfml::system::Vector2 as sfVec2;
use ncollide2d::bounding_volume::{self, AABB, BoundingVolumeInterferencesCollector};
use ncollide2d::bounding_volume::{AABB, BoundingVolumeInterferencesCollector};
use ncollide2d::partitioning::BVT;
use sfml::graphics::RectangleShape;
use std::{thread, time};
@ -42,18 +42,15 @@ pub struct EntState<'a> {
fn main() {
let loader = Loader::new();
let mut state = EntState {
dynamic_entities: Rc::new(RefCell::new(Vec::new())),
static_entities: Rc::new(RefCell::new(Vec::new()))
};
{
let mut state_borrow = &state;
loader.read_static_entities(String::from("static_entities.txt"), state_borrow);
}
loader.read_static_entities(String::from("static_entities.txt"), &state);
loader.read_dynamic_entities(String::from("dynamic_entities.txt"), &state);
let static_sprites: Vec<(&Sprite, AABB<f64>)> = vec![
// (
@ -64,33 +61,11 @@ fn main() {
// bounding_volume::AABB::new(na::Point2::new(pos.x as f64, pos.y as f64),
// na::Point2::new((pos.x + bounds.width) as f64, (pos.y + bounds.width) as f64))
// },
// ),
// (
// &block_sprite2,
// {
// let bounds = &block_sprite2.local_bounds();
// let pos = &block_sprite2.position();
// bounding_volume::AABB::new(na::Point2::new(pos.x as f64, pos.y as f64),
// na::Point2::new((pos.x + bounds.width) as f64, (pos.y + bounds.width) as f64))
// },
// ),
// (
// &block_sprite3,
// {
// let bounds = &block_sprite3.local_bounds();
// let pos = &block_sprite3.position();
// bounding_volume::AABB::new(na::Point2::new(pos.x as f64, pos.y as f64),
// na::Point2::new((pos.x + bounds.width) as f64, (pos.y + bounds.width) as f64))
// },
// ),
];
let bvt = BVT::new_balanced(static_sprites);
let mut sprite = Sprite::new();
// sprite.set_texture(&spritesheet_text, false);
// sprite.set_texture_rect(&util::grab_sheet_rec(String::from("playerBlue_stand.png"), &spritesheet_desc));
let mut window = RenderWindow::new(
(512, 512),
"Custom drawable",
@ -179,10 +154,8 @@ fn main() {
window.draw(ent);
}
if interferences.len() == 0 {
// window.draw(&block_sprite);
// window.draw(&block_sprite2);
// window.draw(&block_sprite3);
for ent in state.dynamic_entities.borrow().iter() {
window.draw(ent);
}
window.display();

@ -4,11 +4,6 @@ use std::collections::HashMap;
use std::borrow::Cow;
use std::str::FromStr;
use sfml::graphics::IntRect;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use crate::EntState;
use sfml::graphics::Sprite;
pub fn read_spritesheet(filename: String) -> HashMap<String, HashMap<String, i32>> {
@ -30,8 +25,6 @@ pub fn read_spritesheet(filename: String) -> HashMap<String, HashMap<String, i32
let mut map_entry: HashMap<String, i32> = HashMap::new();
//println!("{:?}", d.name());
let mut name: String = String::new();
for i in d.attributes() {

Loading…
Cancel
Save