blob: 29ba52bead6a7053913f595e6548dcd999f4ca41 (
plain)
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
|
function! space_vlaze#game#Init()
let s:loop = 1
let s:score = 0
let s:start_time = localtime()
let s:ticks = 1
call space_vlaze#game#SetupWindow()
call space_vlaze#colors#Initialize()
call space_vlaze#game#InitializeBoard()
call space_vlaze#mappings#Initialize()
while s:loop ==# 1
sleep 50ms
call space_vlaze#mappings#Listen()
call space_vlaze#enemy#AddEnemiesToBoard()
call space_vlaze#game#RenderBoard()
let s:ticks += 1
endwhile
endfunction
function! space_vlaze#game#SetupWindow()
setlocal bufhidden=delete noswapfile nolazyredraw
endfunction
function! space_vlaze#game#InitializeBoard()
call space_vlaze#game#SetupBoard()
call space_vlaze#game#RenderBoard()
endfunction
function! space_vlaze#game#SetupBoard()
let s:board = []
let s:BOARD_HEIGHT = 20
let s:BOARD_WIDTH = 80
call space_vlaze#player#SetPlayerX(s:BOARD_WIDTH / 2 - 1)
call space_vlaze#player#SetPlayerY(s:BOARD_HEIGHT / 2)
" Create 20-row by 80-column board initialised with spaces
let i = 0
while i < s:BOARD_HEIGHT
let s:board = add(s:board, [])
let j = 0
while j < s:BOARD_WIDTH
let s:board[i] = add(s:board[i], ' ')
let j += 1
endwhile
let i += 1
endwhile
" Initialise player to the middle of the board
let s:board[space_vlaze#player#PlayerY()][space_vlaze#player#PlayerX()] = space_vlaze#player#PlayerCharacter()
endfunction
function! space_vlaze#game#RenderBoard()
let i = 1
while i <= s:BOARD_HEIGHT
call setline(i, join(s:board[i - 1], ''))
let i += 1
endwhile
redraw!
endfunction
function! space_vlaze#game#Board()
return s:board
endfunction
function! space_vlaze#game#BoardCell(y, x)
return s:board[a:y][a:x]
endfunction
function! space_vlaze#game#SetBoardCell(y, x, value)
if space_vlaze#game#IsWithinBoard(a:y, a:x)
let s:board[a:y][a:x] = a:value
endif
endfunction
function! space_vlaze#game#IsBoardCellEmpty(y, x)
if space_vlaze#game#IsWithinBoard(a:y, a:x)
return s:board[a:y][a:x] ==# ' '
endif
endfunction
function! space_vlaze#game#IsWithinBoard(y, x)
return a:y >=# 0 && a:y <# s:BOARD_HEIGHT && a:x >=# 0 && a:x <# s:BOARD_WIDTH
endfunction
function! space_vlaze#game#BoardHeight()
return s:BOARD_HEIGHT
endfunction
function! space_vlaze#game#BoardWidth()
return s:BOARD_WIDTH
endfunction
function! space_vlaze#game#Ticks()
return s:ticks
endfunction
function! space_vlaze#game#Quit()
let s:loop = -1
endfunction
function! space_vlaze#game#Pause()
endfunction
|