Jump to content




bouncing ball


  • You cannot reply to this topic
5 replies to this topic

#1 Hydrotronics

  • Members
  • 131 posts
  • LocationThe hall of 1000 monkeys and only 1 typewriter

Posted 06 September 2016 - 03:39 PM

So I'm trying to make a game of Pong over Rednet and I thought that making this would be simple, but I was wrong apparently!!!

I made a tiny piece of code to test the ball bouncing physics, but the X axis didn't move.

I made another program to test the movement of the numbers

This is basically what I did:

while true do
  local x, y = term.getCursorPos()
  term.setCursorPos(x+1,y+1)
  print((x+1).."/"..(y+1)
end
when I did this, I noticed that the X integer did not change! The Y Integer changed but the X one didn't. Can I be told why this is?

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 06 September 2016 - 03:54 PM

Please post the code of your bouncing ball physics.

#3 Hydrotronics

  • Members
  • 131 posts
  • LocationThe hall of 1000 monkeys and only 1 typewriter

Posted 06 September 2016 - 04:26 PM

here it is

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 06 September 2016 - 04:50 PM

The first problem I see is xpos / ypos aren't defined anywhere, yet you add or subtract from them.

Besides that, it's unnecessarily complicated with if statements. Why not just set LR to -1 or 1, and add it to xpos?

Eg:
local xpos, ypos = 10, 10
local xmotion, ymotion = -1, 1
while true do
  if xpos == 1 or xpos == 51 then
    xmotion = -xmotion
  end
  if ypos == 1 or ypos == 19 then
    ymotion = -ymotion
  end
  xpos = xpos + xmotion
  ypos = ypos + ymotion
end


#5 valithor

  • Members
  • 1,053 posts

Posted 06 September 2016 - 07:54 PM

For future reference, print causes the cursor to go to the beginning of the next line. If you were to use term.write instead of print your example would work (your bouncing ball program might even work, haven't actually looked at it).

#6 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 06 September 2016 - 08:06 PM

Not to do with the problem you're having, but I would also recommend moving your drawBall function out of and above the while loop.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users