鼻歌混じりにノリノリで書いたら400行弱。 ちょっと長いです。 そこで削りに削って150行に納めてみました。 とてもとても読みにくくなりました。
最終的に250行程度になったのですが、無理矢理な行き当たりばったりな改変を行ったせいか、大変汚いコードとなりました。
でも、まぁ、いいや。 と思って、kerotan0820 さんの日記に貼り付けて来たのがつい先ほどの事です。
そこで、気づいてしまいました。
そう。 この日記にもポイントが付くのですよ。 私は400行ものプログラムを書いたのです。 それをこの日記に張れば? それは大変素晴らしい事になったと思います。
風の噂では、7万ポイント溜めれば、管理人さん達のプリキュアのコスプレ写真と交換できるそうです。 私はこれがとても欲しくて、必死にポイントを溜めているところなのです。
失敗しました。 ので、ここにもう一度張る事にします。 でも、150行も削ってしまったのです。 もう1度書く気力もありません。 ホントに惜しい事をしました。
さて、何ポイント付くのかな。
#include
#include
enum HITCODE {ST_NORMAL, ST_CHIT, ST_OHIT};
struct TARGET{
POINT from; //ターゲットの移動開始位置
POINT to; // ・・ 移動先位置
HITCODE hitCode;
int moveCount; // ・・ 移動フレーム数(10フレームで移動先へ到達する)
int image;
};
union SCORE{
unsigned int score;
struct{
unsigned int shot : 16; //ショット回数
unsigned int great : 8; //いい当たり回数
unsigned int good : 8; //まぁまぁ当たり回数
};
};
struct SHOOTST{
TARGET target;
SCORE score;
BOOL play;
int time;
};
//ターゲットの色[HITCODE][0: 外側、1: 内側]
static const int Colors[][2] = {
{RGB(0, 0, 124), RGB(0, 0, 255)},
{RGB(0, 0, 124), RGB(255, 255, 255)},
{RGB(255, 255, 0), RGB(0, 0, 255)}
};
static BOOL Mouse;
static void (*SceneFunction)(SHOOTST*);
static void initialize(SHOOTST *sst);
static void playScene(SHOOTST *sst);
static void scoreScene(SHOOTST *sst);
static void addHole(TARGET *tg, int x, int y);
static void drawTarget(TARGET *targ, int x, int y);
static void drawScope(int x, int y);
static void drawScore(SCORE *scr, int x, int y, double per);
static void drawTimerBoard(int time);
///////////////////////////////////////////////////////////////////////////////////////////////////
//エントリーポイント //
int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)/////////
{
SHOOTST sootSt = {0};
ChangeWindowMode(TRUE);
if(DxLib_Init() == -1 || SetDrawScreen(DX_SCREEN_BACK)) return -1;
SetDrawValidGraphCreateFlag(TRUE);
SetDrawValidAlphaChannelGraphCreateFlag(TRUE);
initialize(&sootSt);
SceneFunction = playScene;
while(!ProcessMessage() && !ClearDrawScreen() && !CheckHitKey(KEY_INPUT_ESCAPE)){
SceneFunction(&sootSt);
ScreenFlip();
}
DxLib_End();
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//初期化 //
void initialize(SHOOTST *sst)//////////////////////////////////////////////////////////////////////
{
sst->target.from.x = sst->target.to.x = 320;
sst->target.from.y = sst->target.to.y = 240;
sst->target.hitCode = ST_NORMAL;
if(!sst->target.image){
sst->target.image = MakeGraph(100, 100);
}else{
SetDrawScreen(sst->target.image);
SetDrawBlendMode(DX_BLENDMODE_MUL, 0);
DrawBox(0, 0, 100, 100, GetColor(0, 0, 0), TRUE);
SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 255);
SetDrawScreen(DX_SCREEN_BACK);
}
sst->play = FALSE;
sst->score.score = 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//メインのシーン //
void playScene(SHOOTST *sst)///////////////////////////////////////////////////////////////////////
{
DrawBox(0, 0, 640, 480, GetColor(205, 205, 255), TRUE);
static const double Accell[] = {0.2, 0.3, 0.4, 0.6, 0.8, 0.85, 0.91, 0.95, 0.97, 0.98, 0.99};
int txp, typ, mx, my;
if(sst->play){
int tim = GetNowCount() - sst->time;
if(tim time);
}else{
SceneFunction = scoreScene;
}
}else{
sst->time = GetNowCount();
}
//ターゲット・マウスの描画
GetMousePoint(&mx, &my);
txp = (int)(sst->target.from.x + (sst->target.to.x - sst->target.from.x) * Accell[sst->target.moveCount]);
typ = (int)(sst->target.from.y + (sst->target.to.y - sst->target.from.y) * Accell[sst->target.moveCount]);
drawTarget(&sst->target, txp, typ);
drawScope(mx, my);
drawScore(&sst->score, 0, 400, 1);
//ターゲットの移動
if(sst->target.moveCount != -1 && sst->target.moveCount++ == 10){
sst->target.from = sst->target.to;
sst->target.moveCount = -1;
sst->target.hitCode = ST_NORMAL;
}
if(GetMouseInput() & MOUSE_INPUT_LEFT){
if(!Mouse){ //撃った
double len = sqrt(pow((double)(txp - mx), 2) + pow((double)(typ - my), 2));
sst->score.shot++;
if(len target.hitCode = ST_CHIT;
sst->score.great++;
}else{ //まぁまぁ当たり
sst->target.hitCode = ST_OHIT;
sst->score.good++;
}
addHole(&sst->target, mx - txp + 50, my - typ + 50);
//ターゲットの新しい移動先を設定
sst->target.from.x = txp;
sst->target.from.y = typ;
sst->target.moveCount = 0;
sst->target.to.x = 50 + GetRand(540);
sst->target.to.y = 50 + GetRand(380);
}else{ //はずれた
sst->target.hitCode = ST_NORMAL;
}
Mouse = sst->play = TRUE;
}
}else Mouse = FALSE;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//終わった後にスコアを表示するシーン //
void scoreScene(SHOOTST *sst)//////////////////////////////////////////////////////////////////////
{
static const char *RankC[] = {"F-", "F", "F+", "E-", "E", "E+", "D-", "D", "D+", "C-", "C", "C+", "B-", "B", "B+", "A-", "A", "A+"};
double gr = sst->score.great ? sst->score.great * 100.0 / sst->score.shot : 0;
double gd = sst->score.good ? sst->score.good * 100.0 / sst->score.shot : 0;
int score = sst->score.great * 2 + sst->score.good + (sst->score.great + sst->score.good - sst->score.shot) * 2;
int rank = (int)((score * gr * 2 + score * gd + score) / 2000);
if(rank 17) rank = 17;
DrawBox(0, 0, 640, 480, GetColor(255, 255, 255), TRUE);
drawScore(&sst->score, 20, 250, 3);
DrawExtendFormatString(170, 50, 5, 5, GetColor(0, 0, 0), "RANK %s", RankC[rank]);
DrawBox(550, 440, 630, 470, GetColor(127, 127, 127), TRUE);
int mx, my;
BOOL btn = FALSE;
GetMousePoint(&mx, &my);
if(mx >= 550 && mx = 440 && my image);
DrawCircle(xo, yo, 3, GetColor(0, 0, 0), TRUE);
DrawCircle(xo, yo, 1, GetColor(127, 127, 127), TRUE);
SetDrawScreen(DX_SCREEN_BACK);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//ターゲットの描画 //
void drawTarget(TARGET *tg, int x, int y)//////////////////////////////////////////////////////////
{
DrawCircle(x, y, 50, Colors[tg->hitCode][0], TRUE);
DrawCircle(x, y, 16, Colors[tg->hitCode][1], TRUE);
DrawGraph(x - 50, y - 50, tg->image, TRUE);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//スコープの描画 //
void drawScope(int x, int y)///////////////////////////////////////////////////////////////////////
{
DrawLine(0, y, 640, y, GetColor(127, 127, 127));
DrawLine(x, 0, x, 480, GetColor(127, 127, 127));
DrawCircle(x, y, 50, GetColor(0, 0, 0), FALSE);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//スコアの描画 //
void drawScore(SCORE *scr, int x, int y, double per)///////////////////////////////////////////////
{
DrawExtendFormatString(x, (int)(y + 0 * per), (int)per, (int)per, GetColor(0, 0, 0), "Shot: %u", scr->shot);
DrawExtendFormatString(x, (int)(y + 15 * per), (int)per, (int)per, GetColor(0, 0, 0), "Great: %u", scr->great);
DrawExtendFormatString(x, (int)(y + 30 * per), (int)per, (int)per, GetColor(0, 0, 0), "Good: %u", scr->good);
DrawExtendFormatString(x, (int)(y + 45 * per), (int)per, (int)per, GetColor(0, 0, 0), "Hit: %u", scr->great + scr->good);
DrawExtendFormatString(x, (int)(y + 60 * per), (int)per, (int)per, GetColor(0, 0, 0), "Score: %d",
scr->great * 2 + scr->good + (scr->great + scr->good - scr->shot) * 2);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//残り時間を表示するアレの描画 //
void drawTimerBoard(int time)//////////////////////////////////////////////////////////////////////
{
char buf[10];
double per = time / 30000.0, ox = 320 * per, oy = 240 * per;
sprintf_s(buf, 10, "%2.3f", 30 - time / 1000.0);
int wid = GetDrawExtendStringWidth(per, buf, 7);
DrawBox((int)(320 - ox), (int)(240 - oy), (int)(320 + ox), (int)(240 + oy), GetColor(164, 164, 205), TRUE);
per *= 4;
DrawExtendString(320 - (wid / 2 * 4), 240, per, per, buf, GetColor(0, 0, 0));
}
#出ました。 2倍ボーナスで1241ポイントでした。 まさかの4桁超えです。 さすがソースコード。 管理人さん達によるコスプレブロマイドをゲットする日も近そうですね。