-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_World.spin
175 lines (138 loc) · 3.81 KB
/
03_World.spin
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
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
#0, UP, RIGHT, DOWN, LEFT
OBJ
lcd : "LameLCD"
gfx : "LameGFX"
map : "LameMap"
ctrl : "LameControl"
fn : "LameFunctions"
state : "PikeState"
player : "gfx_nash"
DAT
playerx long 0
playery long 0
xoffset long 0
yoffset long 0
targetx long 0
targety long 0
moving byte 0
frame byte 0
dir byte DOWN
count byte 0
OBJ
map_parrot_town : "map_parrot_town"
map_path1 : "map_path1"
map_path2 : "map_path2"
tilemap : "gfx_pikeman"
CON
WORLD_W = 1
WORLD_H = 3
DAT
currentmap word 0
worldmap word 0[9]
worldx word 0
worldy word 2
mapchanged word 0
PUB Main
lcd.Start(gfx.Start)
ctrl.Start
Init
repeat
View
PUB Init
playerx := targetx := 3<<3
playery := targety := 4<<3
worldmap[0] := map_path2.Addr
worldmap[1] := map_path1.Addr
worldmap[2] := map_parrot_town.Addr
mapchanged := 1
PUB View
repeat
ctrl.Update
gfx.ClearScreen(0)
HandlePlayer
ControlMap
ControlOffset
map.Draw(xoffset, yoffset)
DrawPlayer
fn.Sleep(30)
if playerx >> 3 > 10
'playerx := targetx := 3 << 3
return state.SetState(state#_BATTLE)
lcd.DrawScreen
PUB HandlePlayer | adjust
if not moving
moving := 1
if targetx > playerx
playerx++
elseif targetx < playerx
playerx--
elseif targety > playery
playery++
elseif targety < playery
playery--
else
if ctrl.Left
dir := LEFT
if not map.TestPoint((playerx>>3)-1, playery>>3)
targetx -= 8
elseif ctrl.Right
dir := RIGHT
if not map.TestPoint((playerx>>3)+1, playery>>3)
targetx += 8
elseif ctrl.Up
dir := UP
if not map.TestPoint(playerx>>3, (playery>>3)-1)
targety -= 8
elseif ctrl.Down
dir := DOWN
if not map.TestPoint(playerx>>3, (playery>>3)+1)
targety += 8
else
moving := 0
if moving
count++
if count & $3 == 0
case (count >> 2) & $1
0: frame := 1
1: frame := 2
else
frame := 0
'count := 0
PUB DrawPlayer
gfx.Sprite(player.Addr,(playerx)-xoffset,(playery)-yoffset, dir*3+frame)
PUB ControlMap
if not moving
if playerx < 0
if worldx > 0
worldx--
playerx := targetx := (map.GetWidth-1)<<3
if playerx > (map.GetWidth-1)<<3
if worldx < WORLD_W-1
worldx++
playerx := targetx := 0
if playery < 0
if worldy > 0
worldy--
playery := targety := (map.GetHeight-1)<<3
if playery > (map.GetHeight-1)<<3
if worldy < WORLD_H-1
worldy++
playery := targety := 0
if mapchanged
map.Load(tilemap.Addr, worldmap[WORLD_W*worldx + worldy])
PUB ControlOffset | bound_x, bound_y
bound_x := map.GetWidth<<3 - lcd#SCREEN_W
bound_y := map.GetHeight<<3 - lcd#SCREEN_H
xoffset := playerx + (word[player.Addr][1]>>1) - (lcd#SCREEN_W>>1)
if xoffset < 0
xoffset := 0
elseif xoffset > bound_x
xoffset := bound_x
yoffset := playery + (word[player.Addr][2]>>1) - (lcd#SCREEN_H>>1)
if yoffset < 0
yoffset := 0
elseif yoffset > bound_y
yoffset := bound_y