Пример #1
0
//  Play a single Set and record winner then display a screen showing who won
void Set::Play(Player players[], int BGPos[], int cursorpos[], int cursoractual[]) {
	bool running = true;
	int leg = 0;
	bool lastthrow = 0;
	
	while (running) {
		legs[leg].Play(players, BGPos, cursorpos, cursoractual);
		leg++;
		if (players[0].p_legwins[setnumber] == 3 || players[1].p_legwins[setnumber] == 3) {
			running = false;
		}
	
	}
	
	if (players[0].p_legwins[setnumber] == 3) {
		lastthrow = 0;
	} else {
		lastthrow = 1;
	}
 	ClearScreenBlocks(25,31);
	DrawWindow(0, 0, 30, 20);
	players[lastthrow].DrawName(13, 8);
	DrawText(13, 10, "Wins the Set!", 25);
	players[lastthrow].p_setwins++;
	
	for (int i = 0; i < DELAY; i++) {
		WaitVSync();
	}
}
Пример #2
0
// Play a single leg, resetting all necessary numbers before doing so.
void Leg::Play(Player players[], int BGPos[], int cursorpos[], int cursoractual[]) {
	
	players[0].ResetForNextLeg();
	players[1].ResetForNextLeg();
	ClearScreenBlocks(25,31);
	DrawDartboard();
	DrawWindow(19, 0, 11, 20);
	players[0].DrawName(20,2);
	players[1].DrawName(25,2);
	players[0].DrawPoints(20,3);
	players[1].DrawPoints(25,3);

	bool running = true;
	int pointsdisplay = 1;		//  remember number of lines of points displayed so far

	//  Game loop
	//  flip-flop between players 1 and 2, after each turn check for a winner
	while (running)
	{
		UpdateObjects();
		
		playertothrow = !playertothrow;
		players[playertothrow].TakeTurn(cursoractual, cursorpos, BGPos, playertothrow);
		
		if (playertothrow == 1) {	
			pointsdisplay++;
		}
		if (players[playertothrow].GetPoints() == 0) {
			running = false;
		}
	}
	
	//  Once someone wins clear screen and display winner
	ClearScreenBlocks(25,31);
	DrawWindow(0, 0, 30, 20);
	players[playertothrow].DrawName(13, 8);
	players[playertothrow].p_legwins[setnumber]++;
	DrawText(13, 10, "Wins the Leg!", 25);	
	for (int i = 0; i < DELAY; i++) {
		WaitVSync();
	}	
	
}
Пример #3
0
//  Take a 'turn' (throw three darts)
void Player::TakeTurn(int cursoractual[], int cursorpos[], int BGPos[], bool playertothrow) {
	int throws = 3;
	int wait = 0;
	p_turnthrows = 0;
	p_turnstartpoints = p_points;
	SetTile(27, 23+5*playertothrow, 1, 5);
	SetTile(27, 23+5*playertothrow-1, 1, 5);
	SetTile(27, 23+5*playertothrow-2, 1, 5);
	
	while ((throws > 0 && p_points > 0) || wait < 40) {
		UpdateObjects();
		
		if (throws > 0 && p_points > 0) {	
			WaitVSync();
			UpdateObjects();
			TakeAShot(cursoractual, cursorpos, BGPos);
			DrawPoints(20+5*playertothrow, 4 + p_throws);
			
			SetTile(27, 23+5*playertothrow-p_turnthrows, 1, 4);
			
			p_throws++;
			p_turnthrows++;
			throws--;
		} else {
			wait++;
		}
		
		for (int i = 0; i < p_turnthrows; i++) {
			darts[i].UpdateDart(BGPos);			
		}
	}
	SetTile(27, 23+5*playertothrow, 1, 4);
	SetTile(27, 23+5*playertothrow-1, 1, 4);
	SetTile(27, 23+5*playertothrow-2, 1, 4);
	ClearObjects();
}
Пример #4
0
int main()
{
	// Set display options.
	// DCNT_MODE0 sets mode 0, which provides four tiled backgrounds.
	// DCNT_OBJ enables objects.
	// DCNT_OBJ_1D make object tiles mapped in 1D (which makes life easier).
	REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_OBJ;
	
	REG_BG0CNT = BG_CBB(0) | BG_SBB(30) | BG_8BPP | BG_REG_32x32 | BG_PRIO(0);
	
	REG_BG1CNT = BG_CBB(0) | BG_SBB(29) | BG_8BPP | BG_REG_32x32 | BG_PRIO(1);
	
	REG_BG2CNT = BG_CBB(0) | BG_SBB(25) | BG_8BPP | BG_REG_64x64 | BG_PRIO(2);
	REG_BG2HOFS = 0;
	REG_BG2VOFS = 0;
	
	ClearObjects();
	
	SetPaletteBG(1, RGB(31, 31, 31)); // white
	
	//Load each tile in font_bold into it's corresponding position in charblock 0
	for (int i = 0; i < 128; i++)
	{
		LoadTile8(0, i, font_bold[i]);
	}
	
	DrawText(5, (SCREEN_HEIGHT / 16) - 2, "DECEPTIVE DIMENSIONS");
	DrawText(5, (SCREEN_HEIGHT / 16), "Press start to begin");
	
	Buttons buttons;
	int framecounter = 0;
	
	//Title screen (under construction)
	while (true)
	{
		buttons.Update();
		
		if (buttons.StartJustPressed())
		{
			break;
		}
		
		WaitVSync();	
	}
	
	while (true)
	{
		//Load Custom spritesheet
		LoadPaletteObjData(0, spritesheet4Pal, sizeof spritesheet4Pal);
		LoadPaletteBGData(0, backgroundnewnewPal, sizeof backgroundnewnewPal);
		LoadTileData(4, 0, spritesheet4Tiles, sizeof spritesheet4Tiles);
		LoadTileData(0, 0, backgroundnewnewTiles, sizeof backgroundnewnewTiles);
		
		int levelnumber = 1;
		
		Level level(levelnumber);
		
		for (int screenblock = 21; screenblock < 31; screenblock++)
		{
			level.FillScreenblock(screenblock, 0);
		}
		
		level.DrawBackground(level.curdimension);
		
		bool gamerunning = true;
		
		//Main game loop
		while (gamerunning)
		{
			buttons.Update();
			
			gamerunning = level.CheckIfLevelComplete();
			level.TakeInput(buttons);
			level.MoveObjects();
			level.Draw();
			level.UpdateLevelObjects(framecounter);

			framecounter++;
			
			WaitVSync();
			FlipBuffers();
		}
		
		//Reload each tile in font_bold into it's corresponding position in charblock 0
		for (int i = 0; i < 128; i++)
		{
			LoadTile8(0, i, font_bold[i]);
		}
		
		SetPaletteBG(0, RGB(0, 0, 0)); // black
		SetPaletteBG(1, RGB(31, 31, 31)); // white		
		
		for (int screenblock = 25; screenblock < 31; screenblock++)
		{
			for (int y = 0; y < 32; y++)
			{
				for (int x = 0; x < 32; x++)
				{
					SetTile(screenblock, x, y, 0);
				}
			}
		}
		
		level.player.drawx = SCREEN_WIDTH;
		
		SetObject(level.player.GetObjNum(),
		  ATTR0_SHAPE(2) | ATTR0_8BPP | ATTR0_HIDE,
		  ATTR1_SIZE(2) | ATTR1_X(level.player.drawx),
		  ATTR2_ID8(0) | ATTR2_PRIO(2));
		
		UpdateObjects();
		
		DrawText(6, (SCREEN_HEIGHT / 16) - 2, "That's all folks!!");
		DrawText(3, (SCREEN_HEIGHT / 16), "Press start to try again");
		
		while (true)
		{
			buttons.Update();
			
			if (buttons.StartJustPressed())
			{
				break;
			}
			
			WaitVSync();
		}
	}
}
Пример #5
0
//  Throw a single dart, handles both AI and Player controlled, if a player than enable cursor and wait for input
//  if computer then call target select functions and decide what to do with results by passing to DartLocationDecide()
void Player::TakeAShot(int cursoractual[], int cursorpos[],int BGPos[]){
	bool wait = true;
	oldkey[A_KEY] = true;

	if (p_ishuman == true) {		
		while (wait) {
			WaitVSync();
			UpdateObjects();
			HandleCursorMovement(cursoractual, cursorpos, BGPos);
			
			for (int i = 0; i < p_turnthrows; i++) {
				darts[i].UpdateDart(BGPos);			
			}
			
			if ((REG_P1 & KEY_A) == 0 && oldkey[A_KEY] == false) {
				GetPointsValue(cursoractual, BGPos);
				wait = false;
				oldkey[A_KEY] = true;
			}
			if ((REG_P1 & KEY_A) != 0) {
				oldkey[A_KEY] = false;
			}
		}
		if (p_colinmode) {
			Inaccuracy();
			DartLocationDecide();
			darts[p_turnthrows] = Dart(p_darthitloc[0], p_darthitloc[1], p_turnthrows+1);					
		} else {	
			darts[p_turnthrows] = Dart(cursoractual[0]+BGPos[0], cursoractual[1]+BGPos[1], p_turnthrows+1);	
		}
	} else {
		for (int animate = 0; animate < 10; animate++) {
			WaitVSync();
			UpdateObjects();
			for (int i = 0; i < p_turnthrows; i++) {
				darts[i].UpdateDart(BGPos);			
			}					
		}
		for (int i  = DELAY; i > 0; i--) {
			WaitVSync();
		}		
		TargetSelect(0);
		Inaccuracy();
		DartLocationDecide();
		BGPos[0] = p_darthitloc[0]-80;
		BGPos[1] = p_darthitloc[1]-80;
		
		REG_BG3HOFS = BGPos[0];
		REG_BG3VOFS = BGPos[1];	
		darts[p_turnthrows] = Dart(p_darthitloc[0], p_darthitloc[1], p_turnthrows+1);
	}
	if (CheckLegality(p_hit)) {
		p_points -= p_hit;	
		DrawText(20, 17, "          ", 25);
		if (p_targettype == 0) {
			DrawText(20, 17, "Single", 25);
			DrawNumber(27, 17, (p_hit), 25);
		} else if (p_targettype == 1) {
			DrawText(24, 17, "Bull", 25);
		} else if (p_targettype == 2) {
			DrawText(20, 17, "Double", 25);
			DrawNumber(27, 17, (p_hit/2), 25);
		} else if (p_targettype == 3) {
			DrawText(20, 17, "Treble", 25);
			DrawNumber(27, 17, (p_hit/3), 25);
		} else if (p_targettype == 4) {
			DrawText(21, 17, "BullsEye", 25);
		} else {
			DrawText(24, 17, "Miss", 25);
		}				
	} else {
		DrawText(20, 17, "  Illegal   ", 25);
	}

}
Пример #6
0
int main()
{
    LoadAssets();
    ClearObjects();
    InitialiseStage();

    uint16_t oldKeys = REG_P1;

    Cursor cursor = Cursor(0);

    bool pieceSelected = false;
    int currentPiece = 0;
    int* moves = new int[28];
    int* takingMoves = new int[16];

    int currentTurnColor = WHITE;
    for(int i = 0; i < 2; i++)
        for(int j = 0; j < 16; j++)
            _lostPieces[i][j] = -1;


    while (true)
    {
        if(!(REG_P1 & KEY_RIGHT) && (oldKeys & KEY_RIGHT))
            cursor.Move(1,  0);
        if(!(REG_P1 & KEY_LEFT) && (oldKeys & KEY_LEFT))
            cursor.Move(-1, 0);
        if(!(REG_P1 & KEY_DOWN) && (oldKeys & KEY_DOWN))
            cursor.Move(0,  1);
        if(!(REG_P1 & KEY_UP) && (oldKeys & KEY_UP))
            cursor.Move(0, -1);

        if(!(REG_P1 & KEY_A) && (oldKeys & KEY_A))
        {
            if(PieceAt(cursor.X(), cursor.Y()))
            {
                pieceSelected = true;
                for(int i = 0; i < 16 && takingMoves[i] >= 0; i++)
                    if(takingMoves[i] % 8 == cursor.X() && takingMoves[i] / 8 == cursor.Y())
                    {
                        TakePiece(currentPiece % 8, currentPiece / 8, cursor.X(), cursor.Y());
                        currentTurnColor = (currentTurnColor == WHITE ? BLACK : WHITE);
                        pieceSelected = false;
                        ClearHighlights();
                        takingMoves[0] = -1;
                        break;
                    }

                if(pieceSelected && PieceColor(cursor.X(), cursor.Y()) == currentTurnColor)
                {
                    ClearHighlights();

                    AvailableMoves(cursor.X(), cursor.Y(), moves, takingMoves);

                    currentPiece = cursor.Y() * 8 + cursor.X();

                    for(int i = 0; i < 28 && moves[i] >= 0; i++)
                        Highlight(moves[i] % 8, moves[i] / 8, GREEN);

                    for(int i = 0; i < 16 && takingMoves[i] >= 0; i++)
                        Highlight(takingMoves[i] % 8, takingMoves[i] / 8, RED);
                }
            }
            else if(pieceSelected)
            {
                ClearHighlights();

                if(!PieceAt(cursor.X(), cursor.Y()))
                {
                    for(int i = 0; i < 28 && moves[i] >= 0; i++)
                        if(moves[i] % 8 == cursor.X() && moves[i] / 8 == cursor.Y())
                        {
                            MovePiece(currentPiece % 8, currentPiece / 8, cursor.X(), cursor.Y());
                            currentTurnColor = (currentTurnColor == WHITE ? BLACK : WHITE);
                            pieceSelected = false;
                            break;
                        }
                }
            }
        }

        oldKeys = REG_P1;

        if(currentTurnColor == WHITE)
            DrawString(20, 1, "WHITE", 5);
        else
            DrawString(20, 1, "BLACK", 5);

        WaitVSync();
        UpdateObjects();
    }

    return 0;
}
Пример #7
0
int main(){

	uint8_t y,dx,x,fileNo=0,c;
	uint16_t j=0;

//	uint32_t test=0xaabbccdd;
//	mmc_readsector(test);



	topMenu();
	init();
	topMenu();



	FS_File file;
	FRESULT res;
	x=2;y=15;
	
	while(1){
		res=FS_ListDir(&file);
		if(file.filename[0]==0) break;
		if(res==FR_OK){
			if(filter(&file)){
				
				j=0;
				for(dx=0;dx<8;dx++){
					c=file.filename[j++];
					if(c=='~') c='-';
					vram[(y*40)+x+dx]=c-32;
				}
				y++;
				if(y==25){
					y=5;
					x+=9;
				}

				break;
			}
		}else{
				Print((26*40*2)+(7*2),PSTR("LIST FILE FAIL"),0);
		}
	}

	int bytesRead;


	while(1){


			x=2;y=2;
			res=FS_ReadBlock(&file,&bytesRead);
			if(res==0){

				for(j=0;j<512;j++){
					c=sector.buffer[j];
					if(c<32 || c>'z')c=32;
					if(c>='a' && c<='z')c&=~0x20;
					vram[(y*40)+x]=c-32;
					
					x++;
					if(x>=38){
						x=2;
						y++;
					}
				}

				PrintHexInt(30,22,bytesRead);

			}else{
				Print((26*40*2)+(7*2),PSTR("BLOCK READ FAIL"),0);
			}
		
		
			while(1){
				if(joypad_status&BTN_RIGHT){
					while(joypad_status!=0){};
					break;
				}

				if(joypad_status&BTN_SR){
					break;
				}
			};

		
	}

	unsigned char col=1,dir=1;
	while(1){
		//drawCursor(x-1,y+fileNo,37,col);
		DrawBar((y+fileNo)*40*2,40,col);
		WaitVSync(6);	

		col+=dir;
		if(col==5){
			dir=-1;
		}else if(col==0){
			dir=1;
		}

	}

	while(1);
}
Пример #8
0
int main()
{
	initializeGraphics();	

	MouseType mouseObject = IDLE;

	int cursorXLocation = 10;
	int cursorYLocation = 10;

	// These control building & unit logic
	GameEntity* buildingsContainer = NULL;
	GameEntity* unitsContainer = NULL;

	uint16_t population = 0;		// This controls population count
	uint16_t frame = 0;				// This counts frames
	uint16_t unitSpawnDelay = 0;			// This controls the delay between unit spawns

	while (true)
	{
		FlipBuffers();																				// Flip buffers
		
		ClearScreen8(SAND_COLOR);																	// Clear screen

		render(buildingsContainer,unitsContainer);													// Render all buildings and units

		animatePowerPlant(frame);																	// Animate the power plant
		animateBarracks(frame);																		// Animate the barracks

		if(mouseObject!=IDLE)																		// If there has been some mouse action ...
		{
			if(isMovement(mouseObject))																	// ... and it is movement ...
			{
				move(cursorXLocation,cursorYLocation,mouseObject);											// ... movet the mouse.
			}
			 
			else if(isPlacement(mouseObject))															// ... if it is placement ...
			{
				place(cursorXLocation,cursorYLocation,mouseObject,buildingsContainer);						// ... attempt placement.
			}

			else if(isSpawning(mouseObject) && unitSpawnDelay==0 && population!=POP_CAP)				// ... if it is a unit and it's not to soon after the last unit was trained and population cap has not been reached  ...
			{														
				spawn(unitsContainer,buildingsContainer);													// place the unit
				population++;																				// increase population

				unitSpawnDelay = UNIT_SPAWN_COOLDOWN_PERIOD;												// start cooldown timer
			}
		}

		drawCursor(cursorXLocation,cursorYLocation);												// Draw the cursor

		mouseObject = updatedMouseType();															// Update the mouse

		WaitVSync();																				// Sync

		frame = (frame == 100) ? 0 : frame+1;														//	Reset frame count every 100 frames, else increase by one

		if(unitSpawnDelay!=0)																		// If there is a cooldown timer in action ...
			unitSpawnDelay--;																			// ... update it!

	}
	
	// We are environmentaly concious, so we clean after ourselves
	delete buildingsContainer;					
	delete unitsContainer;

	return 0;
}
Пример #9
0
void enterMenu(int menu){
	LoadPaletteBGData(0, menuBGPal, menuBGPalLen);
	
	bool active = true;
	int option = 0;
	int keyPressCoolDown = 30;
	if(menu == 0)ClearObjects();
	
	//MENU LOOP
	while(active){
		keyPressCoolDown--;
		if(keyPressCoolDown <= 0)keyPressCoolDown = 0;
		clearText();
		switch(menu){
			case 0://Main menu
			if((REG_KEYINPUT & KEY_UP) == 0){
				option = 0;
			}
			if((REG_KEYINPUT & KEY_DOWN) == 0){
				option = 1;
			}
			if((REG_KEYINPUT & KEY_A) == 0 && keyPressCoolDown == 0){
				if(option == 0){
					active = false;
					gameInit();
				}else{
					menu = 1;
					keyPressCoolDown = 30;
				}
			}
			drawText(60,20,"Super Crate Box");
			drawText(105,65,"PLAY");
			drawText(93,90,"CREDITS");
			
			if(option == 0)drawText(90, 65, ">      <");
			if(option == 1)drawText(78, 90, ">         <");
			break;
			
			case 1://Credits
			if((REG_KEYINPUT & KEY_A) == 0 && keyPressCoolDown == 0){
				menu = 0;
				keyPressCoolDown = 30;
			}
			if((REG_KEYINPUT & KEY_B) == 0 && keyPressCoolDown == 0){
				menu = 0;
				keyPressCoolDown = 30;
			}
			
			drawText(30, 20, "GBA - Super Crate Box");
			drawText(30,60, "Created by Peter Black");
			drawText(70,80, "for CGA 2014");
			drawText(8, 135, "Assets & Gameplay C Vlambeer");
			break;
			
			case 2://Game Over
			if((REG_KEYINPUT & KEY_A) == 0 && keyPressCoolDown == 0){
				active = false;
				gameInit();
			}
			if((REG_KEYINPUT & KEY_B) == 0 && keyPressCoolDown == 0){
				menu = 0;
				ClearObjects();
				keyPressCoolDown = 30;
			}
		
			drawText(82,60,"GAME OVER");
			drawText(85,80,"Score:");
			drawText(133,80,toString(score));
			drawText(77, 125,"A = Retry");
			drawText(65, 135,"B = Main Menu");
			
			
			break;
		}
		
		
		WaitVSync();
		UpdateObjects();
	}
	
	LoadPaletteBGData(0, backgroundPal, backgroundPalLen);
}
Пример #10
0
int main()
{
	init();
	
	enterMenu(0);

	int cloudScroll = 0;
	int loopSlower = 0;
	bool shootCoolDown = true;
	int reloadTimer = 0;
	
	//GAME LOOP
	while (true)
	{	
		//INPUT
		if((REG_KEYINPUT & KEY_RIGHT) == 0){
			tryMove(2,0,player.getWidth()-2,player.getHeight()/2,player);
			player.setRunning(true);
			player.setDir(true);
		}
		if((REG_KEYINPUT & KEY_LEFT) == 0){
			tryMove(-2,0,0,player.getHeight()/2,player);
			player.setRunning(true);
			player.setDir(false);
		}
		if((REG_KEYINPUT & KEY_UP) == 0 || (REG_KEYINPUT & KEY_B) == 0){
			if(player.getLanded()){
				player.jump();
				player.updateFrame();
			}
			player.setJumpHeight(player.getJumpHeight()+4);
		}
		if((REG_KEYINPUT & KEY_A) == 0){
			if(shootCoolDown){
				if(weapon == 8){
					if(player.getDir())tryMove(-2,0,0,player.getHeight()/2,player);
					else tryMove(2,0,player.getWidth()-2,player.getHeight()/2,player);
				}else if(weapon == 1){
					if(player.getDir())tryMove(-1,0,0,player.getHeight()/2,player);
					else tryMove(1,0,player.getWidth()-2,player.getHeight()/2,player);
				}
				shoot();
				shootCoolDown = false;
				reloadTimer = 0;
			}
		}
		
		//Player movement
		if(player.getJumping()){
			if(!tryMove(0,-3,player.getWidth()/2,0,player)){
				player.setJumping(false);
			}
		}else{
			if(!tryMove(0,2,player.getWidth()/2,player.getHeight(),player)){
				tryMove(0,1,player.getWidth()/2,player.getHeight(),player);
				player.setLanded(true);
				player.setJumping(false);
			}else{
				player.setLanded(false);
			}
		}

		//Monster Movement
		for(int i = 0; i < enemies.size(); i++){
			if(!enemies.at(i).isDead()){
				if(enemies.at(i).getDir()){
					if(!tryMove(1,0,enemies.at(i).getWidth(),(enemies.at(i).getHeight()/2)+1,enemies.at(i))){
						enemies.at(i).setDir(false);
					}
				}else{
					if(!tryMove(-1,0,0,(enemies.at(i).getHeight()/2)+1,enemies.at(i))){
						enemies.at(i).setDir(true);
					}
				}
				tryMove(0,2,enemies.at(i).getWidth()/2,enemies.at(i).getHeight(),enemies.at(i));
				ObjBuffer[i+3].attr0 &= ~(ATTR0_HIDE);
			}else{
				ObjBuffer[i+3].attr0 |= ATTR0_HIDE;
			}
		}
		
		//Bullet movement
		for(int i = 0; i < bullets.size(); i++){
			if(!bullets.at(i).isDead()){
			
				int yMove = 0;
				if(rand() % 3 == 0)yMove = bullets.at(i).getLift(); 
				
				if(bullets.at(i).getType() == 4){
				
					tryMove(0,1,bullets.at(i).getWidth(),bullets.at(i).getHeight()+4,bullets.at(i));
					
				}else if(bullets.at(i).getType() == 6){
					if(player.getDir()){
						ObjBuffer[i+24].attr1 &= ~(ATTR1_HFLIP);
						bullets.at(i).move(player.getX()+8, player.getY());
					}else{
						ObjBuffer[i+24].attr1 |= ATTR1_HFLIP;
						bullets.at(i).move(player.getX()-8, player.getY());
					}	
					if(bullets.at(i).charge()){
						bullets.at(i).setDead(true);
						int number = 0;
						if(player.getDir())number = (SCREEN_WIDTH - player.getX())/8;
						else number = (0 + player.getX())/8;
	
						for(int i = 0; i < number; i++){
							spawnBullet(7);
						}
					}
				}else if(bullets.at(i).getType() == 7){
					if(bullets.at(i).charge())bullets.at(i).setDead(true);
				}else{
					if(bullets.at(i).getDir()){
						if(!tryMove(2,yMove,bullets.at(i).getWidth(), bullets.at(i).getHeight(), bullets.at(i))){	
							if(bullets.at(i).getType() == 3 && !bullets.at(i).getBounce()){
								bullets.at(i).setBounce(true);
								bullets.at(i).setDir(false);
							}else{
								bullets.at(i).setDead(true);
								if(bullets.at(i).getType() == 0
								|| bullets.at(i).getType() == 4){
									explode(bullets.at(i).getX(), bullets.at(i).getY());
								}
							}
						}
					}else{ 
						if(!tryMove(-2,yMove,bullets.at(i).getWidth(), bullets.at(i).getHeight(), bullets.at(i))){
							if(bullets.at(i).getType() == 3 && !bullets.at(i).getBounce()){
								bullets.at(i).setBounce(true);
								bullets.at(i).setDir(true);
							}else{
								bullets.at(i).setDead(true);
								if(bullets.at(i).getType() == 0
								|| bullets.at(i).getType() == 4){
									explode(bullets.at(i).getX(), bullets.at(i).getY());
								}
							}
						}
					}
				}
				ObjBuffer[i+24].attr0 &= ~(ATTR0_HIDE);
			}else{
				ObjBuffer[i+24].attr0 |= ATTR0_HIDE;
			}
		}
		
		for(int i = 0; i < enemies.size(); i++){
			if(!enemies.at(i).isDead()){
				if(checkEntityCollision(player, enemies.at(i))){
					player.setDead(true);
				}
				
				for(int k = 0; k < bullets.size(); k++){
					if(!bullets.at(k).isDead()){
						if(checkEntityCollision(bullets.at(k), enemies.at(i))){
							enemies.at(i).hurt(bullets.at(k).getDamage());
							if(bullets.at(k).getType() != 3
							&& bullets.at(k).getType() != 6
							&& bullets.at(k).getType() != 7){
								bullets.at(k).setDead(true);
								if(bullets.at(k).getType() == 0
								|| bullets.at(k).getType() == 4){
									explode(bullets.at(k).getX(), bullets.at(k).getY());
								}
							}
							break;
						}
					}
				}
			}
		}
		
		if(checkEntityCollision(player, crate)){
			crate.setDead(true);
			weapon = crate.getWeapon();
			score++;
		}
		
		if(crate.isDead()){
			switch(rand() % 7){
				case 0:crate.move(80,32);
				break;
				case 1:crate.move(150,32);
				break;
				case 2:crate.move(30,64);
				break;
				case 3:crate.move(200,64);
				break;
				case 4:crate.move(115,104);
				break;
				case 5:crate.move(80,144);
				break;
				case 6:crate.move(150,144);
				break;
			}
			int newWep = 0;
			do newWep = rand() % 9;
			while(newWep == weapon || newWep == 6);
			crate.setWeapon(newWep);
			crate.setDead(false);
		}
		
		//General Slow things
		if(loopSlower % 7 == 0){
			cloudScroll++;
			REG_BG3HOFS = cloudScroll;
		
			SetTile(30, 14, 19, 16+rand()%5);
			SetTile(30, 15, 19, 16+rand()%5);
			
			player.updateFrame();
			
			for(int i = 0; i < enemies.size(); i++){
				if(!enemies.at(i).isDead()){
					enemies.at(i).updateFrame();
				}
			}
			ObjBuffer[2].attr2 = ATTR2_ID8(player.getFrame());
			for(int i = 0; i < enemies.size(); i++){
				ObjBuffer[i+3].attr2 = ATTR2_ID8(enemies.at(i).getFrame());
			}
			
		}
		
		reloadTimer++;
		if(weapon == 0 || weapon == 5 || weapon == 6 || weapon == 7){
			if(reloadTimer >= 60){
				shootCoolDown = true;
			}
		}else if(weapon == 2 || weapon == 4){
			if(reloadTimer >= 45){
				shootCoolDown = true;
			}
		}else if (weapon == 3){
			if(reloadTimer >= 20){
				shootCoolDown = true;
			}
		}else if(weapon ==  1){
			if(reloadTimer >= 10){
				shootCoolDown = true;
			}
		}else{
			if(reloadTimer >= 5){
				shootCoolDown = true;
			}
		}
		if(reloadTimer > 1000)reloadTimer = 60;
		
		//Monster spawner
		if(rand()%100 == 0){
			spawnMonster();	
		}
		
		//Player state updates
		if(player.getJumping())player.setState(2);
		else if(player.getRunning())player.setState(1);
		else player.setState(0);
		
		if(!player.getDir()){
			ObjBuffer[0].attr1 |= ATTR1_HFLIP;
			ObjBuffer[2].attr1 |= ATTR1_HFLIP;
		}else{
			ObjBuffer[0].attr1 &= ~(ATTR1_HFLIP);
			ObjBuffer[2].attr1 &= ~(ATTR1_HFLIP);
		}
		
		if(weapon == 8)ObjBuffer[0].attr0 |= ATTR0_SHAPE(1);
		else ObjBuffer[0].attr0 &= ~(ATTR0_SHAPE(1));
		
		ObjBuffer[0].attr2 = ATTR2_ID8(22+weapon);
			
		for(int i = 0; i < enemies.size(); i++){
			if(!enemies.at(i).isDead()){
				if(!enemies.at(i).getDir())ObjBuffer[i+3].attr1 |= ATTR1_HFLIP;
				else ObjBuffer[i+3].attr1 &= ~(ATTR1_HFLIP);
			}
		}
		
		player.update();
		
		if(player.isDead())enterMenu(2);
	
		//Render
		if(!player.getDir()){
			if(weapon != 8)SetObjectX(0, player.getX()-4);
			else{
				if(player.getX()-12 <= 0) SetObjectX(0, 0);
				else SetObjectX(0, player.getX()-12);
			}	
		}else{
			SetObjectX(0, player.getX()+4);
		}
		SetObjectY(0, player.getY()+1);
		
		SetObjectX(1, crate.getX());
		SetObjectY(1, crate.getY());
		
		SetObjectX(2, player.getX());
		SetObjectY(2, player.getY());
		
		for(int i = 0; i < enemies.size(); i++){
			if(!enemies.at(i).isDead()){
				SetObjectX(i+3, enemies.at(i).getX());
				SetObjectY(i+3, enemies.at(i).getY());
			}
		}
		
		for(int i = 0; i < bullets.size(); i++){
			if(!bullets.at(i).isDead()){
				SetObjectX(i+24, bullets.at(i).getX());
				SetObjectY(i+24, bullets.at(i).getY());
			}
		}

		drawText(112,10,toString(score));
		
		WaitVSync();
		UpdateObjects();
		clearText();
		loopSlower++;
	}

	return 0;

}