Skip to content

Commit 6961ed0

Browse files
committed
Initial commite of jni, res, and assets files from development directory.
1 parent c5d963c commit 6961ed0

File tree

476 files changed

+155631
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

476 files changed

+155631
-0
lines changed

assets/Breakout/Ball.lua

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module(..., package.seeall);
2+
3+
require('Wall');
4+
5+
DT = 0.001;
6+
7+
local mt = getfenv();
8+
mt.__index = mt;
9+
10+
function new()
11+
local obj = {};
12+
13+
obj.x = Wall.WIDTH/2;
14+
obj.y = Wall.HEIGHT - 3;
15+
obj.vx = 80;
16+
obj.vy = -80;
17+
18+
setmetatable(obj, mt);
19+
return obj;
20+
end
21+
22+
function draw(self, p)
23+
p:setColor(Painter.WHITE);
24+
p:ball(self.x, self.y);
25+
end
26+
27+
function tick(self, f)
28+
local x = f.x;
29+
local y = f.y;
30+
local LIM = .2;
31+
if (x > LIM) then x = LIM; end
32+
if (x < -LIM) then x = -LIM; end
33+
if (y > LIM) then y = LIM; end
34+
if (y < -LIM) then y = -LIM; end
35+
36+
self.vx = self.vx + 20*x;
37+
self.vy = self.vy + 20*y;
38+
self.x = self.x + DT*self.vx;
39+
self.y = self.y + DT*self.vy;
40+
end
41+
42+

assets/Breakout/Brick.lua

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
module(..., package.seeall);
2+
3+
WIDTH = 20;
4+
HEIGHT = 8;
5+
6+
local mt = getfenv();
7+
mt.__index = mt;
8+
9+
function new(col, row)
10+
local obj = {};
11+
12+
obj.col = col;
13+
obj.row = row;
14+
obj.countDownTimer = -1;
15+
16+
setmetatable(obj, mt);
17+
return obj;
18+
end
19+
20+
function draw(self, p)
21+
local iColor;
22+
if (self.countDownTimer == -1) then
23+
iColor = (math.floor(self.row/2) % Painter.nColor) + 1;
24+
p:setColor(iColor);
25+
p:bar(self.col*WIDTH+1, self.row*HEIGHT+1,
26+
(self.col+1)*WIDTH-1, (self.row+1)*HEIGHT-1);
27+
elseif (self.countDownTimer ~= 0) then
28+
iColor = (math.floor(self.countDownTimer/10) % Painter.nColor) + 1;
29+
p.setColor(iColor);
30+
p:bar(self.col*WIDTH+1, self.row*HEIGHT+1,
31+
(self.col+1)*WIDTH-1, (self.row+1)*HEIGHT-1);
32+
end
33+
end
34+
35+
function tick(self, ball)
36+
local f = {x=0, y=0};
37+
if (self.countDownTimer == 0) then
38+
return f;
39+
end
40+
if (self.countDownTimer > 0) then
41+
self.countDownTimer = self.countDownTimer - 1;
42+
end
43+
44+
local f1 = (ball.y - self.row * HEIGHT) * WIDTH -
45+
(ball.x - self.col * WIDTH) * HEIGHT;
46+
local f2 = (ball.y - self.row * HEIGHT - HEIGHT) * WIDTH +
47+
(ball.x - self.col * WIDTH) * HEIGHT;
48+
local d = (f1 < 0);
49+
local u = (f2 < 0);
50+
if (d and u) then -- top
51+
if (self.row * HEIGHT - ball.y - 1 < 0) then
52+
f.y = f.y + self.row * HEIGHT - ball.y - 1;
53+
end
54+
elseif (d and not u) then -- right
55+
if (self.col * WIDTH + WIDTH - ball.x + 1 > 0) then
56+
f.x = f.x + self.col * WIDTH + WIDTH - ball.x + 1;
57+
end
58+
elseif (not d and u) then -- left
59+
if (self.col *WIDTH - ball.x - 1 < 0) then
60+
f.y = f.y + self.col * WIDTH - ball.x - 1;
61+
end
62+
else -- bottom
63+
if (self.row *HEIGHT + HEIGHT - ball.y + 1 > 0) then
64+
f.y = self.row * HEIGHT + HEIGHT - ball.y + 1;
65+
end
66+
end
67+
68+
return f;
69+
end
70+
71+
function destroy(self)
72+
if (self.countDownTimer == -1) then
73+
self.countDownTimer = 60;
74+
end
75+
end

