This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Hydrotronics's profile picture

bouncing ball

Started by Hydrotronics, 06 September 2016 - 02:39 PM
Hydrotronics #1
Posted 06 September 2016 - 04: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?
KingofGamesYami #2
Posted 06 September 2016 - 04:54 PM
Please post the code of your bouncing ball physics.
Hydrotronics #3
Posted 06 September 2016 - 05:26 PM
here it is
KingofGamesYami #4
Posted 06 September 2016 - 05: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
valithor #5
Posted 06 September 2016 - 08: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).
Dog #6
Posted 06 September 2016 - 09: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.