ใครเก่ง C++ ช่วยหน่อยครับ ต้องส่งพรุ่งนี้ 

เริ่มโดย Tuuu, 24 กุมภาพันธ์ 2008, 13:27:28

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

Tuuu

  คือเป้นโปรเจคเกมอ่ะครับ ผมพยายามเขียนมาอาทิตย์นึงแระ แต่ยังทำไม่ได้สักที ไม่ทราบว่าใครเขียนเป็นมั่งครับ


ผมได้เกมแบบในรูปนี้อ่ะครับ โดยลูกบอลจะกระเด้งอยู่ภายในขอบ และจะเริ่มใหม่เมื่อบอลตกมาด้านล่าง
เมื่อยิงโดนบล๊อกด้านบน บล๊อกจะหาย แล้วบางบล๊อกก็จะมีสิ่งของตกลงมาเป็นไอเท็มที่ทำให้ตัวเราใหญ่ขึ้น/เล็กลง ประมาณนี้อ่ะครับ

นี่เป็นโค๊ดที่ผมเขียนเอาไว้แล้วครับ(จะได้เชื่อว่าผมพยายามแล้วจริงๆ)



#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <iostream>
#include <stdlib.h>
#include <sstream>

#include "math.h"

using namespace std;

bool isCD = false;
int start = 0;
int stop = 0;
int moveStep = 15;

int boxSize = 15, boxMid = boxSize/2,boxX = boxMid,boxY = boxMid;   //Box Size


const float DEG2RAD = 3.14159/180;

int boxMoveDirection = 2;

const int SCREEN_WIDTH = 640,
SCREEN_HEIGHT = 480;

const int TIME_RATE = 10; //50 ms
int targetSize = 100, targetMid =  targetSize/2,
targetX = (SCREEN_WIDTH/2),
targetY = (SCREEN_HEIGHT/2);

const int BALL_SPEED = 4,
ANGLE = 60,
GO_LEFT = 0x01,
GO_RIGHT = 0x02,
GO_UP = 0x10,
GO_DOWN = 0x20;

int ballX,
ballY,
ballSize,
ballDirection;

double deegree2radius(int);

//Function declaration.
void init(void);
void drawBox(int, int, int);
void handleKeyboard(unsigned char, int, int);
void handleDisplay(void);
void handleTimer(void);

double findX(const double, const double);
double findY(const double, const double);

void moveBall(int, int, int, int);






char* IntToString(int number)
{
ostringstream oss;
//Works just like cout
oss<<number;

string tmp = oss.str();
char *buff = new char[tmp.length()+1];
strcpy(buff, tmp.c_str());

//Return the underlying string
return buff;
}



////////////////////////////////////////   Text  /////////////////////////////////////////




void drawText(GLfloat x, GLfloat y, char *str)
{
int i, len;

glColor3f(1.0f, 0.0f, 0.0f);
glRasterPos2f(x, y);

for(i = 0, len = strlen(str); i < len; i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, (int)str[i]);

}

////////////////////////////////////////////////////////////////////////////////////////





////////////////////////////////////////    Box  /////////////////////////////////////////


void drawBox1(int x, int y, int size)


{
glBegin(GL_QUADS);
glColor3f(1,0.7,0.7);
glVertex2i(x-size,y+size);
glVertex2i(x+size+20,y+size);
glVertex2i(x+size+20,y-size);
glVertex2i(x-size,y-size);
glEnd();
}


void drawBox2(int x, int y, int size)


{
glBegin(GL_QUADS);
glColor3f(0,0,1);
glVertex2i(x-size,y+size);
glVertex2i(x+size+20,y+size);
glVertex2i(x+size+20,y-size);
glVertex2i(x-size,y-size);
glEnd();
}



void drawBox3(int x, int y, int size)


{
glBegin(GL_QUADS);
glColor3f(0,1.5,1.7);
glVertex2i(x-size,y+size);
glVertex2i(x+size+20,y+size);
glVertex2i(x+size+20,y-size);
glVertex2i(x-size,y-size);
glEnd();
}