assets/Breakout/Game.lua

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module(..., package.seeall);
2+
3+
require('Wall');
4+
require('Ball');
5+
require('Paddle');
6+
7+
8+
local mt = getfenv();
9+
mt.__index = mt;
10+
11+
function new()
12+
local obj = {};
13+
14+
obj.wall = Wall.new();
15+
obj.ball = Ball.new();
16+
obj.paddle = Paddle.new();
17+
18+
setmetatable(obj, mt);
19+
return obj;
20+
end
21+
22+
function draw(self, p)
23+
self.wall:draw(p);
24+
self.ball:draw(p);
25+
self.paddle:draw(p);
26+
end
27+
28+
function setX(self, x)
29+
self.paddle:setX(x);
30+
end
31+
32+
function tick(self)
33+
f = self.wall:tick(self.ball);
34+
fpaddle = self.paddle:tick(self.ball);
35+
f.x = f.x + fpaddle.x;
36+
f.y = f.y + fpaddle.y;
37+
38+
self.ball:tick(f);
39+
if (self.ball.y > Wall.HEIGHT) then
40+
self.ball = Ball.new();
41+
end
42+
end

assets/Breakout/Paddle.lua

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module(..., package.seeall);
2+
3+
require('Wall');
4+
require('Painter');
5+
6+
WIDTH = 32;
7+
8+
local mt = getfenv();
9+
mt.__index = mt;
10+
11+
function new()
12+
local obj = {};
13+
14+
obj.x = Wall.WIDTH/2;
15+
16+
setmetatable(obj, mt);
17+
return obj;
18+
end
19+
20+
function draw(self, p)
21+
p:setColor(Painter.ORANGE);
22+
p:bar(self.x - WIDTH/2, Wall.HEIGHT - 2,
23+
self.x + WIDTH/2, Wall.HEIGHT);
24+
end
25+
26+
function tick(self, ball)
27+
local f = {x=0, y=0};
28+
local s = ball.x - self.x + WIDTH/2;
29+
if ((s >= 0) and (s < WIDTH)
30+
and (Wall.HEIGHT - 3 - ball.y < 0)) then
31+
f.x = (Wall.HEIGHT-3-ball.y)*(self.x-ball.x)/WIDTH;
32+
f.y = Wall.HEIGHT-3-ball.y;
33+
end
34+
35+
return f;
36+
end
37+
38+
function setX(self, x)
39+
self.x = x;
40+
end

