Skip to content

Instantly share code, notes, and snippets.

@kobake
Last active January 1, 2016 01:49
Show Gist options
  • Save kobake/8075001 to your computer and use it in GitHub Desktop.
Save kobake/8075001 to your computer and use it in GitHub Desktop.
game
// 描画先
class Dst{
int x;
int y;
};
// セル位置
class CellPos{
int x;
int y;
};
// 描画先にセル位置を加算すると新しい描画先が得られる
Dst operator + (Dst dst, CellPos cell_pos)
{
return Dst(
dst.x + cell_pos.x * 16 + cell_pos.y * 16,
dst.y - cell_pos.x * 8 + cell_pos.y * 8
);
}
// テクスチャ1個
class Texture{
int res;
int width;
int height;
void Draw(Dst dst, Src src)
{
//よしなに
}
};
// チップ1個
class Chip{
int chip_number;
const Texture* texture_ref;
void Draw(Dst dst)
{
int tex_x = (chip_number % 32) * 32; // ※幅32個分のテクスチャサイズの場合
int tex_y = (chip_number / 32) * 32;
texture_ref->Draw(dst, Src(tex_x, tex_y, 32, 32));
}
};
// セル1マス (最大10チップが重なる)
class Cell{
Chip chips[10];
void Draw(Dst dst)
{
for(int i = 0; i < 10; i++){
if(chips[i]){
chips[i].Draw(dst + Dst(0, -16 * i));
}
}
}
};
// マップ
class Map{
Cell cells[100 * 100];
int width;
int height;
void Draw(Dst dst)
{
for(int y = 0; y < height; y++){
for(int x = 0; x < width; x++){
cellAt(x, y).Draw(dst + Dst(hoge));
}
}
}
Cell cellAt(int x, int y)
{
return cells[x * width + y];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment