キャラの往復
Posted: 2015年12月01日(火) 22:34
DXlibを使用して、ゲームを作るのに、キャラクターをウインドウの壁の間を往復させたいのですがどうすればいいですか?
#define _USE_MATH_DEFINES
#include "DxLib.h"
#include <math.h>
#define W 640
#define H 480
class Player {
double x, y, v, ang;
public:
Player() { x = 320, y = 240, v = 5, ang = 0; }
void update() {
if (!(0<=x && x<W)) {
ang += M_PI;
}
x += cos(ang)*v;
y += sin(ang)*v;
}
void draw() {
DrawCircle((int)x, (int)y, 10, GetColor(255, 255, 255), TRUE);
}
};
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
Player p;
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0) {
p.update();
p.draw();
}
DxLib_End();
return 0;
}