Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. pong video game

pong video game

Scheduled Pinned Locked Moved Visual Basic
game-devperformancehelp
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cedrickdeorange
    wrote on last edited by
    #1

    I am trying to do a game of pong. My problem is, i can't get the ball served to a patricular point or location. By changing a valriables value i can get the ball served either to the left or right, up or down. the ball is located in thr middle of the form. When i serve the ball it will either do up or down and then bounce off the top or bottom, so if i want to serve a ball directly to a point say in the top left hand corner. i can't. here are the variables i am using and a bit of code trying to explain what i mean i'm using a timer for the ball speed Dim XChange As Integer = -5 Dim YChange As Integer = 5 Dim BallDirX As Integer 'for direction Dim BallDirY As Integer 'for direction Dim X, Y As Integer 'unused just in case If picBall.Top < 0 Then picBall.Top = 0 XChange = -5 YChange = 5 Here I want the ball to bounce off the wall and goto a YPoint say 50 and the xpoint as zero as the ball bounces in thay direction End If thnks from Zeldacat

    Regards Zeldacat

    M 1 Reply Last reply
    0
    • C Cedrickdeorange

      I am trying to do a game of pong. My problem is, i can't get the ball served to a patricular point or location. By changing a valriables value i can get the ball served either to the left or right, up or down. the ball is located in thr middle of the form. When i serve the ball it will either do up or down and then bounce off the top or bottom, so if i want to serve a ball directly to a point say in the top left hand corner. i can't. here are the variables i am using and a bit of code trying to explain what i mean i'm using a timer for the ball speed Dim XChange As Integer = -5 Dim YChange As Integer = 5 Dim BallDirX As Integer 'for direction Dim BallDirY As Integer 'for direction Dim X, Y As Integer 'unused just in case If picBall.Top < 0 Then picBall.Top = 0 XChange = -5 YChange = 5 Here I want the ball to bounce off the wall and goto a YPoint say 50 and the xpoint as zero as the ball bounces in thay direction End If thnks from Zeldacat

      Regards Zeldacat

      M Offline
      M Offline
      Matthew Butler 0
      wrote on last edited by
      #2

      I'm assuming from the code you have given that the ball can only move by a cirtain amount each time (5pix up/down and 5pix left/right)... this might not be enough. What you need to do is calculate both the horizontal and vertical distances to the wall and then divide them by the number of ticks you want the ball to move until it reaches the wall: this is the amount you need to move the ball each timer tick... If the distance to the left wall is 100 pixels (for example) and the distance you want the ball to travel downwards is 40 pixels (giving the target position of (0, 40)) then the ball will need to move 100/N to the left and 40/N downwards each timer tick, where N is the number of ticks you want the ball to move until it reaches the wall. I believe this would work: it requires the ball's vertical/horizontal speed to be something other than 5 pixels per tick though. Essentially you need to use relative positioning rather than absolute positioning. (Small edit at 3:45). Hope this helps.

      Matthew Butler

      modified on Saturday, December 15, 2007 10:42:33 AM

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups