108 lines
2.0 KiB
Odin
108 lines
2.0 KiB
Odin
package main
|
|
|
|
import rand "core:math/rand"
|
|
import rl "vendor:raylib"
|
|
|
|
INV_SIZE :: 16
|
|
|
|
ItemKind :: enum {
|
|
None,
|
|
Weapon,
|
|
Armor,
|
|
Amulet,
|
|
Potion,
|
|
}
|
|
|
|
Item :: struct {
|
|
kind: ItemKind,
|
|
name: string,
|
|
level: i32,
|
|
dmg: i32,
|
|
crit: f32,
|
|
atk_spd: f32,
|
|
armor: i32,
|
|
hp_bonus: i32,
|
|
heal: i32,
|
|
}
|
|
|
|
GroundItem :: struct {
|
|
using base: BaseEntity,
|
|
item: Item,
|
|
}
|
|
|
|
item_color :: proc(kind: ItemKind) -> rl.Color {
|
|
#partial switch kind {
|
|
case .Weapon:
|
|
return {200, 120, 60, 255}
|
|
case .Armor:
|
|
return {80, 140, 220, 255}
|
|
case .Amulet:
|
|
return {180, 100, 220, 255}
|
|
case .Potion:
|
|
return {80, 220, 80, 255}
|
|
case .None:
|
|
return {120, 120, 120, 255}
|
|
}
|
|
return {120, 120, 120, 255}
|
|
}
|
|
|
|
item_kind_name :: proc(kind: ItemKind) -> string {
|
|
#partial switch kind {
|
|
case .Weapon:
|
|
return "Sword"
|
|
case .Armor:
|
|
return "Armor"
|
|
case .Amulet:
|
|
return "Amulet"
|
|
case .Potion:
|
|
return "Potion"
|
|
case .None:
|
|
return "Empty"
|
|
}
|
|
return "Empty"
|
|
}
|
|
|
|
make_ground_item :: proc(pos: rl.Vector2, item: Item) -> Entity {
|
|
return Entity {
|
|
v = GroundItem {
|
|
base = BaseEntity {
|
|
pos = pos,
|
|
col_size = 12,
|
|
gfx = {0 = GfxCircle{pos = {}, radius = 7, color = item_color(item.kind)}},
|
|
},
|
|
item = item,
|
|
},
|
|
}
|
|
}
|
|
|
|
random_item :: proc(level: i32) -> Item {
|
|
kind := ItemKind(rand.int_max(4) + 1)
|
|
item := Item {
|
|
kind = kind,
|
|
name = item_kind_name(kind),
|
|
level = level,
|
|
}
|
|
|
|
switch kind {
|
|
case .Weapon:
|
|
item.dmg = 6 + level * 3 + i32(rand.int_max(6))
|
|
item.crit = 0.05 + f32(rand.int_max(15)) * 0.01
|
|
item.atk_spd = f32(rand.int_max(20)) * 0.01
|
|
case .Armor:
|
|
item.armor = 3 + level * 2 + i32(rand.int_max(4))
|
|
item.hp_bonus = 10 + level * 4 + i32(rand.int_max(10))
|
|
case .Amulet:
|
|
item.crit = 0.03 + f32(rand.int_max(12)) * 0.01
|
|
item.hp_bonus = 5 + level * 2 + i32(rand.int_max(8))
|
|
item.atk_spd = f32(rand.int_max(15)) * 0.01
|
|
case .Potion:
|
|
item.heal = 30 + level * 8 + i32(rand.int_max(15))
|
|
case .None:
|
|
{}
|
|
}
|
|
return item
|
|
}
|
|
|
|
item_update :: proc(state: ^GameState, i: ^GroundItem, h: Handle, dt: f32) {
|
|
}
|