void drawBox4(int x, int y, int size)


{
glBegin(GL_QUADS);
glColor3f(1,0,1.7);
glVertex2i(x-size,y+size);
glVertex2i(x+size+20,y+size);
glVertex2i(x+size+20,y-size);
glVertex2i(x-size,y-size);
glEnd();
}


////////////////////////////////////////////////////////////////////////////////////////








double degree2radius(int degree)
{
return (degree * 3.14)/180;
}

double findX(const double distance, const double angle)
{
return distance * cos(angle);
}

double findY(const double distance, const double angle)
{
return distance * sin(angle);
}

void moveBall(int* currentX, int* currentY)
{
    
double distance = ((double)BALL_SPEED) * (((double)TIME_RATE)/1000);   // Ball Speed

double offsetX = (int)(findX(distance, degree2radius(ANGLE))*100);
double offsetY = (int)(findY(distance, degree2radius(ANGLE))*100);

if(ballDirection & GO_LEFT)
(*currentX) -= (int)offsetX;
else if(ballDirection & GO_RIGHT)
(*currentX) += (int)offsetX;

if(ballDirection & GO_UP)
(*currentY) += (int)offsetY;
else if(ballDirection & GO_DOWN)
(*currentY) -= (int)offsetY;

//check ball collide scrren
if(ballX >= SCREEN_WIDTH) //when ball collide right
{
ballDirection &= 0xF0;
ballDirection |= GO_LEFT;
}

if(ballX <= 0)
{
ballDirection &= 0xF0;
ballDirection |= GO_RIGHT;
}

if(ballY >= SCREEN_HEIGHT)
{
ballDirection &= 0x0F;
ballDirection |= GO_DOWN;
}

if(ballY <= 0)
{
ballDirection &= 0x0F;
ballDirection |= GO_UP;
}
}

void init(void)
{
ballX = 220;
ballY = 10;
ballSize = 10;
//ballDirection = GO_RIGHT | GO_UP;



//////////////////////////////   Ball Move   /////////////////////////////////////

if((ANGLE < 90)||(ANGLE > 270))
ballDirection |= GO_RIGHT;
else
ballDirection |= GO_LEFT;

if(ANGLE < 180)
ballDirection |= GO_UP;
else
ballDirection |= GO_DOWN;

//////////////////////////////////////////////////////////////////////////////////////

    gluOrtho2D(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT);//Setup our viewing area
}


/////////////////////////////    Ball  /////////////////////////////////////////////

void drawBox(int x, int y, int size)

{
         glColor3f(1, 1, 0);
    
int mid = size/2;

glBegin(GL_QUADS);
glVertex2i(x - mid, y + mid);
glVertex2i(x + mid, y + mid);
glVertex2i(x + mid, y - mid);
glVertex2i(x - mid, y - mid);
glEnd();
}


//////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////   Key Board  ///////////////////////////////////////////



void handleKeyboard(unsigned char key, int x, int y)
{

switch(key){
case 'q': // Out Game
case 'Q':
exit(0);
break;

case '6' ://move right
boxX += moveStep;
if(boxX > 380){
                boxX -= moveStep;}
break;

case '4' ://move left
boxX -= moveStep;
if(boxX < -210){
                boxX += moveStep;}
break;

case 'S':
case 's':
         start =1;
         break;
        
case 'A':
case 'a':
         stop ++;
         if(stop==2){
                    stop = 0;
                     }
        
         break;

}
glutPostRedisplay();

}



////////////////////////////////////////////////////////////////////////////////////


void handleDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
if (start == 0){
              drawText(300,330,"How to");          
              drawText(250,300,"''Press S to start Game''");
              drawText(240,270,"''Presss A to Pause Game''");
              drawText(247,240,"''Presss Q to Exit Game''");
              drawText(210,30,"Keerati Tangyoocharoen 49166-0064");    
              drawText(270,15,"Copyright 2008");                       
              }
             
             
if (start == 1){
glColor3f(0.5,1,0.5);  //Color Player
glBegin(GL_QUADS); //Built Player
glVertex2i(boxX - boxMid+200,boxY + boxMid); //Point Player
glVertex2i(boxX + boxMid+270,boxY + boxMid); //Point Player
glVertex2i(boxX + boxMid+270,boxY - boxMid); //Point Player
glVertex2i(boxX - boxMid+200,boxY - boxMid); //Point Player
glEnd();


        drawBox1(100,200,10);  //Built Box1
        drawBox2(450,450,10);  //Built Box2
        drawBox3(450,200,10);  //Built Box3
        drawBox4(100,450,10);  //Built Box4       




        if(stop ==0){
                moveStep = 15;
                }
        if(stop == 1){
                moveStep = 0;
                }
drawBox(ballX, ballY, ballSize);
}
glFlush();
}
void handleIdle(){
int boxLeft = boxX - boxMid,
boxRight = boxX + boxMid,
boxTop = boxY + boxMid,
boxButtom = boxY - boxMid;
int targetLeft = targetX - targetMid,
targetRight = targetX + targetMid,
targetTop = targetY + targetMid,
targetButtom = targetY - targetMid;
if((boxRight>targetLeft)&&(boxLeft<targetRight)){
if((boxTop > targetButtom)&&(boxButtom < targetTop))
isCD = true;
else
isCD = false;
}
else{
isCD = false;
}
}


void handleTimer(int value)
{    if(stop==0){
moveBall(&ballX, &ballY);
    }
glutPostRedisplay();//Refresh the screen

glutTimerFunc(TIME_RATE, handleTimer, 0);
}






int main(int argc, char ** argv)
{
glutInit(&argc, argv);
    glutInitWindowSize(640, 480);
    glutInitWindowPosition(10, 50);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutCreateWindow("Get A !!!");
    init();

glutKeyboardFunc(handleKeyboard);
    glutDisplayFunc(handleDisplay);
glutTimerFunc(0, handleTimer, 0);
glutIdleFunc(handleIdle);
    glutMainLoop();
}



รบกวนช่วยหน่อยนะครับ    :-* :-* :-* :-*

Tuuu

สงสัยจะไม่มีคนตอบจริงๆ
เฮ้ออ......
ผมผิดเองที่โง่อ่ะครับ

เครียดหว่ะ


เดี๋ยวจะบอกว่าชื่ออะไร

คือถ้ายังไม่มีคนตอบให้ ก็อย่าไปประชดประชันขนาดนั้นคับ

เด๋วถ้ามีคนตอบได้ เขาก็เข้ามาตอบเองล่ะคับ

ว่าแต่ อ่านได้ หน่อยหนึ่ง งงเต็ก ไปต่อไม่เป็นเหมือนกันคร๊าบบบบบบบบ
[direct=http://www.thaiseoboard.com/index.php/topic,17065.0.html]เศรษฐีผู้รวยด้วยหนูตายหนึ่งตัว[/direct][direct=http://xn--82ca6ayaze0a4a4hsa2lj6l.blogspot.com/]บริการรีวิว เพิ่มคำวิจารณ์ 5 ดาวแฟนเพจ[/direct][direct=http://xn--12cbpr2dl9a3a2f5cd0a8me2dvco.blogspot.com/]ขายชิบ ไพ่เท็กซัส[/direct]
เกิดในที่...ที่ดี...นั้นดีแน่ 
เกิดในที่...ที่แย่...ก็ดีได้  
เกิดที่ดี...แล้วแย่...มีถมไป  
เกิดที่ไหน...ก็ดีได้ถ้าใฝ่ดี

มอมแมม

ไม่มีคนตอบ = ไม่มีคนรู้ เพราะฉะนั้นรอต่อไปจนกว่าจะมีผู้รู้มาตอบ

แนะนำให้ไปโพสถามในบอร์ดเกี่ยวกับ ภาษา C หรือ บอร์ดที่เกี่ยวกับ โปรแกรมมิ่ง โดยตรง จะได้คำตอบไวกว่า แต่ถามในแนวให้เขาแนะวิธี ถ้าขอ ให้เขาเขียน code ให้คงยาก หรืออาจจะเอา code ไปโชว์ แล้วถามว่าผิดพลาดตรงไหน หรือขาดส่วนไหน เป็นเช่นนั้นแล

jonu2528

C++ พื้นฐานพอช่วยได้ครับ ::) ::)



แต่ C++ Object นี่ไม่เคยเขียนเลยครับ :P :P
[direct=http://riwwee.com/view-4501.html]รีวิว cloud mining คือ อะไร? ขุด bitcoin ทำกันยังไง step by Step[/direct]

alcoholik

ขี้เกียจอ่านโค้ดครับ

แนะนำ DirectX SDK ง่ายดีนะ C++ ด้วย

ในเมื่อลองทำแล้วก็น่าจะได้แล้วนี่ ถ้าติด bug ถามมาเป็นข้อ ๆ ดีกว่าครับ จะได้ช่วยถูก

เอาโค้ดมาแปะหมดงี้ขี้เกียจดูครับ
คนเจ้าปัญญา : พอพบปัญหาอะไรก็วางก่อน พอเป็นอิสระมีอำนาจเหนือกว่าปัญหาแล้ว จึงจัดการกับปัญหานั้นอย่างเหนือชั้น

NineTua

พอได้ป่ะ
คอมเม้นให้ด้วย
เผื่อไม่รู้ว่าตรงไหนคืออะไร



#ifdef __APPLE__
   #include <OpenGL/OpenGL.h>
   #include <GLUT/glut.h>
#else
   #include <GL/glut.h>
#endif

#include <iostream>
#include <stdlib.h>\

#include <sstream>
#include "math.h"

using namespace std;

const int   SCREEN_WIDTH = 640,
         SCREEN_HEIGHT = 480;

int playerW = 100,
    playerH = 10,
    playerX = SCREEN_WIDTH/2,
    playerY = playerH/2,
    playerT = playerY+(playerH/2),
    playerB = playerY-(playerH/2),
    playerR  = playerX+(playerW/2),
    playerL = playerX-(playerW/2);

   
int ballW = 10,
    ballH = 10,
    ballX = playerX,
    ballY = playerT+(ballH/2),
    ballT = ballY+(ballH/2),
    ballB = ballY-(ballH/2),
    ballR = ballX+(ballW/2),
    ballL = ballX-(ballW/2);
   
int box1W = 70,
    box1H = 20,
    box1X = 180,
    box1Y = 400,
    box1T = box1Y+(box1H/2),
    box1B = box1Y-(box1H/2),
    box1R = box1X+(box1W/2),
    box1L = box1X-(box1W/2);
   
int box2W = 70,
    box2H = 20,
    box2X = 270,
    box2Y = 400,
    box2T = box2Y+(box2H/2),
    box2B = box2Y-(box2H/2),
    box2R = box2X+(box2W/2),
    box2L = box2X-(box2W/2);

int box3W = 70,
    box3H = 20,
    box3X = 360,
    box3Y = 400,
    box3T = box3Y+(box3H/2),
    box3B = box3Y-(box3H/2),
    box3R = box3X+(box3W/2),
    box3L = box3X-(box3W/2);

int box4W = 70,
    box4H = 20,
    box4X = 450,
    box4Y = 400,
    box4T = box4Y+(box4H/2),
    box4B = box4Y-(box4H/2),
    box4R = box4X+(box4W/2),
    box4L = box4X-(box4W/2);
   
int moveStep = 60;
int ballSpeed = 5;
int start = 0;
bool ballMove = false;
int angle = 45;
int ballState = 0; //0 is left-up, 1 is left-down, 2 is right-up, 3 is right-down
int winer = 0;

void update(void)
{
    playerT = playerY+(playerH/2);
    playerB = playerY-(playerH/2);
    playerR  = playerX+(playerW/2);
    playerL = playerX-(playerW/2);

    ballT = ballY+(ballH/2);
    ballB = ballY-(ballH/2);
    ballR = ballX+(ballW/2);
    ballL = ballX-(ballW/2);
   
    box1T = box1Y+(box1H/2);
    box1B = box1Y-(box1H/2);
    box1R = box1X+(box1W/2);
    box1L = box1X-(box1W/2);
   
    box2T = box2Y+(box2H/2);
    box2B = box2Y-(box2H/2);
    box2R = box2X+(box2W/2);
    box2L = box2X-(box2W/2);

    box3T = box3Y+(box3H/2);
    box3B = box3Y-(box3H/2);
    box3R = box3X+(box3W/2);
    box3L = box3X-(box3W/2);

    box4T = box4Y+(box4H/2);
    box4B = box4Y-(box4H/2);
    box4R = box4X+(box4W/2);
    box4L = box4X-(box4W/2);
}

////////////////////////////////////////   Text  /////////////////////////////////////////
void drawText(GLfloat x, GLfloat y, char *str)
{
   int i, len;

   glColor3f(1.0f, 0.0f, 0.0f);
   glRasterPos2f(x, y);

   for(i = 0, len = strlen(str); i < len; i++)
      glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, (int)str);

}
////////////////////////////////////////////////////////////////////////////////////////





