응애맘마조
중력 반사 미사일 본문
저번 반사하는 미사일에 추가로 중력을 더한 미사일을 만드는게 과제였습니다.
//bullet.cpp
#include "stdafx.h"
Bullet::Bullet()
{
missile.SetLocalPos(Vector2(2000.0f, 2000.0f));
missile.scale.x = 30.0f;
missile.rotation = 0.0f;
missile.isVisible = false;
missilePet.SetParentRT(missile);
missilePet.SetLocalPos(Vector2(50.0f, 50.0f));
missilePet.scale = Vector2(10.0f, 10.0f);
missilePet.rotation = 0.0f;
missilePet.isAxis = true;
missilePet.isVisible = false;
}
void Bullet::Update(ObRect player)
{
if (!missilePet.isVisible) return;
cout << scalar << endl;
Vector2 dir = fireDir * scalar + DOWN * gravity;
missile.MoveWorldPos(dir * DELTA);
missile.rotation = Utility::DirToRadian(dir);
missilePet.revolution += 360.0f * ToRadian * DELTA;
gravity += 300.0f * DELTA;
missile.Update();
missilePet.Update();
}
void Bullet::LateUpdate()
{
//위
if (missile.GetWorldPos().y >= app.GetHalfHeight() + CAM->position.y)
{
fireDir.y *= -1.0f;
gravity *= -0.7f;
scalar *= 0.7f;
missile.SetWorldPosY(app.GetHalfHeight() + CAM->position.y);
}
//아래
if (missile.GetWorldPos().y <= -app.GetHalfHeight() + CAM->position.y)
{
fireDir.y *= -1.0f;
gravity *= -0.7f;
scalar *= 0.7f;
missile.SetWorldPosY(-app.GetHalfHeight() + CAM->position.y);
}
//왼쪽
if (missile.GetWorldPos().x <= -app.GetHalfWidth() + CAM->position.x)
{
fireDir.x *= -1.0f;
gravity *= -0.7f;
scalar *= 0.7f;
missile.SetWorldPosX(-app.GetHalfWidth() + CAM->position.x);
}
//오른쪽
if (missile.GetWorldPos().x >= app.GetHalfWidth() + CAM->position.x)
{
fireDir.x *= -1.0f;
gravity *= -0.7f;
scalar *= 0.7f;
missile.SetWorldPosX(app.GetHalfWidth() + CAM->position.x);
}
}
void Bullet::Render()
{
if (!missilePet.isVisible) return;
missile.Render();
missilePet.Render();
}
bool Bullet::Shoot(Vector2 fireDir, float scalar, Vector2 firePos)
{
if (!missilePet.isVisible)
{
missile.isVisible = true;
missilePet.isVisible = true;
missilePet.revolution = 0.0f;
missile.rotation = Utility::DirToRadian(fireDir);
missile.SetWorldPos(firePos);
this->fireDir = fireDir;
gravity = 0.0f;
this->scalar = scalar * 5.0f;
return true;
}
return false;
}
코드입니다.
읽어주셔서 감사합니다.
Comments