summaryrefslogtreecommitdiff
path: root/noncore/games/bounce/game.cpp
Side-by-side diff
Diffstat (limited to 'noncore/games/bounce/game.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/bounce/game.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/noncore/games/bounce/game.cpp b/noncore/games/bounce/game.cpp
index 1f1f8cd..bbd3d0b 100644
--- a/noncore/games/bounce/game.cpp
+++ b/noncore/games/bounce/game.cpp
@@ -1,72 +1,79 @@
/*
* Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <stdlib.h>
-#include <qtimer.h>
+#include "game.h"
+
+/* OPIE */
+#include <opie2/odebug.h>
#include <qpe/qpeapplication.h>
+using namespace Opie::Core;
-#include "game.h"
+/* QT */
+#include <qtimer.h>
+
+/* STD */
+#include <stdlib.h>
#define TILE_SIZE 9
#define TILE_FIRST ((FIELD_WIDTH-2)*(FIELD_HEIGHT-2))
#define TILE_FREE (TILE_FIRST + 0)
#define TILE_BORDER (TILE_FIRST + 1)
#define TILE_WALLEND (TILE_FIRST + 2)
#define TILE_WALLUP (TILE_FIRST + 3)
#define TILE_WALLDOWN (TILE_FIRST + 4)
#define TILE_WALLLEFT (TILE_FIRST + 5)
#define TILE_WALLRIGHT (TILE_FIRST + 6)
#define GAME_DELAY 15
#define BALL_ANIM_DELAY 60
#define WALL_DELAY 100
#define MS2TICKS( ms ) ((ms)/GAME_DELAY)
Arrow::Arrow(QCanvasPixmapArray* array, QCanvas* canvas)
: QCanvasSprite( array, canvas )
{
m_vertical = true;
move(3,3);
}
void Arrow::update()
{
if ( m_vertical )
setFrame( 0 );
else
setFrame( 1 );
}
void Arrow::changeDirection()
{
m_vertical = ! m_vertical;
update();
}
Ball::Ball(QCanvasPixmapArray* array, QCanvas* canvas)
: QCanvasSprite( array, canvas ), m_animDelay( 0 ), m_soundDelay( MS2TICKS(BALL_ANIM_DELAY)/2 )
{
}
void Ball::update()
{
m_animDelay--;
@@ -322,97 +329,97 @@ JezzGame::JezzGame( int ballNum, QWidget *parent, const char *name )
m_field->setTile( x, FIELD_HEIGHT-1, TILE_BORDER );
connect( m_field, SIGNAL(ballCollision(Ball*,int,int,int)), this, SLOT(ballCollision(Ball*,int,int,int)) );
// create view
m_view = new JezzView( m_field, this, "m_view" );
m_view->move( 0, 0 );
m_view->adjustSize();
connect( m_view, SIGNAL(buildWall(int,int,bool)), this, SLOT(buildWall(int,int,bool)) );
// create balls
for ( int n=0; n<ballNum; n++ )
{
Ball *ball = new Ball( m_ballPixmaps, m_field );
m_balls.append( ball );
ball->setVelocity( ((rand() & 1)*2-1)*2, ((rand() & 1)*2-1)*2 );
ball->setFrame( rand() % 25 );
ball->move( 4*TILE_SIZE + ( rand() - 50 ) % ( (FIELD_WIDTH-8)*TILE_SIZE ),
4*TILE_SIZE + rand() % ( (FIELD_HEIGHT-8)*TILE_SIZE ) );
ball->show();
}
// create arrow
arrow = new Arrow( m_arrowPixmaps, m_field );
arrow->show();
// create text label
m_text = new QCanvasText( m_field );
// create game clock
m_clock = new QTimer( this );
connect( m_clock, SIGNAL(timeout()), this, SLOT(tick()) );
m_clock->start( GAME_DELAY );
// setup geometry
setFixedSize( m_view->size() );
}
JezzGame::~JezzGame()
{
m_balls.clear();
delete m_view;
delete m_field;
delete m_ballPixmaps;
}
void JezzGame::display( QString text, int size )
{
- qDebug("This function \"display\" shouldn't be called!!!");
+ odebug << "This function \"display\" shouldn't be called!!!" << oendl;
if ( !text.isEmpty() )
{
QFont font( "Helvetica", size, QFont::Bold );
font.setStyleHint( QFont::Helvetica );
m_text->setFont( font );
m_text->setText( text );
QRect size = m_text->boundingRect();
m_text->move( ( FIELD_WIDTH*TILE_SIZE - size.width() ) / 2,
( FIELD_HEIGHT*TILE_SIZE - size.height() ) / 2 );
m_text->show();
} else
{
m_text->hide();
}
}
void JezzGame::start()
{
m_running = true;
}
void JezzGame::stop()
{
m_running = false;
}
void JezzGame::makeBlack()
{
// copy current field into buffer
for ( int y=0; y<FIELD_HEIGHT; y++ )
for ( int x=0; x<FIELD_WIDTH; x++ )
m_buf[x][y] = m_field->tile( x, y );
// fill areas that contains a ball
for ( Ball *ball=m_balls.first(); ball!=0; ball=m_balls.next() )
fill( ball->x()/TILE_SIZE, ball->y()/TILE_SIZE );
// areas still free can be blacked now
for ( int y=0; y<FIELD_HEIGHT; y++ )
for ( int x=0; x<FIELD_WIDTH; x++ )
{
if ( m_buf[x][y]==TILE_FREE )
m_field->setGameTile( x, y, true );
}