very intense racer game - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

very intense racer game

(cc)(cc) Posts: 23Member
[b][red]This message was edited by (cc) at 2006-1-20 9:41:25[/red][/b][hr]
[b][red]This message was edited by (cc) at 2006-1-19 10:0:47[/red][/b][hr]
maybe intense is the wrong word. ( you have to try to keep the cursor inside the road by moving left or right, while the road twists)

I need help, when i loop the road it goes extremly fast, how could i loop so its timed or slower?
Any suggestions how you would build a game like this greatly appreciated.
compiled in dev++ code

[code]
#include
#include
#include
#include
#define roadwidth 50
using namespace std;

int random();
int srandom(int i);
void sidewalk1();
void sidewalk2();
void sidewalk3();
void sidewalk4();
void sidewalk5();
void printroad();
void road(char a[]);
void setmiddle();
void mainroad();
int middlecursor();
// the road
char road1[roadwidth];
char road2[roadwidth];
char road3[roadwidth];
char road4[roadwidth];
char road5[roadwidth];


int cursormid = (roadwidth/2);
int middle = (roadwidth/ 2);
int level = 2;
int legalwidth = (roadwidth/ level);
int rightlimit = (roadwidth/ 4)* 3;
int leftlimit = (roadwidth/ 3);
char midcursor; //main controler, takes n, m and q
int life = roadwidth;
int main(){
srand(time(NULL));
int go, counter = 0;
cout << " N to move left, M to move right, Q to quit!!";
cout << "
(press one of these letters to go)" << endl;

while(midcursor != 'q' && midcursor != 'Q' && counter <= 100 && life != 0)
{
// some stats to show whats going on
counter++;
cout << "counter: "<< counter << endl;
cout << "legalwidth is: " << legalwidth << endl;
cout << "middle of gap is: " << middle << endl;
cout << "rightlimit: " << rightlimit << endl;
cout << "leftlimit: " << leftlimit << endl;
cout << "cursor position: " << cursormid << endl;
cout << "life left: " << life << endl;
cin >> midcursor;

system("cls");
mainroad();
}



cout << "Thanks for trying!" << endl;

system("pause");
}
void mainroad(){

sidewalk1();
setmiddle();

sidewalk2();
setmiddle();

sidewalk3();
setmiddle();

sidewalk4();
setmiddle();
middlecursor();

sidewalk5();
setmiddle();

printroad();

}

void sidewalk1(){
int u = 0;
// fill the screen with "A" and call function to create gap
while (u != roadwidth){
s++;
road1[u] = 'A';
road(road1);

}}
void sidewalk2(){
int u = 0;
// fill the screen with "A" and call function to create gap line2 etc
while (u != roadwidth){
s++;
road2[u] = 'A';
road(road2);}

}
void sidewalk3(){
int u = 0;
// fill the screen with "A" and call function to create gap line3 etc
while (u != roadwidth){
s++;
road3 [u] = 'A';
road(road3);}
}
void sidewalk4(){
int u = 0;
// fill the screen with "A" and call function to create gap
while (u != roadwidth){
s++;
road4[u] = 'A';
road(road4);}
}
void sidewalk5(){
int u = 0;
// fill the screen with "A" and call function to create gap
while (u != roadwidth){
s++;
road5[u] = 'A';
road(road5);}
}
int random(){
int n = 20;
return rand()%n;}

int srandom(int i){
return rand()%i;}

void printroad(){
// print the road
for(int f = 0; i != roadwidth; f++){
cout << road1[f] ;}
cout << endl;
for(int f = 0; f != roadwidth; i++){
cout << road2[f] ;}
cout << endl;
for(int f = 0; f != roadwidth; i++){
cout << road3[f] ;}
cout << endl;
for(int f = 0; f != roadwidth; i++){
cout << road4[f] ;}
cout << endl;
for(int f = 0; f != roadwidth; i++){
cout << road5[f] ;}
cout << endl;
cout << endl;

}
void road(char a[]){
// create the gap for road/ set the middle for the gap

int minus1 = middle ;
int pluss1 = middle - 1;
for(int i = legalwidth/2;i > 0; i--){
pluss1++;
minus1--;
a[minus1] = ' ';
a[pluss1] = ' ';}
}
// makes the gap change position right and left
void setmiddle(){
int f = srandom(2);
//int addorsub = srandom(2);
// cout << "random 1/2: " << f << " addorsub: " << addorsub << endl;
if(middle > leftlimit && middle < rightlimit && f == 1)
middle++;
//middle += addorsub;
if(middle > leftlimit && middle < rightlimit && f == 0)
middle--;
//middle -= addorsub;
if(middle <= leftlimit)
middle++;
if(middle >= rightlimit)
middle--;
}
// controller for spaceship
int middlecursor(){
if( midcursor == 'n' || midcursor == 'N')
road4[cursormid--] = 'V';
if(midcursor == 'm' || midcursor == 'M')
road4[cursormid++] = 'V';
if(cursormid <= leftlimit){
cout << "TAKING DAMAGE turn right!!!" << endl;
life--;}
if(cursormid >= rightlimit){
cout << "TAKING DAMAGE turn left!!!!" << endl;
life--;}
if(midcursor == 'q' || midcursor == 'Q')
return -1;
if(midcursor != 'n' && midcursor != 'N' && midcursor != 'm' &&
midcursor != 'q' && midcursor != 'Q') {
cout <<" Wrong key(n, m, or q), your loosing LIFE!! " << endl;
life--;}
}[/code]


