First commit of LuaGame with an OpenGL backend.
[luagame.git] / demos / shine_on / scripts / main.lua
blob5caac34d18492a86006171e1486c38b3f5b954f8
1 --[[
2 This script is the main script. It requires the code.lua file,
3 which is where one really wants to do work.
4 --]]
6 --global vars
7 done = false --used for the main game loop
8 ticks = 0 --clock ticks (frames since start of level)
10 --turn cursor off
11 show_cursor(false)
12 instr_log("cursor off", "input")
14 --initialize the event manager
15 -- set up ESC key exit default
16 evman = EventManager:new()
17 evman.keyboard.pressed[Keys.ESCAPE] = function() done = true end
18 evman.quit = function() done = true end
19 instr_log("created evman", "input", "gameplay")
21 --require the code
22 require("scripts/code")
23 instr_log("included real code", "gameplay")
25 --fps stuff
26 fps = FPSManager:new()
27 fps:set_fps(target_fps)
28 instr_log("set fps","gameplay","video")
30 --random number generator stuff
31 -- reseeds the random number generator periodically
33 local c = 0
34 function rrand()
35 if c == target_fps*100 then
36 c = 0
37 math.randomseed(os.time())
38 end
39 c = c + 1
40 end
41 end
43 rrand()
45 titlescreen = get_image("images/title.png")
46 instr_log("+title screen", "event")
47 title = true
48 instr_log("random classless event")
49 --title screen loop
50 while done ~= true do
51 evman:gather_events()
52 blit(titlescreen,0,0,0,1,1)
54 if title == false then
55 done = true
56 end
57 --redraw screen
58 update_screen()
60 --update clock ticks
61 ticks = ticks + 1
63 --delay to maintain proper fps
64 fps:update()
65 end
66 instr_log("-title screen", "event")
67 done = false
68 instr_log("+main loop", "event", "gameplay")
69 --main game loop
70 while done ~= true do
71 rrand()
73 --process events
74 evman:gather_events()
76 --calc collisions
77 global_collide()
79 --update everything
80 global_update()
82 --draw everything
83 global_draw()
85 --redraw screen
86 update_screen()
88 --update clock ticks
89 ticks = ticks + 1
91 --delay to maintain proper fps
92 fps:update()
94 end
95 instr_log("-main loop", "event", "gameplay")
96 instr_stats()
97 instr_print_log("event")
98 instr_print_log("gameplay")
99 instr_print_log("input")
100 instr_print_log("input","gameplay")
101 instr_print_log()