Another newbie trying to dwell into genesis programming world. I am trying to make an arkanoid style of game (a paddle and a ball). I have problems in showing the correct sprites of the paddle and the ball.
The ball is a 16x16 pixels bmp image of 2 colors (black and red, I set black for transparent) and the paddle is a 24x8 bmp image (again black color here is to be set transparent)
I export the tiles and palettes of the bmps (in C format) using imagenesis with the following settings:
Mode:
- 15color, 4bpp, 1 plane, 8x8 tiles
- Drawing in the Y direction first, then in the X (Sprites)
- Enable transparency
- Select transparent color -> I choose the black color mentioned before
Then I load the tiles in vram, create the sprites and check with kmods
both vram and sprites. What I see is that the tiles are distorted, in fact it seems that every pixel is doubled through the x-axis and thus the result is wrong.
Can somebody guide me what I am doing wrong?
here is the original ball sprite (drawn in Paint)
![Image](http://i1046.photobucket.com/albums/b463/elefas/Various/ball.jpg)
and here is what sprites list has loaded
![Image](http://i1046.photobucket.com/albums/b463/elefas/Various/rom_Spr.jpg)
As you can hardly distinguish the right side pixels seem to be missing in the last image
finally I am attaching the source code in case it might be of any use
main.c
Code: Select all
/*
* main.c
*
* Created on: 28 Ιαν 2011
* Author: elefas
*/
#include "genesis.h"
#define numberof(table) (sizeof(table) / sizeof(*(table)))
#define TILE 32
#define numberOfTiles(x) (sizeof(x)/TILE)
//tiles
extern unsigned char ball_tiles[128];
extern unsigned char paddle_tiles[96];
//palettes
extern unsigned short ball_palette[16];
extern unsigned short paddle_palette[16];
//sprite list
_spritedef *ball;
_spritedef *paddle;
u8 gravity;
u16 width ;
u16 height ;
u16 score;
u8 delay;
u32 frames;
u8 direction;
u8 border;
void setupGraphics()
{
u16 ballVramAddress = 0x0040; //vram address for ball tiles is 64 (0x40)
u16 paddleVramAddress = ballVramAddress + numberOfTiles(ball_tiles);
VDP_setScreenHeight224();
VDP_setScreenWidth320();
height = VDP_getScreenHeight();
width = VDP_getScreenWidth() - 24;
VDP_loadTileData(ball_tiles, ballVramAddress, numberOfTiles(ball_tiles), 1);
VDP_loadTileData(paddle_tiles, paddleVramAddress, numberOfTiles(paddle_tiles), 1);
VDP_setPalette(0, ball_palette);
VDP_setPalette(1, paddle_palette);
/*set the ball sprite data at position (160,0 = 128+160= 288, 128+0= 128), 0xA=0101b=16x16 (sprite size in tiles),
* 32832 = 32768 + 64 = 1000000000000000b(priority/vflip/hflip) + 1000000b(vram position of tile data)*/
VDP_setSprite(0, width/2, 0, 0x5, 0x8000 + ballVramAddress, 1);
VDP_setSprite(1, width/2, height - border, 0x8, 0x8000 + paddleVramAddress, 0);
}
void init()
{
setupGraphics();
frames = 0;
gravity = 1;
score = 0;
delay = 80;
border = 5;
VDP_drawTextBG(APLAN, "SCORE: ", 0x8000, 0, 0);
}
void dropBall(u32 frames, u16 delay)
{
char str[16];
ball = &spriteDefCache[0];
int y = ball->posy;
int x = ball->posx;
if (frames%delay==0)
{
if (gravity)
{
if(y<height)
{
y += 1;
//random change direction
if (direction == 0)
{
if (x<width-border)
x++;
else
direction = !direction;
}
else
{
if (x>0 + border)
x--;
else
direction = !direction;
}
}
}
else if (!gravity)
{
if(y>0 + border)
{
y -= 1;
//random change direction
if (direction == 0)
{
if (x<width-border)
x++;
else
direction = !direction;
}
else
{
if (x>0 + border)
x--;
else
direction = !direction;
}
}
else
{
gravity = !gravity;
}
}
VDP_setSpritePosition(0, x, y);
}
// intToStr(ball->posy, str, 1);
// VDP_drawText(str, 2, 27);
}
static void handleInput()
{
u16 value;
value = JOY_readJoypad(JOY_1);
char str[16];
//paddle left right movement
if (frames%delay/10==0)
{
paddle = &spriteDefCache[1];
if (value & BUTTON_START)
{
init();
}
if (value & BUTTON_LEFT)
{
u16 xpos =paddle->posx;
if (xpos > 0) xpos -= 1;
VDP_setSpritePosition(1, xpos, paddle->posy);
}
if (value & BUTTON_RIGHT)
{
u16 xpos = paddle->posx;
if (xpos < width -8) xpos += 1;
VDP_setSpritePosition(1, xpos, paddle->posy);
}
if (value & BUTTON_UP)
{
if (delay >1) delay --;
}
if (value & BUTTON_DOWN)
{
if (delay <10) delay ++;
}
// intToStr(paddle->posx, str, 1);
// VDP_drawText(str, 2, 25);
// }
}
}
void drawScore()
{
char scoreStr[16];
intToStr(score, scoreStr, 1);
VDP_drawTextBG(APLAN, scoreStr, 0x8000, 7, 0);
}
void collisionDetection()
{
vu16 *pw;
pw = (u16 *) GFX_CTRL_PORT;
u16 collision = *pw & 0x20; //check control register bit no. 5 for sprite collision
if (collision) //if collision happens reverse gravity, add up score and choose randomly a direction (left or right)
{
gravity = !gravity;
direction = random()/32768;
score = score + 100/delay;
drawScore();
}
}
//main starts here
int main(){
//initialize game
init();
while(1)
{
dropBall(frames, delay);
handleInput();
collisionDetection();
VDP_blit();
//count frames
frames ++;
}
}
Code: Select all
/*
* sprites.c
*
* Created on: 28 Ιαν 2011
* Author: elefas
*/
/**
* sprite tile data
*/
const unsigned char ball_tiles[128]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x11,0x11,0x00,0x01,0x10,0x00, /* Tile #0 */
0x01,0x11,0x10,0x01,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x01,0x11,0x11,0x11, /* Tile #1 */
0x00,0x01,0x11,0x11,0x00,0x01,0x11,0x11,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
0x11,0x11,0x10,0x00,0x11,0x11,0x11,0x10,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, /* Tile #2 */
0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, /* Tile #3 */
0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x10,0x11,0x11,0x10,0x00
};
const unsigned char paddle_tiles[96] = {
0x11,0x11,0x11,0x11,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, /* Tile #0 */
0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x23,0x33,0x33,0x33,0x11,0x11,0x11,0x11,
0x11,0x11,0x11,0x11,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, /* Tile #1 */
0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x33,0x33,0x33,0x33,0x11,0x11,0x11,0x11,
0x11,0x11,0x11,0x11,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, /* Tile #2 */
0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x33,0x33,0x33,0x33,0x11,0x11,0x11,0x11
};
/**
* sprite palettes data
*/
const unsigned short ball_palette[16]={
0x0000,0x000E,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
};
const unsigned short paddle_palette[16] = {
0x0000,0x0000,0x0CCC,0x0888,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
};