-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.odin
57 lines (49 loc) · 1.32 KB
/
player.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
package main
import cur "extra:curses"
Player :: struct {
position : Position,
health: int,
max_health : int,
attack: int,
gold: int,
exp: int,
}
HEALTH :: 20
player_new :: proc() -> Player {
return {
health = HEALTH,
max_health = HEALTH,
attack = 1,
}
}
player_draw :: proc(p : ^Player) {
cur.mvprintw(p.position.y, p.position.x, "@")
}
player_input :: proc(p : ^Player, input : i32) -> Position{
newPos := p.position
switch input {
case 'w', 'W':
newPos.y -= 1
case 's', 'S':
newPos.y += 1
case 'a', 'A':
newPos.x -= 1
case 'd', 'D':
newPos.x += 1
}
return newPos
}
player_move :: proc(p : ^Player, pos :Position, level : [MAXLEVELROW][MAXLEVELCOL]cur.chtype ) {
cur.mvaddch(p.position.y, p.position.x, level[p.position.y][p.position.x])
p.position = pos
player_draw(p)
}
player_check_position :: proc(level : ^Level, pos: Position) {
//player_check_position :: proc(p : ^Player, pos : Position, level : [MAXLEVELROW][MAXLEVELCOL]cur.chtype) {
switch cur.mvinch(pos.y, pos.x) {
case '.', '#', '+':
player_move(&level.player, pos, level.tiles)
case 'X', 'G', 'T':
combat(&level.player, monster_at(pos, level.monsters[:]), true)
}
}