[newbie] Have idea planned out, is it workable?
Posted: Fri Nov 26, 2010 2:06 pm
Hi,
Super-disclaimer: most of my current questions are extremely newbie-questions. Some of the answers to them I will find in the docs or by looking at examples, some don't. If you have an urge to reply: RTFM please just ignore the thread. If you otoh like to help out a slow paced newbie please read on.
I put the questions first, so they are easier to find and leave the rest of the post for when you need more info before answering
My idea is to make a game of beads (like these), it will consist of three areas:
Before I go into the details of any of the above I need a cool splash-screen , and that is what I hope to get help with. I know how I want it to look but I need some[2] pointers in the right direction for how to accomplish it. I have layed out a basic version using the code below:
I hope this pic shows some basic properties that I want my 'beadengine' to have:
Thanks for your time and effort, not only in this thread but overall in the community.
With high expectations,
fcg
[Edit] Changed some question, adjusted post to 8x8 tiles instead of 6x6 ones - that comes later
[1] I'll leave the question here anyway, as I think this is a good start to keep a record of my doings
[2] This is probably an understatement, but since I'm new to these boards I don't really have a feel for the value of 'some'
Super-disclaimer: most of my current questions are extremely newbie-questions. Some of the answers to them I will find in the docs or by looking at examples, some don't. If you have an urge to reply: RTFM please just ignore the thread. If you otoh like to help out a slow paced newbie please read on.
- Revisions (current in bold):
- 0. Initial post, backstory, rough plans
- 1. Refined questions about layers, tiles and timers
- 2. Removed a question about non-power-of-2-tiles
I put the questions first, so they are easier to find and leave the rest of the post for when you need more info before answering
- Do you think it is worth it to first learn how to draw to a screen pixel by pixel or is it smarter to go for the layered and tiled approach directly?
- I went with the 'pixel-by-pixel approach, see the code below... - (Currently moot: rewritten to use 8x8 tiles for now:) How do I use tiles of a non-standard dimension keeping an offset while drawing?
- How do I draw tiles?
- How do I draw the "background", "board" and "beads" on different layers?
- How do I (re)draw on a layer with a delay? (I want to create a small incremental animation of the "beads" in the splash-screen)
My idea is to make a game of beads (like these), it will consist of three areas:
- Composer
- Minigames
- Adventure game
Before I go into the details of any of the above I need a cool splash-screen , and that is what I hope to get help with. I know how I want it to look but I need some[2] pointers in the right direction for how to accomplish it. I have layed out a basic version using the code below:
I hope this pic shows some basic properties that I want my 'beadengine' to have:
- each bead is a tile 8*8 pixels (with one color and transparent pixels in the corner and center)
- the board consists of a background color, border and evenly positioned pins to put beads on.
- the maximum board is 30*22 pins surrounded by a border
- beads can be placed on the pins
- etc (things I have in my head but can't formulate, feel free to ask questions...
Code: Select all
#include <nds.h>
/* These are the "border and pin"-tiles
- they are refered to in the "board"-array
- the color values mean:
0 = no color
X = taken from the palette
*/
// border and pin tile - border-top
u8 bpTop[64] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
};
// border and pin tile - border-right
u8 bpRight[64] = {
0,0,2,2,0,0,0,0,
0,0,2,2,0,0,0,0,
0,0,2,2,0,0,0,0,
0,0,2,2,0,0,0,0,
0,0,2,2,0,0,0,0,
0,0,2,2,0,0,0,0,
0,0,2,2,0,0,0,0,
0,0,2,2,0,0,0,0,
};
// border and pin tile - border-bottom
u8 bpBottom[64] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
};
// border and pin tile - border-left
u8 bpLeft[64] = {
0,0,0,0,2,2,0,0,
0,0,0,0,2,2,0,0,
0,0,0,0,2,2,0,0,
0,0,0,0,2,2,0,0,
0,0,0,0,2,2,0,0,
0,0,0,0,2,2,0,0,
0,0,0,0,2,2,0,0,
0,0,0,0,2,2,0,0,
};
// border and pin tile - pin
u8 bpPin[64] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,2,2,0,0,0,
0,0,0,2,2,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
};
// border and pin tile - Corner: north-west
u8 bpcNW[64] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,2,
0,0,0,0,0,2,2,2,
0,0,0,0,0,2,2,0,
0,0,0,0,2,2,0,0
};
// border and pin tile - Corner: north-east
u8 bpcNE[64] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
2,0,0,0,0,0,0,0,
2,2,2,0,0,0,0,0,
0,2,2,0,0,0,0,0,
0,0,2,2,0,0,0,0,
};
// border and pin tile - Corner: south-west
u8 bpcSW[64] = {
0,0,0,0,2,2,0,0,
0,0,0,0,0,2,2,0,
0,0,0,0,0,2,2,2,
0,0,0,0,0,0,0,2,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
};
// border and pin tile - Corner: south-east
u8 bpcSE[64] = {
0,0,2,2,0,0,0,0,
0,2,2,0,0,0,0,0,
2,2,2,0,0,0,0,0,
2,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
};
/* This is the "board", it consists of 32*24 "border and pin"-tiles = 768 tiles in total
Border and Pin codes:
0 = nothing
1 = bpTop
2 = bpRight
3 = bpBottom
4 = bpLeft
5 = bpPin
6 = bpcNW
7 = bpcNE
8 = bpcSW
9 = bpcSE
*/
u8 board[768] = {
6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,7,
4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
4,5,5,5,5,5,5,5,5,5,5,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5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,2,
8,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,9
};
/* This is the "bead"-tile
- they are put on the "board"
- they are refered to in the "beads" array
- the values mean:
0 = no color
1 = color taken from the value in the "beads" array
*/
u8 bead[64] = {
0,1,1,1,1,1,1,0,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,0,0,1,1,1,
1,1,1,0,0,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
0,1,1,1,1,1,1,0
};
/* These are the beads, they take up 32*24 tiles = 768 tiles in total
(notice the border of emptiness!)
Bead codes:
0 = nothing
X = color talen from palette
*/
u8 beads_template[768] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
0,3,3,3,3,3,3,3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3,3,3,3,3,3,3,3,3,3,3,3,3,0,
0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
0,3,3,3,0,3,0,0,0,3,3,0,0,0,0,3,3,0,3,3,3,0,0,3,3,3,3,0,0,3,3,0,
0,3,3,3,0,3,0,3,3,0,3,0,3,3,3,3,0,3,0,3,3,0,3,0,3,3,0,3,3,3,3,0,
0,3,3,3,0,3,0,0,0,3,3,0,0,0,3,3,0,3,3,0,3,0,3,3,0,3,3,0,0,3,3,0,
0,3,3,3,0,3,0,3,3,0,3,0,3,3,3,3,0,0,0,0,3,0,3,3,0,3,3,3,3,0,3,0,
0,3,3,3,3,3,0,3,3,0,3,0,3,3,3,3,0,3,3,0,3,0,3,3,0,3,3,3,3,0,3,0,
0,3,3,3,0,3,0,0,0,3,3,0,0,0,0,3,0,3,3,0,3,0,0,0,3,3,0,0,0,3,3,0,
0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
//---------------------------------------------------------------------------------
int main(void)
{
// pixel coordinates
int x;
int y;
// tile coordinates
// we have 32 * 24 tiles of the size 8*8 pixels.
int x_tile;
int y_tile;
//initialize the DS Dos-like functionality
consoleDemoInit();
//set frame buffer mode 0
videoSetMode(MODE_FB0);
//enable VRAM A for writing by the cpu and use
//as a framebuffer by video hardware
vramSetBankA(VRAM_A_LCD);
//load our palette
BG_PALETTE[0] = RGB15(0,0,31); // Debug
BG_PALETTE[1] = RGB15(4,4,0); // Background
BG_PALETTE[2] = RGB15(27,27,19); // Border % pins
BG_PALETTE[3] = RGB15(31,0,0); // Red
BG_PALETTE[4] = RGB15(0,31,0); // Green
// draw the background
for(y = 0; y < 192; y++) {
for (x = 0; x < 256; x++) {
VRAM_A[x+(y*256)] = BG_PALETTE[1];
}
}
// draw the board
for(y_tile = 0; y_tile < 24; y_tile++) {
for(x_tile = 0; x_tile < 32; x_tile++) {
if(board[x_tile+(y_tile*32)] != 0) {
if(board[x_tile+(y_tile*32)] == 1) {
for(y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if(bpTop[x+y*8] != 0) {
VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpTop[x+y*8]];
}
}
}
}
if(board[x_tile+(y_tile*32)] == 2) {
for(y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if(bpRight[x+y*8] != 0) {
VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpRight[x+y*8]];
}
}
}
}
if(board[x_tile+(y_tile*32)] == 3) {
for(y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if(bpBottom[x+y*8] != 0) {
VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpBottom[x+y*8]];
}
}
}
}
if(board[x_tile+(y_tile*32)] == 4) {
for(y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if(bpLeft[x+y*8] != 0) {
VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpLeft[x+y*8]];
}
}
}
}
if(board[x_tile+(y_tile*32)] == 5) {
for(y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if(bpPin[x+y*8] != 0) {
VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpPin[x+y*8]];
}
}
}
}
if(board[x_tile+(y_tile*32)] == 6) {
for(y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if(bpcNW[x+y*8] != 0) {
VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpcNW[x+y*8]];
}
}
}
}
if(board[x_tile+(y_tile*32)] == 7) {
for(y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if(bpcNE[x+y*8] != 0) {
VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpcNE[x+y*8]];
}
}
}
}
if(board[x_tile+(y_tile*32)] == 8) {
for(y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if(bpcSW[x+y*8] != 0) {
VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpcSW[x+y*8]];
}
}
}
}
if(board[x_tile+(y_tile*32)] == 9) {
for(y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if(bpcSE[x+y*8] != 0) {
VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[bpcSE[x+y*8]];
}
}
}
}
}
}
}
// draw the beads
for(y_tile = 0; y_tile < 24; y_tile++) {
for(x_tile = 0; x_tile < 32; x_tile++) {
if(beads[x_tile+(y_tile*32)] != 0) {
for(y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if(bead[x+y*8] != 0) {
VRAM_A[((x_tile*8+x))+((y_tile*8+y)*(32*8))] = BG_PALETTE[beads[x_tile+(y_tile*32)]];
}
}
}
}
}
}
while(1) {
swiWaitForVBlank();
}
return 0;
}
With high expectations,
fcg
[Edit] Changed some question, adjusted post to 8x8 tiles instead of 6x6 ones - that comes later
[1] I'll leave the question here anyway, as I think this is a good start to keep a record of my doings
[2] This is probably an understatement, but since I'm new to these boards I don't really have a feel for the value of 'some'