Car Application

This is a discussion on Car Application within the C++ Programming forums, part of the General Programming Boards category; Hi I am attempting to make an introduction to an 80's line style game ala paperboy. What si supposed to ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    6

    Unhappy Car Application

    Hi

    I am attempting to make an introduction to an 80's line style game ala paperboy.
    What si supposed to happen is the 'car' doesnt move but the buildings made of boxes move and constantly loop. What currently happens is the application just quits , could you help please , cheers.

    Code:
    #include <iostream>
    #include <graphics.h>
    #include <iostream>
    #include <math.h>
    
    using namespace std;
    
    
    
    
    
    
    
    struct Vertex {
        double x, y, z;
        // need default values for constructor to work in Face struct...
        Vertex(double _x=0, double _y=0,double _z=0) {
            x = _x;
            y = _y;
            z = _z;
        }
    };
    
    struct Face {
        // start top-left and go anti-clockwise;
        Vertex vertices[4];
        Vertex v0, v1, v2, v3;
    
        Face(Vertex _pts[]) {
            for (int i = 0; i< 4; i++)
                vertices[i] = _pts[i];
            v0 = vertices[0];
            v1 = vertices[1];
            v2 = vertices[2];
            v3 = vertices[3];
        }
        void drawBody() {
            moveto(v0.x,v0.y);
            lineto(v1.x, v1.y);
            lineto(v2.x, v2.y);
            lineto(v3.x, v3.y);
            lineto(v0.x, v0.y);
        }
    };
    
    int main() {
    initwindow(640, 480, "Rectangle");
    Vertex pts[] = {Vertex(100,100,0), Vertex(100, 200, 0), Vertex(200, 200, 0), Vertex(200, 100, 0)};
    Face f = Face(pts);
    f.drawBody();
    
        int centreX, centreY;
        centreX = 100;
        float angle = -M_PI_2;
        float dTheta = M_PI/10;
        int myColour = 1;
        centreY = 300 + 50*sin(angle);
        circle(centreX, centreY, 1);
        setlinestyle(0, 1, 1);
        setfillstyle(1, 15);
        int stangle = 0;  // stangle == start angle
    
     for (int i = 0; i < 4; i++){
            pieslice(centreX, centreY,stangle + i*90, stangle+30+(i*90), 40);
     }
    
    while (!kbhit( )) {
    	delay(200);
            cleardevice();
            angle += dTheta;
            stangle -= 5;
            if (myColour == 15)
            myColour = 4;
            else myColour = 15;
            setfillstyle(1, myColour);
            for (int i = 0; i < 4; i++){
            pieslice(centreX, centreY,stangle + i*90, stangle+30+(i*90), 40);
            pieslice(centreX+105, centreY,stangle + i*90, stangle+30+(i*90), 40);
            }
    closegraph();
    return 0;
    }
     }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    It seems to me like it quits as soon as you press a key....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    Its supposed to do this for now , right now its quitting when you press nothing

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    Yeah, that's what crappy indentation buys you - frustration and confusion.
    Code:
        while (!kbhit()) {
            delay(200);
            cleardevice();
            angle += dTheta;
            stangle -= 5;
            if (myColour == 15)
                myColour = 4;
            else
                myColour = 15;
            setfillstyle(1, myColour);
            for (int i = 0; i < 4; i++) {
                pieslice(centreX, centreY, stangle + i * 90,
                         stangle + 30 + (i * 90), 40);
                pieslice(centreX + 105, centreY, stangle + i * 90,
                         stangle + 30 + (i * 90), 40);
            }
            closegraph();
            return 0;
        }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    I'm new to c++ how do i fix this?

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    Huh?

    Fix what?

    The indentation, so that you might have a chance of figuring out the program flow from just looking at the code?

    Or do you need to know why a return statement inside a while loop causes that loop to end immediately?

    Or maybe read this
    A development process
    Since you're "new", you should NOT be writing so much code that you have NO idea what might happen if you try to run it.

    Write, compile, test WITHIN your ability to predict the outcome. If you write too much code and you're completely lost, then you simply wrote too much code at once. Slow the pace and write smaller parts and make sure you understand what really happens.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c program help :>
    By n2134 in forum C Programming
    Replies: 9
    Last Post: 02-06-2010, 11:12 AM
  2. Replies: 0
    Last Post: 11-22-2009, 10:23 AM
  3. OpenGL coordinates
    By Da-Nuka in forum Game Programming
    Replies: 5
    Last Post: 01-10-2005, 10:26 AM
  4. i really need help here
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 04-09-2002, 10:47 PM
  5. I need help with an algorithm
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 04-07-2002, 07:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21