View Full Version: Get the "o"

C++ Learning Community > C++ Works in Progress > Get the "o"


Title: Get the "o"
Description: hehe


aaron7215 - May 20, 2005 07:20 PM (GMT)
Hey guys, I made this game, but it has some glitches, can you help me fix it?:
CODE
#include <stdlib.h>
#include <windows.h>
#include <iostream>
#include <string>
//define the keys
#define VK_A 0x41
#define VK_D 0x44
#define VK_S 0x53
#define VK_W 0x57
using namespace std;

int main()
{
INPUT_RECORD InputRecord;
//set all the variables
int caca = 0;
int x = 32;
int y = 10;
int xx = 32;
int yy = 16;
int score;
int i;
int ii;
int xvar;
int yvar;
int cana;
int canw;
int cand;
int cans;
int cacaca;
string str;
string str2;
do
{
//set other variables
xvar = 0;
yvar = 0;
//repeat
for (i=0;i<23;i++)
{
//repeat
for (ii=0;ii<79;ii++)
{
//if O and o are collided
if ((xx == x) && (yy = y))
{
//move o and set score +1
xx = rand()/20/25;
yy = rand()/20/100;
score+=1;
}
else
//this part is the glitch part, sometimes when O is same y as o, and O x is smaller
then o x(xx), then O doesnt show up








{
if ((xvar < x) && (yvar == y))
{
str = " ";
}
if ((xvar == x) && (yvar == y))
{
str = "O";
}
if ((xvar < xx) && (yvar == yy))
{
str = " ";
}
if ((xvar == xx) && (yvar == yy))
{
str = "o";
}
}
xvar+=1;
cout << str;
str = "";
}
xvar = 0;
yvar+=1;
cout << "\n";
str = "";
}









//up to here
if(GetAsyncKeyState(VK_A) && 0x41)
{
if (cana == 0)
{
if (x > 0)
{
x-=1;
cana = 1;                              
}
}
}
else
{
cana = 0;  
}
if(GetAsyncKeyState(VK_D) && 0x44)
{
if (cand == 0)
{
if (x < 79)
{
x+=1;                              
cand =1;
}
}
}
else
{
cand = 0;  
}
if(GetAsyncKeyState(VK_W) && 0x57)
{
if (canw == 0)
{
if (y > 0)
{
y-=1;                              
canw = 1;
}
}
}
else
{
canw = 0;  
}
if(GetAsyncKeyState(VK_S) && 0x53)
{
if (cans == 0)
{
if (y < 24)
{
y+=1;                              
cans = 1;
}
}
}
else
{
cans = 0;  
}
str = "";
str2 = "";
system("cls");
}
while (caca == 0);
return 0;  
}

thanks

ramirez - May 20, 2005 07:24 PM (GMT)
- What glitches?
- Please use code indenting, I am not going to bother reading it otherwise.

aaron7215 - May 20, 2005 07:32 PM (GMT)
ok i did what you said. the glitches are that when you are to the left of o, the big O doesn't show up, and even if you are the same x and not the same y, you still get the point.

ramirez - May 20, 2005 08:54 PM (GMT)
It still is not indented. :P

aaron7215 - May 20, 2005 08:57 PM (GMT)
? I Commented it, I don't know what you mean by indented, but I will try.

aaron7215 - May 20, 2005 09:20 PM (GMT)
Nvm, I figured it out. YAY! Expect a game out soon.

ramirez - May 20, 2005 10:19 PM (GMT)
QUOTE (aaron7215 @ May 20 2005, 08:57 PM)
? I Commented it, I don't know what you mean by indented, but I will try.

Not indented code:
CODE
int main()
{
cout << "Hello World!" << endl;
system("pause");
return 0;
}

Indented code:
CODE
int main()
{
   cout << "Hello World!" << endl;
   system("pause");
   return 0;
}

Improves readibility by a huge amount.

aaron7215 - May 22, 2005 01:54 AM (GMT)
oh ok.

Rmstn1580 - December 5, 2005 05:27 AM (GMT)
The code wouldn't compile...




Hosted for free by InvisionFree