
#include "neslib.h"

//#define DEBUG
#define HAS_DEBUGGER

#define PLAYER_1 0
#define PLAYER_2 1

void sfx_play(char a, char b) {
  a=a;
  b=b;
}

static const unsigned char palette[]={ 
0xD, 0x00, 0x3D, 0x3c,
0xD, 0x09, 0x1B, 0x3c,
0x07, 0x28, 0xF, 0x379,
0x07, 0x21, 0x1C, 0x0F,
  
0x00, 0x11, 0x16, 0x0D,
0x00, 0x27, 0x16, 0x0D,
0x00, 0x17, 0x15, 0x29,
0x00, 0x27, 0x16, 0x0D,
}; 

static const unsigned char paused_palette[]={ 
0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F,
  
0x00, 0x11, 0x16, 0x0D,
0x00, 0x27, 0x16, 0x0D,
0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F,
}; 

#pragma bss-name(push,"ZEROPAGE")
#pragma data-name(push,"ZEROPAGE")

unsigned char oam_off;

static unsigned char i, j;

static unsigned char player_dir[2];

static unsigned char player_attack_tick[2];

static unsigned char player_x[2];
static unsigned char player_y[2];

static unsigned char enemies_x[8];
static unsigned char enemies_y[8];


static unsigned char enemies_enemy[8];


#pragma bss-name(push,"BSS")
#pragma data-name(push,"BSS")

static unsigned char spr;
static unsigned char frame;
static unsigned char dx;
static unsigned char dy;

static unsigned char enemy_spawn_points_x[8];
static unsigned char enemy_spawn_points_y[8];

static unsigned char scr_x;
static unsigned char scr_y;

static char to_scroll_x;
static char to_scroll_y;

static unsigned char player_hp[2];

static unsigned char to_scroll_x_neg;
static unsigned char to_scroll_y_neg;

static unsigned char enemies_health[8];

static unsigned char enemies_dir[8];
static unsigned char enemy_leg[8];
static unsigned char enemy_push_timer[8];
static unsigned char enemy_push_dir[8];

static unsigned char enemies_type[8];

static unsigned char player_carry[2];
static unsigned char player_carry_dir[2];

static unsigned char player_god_mode[2];

static unsigned char item_type[4];
static unsigned char item_x[4];
static unsigned char item_y[4];
static unsigned char item_placed[4];


static unsigned char difficulty;

static unsigned char enemy_speed;

static unsigned char next_level;

static unsigned char enemy_damage_modifier;

static unsigned char spawn_hp;


#ifdef HAS_DEBUGGER


#define debug_info_val (*(unsigned char*)0xFA)
#define break_points_enable_val (*(unsigned char*)0xFB)
#define break_point_val (*(unsigned char*)0xFF)


#define TIMER_ENABLE(x) break_points_enable_val |=(1<<x);
#define TIMER_DISABLE(x) break_points_enable_val &=~(1<<x);

#define TIMER_BEGIN(x) if(break_points_enable_val&(1<<x)) { debug_info_val |=(1<<x); break_point_val = 0; }
#define TIMER_TICK(x) if(break_points_enable_val&(1<<x)) break_point_val++;
#define TIMER_SET_VAL(x, y) if(break_points_enable_val&(1<<x)) break_point_val=y;
#define TIMER_END(x) if(break_points_enable_val&(1<<x)) { debug_info_val &=~(1<<x); break_point_val++; }

#define DEBUG_SET(x) break_point_val = x

#else

#define TIMER_ENABLE(x)
#define TIMER_DISABLE(x)

#define TIMER_BEGIN(x)
#define TIMER_TICK(x)
#define TIMER_SET_VAL(x, y)
#define TIMER_END(x)

#define DEBUG_SET(x)

#endif

// tilesets

static const char bg_menu[] = {

0x02, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xda, 0xd9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 
0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 
0xf9, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xd2, 0xd1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 
0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 
0xf1, 0xfa, 0xf9, 0xfa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f2, 0xf1, 0xe6, 0xe5, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xbc, 0xbb, 0xdd, 0x00, 0x01, 
0x02, 0xfa, 0xf9, 0xe8, 0xe7, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0x55, 0x54, 0x53, 
0x52, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xfa, 0xf9, 0xdd, 0x00, 0x01, 
0x02, 0xf2, 0xf1, 0xe4, 0xe3, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0x51, 0x50, 0x4f, 
0x4e, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xf2, 0xf1, 0xdd, 0x00, 0x01, 
0x02, 0xe1, 0x01, 0x0b, 0x4d, 0x4c, 0x4c, 0x4b, 0xe1, 0x01, 0x0b, 0x00, 0x01, 0x63, 0x55, 0x55, 
0x11, 0x55, 0x50, 0x50, 0x55, 0x00, 0x55, 0x01, 0x06, 0x00, 0x05, 0x55, 0x15, 0x45, 0x55, 0x15, 
0x55, 0x00, 0x55, 0x55, 0x51, 0x54, 0x55, 0x11, 0x55, 0x00, 0x44, 0x55, 0x01, 0x03, 0x51, 0x55, 
0x00, 0x54, 0x55, 0x55, 0x50, 0x50, 0x55, 0x55, 0x00, 0x05, 0x01, 0x06, 0x00, 0x01, 0x09, 0x01, 
0x00, };

