Stef wrote:I really need to see your code with line number as i don't understand which error is for what.
Here is the code in its entirety. Ignore the tile collision code, as i am trying to figure it out to work with scroll region. 8P
#include <genesis.h>
#include <vdp.h>
#include <vdp_pal.h>
#include <gfx.h>
#define ANIM_STANDSIDES 0
#define ANIM_WALKSIDES 1
#define ANIM_SLEEPSIDES 2
#define ANIM_STANDDOWN 3
#define ANIM_WALKDOWN 4
#define ANIM_SLEEPDOWN 5
#define ANIM_STANDUP 6
#define ANIM_WALKUP 7
#define MIN_POSX FIX32(10)
#define MAX_POSX FIX32(400)
#define MIN_POSY FIX32(10)
#define MAX_POSY FIX32(400)
//TODO: MAP COLLISION, CITIZANS, PLAYER/NPC Z ORDER,
// forward
static void handleInput();
static void joyEvent(u16 joy, u16 changed, u16 state);
static void updateAnim();
static void updateCamera();
// sprites structure
Sprite sprites[2];
//
fix32 camx; //Viewport
fix32 camy;
u16 php = 99; //player hp
u16 psp = 0; //player special power.
int posx;
int posy;
s16 xorder;
s16 yorder;
u16 current_anim = ANIM_STANDSIDES;
u8 mleft = 0;
u8 mright = 0;
u8 mup = 0;
u8 mdown = 0;
u16 panimspeed[5]; //0 = idle, 1 = walk, 2 = sleep/knockedout
u16 panimframe = 0;
u16 panimtimer = 0;
s8 animpingpong = 1;
char str[25];
char strtwo[25];
int PlanXPosInTile = 0;
int PlanYPosInTile = -3;
u16 MapXPosInTile = 0;
u16 MapYPosInTile = 0;
u16 MapWidthInTile = 40;
u16 MapHeightInTile = 28;
u16 indb;
u16 inda;
int shiftMapTimer = 0;
Map *map;
map = unpackMap(bgb_image.map, NULL);
int pInMAX = 0;
int pInMAY = 0;
#define TILEMAP_WIDTH 96
#define TILEMAP_HEIGHT 14
int tilemap[TILEMAP_WIDTH][TILEMAP_HEIGHT]; // a tilemap
int tileset_properties[TILEMAP_WIDTH][TILEMAP_HEIGHT];
int tile = 0;
int tileproperty = 0;
#define TILEPROP_NOTSOLID 0
#define TILEPROP_SOLID 1
int main()
{
u16 palette[64];
// disable interrupt when accessing VDP
SYS_disableInts();
// initialization
VDP_setScreenWidth320();
// init sprites engine
SPR_init(0);
VDP_setPaletteColors(0, palette_black, 64);
//VDP_setTextPalette(palette_grey[0]);
//VDP_setPalette(PAL0, jason_sprite.palette->data);
//VDP_setPalette(PAL1, bgb_image.palette->data);
//VDP_setPalette(PAL2, bga_image.palette->data);
// load background
indb = TILE_USERINDEX;
VDP_loadTileSet(bgb_image.tileset, indb, TRUE);
VDP_setMapEx(BPLAN, bgb_image.map, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, indb), PlanXPosInTile, PlanYPosInTile, MapXPosInTile, MapYPosInTile, MapWidthInTile, MapHeightInTile);
indb += bgb_image.tileset->numTile;
//inda = TILE_USERINDEX;
//VDP_loadTileSet(bga_image.tileset, inda, TRUE);
//VDP_setMapEx(BPLAN, bga_image.map, TILE_ATTR_FULL(PAL2, TRUE, FALSE, FALSE, inda), 0, 25, 0, 0, MapWidthInTile, MapHeightInTile);
//inda += bga_image.tileset->numTile;
// VDP process done, we can re enable interrupts
SYS_enableInts();
camx = -1;
camy = -1;
posx = 150;
posy = 101;
xorder = 0;
yorder = 0;
current_anim = 0;
//VDP_setTextPalette(1);
// init jason sprite
SPR_initSprite(&sprites[0], &jason_sprite, posx, posy, TILE_ATTR(PAL1, TRUE, FALSE, FALSE));
SPR_initSprite(&sprites[1], &point_sprite, posx, posy, TILE_ATTR(PAL1, TRUE, FALSE, FALSE));
SPR_update(sprites, 1);
// prepare palettes
memcpy(&palette[0], bgb_image.palette->data, 16 * 2);
memcpy(&palette[16], jason_sprite.palette->data, 16 * 2);
// fade in
VDP_fadeIn(0, (3 * 16) - 1, palette, 20, FALSE);
JOY_setEventHandler(joyEvent);
while(TRUE)
{
handleInput();
updateAnim();
updateCamera();
intToStr(posx, str, 1);
VDP_drawText(str, 8, 25);
intToStr(pInMAX, strtwo, 1);
VDP_drawText(strtwo, 1, 25);
// update sprites (only one to update here)
SPR_update(sprites, 2);
VDP_waitVSync();
}
return 0;
}
static void handleInput()
{
tileset_properties[0][0] = TILEPROP_SOLID;
tileset_properties[0][1] = TILEPROP_SOLID;
tileset_properties[0][2] = TILEPROP_SOLID;
tileset_properties[0][3] = TILEPROP_SOLID;
tileset_properties[1][0] = TILEPROP_SOLID;
tileset_properties[1][1] = TILEPROP_SOLID;
tileset_properties[1][2] = TILEPROP_SOLID;
tileset_properties[1][3] = TILEPROP_SOLID;
tileset_properties[2][0] = TILEPROP_SOLID;
tileset_properties[2][1] = TILEPROP_SOLID;
tileset_properties[2][2] = TILEPROP_SOLID;
tileset_properties[2][3] = TILEPROP_SOLID;
tileset_properties[3][0] = TILEPROP_SOLID;
tileset_properties[3][1] = TILEPROP_SOLID;
tileset_properties[3][2] = TILEPROP_SOLID;
tileset_properties[3][3] = TILEPROP_SOLID;
tileset_properties[11][0] = TILEPROP_SOLID;
tileset_properties[11][1] = TILEPROP_SOLID;
tileset_properties[11][2] = TILEPROP_SOLID;
tileset_properties[11][3] = TILEPROP_SOLID;
tileset_properties[12][0] = TILEPROP_SOLID;
tileset_properties[12][1] = TILEPROP_SOLID;
tileset_properties[12][2] = TILEPROP_SOLID;
tileset_properties[12][3] = TILEPROP_SOLID;
tileset_properties[13][0] = TILEPROP_SOLID;
tileset_properties[13][1] = TILEPROP_SOLID;
tileset_properties[13][2] = TILEPROP_SOLID;
tileset_properties[13][3] = TILEPROP_SOLID;
tileset_properties[14][0] = TILEPROP_SOLID;
tileset_properties[14][1] = TILEPROP_SOLID;
tileset_properties[14][2] = TILEPROP_SOLID;
tileset_properties[14][3] = TILEPROP_SOLID;
u16 value = JOY_readJoypad(JOY_1);
pInMAX = posx/16;
pInMAY = posy/16;
tileproperty = tileset_properties[pInMAX][pInMAY];
SPR_setPosition(&sprites[1], pInMAX, pInMAY);
if ((value & BUTTON_UP) && posy > 5 && tileproperty == TILEPROP_NOTSOLID) { posy -= 1; SPR_setPosition(&sprites[0], posx, posy); }
if ((value & BUTTON_DOWN) && posy < 176) { posy += 1; SPR_setPosition(&sprites[0], posx, posy); }
if ((value & BUTTON_RIGHT)) { SPR_setAttribut(&sprites[0], TILE_ATTR(PAL1,TRUE,FALSE,FALSE)); }
if ((value & BUTTON_LEFT)) { SPR_setAttribut(&sprites[0], TILE_ATTR(PAL1,TRUE,FALSE,TRUE)); }
if (value & BUTTON_LEFT) xorder = -1;
else if (value & BUTTON_RIGHT) xorder = +1;
else xorder = 0;
if (value & BUTTON_UP) yorder = -1;
else if (value & BUTTON_DOWN) yorder = +1;
else yorder = 0;
}
static void joyEvent(u16 joy, u16 changed, u16 state)
{
// START button state changed
if (changed & BUTTON_START)
{
}
if (changed & BUTTON_LEFT)
{
if ((state & BUTTON_LEFT) && (mright != 1)) { mleft = 1; } else { mleft = 0; }
if ((state & BUTTON_LEFT)) { } else { shiftMapTimer = 0; }
}
if (changed & BUTTON_RIGHT)
{
if ((state & BUTTON_RIGHT) && (mleft != 1)) { mright = 1; } else { mright = 0; }
if ((state & BUTTON_LEFT)) { } else { shiftMapTimer = 0; }
}
}
static void updateAnim()
{
panimspeed[0] = 50; //idle
panimspeed[1] = 20; //walk
panimspeed[2] = 2; //sleep
//if (yorder == 0 && ((xorder == -1) | (xorder == +1))) current_anim = ANIM_WALKSIDES;
//if (yorder == -1 && xorder == 0) current_anim = ANIM_WALKUP;
//if (yorder == +1 && xorder == 0) current_anim = ANIM_WALKDOWN;
if ((current_anim == ANIM_STANDSIDES) | (current_anim == ANIM_STANDUP) | (current_anim == ANIM_STANDDOWN))
{
if (animpingpong > 0)
{
if (panimtimer < panimspeed[0])
{
panimtimer++;
}
else
{
if (panimframe < 2){ panimframe++; SPR_setFrame(&sprites[0], panimframe); panimtimer = 0; } else { animpingpong = -1; panimtimer = 0; }
}
}
if (animpingpong < 0)
{
if (panimtimer < panimspeed[0])
{
panimtimer++;
}
else
{
if (panimframe > 0)
{
panimframe--;
SPR_setFrame(&sprites[0], panimframe);
panimtimer = 0;
}
else
{
animpingpong = +1; panimtimer = 0;
}
}
}
}
if ((current_anim == ANIM_WALKSIDES) | (current_anim == ANIM_WALKUP) | (current_anim == ANIM_WALKDOWN))
{
animpingpong = +1;
if (panimtimer < panimspeed[1])
{
panimtimer++;
}
else
{
if (panimframe < 3)
{
panimframe++;
SPR_setFrame(&sprites[0], panimframe);
panimtimer = 0;
}
else
{
panimframe = 0;
SPR_setFrame(&sprites[0], panimframe);
panimtimer = 0;
}
}
}
if (yorder > 0 && xorder == 0)
{
current_anim = ANIM_WALKDOWN; SPR_setAnim(&sprites[0], ANIM_WALKDOWN);
}
else if (yorder < 0 && xorder == 0)
{
current_anim = ANIM_WALKUP; SPR_setAnim(&sprites[0], ANIM_WALKUP);
}
else if (yorder == 0 && (xorder < 0) | (xorder > 0))
{
current_anim = ANIM_WALKSIDES; SPR_setAnim(&sprites[0], ANIM_WALKSIDES);
}
else if (yorder == 0 && xorder == 0)
{
if (current_anim == ANIM_WALKDOWN) { SPR_setAnim(&sprites[0], ANIM_STANDDOWN); current_anim = ANIM_STANDDOWN; }
if (current_anim == ANIM_WALKUP) { SPR_setAnim(&sprites[0], ANIM_STANDUP); current_anim = ANIM_STANDUP; }
if (current_anim == ANIM_WALKSIDES) { SPR_setAnim(&sprites[0], ANIM_STANDSIDES); current_anim = ANIM_STANDSIDES; }
}
}
static void updateCamera()
{
u16 value = JOY_readJoypad(JOY_1);
if ((value & BUTTON_RIGHT) && MapXPosInTile < 60 && mleft != 1)
{
if (shiftMapTimer < 4)
{
shiftMapTimer++;
}
else
{
MapXPosInTile += 1;
indb = TILE_USERINDEX;
VDP_setMapEx(BPLAN, bgb_image.map, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, indb), PlanXPosInTile, PlanYPosInTile, MapXPosInTile, MapYPosInTile, MapWidthInTile, MapHeightInTile);
//indb += bgb_image.tileset->numTile;
shiftMapTimer = 0;
}
}
if ((value & BUTTON_LEFT) && MapXPosInTile > 0 && mright != 1)
{
if (shiftMapTimer < 4)
{
shiftMapTimer++;
}
else
{
MapXPosInTile -= 1;
indb = TILE_USERINDEX;
VDP_setMapEx(BPLAN, bgb_image.map, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, indb), PlanXPosInTile, PlanYPosInTile, MapXPosInTile, MapYPosInTile, MapWidthInTile, MapHeightInTile);
//indb += bgb_image.tileset->numTile;
shiftMapTimer = 0;
}
}
}