응애맘마조

태양계2 본문

공부/2D과제

태양계2

TH.Wert 2022. 12. 22. 13:02

저번 태양계 과제에 이어서 더 꾸미는 것이 과제였습니다.

 

 

 

 

실행 영상입니다.

#include "framework.h"

MainGame::~MainGame()
{
   
}

void MainGame::Init()
{
    //MemDc 메모리상의 dc를 하나 더 추가
    HBITMAP	 m_hOldBitmap, m_hBitmap;
    HDC	hdc = GetDC(g_hwnd); //기존 핸들
    g_MemDC = CreateCompatibleDC(hdc);
    m_hBitmap = CreateCompatibleBitmap(hdc, 800, 600);
    m_hOldBitmap = (HBITMAP)SelectObject(g_MemDC, m_hBitmap);
    ReleaseDC(g_hwnd, hdc);

    planet[0].SetWorldPos(Vector2(400.0f, 300.0f));
    planet[0].scale.x = 100.0f;
    planet[0].scale.y = 100.0f;
    planet[0].rotation = 0.0f;
    planet[0].isAxis = true;

    planet[1].SetLocalPos(Vector2(0, -150.0f));
    planet[1].scale.x = 50.0f;
    planet[1].scale.y = 50.0f;
    planet[1].rotation = 0.0f;
    planet[1].isAxis = true;
    
    planet[2].SetLocalPos(Vector2(150.0f, 0));    
    planet[2].scale.x = 50.0f;
    planet[2].scale.y = 50.0f;
    planet[2].rotation = 0.0f;
    planet[2].isAxis = true;

    planet[3].SetLocalPos(Vector2(0, 150.0f));
    planet[3].scale.x = 50.0f;
    planet[3].scale.y = 50.0f;
    planet[3].rotation = 0.0f;
    planet[3].isAxis = true;

    planet[4].SetLocalPos(Vector2(-150.0f, 0));
    planet[4].scale.x = 50.0f;
    planet[4].scale.y = 50.0f;
    planet[4].rotation = 0.0f;
    planet[4].isAxis = true;

    planet[5].SetLocalPos(Vector2(0, -40.0f));
    planet[5].scale.x = 20.0f;
    planet[5].scale.y = 20.0f;
    planet[5].rotation = 0.0f;
    planet[5].isAxis = true;

    planet[6].SetLocalPos(Vector2(40.0f, 20.0f));
    planet[6].scale.x = 20.0f;
    planet[6].scale.y = 20.0f;
    planet[6].rotation = 0.0f;
    planet[6].isAxis = true;

    planet[7].SetLocalPos(Vector2(-40.0f, 20.0f));
    planet[7].scale.x = 20.0f;
    planet[7].scale.y = 20.0f;
    planet[7].rotation = 0.0f;
    planet[7].isAxis = true;

    planet[8].SetLocalPos(Vector2(0, -40.0f));
    planet[8].scale.x = 20.0f;
    planet[8].scale.y = 20.0f;
    planet[8].rotation = 0.0f;
    planet[8].isAxis = true;

    planet[9].SetLocalPos(Vector2(40.0f, 20.0f));
    planet[9].scale.x = 20.0f;
    planet[9].scale.y = 20.0f;
    planet[9].rotation = 0.0f;
    planet[9].isAxis = true;

    planet[10].SetLocalPos(Vector2(-40.0f, 20.0f));
    planet[10].scale.x = 20.0f;
    planet[10].scale.y = 20.0f;
    planet[10].rotation = 0.0f;
    planet[10].isAxis = true;

    planet[11].SetLocalPos(Vector2(0, -40.0f));
    planet[11].scale.x = 20.0f;
    planet[11].scale.y = 20.0f;
    planet[11].rotation = 0.0f;
    planet[11].isAxis = true;

    planet[12].SetLocalPos(Vector2(40.0f, 20.0f));
    planet[12].scale.x = 20.0f;
    planet[12].scale.y = 20.0f;
    planet[12].rotation = 0.0f;
    planet[12].isAxis = true;

    planet[13].SetLocalPos(Vector2(-40.0f, 20.0f));
    planet[13].scale.x = 20.0f;
    planet[13].scale.y = 20.0f;
    planet[13].rotation = 0.0f;
    planet[13].isAxis = true;

    planet[14].SetLocalPos(Vector2(0, -40.0f));
    planet[14].scale.x = 20.0f;
    planet[14].scale.y = 20.0f;
    planet[14].rotation = 0.0f;
    planet[14].isAxis = true;

    planet[15].SetLocalPos(Vector2(40.0f, 20.0f));
    planet[15].scale.x = 20.0f;
    planet[15].scale.y = 20.0f;
    planet[15].rotation = 0.0f;
    planet[15].isAxis = true;

    planet[16].SetLocalPos(Vector2(-40.0f, 20.0f));
    planet[16].scale.x = 20.0f;
    planet[16].scale.y = 20.0f;
    planet[16].rotation = 0.0f;
    planet[16].isAxis = true;

    planet[17].SetLocalPos(Vector2(0, -300.0f));
    planet[17].scale.x = 70.0f;
    planet[17].scale.y = 70.0f;
    planet[17].rotation = 0.0f;
    planet[17].isAxis = true;

    planet[18].SetLocalPos(Vector2(300.0f, 0));
    planet[18].scale.x = 70.0f;
    planet[18].scale.y = 70.0f;
    planet[18].rotation = 0.0f;
    planet[18].isAxis = true;

    planet[19].SetLocalPos(Vector2(0, 300.0f));
    planet[19].scale.x = 70.0f;
    planet[19].scale.y = 70.0f;
    planet[19].rotation = 0.0f;
    planet[19].isAxis = true;

    planet[20].SetLocalPos(Vector2(-300.0f, 0));
    planet[20].scale.x = 70.0f;
    planet[20].scale.y = 70.0f;
    planet[20].rotation = 0.0f;
    planet[20].isAxis = true;

    planet[21].SetLocalPos(Vector2(35.0f, 35.0f));
    planet[21].scale.x = 70.0f;
    planet[21].scale.y = 70.0f;
    planet[21].rotation = 0.0f;
    planet[21].isAxis = true;

    planet[22].SetLocalPos(Vector2(765.0f, 35.0f));
    planet[22].scale.x = 70.0f;
    planet[22].scale.y = 70.0f;
    planet[22].rotation = 0.0f;
    planet[22].isAxis = true;

    planet[23].SetLocalPos(Vector2(35.0f, 565.0f));
    planet[23].scale.x = 70.0f;
    planet[23].scale.y = 70.0f;
    planet[23].rotation = 0.0f;
    planet[23].isAxis = true;

    planet[24].SetLocalPos(Vector2(765.0f, 565.0f));
    planet[24].scale.x = 70.0f;
    planet[24].scale.y = 70.0f;
    planet[24].rotation = 0.0f;
    planet[24].isAxis = true;

    for (int i = 1; i < 5; i++)
    {
        planet[i].SetParentRT(planet[0]);
    }

    for (int i = 5; i < 8; i++)
    {
        planet[i].SetParentRT(planet[1]);
    }

    for (int i = 8; i < 11; i++)
    {
        planet[i].SetParentRT(planet[2]);
    }

    for (int i = 11; i < 14; i++)
    {
        planet[i].SetParentRT(planet[3]);
    }

    for (int i = 14; i < 17; i++)
    {
        planet[i].SetParentRT(planet[4]);
    }

    for (int i = 17; i < 21; i++)
    {
        planet[i].SetParentRT(planet[0]);
    }
}

