Author Topic: Pong Bounce  (Read 9104 times)

0 Members and 1 Guest are viewing this topic.

Offline Vile Smile

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 10
  • Rating: +0/-0
    • View Profile
Pong Bounce
« on: October 17, 2010, 08:56:40 pm »
In my pong game, I have a paddle and a ball. My goal is to get the ball to bounce in a direction depending on the contact position, so if the ball hits the upper part of the paddle, it will bounce up, and if it hits the lower part, it will bounce down. I've accomplished this with the following code:
Code: [Select]
:(Y-A)->VY is the ball's position.
A is the paddle's position.
V is the ball's speed.

This works, but causes the ball to move up and down much too fast. So I decided to change the code to the following:
Code: [Select]
:(Y-A)/2->V

This works when the ball is hit down, but when it hits the upper part of the paddle, the ball squiggles up and down until it is hit by the next paddle.

TL;DR
: What is a good way to make a ball bounce against the paddle depending on where the ball and the paddle collide?


Also, as a unrelated question, how would I create a full screen image, such as a title screen?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Pong Bounce
« Reply #1 on: October 17, 2010, 08:57:44 pm »
You need to do signed division.
Code: [Select]
:(Y-A)//2->Vshould work.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Vile Smile

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 10
  • Rating: +0/-0
    • View Profile
Re: Pong Bounce
« Reply #2 on: October 17, 2010, 09:03:28 pm »
You need to do signed division.
Code: [Select]
:(Y-A)//2->Vshould work.
Thanks! BTW, is your avatar related to a game you've made or that is available?


Also, does someone have an answer for the second question?

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Pong Bounce
« Reply #3 on: October 17, 2010, 09:03:51 pm »

Also, as a unrelated question, how would I create a full screen image, such as a title screen?

Not easily. You would have to design the whole menu, using bitmaps and probably sprites. Basically, you just have to draw all of the graphics from data. The data and menu engine will increase your program size by at least a kilobyte.

EDIT: Calc's avatar comes from his port of F-Zero, which I believe is still in production.
« Last Edit: October 17, 2010, 09:05:02 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Pong Bounce
« Reply #4 on: October 17, 2010, 09:10:55 pm »
a title screen would be easy to import. do you already have the screen in a Pic variable? then you could just do Copy([Pic#],L6,768) in your program and the picture variable will be copied to the buffer


Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Pong Bounce
« Reply #5 on: October 17, 2010, 09:49:09 pm »
a title screen would be easy to import. do you already have the screen in a Pic variable? then you could just do Copy([Pic#],L6,768) in your program and the picture variable will be copied to the buffer
Actually, if you just want to display it it's even easier.  Just do this:
[Pic#]->DispGraph

Welcome here Vile Smile!  Awesome Avatar and username by the way. :)

Offline Vile Smile

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 10
  • Rating: +0/-0
    • View Profile
Re: Pong Bounce
« Reply #6 on: October 17, 2010, 09:56:40 pm »
a title screen would be easy to import. do you already have the screen in a Pic variable? then you could just do Copy([Pic#],L6,768) in your program and the picture variable will be copied to the buffer
Actually, if you just want to display it it's even easier.  Just do this:
[Pic#]->DispGraph


Welcome here Vile Smile!  Awesome Avatar and username by the way. :)

Thanks for the welcome! :)

So I'd just use a large hexidecimal code like with sprites?
« Last Edit: October 17, 2010, 09:57:05 pm by Vile Smile »

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Pong Bounce
« Reply #7 on: October 17, 2010, 09:58:25 pm »
That'd be the easiest. If you want an interactive menu (or greyscale), it would take a slightly different approach.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Vile Smile

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 10
  • Rating: +0/-0
    • View Profile
Re: Pong Bounce
« Reply #8 on: October 17, 2010, 10:05:17 pm »
Sorry to continue this, but is there a program that can generate a hexidecimal code that could fit on the entire screen?

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Pong Bounce
« Reply #9 on: October 17, 2010, 10:07:20 pm »
If its full screen, its MUCH easier to just import the picture, no codes required.  Just put it in a picture variable and then do what nemo or ztrumpet suggested (depending on your needs).  The compiler will automatically convert the picture into data when it compiles as if you had the hex codes there.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Pong Bounce
« Reply #10 on: October 17, 2010, 11:59:48 pm »
You need to do signed division.
Code: [Select]
:(Y-A)//2->Vshould work.
Thanks! BTW, is your avatar related to a game you've made or that is available?
A game that only him and myself currently have on our computer ;D I think he stopped working on it for a while, though.

Welcome here by the way :)

Also for title screens, if your screen got huge gaps of white or black horizontally, sometimes it may be best to just store parts of it then recall each parts at the appropriate location the fill the remaining stuff with a black rectangle or something. That saves quite a bit of space.