• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

I killed my Vbasic Program!

Tab

Lifer
Option Explicit
'pong balls
Dim BallX(10) As Single
Dim BallY(10) As Single
Dim DirEx(10) As Integer
Dim DirWi(10) As Integer
Dim DistanceX As Integer
Dim DistanceY As Integer
Dim resettime As Long
'environment and edges of the game
Dim intLong As Integer
Dim intBegin As Integer
Dim Lside As Integer
Dim Rside As Integer
Dim Tside As Integer
Dim Dside As Integer
Dim intcount As Integer
Dim Score As Integer
Dim MouseaxisY As Single


Private Sub cmdSpeed_Click()
If Val(txtBall.Text) > 13 Then
Let intLong = 12
Let txtBall.Text = 12
ElseIf Val(txtBall.Text) < 1 Then
Let intLong = 12
Let txtBall.Text = 12
End If
Let intBegin = Val(txtBall.Text) / 2
Let intLong = Val(txtBall.Text)
End Sub

Private Sub Form_Load()
Print Picture1.ScaleWidth
For intcount = 0 To 10
Let DirEx(intcount) = 1
Let DirWi(intcount) = 1
Let BallX(intcount) = Picture1.ScaleWidth / 2
Let BallY(intcount) = Picture1.ScaleHeight / 2
Let intBegin = 5
Let intLong = 12
Let Score = 0
Next intcount
Let Lside = 0
Let Rside = Picture1.ScaleWidth
Let Tside = 0
Let Dside = Picture1.ScaleHeight
Let DistanceX = 16
Let DistanceY = 16
Let intBegin = 4
Let intLong = 10
Let BallX(0) = Picture1.ScaleWidth / 2
Let BallY(0) = Picture1.ScaleHeight / 2
End Sub

Private Sub mnu_file_exit_Click()
Unload Me
End Sub

Private Sub mnu_file_start_Click()
Timer.Enabled = Not Timer.Enabled
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Let MouseaxisY = Y
End Sub

Private Sub Timer_Timer()
Let Paddle.Y1 = MouseaxisY
Let Paddle.Y2 = MouseaxisY + 50
Let Paddle1.Y1 = MouseaxisY
Let Paddle1.Y2 = MouseaxisY + 50
Picture1.Refresh
Let Label.Caption = Str(BallX(0)) & "," & Str(BallY(0))
For intcount = 0 To 0
Randomize
Picture1.DrawWidth = 10
Picture1.ForeColor = RGB(Int(Rnd * Int(Rnd * 125)) + 175, Int(Rnd * 50), Int(Rnd * 50))
Picture1.Line (BallX(intcount), BallY(intcount))-Step(1, 1)
Let BallX(intcount) = BallX(intcount) + DirEx(intcount) * DistanceX
Let BallY(intcount) = BallY(intcount) + DirWi(intcount) * DistanceY
If BallX(intcount) >= Rside Then
Let DirEx(intcount) = -1
Let DistanceX = Int(Rnd * intLong) + intBegin
Let DistanceY = Int(Rnd * intLong) + intBegin
ElseIf BallX(intcount) <= Lside Then
Let Score = Score + Val(txtBall.Text)
Let TxtScore = Score
Let TxtScore.Text = "Score: " & Score
Let DirEx(intcount) = 1
Let DistanceX = Int(Rnd * intLong) + intBegin
Let DistanceY = Int(Rnd * intLong) + intBegin
End If
'If the ball hits left or right side, this is where the ball hits the paddle
'if it hits, you get one point, if you miss it gets reset to 0 and
'you can play the game again

If BallX(intcount) < Lside + 10 Then
If BallY(0) >= Paddle.Y1 And BallY(0) <= Paddle.Y2 Then
'if x > 3 and x < 7 then
Let Score = Score + Val(txtBall.Text)
Let TxtScore = Score
Let TxtScore.Text = "Score: " & Score
Let DirEx(intcount) = 1
Let DistanceX = Int(Rnd * intLong) + intBegin
Let DistanceY = Int(Rnd * intLong) + intBegin
End If
End If

If BallX(intcount) < Lside Then
If BallY(0) >= Paddle.Y1 And BallY(0) <= Paddle.Y2 Then
Let DirEx(intcount) = 1
Let DistanceX = Int(Rnd * intLong) + intBegin
Let DistanceY = Int(Rnd * intLong) + intBegin
Else
For resettime = 0 To 5000000
Next resettime
Let Score = 0
Let TxtScore = "Score: 0"
Let DirEx(intcount) = Int(Rnd * 3) - 1
Let DirWi(intcount) = 1
Let BallX(intcount) = Picture1.ScaleWidth / 2
Let BallY(intcount) = Picture1.ScaleHeight / 2
Let DirEx(intcount) = 1
End If
End If

' If BallX(intcount) < Rside + 10 Then
' If BallY(0) >= Paddle1.Y1 And BallY(0) <= Paddle1.Y2 Then
' 'if x > 3 and x < 7 then
' Let Score = Score + Val(txtBall.Text)
' Let TxtScore = Score
' Let TxtScore.Text = "Score: " & Score
' Let DirEx(intcount) = 1
' Let DistanceX = Int(Rnd * intLong) + intBegin
' Let DistanceY = Int(Rnd * intLong) + intBegin
' End If
' End If
'
' If BallX(intcount) < Rside Then
' If BallY(0) >= Paddle1.Y1 And BallY(0) <= Paddle1.Y2 Then
' Let DirEx(intcount) = 1
' Let DistanceX = Int(Rnd * intLong) + intBegin
' Let DistanceY = Int(Rnd * intLong) + intBegin
' Else
' For resettime = 0 To 5000000
' Next resettime
' Let Score = 0
' Let TxtScore = "Score: 0"
' Let DirEx(intcount) = Int(Rnd * 3) - 1
' Let DirWi(intcount) = 1
' Let BallX(intcount) = Picture1.ScaleWidth / 2
' Let BallY(intcount) = Picture1.ScaleHeight / 2
' Let DirEx(intcount) = 1
' End If
' End If

If BallY(intcount) > Dside Then
Let DirWi(intcount) = -1
Let DistanceX = Int(Rnd * intLong) + intBegin
Let DistanceY = Int(Rnd * intLong) + intBegin
Let intBegin = intBegin + 5

ElseIf BallY(intcount) > Rside Then
Let DirWi(intcount) = 1
Let DistanceX = Int(Rnd * intLong) + intBegin
Let DistanceY = Int(Rnd * intLong) + intBegin
Let intBegin = intBegin + 5

ElseIf BallY(intcount) < Tside Then
Let DirWi(intcount) = 1
Let DistanceX = Int(Rnd * 20) + intBegin
Let DistanceY = Int(Rnd * 20) + intBegin
Let intBegin = intBegin - 10
End If
Next intcount
End Sub

Please, someone help me...
 
#define GRAPHPATH "C:\\BC5\\BGI"
#include <stdio>
#include <conio>
#include <graphics>
#include <dos>
#include <iostream>

void SetupGraphics(void) {

int gdriver = DETECT, gmode, error;
initgraph(&gdriver, &gmode, GRAPHPATH);

} // SetupGraphics

void makeSound(){

sound(440);
delay(30);
nosound();

} // makeSound


