Engine 0.0.4
Game engine in lua
Loading...
Searching...
No Matches
draw_poly.lua
Go to the documentation of this file.
1local function decorator_poo(object, func)
2 if not object or not func then return func end
3 return function(a, b, c, d)
4 return func(object, a, b, c, d)
5 end
6end
7
8local function decorator_line(func_draw_line)
9 return function(mode, verts)
10 local index = 4
11 while index <= #verts do
12 func_draw_line(verts[index - 3], verts[index - 2], verts[index - 1], verts[index])
13 index = index + 2
14 end
15 end
16end
17
18local function decorator_poly(func_draw_poly, std, modes, repeats)
19 return function (engine_mode, verts, x, y, scale, angle, ox, oy)
20 if #verts < 6 or #verts % 2 ~= 0 then return end
21 local mode = modes and modes[engine_mode + 1] or engine_mode
22 local rotated = std.math.cos and angle and angle ~= 0
23 ox = ox or 0
24 oy = oy or ox or 0
25
26 if repeats and repeats[engine_mode + 1] then
27 verts[#verts + 1] = verts[1]
28 verts[#verts + 1] = verts[2]
29 end
30
31 if x and y and not rotated then
32 local index = 1
33 local verts2 = {}
34 scale = scale or 1
35
36 while index <= #verts do
37 if index % 2 ~= 0 then
38 verts2[index] = x + (verts[index] * scale)
39 else
40 verts2[index] = y + (verts[index] * scale)
41 end
42 index = index + 1
43 end
44 func_draw_poly(mode, verts2)
45 elseif x and y then
46 local index = 1
47 local verts2 = {}
48 while index < #verts do
49 local px = verts[index]
50 local py = verts[index + 1]
51 local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle))
52 local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle))
53 verts2[index] = xx
54 verts2[index + 1] = yy
55 index = index + 2
56 end
57 func_draw_poly(mode, verts2)
58 else
59 func_draw_poly(mode, verts)
60 end
61 end
62end
63
64local function install(std, game, application, config)
65 local draw_line = decorator_poo(config.object, config.line)
66 local draw_poly = decorator_poo(config.object, config.poly) or decorator_line(draw_line)
67 std = std or {}
68 std.draw = std.draw or {}
69 std.draw.poly = config.poly2 or decorator_poly(draw_poly, std, config.modes, config.repeats)
70 return {poly=std.draw.poly}
71end
72
73local P = {
75}
76
77return P
local function decorator_poly(func_draw_poly, std, modes, repeats)
local function decorator_poo(object, func)
local function install(std, game, application, config)
local function decorator_line(func_draw_line)
local application
Definition main.lua:16
local game
Definition main.lua:17
local std
Definition main.lua:18