ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • C 게임프로그래밍 7
    프로그래밍 2013. 11. 9. 19:31
    반응형
    #include 
    #include 
    #include 
    
    char bg[25][80];
    int playerX;
    int playerY;
    
    bool fire;
    int bulletX;
    int bulletY;
    
    void PrintfScreen(void);
    void ClearScreen(void);
    void GameMain(void);
    
    void KeyControl(void);
    void BulletDraw(void);
    void PlayerDraw(void);
    
    void main(void)
    {
    	playerX = 0;
    	playerY = 12;
    
    	fire = false;
    
    	for(;;)
    	{
    		ClearScreen();
    		GameMain();
    		PrintfScreen();
    	}
    }
    
    void PrintfScreen(void)
    {
    	bg[24][79] = 0;
    	printf("%s",bg);
    }
    
    
    void ClearScreen(void)
    {
    	system("cls");
    	for(int y = 0; y< 25; y++)
    	{
    		for(int x = 0; x<80;x++)
    		{
    			bg[y][x] = ' ';
    		}
    	}
    }
    
    
    
    void GameMain(void)
    {
    	KeyControl();
    	BulletDraw();
    	PlayerDraw();
    }
    
    
    void KeyControl(void)
    {
    	char pressKey;
    
    	if(kbhit())
    	{
    		pressKey = getch();
    
    		switch(pressKey)
    		{
    		case 72:
    			playerY--;
    			if(playerY < 1)
    				playerY = 1;
    				break;
    		case 75:
    			playerX--;
    			if(playerX < 0)
    				playerX = 0;
    			break;
    		case 77:
    			playerX++;
    			if(playerX > 75)
    				playerX = 75;
    			break;
    		case 80:
    			playerY++;
    			if(playerY > 23)
    				playerY = 23;
    			break;
    		case 32:
    			if(fire == false)
    			{
    				fire = true;
    				bulletX = playerX + 5;
    				bulletY = playerY;
    			}
    			break;
    
    
    		}
    	}
    }
    
    
    void BulletDraw(void)
    {
    	if(fire != true)
    	{
    		return;
    	}
    
    	bg[bulletY][bulletX - 1] = '-';
    	bg[bulletY][bulletX + 0] = '>';
    
    	bulletX++;
    	if(bulletX > 79)
    	{
    		fire = false;
    	}
    
    }
    
    void PlayerDraw(void)
    {
    	bg[playerY - 1][playerX + 0] = '-';
    	bg[playerY - 1][playerX + 1] = '>';
    	bg[playerY + 0][playerX + 1] = '>';
    	bg[playerY - 0][playerX + 2] = '>';
    	bg[playerY - 0][playerX + 3] = '>';
    	bg[playerY + 1][playerX + 0] = '-';
    	bg[playerY + 1][playerX + 1] = '>';
    
    
    }
    
    
    반응형

    '프로그래밍' 카테고리의 다른 글

    1 강. Direct3D 기본 환경 만들기  (0) 2013.11.14
    C 게임프로그래밍 8  (0) 2013.11.09
    C 게임프로그래밍 6  (0) 2013.11.09
    C 게임프로그래밍 5  (0) 2013.11.09
    C 게임프로그래밍 4  (0) 2013.11.09
Designed by Tistory.