Comments

  • coder_mancoder_man Posts: 15Member
    : [b][red]This message was edited by (cc) at 2006-1-20 9:41:25[/red][/b][hr]
    : [b][red]This message was edited by (cc) at 2006-1-19 10:0:47[/red][/b][hr]
    : maybe intense is the wrong word. ( you have to try to keep the cursor inside the road by moving left or right, while the road twists)
    :
    : I need help, when i loop the road it goes extremly fast, how could i loop so its timed or slower?
    : Any suggestions how you would build a game like this greatly appreciated.
    : compiled in dev++ code
    :
    : [code]
    : #include
    : #include
    : #include
    : #include
    : #define roadwidth 50
    : using namespace std;
    :
    : int random();
    : int srandom(int i);
    : void sidewalk1();
    : void sidewalk2();
    : void sidewalk3();
    : void sidewalk4();
    : void sidewalk5();
    : void printroad();
    : void road(char a[]);
    : void setmiddle();
    : void mainroad();
    : int middlecursor();
    : // the road
    : char road1[roadwidth];
    : char road2[roadwidth];
    : char road3[roadwidth];
    : char road4[roadwidth];
    : char road5[roadwidth];
    :
    :
    : int cursormid = (roadwidth/2);
    : int middle = (roadwidth/ 2);
    : int level = 2;
    : int legalwidth = (roadwidth/ level);
    : int rightlimit = (roadwidth/ 4)* 3;
    : int leftlimit = (roadwidth/ 3);
    : char midcursor; //main controler, takes n, m and q
    : int life = roadwidth;
    : int main(){
    : srand(time(NULL));
    : int go, counter = 0;
    : cout << " N to move left, M to move right, Q to quit!!";
    : cout << "
    (press one of these letters to go)" << endl;
    :
    : while(midcursor != 'q' && midcursor != 'Q' && counter <= 100 && life != 0)
    : {
    : // some stats to show whats going on
    : counter++;
    : cout << "counter: "<< counter << endl;
    : cout << "legalwidth is: " << legalwidth << endl;
    : cout << "middle of gap is: " << middle << endl;
    : cout << "rightlimit: " << rightlimit << endl;
    : cout << "leftlimit: " << leftlimit << endl;
    : cout << "cursor position: " << cursormid << endl;
    : cout << "life left: " << life << endl;
    : cin >> midcursor;
    :
    : system("cls");
    : mainroad();
    : }
    :
    :
    :
    : cout << "Thanks for trying!" << endl;
    :
    : system("pause");
    : }
    : void mainroad(){
    :
    : sidewalk1();
    : setmiddle();
    :
    : sidewalk2();
    : setmiddle();
    :
    : sidewalk3();
    : setmiddle();
    :
    : sidewalk4();
    : setmiddle();
    : middlecursor();
    :
    : sidewalk5();
    : setmiddle();
    :
    : printroad();
    :
    : }
    :
    : void sidewalk1(){
    : int u = 0;
    : // fill the screen with "A" and call function to create gap
    : while (u != roadwidth){
    : s++;
    : road1[u] = 'A';
    : road(road1);
    :
    : }}
    : void sidewalk2(){
    : int u = 0;
    : // fill the screen with "A" and call function to create gap line2 etc
    : while (u != roadwidth){
    : s++;
    : road2[u] = 'A';
    : road(road2);}
    :
    : }
    : void sidewalk3(){
    : int u = 0;
    : // fill the screen with "A" and call function to create gap line3 etc
    : while (u != roadwidth){
    : s++;
    : road3 [u] = 'A';
    : road(road3);}
    : }
    : void sidewalk4(){
    : int u = 0;
    : // fill the screen with "A" and call function to create gap
    : while (u != roadwidth){
    : s++;
    : road4[u] = 'A';
    : road(road4);}
    : }
    : void sidewalk5(){
    : int u = 0;
    : // fill the screen with "A" and call function to create gap
    : while (u != roadwidth){
    : s++;
    : road5[u] = 'A';
    : road(road5);}
    : }
    : int random(){
    : int n = 20;
    : return rand()%n;}
    :
    : int srandom(int i){
    : return rand()%i;}
    :
    : void printroad(){
    : // print the road
    : for(int f = 0; i != roadwidth; f++){
    : cout << road1[f] ;}
    : cout << endl;
    : for(int f = 0; f != roadwidth; i++){
    : cout << road2[f] ;}
    : cout << endl;
    : for(int f = 0; f != roadwidth; i++){
    : cout << road3[f] ;}
    : cout << endl;
    : for(int f = 0; f != roadwidth; i++){
    : cout << road4[f] ;}
    : cout << endl;
    : for(int f = 0; f != roadwidth; i++){
    : cout << road5[f] ;}
    : cout << endl;
    : cout << endl;
    :
    : }
    : void road(char a[]){
    : // create the gap for road/ set the middle for the gap
    :
    : int minus1 = middle ;
    : int pluss1 = middle - 1;
    : for(int i = legalwidth/2;i > 0; i--){
    : pluss1++;
    : minus1--;
    : a[minus1] = ' ';
    : a[pluss1] = ' ';}
    : }
    : // makes the gap change position right and left
    : void setmiddle(){
    : int f = srandom(2);
    : //int addorsub = srandom(2);
    : // cout << "random 1/2: " << f << " addorsub: " << addorsub << endl;
    : if(middle > leftlimit && middle < rightlimit && f == 1)
    : middle++;
    : //middle += addorsub;
    : if(middle > leftlimit && middle < rightlimit && f == 0)
    : middle--;
    : //middle -= addorsub;
    : if(middle <= leftlimit)
    : middle++;
    : if(middle >= rightlimit)
    : middle--;
    : }
    : // controller for spaceship
    : int middlecursor(){
    : if( midcursor == 'n' || midcursor == 'N')
    : road4[cursormid--] = 'V';
    : if(midcursor == 'm' || midcursor == 'M')
    : road4[cursormid++] = 'V';
    : if(cursormid <= leftlimit){
    : cout << "TAKING DAMAGE turn right!!!" << endl;
    : life--;}
    : if(cursormid >= rightlimit){
    : cout << "TAKING DAMAGE turn left!!!!" << endl;
    : life--;}
    : if(midcursor == 'q' || midcursor == 'Q')
    : return -1;
    : if(midcursor != 'n' && midcursor != 'N' && midcursor != 'm' &&
    : midcursor != 'q' && midcursor != 'Q') {
    : cout <<" Wrong key(n, m, or q), your loosing LIFE!! " << endl;
    : life--;}
    : }[/code]
    :
    :
    : In order to slow it down.
    You may take the help of delay() function which can be found in dos.h.
    Its prototype is
    void delay(milliseconds);
    The computer waits for the given milliseconds as soon as this command is executed.


  • (cc)(cc) Posts: 23Member
    : : In order to slow it down.
    : You may take the help of delay() function which can be found in dos.h.
    : Its prototype is
    : void delay(milliseconds);
    : The computer waits for the given milliseconds as soon as this command is executed.
    :
    :
    :
    i tried this, I'm sure im missing something.
    dos.h is included in library im guessing (does cdos work?)
    when i define it the function
    void delay(int n) { /* not sure what to put in here*/ }

    If you can give me a simple example that works, Im very new and still need to be spoon feed :-)
  • coder_mancoder_man Posts: 15Member
    : : : In order to slow it down.
    : : You may take the help of delay() function which can be found in dos.h.
    : : Its prototype is
    : : void delay(milliseconds);
    : : The computer waits for the given milliseconds as soon as this command is executed.
    : :
    : :
    : :
    : i tried this, I'm sure im missing something.
    : dos.h is included in library im guessing (does cdos work?)
    : when i define it the function
    : void delay(int n) { /* not sure what to put in here*/ }
    :
    : If you can give me a simple example that works, Im very new and still need to be spoon feed :-)
    :
    Here's a code that should help you out.This program prints numbers from 1 to 10 by waiting for 1 sec after each output.
    [code]
    #include
    #include
    void main()
    {
    for(int i=1;i<=10;i++)
    {
    cout<<i;
    delay(1000);
    }
    }

  • (cc)(cc) Posts: 23Member

    [code]
    #include
    #include
    using namespace std;

    int main(){
    for(int i=1;i<=10;i++)
    {
    cout<< i;
    delay(1000);

    }
    }
    [/code]
    im getting this message:
    delay undeclared
Sign In or Register to comment.