-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectile.lua
More file actions
47 lines (29 loc) · 1.09 KB
/
Copy pathprojectile.lua
File metadata and controls
47 lines (29 loc) · 1.09 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
module (..., package.seeall)
local director = require ("director")
local physics = require( "physics" )
local globalLayer
local _H = display.contentHeight
local _W = display.contentWidth
local distance = 60
local bulletSpeed = 10
function new( _newAngle )
globalLayer = display.newGroup()
globalLayer.name = "projectile"
local bulletImage = display.newImage("bullet.png")
globalLayer:insert(bulletImage)
-- center it
bulletImage.x = 0
bulletImage.y = 0
bulletImage:scale(0.8, 0.8)
globalLayer.rotation = _newAngle
globalLayer.x = (_W/2) + math.cos(math.rad(_newAngle)) * distance
globalLayer.y = (_H/2) + math.sin(math.rad(_newAngle)) * distance
physics.addBody(globalLayer, "kinematic", {density=0.1, friction=1.0, bounce=0.5, radius=10, isSensor=true});
local forceX = ((_W/2) + math.cos(math.rad(_newAngle)) * distance) - (_W/2)
local forceY = ((_H/2) + math.sin(math.rad(_newAngle)) * distance) - (_H/2)
globalLayer:setLinearVelocity(forceX*bulletSpeed, forceY*bulletSpeed)
local function explode()
bulletImage.isVisible = false
end
return globalLayer
end