assets/Breakout/Painter.lua

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
module(..., package.seeall);
2+
3+
require('gles1');
4+
require('carray');
5+
6+
RED = 'red';
7+
ORANGE = 'orange';
8+
YELLOW = 'yellow';
9+
GREEN = 'green';
10+
WHITE = 'white';
11+
BLACK = 'black';
12+
13+
local mt = getfenv();
14+
mt.__index = mt;
15+
16+
function new()
17+
local obj = {};
18+
setmetatable(obj, mt);
19+
return obj;
20+
end
21+
22+
23+
local v8 = carray.new("float",
24+
{0, 0,
25+
1, 0,
26+
0, 1,
27+
1, 1});
28+
29+
function bar(self, x1, y1, x2, y2)
30+
--[[
31+
local v = carray.new("float",
32+
{x1, y1,
33+
x2, y1,
34+
x1, y2,
35+
x2, y2});
36+
--]]
37+
v8[1] = x1; v8[2] = y1;
38+
v8[3] = x2; v8[4] = y1;
39+
v8[5] = x1; v8[6] = y2;
40+
v8[7] = x2; v8[8] = y2;
41+
gl.EnableClientState(gl.VERTEX_ARRAY);
42+
gl.VertexPointer(2, gl.FLOAT, 0, carray.pointer(v8));
43+
gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4);
44+
gl.DisableClientState(gl.VERTEX_ARRAY);
45+
end
46+
47+
function ball(self, x, y)
48+
--[[
49+
local v = carray.new("float",
50+
{x+3, y,
51+
x, y+3,
52+
x-3, y,
53+
x, y-3});
54+
--]]
55+
v8[1] = x+3; v8[2] = y;
56+
v8[3] = x; v8[4] = y+3;
57+
v8[5] = x-3; v8[6] = y;
58+
v8[7] = x; v8[8] = y-3;
59+
gl.EnableClientState(gl.VERTEX_ARRAY);
60+
gl.VertexPointer(2, gl.FLOAT, 0, carray.pointer(v8));
61+
gl.DrawArrays(gl.TRIANGLE_FAN, 0, 4);
62+
gl.DisableClientState(gl.VERTEX_ARRAY);
63+
end
64+
65+
colorNames = {"yellow", "green", "orange", "red", "white", "black"};
66+
colorTable = {{1,1,0},
67+
{0,1,0},
68+
{1,0.5,0},
69+
{1,0,0},
70+
{1,1,1},
71+
{0,0,0}};
72+
do
73+
local n = 0;
74+
local i;
75+
for i = 1,#colorNames do
76+
colorTable[colorNames[i]] = colorTable[i];
77+
end
78+
end
79+
nColor = #colorTable;
80+
81+
function setColor(self, name)
82+
c = colorTable[name];
83+
if (c) then
84+
gl.Color4f(c[1], c[2], c[3], 1);
85+
end
86+
end

assets/Breakout/Wall.lua

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
module(..., package.seeall);
2+
3+
require('Brick');
4+
5+
EXPAND = 1;
6+
ROWS_COUNT = 16 * EXPAND;
7+
COLS_COUNT = 8*3 * EXPAND;
8+
9+
10+
WIDTH = ROWS_COUNT * Brick.WIDTH;
11+
HEIGHT = COLS_COUNT * Brick.HEIGHT;
12+
13+
local mt = getfenv();
14+
mt.__index = mt;
15+
16+
function new()
17+
local obj = {};
18+
19+
obj.bricks = {};
20+
local row, col;
21+
for row = 0,ROWS_COUNT/3 do
22+
for col = 0,COLS_COUNT-1 do
23+
obj.bricks[#obj.bricks + 1] = Brick.new(col, row);
24+
end
25+
end
26+
27+
setmetatable(obj, mt);
28+
return obj;
29+
end
30+
31+
function draw(self, p)
32+
local i;
33+
for i = 1,#self.bricks do
34+
self.bricks[i]:draw(p);
35+
end
36+
end
37+
38+
function tick(self, ball)
39+
f = {x=0, y=0};
40+
if (ball.x < 1) then
41+
f.x = f.x + (1 - ball.x);
42+
end
43+
if (ball.x > WIDTH - 1) then
44+
f.x = f.x + (WIDTH - 1 - ball.x);
45+
end
46+
if (ball.y < 1) then
47+
f.y = f.y + (1 - ball.y);
48+
end
49+
50+
local i;
51+
for i = 1,#self.bricks do
52+
local fbrick = self.bricks[i]:tick(ball);
53+
f.x = f.x + fbrick.x;
54+
f.y = f.y + fbrick.y;
55+
if ((fbrick.x ~= 0) or (fbrick.y ~= 0)) then
56+
self.bricks[i]:destroy();
57+
end
58+
end
59+
60+
return f;
61+
end

0 commit comments

Comments
 (0)