///////////////////////////////////   Key Board  ///////////////////////////////////////////
void handleKeyboard(unsigned char key, int x, int y)
{

   switch(key){
   case 'q': // Out Game
   case 'Q':
      exit(0);
      break;
   case '6' ://move right
        if(playerX < (640-(playerW/2))){
            playerX += moveStep;
            if(!ballMove)
                ballX = playerX;
            if(playerX > (640-(playerW/2)))
                playerX = 640-(playerW/2);
        }
      break;
   case '4' ://move left
      if(playerX > playerW/2){
            playerX -= moveStep;
            if(!ballMove)
                ballX = playerX;
            if(playerX < (playerW/2))
                playerX = playerW/2;
        }
      break;
   case 'S':
   case 's':{
              start =1;
              winer = 0;
              playerX = SCREEN_WIDTH/2;
              playerY = playerH/2;
              ballX = playerX;
              ballY = playerT+(ballH/2);
              box1X = 180;
              box1Y = 400;
              box2X = 270;
              box2Y = 400;
              box3X = 360;
              box3Y = 400;
              box4X = 450;
              box4Y = 400;
         }
         break;
     case 32 :{
          if(!ballMove)
              ballMove = true;
         }
         break;
   }
   glFlush();
   glutPostRedisplay();
   glutSwapBuffers();
   }
////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////    Ball  /////////////////////////////////////////////
void drawball()
{
    glColor3f(1, 1, 1);
   glBegin(GL_QUADS);
      glVertex2i(ballL,ballT);
      glVertex2i(ballR,ballT);
      glVertex2i(ballR,ballB);
      glVertex2i(ballL,ballB);
   glEnd();
}
//////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////   Player  /////////////////////////////////////////////
void player()
{
    glColor3f(0, 1, 0);
   glBegin(GL_QUADS);
      glVertex2i(playerL,playerT);
      glVertex2i(playerR,playerT);
      glVertex2i(playerR,playerB);
      glVertex2i(playerL,playerB);
   glEnd();
}
//////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////   Box1 /////////////////////////////////////////////
void box1()
{
    glColor3f(0.5, 1, 0.5);
   glBegin(GL_QUADS);
      glVertex2i(box1L,box1T);
      glVertex2i(box1R,box1T);
      glVertex2i(box1R,box1B);
      glVertex2i(box1L,box1B);
   glEnd();
}
//////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////   Box2  /////////////////////////////////////////////
void box2()
{
    glColor3f(1, 1, 0.4);
   glBegin(GL_QUADS);
      glVertex2i(box2L,box2T);
      glVertex2i(box2R,box2T);
      glVertex2i(box2R,box2B);
      glVertex2i(box2L,box2B);
   glEnd();
}
//////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////   Box3  /////////////////////////////////////////////
void box3()
{
    glColor3f(1, 0.5, 0);
   glBegin(GL_QUADS);
      glVertex2i(box3L,box3T);
      glVertex2i(box3R,box3T);
      glVertex2i(box3R,box3B);
      glVertex2i(box3L,box3B);
   glEnd();
}
//////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////   Box4 /////////////////////////////////////////////
void box4()
{
    glColor3f(1, 0.5, 0.5);
   glBegin(GL_QUADS);
      glVertex2i(box4L,box4T);
      glVertex2i(box4R,box4T);
      glVertex2i(box4R,box4B);
      glVertex2i(box4L,box4B);
   glEnd();
}
//////////////////////////////////////////////////////////////////////////////////////////


