diff --git a/map.txt b/map.txt new file mode 100644 index 00000000..1f38261c --- /dev/null +++ b/map.txt @@ -0,0 +1,8 @@ +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 diff --git a/src/main.rs b/src/main.rs index 87e9d8e1..1bb2ee5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,21 +28,44 @@ use ncollide2d::bounding_volume::{self, AABB, BoundingVolumeInterferencesCollect use ncollide2d::partitioning::BVT; use sfml::graphics::RectangleShape; use std::{thread, time}; +use std::cell::RefCell; +use std::rc::Rc; +pub struct tSprite { + pub value1: i32, + value2: f64 +} +impl tSprite { + pub fn new() -> tSprite { + tSprite { value1: 0, value2: 0.0 } + } +} fn main() { - // Load the spritsheet + // Load the spritesheet let spritesheet_desc = util::read_spritesheet(String::from("spritesheet_complete.xml")); let spritesheet_text = Texture::from_file("spritesheet_complete.png") .expect("Couldn't load texture"); - let mut block_sprite = Sprite::new(); - block_sprite.set_texture(&spritesheet_text, false); - block_sprite.set_texture_rect(&util::grab_sheet_rec(String::from("blockBrown.png"), &spritesheet_desc)); - block_sprite.set_position((64.0, 64.0)); + let shared_container: Rc>> = Rc::new(RefCell::new(Vec::new())); + + shared_container.borrow_mut().push(tSprite::new()); + + let mut sprite_vec = shared_container.borrow_mut(); + + sprite_vec.last().unwrap().value1 = 0; + + // sp.set_position((0.0,0.0)); + //println!("{:?}", sp); + + +// 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)); @@ -53,16 +76,16 @@ fn main() { block_sprite3.set_texture_rect(&util::grab_sheet_rec(String::from("blockBrown.png"), &spritesheet_desc)); block_sprite3.set_position((192.0, 64.0)); - let idx_and_bounding_spheres: Vec<(&Sprite, AABB)> = vec![ - ( - &block_sprite, - { - let bounds = &block_sprite.local_bounds(); - let pos = &block_sprite.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 static_sprites: Vec<(&Sprite, AABB)> = vec![ +// ( +// &block_sprite, +// { +// let bounds = &block_sprite.local_bounds(); +// let pos = &block_sprite.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_sprite2, { @@ -83,7 +106,7 @@ fn main() { ), ]; - let bvt = BVT::new_balanced(idx_and_bounding_spheres); + let bvt = BVT::new_balanced(static_sprites); let mut sprite = Sprite::new(); sprite.set_texture(&spritesheet_text, false); @@ -173,7 +196,7 @@ fn main() { window.draw(&collision_sprite); if interferences.len() == 0 { - window.draw(&block_sprite); + // window.draw(&block_sprite); window.draw(&block_sprite2); window.draw(&block_sprite3); } diff --git a/src/player.rs b/src/player.rs index 13bf63b2..a6d37d25 100644 --- a/src/player.rs +++ b/src/player.rs @@ -97,7 +97,7 @@ impl<'s> Player<'s> { pub fn update(&mut self, delta_t: f32) { self.pos.x += self.delta.x * delta_t * 8.0; self.pos.y += self.delta.y * delta_t * 8.0; - println!("{:?}", self.delta); + //println!("{:?}", self.delta); let friction = 10.0; let ratio = 1.0 / (1.0 + delta_t * friction); self.delta *= ratio; diff --git a/src/util.rs b/src/util.rs index 5ffd383d..d03a7c46 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,6 +4,9 @@ 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; pub fn read_spritesheet(filename: String) -> HashMap> { @@ -75,4 +78,11 @@ pub fn grab_sheet_rec(spritename: String, spritesheet: &HashMap