-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel1.lua
More file actions
94 lines (58 loc) · 1.45 KB
/
level1.lua
File metadata and controls
94 lines (58 loc) · 1.45 KB
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
module (..., package.seeall)
local director = require ("director")
local physics = require( "physics" )
local globalLayer
local gameLayer
-- external modules
local cannon = require("cannon")
local cannonInstance
local enemy = require("enemy")
local gamestate = require("gamestate")
local _H = display.contentHeight
local _W = display.contentWidth
_G.firstTouch = true
function touchListener(event)
if not _G.firstTouch then
if not _G.gameEnded then
if event.phase == "began" then
cannon.setRotation(event.x, event.y)
cannon.startShooting()
else
if event.phase == "moved" then
cannon.setRotation(event.x, event.y)
else
if event.phase == "ended" then
cannon.stopShooting()
end
end
end
end
else
_G.firstTouch = false
end
end
function init()
--physics.setDrawMode( "hybrid" )
physics.start()
physics.setGravity( 0, 0 )
globalLayer = display.newGroup()
gameLayer = display.newGroup()
globalLayer:insert(gameLayer)
globalLayer:insert(gamestate.new())
end
function setupBackground()
local background = display.newImage("background.png")
gameLayer:insert(background)
background.x = _W/2
background.y = _H/2
background:scale(1.5, 1.5)
end
function new()
init()
setupBackground()
cannonInstance = cannon.new()
gameLayer:insert(cannonInstance)
gamestate.startSpawningEnemies()
Runtime:addEventListener( "touch", touchListener )
return globalLayer
end