static const char collision_bottom_right[] = {
0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1, 
0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 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{2, 2, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 2, 3, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, 2, 4, 3, 4, 4, 4, 5, 4, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 2, 6, 3, 6, 5, 6, 6, 6, 7, 6, 25, 2, 26, 2, 27, 2, 28, 2, 29, 2, 25, 3, 26, 3, 27, 3, 28, 3, 29, 3, 26, 4, 27, 4, 28, 4, 29, 4, 25, 5, 26, 5, 27, 5, 28, 5, 29, 5, 25, 6, 26, 6, 28, 6, 29, 6, 2, 22, 3, 22, 5, 22, 6, 22, 7, 22, 2, 23, 3, 23, 5, 23, 6, 23, 7, 23, 2, 24, 3, 24, 4, 24, 5, 24, 6, 24, 7, 24, 2, 25, 3, 25, 4, 25, 5, 25, 2, 26, 3, 26, 4, 26, 5, 26, 6, 26, 7, 26, 2, 27, 3, 27, 4, 27, 5, 27, 6, 27, 7, 27, 25, 22, 26, 22, 28, 22, 29, 22, 25, 23, 26, 23, 28, 23, 29, 23, 25, 24, 26, 24, 27, 24, 28, 24, 29, 24, 26, 25, 27, 25, 28, 25, 29, 25, 25, 26, 26, 26, 27, 26, 28, 26, 29, 26, 25, 27, 26, 27, 27, 27, 28, 27, 29, 27, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, };


#pragma bss-name(push,"ZEROPAGE")
#pragma data-name(push,"ZEROPAGE")


static unsigned char temp0;
static unsigned char temp1;
static unsigned char temp2;
static unsigned char temp3;
static unsigned char temp4;
static unsigned char temp5;
static unsigned char temp6;
static unsigned char temp7;
//static char stemp0;
//static char stemp1;

static unsigned int int_temp0;
//static unsigned int int_temp1;

#ifdef DEBUG

static unsigned char used_temps = 0;

#define CHECK_FREE(t) if(used_temps & (1<<t)) {DEBUG_SET((((unsigned char)__LINE__)%200));while(1) ppu_wait_nmi(); } else {used_temps |= (1<<t);}
#define SET_FREE(t) used_temps &= ~(1<<t);

#else

#define CHECK_FREE(t)
#define SET_FREE(t) 

#endif


#pragma bss-name(push,"BSS")
#pragma data-name(push,"BSS")

//#include "enemy_sprites.h"

/*
static const char spider_damaged_stand_up[] = {
    -8, -8, 0x80, 1,
    0,  -8, 0x82, 1,
    128
};
static const char spider_damaged_stand_down[] = {
    -8, -8, 0x80, 1|OAM_FLIP_V,
    0,  -8, 0x82, 1|OAM_FLIP_V,
    128
};
static const char spider_damaged_stand_right[] = {
    -8, -8, 0xA0, 1,
    0,  -8, 0xA2, 1,
    128
};
static const char spider_damaged_stand_left[] = {
    -8, -8, 0xA2, 1|OAM_FLIP_H,
    0,  -8, 0xA0, 1|OAM_FLIP_H,
    128
};
*/
static const char spider_damaged_attack_up[] = {
    -8, -8, 0x84, 1,
    0,  -8, 0x86, 1,
    128
};
static const char spider_damaged_attack_down[] = {
    -8, -8, 0x84, 1|OAM_FLIP_V,
    0,  -8, 0x86, 1|OAM_FLIP_V,
    128
};
static const char spider_damaged_attack_right[] = {
    -8, -8, 0xA4, 1,
    0,  -8, 0xA6, 1,
    128
};
static const char spider_damaged_attack_left[] = {
    -8, -8, 0xA6, 1|OAM_FLIP_H,
    0,  -8, 0xA4, 1|OAM_FLIP_H,
    128
};

static const char spider_damaged_leg_0_up[] = {
    -8, -8, 0x88, 1,
    0,  -8, 0x8A, 1,
    128
};
static const char spider_damaged_leg_0_down[] = {
    -8, -8, 0x88, 1|OAM_FLIP_V,
    0,  -8, 0x8A, 1|OAM_FLIP_V,
    128
};
static const char spider_damaged_leg_0_right[] = {
    -8, -8, 0xA8, 1,
    0,  -8, 0xAA, 1,
    128
};
static const char spider_damaged_leg_0_left[] = {
    -8, -8, 0xAA, 1|OAM_FLIP_H,
    0,  -8, 0xA8, 1|OAM_FLIP_H,
    128
};

static const char spider_damaged_leg_1_up[] = {
    -8, -8, 0x8A, 1|OAM_FLIP_H,
    0,  -8, 0x88, 1|OAM_FLIP_H,
    128
};
static const char spider_damaged_leg_1_down[] = {
    -8, -8, 0x8A, 1|OAM_FLIP_H|OAM_FLIP_V,
    0,  -8, 0x88, 1|OAM_FLIP_H|OAM_FLIP_V,
    128
};
static const char spider_damaged_leg_1_right[] = {
    -8, -8, 0xA8, 1|OAM_FLIP_V,
    0,  -8, 0xAA, 1|OAM_FLIP_V,
    128
};
static const char spider_damaged_leg_1_left[] = {
    -8, -8, 0xAA, 1|OAM_FLIP_H|OAM_FLIP_V,
    0,  -8, 0xA8, 1|OAM_FLIP_H|OAM_FLIP_V,
    128
};

/*
static const char spider_stand_up[] = {
    -8, -8, 0x80, 2,
    0,  -8, 0x82, 2,
    128
};
static const char spider_stand_down[] = {
    -8, -8, 0x80, 2|OAM_FLIP_V,
    0,  -8, 0x82, 2|OAM_FLIP_V,
    128
};
static const char spider_stand_right[] = {
    -8, -8, 0xA0, 2,
    0,  -8, 0xA2, 2,
    128
};
static const char spider_stand_left[] = {
    -8, -8, 0xA2, 2|OAM_FLIP_H,
    0,  -8, 0xA0, 2|OAM_FLIP_H,
    128
};
*/

static const char spider_attack_up[] = {
    -8, -8, 0x84, 2,
    0,  -8, 0x86, 2,
    128
};
static const char spider_attack_down[] = {
    -8, -8, 0x84, 2|OAM_FLIP_V,
    0,  -8, 0x86, 2|OAM_FLIP_V,
    128
};
static const char spider_attack_right[] = {
    -8, -8, 0xA4, 2,
    0,  -8, 0xA6, 2,
    128
};
static const char spider_attack_left[] = {
    -8, -8, 0xA6, 2|OAM_FLIP_H,
    0,  -8, 0xA4, 2|OAM_FLIP_H,
    128
};

static const char spider_leg_0_up[] = {
    -8, -8, 0x88, 2,
    0,  -8, 0x8A, 2,
    128
};
static const char spider_leg_0_down[] = {
    -8, -8, 0x88, 2|OAM_FLIP_V,
    0,  -8, 0x8A, 2|OAM_FLIP_V,
    128
};
static const char spider_leg_0_right[] = {
    -8, -8, 0xA8, 2,
    0,  -8, 0xAA, 2,
    128
};
static const char spider_leg_0_left[] = {
    -8, -8, 0xAA, 2|OAM_FLIP_H,
    0,  -8, 0xA8, 2|OAM_FLIP_H,
    128
};

static const char spider_leg_1_up[] = {
    -8, -8, 0x8A, 2|OAM_FLIP_H,
    0,  -8, 0x88, 2|OAM_FLIP_H,
    128
};
static const char spider_leg_1_down[] = {
    -8, -8, 0x8A, 2|OAM_FLIP_H|OAM_FLIP_V,
    0,  -8, 0x88, 2|OAM_FLIP_H|OAM_FLIP_V,
    128
};
static const char spider_leg_1_right[] = {
    -8, -8, 0xA8, 2|OAM_FLIP_V,
    0,  -8, 0xAA, 2|OAM_FLIP_V,
    128
};
static const char spider_leg_1_left[] = {
    -8, -8, 0xAA, 2|OAM_FLIP_H|OAM_FLIP_V,
    0,  -8, 0xA8, 2|OAM_FLIP_H|OAM_FLIP_V,
    128
};

///////////////////

/*
static const char bat_damaged_stand_up[] = {
    -8, -8, 0x90, 1,
    0,  -8, 0x92, 1,
    128
};
static const char bat_damaged_stand_down[] = {
    -8, -8, 0x90, 1|OAM_FLIP_V,
    0,  -8, 0x92, 1|OAM_FLIP_V,
    128
};
static const char bat_damaged_stand_right[] = {
    -8, -8, 0xB0, 1,
    0,  -8, 0xB2, 1,
    128
};
static const char bat_damaged_stand_left[] = {
    -8, -8, 0xB2, 1|OAM_FLIP_H,
    0,  -8, 0xB0, 1|OAM_FLIP_H,
    128
};
*/

static const char bat_damaged_attack_up[] = {
    -8, -8, 0x94, 1,
    0,  -8, 0x96, 1,
    128
};
static const char bat_damaged_attack_down[] = {
    -8, -8, 0x94, 1|OAM_FLIP_V,
    0,  -8, 0x96, 1|OAM_FLIP_V,
    128
};
static const char bat_damaged_attack_right[] = {
    -8, -8, 0xB4, 1,
    0,  -8, 0xB6, 1,
    128
};
static const char bat_damaged_attack_left[] = {
    -8, -8, 0xB6, 1|OAM_FLIP_H,
    0,  -8, 0xB4, 1|OAM_FLIP_H,
    128
};

static const char bat_damaged_leg_0_up[] = {
    -8, -8, 0x98, 1,
    0,  -8, 0x9A, 1,
    128
};
static const char bat_damaged_leg_0_down[] = {
    -8, -8, 0x98, 1|OAM_FLIP_V,
    0,  -8, 0x9A, 1|OAM_FLIP_V,
    128
};
static const char bat_damaged_leg_0_right[] = {
    -8, -8, 0xB8, 1,
    0,  -8, 0xBA, 1,
    128
};
static const char bat_damaged_leg_0_left[] = {
    -8, -8, 0xBA, 1|OAM_FLIP_H,
    0,  -8, 0xB8, 1|OAM_FLIP_H,
    128
};

static const char bat_damaged_leg_1_up[] = {
    -8, -8, 0x9A, 1|OAM_FLIP_H,
    0,  -8, 0x98, 1|OAM_FLIP_H,
    128
};
static const char bat_damaged_leg_1_down[] = {
    -8, -8, 0x9A, 1|OAM_FLIP_H|OAM_FLIP_V,
    0,  -8, 0x98, 1|OAM_FLIP_H|OAM_FLIP_V,
    128
};
static const char bat_damaged_leg_1_right[] = {
    -8, -8, 0xB8, 1|OAM_FLIP_V,
    0,  -8, 0xBA, 1|OAM_FLIP_V,
    128
};
static const char bat_damaged_leg_1_left[] = {
    -8, -8, 0xBA, 1|OAM_FLIP_H|OAM_FLIP_V,
    0,  -8, 0xB8, 1|OAM_FLIP_H|OAM_FLIP_V,
    128
};

/*
static const char bat_stand_up[] = {
    -8, -8, 0x90, 2,
    0,  -8, 0x92, 2,
    128
};
static const char bat_stand_down[] = {
    -8, -8, 0x90, 2|OAM_FLIP_V,
    0,  -8, 0x92, 2|OAM_FLIP_V,
    128
};
static const char bat_stand_right[] = {
    -8, -8, 0xB0, 2,
    0,  -8, 0xB2, 2,
    128
};
static const char bat_stand_left[] = {
    -8, -8, 0xB2, 2|OAM_FLIP_H,
    0,  -8, 0xB0, 2|OAM_FLIP_H,
    128
};
*/

static const char bat_attack_up[] = {
    -8, -8, 0x94, 2,
    0,  -8, 0x96, 2,
    128
};
static const char bat_attack_down[] = {
    -8, -8, 0x94, 2|OAM_FLIP_V,
    0,  -8, 0x96, 2|OAM_FLIP_V,
    128
};
static const char bat_attack_right[] = {
    -8, -8, 0xB4, 2,
    0,  -8, 0xB6, 2,
    128
};
static const char bat_attack_left[] = {
    -8, -8, 0xB6, 2|OAM_FLIP_H,
    0,  -8, 0xB4, 2|OAM_FLIP_H,
    128
};

static const char bat_leg_0_up[] = {
    -8, -8, 0x98, 2,
    0,  -8, 0x9A, 2,
    128
};
static const char bat_leg_0_down[] = {
    -8, -8, 0x98, 2|OAM_FLIP_V,
    0,  -8, 0x9A, 2|OAM_FLIP_V,
    128
};
static const char bat_leg_0_right[] = {
    -8, -8, 0xB8, 2,
    0,  -8, 0xBA, 2,
    128
};
static const char bat_leg_0_left[] = {
    -8, -8, 0xBA, 2|OAM_FLIP_H,
    0,  -8, 0xB8, 2|OAM_FLIP_H,
    128
};

static const char bat_leg_1_up[] = {
    -8, -8, 0x9A, 2|OAM_FLIP_H,
    0,  -8, 0x98, 2|OAM_FLIP_H,
    128
};
static const char bat_leg_1_down[] = {
    -8, -8, 0x9A, 2|OAM_FLIP_H|OAM_FLIP_V,
    0,  -8, 0x98, 2|OAM_FLIP_H|OAM_FLIP_V,
    128
};
static const char bat_leg_1_right[] = {
    -8, -8, 0xB8, 2|OAM_FLIP_V,
    0,  -8, 0xBA, 2|OAM_FLIP_V,
    128
};
static const char bat_leg_1_left[] = {
    -8, -8, 0xBA, 2|OAM_FLIP_H|OAM_FLIP_V,
    0,  -8, 0xB8, 2|OAM_FLIP_H|OAM_FLIP_V,
    128
};



unsigned char isBlocked(unsigned char x, unsigned char y){
    if((x>122 && x<134 && y > 114 && y < 125))
    {
        return 1;
    }
    if(x<128){
        if(y<120){
            return collision_top_left[(x>>3)+((y>>3)<<4)];
        }else{
            y-=120;
            return collision_bottom_left[(x>>3)+((y>>3)<<4)];
        }
    }else{
        x -= 128;
        if(y<120){
            return collision_top_right[(x>>3)+((y>>3)<<4)];
        }else{
            y-=120;
            return collision_bottom_right[(x>>3)+((y>>3)<<4)];
        }
    }
}

void __fastcall__ took_damage(void)
{
	#define DAMAGE_POSITION_X temp0
	#define DAMAGE_POSITION_Y temp1
    
	#define DAMAGE_W temp6
	#define DAMAGE_H temp7
    
	#define ENEMY_POSITION_X temp2
	#define ENEMY_POSITION_Y temp3
	#define DAMAGE_DIFF_X temp4
	#define DAMAGE_DIFF_Y temp5
    
	#define k temp5

	for(j=0; j<8; ++j)
	{
		if(enemies_health[j] == 0)
		{
			continue;
		}

		ENEMY_POSITION_X = enemies_x[j];
		ENEMY_POSITION_Y = enemies_y[j];

		if(DAMAGE_POSITION_X > ENEMY_POSITION_X)
		{
			DAMAGE_DIFF_X = DAMAGE_POSITION_X - ENEMY_POSITION_X;
		}
		else
		{
			DAMAGE_DIFF_X = ENEMY_POSITION_X - DAMAGE_POSITION_X;
		}

		if(DAMAGE_POSITION_Y > ENEMY_POSITION_Y)
		{
			DAMAGE_DIFF_Y = DAMAGE_POSITION_Y - ENEMY_POSITION_Y;
		}
		else
		{
			DAMAGE_DIFF_Y = ENEMY_POSITION_Y - DAMAGE_POSITION_Y;
		}

		if((DAMAGE_DIFF_X < DAMAGE_W) && (DAMAGE_DIFF_Y < DAMAGE_H))
		{
			enemies_health[j]--;
            if(enemies_health[j])
            {
                enemy_push_timer[j] = 4;
                enemy_push_dir[j] = player_dir[i];
            }
			else
			{
				// Killed enemy SFX
				sfx_play(1, 0);
			}
			break;
		}
	}
}

void __fastcall__ tick_enemies(void)
{
	#define SELECTED_AXIS temp0
	#define SELECTED_PLAYER temp1
	#define SELECTED_ENEMY temp2
	#define SELECTED_DIRECTION temp3
	#define SELECTED_SPAWN_POINT temp4
	#define COLLISION_RESULT temp5
	#define DIRECTION_RANDOMNESS temp6
	#define DIFF_X stemp0
	#define DIFF_Y stemp1
	
	SELECTED_SPAWN_POINT = rand8() & 7;

	for(i=0; i<8; ++i)
    {
		if(enemies_health[i] == 0 && (frame&7) == i)
		{
			enemies_x[i] = enemy_spawn_points_x[SELECTED_SPAWN_POINT];
			enemies_y[i] = enemy_spawn_points_y[SELECTED_SPAWN_POINT];
            enemy_push_timer[i] = 0;
            enemies_health[i] = spawn_hp;
			enemies_type[i] = (i&1);
			return;
		}
	}
    
	SELECTED_ENEMY = frame & 7;
    enemy_leg[SELECTED_ENEMY] = 1-enemy_leg[SELECTED_ENEMY];
	SELECTED_PLAYER = enemies_enemy[SELECTED_ENEMY];

	// Decide on the direction
	DIRECTION_RANDOMNESS = rand8() & 3;
    if(DIRECTION_RANDOMNESS == 0)
	{
		DIRECTION_RANDOMNESS = rand8() & 3;
		switch(DIRECTION_RANDOMNESS)
		{
		case 0:
			SELECTED_DIRECTION = PAD_LEFT;
			break;
		case 1:
			SELECTED_DIRECTION = PAD_RIGHT;
			break;
		case 2:
			SELECTED_DIRECTION = PAD_UP;
			break;
		case 3:
			SELECTED_DIRECTION = PAD_DOWN;
			break;
		default:
			SELECTED_DIRECTION = PAD_LEFT;
		}
		
	}
	else if(DIRECTION_RANDOMNESS == 1)
	{
		SELECTED_DIRECTION = enemies_dir[SELECTED_ENEMY];
	}
	else
	{
		SELECTED_AXIS = rand8() & 1;
		if(SELECTED_AXIS)
		{
			if(enemies_x[SELECTED_ENEMY] > player_x[SELECTED_PLAYER])
			{
				SELECTED_DIRECTION = PAD_LEFT;
			}
			else
			{
				SELECTED_DIRECTION = PAD_RIGHT;
			}
		}
		else
		{
			if(enemies_y[SELECTED_ENEMY] > player_y[SELECTED_PLAYER])
			{
				SELECTED_DIRECTION = PAD_UP;
			}
			else
			{
				SELECTED_DIRECTION = PAD_DOWN;
    		}
		}
	}
	
    enemies_dir[SELECTED_ENEMY] = SELECTED_DIRECTION; 
    temp6 = enemies_x[SELECTED_ENEMY];
    temp7 = enemies_y[SELECTED_ENEMY];
    
    if(enemy_push_timer[SELECTED_ENEMY])
    {
    }
    else if(SELECTED_DIRECTION == PAD_RIGHT)
    {
		enemies_x[SELECTED_ENEMY] += enemy_speed;
    }
    else if(SELECTED_DIRECTION == PAD_LEFT)
    {
		enemies_x[SELECTED_ENEMY] -= enemy_speed;
    }
    else if(SELECTED_DIRECTION == PAD_UP)
    {
		enemies_y[SELECTED_ENEMY] -= enemy_speed;
    }
    else if(SELECTED_DIRECTION == PAD_DOWN)
    {
		enemies_y[SELECTED_ENEMY] += enemy_speed;
    }
    
	// Check collisions with level
	COLLISION_RESULT = isBlocked(enemies_x[SELECTED_ENEMY], enemies_y[SELECTED_ENEMY]);
    
    if(COLLISION_RESULT)
    {
        enemies_x[SELECTED_ENEMY] = temp6;
        enemies_y[SELECTED_ENEMY] = temp7;
    }
    else
    {
        // Check collisions with other enemies
        for(i=0; i<8; ++i)
        {
            if(SELECTED_ENEMY == i)
                continue;
    
            if(enemies_x[i] - 6 < enemies_x[SELECTED_ENEMY] && enemies_x[i] + 6 > enemies_x[SELECTED_ENEMY])
            {
                if(enemies_y[i] - 6 < enemies_y[SELECTED_ENEMY] && enemies_y[i] + 6 > enemies_y[SELECTED_ENEMY])
                {
                    enemies_x[SELECTED_ENEMY] = temp6;
                    enemies_y[SELECTED_ENEMY] = temp7;
                }
            }
        }
    }


	// Draw
    for(i=0; i<8; ++i)
    {
        if(enemy_push_timer[i] && (frame&3))
        {
            if(frame&1)
            {
                enemy_push_timer[i]--;
                temp6 = enemies_x[i];
                temp7 = enemies_y[i];
                switch(enemy_push_dir[i])
                {
                    case PAD_LEFT:
                        enemies_x[i]-=2;
                        break;
                    case PAD_RIGHT:
                        enemies_x[i]+=2;
                        break;
                    case PAD_UP:
                        enemies_y[i]-=2;
                        break;
                    case PAD_DOWN:
                        enemies_y[i]+=2;
                        break;
                }
                if(isBlocked(enemies_x[i], enemies_y[i]))
                {
                    enemies_x[i] = temp6;
                    enemies_y[i] = temp7;
                }
            }
           
        }
        
        
        COLLISION_RESULT = 0;
        for(j=0; j<2; j++){
            if((frame&enemy_damage_modifier) == 0)
            {
                if(enemies_x[i] - 5 < player_x[j] && enemies_x[i] + 5 > player_x[j])
                {
                    if(enemies_y[i] - 5 < player_y[j] && enemies_y[i] + 5 > player_y[j])
                    {
                        if(player_hp[j] && player_god_mode[j] == 0)
						{
                            COLLISION_RESULT = 1;
                            player_hp[j]--;
                            player_god_mode[j] = 4;
							
							// Took Damage SFX
							sfx_play(0, 1);
                        }
                        if(player_hp[j] == 0 && enemies_enemy[i] == j){
                            enemies_enemy[i] = 1-enemies_enemy[i];
                        }
                    }
                }
            }
        }
        
        int_temp0 = enemies_x[i];
        int_temp0 <<= 1;
        int_temp0 -= scr_x;
        
        if(int_temp0 > 255)
			continue;

        temp0 = int_temp0;
        
        int_temp0 = enemies_y[i];
        int_temp0 <<= 1;
        int_temp0 -= scr_y;
        
        if(int_temp0 > 255)
			continue;
        
		temp1 = int_temp0;
        if(enemy_push_timer[i]&1)
        {       
            if(COLLISION_RESULT)
            {
				if(enemies_type[i] == 0)
				{
					switch(enemies_dir[i])
					{
						default:
						case PAD_UP:
							spr = oam_meta_spr(temp0, temp1-2, spr, spider_damaged_attack_up);
						break;
						case PAD_DOWN:
							spr = oam_meta_spr(temp0, temp1+2, spr, spider_damaged_attack_down);
						break;
						case PAD_LEFT:
							spr = oam_meta_spr(temp0-2, temp1, spr, spider_damaged_attack_left);
						break;
						case PAD_RIGHT:
							spr = oam_meta_spr(temp0+2, temp1, spr, spider_damaged_attack_right);
						break;
					}
				}
				else
				{
					switch(enemies_dir[i])
					{
						default:
						case PAD_UP:
							spr = oam_meta_spr(temp0, temp1-2, spr, bat_damaged_attack_up);
						break;
						case PAD_DOWN:
							spr = oam_meta_spr(temp0, temp1+2, spr, bat_damaged_attack_down);
						break;
						case PAD_LEFT:
							spr = oam_meta_spr(temp0-2, temp1, spr, bat_damaged_attack_left);
						break;
						case PAD_RIGHT:
							spr = oam_meta_spr(temp0+2, temp1, spr, bat_damaged_attack_right);
						break;
					}
				}
            }
            else
            {
                if(enemy_leg[i])
                {
					if(enemies_type[i] == 0)
					{
						switch(enemies_dir[i])
						{
							default:
							case PAD_UP:
								spr = oam_meta_spr(temp0, temp1, spr, spider_damaged_leg_0_up);
							break;
							case PAD_DOWN:
								spr = oam_meta_spr(temp0, temp1, spr, spider_damaged_leg_0_down);
							break;
							case PAD_LEFT:
								spr = oam_meta_spr(temp0, temp1, spr, spider_damaged_leg_0_left);
							break;
							case PAD_RIGHT:
								spr = oam_meta_spr(temp0, temp1, spr, spider_damaged_leg_0_right);
							break;
						}
					}
					else
					{
						switch(enemies_dir[i])
						{
							default:
							case PAD_UP:
								spr = oam_meta_spr(temp0, temp1, spr, bat_damaged_leg_0_up);
							break;
							case PAD_DOWN:
								spr = oam_meta_spr(temp0, temp1, spr, bat_damaged_leg_0_down);
							break;
							case PAD_LEFT:
								spr = oam_meta_spr(temp0, temp1, spr, bat_damaged_leg_0_left);
							break;
							case PAD_RIGHT:
								spr = oam_meta_spr(temp0, temp1, spr, bat_damaged_leg_0_right);
							break;
						}
					}
                }
                else
                {
					if(enemies_type[i] == 0)
					{
						switch(enemies_dir[i])
						{
							default:
							case PAD_UP:
								spr = oam_meta_spr(temp0, temp1, spr, spider_damaged_leg_1_up);
							break;
							case PAD_DOWN:
								spr = oam_meta_spr(temp0, temp1, spr, spider_damaged_leg_1_down);
							break;
							case PAD_LEFT:
								spr = oam_meta_spr(temp0, temp1, spr, spider_damaged_leg_1_left);
							break;
							case PAD_RIGHT:
								spr = oam_meta_spr(temp0, temp1, spr, spider_damaged_leg_1_right);
							break;
						}
					}
					else
					{
						switch(enemies_dir[i])
						{
							default:
							case PAD_UP:
								spr = oam_meta_spr(temp0, temp1, spr, bat_damaged_leg_1_up);
							break;
							case PAD_DOWN:
								spr = oam_meta_spr(temp0, temp1, spr, bat_damaged_leg_1_down);
							break;
							case PAD_LEFT:
								spr = oam_meta_spr(temp0, temp1, spr, bat_damaged_leg_1_left);
							break;
							case PAD_RIGHT:
								spr = oam_meta_spr(temp0, temp1, spr, bat_damaged_leg_1_right);
							break;
						}
					}
                }
            }
        }
        else
        {
            if(COLLISION_RESULT)
            {
				if(enemies_type[i] == 0)
				{
					switch(enemies_dir[i])
					{
						default:
						case PAD_UP:
							spr = oam_meta_spr(temp0, temp1-2, spr, spider_attack_up);
						break;
						case PAD_DOWN:
							spr = oam_meta_spr(temp0, temp1+2, spr, spider_attack_down);
						break;
						case PAD_LEFT:
							spr = oam_meta_spr(temp0-2, temp1, spr, spider_attack_left);
						break;
						case PAD_RIGHT:
							spr = oam_meta_spr(temp0+2, temp1, spr, spider_attack_right);
						break;
					}
				}
				else
				{
					switch(enemies_dir[i])
					{
						default:
						case PAD_UP:
							spr = oam_meta_spr(temp0, temp1-2, spr, bat_attack_up);
						break;
						case PAD_DOWN:
							spr = oam_meta_spr(temp0, temp1+2, spr, bat_attack_down);
						break;
						case PAD_LEFT:
							spr = oam_meta_spr(temp0-2, temp1, spr, bat_attack_left);
						break;
						case PAD_RIGHT:
							spr = oam_meta_spr(temp0+2, temp1, spr, bat_attack_right);
						break;
					}
				}
            }
            else
            {
                if(enemy_leg[i])
                {
					if(enemies_type[i] == 0)
					{
						switch(enemies_dir[i])
						{
							default:
							case PAD_UP:
								spr = oam_meta_spr(temp0, temp1, spr, spider_leg_0_up);
							break;
							case PAD_DOWN:
								spr = oam_meta_spr(temp0, temp1, spr, spider_leg_0_down);
							break;
							case PAD_LEFT:
								spr = oam_meta_spr(temp0, temp1, spr, spider_leg_0_left);
							break;
							case PAD_RIGHT:
								spr = oam_meta_spr(temp0, temp1, spr, spider_leg_0_right);
							break;
						}
					}
					else
					{
						switch(enemies_dir[i])
						{
							default:
							case PAD_UP:
								spr = oam_meta_spr(temp0, temp1, spr, bat_leg_0_up);
							break;
							case PAD_DOWN:
								spr = oam_meta_spr(temp0, temp1, spr, bat_leg_0_down);
							break;
							case PAD_LEFT:
								spr = oam_meta_spr(temp0, temp1, spr, bat_leg_0_left);
							break;
							case PAD_RIGHT:
								spr = oam_meta_spr(temp0, temp1, spr, bat_leg_0_right);
							break;
						}
					}
                }
                else
                {
					if(enemies_type[i] == 0)
					{
						switch(enemies_dir[i])
						{
							default:
							case PAD_UP:
								spr = oam_meta_spr(temp0, temp1, spr, spider_leg_1_up);
							break;
							case PAD_DOWN:
								spr = oam_meta_spr(temp0, temp1, spr, spider_leg_1_down);
							break;
							case PAD_LEFT:
								spr = oam_meta_spr(temp0, temp1, spr, spider_leg_1_left);
							break;
							case PAD_RIGHT:
								spr = oam_meta_spr(temp0, temp1, spr, spider_leg_1_right);
							break;
						}
					}
					else
					{
						switch(enemies_dir[i])
						{
							default:
							case PAD_UP:
								spr = oam_meta_spr(temp0, temp1, spr, bat_leg_1_up);
							break;
							case PAD_DOWN:
								spr = oam_meta_spr(temp0, temp1, spr, bat_leg_1_down);
							break;
							case PAD_LEFT:
								spr = oam_meta_spr(temp0, temp1, spr, bat_leg_1_left);
							break;
							case PAD_RIGHT:
								spr = oam_meta_spr(temp0, temp1, spr, bat_leg_1_right);
							break;
						}
					}
                }
            }
        }
    }
}

//#include "player_sprites.h"

static const char player_carry_0_meta_spr_stand_up[] = {
    -8, -8, 0x3C, 0,
    0, -8,  0x3E, 0,
    128
};
static const char player_carry_0_meta_spr_stand_down[] = {
    -8, -8, 0x3C, 0|OAM_FLIP_V,
    0, -8,  0x3E, 0|OAM_FLIP_V,
    128
};

static const char player_carry_0_meta_spr_stand_left[] = {
    -8, -8, 0x5C, 0|OAM_FLIP_H,
    0, -8,  0x5A, 0|OAM_FLIP_H,
    128
};

static const char player_carry_0_meta_spr_stand_right[] = {
    -8, -8, 0x5A, 0,
    0, -8,  0x5C, 0,
    128
};


static const char player_carry_0_meta_spr_left_foot_up[] = {
    -8, -8, 0x38, 0,
    0, -8,  0x3A, 0,
    128
};

static const char player_carry_0_meta_spr_right_foot_up[] = {
    -8, -8, 0x3A, 0|OAM_FLIP_H,
    0, -8,  0x38, 0|OAM_FLIP_H,
    128
};

static const char player_carry_0_meta_spr_left_foot_down[] = {
    -8, -8, 0x38, 0|OAM_FLIP_V,
    0, -8,  0x3A, 0|OAM_FLIP_V,
    128
};

static const char player_carry_0_meta_spr_right_foot_down[] = {
    -8, -8, 0x3A, 0|OAM_FLIP_H|OAM_FLIP_V,
    0, -8,  0x38, 0|OAM_FLIP_H|OAM_FLIP_V,
    128
};


static const char player_carry_0_meta_spr_left_foot_right[] = {
    -8, -8, 0x40, 0,
    0, -8,  0x58, 0,
    128
};

static const char player_carry_0_meta_spr_right_foot_right[] = {
    -8, -8, 0x40, 0|OAM_FLIP_V,
    0, -8,  0x58, 0|OAM_FLIP_V,
    128
};


static const char player_carry_0_meta_spr_left_foot_left[] = {
    -8, -8, 0x58, 0|OAM_FLIP_H,
    0, -8,  0x40, 0|OAM_FLIP_H,
    128
};

static const char player_carry_0_meta_spr_right_foot_left[] = {
    -8, -8, 0x58, 0|OAM_FLIP_H|OAM_FLIP_V,
    0, -8,  0x40, 0|OAM_FLIP_H|OAM_FLIP_V,
    128
};


static const char player_carry_1_meta_spr_stand_up[] = {
    -8, -8, 0x3C, 1,
    0, -8,  0x3E, 1,
    128
};
static const char player_carry_1_meta_spr_stand_down[] = {
    -8, -8, 0x3C, 1|OAM_FLIP_V,
    0, -8,  0x3E, 1|OAM_FLIP_V,
    128
};

static const char player_carry_1_meta_spr_stand_left[] = {
    -8, -8, 0x5C, 1|OAM_FLIP_H,
    0, -8,  0x5A, 1|OAM_FLIP_H,
    128
};

static const char player_carry_1_meta_spr_stand_right[] = {
    -8, -8, 0x5A, 1,
    0, -8,  0x5C, 1,
    128
};


static const char player_carry_1_meta_spr_left_foot_up[] = {
    -8, -8, 0x38, 1,
    0, -8,  0x3A, 1,
    128
};

static const char player_carry_1_meta_spr_right_foot_up[] = {
    -8, -8, 0x3A, 1|OAM_FLIP_H,
    0, -8,  0x38, 1|OAM_FLIP_H,
    128
};

static const char player_carry_1_meta_spr_left_foot_down[] = {
    -8, -8, 0x38, 1|OAM_FLIP_V,
    0, -8,  0x3A, 1|OAM_FLIP_V,
    128
};

static const char player_carry_1_meta_spr_right_foot_down[] = {
    -8, -8, 0x3A, 1|OAM_FLIP_H|OAM_FLIP_V,
    0, -8,  0x38, 1|OAM_FLIP_H|OAM_FLIP_V,
    128
};


static const char player_carry_1_meta_spr_left_foot_right[] = {
    -8, -8, 0x56, 1,
    0, -8,  0x58, 1,
    128
};

static const char player_carry_1_meta_spr_right_foot_right[] = {
    -8, -8, 0x56, 1|OAM_FLIP_V,
    0, -8,  0x58, 1|OAM_FLIP_V,
    128
};


static const char player_carry_1_meta_spr_left_foot_left[] = {
    -8, -8, 0x58, 1|OAM_FLIP_H,
    0, -8,  0x56, 1|OAM_FLIP_H,
    128
};

static const char player_carry_1_meta_spr_right_foot_left[] = {
    -8, -8, 0x58, 1|OAM_FLIP_H|OAM_FLIP_V,
    0, -8,  0x56, 1|OAM_FLIP_H|OAM_FLIP_V,
    128
};

static const char player_0_meta_spr_stand_up[] = {
    -8, -8, 0x24, 0,
    0, -8,  0x26, 0,
    128
};
static const char player_0_meta_spr_stand_down[] = {
    -8, -8, 0x24, 0|OAM_FLIP_V,
    0, -8,  0x26, 0|OAM_FLIP_V,
    128
};

static const char player_0_meta_spr_stand_left[] = {
    -8, -8, 0x46, 0|OAM_FLIP_H,
    0, -8,  0x44, 0|OAM_FLIP_H,
    128
};

static const char player_0_meta_spr_stand_right[] = {
    -8, -8, 0x44, 0,
    0, -8,  0x46, 0,
    128
};


static const char player_0_meta_spr_left_foot_up[] = {
    -8, -8, 0x20, 0,
    0, -8,  0x22, 0,
    128
};

static const char player_0_meta_spr_right_foot_up[] = {
    -8, -8, 0x22, 0|OAM_FLIP_H,
    0, -8,  0x20, 0|OAM_FLIP_H,
    128
};

static const char player_0_meta_spr_left_foot_down[] = {
    -8, -8, 0x20, 0|OAM_FLIP_V,
    0, -8,  0x22, 0|OAM_FLIP_V,
    128
};

static const char player_0_meta_spr_right_foot_down[] = {
    -8, -8, 0x22, 0|OAM_FLIP_H|OAM_FLIP_V,
    0, -8,  0x20, 0|OAM_FLIP_H|OAM_FLIP_V,
    128
};


static const char player_0_meta_spr_left_foot_right[] = {
    -8, -8, 0x40, 0,
    0, -8,  0x42, 0,
    128
};

static const char player_0_meta_spr_right_foot_right[] = {
    -8, -8, 0x40, 0|OAM_FLIP_V,
    0, -8,  0x42, 0|OAM_FLIP_V,
    128
};


static const char player_0_meta_spr_left_foot_left[] = {
    -8, -8, 0x42, 0|OAM_FLIP_H,
    0, -8,  0x40, 0|OAM_FLIP_H,
    128
};

static const char player_0_meta_spr_right_foot_left[] = {
    -8, -8, 0x42, 0|OAM_FLIP_H|OAM_FLIP_V,
    0, -8,  0x40, 0|OAM_FLIP_H|OAM_FLIP_V,
    128
};


static const char player_0_meta_spr_attack_0_up[] = {
    -8, 0,   0x48, 0,
    0, 0,    0x4A, 0,
    -8, -16, 0x28, 0,
    0, -16,  0x2A, 0,
    128
};

static const char player_0_meta_spr_attack_1_up[] = {
    -8, 0,   0x4C, 0,
    0, 0,    0x4E, 0,
    -8, -16, 0x2C, 0,
    0, -16,  0x2E, 0,
    128
};


static const char player_0_meta_spr_attack_0_down[] = {
    -8, 0,   0x28, 0|OAM_FLIP_V,
    0, 0,    0x2A, 0|OAM_FLIP_V,
    -8, -16, 0x48, 0|OAM_FLIP_V,
    0, -16,  0x4A, 0|OAM_FLIP_V,
    128
};

static const char player_0_meta_spr_attack_1_down[] = {
    -8, 0,   0x2C, 0|OAM_FLIP_V,
    0, 0,    0x2E, 0|OAM_FLIP_V,
    -8, -16, 0x4C, 0|OAM_FLIP_V,
    0, -16,  0x4E, 0|OAM_FLIP_V,
    128
};

static const char player_0_meta_spr_attack_0_right[] = {
    -8,-8, 0x30, 0,
    0, -8, 0x32, 0,
    8, -8, 0x34, 0,
    128
};

static const char player_0_meta_spr_attack_1_right[] = {
    -8,-8, 0x50, 0,
    0, -8, 0x52, 0,
    8, -8, 0x54, 0,
    128
};

static const char player_0_meta_spr_attack_0_left[] = {
    -16, -8, 0x34, 0|OAM_FLIP_H,
    -8,  -8, 0x32, 0|OAM_FLIP_H,
    0,   -8, 0x30, 0|OAM_FLIP_H,
    128
};

static const char player_0_meta_spr_attack_1_left[] = {
    -16, -8, 0x54, 0|OAM_FLIP_H,
    -8,  -8, 0x52, 0|OAM_FLIP_H,
    0,   -8, 0x50, 0|OAM_FLIP_H,
    128
};


static const char player_1_meta_spr_stand_up[] = {
    -8, -8, 0x24, 1,
    0, -8,  0x26, 1,
    128
};
static const char player_1_meta_spr_stand_down[] = {
    -8, -8, 0x24, 1|OAM_FLIP_V,
    0, -8,  0x26, 1|OAM_FLIP_V,
    128
};

static const char player_1_meta_spr_stand_left[] = {
    -8, -8, 0x46, 1|OAM_FLIP_H,
    0, -8,  0x44, 1|OAM_FLIP_H,
    128
};

static const char player_1_meta_spr_stand_right[] = {
    -8, -8, 0x44, 1,
    0, -8,  0x46, 1,
    128
};


static const char player_1_meta_spr_left_foot_up[] = {
    -8, -8, 0x20, 1,
    0, -8,  0x22, 1,
    128
};

static const char player_1_meta_spr_right_foot_up[] = {
    -8, -8, 0x22, 1|OAM_FLIP_H,
    0, -8,  0x20, 1|OAM_FLIP_H,
    128
};

static const char player_1_meta_spr_left_foot_down[] = {
    -8, -8, 0x20, 1|OAM_FLIP_V,
    0, -8,  0x22, 1|OAM_FLIP_V,
    128
};

static const char player_1_meta_spr_right_foot_down[] = {
    -8, -8, 0x22, 1|OAM_FLIP_H|OAM_FLIP_V,
    0, -8,  0x20, 1|OAM_FLIP_H|OAM_FLIP_V,
    128
};


static const char player_1_meta_spr_left_foot_right[] = {
    -8, -8, 0x40, 1,
    0, -8,  0x42, 1,
    128
};

static const char player_1_meta_spr_right_foot_right[] = {
    -8, -8, 0x40, 1|OAM_FLIP_V,
    0, -8,  0x42, 1|OAM_FLIP_V,
    128
};


static const char player_1_meta_spr_left_foot_left[] = {
    -8, -8, 0x42, 1|OAM_FLIP_H,
    0, -8,  0x40, 1|OAM_FLIP_H,
    128
};

static const char player_1_meta_spr_right_foot_left[] = {
    -8, -8, 0x42, 1|OAM_FLIP_H|OAM_FLIP_V,
    0, -8,  0x40, 1|OAM_FLIP_H|OAM_FLIP_V,
    128
};


static const char player_1_meta_spr_attack_0_up[] = {
    -8, 0,   0x48, 1,
    0, 0,    0x4A, 1,
    -8, -16, 0x28, 1,
    0, -16,  0x2A, 1,
    128
};

static const char player_1_meta_spr_attack_1_up[] = {
    -8, 0,   0x4C, 1,
    0, 0,    0x4E, 1,
    -8, -16, 0x2C, 1,
    0, -16,  0x2E, 1,
    128
};


static const char player_1_meta_spr_attack_0_down[] = {
    -8, 0,   0x28, 1|OAM_FLIP_V,
    0, 0,    0x2A, 1|OAM_FLIP_V,
    -8, -16, 0x48, 1|OAM_FLIP_V,
    0, -16,  0x4A, 1|OAM_FLIP_V,
    128
};

static const char player_1_meta_spr_attack_1_down[] = {
    -8, 0,   0x2C, 1|OAM_FLIP_V,
    0, 0,    0x2E, 1|OAM_FLIP_V,
    -8, -16, 0x4C, 1|OAM_FLIP_V,
    0, -16,  0x4E, 1|OAM_FLIP_V,
    128
};

static const char player_1_meta_spr_attack_0_right[] = {
    -8,-8, 0x30, 1,
    0, -8, 0x32, 1,
    8, -8, 0x34, 1,
    128
};

static const char player_1_meta_spr_attack_1_right[] = {
    -8,-8, 0x50, 1,
    0, -8, 0x52, 1,
    8, -8, 0x54, 1,
    128
};

static const char player_1_meta_spr_attack_0_left[] = {
    -16, -8, 0x34, 1|OAM_FLIP_H,
    -8,  -8, 0x32, 1|OAM_FLIP_H,
    0,   -8, 0x30, 1|OAM_FLIP_H,
    128
};

static const char player_1_meta_spr_attack_1_left[] = {
    -16, -8, 0x54, 1|OAM_FLIP_H,
    -8,  -8, 0x52, 1|OAM_FLIP_H,
    0,   -8, 0x50, 1|OAM_FLIP_H,
    128
};


void  __fastcall__ draw_player(void){
    if(i==0){
        if(player_carry[0] != 0xFF){
            if(temp2 & (PAD_LEFT|PAD_RIGHT|PAD_UP|PAD_DOWN)){
                switch(player_carry_dir[0])
                {
                    case PAD_UP:
                        if(frame&16)
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_left_foot_up);
                        }
                        else
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_right_foot_up);
                        }
                    break;
                    case PAD_DOWN:
                        if(frame&16)
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_left_foot_down);
                        }
                        else
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_right_foot_down);
                        }
                    break;
                    case PAD_LEFT:
                        if(frame&16)
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_left_foot_left);
                        }
                        else
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_right_foot_left);
                        }
                    break;
                    case PAD_RIGHT:
                        if(frame&16)
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_left_foot_right);
                        }
                        else
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_right_foot_right);
                        }
                    break;
                }
            }
            else
            {
                switch(player_carry_dir[i])
                {
                    case PAD_UP:
                        spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_stand_up);
                    break;
                    case PAD_DOWN:
                        spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_stand_down);
                    break;
                    case PAD_LEFT:
                        spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_stand_left);
                    break;
                    case PAD_RIGHT:
                        spr = oam_meta_spr(temp0, temp1, spr, player_carry_0_meta_spr_stand_right);
                    break;
                }
            }
        }else if(player_attack_tick[i]){
            switch(player_dir[i])
            {
                case PAD_UP:
                    if(player_attack_tick[i] > 8){
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_attack_0_up);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_attack_1_up);
                    }
                break;
                case PAD_DOWN:
                    if(player_attack_tick[i] > 8){
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_attack_0_down);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_attack_1_down);
                    }
                break;
                case PAD_RIGHT:
                    if(player_attack_tick[i] > 8){
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_attack_0_right);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_attack_1_right);
                    }
                break;
                case PAD_LEFT:
                    if(player_attack_tick[i] > 8){
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_attack_0_left);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_attack_1_left);
                    }
                break;
            }
            player_attack_tick[i]--;
        }
        else if(temp2 & (PAD_LEFT|PAD_RIGHT|PAD_UP|PAD_DOWN)){
            
            switch(player_dir[i])
            {
                case PAD_UP:
                    if(frame&16)
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_left_foot_up);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_right_foot_up);
                    }
                break;
                case PAD_DOWN:
                    if(frame&16)
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_left_foot_down);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_right_foot_down);
                    }
                break;
                case PAD_LEFT:
                    if(frame&16)
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_left_foot_left);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_right_foot_left);
                    }
                break;
                case PAD_RIGHT:
                    if(frame&16)
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_left_foot_right);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_right_foot_right);
                    }
                break;
            }
        }
        else
        {
            switch(player_dir[i])
            {
                case PAD_UP:
                    spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_stand_up);
                break;
                case PAD_DOWN:
                    spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_stand_down);
                break;
                case PAD_LEFT:
                    spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_stand_left);
                break;
                case PAD_RIGHT:
                    spr = oam_meta_spr(temp0, temp1, spr, player_0_meta_spr_stand_right);
                break;
            }
        }
    }else if(i == 1){
         if(player_carry[1] != 0xFF){
            if(temp2 & (PAD_LEFT|PAD_RIGHT|PAD_UP|PAD_DOWN)){
                switch(player_carry_dir[1])
                {
                    case PAD_UP:
                        if(frame&16)
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_left_foot_up);
                        }
                        else
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_right_foot_up);
                        }
                    break;
                    case PAD_DOWN:
                        if(frame&16)
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_left_foot_down);
                        }
                        else
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_right_foot_down);
                        }
                    break;
                    case PAD_LEFT:
                        if(frame&16)
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_left_foot_left);
                        }
                        else
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_right_foot_left);
                        }
                    break;
                    case PAD_RIGHT:
                        if(frame&16)
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_left_foot_right);
                        }
                        else
                        {
                            spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_right_foot_right);
                        }
                    break;
                }
            }
            else
            {
                switch(player_carry_dir[1])
                {
                    case PAD_UP:
                        spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_stand_up);
                    break;
                    case PAD_DOWN:
                        spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_stand_down);
                    break;
                    case PAD_LEFT:
                        spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_stand_left);
                    break;
                    case PAD_RIGHT:
                        spr = oam_meta_spr(temp0, temp1, spr, player_carry_1_meta_spr_stand_right);
                    break;
                }
            }
        }else if(player_attack_tick[i]){
            
            switch(player_dir[i])
            {
                case PAD_UP:
                    if(player_attack_tick[i] > 8){
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_attack_0_up);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_attack_1_up);
                    }
                break;
                case PAD_DOWN:
                    if(player_attack_tick[i] > 8){
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_attack_0_down);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_attack_1_down);
                    }
                break;
                case PAD_RIGHT:
                    if(player_attack_tick[i] > 8){
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_attack_0_right);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_attack_1_right);
                    }
                break;
                case PAD_LEFT:
                    if(player_attack_tick[i] > 8){
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_attack_0_left);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_attack_1_left);
                    }
                break;
            }
            player_attack_tick[i]--;
        }
        else if(temp2 & (PAD_LEFT|PAD_RIGHT|PAD_UP|PAD_DOWN)){
            
            switch(player_dir[i])
            {
                case PAD_UP:
                    if(frame&16)
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_left_foot_up);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_right_foot_up);
                    }
                break;
                case PAD_DOWN:
                    if(frame&16)
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_left_foot_down);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_right_foot_down);
                    }
                break;
                case PAD_LEFT:
                    if(frame&16)
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_left_foot_left);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_right_foot_left);
                    }
                break;
                case PAD_RIGHT:
                    if(frame&16)
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_left_foot_right);
                    }
                    else
                    {
                        spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_right_foot_right);
                    }
                break;
            }
        }
        else
        {
            switch(player_dir[i])
            {
                case PAD_UP:
                    spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_stand_up);
                break;
                case PAD_DOWN:
                    spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_stand_down);
                break;
                case PAD_LEFT:
                    spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_stand_left);
                break;
                case PAD_RIGHT:
                    spr = oam_meta_spr(temp0, temp1, spr, player_1_meta_spr_stand_right);
                break;
            }
        }
    }
}

