Skip to content

Commit

Permalink
[examples] add some testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryjianjun committed Nov 15, 2014
1 parent ecee7db commit b44a70f
Show file tree
Hide file tree
Showing 26 changed files with 83 additions and 296 deletions.
2 changes: 1 addition & 1 deletion src/include/xconfigs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C" {
#endif

#if !defined(CONFIG_AUTO_BOOT_COMMAND)
#define CONFIG_AUTO_BOOT_COMMAND "exec /romdisk/demos/"
#define CONFIG_AUTO_BOOT_COMMAND "exec /romdisk/examples/"
#endif

#if !defined(CONFIG_MAX_BRIGHTNESS)
Expand Down
50 changes: 0 additions & 50 deletions src/romdisk/demos/graphics/balls/Ball.lua

This file was deleted.

Binary file removed src/romdisk/demos/graphics/balls/ball1.png
Binary file not shown.
Binary file removed src/romdisk/demos/graphics/balls/ball2.png
Binary file not shown.
Binary file removed src/romdisk/demos/graphics/balls/ball3.png
Binary file not shown.
Binary file removed src/romdisk/demos/graphics/balls/ball4.png
Binary file not shown.
Binary file removed src/romdisk/demos/graphics/balls/ball5.png
Binary file not shown.
Binary file removed src/romdisk/demos/scene1.png
Binary file not shown.
95 changes: 0 additions & 95 deletions src/romdisk/demos/scene2.lua

This file was deleted.

Binary file removed src/romdisk/demos/scene2.png
Binary file not shown.
File renamed without changes.
22 changes: 12 additions & 10 deletions src/romdisk/examples/graphics/balls/Ball.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ local M = Class(DisplayObject)
function M:init(image)
self.super:init()

local width, height = application:getScreenSize()
local w, h = application:getScreenSize()
local assets = application:getAssets()

self.maxWidth = width
self.maxHeight = height
self.maxWidth = w
self.maxHeight = h
self.xdirection = 1
self.ydirection = 1
self.xspeed = math.random(40, 100) / 10
self.yspeed = math.random(40, 100) / 10
self.rspeed = math.random(-360, 360) * math.pi / 180 * 2

self:setX(math.random(0, self.maxWidth - 80))
self:setY(math.random(0, self.maxHeight - 80))
self:addChild(assets:loadDisplay(image))
self:setX(math.random(40, self.maxWidth - 40))
self:setY(math.random(40, self.maxHeight - 40))
self:addChild(assets:loadDisplay(image):setAnchor(0.5, 0.5))
self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end

Expand All @@ -26,23 +27,24 @@ function M:onEnterFrame(e)
x = x + (self.xspeed * self.xdirection)
y = y + (self.yspeed * self.ydirection)

if x < 0 then
if x < 40 then
self.xdirection = 1
end

if x > self.maxWidth - 80 then
if x > self.maxWidth - 40 then
self.xdirection = -1
end

if y < 0 then
if y < 40 then
self.ydirection = 1
end

if y > self.maxHeight - 80 then
if y > self.maxHeight - 40 then
self.ydirection = -1
end

self:setPosition(x, y)
self:setRotation(self:getRotation() + self.rspeed)
end

return M
Binary file added src/romdisk/examples/graphics/balls/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ local M = Class(DisplayObject)
function M:init()
self.super:init()

local w, h = application:getScreenSize()
local assets = application:getAssets()

self:addChild(DisplayShape.new(w, h)
:setSource(Pattern.texture(assets:loadTexture("graphics/balls/bg.png")):setExtend(Pattern.EXTEND_REPEAT))
:paint())

self:addChild(Ball.new("graphics/balls/ball1.png"))
self:addChild(Ball.new("graphics/balls/ball2.png"))
self:addChild(Ball.new("graphics/balls/ball3.png"))
Expand Down
8 changes: 0 additions & 8 deletions src/romdisk/examples/graphics/balls/main.lua

This file was deleted.

23 changes: 23 additions & 0 deletions src/romdisk/examples/graphics/cursor/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local M = Class(DisplayObject)

function M:init()
self.super:init()

local w, h = application:getScreenSize()
local assets = application:getAssets()

local w, h = application:getScreenSize()
self:addChild(DisplayShape.new(w, h):setSourceColor(1, 1, 1):paint())

local cursor = assets:loadDisplay("graphics/cursor/cursor.png")
:addEventListener(Event.MOUSE_DOWN, function(d, e) d:setPosition(e.info.x, e.info.y) end)
:addEventListener(Event.MOUSE_MOVE, function(d, e) d:setPosition(e.info.x, e.info.y) end)
:addEventListener(Event.MOUSE_UP, function(d, e) d:setPosition(e.info.x, e.info.y) end)
:addEventListener(Event.TOUCHES_BEGIN, function(d, e) d:setPosition(e.info.x, e.info.y) end)
:addEventListener(Event.TOUCHES_MOVE, function(d, e) d:setPosition(e.info.x, e.info.y) end)
:addEventListener(Event.TOUCHES_END, function(d, e) d:setPosition(e.info.x, e.info.y) end)
:addEventListener(Event.TOUCHES_CANCEL, function(d, e) d:setPosition(e.info.x, e.info.y) end)
self:addChild(cursor)
end

return M
13 changes: 0 additions & 13 deletions src/romdisk/examples/graphics/cursor/main.lua

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ local M = Class(DisplayObject)
function M:init()
self.super:init()

local width, height = application:getScreenSize()
local assets = application:getAssets()
self:addChild(assets:loadDisplay("scene1.png"))
local w, h = application:getScreenSize()
self:addChild(DisplayShape.new(w, h):setSourceColor(0.8, 0.7, 0.5):paint())

for i=1,5 do
for i = 1, 5 do
local shape = DisplayShape.new(100, 50)
:setLineWidth(6)
:rectangle(0, 0, 100, 50)
:setSourceColor(1, 0, 0, 0.5)
:fillPreserve()
:setSourceColor(0, 0, 0)
:stroke()
:setPosition(math.random(0, width - 100), math.random(0, height - 50))
:setPosition(math.random(0, w - 100), math.random(0, h - 50))

shape:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, shape)
shape:addEventListener(Event.MOUSE_MOVE, self.onMouseMove, shape)
Expand Down
86 changes: 0 additions & 86 deletions src/romdisk/examples/graphics/dragme/main.lua

This file was deleted.

Loading

0 comments on commit b44a70f

Please sign in to comment.