mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-09-27 20:48:54 +00:00
add inventory structure
This commit is contained in:
parent
41f72f3c7a
commit
6bcb498c5d
|
@ -1,3 +1,45 @@
|
|||
#[derive(Clone)]
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ mod sound;
|
|||
mod text_script;
|
||||
mod texture_set;
|
||||
mod ui;
|
||||
mod weapon;
|
||||
mod inventory;
|
||||
|
||||
struct Game {
|
||||
scene: Option<Box<dyn Scene>>,
|
||||
|
|
|
@ -10,6 +10,7 @@ use crate::frame::Frame;
|
|||
use crate::ggez::{Context, GameResult};
|
||||
use crate::SharedGameState;
|
||||
use crate::str;
|
||||
use crate::inventory::Inventory;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
|
@ -31,6 +32,7 @@ pub struct Player {
|
|||
pub cond: Condition,
|
||||
pub flags: Flag,
|
||||
pub equip: Equipment,
|
||||
pub inventory: Inventory,
|
||||
pub direction: Direction,
|
||||
pub display_bounds: Rect<usize>,
|
||||
pub hit_bounds: Rect<usize>,
|
||||
|
@ -70,6 +72,7 @@ impl Player {
|
|||
cond: Condition(0x80),
|
||||
flags: Flag(0),
|
||||
equip: Equipment(0),
|
||||
inventory: Inventory::new(),
|
||||
direction: Direction::Right,
|
||||
display_bounds: constants.my_char.display_bounds,
|
||||
hit_bounds: constants.my_char.hit_bounds,
|
||||
|
|
Loading…
Reference in a new issue