#define min_x 60
#define max_x (255-60)
#define min_y 60
#define max_y (240-60)

const static char item_target_x[4] = {108, 148, 108, 148};
const static char item_target_y[4] = {99, 140, 139, 99};

void __fastcall__ tick_players(void)
{
    /*
    int_temp0 = 120;
    int_temp0 <<= 1;
    int_temp0 -= scr_x;

    temp0 = int_temp0;

    int_temp0 = 120;
    int_temp0 <<= 1;
    int_temp0 -= scr_y;
    temp1 = int_temp0;
    spr = oam_spr(temp0, temp1, 0x2, 0x2, spr);
*/
    
    switch(player_hp[0]){
        default:
            spr = oam_spr(0x10, 0x10, 0x60, 0x0, spr);
            spr = oam_spr(0x10, 0x20, 0x60, 0x0, spr);
        break;
        case 3:
            spr = oam_spr(0x10, 0x10, 0x62, 0x0, spr);
            spr = oam_spr(0x10, 0x20, 0x60, 0x0, spr);
        break;
        case 2:
            spr = oam_spr(0x10, 0x10, 0x64, 0x0, spr);
            spr = oam_spr(0x10, 0x20, 0x60, 0x0, spr);
        break;
        case 1:
            spr = oam_spr(0x10, 0x10, 0x64, 0x0, spr);
            spr = oam_spr(0x10, 0x20, 0x62, 0x0, spr);
        break;
        case 0:
            spr = oam_spr(0x10, 0x10, 0x64, 0x0, spr);
            spr = oam_spr(0x10, 0x20, 0x64, 0x0, spr);
        break;
    }
    switch(player_hp[1]){
        default:
            spr = oam_spr(0xE8, 0x10, 0x60, 0x1, spr);
            spr = oam_spr(0xE8, 0x20, 0x60, 0x1, spr);
        break;
        case 3:
            spr = oam_spr(0xE8, 0x10, 0x62, 0x1, spr);
            spr = oam_spr(0xE8, 0x20, 0x60, 0x1, spr);
        break;
        case 2:
            spr = oam_spr(0xE8, 0x10, 0x64, 0x1, spr);
            spr = oam_spr(0xE8, 0x20, 0x60, 0x1, spr);
        break;
        case 1:
            spr = oam_spr(0xE8, 0x10, 0x64, 0x1, spr);
            spr = oam_spr(0xE8, 0x20, 0x62, 0x1, spr);
        break;
        case 0:
            spr = oam_spr(0xE8, 0x10, 0x64, 0x1, spr);
            spr = oam_spr(0xE8, 0x20, 0x64, 0x1, spr);
        break;
    }
    
    to_scroll_x = 0;
    to_scroll_y = 0;
    
    for(i=0; i<2; ++i)
    {
        if(player_god_mode[i])
        {
            if((frame&2) == 0)
            {
                player_god_mode[i]--;
                pal_col(16+(i<<2)+3, palette[16+(i<<2)+3]);
                pal_col(16+(i<<2)+1, palette[16+(i<<2)+1]);
            }
            else
            {
                pal_col(16+(i<<2)+3, 0x20);
                pal_col(16+(i<<2)+1, 0xD);
                
            }
        }
        if(player_hp[i] == 0){
            continue;
        }
        int_temp0 = player_x[i];
        int_temp0 <<= 1;
        int_temp0 -= scr_x;
        
        temp0 = int_temp0;
        
        int_temp0 = player_y[i];
        int_temp0 <<= 1;
        int_temp0 -= scr_y;
        
        temp1 = int_temp0;
        
        temp2 = pad_poll(i);
        
        draw_player();
        
        if(temp0<min_x && scr_x > 0)
        {
            to_scroll_x = (min_x-temp0)>>1;
            if(to_scroll_x > scr_x)
            {
                to_scroll_x = scr_x;
            }
            to_scroll_x_neg = 1;
        } else if(temp0 > max_x && scr_x < 255)
        {
            to_scroll_x =  (temp0-max_x)>>1;
            
            if(to_scroll_x > 254-scr_x)
            {
                to_scroll_x = 254-scr_x;
            }
            to_scroll_x_neg = 0;
        }
        
        #
        if(temp1<min_y && scr_y > 0)
        {
            to_scroll_y = (min_y-temp1)>>1;
            if(to_scroll_y > scr_y)
            {
                to_scroll_y = scr_y;
            }
            to_scroll_y_neg = 1;
        } else if(temp1 > max_y && scr_y < 255)
        {
            to_scroll_y =  (temp1-max_y)>>1;
            
            if(to_scroll_y > 238-scr_y)
            {
                to_scroll_y = 238-scr_y;
            }
            to_scroll_y_neg = 0;
        }
    
        
        if(temp2 & PAD_B)
        {
            if(player_carry[i] == 0xFF)
            {
                temp4 = player_x[i];
                temp5 = player_y[i];
                
                if(player_dir[i] == PAD_LEFT) temp4 -= 4;
                else if(player_dir[i] == PAD_RIGHT) temp4 += 4;
                
                if(player_dir[i] == PAD_UP)  temp5 -= 4;
                else if(player_dir[i] == PAD_DOWN) temp5 += 2;
            
                for(j=0; j<4; j++)
                {
                    if(item_placed[j])
                    {
                        continue;
                    }
                    if(item_x[j]-4 <temp4 && item_x[j]+4>temp4)
                    {
                        if(item_y[j]-5 <temp5 && item_y[j]+5>temp5)
                        {
                            if(player_carry[1-i] != j || player_carry_dir[1-i] != player_dir[i])
                            {
                                player_carry[i] = j;
                                player_carry_dir[i] = player_dir[i];

								// Item pickup SFX
								sfx_play(5, 3);
                            }
                        }
                    }
                }
            }
        }
        else
        {
            player_carry[i] = 0xFF;

        }
        
        if(player_attack_tick[i] < 3 && (temp2 & (PAD_A))){
            player_attack_tick[i] = 16;
        }
        
        temp1 = 1-i;
    
        temp6 = 0;
        if(player_carry[i] != 0xFF)
        {
            temp6++;
            if(player_carry[temp1] == player_carry[i])
            {
                temp6++;
            }
        }
        
        
        if(temp6 == 2)
        {
            if(i==0 && (frame&3) == 0)
            {
                temp2 = pad_poll(0)&pad_poll(1);
                
                      
                if(temp2 & PAD_LEFT)
                {
                    if(isBlocked(player_x[0]-1, player_y[0]) == 0 && isBlocked(player_x[1]-1, player_y[1]) == 0){
                        --player_x[0];
                        --player_x[1];
                        --item_x[player_carry[i]];
                    }
                } 
                else if(temp2 & PAD_RIGHT)
                {
                    if(isBlocked(player_x[0]+1, player_y[0]) == 0 && isBlocked(player_x[1]+1, player_y[1]) == 0){
                        ++player_x[0];
                        ++player_x[1];
                        ++item_x[player_carry[i]];
                    }
                }
                
                if(temp2 & PAD_UP)
                {
                    if(isBlocked(player_x[0], player_y[0]-1) == 0 && isBlocked(player_x[1], player_y[1]-1) == 0){
                        --player_y[0];
                        --player_y[1];
                        --item_y[player_carry[i]];
                    }
                } 
                else if(temp2 & PAD_DOWN)
                {
                    if(isBlocked(player_x[0], player_y[0]+1) == 0 && isBlocked(player_x[1], player_y[1]+1) == 0){
                        ++player_y[0];
                        ++player_y[1];
                        ++item_y[player_carry[i]];
                    }
                }
                
            }
        }
        else if((temp6 == 0 ||(frame&7) == i) && (frame&1)== i)
        {
            if(!(player_dir[i] & temp2))
            {
                if(temp2 & PAD_LEFT)
                {
                    player_dir[i] = PAD_LEFT;
                }
                else if(temp2 & PAD_RIGHT)
                {
                    player_dir[i] = PAD_RIGHT;
                }
                else if(temp2 & PAD_DOWN)
                {
                    player_dir[i] = PAD_DOWN;
                }
                else if(temp2 & PAD_UP)
                {
                    player_dir[i] = PAD_UP;
                }
            }
            temp4 = player_x[i];
            temp5 = player_y[i];
            
            if(temp2 & PAD_LEFT)
            {
                if((player_hp[temp1] == 0 || player_x[temp1] < player_x[i] || player_x[temp1]-player_x[i] < 60))
                {
                    --player_x[i];
                }    
            } 
            else if(temp2 & PAD_RIGHT)
            {
                if(player_hp[temp1] == 0 ||player_x[i] < 250 && (player_x[temp1] > player_x[i] || player_x[i]-player_x[temp1] < 60))
                {
                    ++player_x[i];
                }
            }
            
            if(isBlocked(player_x[i], player_y[i])){
                player_x[i] = temp4;
            }
            else if(player_carry[i] != 0xFF)
            {
                item_x[player_carry[i]] += player_x[i]-temp4;
            }
            if(temp2 & PAD_UP)
            {
                if((player_hp[temp1] == 0 ||player_y[temp1] < player_y[i] || player_y[temp1]-player_y[i] < 60))
                {
                    --player_y[i];
                }    
            }
            else if( temp2 & PAD_DOWN)
            {
                if((player_hp[temp1] == 0 || player_y[temp1] > player_y[i] || player_y[i]-player_y[temp1] < 60))
                {
                    ++player_y[i];
                } 
            }
            if(isBlocked(player_x[i], player_y[i])){
                player_y[i] = temp5;
            }
            else if(player_carry[i] != 0xFF)
            {
                item_y[player_carry[i]] += player_y[i]-temp5;
            }
        }
        
        if(player_attack_tick[i] == 10)
        {
            temp0 = player_x[i];
            temp1 = player_y[i];
            temp6 = 5;
            temp7 = 5;
            
            if(player_dir[i] == PAD_LEFT) temp0 -= 4, temp6 = 8;
            else if(player_dir[i] == PAD_RIGHT) temp0 += 4, temp6 = 8;
            
            if(player_dir[i] == PAD_UP)  temp1 -= 4, temp7 = 8;
            else if(player_dir[i] == PAD_DOWN) temp1 += 3, temp7 = 8;
            dx = temp0;
            dy = temp1;
            if(isBlocked(temp0, temp1) == 0){
                took_damage();
            }
        }
    }
    
    temp2 = 0;
    for(i=0; i<4; i++)
    {
        if(item_placed[i]  == 0)
        {
            if(item_x[i] - item_target_x[i] < 2 || -item_x[i] + item_target_x[i]<2)
            {
                if(item_y[i] - item_target_y[i] < 2 || -item_y[i] + item_target_y[i]<2)
                {
                    item_placed[i] = 1;
                    item_x[i] = item_target_x[i];
                    item_y[i] = item_target_y[i];
                    if(player_carry[0] == i)
                    {
                        player_carry[0] = 0xFF;
                    }
                    if(player_carry[1] == i)
                    {
                        player_carry[1] = 0xFF;
                    }
								
					// Item placed SFX
					sfx_play(2, 3);
                }
            }
        }
        
        if(item_placed[i] == 0)
        {
            temp2 = 1;
        }
        int_temp0 = item_x[i];
        int_temp0 <<= 1;
        int_temp0 -= scr_x;
        
        if(int_temp0>255) continue;
        
        temp0 = int_temp0;

        int_temp0 = item_y[i];
        int_temp0 <<= 1;
        int_temp0 -= scr_y;
        if(int_temp0>255) continue;

        
        temp1 = int_temp0;
        
        spr = oam_spr(temp0-4, temp1-8, 0xC0+(item_type[i]<<1), 0x3, spr);
    }
    
    if(temp2 == 0)
    {
        next_level = 1;
	}
}

