void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);
void mapDrawRow(map_view_t *mv, int tx, int ty, word y);
void mapDrawCol(map_view_t *mv, int tx, int ty, word x);
-void animatePlayer(map_view_t *mv, map_view_t *src, short d1, short d2, int x, int y, int ls, bitmap_t *bmp);
+void animatePlayer(map_view_t *src, map_view_t *dest, short d1, short d2, int x, int y, int ls, bitmap_t *bmp);
#define TILEWH 16
#define QUADWH (TILEWH/4)
-#define SPEED 2
+#define SPEED 4
//place holder definitions
#define MAPX 40
#define SWAP(a, b) tmp=a; a=b; b=tmp;
void main() {
bitmap_t ptmp; // player sprite
- int q=0;
+ int q=1;
page_t screen, screen2;
map_t map;
map_view_t mv, mv2;
setkb(1);
/* create the map */
- map = allocMap(MAPX,MAPY); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be bgn properly
+ map = allocMap(MAPX,MAPY); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly
initMap(&map);
mv.map = ↦
mv2.map = ↦
- /* bg the tiles */
+ /* draw the tiles */
ptr = map.data;
ptmp = bitmapLoadPcx("ptmp.pcx"); // load sprite
modexEnter();
modexPalUpdate(ptmp.palette);
screen = modexDefaultPage();
screen.width += (TILEWH*2);
+ screen.height += (TILEWH*2);
mv.page = &screen;
screen2 = modexNextPage(mv.page);
- screen2.width += (TILEWH*2);
mv2.page = &screen2;
- //modexShowPage(mv.page);
/* set up paging */
bg = &mv;
player.x = player.tx*TILEWH;
player.y = player.ty*TILEWH;
modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
- modexCopyPageRegion(bg->page, spri->page, player.x-4, player.y-TILEWH-2, player.x-4, player.y-TILEWH-2, 24, 34);
- modexShowPage(spri->page);
+ modexCopyPageRegion(bg->page, spri->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
+ modexShowPage(bg->page);
while(!keyp(1))
{
//top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square
//when player.tx or player.ty == 0 or player.tx == 20 or player.ty == 15 then stop because that is edge of map and you do not want to walk of the map
//TODO: render the player properly with animation and sprite sheet
- if(keyp(77))
+ //TODO: fexible speeds
+ if(keyp(77) && !keyp(75))
{
if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10)
{
- for(q=0; q<(TILEWH/SPEED); q++)
+ for(q=1; q<=(TILEWH/SPEED); q++)
{
- animatePlayer(spri, bg, 1, 1, player.x, player.y, q, &ptmp);
+ animatePlayer(bg, spri, 1, 1, player.x, player.y, q, &ptmp);
mapScrollRight(bg, SPEED);
mapScrollRight(spri, SPEED);
modexShowPage(spri->page);
}
else if(player.tx < MAPX)
{
- for(q=0; q<(TILEWH/SPEED); q++)
+ for(q=1; q<=(TILEWH/SPEED); q++)
{
player.x+=SPEED;
- animatePlayer(spri, bg, 1, 0, player.x, player.y, q, &ptmp);
+ animatePlayer(bg, spri, 1, 0, player.x, player.y, q, &ptmp);
modexShowPage(spri->page);
}
player.tx++;
}
+ else
+ {
+ modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
+ modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp);
+ modexShowPage(spri->page);
+ }
}
- if(keyp(75))
+ if(keyp(75) && !keyp(77))
{
if(bg->tx > 0 && bg->tx+20 <= MAPX && player.tx == bg->tx + 10)
{
- for(q=0; q<(TILEWH/SPEED); q++)
+ for(q=1; q<=(TILEWH/SPEED); q++)
{
- animatePlayer(spri, bg, 3, 1, player.x, player.y, q, &ptmp);
+ animatePlayer(bg, spri, 3, 1, player.x, player.y, q, &ptmp);
mapScrollLeft(bg, SPEED);
mapScrollLeft(spri, SPEED);
modexShowPage(spri->page);
}
else if(player.tx > 1)
{
- for(q=0; q<(TILEWH/SPEED); q++)
+ for(q=1; q<=(TILEWH/SPEED); q++)
{
player.x-=SPEED;
- animatePlayer(spri, bg, 3, 0, player.x, player.y, q, &ptmp);
+ animatePlayer(bg, spri, 3, 0, player.x, player.y, q, &ptmp);
modexShowPage(spri->page);
}
player.tx--;
}
+ else
+ {
+ modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
+ modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp);
+ modexShowPage(spri->page);
+ }
}
- if(keyp(80))
+ if(keyp(80) && !keyp(72))
{
if(bg->ty >= 0 && bg->ty+15 < MAPY && player.ty == bg->ty + 8)
{
- for(q=0; q<(TILEWH/SPEED); q++)
+ for(q=1; q<=(TILEWH/SPEED); q++)
{
- animatePlayer(spri, bg, 2, 1, player.x, player.y, q, &ptmp);
+ animatePlayer(bg, spri, 2, 1, player.x, player.y, q, &ptmp);
mapScrollDown(bg, SPEED);
mapScrollDown(spri, SPEED);
modexShowPage(spri->page);
}
else if(player.ty < MAPY)
{
- for(q=0; q<(TILEWH/SPEED); q++)
+ for(q=1; q<=(TILEWH/SPEED); q++)
{
player.y+=SPEED;
- animatePlayer(spri, bg, 2, 0, player.x, player.y, q, &ptmp);
+ animatePlayer(bg, spri, 2, 0, player.x, player.y, q, &ptmp);
modexShowPage(spri->page);
}
player.ty++;
}
+ else
+ {
+ modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
+ modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);
+ modexShowPage(spri->page);
+ }
}
- if(keyp(72))
+ if(keyp(72) && !keyp(80))
{
if(bg->ty > 0 && bg->ty+15 <= MAPY && player.ty == bg->ty + 8)
{
- for(q=0; q<(TILEWH/SPEED); q++)
+ for(q=1; q<=(TILEWH/SPEED); q++)
{
- animatePlayer(spri, bg, 0, 1, player.x, player.y, q, &ptmp);
+ animatePlayer(bg, spri, 0, 1, player.x, player.y, q, &ptmp);
mapScrollUp(bg, SPEED);
mapScrollUp(spri, SPEED);
modexShowPage(spri->page);
}
else if(player.ty > 1)
{
- for(q=0; q<(TILEWH/SPEED); q++)
+ for(q=1; q<=(TILEWH/SPEED); q++)
{
player.y-=SPEED;
- animatePlayer(spri, bg, 0, 0, player.x, player.y, q, &ptmp);
+ animatePlayer(bg, spri, 0, 0, player.x, player.y, q, &ptmp);
modexShowPage(spri->page);
}
player.ty--;
}
+ else
+ {
+ modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32);
+ modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp);
+ modexShowPage(spri->page);
+ }
}
-
+
}
modexLeave();
void
mapScrollRight(map_view_t *mv, byte offset) {
- word x, y; /* coordinate for bging */
+ word x, y; /* coordinate for drawing */
/* increment the pixel position and update the page */
mv->page->dx += offset;
mv->page->dx = mv->map->tiles->tileWidth;
- /* bg the next column */
+ /* draw the next column */
x= SCREEN_WIDTH + mv->map->tiles->tileWidth;
mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);
}
void
mapScrollLeft(map_view_t *mv, byte offset) {
- word x, y; /* coordinate for bging */
+ word x, y; /* coordinate for drawing */
/* increment the pixel position and update the page */
mv->page->dx -= offset;
mv->page->data -= 4;
mv->page->dx = mv->map->tiles->tileWidth;
- /* bg the next column */
+ /* draw the next column */
mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);
}
}
void
mapScrollUp(map_view_t *mv, byte offset) {
- word x, y; /* coordinate for bging */
+ word x, y; /* coordinate for drawing */
/* increment the pixel position and update the page */
mv->page->dy -= offset;
mv->page->dy = mv->map->tiles->tileHeight;
- /* bg the next row */
+ /* draw the next row */
y= 0;
mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);
}
void
mapScrollDown(map_view_t *mv, byte offset) {
- word x, y; /* coordinate for bging */
+ word x, y; /* coordinate for drawing */
/* increment the pixel position and update the page */
mv->page->dy += offset;
mv->page->dy = mv->map->tiles->tileHeight;
- /* bg the next row */
+ /* draw the next row */
y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;
mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);
}
mv->dxThresh = mv->map->tiles->tileWidth * 2;
mv->dyThresh = mv->map->tiles->tileHeight * 2;
- /* bg the tiles */
+ /* draw the tiles */
modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);
py=0;
i=mv->ty * mv->map->width + mv->tx;
}
}
-void animatePlayer(map_view_t *mv, map_view_t *src, short d1, short d2, int x, int y, int ls, bitmap_t *bmp)
+void
+animatePlayer(map_view_t *src, map_view_t *dest, short d1, short d2, int x, int y, int ls, bitmap_t *bmp)
{
- int qq;
- int lo = ((TILEWH / SPEED) / 3);
- int loo = (ls + lo);
+ short dire=32*d1;
+ short qq;
+ short lo = ((TILEWH / SPEED) / 3);
+ short loo = (ls + lo);
if(d2==0) qq = 0;
- else qq = ((ls+1)*SPEED);
+ else qq = ((ls)*SPEED);
switch (d1)
{
case 0:
//up
- if(ls<1) { modexCopyPageRegion(mv->page, src->page, x-4, y-qq-TILEWH, x-4, y-qq-TILEWH, 24, 34);
- modexDrawSpriteRegion(mv->page, x-4, y-qq-TILEWH, 24, 0, 24, 32, bmp); }
- if(4>ls && ls>=1) { modexCopyPageRegion(mv->page, src->page, x-4, y-qq-TILEWH, x-4, y-qq-TILEWH, 24, 34);
- modexDrawSpriteRegion(mv->page, x-4, y-qq-TILEWH, 48, 0, 24, 32, bmp); }
- if(7>ls && ls>=4) { modexCopyPageRegion(mv->page, src->page, x-4, y-qq-TILEWH, x-4, y-qq-TILEWH, 24, 34);
- modexDrawSpriteRegion(mv->page, x-4, y-qq-TILEWH, 0, 0, 24, 32, bmp); }
- if(ls>=7) { modexCopyPageRegion(mv->page, src->page, x-4, y-qq-TILEWH, x-4, y-qq-TILEWH, 24, 34);
- modexDrawSpriteRegion(mv->page, x-4, y-qq-TILEWH, 24, 0, 24, 32, bmp); }
+ x=x-4;
+ y=y-qq-TILEWH;
break;
case 1:
// right
- if(ls<1) { modexCopyPageRegion(mv->page, src->page, x+qq-4, y-TILEWH, x+qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
- modexDrawSpriteRegion(mv->page, x+qq-4, y-TILEWH, 24, 32, 24, 32, bmp); }
- if(4>ls && ls>=1) { modexCopyPageRegion(mv->page, src->page, x+qq-4, y-TILEWH, x+qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
- modexDrawSpriteRegion(mv->page, x+qq-4, y-TILEWH, 48, 32, 24, 32, bmp); }
- if(7>ls && ls>=4) { modexCopyPageRegion(mv->page, src->page, x+qq-4, y-TILEWH, x+qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
- modexDrawSpriteRegion(mv->page, x+qq-4, y-TILEWH, 0, 32, 24, 32, bmp); }
- if(ls>=7) { modexCopyPageRegion(mv->page, src->page, x+qq-4, y-TILEWH, x+qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
- modexDrawSpriteRegion(mv->page, x+qq-4, y-TILEWH, 24, 32, 24, 32, bmp); }
+ x=x+qq-4;
+ y=y-TILEWH;
break;
case 2:
//down
- if(ls<1) { modexCopyPageRegion(mv->page, src->page, x-4, y+qq-TILEWH-2, x-4, y+qq-TILEWH-2, 24, 34);
- modexDrawSpriteRegion(mv->page, x-4, y+qq-TILEWH, 24, 64, 24, 32, bmp); }
- if(4>ls && ls>=1) { modexCopyPageRegion(mv->page, src->page, x-4, y+qq-TILEWH-2, x-4, y+qq-TILEWH-2, 24, 34);
- modexDrawSpriteRegion(mv->page, x-4, y+qq-TILEWH, 48, 64, 24, 32, bmp); }
- if(7>ls && ls>=4) { modexCopyPageRegion(mv->page, src->page, x-4, y+qq-TILEWH-2, x-4, y+qq-TILEWH-2, 24, 34);
- modexDrawSpriteRegion(mv->page, x-4, y+qq-TILEWH, 0, 64, 24, 32, bmp); }
- if(ls>=7) { modexCopyPageRegion(mv->page, src->page, x-4, y+qq-TILEWH-2, x-4, y+qq-TILEWH-2, 24, 34);
- modexDrawSpriteRegion(mv->page, x-4, y+qq-TILEWH, 24, 64, 24, 32, bmp); }
+ x=x-4;
+ y=y+qq-TILEWH;
break;
case 3:
//left
- if(ls<1) { modexCopyPageRegion(mv->page, src->page, x-qq-4, y-TILEWH, x-qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
- modexDrawSpriteRegion(mv->page, x-qq-4, y-TILEWH, 24, 96, 24, 32, bmp); }
- if(4>ls && ls>=1) { modexCopyPageRegion(mv->page, src->page, x-qq-4, y-TILEWH, x-qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
- modexDrawSpriteRegion(mv->page, x-qq-4, y-TILEWH, 48, 96, 24, 32, bmp); }
- if(7>ls && ls>=4) { modexCopyPageRegion(mv->page, src->page, x-qq-4, y-TILEWH, x-qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
- modexDrawSpriteRegion(mv->page, x-qq-4, y-TILEWH, 0, 96, 24, 32, bmp); }
- if(ls>=7) { modexCopyPageRegion(mv->page, src->page, x-qq-4, y-TILEWH, x-qq-4, y-TILEWH, 24, 34);// modexWaitBorder();
- modexDrawSpriteRegion(mv->page, x-qq-4, y-TILEWH, 24, 96, 24, 32, bmp); }
+ x=x-qq-4;
+ y=y-TILEWH;
break;
}
+ //TODO: make flexible animation thingy
+ modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
+ if(2>ls && ls>=1) { modexDrawSpriteRegion(dest->page, x, y, 48, dire, 24, 32, bmp); }else
+ if(3>ls && ls>=2) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }else
+ if(4>ls && ls>=3) { modexDrawSpriteRegion(dest->page, x, y, 0, dire, 24, 32, bmp); }else
+ if(5>ls && ls>=4) { modexDrawSpriteRegion(dest->page, x, y, 24, dire, 24, 32, bmp); }
+ modexWaitBorder();
}