#include "../data.h"
#include "../game.h"
#include "qblock.h"

void vg_object_qblock_logic(VG_SPRITE * sp)
{
	sp->frame++;
	switch(sp->state)
	{
		case 0:
		{
			break;
		}
		case 1:
		{
			if(sp->frame < 7)
			{
				sp->y += sp->vy;
			}
			else if(sp->frame < 13)
			{
				sp->y += itofix(1);
			}
			break;
		}
	}
}

void vg_object_qblock_hit(VG_SPRITE * sp)
{
	int i;
	
	if(sp->state == 0)
	{
		vg_player.score += 100;
		sp->vy = itofix(-1);
		sp->frame = 0;
		sp->state = 1;
		for(i = 0; i < VG_MAX_OBJECTS; i++)
		{
			if(!vg_sprite[i].active)
			{
				vg_sprite[i].type = VG_SPRITE_COIN;
				vg_sprite[i].sp = vg_sprite_data[vg_sprite[i].type];
				vg_sprite[i].x = sp->x;
				vg_sprite[i].y = sp->y - itofix(16);
				vg_sprite[i].vx = itofix(0);
				vg_sprite[i].vy = itofix(-1);
				vg_sprite[i].active = 1;
				vg_sprite[i].state = 1;
				vg_sprite[i].angle = itofix(0);
				vg_sprite[i].id = i;
				vg_sprite[i].death = 0;
				vg_sprite[i].frame = 0;
				break;
			}
		}
		ncds_play_sample(vg_sound[VG_SOUND_PLAYER_COIN], 127, -1, -1);
	}
}