#define NAMETABLE_A             0x2000
#define NAMETABLE_B             0x2400
#define NAMETABLE_C             0x2800
#define NAMETABLE_D             0x2c00

void __fastcall__ init(void){
    oam_size(1);
    bank_spr(0);
    bank_bg(1);
	
  vram_adr(NAMETABLE_A);
  vram_unrle(bg_top_left);
  vram_adr(NAMETABLE_B);
  vram_unrle(bg_top_right);
  vram_adr(NAMETABLE_C);
  vram_unrle(bg_bottom_left);
  vram_adr(NAMETABLE_D);
  vram_unrle(bg_bottom_right);
  
  // copy tilesets
  vram_adr(0x0);
  vram_write((unsigned char*)0x0000, 0x2000);
  vram_adr(0x2000);
  vram_write((unsigned char*)0x2000, 0x2000);
	
	ppu_on_all();
    
    difficulty = 0;
    next_level = 0;
}

void __fastcall__ reset(void){
    next_level = 0;
	frame=0;
    
    player_dir[0] = PAD_UP;
    player_dir[1] = PAD_UP;
    
    player_hp[0] = 4;
    player_hp[1] = 4;
    
    scr_x = 128;
    scr_y = 128;
    
    player_x[0] = 120;
    player_y[0] = 120;
    player_x[1] = 136;
    player_y[1] = 120;
    
    player_attack_tick[0] = 0;
    player_attack_tick[1] = 0;
    
    
	enemies_enemy[0] = PLAYER_1;
	enemies_enemy[1] = PLAYER_2;
	enemies_enemy[2] = PLAYER_1;
	enemies_enemy[3] = PLAYER_2;
	enemies_enemy[4] = PLAYER_1;
	enemies_enemy[5] = PLAYER_2;
	enemies_enemy[6] = PLAYER_1;
	enemies_enemy[7] = PLAYER_2;

	for(i=0; i<8; ++i)
	{
		enemies_health[i] = 1;
        enemies_dir[i] = PAD_UP;
        enemy_leg[i] = (i&1);
		enemies_type[i] = (i&1);
	}

	enemy_spawn_points_x[0] = 184;
	enemy_spawn_points_y[0] = 24;
	enemy_spawn_points_x[1] = 232;
	enemy_spawn_points_y[1] = 72;
	enemy_spawn_points_x[2] = 232;
	enemy_spawn_points_y[2] = 168;
	enemy_spawn_points_x[3] = 184;
	enemy_spawn_points_y[3] = 216;
	enemy_spawn_points_x[4] = 72;
	enemy_spawn_points_y[4] = 217;
	enemy_spawn_points_x[5] = 24;
	enemy_spawn_points_y[5] = 167;
	enemy_spawn_points_x[6] = 24;
	enemy_spawn_points_y[6] = 73;
	enemy_spawn_points_x[7] = 72;
	enemy_spawn_points_y[7] = 24;

	for(i=0; i<8; ++i)
    {
		enemies_x[i] = enemy_spawn_points_x[i];
		enemies_y[i] = enemy_spawn_points_y[i];
        enemy_push_timer[i] = 0;
	}

    item_type[0] = 1;
    item_x[0] = 128;
    item_y[0] = 88;
    
    item_type[1] = 2;
    item_x[1] = 128;
    item_y[1] = 108;
    
    item_type[2] = 3;
    item_x[2] = 128;
    item_y[2] = 128;
    
    item_type[3] = 4;
    item_x[3] = 128;
    item_y[3] = 148;
    
    for(i=0; i<4; i++)
    {
        temp0 = rand8()&0xFE;
    
        item_x[i] = spawn[temp0]<<3;
        item_y[i] = spawn[temp0+1]<<3;
        for(j=0; j<i; j++)
        {
            if(item_x[i] == item_x[j] && item_y[i] == item_y[j])
            {
                i--;
                break;
            }
        }
    }
    
    
    for(i=0; i<4; i++)
    {
        item_x[i] += 2 + (rand8()&0x1) + (rand8()&0x1);
        item_y[i] += 2 + (rand8()&0x1) + (rand8()&0x1);
        
    }
    
    
    player_carry[0] = 0xFF;
    player_carry[1] = 0xFF;
    
    item_placed[0] = 0;
    item_placed[1] = 0;
    item_placed[2] = 0;
    item_placed[3] = 0;

    player_god_mode[0] = 0;
    player_god_mode[1] = 0;
    
	difficulty++;
    if(difficulty == 1)
    {
        enemy_speed = 2;
		enemy_damage_modifier = 31;
        spawn_hp = 1;
    }
    else if(difficulty == 2)
    {
        enemy_speed = 2;
		enemy_damage_modifier = 31;
        spawn_hp = 2;
    }
    else if(difficulty == 4)
    {
        enemy_speed = 3;
		enemy_damage_modifier = 31;
        spawn_hp = 2;
    }
    else if(difficulty == 6)
    {
        enemy_speed = 3;
		enemy_damage_modifier = 15;
        spawn_hp = 3;
    } 
    else if(difficulty == 7)
    {
        enemy_speed = 3;
		enemy_damage_modifier = 15;
        spawn_hp = 4;
    }
    else if(difficulty == 8)
    {
        enemy_speed = 4;
		enemy_damage_modifier = 15;
        spawn_hp = 5;
    }
    else if(difficulty == 9)
    {
        enemy_speed = 4;
		enemy_damage_modifier = 7;
        spawn_hp = 6;
    }
    else if(difficulty >= 10)
    {
        enemy_speed = 5;
		enemy_damage_modifier = 7;
        spawn_hp = 6 + (difficulty-10);
    }
    scroll(scr_x, scr_y);
}

