-
Notifications
You must be signed in to change notification settings - Fork 0
/
monster.odin
95 lines (84 loc) · 1.91 KB
/
monster.odin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import "core:fmt"
import cur "extra:curses"
import "core:math/rand"
Monster :: struct {
symbol : cur.chtype,
health : int,
attack : int,
speed : int,
defence : int,
pathfinding: int,
position: Position,
}
monster_select :: proc(level: int, room : ^Room) -> Monster {
mtemp : Monster
mt : u32 // Monster type
switch level {
case 1,2,3:
mt = (rand.uint32() %% 2) + 1
case 4,5:
mt = (rand.uint32() %% 2) + 2
case 6:
mt = 3
}
switch mt {
case 1:
mtemp = monster_spider()
case 2:
mtemp = monster_goblin()
case 3:
mtemp = monster_troll()
}
monster_position(&mtemp, room)
monster_draw(&mtemp)
return mtemp
}
monster_position :: proc(m :^Monster, r : ^Room){
m.position.x = i32(rand.uint32()) %% (r.width - 2) + r.position.x + 1
m.position.y = i32(rand.uint32()) %% (r.height - 2) + r.position.y + 1
}
monster_draw :: proc(m: ^Monster) {
cur.mvaddch(m.position.y, m.position.x, m.symbol)
}
monster_spider :: proc() -> Monster {
return {
symbol = 'X',
health = 2,
attack = 1,
speed = 1,
defence = 1,
pathfinding = 1,
}
}
monster_goblin :: proc() -> Monster {
return {
symbol = 'G',
health = 5,
attack = 3,
speed = 1,
defence = 1,
pathfinding = 2,
}
}
monster_troll :: proc() -> Monster {
return {
symbol = 'T',
health = 15,
attack = 5,
speed = 1,
defence = 1,
pathfinding = 1,
}
}
monster_at :: proc(pos: Position, monster: []Monster) -> ^Monster {
for &m in monster {
if m.position == pos {
return &m
}
}
fmt.panicf("Deu ruim!!")
}
monster_kill :: proc(m: ^Monster) {
cur.mvaddch(m.position.y, m.position.x, '.')
}