第二章「実戦!SDLでゲーム作り@〜某宇宙人〜」第十二話


最後に必要な部分のブロックのソースも付け加えましょう。

ブロックの書き方は、一つのブロックの塊をそのまま描画し、
すでにミサイルが当たってなくなっている部分にのみ、
穴を書いて埋めるという形にしました。





Block.cppのソース

#include "Def.h" struct BLOCK { int bx; int by; int bLive; }; static BLOCK Block[BLOCK_NUM]; void InitBlock() //ブロック初期化 { for(int i=0;i < BLOCK_NUM;i++) { switch(i){ //当たり判定の不要な部分 case 0: case 5: case 20: case 21: case 26: case 27: case 30: case 35: case 50: case 51: case 56: case 57: case 60: case 65: case 80: case 81: case 86: case 87: case 90: case 95: case 110: case 111: case 116: case 117: Block[i].bLive = -1; continue; default: Block[i].bx = ((i % 30) % 6) * 16 + ((int)(i / 30) * 160) +32; //ブロックの座標セット Block[i].by = ((int)((i % 30) / 6) * 16) + 350; Block[i].bLive = 1; }; } } void DrawBlock() //ブロック描画 { int blockx; for(int i=0;i < BLOCK_MAX;i++) //ブロックを描画 { blockx = i*160 + 32; DrawImg(96,32,96,96,blockx,350); } for(int i=0;i < BLOCK_NUM;i++) { if(Block[i].bLive == 0) //ブロックの穴を描画 DrawImg(128,0,18,18,Block[i].bx-1,Block[i].by-1); } } int GetBx(int i) { return Block[i].bx; } int GetBy(int i) { if(!Block[i].bLive == 1) {return -1;} return Block[i].by; } void DeleteBlock(int i) { Block[i].bLive = 0; }