-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.nim
63 lines (51 loc) · 1.76 KB
/
graphics.nim
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
import illwill, entity
const visRange = 10
var tb = newTerminalBuffer(2*visRange + 30, 2*visRange + 1)
proc exitProc*(){.noconv.} =
tb.resetAttributes()
tb.display
illwillDeinit()
showCursor()
quit(0)
setControlCHook(exitProc)
proc initGraphics*() =
illwillInit()
hideCursor()
proc drawWorld*(w: World, player: Ship, windSpeed: int, windDir: Direction) =
let (playerX, playerY) = w.ships[player]
for x in playerX-visRange ..< playerX+visRange+1:
for y in playerY-visRange ..< playerY+visRange+1:
var
coord = w.ships.normalize(x, y)
relCoord = w.ships.normalize(coord.x - playerX + 10,
coord.y - playerY + 10)
if not(coord in w.lands):
tb.write(relCoord.x, relCoord.y, fgBlue, "≈", resetStyle)
else:
tb.write(relCoord.x, relCoord.y, fgGreen, "#", resetStyle)
if coord in w.ships:
tb.write(relCoord.x, relCoord.y, case w.ships[coord].facing
of N: "^"
of NE: "┐"
of E: ">"
of SE: "┘"
of S: "v"
of SW: "└"
of W: "<"
of NW: "┌")
tb.write(2*visRange+2, 0, "Hull: " & $player.hull)
tb.write(2*visRange+2, 1, "Supplies: " & $player.supplies)
tb.write(2*visRange+2, 3, "Wind: " & $(windSpeed*2) & $ windDir)
proc loseScreenSunk*() =
tb.write(0, 0, "You have run your ship aground")
tb.write(0, 1, "Press Ctrl-C to quit")
proc loseScreenStarved*() =
tb.write(0, 0, "You have starved, after running out of supplies")
tb.write(0, 1, "Press Ctrl-C to quit")
proc winScreen*() =
tb.write(0, 0, "Congratulations, you have successfully")
tb.write(0, 1, "circumnavigated the globe")
tb.write(0, 2, "Press Ctrl-C to quit")
proc display*() =
tb.display()
tb.clear()