Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Fun Physics Problem

edited August 2014 in Competition Posts: 145

I have some code that moves platforms down when touched. I'm trying to draw a ball on the platform and use physics to make the ball look like it jumps either up if pressed on the side of the screen it's on or the other direction if pressed on the other side of the screen. Could someone help me with this?

Code:


 -- Use this function to perform your initial 

displayMode(FULLSCREEN)
function setup()
Side=0
Piececounter=1
Jumpdistance=300
shiftcounter = 0
y = {}
side = {}

for i=1,10 do
    side[i] = math.random(0,1)
    y[i] = Jumpdistance*i
end

shift = 0

end

-- This function gets called once every frame
function draw()

background(82,243,243)

-- Set stroke and fill color to white
fill(255,0,0)
stroke(255)

-- Update stroke width
strokeWidth(10)
smooth()


-- Set the line cap mode
lineCapMode(ROUND)



if(shift==1) then
    shiftnow()
end

DrawPieces()
DrawMiddle()
DrawCharacter()
end



 function shiftnow()
  if (shiftcounter>0) then
      shiftcounter = shiftcounter - 5
  end

  print(shiftcounter)
  if(shiftcounter<=0)then
    Piececounter = Piececounter + 1
    if(Piececounter==11)then
        Piececounter=1
    end
      shift=0
    end

    for i=1,10 do
        y[i] = y[i] - 30
    end

    if(y[3]<0)then
    table.remove(y,1)
    table.remove(side,1)
    table.insert(y,10,y[9]+Jumpdistance)
    table.insert(side,10,math.random(0,1))
  end
  end


  function DrawCharacter()


  end

  function DrawPieces()
    for i=1,10 do
-- Draw the line
    if(side[i]==0) then
    fill(255,0,0)
     stroke(255)

    rect((WIDTH/2)-200,y[i],200,70)
   else

    fill(80, 117, 206, 255)
    stroke(255)

    rect((WIDTH/2),y[i],200,70)
   end

    end

   end


  function DrawMiddle()
   stroke(255, 255, 255, 255)
   line(WIDTH/2,-10,WIDTH/2,HEIGHT+10)
  end


  function touched (touch) 
  if(CurrentTouch.state==BEGAN)then
        shift = 1
        shiftcounter = 50
    end


  end
Tagged:

Comments

  • edited August 2014 Posts: 175

    Hi. I'm new here but I think Codea's physics lab test 6 might help you

  • IgnatzIgnatz Mod
    edited August 2014 Posts: 5,396

    What do you mean by "the other direction if pressed on the other side of the screen"?

    If you're going to use physics, I suggest you read up about it first, rather than just trying to include it in a game. You need to understand it.

    I cover it in my ebook on Codea, here, as well as some blog posts

    http://coolcodea.wordpress.com/2013/06/19/index-of-posts/

  • Thanks for the references!

  • IgnatzIgnatz Mod
    Posts: 5,396

    I'll just note that the physics lab project included with Codea includes a lot of unnecessary code (required only for the most complex demos) that I found very confusing when I started. In my ebook and blogs, I've tried to keep things as simple as possible.

Sign In or Register to comment.