C++
ブロック崩しのプログラム  



#include "..\syslib\system.h"
#include "..\syslib\draw.h"
#include "..\syslib\key.h"

class Game : public CSystem,CDraw
{
public:
CMouse mouse;
void Init()
{//アプリケーションの初期化
SetWindowSize(640,480);//画面サイズ
SetHWND(GetHWND());//CDrawクラス初期化
SetScreen(640,480,16);//表示サイズ
mouse.SetHWND(GetHWND());//マウスにハンドルをセット
SetSpriteMode(1);
}
void OnChar(int c)
{
if(c==27)//ESCキーで終了
Exit();
}

void GameInit()
{//グラフィック準備
BoxFill(0,0,640,480,RGB(255,0,255),0);
BoxFill(0,0,63,7,RGB(255,255,255),0);//バー
Circle(4,12,4,RGB(255,0,0),0);//ボール
MakeMaskData(0,RGB(255,0,255));
SetSprite(0,0,0,64,8);
SetSprite(1,0,8,8,8);
}
int block[25][10];
int x,y;
int tx,ty,txx,tyy;
int BallFlag;//ボールの動作フラグ
int BallCount;//ボールの数


void GameMain()
{//ゲーム本体
Score=0;
y=440;//ラケットの縦位置
txx=0;tyy=0;//最初の方向
Stage();
BallFlag=0;

BallCount=4;//最初のボールの数
while(BallCount>=0){
PutScore();
Player();
Racket();
Ball();
HitCheck();
UpDate();//画面更新
}
}
void Run()
{//ここから始まる
GameInit();
GameMain();
}
void Player()
{
//プレイヤーの表示
int mx,my,bl,br;
mouse.Get(mx,my,bl,br);//マウスの取得
x=mx;
PutSprite(0,x,y,0);//バーの表示

if(BallFlag==0){
tx=x+28;ty=y-6;//ボールの座標
if(bl!=0){
BallFlag=1;
txx=2;tyy=-2;//ボールの速度
}
}
}


void Ball()
{
tx += txx;//ボール移動
ty += tyy;
//クリッピングと反射
if(tx<0) txx =-txx;
if(ty<0) tyy =-tyy;
if(tx>=640) txx =-txx;
if(ty>=480) tyy =-tyy;
if(tx>=640) tx =639;
if(ty>=480) {
BallCount--;
BallFlag=0;
}
if(tx<0) tx =0;
if(ty<0) ty =0;
PutSprite(1,tx-2,ty-2,1);//ボールの表示
}

void Stage()
{
int data[25][10]={//ブロックの配置マップ
0,0,0,0,0,0,0,0,0,0,
1,0,1,1,1,1,1,1,0,1,
1,0,1,1,1,1,1,1,0,1,
1,1,1,0,0,0,0,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,0,0,0,0,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,0,1,1,1,1,1,1,0,1,
1,0,1,1,1,1,1,1,0,1,
};
int a,b;
for(a=0;a<25;++a){
for(b=0;b<10;++b){
block[a][b]=data[a][b];
if(block[a][b])
BoxFill(b*64+1,a*32+1,62,30,RGB(0,0,255));
}
}
}

void Racket()
{
//ラケットの判定
if(tx>x && tx<(x+64) && ty>y &&ty<(y+8)){
tyy =-tyy;
}
}

void HitCheck()
{
//ブロック判定
int ax=tx/64;
int ay=ty/32;
if(block[ay][ax]){
block[ay][ax]=0;
BoxFill(ax*64+1,ay*32+1,62,30,RGB(0,0,0));//ブロックを消す
int cx=((tx&63)/2) -16;
int cy=(ty&63/2) -16;
if(cx<0)
cx=-cx;
if(cy<0)
cy=-cy;
if(cx>cy){
txx=-txx;
}else{
if(cx<cy){
tyy =-tyy;
}else{
txx =-txx;
tyy =-tyy;
}
}
}
}
int Score;//点数
void PutScore()
{
char moji[100];
wsprintf(moji,"SCORE %7d BALL=%d",Score,BallCount);
BoxFill(150,0,260,24,0);
DrawText(moji,150,0,RGB(255,255,255),24);
}



};
Game game;


本・漫画・DVD・アニメ・家電・ゲーム | さまざまな報酬パターン | 共有エディタOverleaf
業界NO1のライブチャット | ライブチャット「BBchatTV」  無料お試し期間中で今だけお得に!
35000人以上の女性とライブチャット[BBchatTV] | 最新ニュース | Web検索 | ドメイン | 無料HPスペース