| 1 | require 'dokidoki.module' [[]] |
| 2 | |
| 3 | import(require 'gl') |
| 4 | import(require 'glu') |
| 5 | import(require 'dokidoki.base') |
| 6 | |
| 7 | local actor_scene = require 'dokidoki.actor_scene' |
| 8 | local kernel = require 'dokidoki.kernel' |
| 9 | local v2 = require 'dokidoki.v2' |
| 10 | |
| 11 | local function make_spinner(period) |
| 12 | local rotation = 0 |
| 13 | |
| 14 | self = { |
| 15 | pos = v2(320, 240), |
| 16 | update = function () |
| 17 | rotation = rotation + 360 / period / 60 |
| 18 | end, |
| 19 | draw = function () |
| 20 | glRotated(rotation, 0, 0, 1) |
| 21 | glScaled(100, 100, 100) |
| 22 | glColor3d(0.5, 0.25, 1) |
| 23 | glBegin(GL_QUADS) |
| 24 | glVertex2d(-1, -1) |
| 25 | glVertex2d( 1, -1) |
| 26 | glVertex2d( 1, 1) |
| 27 | glVertex2d(-1, 1) |
| 28 | glEnd() |
| 29 | end |
| 30 | } |
| 31 | |
| 32 | return self |
| 33 | end |
| 34 | |
| 35 | function init (game) |
| 36 | game.add_actor{ |
| 37 | draw_setup = function () |
| 38 | glClearColor(0, 0, 0.25, 0) |
| 39 | glClear(GL_COLOR_BUFFER_BIT) |
| 40 | glMatrixMode(GL_PROJECTION) |
| 41 | glLoadIdentity() |
| 42 | glOrtho(0, 640, 0, 480, 1, -1) |
| 43 | glMatrixMode(GL_MODELVIEW) |
| 44 | glLoadIdentity() |
| 45 | end |
| 46 | } |
| 47 | |
| 48 | game.add_actor(make_spinner(4)) |
| 49 | end |
| 50 | |
| 51 | kernel.start_main_loop(actor_scene.make_actor_scene( |
| 52 | {"update"}, |
| 53 | {"draw_setup", "draw"}, |
| 54 | init)) |
| 55 |