forked from rik-cross/pico-8-adventure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
part3-ecs.p8
106 lines (94 loc) · 5.74 KB
/
part3-ecs.p8
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
pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
-- a table comtaining all game entities
entities = {}
-- creates and returns a new position
function newposition(x,y,w,h)
local p = {}
p.x = x
p.y = y
p.w = w
p.h = h
return p
end
-- creates and returns a new sprite
function newsprite(x,y)
local s = {}
s.x = x
s.y = y
return s
end
-- creates and returns a new entity
function newentity(position,sprite)
local e = {}
e.position = position
e.sprite = sprite
add(entities,e)
return e
end
gs = {}
gs.update = function()
cls()
--centre camera on player
camera(-64+player.position.x+(player.position.w/2),
-64+player.position.y+(player.position.h/2))
map()
-- draw all entities with sprites and positions
for ent in all(entities) do
if ent.sprite ~= nil and ent.position ~= nil then
sspr(player.sprite.x, player.sprite.y,
player.position.w, player.position.h,
player.position.x, player.position.y)
end
end
camera()
--crosshair sprite
--spr(16,64-4,64-4)
end
function _init()
-- create a player entity
player = newentity(
-- create a position component
newposition(10,10,8,8),
-- create a sprite component
newsprite(8,0)
)
end
function _update()
--check player movement
if btn(0) then player.position.x-=1 end
if btn(1) then player.position.x+=1 end
if btn(2) then player.position.y-=1 end
if btn(3) then player.position.y+=1 end
end
function _draw()
gs.update()
end
__gfx__
0000000000aaaa005555555533333333cccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000aaaaaa05555555533333333cccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700aa5aa5aa5555555533333333cccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000aaaaaaaa5555555533333333cccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000aaaaaaaa5555555533333333cccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700aa5555aa5555555533333333cccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000aaaaaa05555555533333333cccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000aaaa005555555533333333cccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00088000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00088000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
88000088000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
88000088000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00088000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00088000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__map__
0202020202020202020202020202020200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0202020203030303030303030303020200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0202020203030303030304040403020200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0202020203030303030303040403020200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0202020203030303030303030403020200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0202020203030303030303030403020200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0202020203030303030303030303020200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0202020202020202020202020202020200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0202020202020202020202020202020200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000