加速&減速を教えてください!
Posted: 2016年7月07日(木) 22:17
#include "DxLib.h"
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
float v = 1;
float x = 0;
float a = 0.2;
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0) {
if (CheckHitKey(KEY_INPUT_RIGHT)) {
v += a;
}
else {
v = 1;
}
x += v;
if (x > 640) {
x = 0;
}
DrawCircle((int)x, 240, 10, GetColor(255, 255, 255), TRUE);
}
DxLib_End();
return 0;
}
#include "DxLib.h"
const static float V = 1.f;
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
float v = V;
float x = 0;
float a = 0.2;
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0) {
if (CheckHitKey(KEY_INPUT_RIGHT)) {
v += a;
}
else {
v -= a;
if (v < V) {
v = V;
}
}
x += v;
if (x > 640) {
x = 0;
}
DrawCircle((int)x, 240, 10, GetColor(255, 255, 255), TRUE);
}
DxLib_End();
return 0;
}