-
Notifications
You must be signed in to change notification settings - Fork 0
/
anotherRover.lua
54 lines (43 loc) · 1.76 KB
/
anotherRover.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
-----------------------------------------------------------------------------------------
--
-- anotherRover.lua
--
-- Another failed attempt at a rover game
-----------------------------------------------------------------------------------------
-- Get local reference to the game globals
local game = globalGame
-- Create the act object
local act = game.newAct()
local json = require( "json" )
------------------------- Start of Activity --------------------------------
-- Init the act
function act:init()
-- Remember to put all display objects in act.group
-- loads data from media/anotherRover/level1.txt
-- ALL SHAPES MUST HAVE THE X and Y Coordinates filped, and x needs to be subracted from act.lua
-- while drawing because of the orientation change
local level = system.pathForFile( "media/anotherRover/level1.txt", system.ResourceDirectory )
local objs = json.decodeFile( level )
-- loops through the loaded level and draws the objects
for i = 1, #objs do
local obj = objs[i]
if obj.shape == "square" then
display.newRect( act.group, act.width - obj.y, obj.x, 50, 50 )
elseif obj.shape == "upRamp" then
local vertices = {25, 25, -60, 25, 25, -25}
local t = display.newPolygon( act.group, act.width - obj.y, obj.x, vertices )
t.rotation = 90
elseif obj.shape == "downRamp" then
local vertices = {-25, -25, 60, 25, -25, 25}
local t = display.newPolygon( act.group, act.width - obj.y, obj.x, vertices )
t.rotation = 90
elseif obj.shape == "circle" then
display.newCircle( act.group, act.width - obj.y, obj.x, 20 )
else
print( "idk how to draw: " .. obj.shape )
end
end
end
------------------------- End of Activity --------------------------------
-- Corona needs the scene object returned from the act file
return act.scene