Thread: Game problem

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    6

    Wink Game problem

    Hey I am currently trying to make a simple game using the microsoft visual c++ compiler.
    The problem I have is with level two. I currently have two circles that i want to move up and down out of holes for the stick man to jump over, I have got them moving but its interfering with the getch so the man cannot move. Any help rectifying this would be very helpful. Thanks in advance

    header files (levels.h)

    Code:
    #ifndef __levels_h__
    #define __levels_h__
    
    void level_one(void);
    void level_two(void);
    void level_three(void);
    void level_four(void);
    
    #endif

    source files levels
    Code:
    #include "graphics_lib.h"
    #include <stdio.h>
    #include <math.h>
    /*
    * The level function - starts executing here
    */
    void level_one(void)
    {    
        int x_head, y_head;
        int wall_colour;
        // TARGET VARIABLLES
        char label [3];
        int x_line;
        int y_line;
        int x_label;
        int y_label;
        int scores[5] = {50,20,10,20,50};
        int line1;
     
        wall_colour=BROWN;
        // Initialise stick man position
        x_head = 150;
        y_head = 180;
        //draw wall one
        setcolor(wall_colour);
        rectangle(470,220,520,324);
        setfillstyle(SOLID_FILL,wall_colour);
        floodfill(490,270,wall_colour);
        // Ground level
        setcolor(GREEN);
        line(0,325,1200,325);
        line(0,325,0,480);
        line(0,480,1200,480);
        line(1200,325,1200,480);
        setfillstyle(SOLID_FILL,GREEN);
        floodfill(1,326,GREEN);
        //draw wall one
        setcolor(wall_colour);
        rectangle(470,220,520,324);
        setfillstyle(SOLID_FILL,wall_colour);
        floodfill(490,270,wall_colour);
        //draw wall two
        setcolor(wall_colour);
        rectangle(970,120,1020,324);
        setfillstyle(SOLID_FILL,wall_colour);
        floodfill(990, 210,wall_colour);
        // TARGET
        for (line1 = 0; line1 < 5; line1++)
        {
      /* Calculate position of line based on the value of the line variable */
      y_line = 300;
      x_line = 550 + 84*line1;
      /* Draw the line in the right place */
      setcolor(BLUE);
      line(x_line, y_line, x_line, y_line + 25);
      /* Calculate position of lable based on the value of the line variable */
      x_label = 550 + 84*line1;
      y_label = 300;
      /* Create a string with lable in it */
      sprintf(label, "%d", scores[line1]);
      /* Use outtextxy to display the text */
      outtextxy (x_label, y_label, label);
        }
     
    }
     
    
    void level_two(int stick_man_colour)
    {
     int x_head, y_head;
     int x_moon1;
     int y_moon1;
     int x_moon2;
     int y_moon2;
     int direction = 0;
     char key_press;
     int move_value = 0;
     int level=1;
     //int stick_man_colour;
     int move = 0;
     // Prototypes 
     int jump_stickman(int x_head, int y_head, int stick_man_colour);
     int jump_stickman2(int x_head, int y_head, int stick_man_colour);
     
     
     // Initialise stick man position
     x_head = 150;
     y_head = 180;
     //Initialise moon_1 position
     x_moon1 = 495;
     y_moon1 = 390;
     //Initialise moon_2 position
     x_moon2 = 795;
     y_moon2 = 390;
     
     
     // Ground level
     setcolor(BLACK);
     line(0,325,1200,325);
     setcolor(GREEN);
     line(0,325,0,480);
     line(0,480,1200,480);
     line(1200,325,1200,480);
     setfillstyle(SOLID_FILL,GREEN);
     floodfill(1,326,GREEN);
     //draw hole one
     setcolor(BLACK);
     rectangle(470,325,520,410);
     setfillstyle(SOLID_FILL,BLACK);
     floodfill(500,350,BLACK);
     //draw hole two
     setcolor(BLACK);
     rectangle(770,325,820,410);
     setfillstyle(SOLID_FILL,BLACK);
     floodfill(800,350,BLACK);
     //cover wall one
     setcolor(BLACK);
     rectangle(470,220,520,410);
     setfillstyle(SOLID_FILL,BLACK);
     floodfill(490,270,BLACK);
     //cover wall two
     setcolor(BLACK);
     rectangle(970,120,1020,324);
     setfillstyle(SOLID_FILL,BLACK);
     floodfill(990,210,BLACK);
     //draw moon_1 
     setcolor(WHITE);
     circle(x_moon1, y_moon1,20);
     setfillstyle(SOLID_FILL, WHITE);
     fillellipse(x_moon1,y_moon1, 20, 20);
     //draw moon_2 
     setcolor(WHITE);
     circle(x_moon2, y_moon2,20);
     setfillstyle(SOLID_FILL, WHITE);
     fillellipse(x_moon2,y_moon2,20,20);
     
     
     while(1)
     {
      if(kbhit == 0)
      {
       key_press = getch();
       
       if (key_press == 75 && x_head >= 60 && level !=3)
       {
        move_value = -58; 
       }
       else if (key_press == 77 && x_head <= 412 && level !=2 && level !=3)
       { move_value = 58;
       }
       
       else if (key_press == 77 && x_head <=890 && level==2) 
       {move_value = 58;
       }
       else if (key_press ==75 && x_head <=870 && level==3)
       {  move_value = 58;
       }
       else if (key_press == 77 && x_head >=60 && level==3)
       {  move_value = -58;
       }
       else if (key_press == 72 && level==2 && x_head<=780)
       {
        x_head = jump_stickman(x_head,y_head, stick_man_colour);
        
       }
       
       else if (key_press == 80 && level==2 && x_head>=180)
       {
        x_head = jump_stickman2(x_head,y_head, stick_man_colour);
        
       }
       
       
       else if (key_press == 80 && level==3 && x_head<=780)
       {
        x_head = jump_stickman(x_head,y_head, stick_man_colour);
        
       }
       
       else if (key_press == 72 && level==3 && x_head>=180)
       {
        x_head = jump_stickman2(x_head,y_head, stick_man_colour);
        
       }
       
      } // end of kbhit
      printf("testing");
      
      
     
      //erase moon_1 
       setcolor(BLACK);
       circle(x_moon1, y_moon1,20);
       setfillstyle(SOLID_FILL, BLACK);
       fillellipse(x_moon1,y_moon1, 20, 20);
       if( direction == 0)
       {
        y_moon1 -=5;
        if( y_moon1 < 80)
         direction = 1;
       }
       else if( direction == 1)
       {
        y_moon1 +=5;
        if( y_moon1 > 380)
         direction = 0;
       }
    
    
    
       //erase moon_2 
    	setcolor(BLACK);
    	circle(x_moon2, y_moon2,20);
    	setfillstyle(SOLID_FILL, BLACK);
    	fillellipse(x_moon2,y_moon2,20,20);
    	if( direction ==0)
    		{
        y_moon2 -=5;
        if( y_moon1 < 80)
         direction = 1;
       }
       else if( direction == 1)
       {
        y_moon2 +=5;
        if( y_moon1 > 380)
         direction = 0;
       }
    	
    
     
    
    
      /* if (y_moon1 <= 390 && y_moon1 >= 150)
       {
        y_moon1 -= 5 ;
       
       if(y_moon1 > 150 )
        y_moon1 -= 5;
      */ 
       //draw moon1
       setcolor(WHITE);
       circle(x_moon1, y_moon1,20);
       setfillstyle(SOLID_FILL, WHITE);
       fillellipse(x_moon1,y_moon1, 20, 20);
       delay(5);
    
      //draw moon_2 
    	setcolor(WHITE);
    	circle(x_moon2, y_moon2,20);
    	setfillstyle(SOLID_FILL, WHITE);
    	fillellipse(x_moon2,y_moon2,20,20);
    	delay(1);
     
     }
     
     
     
     
     if (move == 32 && level==1)
     {
      move_value = 0;
      
      
            
     }
     }
     
     void level_three(void)
     {    
      int x_head, y_head;
      int x_moon1;
      int y_moon1;
      int x_moon2;
      int y_moon2;
      int x_moon3;
      int y_moon3;
      int x_cresent1;
      int y_cresent1;
      int x_cresent2;
      int y_cresent2;
      int x_cresent3;
      int y_cresent3;
      // Initialise stick man position
      x_head = 150;
      y_head = 180;
      //Initialise moon_1 position
      x_moon1 = 495;
      y_moon1 = 390;
      //Initialise cresent_1 position
      x_cresent1 =490;
      y_cresent1 =387;
      //Initialise moon_2 position
      x_moon2 = 795;
      y_moon2 = 390;
      //Initialise cresent_2 position
      x_cresent2 =790;
      y_cresent2 =387;
      //Initialise moon_3 position
      x_moon3 =150;
      y_moon3 =290;
      //Initialise cresent_3 position
      x_cresent3 =142;
      y_cresent3 =287;
      // Ground level
      setcolor(GREEN);
      line(0,325,1200,325);
      line(0,325,0,480);
      line(0,480,1200,480);
      line(1200,325,1200,480);
      setfillstyle(SOLID_FILL,GREEN);
      floodfill(1,326,GREEN);
      //cover hole one
      setcolor(GREEN);
      rectangle(470,325,520,410);
      setfillstyle(SOLID_FILL,GREEN);
      floodfill(500,350,GREEN);
      //cover hole two
      setcolor(GREEN);
      rectangle(770,325,820,410);
      setfillstyle(SOLID_FILL,GREEN);
      floodfill(800,350,GREEN);
      //cover wall one
      setcolor(BLACK);
      rectangle(470,220,520,324);
      setfillstyle(SOLID_FILL,BLACK);
      floodfill(490,270,BLACK);
      //cover wall two
      setcolor(BLACK);
      rectangle(970,120,1020,324);
      setfillstyle(SOLID_FILL,BLACK);
      floodfill(990, 210,BLACK);
      //draw moon_3 
      setcolor(WHITE);
      circle(x_moon3, y_moon3,30);
      setfillstyle(SOLID_FILL, WHITE);
      fillellipse(x_moon3,y_moon3, 30, 30);
      //draw cresent_3
      setcolor(BLACK);
      circle(x_cresent3, y_cresent3,24);
      setfillstyle(SOLID_FILL, BLACK);
      fillellipse(x_cresent3,y_cresent3, 24, 24);
    
     }
     
     
     void level_four(void)
     {
      int x_head, y_head;
      int wall_colour;
      int x_moon3;
      int y_moon3;
      int x_cresent3;
      int y_cresent3;
      wall_colour=BROWN;
      // Initialise stick man position
      x_head = 150;
      y_head = 180;
      //Initialise moon_3 position
      x_moon3 =150;
      y_moon3 =290;
      
      //Initialise cresent_3 position
      x_cresent3 =142;
      y_cresent3 =287;
      // Ground level
      setcolor(GREEN);
      line(0,325,1200,325);
      line(0,325,0,480);
      line(0,480,1200,480);
      line(1200,325,1200,480);
      setfillstyle(SOLID_FILL,GREEN);
      floodfill(1,y_head+226,GREEN);
      //draw wall one
      setcolor(wall_colour);
      rectangle(470,220,520,324);
      setfillstyle(SOLID_FILL,wall_colour);
      floodfill(480,270,wall_colour);
      //draw wall two
      setcolor(wall_colour);
      rectangle(970,120,1020,324);
      setfillstyle(SOLID_FILL,wall_colour);
      floodfill(990, 210,wall_colour);
      //cover moon_3 
      setcolor(BLACK);
      circle(x_moon3, y_moon3,30);
      setfillstyle(SOLID_FILL, BLACK);
      fillellipse(x_moon3,y_moon3,30,30);
      
      
     }
    main source file

    Code:
    
    /*
     *    A program to demonstrate simple graphical operations
     *    C Programming laboratory 1
     */
    
    /*  This line allows the compiler to understand the
     *    graphics functions
     */
    #include "graphics_lib.h"
    #include <stdio.h>
    #include <math.h>
    #define GRAVITY 9.81
    #define PI 3.14159265
    #include "levels.h"
    
     /*
     * The main function - the program starts executing here
     */
    
    // Prototypes 
    int jump_stickman(int x_head, int y_head, int stick_man_colour);
    int jump_stickman2(int x_head, int y_head, int stick_man_colour);
    
    
    
    int main(void)
    {
        /* window variables */
        int x_window=1200, y_window=480;
    
        /*movement keypress*/
        int move = 0;
        /*distance to move x axis*/
        int move_value = 0;
        int exit = 0;
    
    
    
        
        /* stick_man variables */
        int stick_man_colour;
        int x_head, y_head;
        double time;
        int initial_pos_x;
        int initial_pos_y;
        double vel_x;
        double vel_y;
        int pos_x;
        int pos_y;
        int degreeAngle;
        double radAngle;
        int velocity;
        int level=1;
        int shotstaken=0;
        int x_moon1;
        int y_moon1;
        int x_moon2;
        int y_moon2;
        int x_moon3;
        int y_moon3;
        int x_cresent1;
        int y_cresent1;
        int x_cresent2;
        int y_cresent2;
        int x_cresent3;
        int y_cresent3;
    
    
    
    
    
    
        // Allow color choice
        printf("\nChoose an integer representing the colour of your stick-man\n");
        printf("colour from the following options:\n\n");
        printf("1\tBLUE\t\t\t9\tLIGHTBLUE\n");
        printf("2\tGREEN\t\t\t10\tLIGHTGREEN\n");
        printf("3\tCYAN\t\t\t11\tLIGHTCYAN\n");
        printf("4\tRED\t\t\t12\tLIGHTRED\n");
        printf("5\tMAGENTA\t\t\t13\tLIGHTMAGENTA\n");
        printf("6\tBROWN\t\t\t14\tYELLOW\n");
        printf("7\tLIGHTGRAY\t\t15\tWHITE\n");
        printf("8\tDARKGRAY\n");
    
        printf("\nWhat coulour would you like your stick-man to be?\n");
        scanf("%d",&stick_man_colour);
    
    
        //Allow velocity choice
        printf("\nChoose your projectiles velocity\n");
        scanf("%d", &velocity);
        
        printf("\nWhat angle would you like this speed to be at?\n");
        
        printf("\nNote: Angle is measured in degrees from  the ground.");
        printf("\nValues between 89 and -89 are accepted.\n");
        printf("\nTip for inexperienced players: Angle should be more than 0 degrees");
        printf("\nYou will loose a life if it is not.\n");
        scanf("%d", &degreeAngle);
    
        radAngle= ((degreeAngle*PI)/180);
    
    
        vel_y=velocity*sin(radAngle);
        vel_x=velocity*cos(radAngle);
    
    
        // Initialise stick man position
        x_head = 150;
        y_head = 180;
    
        initwindow(x_window, y_window);
    
        //Initialise moon_1 position
        x_moon1 = 495;
        y_moon1 = 390;
    
        //Initialise cresent_1 position
        x_cresent1 =490;
        y_cresent1 =387;
    
        //Initialise moon_2 position
        x_moon2 = 795;
        y_moon2 = 390;
    
        //Initialise cresent_2 position
        x_cresent2 =790;
        y_cresent2 =387;
    
        //Initialise moon_3 position
        x_moon3 =150;
        y_moon3 =290;
    
        //Initialise cresent_3 position
        x_cresent3 =142;
        y_cresent3 =287;
    
    
    
    
        do
        {
            //    ********* DRAW STICK MAN ********
    
            setcolor(stick_man_colour);
            // draw head 
            setfillstyle(SOLID_FILL,stick_man_colour);
            circle(x_head, y_head, 40);
            fillellipse(x_head,y_head, 40,40);
            // draw body 
            line(x_head,y_head+30,x_head,y_head+85);
            // draw arms 
            line(x_head-30,y_head+60,x_head+30,y_head+60);
            // draw legs 
            //Left leg
            line(x_head,y_head+85,x_head - 20,y_head+144);
            // Right Leg
            line(x_head,y_head+85,x_head +20,y_head+144);
            /********* END OF STICK MAN ********/
            
    
        
            if (level == 1)
            {
            level_one();
            }
            
            if (level == 2)
            {
            level_two();
            }
                
            if (level == 3)
            {
            level_three();
            }
    
            if (level == 4)
            {
            level_four();
            }
    
        
    
        
                    move = getch();
    
    
                    if (move == 75 && x_head >= 60 && level !=3)
                        move_value = -58; 
                    
                    else if (move == 77 && x_head <= 412 && level !=2 && level !=3)
                        move_value = 58;
            
                    else if (move == 77 && x_head <=890 && level==2) 
                        move_value = 58;
            
                    else if (move ==75 && x_head <=870 && level==3)
                        move_value = 58;
                
                    else if (move == 77 && x_head >=60 && level==3)
                        move_value = -58;
    
    
                    
                    else if (move == 72 && level==2 && x_head<=780)
                    {
                        x_head = jump_stickman(x_head,y_head, stick_man_colour);
            
    
                    }
    
                        else if (move == 80 && level==2 && x_head>=180)
                    {
                        x_head = jump_stickman2(x_head,y_head, stick_man_colour);
            
    
                    }
    
    
                        else if (move == 80 && level==3 && x_head<=780)
                    {
                        x_head = jump_stickman(x_head,y_head, stick_man_colour);
            
    
                    }
                    
    
                            else if (move == 72 && level==3 && x_head>=180)
                    {
                        x_head = jump_stickman2(x_head,y_head, stick_man_colour);
            
    
                    }
    
    
    
                
    
            
    
            else if (move == 32 && level==1)
            {
                move_value = 0;
    
    
                    
    
    // Draw projectile
        /*        setcolor(stick_man_colour);
                initial_pos_y  = y_head;
                initial_pos_x = x_head;
                moveto(initial_pos_x, initial_pos_y);
                pos_x = initial_pos_x;
    
        
                do
                {
                    time = (pos_x - initial_pos_x) / vel_x;
                    // time taken to move to pos_x 
                    pos_y = (int) (initial_pos_y - (vel_y * time) + (GRAVITY * time * time)/2);
    
                    if (pos_y >= 325)
                        break;
                    if (pos_x >=470 && pos_x <=520 && pos_y>=220)
                        break;
                    if (pos_x>=970 && pos_x <=1020 && pos_y>=120)
                        break;
                    if (shotstaken>=3)
                        break;
                    
                    else
                        lineto(pos_x,pos_y);
    
            
    
    
        
            pos_x++;
    
            setcolor(stick_man_colour);
            // draw head 
            setfillstyle(SOLID_FILL,stick_man_colour);
            circle(pos_x, pos_y, 40);
            fillellipse(pos_x,pos_y, 40,40);
            // draw body 
            line(pos_x,pos_y+30,pos_x,pos_y+85);
            // draw arms 
            line(pos_x-30,pos_y+60,pos_x+30,pos_y+60);
            // draw legs 
            //Left leg
            line(pos_x,pos_y+85,pos_x - 20,pos_y+144);
            // Right Leg
            line(pos_x,pos_y+85,pos_x +20,pos_y+144);
    
    
            Sleep(1);
            setcolor(BLACK);
            // draw head 
            setfillstyle(SOLID_FILL,BLACK);
            circle(pos_x, pos_y, 40);
            fillellipse(pos_x,pos_y, 40,40);
            // draw body 
            line(pos_x,pos_y+30,pos_x,pos_y+85);
            // draw arms 
            line(pos_x-30,pos_y+60,pos_x+30,pos_y+60);
            // draw legs 
            //Left leg
            line(pos_x,pos_y+85,pos_x - 20,pos_y+144);
            // Right Leg
            line(pos_x,pos_y+85,pos_x +20,pos_y+144);
    
    
            
                } while (pos_x <1200);
    
                initial_pos_x =pos_x;
                initial_pos_y =pos_y;
                pos_x = x_head;
                */
    
    
    
    
                // Draw projectile
                setcolor(stick_man_colour);
                initial_pos_y  = y_head + 60;
                initial_pos_x = x_head + 30;
                moveto(initial_pos_x, initial_pos_y);
                pos_x = initial_pos_x;
        
                do
                {
                    time = (pos_x - initial_pos_x) / vel_x;
                    // time taken to move to pos_x 
                    pos_y = (int) (initial_pos_y - (vel_y * time) + (GRAVITY * time * time)/2);
    
                    if (pos_y >= 325)
                        break;
                    if (pos_x >=470 && pos_x <=520 && pos_y>=220)
                        break;
                    if (pos_x>=970 && pos_x <=1020 && pos_y>=120)
                        break;
                    if (shotstaken>=3)
                        break;
                    
                    else
                        lineto(pos_x,pos_y);
    
                    pos_x++;
                } while (pos_x <1200);
                shotstaken = shotstaken+1;
                delay(1000);
    
                setcolor(BLACK);
                initial_pos_y  = y_head + 60;
                initial_pos_x = x_head + 30;
                moveto(initial_pos_x, initial_pos_y);
                pos_x = initial_pos_x;
        
                do
                {
                    time = (pos_x - initial_pos_x) / vel_x;  // time taken to move to pos_x 
                    pos_y = (int) (initial_pos_y - (vel_y * time) + (GRAVITY * time * time)/2);
    
                    if (pos_y >= 325)
                        break;
                    if (pos_x >=470 && pos_x <=520 && pos_y >=220)
                        break;
                    if (pos_x>=970 && pos_x <=1020 && pos_y>=120)
                        break;
                    if    (level>=2)
                        break;
                    else
                        lineto(pos_x,pos_y);
    
                    pos_x++;
                } while (pos_x <1200);
    
    
    
            }
            else
                move_value = 0;
    
    
    
    
            //    ********* COVER STICK MAN ********
            setcolor(BLACK);
            // draw head 
            setfillstyle(SOLID_FILL,BLACK);
            circle(x_head, y_head, 40);
            fillellipse(x_head,y_head, 40, 40);
            // draw body 
            line(x_head,y_head+30,x_head,y_head+85);
            // draw arms 
            line(x_head-30,y_head+60,x_head+30,y_head+60);
            // draw legs 
            //Left leg
            line(x_head,y_head+85,x_head - 20,y_head+144);
            // Right Leg
            line(x_head,y_head+85,x_head +20,y_head+144);
            /********* END OF STICK MAN ********/
            
    
            x_head = x_head + move_value;
        
    
            if (level >= 2)
                shotstaken = 0; 
    
            if (shotstaken==3){
                shotstaken = 0;
                level++;
            }
    
    
            printf("\n%d %d\n",shotstaken,level);
            
    
            if (x_head>=890 && level==2)
                level++;
    
            if (x_head<=210 && level==3)
                level++;
    
            if (y_head <=110 && level==1 && move ==80)
                y_head = 180;
    
    
            
        } while (exit == 0);
    
    
        
        return 0;
    
    }
    
    
    int jump_stickman(int x_head, int y_head, int stick_man_colour)
    {
    
    
        int initial_pos_x;
        
        int initial_pos_y;
        double time;
        int pos_x;
        int pos_y;
        double vel_x;
        double vel_y;
    
        vel_x = 25;
        vel_y = 30;
    
    
                setcolor(stick_man_colour);
                initial_pos_y  = y_head;
                initial_pos_x = x_head;
                moveto(initial_pos_x, initial_pos_y);
                pos_x = initial_pos_x;
    
        
                do
                {
                    time = (pos_x - initial_pos_x) / vel_x;
                    // time taken to move to pos_x 
                    pos_y = (int) (initial_pos_y - (vel_y * time) + (GRAVITY * time * time)/2);
    
                    if (pos_y > y_head)
                        break;
            
                    
                    else
                    {
                
        
        
    
            setcolor(stick_man_colour);
            // draw head 
            setfillstyle(SOLID_FILL,stick_man_colour);
            circle(pos_x, pos_y, 40);
            fillellipse(pos_x,pos_y, 40,40);
            // draw body 
            line(pos_x,pos_y+30,pos_x,pos_y+85);
            // draw arms 
            line(pos_x-30,pos_y+60,pos_x+30,pos_y+60);
            // draw legs 
            //Left leg
            line(pos_x,pos_y+85,pos_x - 20,pos_y+144);
            // Right Leg
            line(pos_x,pos_y+85,pos_x +20,pos_y+144);
    
    
            Sleep(1);
            setcolor(BLACK);
            // draw head 
            setfillstyle(SOLID_FILL,BLACK);
            circle(pos_x, pos_y, 40);
            fillellipse(pos_x,pos_y, 40,40);
            // draw body 
            line(pos_x,pos_y+30,pos_x,pos_y+85);
            // draw arms 
            line(pos_x-30,pos_y+60,pos_x+30,pos_y+60);
            // draw legs 
            //Left leg
            line(pos_x,pos_y+85,pos_x - 20,pos_y+144);
            // Right Leg
            line(pos_x,pos_y+85,pos_x +20,pos_y+144);
            }
    
    
                pos_x++;
                } while (pos_x <1200);
                
        /*    setcolor(stick_man_colour);
            // draw head 
            setfillstyle(SOLID_FILL,stick_man_colour);
            circle(pos_x, pos_y, 40);
            fillellipse(pos_x,pos_y, 40,40);
            // draw body 
            line(pos_x,pos_y+30,pos_x,pos_y+85);
            // draw arms 
            line(pos_x-30,pos_y+60,pos_x+30,pos_y+60);
            // draw legs 
            //Left leg
            line(pos_x,pos_y+85,pos_x - 20,pos_y+144);
            // Right Leg
            line(pos_x,pos_y+85,pos_x +20,pos_y+144);
    
    */
    
    
            //    initial_pos_x =pos_x;
            //    initial_pos_y =pos_y;
            //    pos_x = x_head;
    
    
                return pos_x;
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    int jump_stickman2(int x_head, int y_head, int stick_man_colour)
    {
    
    
        int initial_pos_x;
        
        int initial_pos_y;
        double time;
        int pos_x;
        int pos_y;
        double vel_x;
        double vel_y;
    
        vel_x = -25;
        vel_y = 30;
    
    
            setcolor(stick_man_colour);
                initial_pos_y  = y_head;
                initial_pos_x = x_head;
                moveto(initial_pos_x, initial_pos_y);
                pos_x = initial_pos_x;
    
        
                do
                {
                    time = (pos_x - initial_pos_x) / vel_x;
                    // time taken to move to pos_x 
                    pos_y = (int) (initial_pos_y - (vel_y * time) + (GRAVITY * time * time)/2);
    
                    if (pos_y > y_head)
                        break;
            
                    
                    else
                    {
                
        
        
    
            setcolor(stick_man_colour);
            // draw head 
            setfillstyle(SOLID_FILL,stick_man_colour);
            circle(pos_x, pos_y, 40);
            fillellipse(pos_x,pos_y, 40,40);
            // draw body 
            line(pos_x,pos_y+30,pos_x,pos_y+85);
            // draw arms 
            line(pos_x-30,pos_y+60,pos_x+30,pos_y+60);
            // draw legs 
            //Left leg
            line(pos_x,pos_y+85,pos_x - 20,pos_y+144);
            // Right Leg
            line(pos_x,pos_y+85,pos_x +20,pos_y+144);
    
    
            Sleep(1);
    
    
            setcolor(BLACK);
            // draw head 
            setfillstyle(SOLID_FILL,BLACK);
            circle(pos_x, pos_y, 40);
            fillellipse(pos_x,pos_y, 40,40);
            // draw body 
            line(pos_x,pos_y+30,pos_x,pos_y+85);
            // draw arms 
            line(pos_x-30,pos_y+60,pos_x+30,pos_y+60);
            // draw legs 
            //Left leg
            line(pos_x,pos_y+85,pos_x - 20,pos_y+144);
            // Right Leg
            line(pos_x,pos_y+85,pos_x +20,pos_y+144);
            }
    
    
                pos_x--;
                } while (pos_x <1200);
                
        
    
                return pos_x;
    
    
    
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I have no idea what you think you mean by "interfering with the getch". Does this mean that your program no longer responds to input? Do you mean that when you start moving the circles stop?

    You need to realize that once you get into one of those do-while loops you can't get out of it until the while condition is no longer met. In general, you shouldn't have any loops inside your game loop -- each cycle through the game loop should process input if it exists, move your moving objects ever-so-slightly to a new position, then go back to the start.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    6
    Yer the game no longer responds to any input, so the man won't move, the circles continue to move though.
    Any advice on how to have them moving independently of inputs without effecting the rest of the game without using a loop then?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Remove the do and the while.

    I'm assuming you see the animation you want -- so just draw one frame every time through the loop, instead of drawing all the frames at once.

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    6
    Couldn't get it working, so decided to just have the moons move when the player does.
    Problem I have now is with the collisons between the man and the moons.
    A collision is detected if the man walks into the moons, however if he jumps into one or jumps and walks no collision is detected. I understand that because of my jump fucntion the x position isnt calculated while in jump just at the begining and end of the jump, however I cannot seem to work out why after jumping a collision is not calculated even if you then walk through a moon?

    Code:
    if (level ==2 && x_head -30 >= 785 && x_head -30 <= 805 && y_moon3 >= y_head -20 && y_moon3 <=325)
    		{
    		level =5;
    
    		}
    
    		 if (level ==2 && x_head-30 >= 495 && x_head -30 <= 515 && y_moon2 >= y_head -20 && y_moon2 <=325)
    	 	{
    			level =5;
    
    		}
    
    		 
    		if (level ==2 && x_head +30 >= 785 && x_head +30 <= 805 && y_moon3 >= y_head -20 && y_moon3 <=325)
    		{
    		level =5;
    
    		}
    
    		 if (level ==2 && x_head+30 >= 495 && x_head +30 <= 515 && y_moon2 >= y_head -20 && y_moon2 <=325)
    	 	{
    			level =5;
    
    		}

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I don't know, because I don't see any (easily-identifiable) collision-checking in the rest of your code (assuming that what you just posted is your jump-collision).

    My advice is that you need to learn a skill: put aside what you think the code does, or what you intended it to do when you wrote it, and read the code for what it actually is. Sit down with your code and a big piece of paper with your variables on it and trace out what happens as the code runs.

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    There is a lot wrong with this code and not all of it can be addressed here. I recommend purchasing a few books both on C++ programming and game programming. These will help you understand why all of the hard-coded values and hard-coded 'stuff' is never going to work. You should ideally be using sprites here which would knock the code down to a few classes and some play, stop, resume statements. Ideally your animation system will have 'tracks' that it can play. I really do not think we can help you any further in this thread without you doing some research on programming in general.

    At the bare minimum you will need:
    • Sprite system
    • Input system
    • Game logic system
    • Rendering or drawing system
    • Resource system (for loading and managing memory for the game's resources)
    Last edited by VirtualAce; 05-29-2011 at 10:39 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with my 2. game constructor problem I think
    By military genius in forum Game Programming
    Replies: 6
    Last Post: 10-10-2009, 11:56 AM
  2. Problem with my game
    By porkandbeans in forum C Programming
    Replies: 3
    Last Post: 05-25-2008, 09:13 AM
  3. A problem in a game I made.
    By eXeCuTeR in forum C Programming
    Replies: 12
    Last Post: 11-17-2007, 10:16 AM
  4. A problem with the game of life
    By uber in forum C Programming
    Replies: 4
    Last Post: 03-25-2007, 04:06 PM
  5. 24 game problem
    By Blizzarddog in forum C++ Programming
    Replies: 10
    Last Post: 11-29-2003, 09:02 AM

Tags for this Thread