Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch btl Excluding Merge-Ins
This is equivalent to a diff from 941b13dad1 to b5bf464440
|
2018-08-28
| ||
| 03:42 | Not much Leaf check-in: b5bf464440 user: zax tags: btl | |
|
2017-09-12
| ||
| 01:37 | Convert to bearTermLib check-in: 77674d118b user: zax tags: btl | |
|
2017-09-11
| ||
| 23:16 | Correct directory structure Leaf check-in: 941b13dad1 user: zax tags: trunk | |
| 22:47 | Update after a bit check-in: 84350377c3 user: zax tags: trunk | |
Changes to nogue.nimble.
1 2 3 4 5 6 7 8 9 10 | # Package version = "0.1.0" author = "ZDS" description = "rogue" license = "MIT" # Dependencies requires "nim >= 0.16.0" | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 | # Package version = "0.1.0" author = "ZDS" description = "rogue" license = "MIT" # Dependencies requires "nim >= 0.16.0" requires "https://github.com/zacharycarter/blt-nim.git" bin = @["nogue"] |
Changes to noguepkg/base.nim.
|
| | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import random, options, deques, strutils
import map, characters
type
Game* = ref GameObj
GameObj = object
y*, x*, ticks*: int
map*: Map
charMap*: Matrix[Character]
characters*: seq[Character]
messages*: Deque[Message]
mode*: GameMode
GameMode* = enum
|
| ︙ | ︙ |
Changes to noguepkg/characters.nim.
| ︙ | ︙ | |||
15 16 17 18 19 20 21 |
Class* = ref object
case kind*: CharacterKind
of ckBeast:
beastKind*: bcKind
ch*: char
of ckPlayer:
playerKind*: pcKind
| | | | 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 |
Class* = ref object
case kind*: CharacterKind
of ckBeast:
beastKind*: bcKind
ch*: char
of ckPlayer:
playerKind*: pcKind
colorName*: string
attrs*: seq[int64]
maxHealth*: int
bcKind* = enum
wolf, bear, stag
pcKind* = enum
priest, warrior, thief
HealthLevel = enum
hlHealthy = "healthy"
hlWounded = "wounded"
hlCritical = "critically injured"
proc kind*(c: Character): CharacterKind = c.class.kind
proc colorName*(c: Character): string = c.class.colorName
proc ch*(c: Character): char = c.class.ch
proc isPC*[T](c: T): bool {. noSideEffect, inline .} = c.kind == ckPlayer
proc verb*(c: Character, v: string): string =
if c.isPC: v
else: v & "s"
|
| ︙ | ︙ |
Changes to noguepkg/classes.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 |
import blt, options, random
import map, characters
let
WOLF = Class(
kind: ckBeast,
beastKind: wolf,
ch: 'W',
colorName: "gray"
)
STAG = Class(
kind: ckBeast,
beastKind: stag,
ch: 'S',
colorName: "brown"
)
BEAR = Class(
kind: ckBeast,
beastKind: bear,
ch: 'B',
colorName: "brown"
)
PRIEST = Class(
kind: ckPlayer,
playerKind: priest,
colorName: "white"
)
WARRIOR = Class(
kind: ckPlayer,
playerKind: warrior,
colorName: "brown"
)
THIEF = Class(
kind: ckPlayer,
playerKind: thief,
colorName: "dark gray"
)
BEAST_CLASSES = [
WOLF, STAG, BEAR
]
PLAYER_CLASSES = [
PRIEST, WARRIOR, THIEF
]
|
| ︙ | ︙ | |||
52 53 54 55 56 57 58 |
proc displayChar*(character: Character): char =
if character.isPC:
'@'
else:
character.ch
| | | | | | | | | | < < < | | 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 |
proc displayChar*(character: Character): char =
if character.isPC:
'@'
else:
character.ch
proc fullColorName*(cell: Cell): string =
case cell.kind:
of ckWall: "gray"
of ckFloor:
case cell.floorKind:
of fkGrass: "green"
of fkStone: "gray"
proc fullColorName*(character: Character): string =
let
levelModifier = case character.level:
of elevated: "lighter"
of divine: "light"
of normal: ""
levelModifier & " " & character.colorName
proc randomPC*(): Character =
Character(
class: random(PLAYER_CLASSES),
health: random(20..60),
speed: random(40..60)
)
proc randomNPC*(): Character =
Character(
class: random(BEAST_CLASSES),
health: random(10..30),
speed: random(40..60)
)
|
Changes to noguepkg/map.nim.
1 2 3 4 5 6 7 8 |
import sequtils, random, math, options
type
CellKind* = enum
ckWall, ckFloor
FloorKind* = enum
fkGrass, fkStone
Cell* = object
| | | | 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 |
import sequtils, random, math, options
type
CellKind* = enum
ckWall, ckFloor
FloorKind* = enum
fkGrass, fkStone
Cell* = object
point*: Point
case kind*: CellKind
of ckWall: discard
of ckFloor:
floorKind*: FloorKind
Matrix*[T] = seq[seq[T]]
Map* = ref MapMatrix
MapMatrix = Matrix[Cell]
Dim* = enum
y, x
Point* = array[y..x, int]
proc `[]`* [T](matrix: Matrix[T], y, x: int): T =
matrix[y][x]
proc `[]`*[T](matrix: Matrix[T], p: Point): T =
matrix[p[y]][p[x]]
proc `[]=`*[T](matrix: var Matrix[T], y, x: int, t: T) =
matrix[y][x] = t
proc `[]=`*[T](matrix: var Matrix[T], p: Point, t: T) =
matrix[p[y]][p[x]] = t
|
| ︙ | ︙ |
Changes to noguepkg/ui.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 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
import tables, deques, strutils, sequtils
import blt
import map, base, characters, classes
type
UiCommand = enum
ucExamine
ExamineCommand = enum
ecPrev, ecNext, ecNormal
const
gameCommands = {
TK_U: Command.up,
TK_K: Command.down,
TK_H: Command.left,
TK_E: Command.right,
TK_L: Command.upleft,
TK_Y: Command.upright,
TK_B: Command.downleft,
TK_M: Command.downright,
TK_Q: quitGame
}.toTable
uiCommands = {
TK_X: ucExamine
}.toTable
examineCommands = {
TK_COMMA: ecPrev,
TK_PERIOD: ecNext,
TK_ESCAPE: ecNormal,
TK_X: ecNormal
}.toTable
var
examineTarget: Point
proc statusRow(game: Game): int = game.y
proc messageRow(game: Game): int = game.y + 1
const
MAXY = 25
MAXX = 80
WINDOWY = 35
proc init*(game: Game) =
discard terminal_open()
discard terminal_set("window.title='nogue'; window.size=80x35")
game.x = MAXX
game.y = MAXY
let
colorInfo = color_from_name("white")
colorAlert = color_from_name("red")
colorSuccess = color_from_name("green")
proc render[T: Cell | Character](t: T, extraAttrs: seq[int] = @[]) =
let
ch = t.displayChar
colorName = t.fullColorName
terminal_color colorName.color_from_name
terminal_put(t.point[x].cint, t.point[y].cint, ch.cint)
proc render(x, y: cint, msg: Message) =
let color = case msg.level:
of mlInfo:
colorInfo
of mlAlert:
colorAlert
of mlSuccess:
colorSuccess
terminal_color color
discard terminal_print(x, y, msg.content.cstring)
proc display(game: Game) =
## Render the whole game screen.
var msgBufferLength {.global.} = 0
# Render the map.
terminal_layer(1)
for y in 0..game.map[].high:
let row = game.map[y]
for x in 0..row.high:
render row[x]
# Populate the map with all characters.
terminal_layer(2)
terminal_clear_area(0, 0, 80, 25)
for character in game.characters:
render character
# Render status line.
terminal_layer(0)
if game.mode != gmNormal:
let modeStr = $game.mode
discard terminal_print(0.cint, game.statusRow.cint, modeStr.cstring)
else:
discard terminal_print(0.cint, game.statusRow.cint, "----------".cstring)
# Message rendering
var onScreenMessages {.global.} = initDeque[Message]()
# Render new message rows.
terminal_clear_area(0.cint, game.messageRow.cint, MAXX.cint, (WINDOWY-MAXY).cint)
case game.mode:
of gmExamine:
let targetCharacter = game.charMap[examineTarget]
if not targetCharacter.isNil:
render(targetCharacter)
discard terminal_print(0.cint, game.messageRow.cint, targetCharacter.charInfo)
msgBufferLength += 1
of gmNormal:
while game.messages.len > 0:
if onScreenMessages.len > WINDOWY-MAXY:
onScreenMessages.popLast()
onScreenMessages.addFirst(game.messages.popLast())
var i = 0
for msg in onScreenMessages:
render(0.cint, (game.messageRow + i).cint, msg)
i += 1
proc handle(game: var Game, command: UiCommand) =
case command:
of ucExamine:
game.mode = gmExamine
proc findExamineTarget(game: Game, point: var Point, f: proc(p: var Point, y, x: int)) =
|
| ︙ | ︙ | |||
161 162 163 164 165 166 167 |
game.findExamineTarget(currentPoint, mPrevPoint)
of ecNext:
game.findExamineTarget(currentPoint, mNextPoint)
of ecNormal:
game.mode = gmNormal
proc cycle*(game: var Game): Command =
| < < | | > | | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
game.findExamineTarget(currentPoint, mPrevPoint)
of ecNext:
game.findExamineTarget(currentPoint, mNextPoint)
of ecNormal:
game.mode = gmNormal
proc cycle*(game: var Game): Command =
# Refresh display and get input.
display game
terminal_refresh()
var input = terminal_read()
echo "INPUT: ", input
# Handle player input.
result = Command.noOp
case game.mode:
of gmNormal:
if input in uiCommands:
let uiCommand = uiCommands[input]
game.handle(uiCommand)
if input in gameCommands:
result = gameCommands[input]
of gmExamine:
if input in examineCommands:
let examineCommand = examineCommands[input]
game.handle(examineCommand)
proc cleanUp*() =
terminal_close()
|