ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • C 게임프로그래밍 6
    프로그래밍 2013. 11. 9. 19:30
    반응형
    #include 
    #include 
    #include 
    
    char bg[25][80];
    int playerX = 10;
    int playerY = 10;
    
    
    void PrintfScreen(void);
    void ClearScreen(void);
    void GameMain(void);
    
    void main(void)
    {
    	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)
    {
    	char pressKey=0;
    	
    
    	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;
    
    
    		}
    	}
    
    	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] = '>';
    }
    
    
    
    반응형

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

    C 게임프로그래밍 8  (0) 2013.11.09
    C 게임프로그래밍 7  (0) 2013.11.09
    C 게임프로그래밍 5  (0) 2013.11.09
    C 게임프로그래밍 4  (0) 2013.11.09
    C 게임프로그래밍 3  (0) 2013.11.09
Designed by Tistory.