(collide.c/h ; main.c) Fixed visual glitch and implemented secret ways.

Created new functions in collide.c to make this kind of destructive 
collisions easier. Improved by a bit the level design and fixed the 
related softlock.
master
KikooDX 3 years ago
parent 9a29fb2ea2
commit e1ac070634
  1. 2
      include/collide.h
  2. BIN
      platform.g3a
  3. 41
      src/collide.c
  4. 6
      src/main.c

@ -1,2 +1,4 @@
char collide(int x, int y, char level[], char tile);
char collide_solid(int x, int y, char level[]);
char collide_point(int x, int y, char level[], char tile);
char collide_and_erase(int x, int y, char level[], char tile);

Binary file not shown.

@ -1,4 +1,5 @@
#include "collide.h"
#include "draw.h"
#define PLAYER_SIDES 11
#define LEVEL_WIDTH 28
@ -7,15 +8,17 @@ char collide(int x, int y, char level[], char tile)
{
if ((level[(int)(x/16) + (int)(y/16) * LEVEL_WIDTH] == tile) ||
(level[(int)(x/16) + (int)((y+PLAYER_SIDES)/16) * LEVEL_WIDTH] == tile) ||
(level[(int)((x+PLAYER_SIDES)/16) + (int)((y+PLAYER_SIDES)/16) * LEVEL_WIDTH] == tile) ||
(level[(int)((x+PLAYER_SIDES)/16) + (int)(y/16) * LEVEL_WIDTH] == tile) /*||
(level[(int)(x/16) + (int)((y+PLAYER_SIDES/2)/16) * LEVEL_WIDTH] == tile) ||
(level[(int)((x+PLAYER_SIDES/2)/16) + (int)(y/16) * LEVEL_WIDTH] == tile) ||
(level[(int)((x+PLAYER_SIDES/2)/16) + (int)((y+PLAYER_SIDES)/16) * LEVEL_WIDTH] == tile) ||
(level[(int)((x+PLAYER_SIDES)/16) + (int)((y+PLAYER_SIDES/2)/16) * LEVEL_WIDTH] == tile)*/) return 1;
(level[(int)((x+PLAYER_SIDES)/16) + (int)((y+PLAYER_SIDES)/16) *
LEVEL_WIDTH] == tile) || (level[(int)((x+PLAYER_SIDES)/16) + (int)(y/16) *
LEVEL_WIDTH] == tile)) return 1;
return 0;
}
char collide_point(int x, int y, char level[], char tile)
{
return (level[(int)(x/16) + (int)(y/16) * LEVEL_WIDTH] == tile);
}
char collide_solid(int x, int y, char level[])
{
return (collide(x, y, level, '0') ||
@ -23,3 +26,29 @@ char collide_solid(int x, int y, char level[])
collide(x, y, level, '~') ||
collide(x, y, level, '#'));
}
char collide_and_erase(int x, int y, char level[], char tile)
{
char collided = 0;
if (collide_point(x, y, level, tile))
{
erase_tile(x, y, level);
collided = 1;
}
if (collide_point(x + 11, y, level, tile))
{
erase_tile(x + 11, y, level);
collided = 1;
}
if (collide_point(x, y + 11, level, tile))
{
erase_tile(x, y + 11, level);
collided = 1;
}
if (collide_point(x + 11, y + 11, level, tile))
{
erase_tile(x + 11, y + 11, level);
collided = 1;
}
return collided;
}

@ -230,7 +230,7 @@ int main(void)
if (collide(player_x, player_y, level, 'j'))
{
UG_CAN_JUMP = 1;
erase_tile(player_x, player_y, level);
collide_and_erase(player_x, player_y, level, 'j');
draw_upgrade_message('j');
}
//coin get
@ -238,8 +238,10 @@ int main(void)
{
coins[coin_id] = 1;
coin_count++;
erase_tile(player_x, player_y, level);
collide_and_erase(player_x, player_y, level, 'c');
}
//secret way/hidden passage
collide_and_erase(player_x, player_y, level, 's');
//exit
if (keydown(KEY_EXIT)) return 0;
}

Loading…
Cancel
Save