#include "obstacle.h" void Obstacle::Init() { int typeValue = GetRandomValue(0, 2); // 장애물 타입 0은 top, 1은 bottom, 2는 both type = ObstacleType(typeValue); // 장애물 타입을 랜덤하게 설정함 width = GetRandomValue(100, 150); // 파이프 너비는 위와 아래 파이프가 동일 하다 upPipeHeight = GetRandomValue(250, 400); // 위 파이프의 높이 middleHeight = GetRandomValue(300, 400); // 위와 아래 파이프 사이의 공간 upPipe = {GetScreenWidth(), 0, width, upPipeHeight}; downPipe = {GetScreenWidth(), upPipeHeight + middleHeight, width, GetScreenHeight() - (upPipeHeight + middleHeight)}; } void Obstacle::Update() { upPipe.x -= speed; downPipe.x -= speed; } // 파이프가 화면 왼쪽끝을 넘어가면 지우기 위해 왼쪽 끝의 값을 가져옴 int Obstacle::GetPipePosition() { return upPipe.x + upPipe.bWidth; } void Obstacle::Draw() { if (type == ObstacleType::top) { DrawRectangle(upPipe.x, upPipe.y, upPipe.bWidth, upPipe.bHeight, DARKGREEN); }else if (type == ObstacleType::bottom) { DrawRectangle(downPipe.x, downPipe.y, downPipe.bWidth, downPipe.bHeight, DARKGREEN); }else { DrawRectangle(upPipe.x, upPipe.y, upPipe.bWidth, upPipe.bHeight, DARKGREEN); DrawRectangle(downPipe.x, downPipe.y, downPipe.bWidth, downPipe.bHeight, DARKGREEN); } }