void main(){

SetupGraphics();


bool intro;
cout << "\n";
cout << " Welcome to Pong Beta 1.0! \n\n";
cout << " Commands: \n";
cout << " q - exit \n";
cout << " w - freeze paddle \n";
cout << " a - Left Paddle Up \n";
cout << " s - Right Paddle Up \n";
cout << " z - Left Paddle Down \n";
cout << " x - Right Paddle Down \n";
cout << "\n";
cout << "Press a key to continue...";
do {
intro = kbhit();
} while(!intro);
cleardevice();
clrscr();
setfillstyle(1,0);
floodfill(100,100,12);

bool exit = false;

do {

bool makesound = false;
int moveit = 0;
int score = 0;
int scoreOld = 0;

// outer boundaries of screen
const int x_left = 10;
const int y_top = 35;
const int x_right = 630;
const int y_bottom = 470;

// ball location
int x = 100;
int y = 100;
int x1 = x;
int y1 = y;
const int r = 5;

// ball movement
int xm = 1;
int ym = 1;
const int delay = 2;

// left paddle
const int p1_width = 10;
const int p1_height = 50;

int p1_x_left = x_left + 10;
int p1_y_top = y_top + 10;
int p1_x_right = p1_x_left + p1_width;
int p1_y_bottom = p1_y_top + p1_height;
int p1_ym = 1;

// right paddle
const int p2_width = p1_width;
const int p2_height = p1_height;

int p2_x_right = x_right - 10;
int p2_y_top = y_top + 10;
int p2_x_left = p2_x_right - p2_width;
int p2_y_bottom = p2_y_top + p2_height;
int p2_ym = 1;

// draw border
rectangle(x_left, y_top, x_right, y_bottom);

cout << " Score: 0";

do {

// erase old ball
setcolor(0);
circle(x, y, r);
setfillstyle(1, 0);
floodfill(x, y, 0);

// set new coordinates
x = x + xm;
y = y + ym;

// check if ball hits wall
if (x == x_right-6) {xm = -1;}
if (x == x_left+6) {xm = 1;}
if (y == y_top+6) {ym = 1;}
if (y == y_bottom-6) {ym = -1;}

//check if ball hits left paddle
makesound = false;
if ((x == p1_x_left-6) && (y > p1_y_top-6) && (y < p1_y_bottom + 6))
{xm = -1; makesound = true;}
if ((x == p1_x_right+6) && (y > p1_y_top-6) && (y < p1_y_bottom + 6))
{xm = 1; makesound = true;}
if ((y == p1_y_bottom+6) && (x > p1_x_left-6) && (x < p1_x_right + 6))
{ym = 1; makesound = true;}
if ((y == p1_y_top-6) && (x > p1_x_left-6) && (x < p1_x_right + 6))
{ym = -1; makesound = true;}
if (makesound==true) {makeSound(); score++; p1_ym=0;}

//check if ball hits right paddle
makesound = false;
if ((x == p2_x_left-6) && (y > p2_y_top-6) && (y < p2_y_bottom + 6))
{xm = -1; makesound = true;}
if ((x == p2_x_right+6) && (y > p2_y_top-6) && (y < p2_y_bottom + 6))
{xm = 1; makesound = true;}
if ((y == p2_y_bottom+6) && (x > p2_x_left-6) && (x < p2_x_right + 6))
{ym = 1; makesound = true;}
if ((y == p2_y_top-6) && (x > p2_x_left-6) && (x < p2_x_right + 6))
{ym = -1; makesound = true;}
if (makesound==true) {makeSound(); score++; p2_ym=0;}

//draw new multicolor ball
for (int i=0; i<delay; i++){
setcolor(15);
circle(x, y, r);
setfillstyle(1, 1);
floodfill(x, y, 15);
setcolor(15);
circle(x, y, r);
setfillstyle(1, 3);
floodfill(x, y, 15);
setcolor(15);
circle(x, y, r);
setfillstyle(1, 9);
floodfill(x, y, 15);
}

// keyboard input to move paddles and exit
moveit = 0;
if (kbhit()) {moveit = getch();}
switch (moveit){
case 113:
exit = true;
break;
case 97:
if (p1_y_top > (y_top + 6)) {p1_ym = -1;}
break;
case 122:
if (p1_y_bottom < (y_bottom - 6)) {p1_ym = 1;}
break;
case 115:
if (p2_y_top > (y_top + 6)) {p2_ym = -1;}
break;
case 120:
if (p2_y_bottom < (y_bottom - 6)) {p2_ym = 1;}
break;
case 119:
p1_ym = 0;
p2_ym = 0;
break;
}

// erase old paddles if they will be moved
if (p1_ym !=0){
setcolor(0);
rectangle(p1_x_left, p1_y_top, p1_x_right, p1_y_bottom);
setfillstyle(1,0);
floodfill(p1_x_left, p1_y_top, 0);
}
if (p2_ym !=0){
setcolor(0);
rectangle(p2_x_left, p2_y_top, p2_x_right, p2_y_bottom);
setfillstyle(1,0);
floodfill(p2_x_left, p2_y_top, 0);
}

// calculate new position of paddles
p1_y_top += p1_ym;
p1_y_bottom += p1_ym;
p2_y_top += p2_ym;
p2_y_bottom += p2_ym;

// draw new paddles
setcolor(15);
rectangle(p1_x_left, p1_y_top, p1_x_right, p1_y_bottom);
setcolor(15);
rectangle(p2_x_left, p2_y_top, p2_x_right, p2_y_bottom);

// stop paddles when they touch top or bottom
if ((p1_y_top < (y_top + 6)) || (p1_y_bottom > (y_bottom - 6))) {p1_ym = 0;}
if ((p2_y_top < (y_top + 6)) || (p2_y_bottom > (y_bottom - 6))) {p2_ym = 0;}

//scoring
if (score != scoreOld) {cout << "," << score;}
scoreOld = score;
if (score == 50) {exit = true;}

} while (!exit);

exit = false;
cleardevice();
cout << "\n";
cout << " Play again? (enter y or n): ";
char newGame;
cin >> newGame;
if (newGame != 'y') {exit = true;}
cleardevice();
clrscr();
setfillstyle(1,0);
floodfill(100,100,12);

} while (!exit);

} // main
 
Originally posted by: dabuddha
Didn't they ever teach you how to indent? For god's sakes....

I'm sure he would have indented, if the forum software allowed it.

You try indenting somthing in your post and see how sucessful you are with it.
 
alright sorry that isn't indented, it was whipped up in Borland C++, but it makes an awesome game of Pong 🙂 hehe... Alright now C++ is the real way to program. No, take that back... Assembly would be cooler for creating a Pong game but no time right now.
 
Assembly would be cooler for creating a Pong game but no time right now.

No it wouldn't, cause then it wouldn't build on 3 out of 5 of my machines.

I've only got several weeks left! I would have indented but copy and pasting doesnt let me.

It might be usefull if you posted what the problem was other than 'it's broke, fix it!'.
 
Back
Top