-
Notifications
You must be signed in to change notification settings - Fork 1
/
command.p8
65 lines (53 loc) · 868 Bytes
/
command.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
pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
-- here's a simple player class:
function player(o)
return {
x=64,
y=64,
on_input=o.on_input,
}
end
function player_draw(p)
rectfill(p.x,p.y,p.x+2,p.y+2)
end
function player_move_left(p)
p.x-=1
end
function player_move_right(p)
p.x+=1
end
-- here are the different input handlers
-- we can pass to our player class:
function player_human(p)
if btn(⬅️) then
player_move_left(p)
end
if btn(➡️) then
player_move_right(p)
end
end
function player_ai(p)
local t=time()%1
if t<0.5 then
player_move_left(p)
else
player_move_right(p)
end
end
-- and here's our game loop:
function _init()
p1=player{
-- play with these:
-- on_input=player_human,
-- on_input=player_ai,
}
end
function _update60()
p1.on_input(p1)
end
function _draw()
cls()
player_draw(p1)
end