-
Notifications
You must be signed in to change notification settings - Fork 0
/
bird.lua
40 lines (30 loc) · 1.2 KB
/
bird.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
-- Definizione modulo
local M = {}
local composer = require( "composer" )
function M.new( parent, x, y )
if not parent then error( "ERROR: Expected display object" ) end
--Inizializza i suoni e la scena
local scene = composer.getScene( composer.getSceneName( "current" ) )
--Carica lo spritesheet
local sheetData = { width = 50, height = 50, numFrames = 8, sheetContentWidth = 200, sheetContentHeight = 100 }
local sheet = graphics.newImageSheet( "birdSheet.png", sheetData )
local sequenceData = {
{ name = "flyToRight", frames = { 1, 2, 3, 4 } , time = 300, loopCount = 0, loopDirection = "bounce" },
{ name = "flyToLeft", frames = { 8, 7, 6, 5 } , time = 300, loopCount = 0, loopDirection = "bounce" },
}
bird = display.newSprite( parent, sheet, sequenceData )
bird.x, bird.y, bird.width,bird.height = x, y, 50, 50
physics.addBody( bird, "dynamic", { radius = 10, density = 1, bounce = 0.1, friction = 1.0 } )
-- Se l'uccello si trova sul bordo sinistro va verso destra, altrimenti verso sinistra
if x==0 then
bird:setSequence( "flyToRight" )
else
bird:setSequence( "flyToLeft" )
end
bird:play()
--Restituisce l'istanza "bird"
bird.name = "bird"
bird.type = "bird"
return bird
end
return M