forked from ar2rsawseen/GiderosCodingEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
119 lines (98 loc) · 3.01 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
110
111
112
113
114
115
116
117
118
119
require "box2d"
--some initial settings
application:setBackgroundColor("yellow")
:setFps(60)
:setKeepAwake(true)
:enableFiltering()
local font = TTFont.new("tahoma.ttf", 70)
local text = TextField.new(font, "Some text")
--positioning
:setPosition("center", "center")
:setPosition(300,250)
--named colors
:setTextColor("white")
:setAnchorPoint(0.5, 0.5)
:setRotation(45)
:setShadow(3, 3, "gray", 0.5)
:setSkew(60)
local sound = Sound.new("main.mp3")
sound:play(0, true)
local test = Shape.new()
:setFillStyle(Shape.SOLID, "white")
:drawRoundRectangle(90, 90, 10)
:setPosition(100, 100)
:setAnchorPoint(0.5)
:setRotation(45)
:setSkewX(45)
local bitmap = Bitmap.new("crate.png")
:setPosition("center","top")
:setAnchorPoint(0.5)
local bitmap = Shape.new()
:setFillStyle(Shape.SOLID, "red")
:drawRectangle(100,100)
:setAnchorPoint(0.5)
:setAbsolutePosition("right", "bottom")
:setPosition("center","bottom")
local shape = Shape.new()
--named colors
:setFillStyle(Shape.SOLID, "red")
--drawing primitive shape
--:drawRect(100, 100)
:drawCircle(100, 100, 100)
--positioning
:setY("center")
:setX("center")
--touch works also on desktop players
:addEventListener(Event.TOUCHES_BEGIN, function(e)
--recursive print for table
print_r(e.touch)
end)
-- box2d examples
local world = b2.World.new(0, 10, true)
--place image on screen
local crate = Bitmap.new("crate.png", true)
:setPosition("center", "center")
--create rectangle based on image
world:createRectangle(crate, {type = "dynamic"})
--world:createRoundRectangle(test, 90, 90, 10, {type = "dynamic", draggable = true})
--place image on screen
local ball = Bitmap.new("ball.png", true)
:setPosition("left", "center")
--create circle based on image
world:createCircle(ball, {type = "dynamic", draggable = true})
--we can move physical object by moving our sprite
ball:setPosition(400, 100)
--local collisions
world:addBeginContact(ball, crate, function()
print("contact started")
end)
:addEndContact(ball, crate, function()
print("contact ended")
end)
--create terrain so objects won't fall of the screen
:createTerrain(nil, {0,0,
application:getContentWidth(),0,
application:getContentWidth(), application:getContentHeight(),
0, application:getContentHeight(),
0,0})
stage:addChild(text)
:addChild(shape)
:addChild(bitmap)
:addChild(test)
:addChild(crate)
:addChild(ball)
--debugging world
:addChild(world:getDebug())
--updating world
:addEventListener(Event.ENTER_FRAME, function()
world:update()
end)
--controlling z-index
text:bringToFront()
-- How to use
local value = 10
crate:set("linearVelocityX", -value)
GTween.new(crate, .8, {linearVelocityX = crate:get("linearVelocityX") + value * 2}, {reflect = true, setLoop = true, repeatCount = 0})
GTween.new(ball, 0.8, {scaleBody = crate:get("scaleBody") + 0.5}, {reflect = true, setLoop = true, repeatCount = 0})
GTween.new(shape, 0.8, {anchorX = 1, anchorY = 1, rotation = 360}, {reflect = true, setLoop = true, repeatCount = 0})
GTween.new(test, 2, {rotation = 720})