forked from tpnk-dev/zarchy-engine-pico8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.lua
85 lines (61 loc) · 2.23 KB
/
game.lua
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
-- these are the object ids in the scene, use return_model with the correct memory position to add new models
OBJS_DATA = {decode_model(0), decode_model(45)}
--COLORS
pal(1, 140, 1)
pal(13, 134,1)
pal(15, 138,1)
function game_init()
init_terrain()
player = {x=0,y=0,z=100}
main_update_draw = draw_update
main_update = logic_update
-- instantiate a sprite3d
create_sprite3d(player.x,player.y, player.z,
nil,nil,nil,
function(sprite) local sx,sy=project_point(sprite.t_x,sprite.t_y,sprite.t_z) circfill(sx, sy, 1, 8) end,
function(sprite) sprite.x,sprite.y,sprite.z = player.x,player.y,player.z end,
function(sprite) end,
nil, nil)
-- instantiate a object3d
create_object3d(2, 0,100, 3,0,0,0,false,false,function(sprite) gravity(sprite, false, 3) end)
end
function logic_update()
if(btn(0))then
player.x -= 6
end
if(btn(1))then
player.x += 6
end
if(btn(2))then
player.z += 6
end
if(btn(3))then
player.z -= 6
end
if(btn(4))then
if(time()&0x0000.1000 == 0) then
add(game_objects3d, create_sprite3d(player.x,player.y,player.z,
nil,nil,nil,
function(sprite) local sx,sy=project_point(sprite.t_x,sprite.t_y,sprite.t_z) circfill(sx, sy, 0, sprite.life_span + 9) end,
function(sprite) gravity(sprite, false, 0.1) end,
function(sprite) srand(time()) sprite.y = player.y + 0.001 sprite.vy = 2 sprite.vx = rnd(2)-1 sprite.vz = rnd(2)-1 end,
10, true))
end
end
player.x = player.x%(terrain_size)
player.z = player.z%(terrain_size)
player.y = t_height_player
cam_x = player.x --+ 50 - 50
cam_z = player.z - CAM_DIST_TERRAIN
cam_y = 50
cam_y = 25 + t_height_player_smooth
-- logic update objects in terrain
update_terrain()
lasttime = time()
end
function draw_update()
-- must call to render terrain + objects
render_terrain()
-- must call to render map
render_gui()
end