void handleDisplay(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   if (start == 0){
              drawText(40,450,"@  @  @    G    A    M    E    ::    B    A    L    L    @  @  @");
              drawText(275,310,"How to...");           
              drawText(200,270,"''Press S to Start Game''");
              drawText(200,245,"''Press Q to Exit Game''");
              drawText(160,220,"''Press Space Bar to Play Game''");
              drawText(155,190,"''4 = Turn Left  ,  6 = Turn Right''");
              drawText(140,35,"Keerati Tangyoocharoen 49166-0064");     
              drawText(250,10,"Copyright 2008");                       
              }
   if (start == 1){
        drawball();
        player();
        box1();
        box2();
        box3();
        box4();
    }
   
    if (start == 2){
        ballMove = false;
        drawText((SCREEN_WIDTH/2)-70,SCREEN_HEIGHT/2,"''You Win''"); 
        drawText(200,10,"Press ''S'' To  Continue");
    }
   glFlush();
   glutPostRedisplay();
   glutSwapBuffers();
}




void init(void)
{
    gluOrtho2D(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT);//Setup our viewing area
}



void handleTimer(int value)
{
    update();
    if(ballMove)
    {
        if(angle == 45)
        {
            switch(ballState){
            case 0 : //Left Up
                 {
                     ballX -= ballSpeed;
                     ballY += ballSpeed;
                 }
            break;
            case 1 : //Left Down
                 {
                     ballX -= ballSpeed;
                     ballY -= ballSpeed;
                 }
            break;
            case 2 : //Right Up
                 {
                     ballX += ballSpeed;
                     ballY += ballSpeed;
                 }
            break;
            case 3 : //Right Down
                 {
                     ballX += ballSpeed;
                     ballY -= ballSpeed;
                 }
            break;
            }
        }
        update();
        ///////////// collision windows ////////////////
        if(ballL<=0)
        {
            if(ballState == 0)
                ballState = 2;
            else if(ballState == 1)
                ballState = 3;
        }
        if(ballR>=640)
        {
            if(ballState == 2)
                ballState = 0;
            else if(ballState == 3)
                ballState = 1;
        }
        if(ballT >= 480)
        {
            if(ballState == 0)
                ballState = 1;
            else if(ballState == 2)
                ballState = 3;
        }
        if(ballB <= 0)
        {
            ballMove = false;
            ballX = playerX;
            ballY = playerT+(ballH/2);
            ballState = 0;
        }
       
        /////////////// collision player ///////////////
        if((ballB <= playerT)&&(ballL <= playerR)&&(ballR >= playerL))
        {
            if(ballState == 1)
                ballState = 0;
            else if(ballState == 3)
                ballState = 2;
        }
        /////////////// collision box1 /////////////////////
        if((ballB <= box1T)&&(ballL <= box1R)&&(ballR >= box1L)&&(ballT >= box1B))
        {
            if(ballB == box1T)
            {
                if(ballState == 1)
                     ballState = 0;
                else if(ballState == 3)
                     ballState = 2;
            }
            else if(ballL == box1R)
            {
                if(ballState == 1)
                     ballState = 3;
                else if(ballState == 0)
                     ballState = 2;
            }
            else if(ballR == box1L)
            {
                if(ballState == 3)
                     ballState = 1;
                else if(ballState == 2)
                     ballState = 0;
            }
            else
            {
                if(ballState == 2)
                     ballState = 3;
                else if(ballState == 0)
                     ballState = 1;
            }
            box1X = -box1W;
            box1Y = -box1H;
            winer++;
        }
        /////////////// collision box2 /////////////////////
        if((ballB <= box2T)&&(ballL <= box2R)&&(ballR >= box2L)&&(ballT >= box2B))
        {
            if(ballB == box2T)
            {
                if(ballState == 1)
                     ballState = 0;
                else if(ballState == 3)
                     ballState = 2;
            }
            else if(ballL == box2R)
            {
                if(ballState == 1)
                     ballState = 3;
                else if(ballState == 0)
                     ballState = 2;
            }
            else if(ballR == box2L)
            {
                if(ballState == 3)
                     ballState = 1;
                else if(ballState == 2)
                     ballState = 0;
            }
            else
            {
                if(ballState == 2)
                     ballState = 3;
                else if(ballState == 0)
                     ballState = 1;
            }
            box2X = -box2W;
            box2Y = -box2H;
            winer++;
        }
        /////////////// collision box1 /////////////////////
        if((ballB <= box3T)&&(ballL <= box3R)&&(ballR >= box3L)&&(ballT >= box3B))
        {
            if(ballB == box3T)
            {
                if(ballState == 1)
                     ballState = 0;
                else if(ballState == 3)
                     ballState = 2;
            }
            else if(ballL == box3R)
            {
                if(ballState == 1)
                     ballState = 3;
                else if(ballState == 0)
                     ballState = 2;
            }
            else if(ballR == box3L)
            {
                if(ballState == 3)
                     ballState = 1;
                else if(ballState == 2)
                     ballState = 0;
            }
            else
            {
                if(ballState == 2)
                     ballState = 3;
                else if(ballState == 0)
                     ballState = 1;
            }
            box3X = -box3W;
            box3Y = -box3H;
            winer++;
        }
        /////////////// collision box4 /////////////////////
        if((ballB <= box4T)&&(ballL <= box4R)&&(ballR >= box4L)&&(ballT >= box4B))
        {
            if(ballB == box4T)
            {
                if(ballState == 1)
                     ballState = 0;
                else if(ballState == 3)
                     ballState = 2;
            }
            else if(ballL == box4R)
            {
                if(ballState == 1)
                     ballState = 3;
                else if(ballState == 0)
                     ballState = 2;
            }
            else if(ballR == box4L)
            {
                if(ballState == 3)
                     ballState = 1;
                else if(ballState == 2)
                     ballState = 0;
            }
            else
            {
                if(ballState == 2)
                     ballState = 3;
                else if(ballState == 0)
                     ballState = 1;
            }
            box4X = -box4W;
            box4Y = -box4H;
            winer++;
        }
    }
    //////////////winer/////////////////////////
    if(winer == 4)
        start = 2;
   glutPostRedisplay();
   glutTimerFunc(10, handleTimer, 0);
}





int main(int argc, char ** argv)
{
   glutInit(&argc, argv);
    glutInitWindowSize(640, 480);
    glutInitWindowPosition(100, 100);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
    glutCreateWindow("G    a    m    e     .....      Goo !!!!!");
    init();
   glutKeyboardFunc(handleKeyboard);
    glutDisplayFunc(handleDisplay);
   glutTimerFunc(0, handleTimer, 0);
    glutMainLoop();
}







เบื่อพวกอวดเก่ง เบื่อพวกมีแต่ราคาคุย เบื่อพวกขี้โม้ เบื่อพวกทำไมไม่ได้แล้วอ้างนู่นอ้างนี่..

เบื่อพวกก๊อปเว็บ อย่าคิดว่าตามไม่เจอนะฮะ :)