forked from ecker00/Hug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
111 lines (81 loc) · 2.62 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
print("#############################################")
-- Detected_ Löve2D
if love then
love.graphics.setMode( 960, 640 )
require("wrapper.hug")
-- Detected: CoronaSDK
else
display.setStatusBar(display.HiddenStatusBar)
physics = require( "physics" )
end
------------------------------------------------
-- Testing scene
------------------------------------------------
-- Start physics
physics.start()
-- Blue background
local bg = display.newRect(0, 0, display.contentWidth, display.contentHeight)
bg:setFillColor( 50, 90, 120 )
-- Display image: Logo top left
local dot = display.newImage( "images/ball.png", 0, 0 )
dot:setReferencePoint( display.TopLeftReferencePoint )
dot:setFillColor( 100, 255, 230 )
dot:scale( 0.5, 0.5 )
dot.x = 15
dot.y = 15
-- Sprite animation: Animated logo
local data = require('images.hug_ani')
local sheet = graphics.newImageSheet( 'images/hug_ani.png', data:getSheet() )
local logoAni = display.newSprite( sheet, data:getSequenceData() )
logoAni:setSequence('hug_animation')
logoAni:setReferencePoint( display.TopLeftReferencePoint )
logoAni:translate( logoAni.contentWidth+2, logoAni.contentHeight*0.5+1 )
logoAni:scale( 0.5, 0.5 )
logoAni.isVisible = false
logoAni.timeScale = 2
-- Time delay: show and play animation
timer.performWithDelay( 2000, function()
logoAni.isVisible = true
logoAni:play()
end)
-- Setup world group
local world = display.newGroup()
-- Create floor
local floor = display.newRect( world, display.contentWidth*0.25, display.contentHeight*0.75, display.contentWidth*0.5, display.contentHeight*0.15 )
physics.addBody( floor, "static" )
floor:setFillColor( 160, 220, 235 )
floor.id = 'floor'
-- Add physics ball
local function ballLoop()
-- Create ball from regular image
local ball = display.newImage( world, "images/ball.png", 0, 0 )
ball:setFillColor( math.random(128, 255), math.random(128, 255), math.random(128, 255) )
ball.x = display.contentWidth*0.5
ball:scale( 0.5, 0.5 )
ball.id = 'ball'
-- Physics body
local polygonSheet = require('images.ball')
local polygonData = polygonSheet.physicsData( 0.5 )
physics.addBody( ball, "dynamic" , polygonData:get('ball') )
-- Add new ball
timer.performWithDelay( 1000, ballLoop )
end
ballLoop()
-- Frame update
local function update()
-- Remove balls falling off
local r = 0
for i = 1, world.numChildren do
local child = world[i-r]
if child.id == 'ball' then
if child.y > display.contentHeight*0.9 then
child:removeSelf()
r=r+1
end
end
end
-- Move floor
floor.y = math.sin( system.getTimer()*0.002 ) * 50 + display.contentHeight*0.75
end
-- Runtime enter frame
Runtime:addEventListener("enterFrame", update)