code minigame to exercise

gp=display.newGroup( )

qtde=20

vida = 3

local physics = require( “physics” )

physics.start();

physics.setDrawMode(“hybrid”)

local chao=display.newRect( display.contentCenterX, display.contentCenterY+260, 350, 50 )

physics.addBody(chao, “static”)

chao.myName =“chao”

local alvo=display.newRect( 20, display.contentCenterY+200, 30, 70 )

alvo:setFillColor (00, 0, 128)

alvo.myName =“alvo”

physics.addBody( alvo,“static”)

local function woodenblockAnimation()

local animUp = function()

transition.to(alvo, {gp, time=1000, x=295, onComplete=woodenblockAnimation })

end

transition.to(alvo, {gp, time=1000, x=20, onComplete=animUp })

end

woodenblockAnimation()

local rect=display.newRect( display.contentCenterX, display.contentCenterY-100, 120, 50 )

local function anm1()

local anm2 = function()

transition.to(rect, {gp, time=1000, math.random( display.contentWidth ), onComplete=anm1 })

end

transition.to(rect, { gp,time=1000, x=math.random( display.contentWidth ), onComplete=anm2 })

end

anm1()

local function tapListener( event )

local c=display.newCircle( 10, 10, 10, 10 )

c.x=rect.x

c.y=rect.y

c:setFillColor(255, 255, 0)

c.myName =“c”

physics.addBody( c, { density=1.0, friction=0.0, bounce=0.2, radius=10 } )

local function onLocalCollision( self, event )

print( “colidiu” )

  

  if event.phase == “began” then 

if event.target.myName == “c” and event.other.myName == “chao” then 

–local collidedText = display.newText( “Collided!”, display.contentCenterX, display.contentCenterY, native.systemFontBold, 20 )

display.remove( c,1 )

qtde=qtde-1

print( qtde )

if (qtde<=0) then

display.remove(alvo )

display.remove(chao )

display.remove(rect )

– local rect=display.newRect( display.contentCenterX, display.contentCenterY-100, 120, 50 )

end

end

end

  

  if event.phase == “began” then 

if event.target.myName == “c” and event.other.myName == “alvo” then 

–local collidedText = display.newText( “Collided!alvo”, display.contentCenterX, display.contentCenterY, native.systemFontBold, 20 )

display.remove( c,1 )

–local att=1

vida=vida-1

if (vida==0) then

display.remove( alvo )

–transition.cancel( )

end

print( vida )

end

end

end

c.collision = onLocalCollision

c:addEventListener( “collision” )

end

rect:addEventListener( “tap”, tapListener )

Kevin,

Welcome to the community. 

I’m not sure what you’re posting there.  The title does notseems to mention an issue.  I don’t see a question in the body, and the code isn’t formatted, so it is hard to read.

formatyourcode.jpg

Tip: Instead of posting a lot of code, consider posting a zip file with the project and asking a question in the post.  This will get faster help.

i.e. Only post small snippets if you can, because reading big ones is a lot of work and may get fewer responses.  Also, when helping someone, it is nice to be able to run the code instead of just read it.

You can attach a small zipped project, by clicking ‘more reply options’ (lower-right), then…

attaching_files.jpg

One more note.

A great way to ask questions is to:

Title: Make it short and meaningful.

Body:

Include these details:

  1. What you did.
  2. What you saw.
  3. What you expected to see and why.
  4. What you did to debug.

When possible, attach a mini-project or post a short piece of nicely formatted and very legible code.  (I typically paste my code to notepad first, then replace all TABs with 3 spaces.  Otherwise, the code is completely illegible due to extreme TAB indenting.)

Finally, be sure to tell us:

  • Corona version you’re using (ex: 2018.3265)
  • Corona simulator you’re using Windows or OS X
  • Ran it in simulator or on device.
  • If on device, what device and what version of OS.

This may seem like a lot, but we’re going to ask you for it in many cases anyways, so it saves everyone time and gets you a faster and better answer.

Kevin,

Welcome to the community. 

I’m not sure what you’re posting there.  The title does notseems to mention an issue.  I don’t see a question in the body, and the code isn’t formatted, so it is hard to read.

formatyourcode.jpg

Tip: Instead of posting a lot of code, consider posting a zip file with the project and asking a question in the post.  This will get faster help.

i.e. Only post small snippets if you can, because reading big ones is a lot of work and may get fewer responses.  Also, when helping someone, it is nice to be able to run the code instead of just read it.

You can attach a small zipped project, by clicking ‘more reply options’ (lower-right), then…

attaching_files.jpg

One more note.

A great way to ask questions is to:

Title: Make it short and meaningful.

Body:

Include these details:

  1. What you did.
  2. What you saw.
  3. What you expected to see and why.
  4. What you did to debug.

When possible, attach a mini-project or post a short piece of nicely formatted and very legible code.  (I typically paste my code to notepad first, then replace all TABs with 3 spaces.  Otherwise, the code is completely illegible due to extreme TAB indenting.)

Finally, be sure to tell us:

  • Corona version you’re using (ex: 2018.3265)
  • Corona simulator you’re using Windows or OS X
  • Ran it in simulator or on device.
  • If on device, what device and what version of OS.

This may seem like a lot, but we’re going to ask you for it in many cases anyways, so it saves everyone time and gets you a faster and better answer.