world-digger-amethyst

[Archive] Game about Digging a lot using upgradable tools. Made using the Amethyst Engine. Might resume work on it eventually.
git clone https://git.jojolepro.com/world-digger-amethyst.git
Log | Files | Refs | README | LICENSE

player.rs (2214B)


      1 use amethyst::ecs::{VecStorage,Component,System,ReadStorage,Fetch,WriteStorage,Join,Entity};
      2 use amethyst::assets::Handle;
      3 use amethyst::renderer::Texture;
      4 use amethyst::ui::{UiTransform,UiText,UiImage};
      5 
      6 // tools, equipped, backpack, tool stats
      7 
      8 pub struct Tool{
      9     pub name: String,
     10     pub icon: Handle<Texture>,
     11     pub use_time: f32,
     12     pub mine_quantity: i32,
     13     pub cost: i32,
     14 }
     15 
     16 pub struct Backpack{
     17     pub name: String,
     18     pub icon: Handle<Texture>,
     19     pub capacity: i32,
     20     pub cost: i32,
     21 }
     22 
     23 pub struct BlockInstance{
     24     pub weight_left: i32,
     25 }
     26 
     27 impl Component for BlockInstance{
     28     type Storage = VecStorage<Self>;
     29 }
     30 
     31 pub struct BlockDefinition{
     32     pub since_depth: i32,
     33     pub weight: i32,
     34 }
     35 
     36 pub struct BlockDefinitions{
     37     blocks: Vec<BlockDefinition>,
     38 }
     39 
     40 pub struct Inventory{
     41     pub tool: Tool,
     42     pub backpack: Backpack,
     43     pub carrying: i32,
     44     pub money: i32,
     45 }
     46 
     47 pub struct MineProgress{
     48     pub block: Option<Entity>,
     49     pub start: f64,
     50     pub progress: f32,
     51 }
     52 
     53 impl MineProgress{
     54     pub fn reset(&mut self){
     55         self.block = None;
     56         self.start = 0.0;
     57         self.progress = 0.0;
     58     }
     59 }
     60 
     61 pub struct UiUpdaterSystem;
     62 
     63 impl<'a> System<'a> for UiUpdaterSystem {
     64     type SystemData = (
     65         Fetch<'a, Inventory>,
     66         WriteStorage<'a, UiTransform>,
     67         WriteStorage<'a, UiText>,
     68         WriteStorage<'a, UiImage>,
     69         Fetch<'a, MineProgress>,
     70     );
     71 
     72     fn run(&mut self, (inventory,mut transforms,mut texts,mut images,progress): Self::SystemData) {
     73         for (tr,mut text) in (&transforms,&mut texts).join(){
     74             match &*tr.id{
     75                 "money" => text.text = format!("{}$",inventory.money),
     76                 "tool" => text.text = format!("{}",inventory.tool.name),
     77                 "backpack" => text.text = format!("{}",inventory.backpack.name),
     78                 "carry" => text.text = format!("{}/{} Kg",inventory.carrying,inventory.backpack.capacity),
     79                 _ => {},
     80             }
     81         }
     82 
     83         for (mut tr, mut images) in (&mut transforms,&mut images).join(){
     84             match &*tr.id{
     85                 "mine progress" => tr.width = progress.progress * 500.0,
     86                 _ => {},
     87             }
     88         }
     89     }
     90 }