-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
67 lines (56 loc) · 2.23 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
--
-- Abstract: tce Library Plugin Test Project
--
-- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license
-- Copyright (C) 2015 Corona Labs Inc. All Rights Reserved.
--
------------------------------------------------------------
-- Load plugin library
local tiledCollisionEditor = require "plugin.tce"
local physics = require "physics"
local json = require "json"
-------------------------------------------------------------------------------
-- BEGIN (Insert your sample test starting here)
-------------------------------------------------------------------------------
physics.setDrawMode( "hybrid" )
physics.start()
physics.setPositionIterations( 6 )
physics.setVelocityIterations( 16 )
local _CX = display.contentCenterX
local _CY = display.contentCenterY
local fullw = display.actualContentWidth
local fullh = display.actualContentHeight
local _L = _CX - fullw * 0.5
local _R = _CX + fullw * 0.5
local _T = _CY - fullh * 0.5
local _B = _CY + fullh * 0.5
-- Get physical data
local physicalData = tiledCollisionEditor.getPhysicalData( "maps.map" )
-- Create heart image
local heart = display.newImage( "maps/heart.png", 150, 300 )
local options =
{
width = 192,
height = 256,
numFrames = 25
}
-- Create image sheet
local sheet = graphics.newImageSheet( "maps/sprites.png", options )
-- Create hero sprite
local hero = display.newImage( sheet, 1, 250, 100 )
-- Create borders
local topWall = display.newRect( _CX, _T, _R - _L, 10 )
local leftWall = display.newRect( _L, _CY, 10, _B - _L )
local rightWall = display.newRect( _R, _CY, 10, _B - _L )
local bottomWall = display.newRect( _CX, _B, _R - _L, 10 )
physics.addBody( heart, "dynamic", unpack( physicalData.images["heart.png"] ) )
physics.addBody( hero, "dynamic", unpack( physicalData.sprites[0] ) )
physics.addBody( topWall, "static" )
physics.addBody( leftWall, "static" )
physics.addBody( rightWall, "static" )
physics.addBody( bottomWall, "static" )
-- Print physical data
print( json.prettify( physicalData ) )
-------------------------------------------------------------------------------
-- END
-------------------------------------------------------------------------------