2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
#pragma hdrstop
|
2012-12-22 15:18:19 +00:00
|
|
|
#include "precompiled.h"
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
#include "../renderer/Image.h"
|
|
|
|
|
|
|
|
#include "DeviceContext.h"
|
|
|
|
#include "Window.h"
|
|
|
|
#include "UserInterfaceLocal.h"
|
|
|
|
#include "GameBustOutWindow.h"
|
|
|
|
|
|
|
|
#define BALL_RADIUS 12.f
|
|
|
|
#define BALL_SPEED 250.f
|
|
|
|
#define BALL_MAXSPEED 450.f
|
|
|
|
|
|
|
|
#define S_UNIQUE_CHANNEL 6
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
2012-11-28 15:47:07 +00:00
|
|
|
* BOEntity
|
2012-11-26 18:58:24 +00:00
|
|
|
****************************************************************************
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
BOEntity::BOEntity( idGameBustOutWindow* _game )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
game = _game;
|
|
|
|
visible = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
materialName = "";
|
|
|
|
material = NULL;
|
|
|
|
width = height = 8;
|
|
|
|
color = colorWhite;
|
|
|
|
powerup = POWERUP_NONE;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
position.Zero();
|
|
|
|
velocity.Zero();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
removed = false;
|
|
|
|
fadeOut = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
BOEntity::~BOEntity()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOEntity::WriteToSaveGame
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void BOEntity::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &visible, sizeof( visible ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
game->WriteSaveGameString( materialName, savefile );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
savefile->Write( &width, sizeof( width ) );
|
|
|
|
savefile->Write( &height, sizeof( height ) );
|
|
|
|
|
|
|
|
savefile->Write( &color, sizeof( color ) );
|
|
|
|
savefile->Write( &position, sizeof( position ) );
|
|
|
|
savefile->Write( &velocity, sizeof( velocity ) );
|
|
|
|
|
|
|
|
savefile->Write( &powerup, sizeof( powerup ) );
|
|
|
|
savefile->Write( &removed, sizeof( removed ) );
|
|
|
|
savefile->Write( &fadeOut, sizeof( fadeOut ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOEntity::ReadFromSaveGame
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void BOEntity::ReadFromSaveGame( idFile* savefile, idGameBustOutWindow* _game )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
game = _game;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
savefile->Read( &visible, sizeof( visible ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
game->ReadSaveGameString( materialName, savefile );
|
|
|
|
SetMaterial( materialName );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
savefile->Read( &width, sizeof( width ) );
|
|
|
|
savefile->Read( &height, sizeof( height ) );
|
|
|
|
|
|
|
|
savefile->Read( &color, sizeof( color ) );
|
|
|
|
savefile->Read( &position, sizeof( position ) );
|
|
|
|
savefile->Read( &velocity, sizeof( velocity ) );
|
|
|
|
|
|
|
|
savefile->Read( &powerup, sizeof( powerup ) );
|
|
|
|
savefile->Read( &removed, sizeof( removed ) );
|
|
|
|
savefile->Read( &fadeOut, sizeof( fadeOut ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOEntity::SetMaterial
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void BOEntity::SetMaterial( const char* name )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
materialName = name;
|
|
|
|
material = declManager->FindMaterial( name );
|
|
|
|
material->SetSort( SS_GUI );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOEntity::SetSize
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void BOEntity::SetSize( float _width, float _height )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
width = _width;
|
|
|
|
height = _height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOEntity::SetVisible
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void BOEntity::SetColor( float r, float g, float b, float a )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
color.x = r;
|
|
|
|
color.y = g;
|
|
|
|
color.z = b;
|
|
|
|
color.w = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOEntity::SetVisible
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void BOEntity::SetVisible( bool isVisible )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
visible = isVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOEntity::Update
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void BOEntity::Update( float timeslice, int guiTime )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !visible )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Move the entity
|
|
|
|
position += velocity * timeslice;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Fade out the ent
|
2012-11-28 15:47:07 +00:00
|
|
|
if( fadeOut )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
color.w -= timeslice * 2.5;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( color.w <= 0.f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
color.w = 0.f;
|
|
|
|
removed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOEntity::Draw
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void BOEntity::Draw()
|
|
|
|
{
|
|
|
|
if( visible )
|
|
|
|
{
|
|
|
|
dc->DrawMaterialRotated( position.x, position.y, width, height, material, color, 1.0f, 1.0f, DEG2RAD( 0.f ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
* BOBrick
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
BOBrick::BOBrick()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent = NULL;
|
|
|
|
x = y = width = height = 0;
|
|
|
|
powerup = POWERUP_NONE;
|
|
|
|
isBroken = false;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
BOBrick::BOBrick( BOEntity* _ent, float _x, float _y, float _width, float _height )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent = _ent;
|
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
width = _width;
|
|
|
|
height = _height;
|
|
|
|
powerup = POWERUP_NONE;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
isBroken = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ent->position.x = x;
|
|
|
|
ent->position.y = y;
|
|
|
|
ent->SetSize( width, height );
|
|
|
|
ent->SetMaterial( "game/bustout/brick" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ent->game->entities.Append( ent );
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
BOBrick::~BOBrick()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOBrick::WriteToSaveGame
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void BOBrick::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
savefile->Write( &x, sizeof( x ) );
|
|
|
|
savefile->Write( &y, sizeof( y ) );
|
|
|
|
savefile->Write( &width, sizeof( width ) );
|
|
|
|
savefile->Write( &height, sizeof( height ) );
|
|
|
|
|
|
|
|
savefile->Write( &powerup, sizeof( powerup ) );
|
|
|
|
savefile->Write( &isBroken, sizeof( isBroken ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int index = ent->game->entities.FindIndex( ent );
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &index, sizeof( index ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOBrick::ReadFromSaveGame
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void BOBrick::ReadFromSaveGame( idFile* savefile, idGameBustOutWindow* game )
|
|
|
|
{
|
|
|
|
savefile->Read( &x, sizeof( x ) );
|
|
|
|
savefile->Read( &y, sizeof( y ) );
|
|
|
|
savefile->Read( &width, sizeof( width ) );
|
|
|
|
savefile->Read( &height, sizeof( height ) );
|
|
|
|
|
|
|
|
savefile->Read( &powerup, sizeof( powerup ) );
|
|
|
|
savefile->Read( &isBroken, sizeof( isBroken ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int index;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &index, sizeof( index ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
ent = game->entities[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOBrick::SetColor
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void BOBrick::SetColor( idVec4 bcolor )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent->SetColor( bcolor.x, bcolor.y, bcolor.z, bcolor.w );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
BOBrick::checkCollision
|
|
|
|
======================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
collideDir_t BOBrick::checkCollision( idVec2 pos, idVec2 vel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec2 ptA, ptB;
|
|
|
|
float dist;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
collideDir_t result = COLLIDE_NONE;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( isBroken )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return result;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check for collision with each edge
|
|
|
|
idVec2 vec;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Bottom
|
|
|
|
ptA.x = x;
|
|
|
|
ptA.y = y + height;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ptB.x = x + width;
|
|
|
|
ptB.y = y + height;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( vel.y < 0 && pos.y > ptA.y )
|
|
|
|
{
|
|
|
|
if( pos.x > ptA.x && pos.x < ptB.x )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
dist = pos.y - ptA.y;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( dist < BALL_RADIUS )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
result = COLLIDE_DOWN;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( pos.x <= ptA.x )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
vec = pos - ptA;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
vec = pos - ptB;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( ( idMath::Fabs( vec.y ) > idMath::Fabs( vec.x ) ) && ( vec.LengthFast() < BALL_RADIUS ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
result = COLLIDE_DOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( result == COLLIDE_NONE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Top
|
|
|
|
ptA.y = y;
|
|
|
|
ptB.y = y;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( vel.y > 0 && pos.y < ptA.y )
|
|
|
|
{
|
|
|
|
if( pos.x > ptA.x && pos.x < ptB.x )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
dist = ptA.y - pos.y;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( dist < BALL_RADIUS )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
result = COLLIDE_UP;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( pos.x <= ptA.x )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
vec = pos - ptA;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
vec = pos - ptB;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( ( idMath::Fabs( vec.y ) > idMath::Fabs( vec.x ) ) && ( vec.LengthFast() < BALL_RADIUS ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
result = COLLIDE_UP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( result == COLLIDE_NONE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Left side
|
|
|
|
ptA.x = x;
|
|
|
|
ptA.y = y;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ptB.x = x;
|
|
|
|
ptB.y = y + height;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( vel.x > 0 && pos.x < ptA.x )
|
|
|
|
{
|
|
|
|
if( pos.y > ptA.y && pos.y < ptB.y )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
dist = ptA.x - pos.x;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( dist < BALL_RADIUS )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
result = COLLIDE_LEFT;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( pos.y <= ptA.y )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
vec = pos - ptA;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
vec = pos - ptB;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( ( idMath::Fabs( vec.x ) >= idMath::Fabs( vec.y ) ) && ( vec.LengthFast() < BALL_RADIUS ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
result = COLLIDE_LEFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( result == COLLIDE_NONE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Right side
|
|
|
|
ptA.x = x + width;
|
|
|
|
ptB.x = x + width;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( vel.x < 0 && pos.x > ptA.x )
|
|
|
|
{
|
|
|
|
if( pos.y > ptA.y && pos.y < ptB.y )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
dist = pos.x - ptA.x;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( dist < BALL_RADIUS )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
result = COLLIDE_LEFT;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( pos.y <= ptA.y )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
vec = pos - ptA;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
vec = pos - ptB;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( ( idMath::Fabs( vec.x ) >= idMath::Fabs( vec.y ) ) && ( vec.LengthFast() < BALL_RADIUS ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
result = COLLIDE_LEFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
* idGameBustOutWindow
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idGameBustOutWindow::idGameBustOutWindow( idUserInterfaceLocal* g ) : idWindow( g )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gui = g;
|
|
|
|
CommonInit();
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idGameBustOutWindow::~idGameBustOutWindow()
|
|
|
|
{
|
|
|
|
entities.DeleteContents( true );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
Mem_Free( levelBoardData );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::WriteToSaveGame
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idWindow::WriteToSaveGame( savefile );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gamerunning.WriteToSaveGame( savefile );
|
|
|
|
onFire.WriteToSaveGame( savefile );
|
|
|
|
onContinue.WriteToSaveGame( savefile );
|
|
|
|
onNewGame.WriteToSaveGame( savefile );
|
|
|
|
onNewLevel.WriteToSaveGame( savefile );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
savefile->Write( &timeSlice, sizeof( timeSlice ) );
|
|
|
|
savefile->Write( &gameOver, sizeof( gameOver ) );
|
|
|
|
savefile->Write( &numLevels, sizeof( numLevels ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Board Data is loaded when GUI is loaded, don't need to save
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
savefile->Write( &numBricks, sizeof( numBricks ) );
|
|
|
|
savefile->Write( ¤tLevel, sizeof( currentLevel ) );
|
|
|
|
|
|
|
|
savefile->Write( &updateScore, sizeof( updateScore ) );
|
|
|
|
savefile->Write( &gameScore, sizeof( gameScore ) );
|
|
|
|
savefile->Write( &nextBallScore, sizeof( nextBallScore ) );
|
|
|
|
|
|
|
|
savefile->Write( &bigPaddleTime, sizeof( bigPaddleTime ) );
|
|
|
|
savefile->Write( &paddleVelocity, sizeof( paddleVelocity ) );
|
|
|
|
|
|
|
|
savefile->Write( &ballSpeed, sizeof( ballSpeed ) );
|
|
|
|
savefile->Write( &ballsRemaining, sizeof( ballsRemaining ) );
|
|
|
|
savefile->Write( &ballsInPlay, sizeof( ballsInPlay ) );
|
|
|
|
savefile->Write( &ballHitCeiling, sizeof( ballHitCeiling ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Write Entities
|
|
|
|
int i;
|
|
|
|
int numberOfEnts = entities.Num();
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &numberOfEnts, sizeof( numberOfEnts ) );
|
|
|
|
for( i = 0; i < numberOfEnts; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
entities[i]->WriteToSaveGame( savefile );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Write Balls
|
|
|
|
numberOfEnts = balls.Num();
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &numberOfEnts, sizeof( numberOfEnts ) );
|
|
|
|
for( i = 0; i < numberOfEnts; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int ballIndex = entities.FindIndex( balls[i] );
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &ballIndex, sizeof( ballIndex ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Write Powerups
|
|
|
|
numberOfEnts = powerUps.Num();
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &numberOfEnts, sizeof( numberOfEnts ) );
|
|
|
|
for( i = 0; i < numberOfEnts; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int powerIndex = entities.FindIndex( powerUps[i] );
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &powerIndex, sizeof( powerIndex ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Write paddle
|
|
|
|
paddle->WriteToSaveGame( savefile );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Write Bricks
|
|
|
|
int row;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( row = 0; row < BOARD_ROWS; row++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
numberOfEnts = board[row].Num();
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &numberOfEnts, sizeof( numberOfEnts ) );
|
|
|
|
for( i = 0; i < numberOfEnts; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
board[row][i]->WriteToSaveGame( savefile );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::ReadFromSaveGame
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::ReadFromSaveGame( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idWindow::ReadFromSaveGame( savefile );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Clear out existing paddle and entities from GUI load
|
|
|
|
delete paddle;
|
|
|
|
entities.DeleteContents( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gamerunning.ReadFromSaveGame( savefile );
|
|
|
|
onFire.ReadFromSaveGame( savefile );
|
|
|
|
onContinue.ReadFromSaveGame( savefile );
|
|
|
|
onNewGame.ReadFromSaveGame( savefile );
|
|
|
|
onNewLevel.ReadFromSaveGame( savefile );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
savefile->Read( &timeSlice, sizeof( timeSlice ) );
|
|
|
|
savefile->Read( &gameOver, sizeof( gameOver ) );
|
|
|
|
savefile->Read( &numLevels, sizeof( numLevels ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Board Data is loaded when GUI is loaded, don't need to save
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
savefile->Read( &numBricks, sizeof( numBricks ) );
|
|
|
|
savefile->Read( ¤tLevel, sizeof( currentLevel ) );
|
|
|
|
|
|
|
|
savefile->Read( &updateScore, sizeof( updateScore ) );
|
|
|
|
savefile->Read( &gameScore, sizeof( gameScore ) );
|
|
|
|
savefile->Read( &nextBallScore, sizeof( nextBallScore ) );
|
|
|
|
|
|
|
|
savefile->Read( &bigPaddleTime, sizeof( bigPaddleTime ) );
|
|
|
|
savefile->Read( &paddleVelocity, sizeof( paddleVelocity ) );
|
|
|
|
|
|
|
|
savefile->Read( &ballSpeed, sizeof( ballSpeed ) );
|
|
|
|
savefile->Read( &ballsRemaining, sizeof( ballsRemaining ) );
|
|
|
|
savefile->Read( &ballsInPlay, sizeof( ballsInPlay ) );
|
|
|
|
savefile->Read( &ballHitCeiling, sizeof( ballHitCeiling ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
int numberOfEnts;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Read entities
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &numberOfEnts, sizeof( numberOfEnts ) );
|
|
|
|
for( i = 0; i < numberOfEnts; i++ )
|
|
|
|
{
|
|
|
|
BOEntity* ent;
|
|
|
|
|
|
|
|
ent = new( TAG_OLD_UI ) BOEntity( this );
|
2012-11-26 18:58:24 +00:00
|
|
|
ent->ReadFromSaveGame( savefile, this );
|
|
|
|
entities.Append( ent );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Read balls
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &numberOfEnts, sizeof( numberOfEnts ) );
|
|
|
|
for( i = 0; i < numberOfEnts; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int ballIndex;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &ballIndex, sizeof( ballIndex ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
balls.Append( entities[ballIndex] );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Read powerups
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &numberOfEnts, sizeof( numberOfEnts ) );
|
|
|
|
for( i = 0; i < numberOfEnts; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int powerIndex;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &powerIndex, sizeof( powerIndex ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
balls.Append( entities[powerIndex] );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Read paddle
|
2012-11-28 15:47:07 +00:00
|
|
|
paddle = new( TAG_OLD_UI ) BOBrick();
|
2012-11-26 18:58:24 +00:00
|
|
|
paddle->ReadFromSaveGame( savefile, this );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Read board
|
|
|
|
int row;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( row = 0; row < BOARD_ROWS; row++ )
|
|
|
|
{
|
|
|
|
savefile->Read( &numberOfEnts, sizeof( numberOfEnts ) );
|
|
|
|
for( i = 0; i < numberOfEnts; i++ )
|
|
|
|
{
|
|
|
|
BOBrick* brick = new( TAG_OLD_UI ) BOBrick();
|
2012-11-26 18:58:24 +00:00
|
|
|
brick->ReadFromSaveGame( savefile, this );
|
|
|
|
board[row].Append( brick );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::ResetGameState
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::ResetGameState()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gamerunning = false;
|
|
|
|
gameOver = false;
|
|
|
|
onFire = false;
|
|
|
|
onContinue = false;
|
|
|
|
onNewGame = false;
|
|
|
|
onNewLevel = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Game moves forward 16 milliseconds every frame
|
|
|
|
timeSlice = 0.016f;
|
|
|
|
ballsRemaining = 3;
|
|
|
|
ballSpeed = BALL_SPEED;
|
|
|
|
ballsInPlay = 0;
|
|
|
|
updateScore = false;
|
|
|
|
numBricks = 0;
|
|
|
|
currentLevel = 1;
|
|
|
|
gameScore = 0;
|
|
|
|
bigPaddleTime = 0;
|
|
|
|
nextBallScore = gameScore + 10000;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ClearBoard();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::CommonInit
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::CommonInit()
|
|
|
|
{
|
|
|
|
BOEntity* ent;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Precache images
|
|
|
|
declManager->FindMaterial( "game/bustout/ball" );
|
|
|
|
declManager->FindMaterial( "game/bustout/doublepaddle" );
|
|
|
|
declManager->FindMaterial( "game/bustout/powerup_bigpaddle" );
|
|
|
|
declManager->FindMaterial( "game/bustout/powerup_multiball" );
|
|
|
|
declManager->FindMaterial( "game/bustout/brick" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Precache sounds
|
|
|
|
declManager->FindSound( "arcade_ballbounce" );
|
|
|
|
declManager->FindSound( "arcade_brickhit" );
|
|
|
|
declManager->FindSound( "arcade_missedball" );
|
|
|
|
declManager->FindSound( "arcade_sadsound" );
|
|
|
|
declManager->FindSound( "arcade_extraball" );
|
|
|
|
declManager->FindSound( "arcade_powerup" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ResetGameState();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
numLevels = 0;
|
|
|
|
boardDataLoaded = false;
|
|
|
|
levelBoardData = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Create Paddle
|
2012-11-28 15:47:07 +00:00
|
|
|
ent = new( TAG_OLD_UI ) BOEntity( this );
|
|
|
|
paddle = new( TAG_OLD_UI ) BOBrick( ent, 260.f, 440.f, 96.f, 24.f );
|
2012-11-26 18:58:24 +00:00
|
|
|
paddle->ent->SetMaterial( "game/bustout/paddle" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::HandleEvent
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* idGameBustOutWindow::HandleEvent( const sysEvent_t* event, bool* updateVisuals )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int key = event->evValue;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// need to call this to allow proper focus and capturing on embedded children
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* ret = idWindow::HandleEvent( event, updateVisuals );
|
|
|
|
|
|
|
|
if( event->evType == SE_KEY )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !event->evValue2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( key == K_MOUSE1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Mouse was clicked
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ballsInPlay == 0 )
|
|
|
|
{
|
|
|
|
BOEntity* ball = CreateNewBall();
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->SetVisible( true );
|
|
|
|
ball->position.x = paddle->ent->position.x + 48.f;
|
|
|
|
ball->position.y = 430.f;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity.x = ballSpeed;
|
2012-11-28 15:47:07 +00:00
|
|
|
ball->velocity.y = -ballSpeed * 2.f;
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity.NormalizeFast();
|
|
|
|
ball->velocity *= ballSpeed;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::ParseInternalVar
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idGameBustOutWindow::ParseInternalVar( const char* _name, idTokenParser* src )
|
|
|
|
{
|
|
|
|
if( idStr::Icmp( _name, "gamerunning" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gamerunning = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "onFire" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
onFire = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "onContinue" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
onContinue = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "onNewGame" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
onNewGame = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "onNewLevel" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
onNewLevel = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "numLevels" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
numLevels = src->ParseInt();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Load all the level images
|
|
|
|
LoadBoardFiles();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
return idWindow::ParseInternalVar( _name, src );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::GetWinVarByName
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idWinVar* idGameBustOutWindow::GetWinVarByName( const char* _name, bool winLookup, drawWin_t** owner )
|
|
|
|
{
|
|
|
|
idWinVar* retVar = NULL;
|
|
|
|
|
|
|
|
if( idStr::Icmp( _name, "gamerunning" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
retVar = &gamerunning;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( idStr::Icmp( _name, "onFire" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
retVar = &onFire;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( idStr::Icmp( _name, "onContinue" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
retVar = &onContinue;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( idStr::Icmp( _name, "onNewGame" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
retVar = &onNewGame;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( idStr::Icmp( _name, "onNewLevel" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
retVar = &onNewLevel;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( retVar )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return retVar;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
return idWindow::GetWinVarByName( _name, winLookup, owner );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::PostParse
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::PostParse()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idWindow::PostParse();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::Draw
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::Draw( int time, float x, float y )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Update the game every frame before drawing
|
|
|
|
UpdateGame();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = entities.Num() - 1; i >= 0; i-- )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
entities[i]->Draw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::Activate
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* idGameBustOutWindow::Activate( bool activate )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::UpdateScore
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::UpdateScore()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameOver )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gui->HandleNamedEvent( "GameOver" );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check for level progression
|
2012-11-28 15:47:07 +00:00
|
|
|
if( numBricks == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ClearBalls();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gui->HandleNamedEvent( "levelComplete" );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check for new ball score
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameScore >= nextBallScore )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ballsRemaining++;
|
|
|
|
gui->HandleNamedEvent( "extraBall" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Play sound
|
|
|
|
common->SW()->PlayShaderDirectly( "arcade_extraball", S_UNIQUE_CHANNEL );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
nextBallScore = gameScore + 10000;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
gui->SetStateString( "player_score", va( "%i", gameScore ) );
|
|
|
|
gui->SetStateString( "balls_remaining", va( "%i", ballsRemaining ) );
|
|
|
|
gui->SetStateString( "current_level", va( "%i", currentLevel ) );
|
|
|
|
gui->SetStateString( "next_ball_score", va( "%i", nextBallScore ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::ClearBoard
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::ClearBoard()
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ClearPowerups();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ballHitCeiling = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < BOARD_ROWS; i++ )
|
|
|
|
{
|
|
|
|
for( j = 0; j < board[i].Num(); j++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
BOBrick* brick = board[i][j];
|
2012-11-26 18:58:24 +00:00
|
|
|
brick->ent->removed = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
board[i].DeleteContents( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::ClearPowerups
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::ClearPowerups()
|
|
|
|
{
|
|
|
|
while( powerUps.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
powerUps[0]->removed = true;
|
|
|
|
powerUps.RemoveIndex( 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::ClearBalls
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::ClearBalls()
|
|
|
|
{
|
|
|
|
while( balls.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
balls[0]->removed = true;
|
|
|
|
balls.RemoveIndex( 0 );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ballsInPlay = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::LoadBoardFiles
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::LoadBoardFiles()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
int w, h;
|
2012-11-26 18:58:24 +00:00
|
|
|
ID_TIME_T time;
|
|
|
|
int boardSize;
|
2012-11-28 15:47:07 +00:00
|
|
|
byte* currentBoard;
|
|
|
|
|
|
|
|
if( boardDataLoaded )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
boardSize = 9 * 12 * 4;
|
2012-11-28 15:47:07 +00:00
|
|
|
levelBoardData = ( byte* )Mem_Alloc( boardSize * numLevels, TAG_CRAP );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
currentBoard = levelBoardData;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < numLevels; i++ )
|
|
|
|
{
|
|
|
|
byte* pic;
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr name = "guis/assets/bustout/level";
|
2012-11-28 15:47:07 +00:00
|
|
|
name += ( i + 1 );
|
2012-11-26 18:58:24 +00:00
|
|
|
name += ".tga";
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
R_LoadImage( name, &pic, &w, &h, &time, false );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( pic != NULL )
|
|
|
|
{
|
|
|
|
if( w != 9 || h != 12 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->DWarning( "Hell Bust-Out level image not correct dimensions! (%d x %d)", w, h );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
memcpy( currentBoard, pic, boardSize );
|
2012-11-28 15:47:07 +00:00
|
|
|
Mem_Free( pic );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
currentBoard += boardSize;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
boardDataLoaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::SetCurrentBoard
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::SetCurrentBoard()
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int realLevel = ( ( currentLevel - 1 ) % numLevels );
|
2012-11-26 18:58:24 +00:00
|
|
|
int boardSize;
|
2012-11-28 15:47:07 +00:00
|
|
|
byte* currentBoard;
|
2012-11-26 18:58:24 +00:00
|
|
|
float bx = 11.f;
|
|
|
|
float by = 24.f;
|
|
|
|
float stepx = 619.f / 9.f;
|
|
|
|
float stepy = ( 256 / 12.f );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
boardSize = 9 * 12 * 4;
|
|
|
|
currentBoard = levelBoardData + ( realLevel * boardSize );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( j = 0; j < BOARD_ROWS; j++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bx = 11.f;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < 9; i++ )
|
|
|
|
{
|
|
|
|
int pixelindex = ( j * 9 * 4 ) + ( i * 4 );
|
|
|
|
|
|
|
|
if( currentBoard[pixelindex + 3] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec4 bcolor;
|
|
|
|
float pType = 0.f;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
BOEntity* bent = new( TAG_OLD_UI ) BOEntity( this );
|
|
|
|
BOBrick* brick = new( TAG_OLD_UI ) BOBrick( bent, bx, by, stepx, stepy );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
bcolor.x = currentBoard[pixelindex + 0] / 255.f;
|
|
|
|
bcolor.y = currentBoard[pixelindex + 1] / 255.f;
|
|
|
|
bcolor.z = currentBoard[pixelindex + 2] / 255.f;
|
|
|
|
bcolor.w = 1.f;
|
|
|
|
brick->SetColor( bcolor );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
pType = currentBoard[pixelindex + 3] / 255.f;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( pType > 0.f && pType < 1.f )
|
|
|
|
{
|
|
|
|
if( pType < 0.5f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
brick->powerup = POWERUP_BIGPADDLE;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
brick->powerup = POWERUP_MULTIBALL;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
board[j].Append( brick );
|
|
|
|
numBricks++;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
bx += stepx;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
by += stepy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::CreateNewBall
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
BOEntity* idGameBustOutWindow::CreateNewBall()
|
|
|
|
{
|
|
|
|
BOEntity* ball;
|
|
|
|
|
|
|
|
ball = new( TAG_OLD_UI ) BOEntity( this );
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->position.x = 300.f;
|
|
|
|
ball->position.y = 416.f;
|
|
|
|
ball->SetMaterial( "game/bustout/ball" );
|
2012-11-28 15:47:07 +00:00
|
|
|
ball->SetSize( BALL_RADIUS * 2.f, BALL_RADIUS * 2.f );
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->SetVisible( false );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ballsInPlay++;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
balls.Append( ball );
|
|
|
|
entities.Append( ball );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return ball;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::CreatePowerup
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
BOEntity* idGameBustOutWindow::CreatePowerup( BOBrick* brick )
|
|
|
|
{
|
|
|
|
BOEntity* powerEnt = new( TAG_OLD_UI ) BOEntity( this );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
powerEnt->position.x = brick->x;
|
|
|
|
powerEnt->position.y = brick->y;
|
|
|
|
powerEnt->velocity.x = 0.f;
|
|
|
|
powerEnt->velocity.y = 64.f;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
powerEnt->powerup = brick->powerup;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
switch( powerEnt->powerup )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
case POWERUP_BIGPADDLE:
|
|
|
|
powerEnt->SetMaterial( "game/bustout/powerup_bigpaddle" );
|
|
|
|
break;
|
|
|
|
case POWERUP_MULTIBALL:
|
|
|
|
powerEnt->SetMaterial( "game/bustout/powerup_multiball" );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
powerEnt->SetMaterial( "textures/common/nodraw" );
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
powerEnt->SetSize( 619 / 9, 256 / 12 );
|
2012-11-26 18:58:24 +00:00
|
|
|
powerEnt->SetVisible( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
powerUps.Append( powerEnt );
|
|
|
|
entities.Append( powerEnt );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return powerEnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::UpdatePowerups
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::UpdatePowerups()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec2 pos;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < powerUps.Num(); i++ )
|
|
|
|
{
|
|
|
|
BOEntity* pUp = powerUps[i];
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check for powerup falling below screen
|
2012-11-28 15:47:07 +00:00
|
|
|
if( pUp->position.y > 480 )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
powerUps.RemoveIndex( i );
|
|
|
|
pUp->removed = true;
|
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check for the paddle catching a powerup
|
|
|
|
pos.x = pUp->position.x + ( pUp->width / 2 );
|
|
|
|
pos.y = pUp->position.y + ( pUp->height / 2 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
collideDir_t collision = paddle->checkCollision( pos, pUp->velocity );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( collision != COLLIDE_NONE )
|
|
|
|
{
|
|
|
|
BOEntity* ball;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Give the powerup to the player
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( pUp->powerup )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
case POWERUP_BIGPADDLE:
|
|
|
|
bigPaddleTime = gui->GetTime() + 15000;
|
|
|
|
break;
|
|
|
|
case POWERUP_MULTIBALL:
|
|
|
|
// Create 2 new balls in the spot of the existing ball
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int b = 0; b < 2; b++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ball = CreateNewBall();
|
|
|
|
ball->position = balls[0]->position;
|
|
|
|
ball->velocity = balls[0]->velocity;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( b == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity.x -= 35.f;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity.x += 35.f;
|
|
|
|
}
|
|
|
|
ball->velocity.NormalizeFast();
|
|
|
|
ball->velocity *= ballSpeed;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->SetVisible( true );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Play the sound
|
|
|
|
common->SW()->PlayShaderDirectly( "arcade_powerup", S_UNIQUE_CHANNEL );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Remove it
|
|
|
|
powerUps.RemoveIndex( i );
|
|
|
|
pUp->removed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::UpdatePaddle
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::UpdatePaddle()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec2 cursorPos;
|
|
|
|
float oldPos = paddle->x;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
cursorPos.x = gui->CursorX();
|
|
|
|
cursorPos.y = gui->CursorY();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( bigPaddleTime > gui->GetTime() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
paddle->x = cursorPos.x - 80.f;
|
|
|
|
paddle->width = 160;
|
|
|
|
paddle->ent->width = 160;
|
|
|
|
paddle->ent->SetMaterial( "game/bustout/doublepaddle" );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
paddle->x = cursorPos.x - 48.f;
|
|
|
|
paddle->width = 96;
|
|
|
|
paddle->ent->width = 96;
|
|
|
|
paddle->ent->SetMaterial( "game/bustout/paddle" );
|
|
|
|
}
|
|
|
|
paddle->ent->position.x = paddle->x;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
paddleVelocity = ( paddle->x - oldPos );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::UpdateBall
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::UpdateBall()
|
|
|
|
{
|
|
|
|
int ballnum, i, j;
|
2012-11-26 18:58:24 +00:00
|
|
|
bool playSoundBounce = false;
|
|
|
|
bool playSoundBrick = false;
|
|
|
|
static int bounceChannel = 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( ballsInPlay == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( ballnum = 0; ballnum < balls.Num(); ballnum++ )
|
|
|
|
{
|
|
|
|
BOEntity* ball = balls[ballnum];
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check for ball going below screen, lost ball
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ball->position.y > 480.f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->removed = true;
|
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check world collision
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ball->position.y < 20 && ball->velocity.y < 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity.y = -ball->velocity.y;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Increase ball speed when it hits ceiling
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !ballHitCeiling )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ballSpeed *= 1.25f;
|
|
|
|
ballHitCeiling = true;
|
|
|
|
}
|
|
|
|
playSoundBounce = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( ball->position.x > 608 && ball->velocity.x > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity.x = -ball->velocity.x;
|
|
|
|
playSoundBounce = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( ball->position.x < 8 && ball->velocity.x < 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity.x = -ball->velocity.x;
|
|
|
|
playSoundBounce = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check for Paddle collision
|
|
|
|
idVec2 ballCenter = ball->position + idVec2( BALL_RADIUS, BALL_RADIUS );
|
|
|
|
collideDir_t collision = paddle->checkCollision( ballCenter, ball->velocity );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( collision == COLLIDE_UP )
|
|
|
|
{
|
|
|
|
if( ball->velocity.y > 0 )
|
|
|
|
{
|
|
|
|
idVec2 paddleVec( paddleVelocity * 2, 0 );
|
2012-11-26 18:58:24 +00:00
|
|
|
float centerX;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( bigPaddleTime > gui->GetTime() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
centerX = paddle->x + 80.f;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
centerX = paddle->x + 48.f;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity.y = -ball->velocity.y;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
paddleVec.x += ( ball->position.x - centerX ) * 2;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity += paddleVec;
|
|
|
|
ball->velocity.NormalizeFast();
|
|
|
|
ball->velocity *= ballSpeed;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
playSoundBounce = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( collision == COLLIDE_LEFT || collision == COLLIDE_RIGHT )
|
|
|
|
{
|
|
|
|
if( ball->velocity.y > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity.x = -ball->velocity.x;
|
|
|
|
playSoundBounce = true;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
collision = COLLIDE_NONE;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check for collision with bricks
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < BOARD_ROWS; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int num = board[i].Num();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( j = 0; j < num; j++ )
|
|
|
|
{
|
|
|
|
BOBrick* brick = ( board[i] )[j];
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
collision = brick->checkCollision( ballCenter, ball->velocity );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( collision )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Now break the brick if there was a collision
|
|
|
|
brick->isBroken = true;
|
|
|
|
brick->ent->fadeOut = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( brick->powerup > POWERUP_NONE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
verify( CreatePowerup( brick ) != NULL );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
numBricks--;
|
|
|
|
gameScore += 100;
|
|
|
|
updateScore = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Go ahead an forcibly remove the last brick, no fade
|
2012-11-28 15:47:07 +00:00
|
|
|
if( numBricks == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
brick->ent->removed = true;
|
|
|
|
}
|
|
|
|
board[i].Remove( brick );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( collision )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
playSoundBrick = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( collision == COLLIDE_DOWN || collision == COLLIDE_UP )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity.y *= -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( collision == COLLIDE_LEFT || collision == COLLIDE_RIGHT )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ball->velocity.x *= -1;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( playSoundBounce )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->SW()->PlayShaderDirectly( "arcade_ballbounce", bounceChannel );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( playSoundBrick )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->SW()->PlayShaderDirectly( "arcade_brickhit", bounceChannel );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( playSoundBounce || playSoundBrick )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bounceChannel++;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( bounceChannel == 4 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bounceChannel = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check to see if any balls were removed from play
|
2012-11-28 15:47:07 +00:00
|
|
|
for( ballnum = 0; ballnum < balls.Num(); ballnum++ )
|
|
|
|
{
|
|
|
|
if( balls[ballnum]->removed )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ballsInPlay--;
|
|
|
|
balls.RemoveIndex( ballnum );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// If all the balls were removed, update the game accordingly
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ballsInPlay == 0 )
|
|
|
|
{
|
|
|
|
if( ballsRemaining == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameOver = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Game Over sound
|
|
|
|
common->SW()->PlayShaderDirectly( "arcade_sadsound", S_UNIQUE_CHANNEL );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ballsRemaining--;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Ball was lost, but game is not over
|
|
|
|
common->SW()->PlayShaderDirectly( "arcade_missedball", S_UNIQUE_CHANNEL );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ClearPowerups();
|
|
|
|
updateScore = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================
|
|
|
|
idGameBustOutWindow::UpdateGame
|
|
|
|
=============================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameBustOutWindow::UpdateGame()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( onNewGame )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ResetGameState();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Create Board
|
|
|
|
SetCurrentBoard();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gamerunning = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( onContinue )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameOver = false;
|
|
|
|
ballsRemaining = 3;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
onContinue = false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( onNewLevel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
currentLevel++;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ClearBoard();
|
|
|
|
SetCurrentBoard();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
ballSpeed = BALL_SPEED * ( 1.f + ( ( float )currentLevel / 5.f ) );
|
|
|
|
if( ballSpeed > BALL_MAXSPEED )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ballSpeed = BALL_MAXSPEED;
|
|
|
|
}
|
|
|
|
updateScore = true;
|
|
|
|
onNewLevel = false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gamerunning == true )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdatePaddle();
|
|
|
|
UpdateBall();
|
|
|
|
UpdatePowerups();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < entities.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
entities[i]->Update( timeSlice, gui->GetTime() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Delete entities that need to be deleted
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = entities.Num() - 1; i >= 0; i-- )
|
|
|
|
{
|
|
|
|
if( entities[i]->removed )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
BOEntity* ent = entities[i];
|
|
|
|
delete ent;
|
2012-11-28 15:47:07 +00:00
|
|
|
entities.RemoveIndex( i );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( updateScore )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdateScore();
|
|
|
|
updateScore = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|