Hi friends i am new to corona and making a simple balloon burst game but having some errors can you guys please help me I want to make an arrow in bottom left corner of screen and from the bottom right corner balloons are rising i want to hit that balloons from arrow to burst and increase score please help…
The code of arrow is below
local physics=require (“physics”)
physics.start()
force_multiplier=10;
local shot=audio.loadSound(“media/shot.mp3”);
local arrow= display.newImage(“arrow.png”);
arrow.x=60; arrow.y=400;
arrow.xScale=0.5; arrow.yScale=0.5;
function newarrow()
arrow.type=“arrow”;
–Set up properties
physics.addBody(arrow, “kinematic”, {density=0.2, friction=0.2, bounce=0.5, radius=20})
arrow.linearDamping=0.3;
arrow.angularDamping=0.8;
arrow.isarrow=true
arrow.isSensor=true;
function arrow:touch(e)
local t=e.target
if(e.phase==“began”) then
display.getCurrentStage():setFocus(t)
self.isFocus=true
self.bodyType=“kinematic”;
–Stop current motion
self:setLinearVelocity(0,0)
self.angularVelocity=0
myLine=nil
elseif(self.isFocus) then
if(e.phase==“moved”) then
if(myLine) then
myLine.parent:remove(myLine)
end
myLine= display.newLine(self.x, self.y, e.x, e.y)
myLine:setFillColor(255,255,255,50)
myLine.width=8
elseif(e.phase==“ended” or e.phase==“cancelled”) then
display.getCurrentStage():setFocus(nil)
self.isFocus=false
audio.play(shot);
if(myLine) then
myLine.parent:remove(myLine)
end
–Launch the arrow
self.bodyType=“dynamic”;
self:applyForce((self.x - e.x)*force_multiplier, (self.y - e.y)*force_multiplier, self.x,self.y);
– --wait a second to give the arrow time to hit something
– self.timer=timer.performWithDelay(1000, function(e)
– state:dispatchEvent({name=“change”, state=“fire”});
– if(e.count==1) then
– timer.cancel(self.timer);
– self.timer=nil;
– end
– end, 1)
end
end
end
arrow:addEventListener(“touch”, arrow);
end