void main(void){
	init();
    
//    music_play(0);
    oam_clear();

    while(1){
        pal_all(paused_palette);
        scroll(0, 0);
        ppu_wait_nmi();
        
        
        ppu_off();
        vram_adr(NAMETABLE_A);
	vram_unrle(bg_menu);
        ppu_on_all();
        
        pal_all(palette);
        ppu_wait_nmi();
        
        
        ppu_wait_nmi();
        while(1){
            ppu_wait_nmi();
            spr=0;
            oam_clear();
            frame++;
            if(frame&8)
            {
                spr = oam_spr(120, 135, 0x66, 0x3, spr);
                spr = oam_spr(120 + 8, 135, 0x68, 0x3, spr);
            }
            else
            {
                spr = oam_spr(120, 135, 0x6A, 0x3, spr);
                spr = oam_spr(120 + 8, 135, 0x6C, 0x3, spr);
            }
            
            spr = oam_spr(0x60, 0xA4, 0xEA, 0x1, spr);
            spr = oam_spr(0x70, 0xA4, 0xF0, 0x1, spr);
            spr = oam_spr(0x78, 0xA4, 0xEA, 0x1, spr);
            spr = oam_spr(0x80, 0xA4, 0xF2, 0x1, spr);
            spr = oam_spr(0x88, 0xA4, 0xF8, 0x1, spr);
            spr = oam_spr(0x90, 0xA4, 0xE4, 0x1, spr);
            spr = oam_spr(0x98, 0xA4, 0xFA, 0x1, spr);
            
            
            spr = oam_spr(0x60, 0xB4, 0xEA, 0x1, spr);
            spr = oam_spr(0x70, 0xB4, 0xFC, 0x1, spr);
            spr = oam_spr(0x78, 0xB4, 0xEA, 0x1, spr);
            spr = oam_spr(0x80, 0xB4, 0xFA, 0x1, spr);
            spr = oam_spr(0x88, 0xB4, 0xFE, 0x1, spr);
            
            
            spr = oam_spr(0x60, 0xC4, 0xF0, 0x1, spr);
            spr = oam_spr(0x70, 0xC4, 0xE0, 0x1, spr);
            spr = oam_spr(0x78, 0xC4, 0x04, 0x1, spr);
            spr = oam_spr(0x80, 0xC4, 0xF2, 0x1, spr);
            spr = oam_spr(0x88, 0xC4, 0xE0, 0x1, spr);
            spr = oam_spr(0x90, 0xC4, 0xF0, 0x1, spr);
            spr = oam_spr(0x98, 0xC4, 0xE4, 0x1, spr);
            spr = oam_spr(0xA0, 0xC4, 0x18, 0x1, spr);
            
            spr = oam_spr(0x60, 0xD4, 0xE6, 0x1, spr);
            spr = oam_spr(0x70, 0xD4, 0x04, 0x1, spr);
            spr = oam_spr(0x78, 0xD4, 0xF2, 0x1, spr);
            spr = oam_spr(0x80, 0xD4, 0xF8, 0x1, spr);
            spr = oam_spr(0x88, 0xD4, 0xE6, 0x1, spr);
            spr = oam_spr(0x90, 0xD4, 0xFA, 0x1, spr);
            
            
            
            if((pad_trigger(0)|pad_trigger(1))&(PAD_A|PAD_B|PAD_START))
            {
                break;
            }
        }
        spr=0;
        oam_clear();
        
        pal_all(paused_palette);
        ppu_wait_nmi();
        
        
        ppu_off();
        vram_adr(NAMETABLE_A);
	vram_unrle(bg_top_left);
        ppu_on_all();
        
        ppu_wait_nmi();
        
        difficulty = 0;
        next_level = 1;
        
        while(1){
            ppu_wait_nmi();
            spr=0;
            oam_clear();
            
            
            if(next_level)
            {
                // Next level SFX
                sfx_play(3, 2);

                reset();
                
                spr = 0;
                oam_clear();
                pal_all(paused_palette);
                spr = oam_spr(100, 114, 0xF4, 0x1, spr);
                spr = oam_spr(108, 114, 0xEA, 0x1, spr);
                spr = oam_spr(116, 114, 0xF6, 0x1, spr);
                spr = oam_spr(124, 114, 0xEA, 0x1, spr);
                spr = oam_spr(132, 114, 0xF4, 0x1, spr);
                if(difficulty<10)
                {
                    spr = oam_spr(148, 114, 0x04+(difficulty<<1), 0x1, spr);
                }
                else
                {
                    spr = oam_spr(148, 114, 0x05+(difficulty/10), 0x1, spr);
                    spr = oam_spr(156, 114, 0x04+(difficulty%10), 0x1, spr);
                }

                spr = 0;
                frame = 0;
                while(1)
                {
                    ppu_wait_nmi();
                    frame++;
                    if((frame > 100) && (frame == 255 || ((pad_trigger(0)|pad_trigger(1))&(PAD_A|PAD_B|PAD_START))))
                    {
                        spr++;
                        break;
                    }
                }

                pal_all(palette);
                spr = 0;
                oam_clear();
            }

            if(player_hp[0] == 0 || player_hp[1] == 0)
            {
                // Game Over SFX
                sfx_play(4, 2);

                difficulty = 0;
                next_level = 0;
                reset();
                
                spr = 0;
                oam_clear();
                pal_all(paused_palette);
                spr = oam_spr(92, 114, 0xEE, 0x1, spr);
                spr = oam_spr(100, 114, 0xE4, 0x1, spr);
                spr = oam_spr(108, 114, 0xF0, 0x1, spr);
                spr = oam_spr(116, 114, 0xEA, 0x1, spr);
                
                spr = oam_spr(132, 114, 0x04, 0x1, spr);
                spr = oam_spr(140, 114, 0xF6, 0x1, spr);
                spr = oam_spr(148, 114, 0xEA, 0x1, spr);
                spr = oam_spr(156, 114, 0xF2, 0x1, spr);
                
                spr = 0;
                frame = 0;
                while(1)
                {
                    ppu_wait_nmi();
                    frame++;
                    if(frame == 255)
                    {
                        spr++;
                    }
                    if((spr == 4) || (spr >= 1 && ((pad_trigger(0)|pad_trigger(1))&(PAD_A|PAD_B|PAD_START))))
                    {
                        break;
                    }
                }

                pal_all(palette);
                spr = 0;
                oam_clear();
                break;
            }

            temp1 = pad_trigger(0) | pad_trigger(1);
            if(temp1 & PAD_START)
            {
                spr = 0;
                oam_clear();
                pal_all(paused_palette);
                spr = oam_spr(104, 114, 0xE2, 0x1, spr);
                spr = oam_spr(112, 114, 0xE4, 0x1, spr);
                spr = oam_spr(120, 114, 0xE6, 0x1, spr);
                spr = oam_spr(128, 114, 0xE8, 0x1, spr);
                spr = oam_spr(136, 114, 0xEA, 0x1, spr);
                spr = oam_spr(144, 114, 0xEC, 0x1, spr);

                while(!(pad_trigger(0) & PAD_START))
                {
                    ppu_wait_nmi();
                }

                pal_all(palette);
                spr = 0;
                oam_clear();
            }

            int_temp0 = 124;
            int_temp0 <<= 1;
            int_temp0 -= scr_x;
            
            if(int_temp0 <= 255)
            {
                temp0 = int_temp0;
            
                int_temp0 = 116;
                int_temp0 <<= 1;
                int_temp0 -= scr_y;
            
                if(int_temp0 <= 255)
                {
                    temp1 = int_temp0;
                    if(frame&8)
                    {
                        spr = oam_spr(temp0, temp1 - 1, 0x66, 0x3, spr);
                        spr = oam_spr(temp0 + 8, temp1 - 1, 0x68, 0x3, spr);
                    }
                    else
                    {
                        spr = oam_spr(temp0, temp1 - 1, 0x6A, 0x3, spr);
                        spr = oam_spr(temp0 + 8, temp1 -1, 0x6C, 0x3, spr);
                    }
                }
            }
            
            tick_players();
            tick_enemies();
            
            temp0 = 0;
            
            if(to_scroll_x){
                if(to_scroll_x_neg){
                    scr_x -= to_scroll_x;
                }else{
                    scr_x += to_scroll_x;
                }
            }
            if(to_scroll_y){
                if(to_scroll_y_neg){
                    scr_y -= to_scroll_y;
                }else{
                    scr_y += to_scroll_y;
                }
            }
            scroll(scr_x, scr_y);
            ++frame;
            
             
        }
	}
}
