-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlighting.s
123 lines (110 loc) · 1.94 KB
/
lighting.s
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
.include "global.inc"
.export can_player_see
.export line_of_sight
; todo perhaps use ray casting + bresenham's line algorithm?
.segment "ZEROPAGE"
destx: .res 1
desty: .res 1
prevx: .res 1
prevy: .res 1
i: .res 1 ; used for increment in loop, to prevent use of stack
sight: .res 1 ; used to set sight for mobs (mobs can see further in dungeon)
.segment "CODE"
.proc can_player_see
lda #1
sta sight
ldy #0
jmp can_see
.endproc
.proc line_of_sight
lda #14
sta sight
jmp can_see
.endproc
; check if mob can see tile
; todo line of sight
;
; xpos: destination tile x (unmodified)
; ypos: destination tile y (unmodified)
; y: mob index (modified)
;
; out: 0 if can see
; clobbers: x, y, and a1 register
.proc can_see
; load our destination
lda xpos
sta destx
sta prevx
lda ypos
sta desty
sta prevy
; load our source
lda mobs + Mob::coords + Coord::xcoord, y
sta xpos
lda mobs + Mob::coords + Coord::ycoord, y
sta ypos
continue:
; set increment
lda #0
sta i
loop:
; keep advancing until we get to destx
lda destx
cmp xpos
bcc decx ; less than
beq skipx
incx:
inc xpos
jmp skipx
decx:
dec xpos
skipx:
; keep advancing until we get to desty
lda desty
cmp ypos
bcc decy ; less than
beq skipy
incy:
inc ypos
jmp skipy
decy:
dec ypos
skipy:
; check if equal
lda xpos
cmp destx
bne check_passable
lda ypos
cmp desty
; success!
beq success
check_passable:
; check if floor
jsr is_floor
bne fail
; check increment
inc i
lda i
cmp sight
beq fail
; re-try loop until we get to destination *or* impassable
jmp loop
success:
; remember pos
lda prevx
sta xpos
lda prevy
sta ypos
; success result
lda #0
rts
fail:
; remember pos
lda prevx
sta xpos
lda prevy
sta ypos
; failure result
lda #1
rts
.endproc