void MainGame::Update()
{
    if (INPUT->KeyPress('5'))
    {
        planet[0].rotation += 120.0f * ToRadian * DELTA;
    }
    if (INPUT->KeyPress('6'))
    {
        planet[0].rotation -= 120.0f * ToRadian * DELTA;
    }

    planet[0].Update();

    for (int i = 1; i < 5; i++)
    {
        planet[i].rotation += 250.0f * ToRadian * DELTA;
        planet[i].rotation2 += 120.0f * ToRadian * DELTA;
        planet[i].Update();
    }

    for (int i = 5; i < 8; i++)
    {
       planet[i].rotation += 3000.0f * ToRadian * DELTA;
       planet[i].rotation2 += 120.0f * ToRadian * DELTA;
       planet[i].Update();
    }

    for (int i = 8; i < 11; i++)
    {
        planet[i].rotation += 3000.0f * ToRadian * DELTA;
        planet[i].rotation2 += 120.0f * ToRadian * DELTA;
        planet[i].Update();
    }

    for (int i = 11; i < 14; i++)
    {
        planet[i].rotation += 3000.0f * ToRadian * DELTA;
        planet[i].rotation2 += 120.0f * ToRadian * DELTA;
        planet[i].Update();
    }

    for (int i = 14; i < 17; i++)
    {
        planet[i].rotation += 3000.0f * ToRadian * DELTA;
        planet[i].rotation2 += 120.0f * ToRadian * DELTA;
        planet[i].Update();
    }

    for (int i = 17; i < 21; i++)
    {
        planet[i].rotation -= 3000.0f * ToRadian * DELTA;
        planet[i].rotation2 -= 120.0f * ToRadian * DELTA;
        planet[i].Update();
    }

    for (int i = 21; i < 25; i++)
    {
        planet[i].rotation -= 300.0f * ToRadian * DELTA;
        planet[i].Update();
    }

    //키가 눌렸을 때 wm_paint 를 발생 시켜라
    InvalidateRect(g_hwnd, NULL, false);
}

void MainGame::Render()
{
    PAINTSTRUCT ps;
    //hdc-> 도화지
    g_hdc = BeginPaint(g_hwnd, &ps);

    //바탕색 깔기
    PatBlt(g_MemDC, 0, 0, 800, 600, WHITENESS);

    //현재 FPS 출력
    string FPS = "FPS:" + to_string(TIMER->GetFPS());
    TextOutA(g_MemDC, 0, 0, FPS.c_str(), FPS.size());

    for (int i = 0; i < 25; i++)
    {
        planet[i].Render();
    }

    //고속 복사 g_MemDC에서 g_hdc로
    BitBlt(g_hdc, 0, 0, 800, 600, g_MemDC, 0, 0, SRCCOPY);

    EndPaint(g_hwnd, &ps);
}

코드입니다.

 

읽어주셔서 감사합니다.

'공부 > 2D과제' 카테고리의 다른 글

회전하는 미사일 공  (0) 2022.12.26
미사일 발사  (0) 2022.12.23
태양계  (0) 2022.12.21
위, 아래, 왼쪽, 오른쪽 움직이기  (0) 2022.12.20
바늘 시계 만들기  (0) 2022.12.19
Comments