Hello I am 100% completely new to programming. I have a bit of history with working on minor things, however I am dertermined to make my first game. That being said I am running into a bit of a snag.
What I am trying to do fumbling around in the dark is this.
- Create Multiple objects on the screen to generate A Random amount of Object in a Random Location on the Screen.
2)Touch to remove these objects.
3)Get a X amount of “points” everytime the object is touch to removed.
I have found two open source peices of code that will allow me to accomplish generating random number of objects on random location on the screen. As well as touch to remove an object. But the trouble is coming in trying to make these two seperate functions work together.
Can anyone point me in the right direction as to what I am doing wrong.
Below is the touch to remove code I have been working off of.
function onSmileTouch(self, event)
if(event.phase == “began”) then
timer.performWithDelay(1, function() self:removeSelf() end )
end
return true
end
crate = display.newImageRect( “crate.png”, 90,90)
crate.touch = onSmileTouch
crate:addEventListener(“touch”, smile)
Below is the spawn random object code I have been working off of.
local numberSmiles = 15 --local variable; amount can be changed
local function clearSmile( thisSmile )
display.remove( thisSmile ) ; thisSmile = nil
end
local function spawnSmiles()
for i=1,numberSmiles do
smile = display.newImageRect(“crate.png”, 45, 45);
– smile:setReferencePoint(display.CenterReferencePoint); --not necessary; center is default
smile.x = math.random(-10, 400);
smile.y = -40;
transition.to( smile, { time=math.random(2000,8000), x=math.random(-10,400) , y=600, onComplete=clearSmile } );
physics.addBody( smile, “dynamic”, { density=0.1, bounce=0.1, friction=0.1, radius=0 } );
The Problem im having once again is getting these two functions to work together instead of working independently.
More importantly though is how do I get Multiple functions to work together instead of seperatly, because after I get this to work, im planning on adding the gain a point on object removed.