1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-15 18:32:48 +00:00

add inventory structure

This commit is contained in:
Alula 2020-09-10 12:27:33 +02:00
parent 41f72f3c7a
commit 6bcb498c5d
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
3 changed files with 47 additions and 2 deletions

View file

@ -1,3 +1,45 @@
#[derive(Clone)]
pub struct Weapon { pub struct Weapon {
id: u16,
level: u16,
experience: u16,
ammo: u16,
max_ammo: u16,
}
#[derive(Clone, Copy)]
pub struct Item(u16);
#[derive(Clone)]
pub struct Inventory {
current_item: u16,
current_weapon: u16,
items: Vec<Item>,
weapons: Vec<Weapon>,
}
impl Inventory {
#[allow(clippy::new_without_default)]
pub fn new() -> Inventory {
Inventory {
current_item: 0,
current_weapon: 0,
items: Vec::with_capacity(16),
weapons: Vec::with_capacity(16),
}
}
pub fn add_item(&mut self, item_id: u16) {
if !self.has_item(item_id) {
self.items.push(Item(item_id));
}
}
pub fn remove_item(&mut self, item_id: u16) {
self.items.retain(|item| item.0 != item_id);
}
pub fn has_item(&self, item_id: u16) -> bool {
self.items.iter().any(|item| item.0 == item_id)
}
} }

View file

@ -67,7 +67,7 @@ mod sound;
mod text_script; mod text_script;
mod texture_set; mod texture_set;
mod ui; mod ui;
mod weapon; mod inventory;
struct Game { struct Game {
scene: Option<Box<dyn Scene>>, scene: Option<Box<dyn Scene>>,

View file

@ -10,6 +10,7 @@ use crate::frame::Frame;
use crate::ggez::{Context, GameResult}; use crate::ggez::{Context, GameResult};
use crate::SharedGameState; use crate::SharedGameState;
use crate::str; use crate::str;
use crate::inventory::Inventory;
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
@ -31,6 +32,7 @@ pub struct Player {
pub cond: Condition, pub cond: Condition,
pub flags: Flag, pub flags: Flag,
pub equip: Equipment, pub equip: Equipment,
pub inventory: Inventory,
pub direction: Direction, pub direction: Direction,
pub display_bounds: Rect<usize>, pub display_bounds: Rect<usize>,
pub hit_bounds: Rect<usize>, pub hit_bounds: Rect<usize>,
@ -70,6 +72,7 @@ impl Player {
cond: Condition(0x80), cond: Condition(0x80),
flags: Flag(0), flags: Flag(0),
equip: Equipment(0), equip: Equipment(0),
inventory: Inventory::new(),
direction: Direction::Right, direction: Direction::Right,
display_bounds: constants.my_char.display_bounds, display_bounds: constants.my_char.display_bounds,
hit_bounds: constants.my_char.hit_bounds, hit_bounds: constants.my_char.hit_bounds,