-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathjoyas.bas
257 lines (210 loc) · 5.59 KB
/
joyas.bas
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
126
127
128
129
130
131
132
133
134
135
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
'-------------------------------------
' Joyas: A match-three pieces game
'
' Character set redefinition
data charset() b. = $D0,$68,$34,$68,$D0,$68,$34,$68, ' 1: Wall 1
data b. = $16,$2C,$58,$2C,$16,$2C,$58,$2C, ' 2: Wall 2
data b. = $00,$18,$68,$44,$2C,$30,$00,$00, ' 3: Rotated square
data b. = $00,$10,$38,$6C,$38,$10,$00,$00, ' 4: Diamond
data b. = $00,$7C,$54,$7C,$54,$7C,$00,$00, ' 5: Filled Square
data b. = $00,$64,$2C,$10,$68,$4C,$00,$00, ' 6: Cross
data b. = $00,$38,$4C,$5C,$7C,$38,$00,$00, ' 7: Big ball
data b. = $00,$5C,$40,$54,$04,$74,$00,$00, ' 8: Flag?
data b. = $00,$00,$00,$00,$00,$00,$00,$00, ' 9: Explosion
data b. = $7C,$82,$82,$82,$82,$82,$7C,$00, '10: Cursor
data b. = $D1,$6A,$35,$1B,$0E,$04,$00,$00, ' B: Bottom-left
data b. = $11,$AA,$55,$BB,$EE,$44,$00,$00, ' C: Bottom
data b. = $16,$AC,$58,$B0,$E0,$40,$00,$00 ' D: Bottom-right
data explode() b. = $00,$00,$00,$38,$54,$38,$00,$00,
data b. = $00,$00,$24,$40,$12,$08,$44,$00,
data b. = $00,$42,$00,$80,$00,$01,$00,$82,
data b. = $00,$00,$00,$00,$00,$00,$00,$00
' Our board pieces:
data pieces() b. = $03, $44, $85, $C6, $07, $48
' Our empty board (two lines)
data eboard() b. = $80,$40,$81,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$82,$40,$80,
data b. = $40,$80,$81,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$82,$80,$40
data lboard() b. = $80,$40,$8B,$8C,$8C,$8C,$8C,$8C,$8C,$8C,$8C,$8C,$8C,$8D,$40,$80
' Set graphics mode and narrow screen
graphics 18
poke 559, 33
' Redefine character set
move $E000, $7C00, 512
move adr(charset), $7C08, 104
poke 756, $7C
' Set colors
if peek($d014) = 1
' PAL
se. 0,3,8
se. 1,11,10
se. 2,8,6
se. 3,14,14
else
' NTSC
se. 0,4,8
se. 1,12,10
se. 2,9,6
se. 3,2,14
endif
' Array to hold the board, cleared on DIM
dim board(192) byte
mainBoard = adr(board) + 19
fullBoard = adr(board) + 16
hiScore = 0
screen = dpeek(88)
screenBoard = screen + 3
C = mainBoard - screenBoard
' Loop forever
do
' Clear board
for i=0 to 4
move adr(eboard), fullBoard+i*32, 32
next i
' Init game variables
score = 0 ' Score
nmoves = 15 ' Remaining moves
addMove = 16 ' Points to bonus
crsPos = 0 ' Cursor pos
' Clear the screen
mset screen, 176, 0
position 0, 0
' Show game info
print #6, , , " joyas", , , "HI SCORE:"; hiScore
print #6, "BUTTON: game ANY KEY: exit"
' Wait for button press and release
repeat : until not strig(0) or key()
repeat : until strig(0) or key()
' Exit on any key pressed
if key() then end
' Disable attract mode
poke 77,0
' Draw bottom of board
move adr(lboard), screen+160, 16
' Call game loop
while nmoves > 0
@GameLoop
wend
if hiScore < score then hiScore = score
loop
'-------------------------------------
' Move the cursor and wait for play
proc MoveCursor
' Loop
do
' Disable attract mode
poke 77,0
' Wait for valid move
repeat
' Show cursor
poke crsPos+screenBoard, 192+10
pause 1
' Remove cursor
poke crsPos+screenBoard, peek(crsPos+mainBoard)
pause 1
' Move cursor
i = stick(0)
nxtPos = (i=7) - (i=11) + 16 * ((i=13) - (i=14)) + crsPos
until nxtPos <> crsPos and peek(nxtPos + mainBoard) & 63 > 2
' If button is pressed, return
if not strig(0) then Exit
' Move cursor
crsPos = nxtPos
loop
endproc
'-------------------------------------
' Make pieces fall in the board
proc FallPieces
' Move board to screen
move fullBoard, screen, 160
' Search for holes in the board
for A=mainBoard to mainBoard + 151 step 16
for P=A to A+9
if peek(P) & 63 = 9
' If we found a hole, fall pieces!
i = P
while i > mainBoard + 15
poke i, peek(i-16)
i = i-16
wend
' Set new piece and display current position
poke i, pieces(rand(6))
move fullBoard, screen, 160
endif
next P
next A
endproc
'-------------------------------------
' Search matching pieces and remove
proc MatchPieces
' Number of matches found
lsize = 0
' Go through each line
for A = screenBoard to screenBoard + 151 step 16
' And through each column
for X=A to A+9
P = peek(X)
' Test if equal to the next two pieces
if P = peek(X+1) and P = peek(X+2)
' Transform screen pointer to board pointer
Y = X + C
' Clean the three pieces found
PC = (P & 192) + 9
poke Y, PC
poke Y+1, PC
poke Y+2, PC
inc lsize
endif
' Test if equal to the two pieces bellow
IF P = peek(X + 16) and P = peek(X + 32)
' Transform screen pointer to board pointer
Y = X + C
' Clean the three pieces found
PC = (P & 192) + 9
poke Y, PC
poke Y + 16, PC
poke Y + 32, PC
inc lsize
endif
next X
next A
if lsize
' Found a line, add to score and show a little animation
score = score + lsize * lsize
move fullBoard, screen, 160
for i = 0 to 3
sound 1, 80, 0, 10 - i * 3
' Set animation frame
move i*8 + adr(explode), $7C48, 8
pause 4
next i
endif
' Add one move at 16, 32, 64, etc. points
if score >= addMove
inc nmoves
addMove = addMove * 2
endif
' Print current score and moves left
position 18, 8
print #6, "score "; score; "/"; nmoves,
sound
endproc
'-------------------------------------
' Our main game loop
proc GameLoop
' Update number of moves
dec nmoves
' Loop until no pieces are left to move
repeat
@FallPieces
@MatchPieces
until not lsize
' Game over if no more moves
if nmoves < 1 then exit
@MoveCursor
' Perform an exchange
poke crsPos + mainBoard, peek(nxtPos + screenBoard)
poke nxtPos + mainBoard, peek(crsPos + screenBoard)
sound 0, 100, 10, 10
pause 2
sound
endproc