A lightweight on-chain RPG game demo built on Movement.
This package currently includes two main modules:
This module manages all logic related to the player, including:
- 🧍 Player Initialization
- 🎒 Inventory System
- 🗡️ Equipping & Unequipping:
- Sword
- Shield
- Armor
- 🧪 Potion Usage
- ⚔️ Combat:
- Attack enemies (Boar)
- Take damage from enemy counterattacks
- ⭐ Leveling:
- EXP scales exponentially:
100 * 2^(level - 1)
- Auto-heal and mana refill on level up
- +20 max health, +10 max mana per level
- EXP scales exponentially:
This module defines logic for spawning and interacting with enemies:
- 🐗
spawn_boar()
- Spawns a basic early-game enemy:- Health: 30
- Attack: 5
- EXP reward: 50
take_damage()
- Applies damage to enemy and checks if it's killed
Feature | Description |
---|---|
Player creation | Base stats and empty inventory |
Inventory | Single vector-based item inventory |
Equipment | Equip/unequip sword, shield, armor |
Items | Weapon, armor, shield, potions |
Combat | Basic enemy fighting + counterattacks |
EXP & Levels | Exponential scaling XP system |
Potions | Heals player up to max health |
Player Death | Player dies if health reaches zero |
// Initialize a new player
hero::init_player(&signer);
// Get player stats
hero::get_level(&player): u8
hero::get_exp(&player): u64
hero::get_health(&player): u64
hero::get_mana(&player): u64
hero::get_max_health(&player): u64
hero::get_max_mana(&player): u64
// Item structure
struct Item {
id: u64,
name: string::String,
item_type: u8, // 0=sword, 1=shield, 2=armor, 3=potion
power: u64,
}
// Item type constants
hero::type_sword(): u8 // Returns 0
hero::type_shield(): u8 // Returns 1
hero::type_armor(): u8 // Returns 2
hero::type_potion(): u8 // Returns 3
// Item factory (for testing)
hero::make_item(id, name, item_type, power): Item
// Add item to inventory
hero::add_item(&signer, item);
// Equip items
hero::equip_sword(&signer, item_id): bool
hero::equip_shield(&signer, item_id): bool
hero::equip_armor(&signer, item_id): bool
// Unequip items (returns item to inventory)
hero::unequip_sword(&signer): bool
hero::unequip_shield(&signer): bool
hero::unequip_armor(&signer): bool
// Attack enemy (returns true if enemy killed)
hero::attack_enemy(&signer, &mut enemy): bool
// Use potion (consumes item, heals up to max health)
hero::use_potion(&signer, item_id): bool
// Spawn boar enemy
enemies::spawn_boar(): Enemy
// Enemy getters
enemies::get_health(&enemy): u64
enemies::get_attack(&enemy): u64
enemies::get_exp_reward(&enemy): u64
enemies::get_name(&enemy): &string::String
// Apply damage to enemy
enemies::take_damage(&mut enemy, amount): bool
// Enemy factory (for testing)
enemies::make_enemy(name, health, attack, exp_reward): Enemy
- Base Attack: 5 damage (when no sword equipped)
- With Sword: Sword's power value = damage dealt
- Enemy Counterattack: If enemy survives, it attacks back with its attack value
- Player Death: Occurs when health reaches 0
- Player attacks enemy with calculated damage
- If enemy health ≤ 0: enemy dies, player gains EXP
- If enemy survives: enemy counterattacks, player takes damage
- If player health ≤ 0: player dies
- Formula:
100 * 2^(level - 1)
- Level 1 → 2: 100 EXP
- Level 2 → 3: 200 EXP
- Level 3 → 4: 400 EXP
- And so on...
- Max Health: +20 per level
- Max Mana: +10 per level
- Full Restore: Health and mana refilled to maximum
- EXP Carryover: Excess EXP carries to next level
Type | ID | Description |
---|---|---|
Sword | 0 | Increases attack damage |
Shield | 1 | Defensive equipment |
Armor | 2 | Defensive equipment |
Potion | 3 | Consumable, restores health |
- ID: Unique identifier for the item
- Name: Human-readable item name
- Item Type: Determines item category (0-3)
- Power: Effect strength (damage for weapons, heal amount for potions)
- Usage: Consumes item from inventory
- Effect: Restores health by power amount
- Limit: Cannot exceed max health
- Return:
true
if used successfully,false
if item not found
// Create player
hero::init_player(&signer);
// Add items
let sword = hero::make_item(1, string::utf8(b"Iron Sword"), hero::type_sword(), 15);
let potion = hero::make_item(2, string::utf8(b"Health Potion"), hero::type_potion(), 30);
hero::add_item(&signer, sword);
hero::add_item(&signer, potion);
// Equip a sword
hero::equip_sword(&signer, 1);
// Use a potion
hero::use_potion(&signer, 2);
// Spawn and fight a boar
let mut boar = enemies::spawn_boar();
let killed = hero::attack_enemy(&signer, &mut boar);
// Unequip items
hero::unequip_sword(&signer);