응애맘마조
플레이어와 보스에게 조명 본문
플레이어와 보스에게 조명 효과를 주는 것이 과제였습니다. 플레이어는 월드 좌표를 사용하고 조명은 스크린 좌표를 사용하기 때문에 이 둘의 좌표를 맞추는 것이 힌트였습니다.
//main.h
#pragma once
class Main : public Scene
{
private:
ObTileMap* map;
TitanSoul* player;
TitanBoss* boss;
ObRect* ui;
vector<Tile*> PlWay;
Vector2 plDest;
Vector2 plSour;
float g;
public:
virtual void Init() override;
virtual void Release() override;
virtual void Update() override;
virtual void LateUpdate() override;
virtual void Render() override;
virtual void ResizeScreen() override;
};
//main.cpp
#include "stdafx.h"
#include "Main.h"
void Main::Init()
{
map = new ObTileMap;
map->file = "map2.txt";
map->Load();
map->CreateTileCost();
player = new TitanSoul;
boss = new TitanBoss;
ui = new ObRect;
ui->scale = Vector2(200.0f, 100.0f);
ui->pivot = OFFSET_LT;
ui->SetWorldPos(Vector2(-app.GetHalfWidth(), app.GetHalfHeight()));
ui->space = SPACE::SCREEN;
LIGHT->light.lights[0].radius = 300.0f;
LIGHT->light.lights[1].radius = 300.0f;
}
void Main::Release()
{
SafeDelete(player);
SafeDelete(boss);
SafeDelete(map);
SafeDelete(ui);
}
void Main::Update()
{
ImGui::SliderFloat2("1_LightPos", (float*)&LIGHT->light.lights[0].screenPos, 0.0f, 2000.0f);
ImGui::SliderFloat("1_radius", &LIGHT->light.lights[0].radius, 0.0f, 2000.0f);
ImGui::SliderFloat2("2_LightPos", (float*)&LIGHT->light.lights[1].screenPos, 0.0f, 2000.0f);
ImGui::SliderFloat("2_radius", &LIGHT->light.lights[1].radius, 0.0f, 2000.0f);
ImGui::ColorEdit3("InColor", (float*)&LIGHT->light.inColor);
ImGui::ColorEdit3("OutColor", (float*)&LIGHT->light.outColor);
ImGui::SliderFloat("Select", &LIGHT->light.select.x, 0.0f, 1.0f);
LIGHT->SetLightPos(player->col->GetWorldPos(), 0);
LIGHT->SetLightPos(boss->col->GetWorldPos(), 1);
if (INPUT->KeyDown(VK_RBUTTON))
{
Int2 sour, dest;
bool isFind;
isFind = map->WorldPosToTileIdx(player->col->GetWorldPos(), sour);
isFind &= map->WorldPosToTileIdx(INPUT->GetWorldMousePos(), dest);
if (isFind)
{
if (map->PathFinding(sour, dest, PlWay))
{
for (int i = 0; i < PlWay.size(); i++)
{
cout << "Way" << i << ":" << PlWay[i]->idx.x <<
"," << PlWay[i]->idx.y << endl;
}
g = 0.0f;
plSour = player->col->GetWorldPos();
PlWay.pop_back();
plDest = PlWay.back()->Pos;
}
}
}
if (!PlWay.empty())
{
player->col->SetWorldPos(Utility::Lerp(plSour, plDest, g));
g += DELTA * 3.0f;
if (g > 1.0f)
{
g = 0.0f;
plSour = plDest;
PlWay.pop_back();
if (!PlWay.empty())
plDest = PlWay.back()->Pos;
}
}
boss->targetPos = player->col->GetWorldPos();
if (INPUT->KeyPress(VK_UP))
{
CAM->position += UP * 300.0f * DELTA;
}
else if (INPUT->KeyPress(VK_DOWN))
{
CAM->position += DOWN * 300.0f * DELTA;
}
if (INPUT->KeyPress(VK_RIGHT))
{
CAM->position += RIGHT * 300.0f * DELTA;
}
else if (INPUT->KeyPress(VK_LEFT))
{
CAM->position += LEFT * 300.0f * DELTA;
}
player->Update();
boss->Update();
map->Update();
ui->Update();
}
void Main::LateUpdate()
{
Int2 tileIdx;
vector<Vector2> footPos = player->SetFoot();
for (int i = 0; i < 4; i++)
{
if (map->WorldPosToTileIdx(footPos[i], tileIdx))
{
if (map->GetTileState(tileIdx) == TILE_WALL)
{
player->StepBack();
}
}
}
if (ui->IntersectScreenMouse(INPUT->GetScreenMousePos()))
{
ui->color = Color(1,0,0,1);
}
else
{
ui->color = Color(0, 0, 0, 1);
}
}
void Main::Render()
{
//DWRITE->GetDC()->BeginDraw();
DWRITE->RenderText(L"ㅎ2ㅎ2ㅎ2", RECT{100,100,200,200}, 50.0f, L"궁서체",
Color(0.0f, 0.0f, 0.0f, 1.0f), DWRITE_FONT_WEIGHT_THIN,
DWRITE_FONT_STYLE_ITALIC, DWRITE_FONT_STRETCH_ULTRA_CONDENSED);
//DWRITE->GetDC()->EndDraw();
map->Render();
player->Render();
boss->Render();
ui->Render();
}
void Main::ResizeScreen()
{
}
int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR param, int command)
{
app.SetAppName(L"Game1");
app.SetInstance(instance);
app.InitWidthHeight(1600.0f, 1080.0f);
WIN->Create();
Main* main = new Main();
int wParam = (int)WIN->Run(main);
SafeDelete(main);
WIN->Destroy();
WIN->DeleteSingleton();
return wParam;
}
코드입니다.
읽어주셔서 감사합니다.
Comments