[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-games-devel
Subject:    [Kde-games-devel] Some more eyecandy for kbounce
From:       Andreas Scherf <ascherfy () googlemail ! com>
Date:       2010-05-04 22:36:30
Message-ID: 201005050036.30882.ascherfy () googlemail ! com
[Download RAW message or body]

Hello,
i added some eyecand, fixed the suspend state and added a second before 
starting the game while shwing a "go". The last think prevents the user from a 
click inside a new ball after starting the game. I added this and some fading 
annimations via qanimation framework to raise the quality a bit. What do you 
think? Should it go into 4.5 or should i wait?

Andreas

["kbounce_eyecandy.diff" (text/x-patch)]

Index: gamewidget.cpp
===================================================================
--- gamewidget.cpp	(Revision 1122882)
+++ gamewidget.cpp	(Arbeitskopie)
@@ -18,6 +18,7 @@
 
 #include "gamewidget.h"
 #include "settings.h"
+#include "overlay.h"
 
 #include <QPalette>
 #include <QTimer>
@@ -30,6 +31,7 @@
 static const int MIN_FILL_PERCENT = 75;
 static const int POINTS_FOR_LIFE = 15;
 static const int TICKS_PER_SECOND = 1000 / GAME_TIME_DELAY;
+static const int GAME_START_DELAY = 1;
 
 KBounceGameWidget::KBounceGameWidget( QWidget* parent )
     : KGameCanvasWidget( parent ), m_state( BeforeFirstGame ),
@@ -42,7 +44,7 @@
     connect( m_board, SIGNAL( fillChanged( int ) ), this, SLOT( onFillChanged( int ) \
) );  connect( m_board, SIGNAL( wallDied() ), this, SLOT( onWallDied() ) );
 
-    m_overlay = new KGameCanvasPixmap( this );
+	m_overlay = new KBounceOverlay( this );
     m_overlay->raise();
     m_overlay->hide();
 
@@ -81,12 +83,12 @@
 {
     if ( m_state != BeforeFirstGame && m_state != GameOver )
     {
+		m_board->playSound("timeout.wav");
         closeLevel();
         unsetCursor();
         m_state = GameOver;
         emit stateChanged( m_state );
         emit gameOver();
-
         redraw();
     }
 }
@@ -248,6 +250,13 @@
             closeGame();
         else
         {
+			// Let the user some time to die ...
+			if ( m_state == GameStarting && m_time == getLevelTotalTime() - GAME_START_DELAY \
) +			{
+				m_state = Running;
+				emit stateChanged( m_state );
+				redraw();
+			}
             m_time--;
             emit timeChanged( m_time );
         }
@@ -320,7 +329,7 @@
 
 void KBounceGameWidget::newLevel()
 {
-    m_state = Running;
+    m_state = GameStarting;
     emit stateChanged( m_state );
 
     m_clock->start();
@@ -329,7 +338,7 @@
 
     m_bonus = 0;
     m_lives = m_level + 1;
-    m_time = 30 * ( m_level + 2 );
+    m_time = getLevelTotalTime();
     emit livesChanged( m_lives );
     emit timeChanged( m_time );
 
@@ -341,6 +350,10 @@
     redraw();
 }  
 
+int KBounceGameWidget::getLevelTotalTime() const
+{
+	return (30 * ( m_level + 2 )) + GAME_START_DELAY;
+}
 
 void KBounceGameWidget::redraw()
 {
@@ -353,29 +366,52 @@
 	    m_board->hide();
 	    generateOverlay();
 	    m_overlay->show();
+		m_overlay->fadeIn();
 	    break;
+	case GameStarting:
+		m_board->show();
+		generateOverlay();
+		m_overlay->fadeOut();
+	    break;
 	case Running:
-	    m_board->show();
 	    m_overlay->hide();
 	    break;
 	default:
 	    m_board->show();
 	    generateOverlay();
+		if (!m_overlay->isVisible())
+		{
 	    m_overlay->show();
+			m_overlay->fadeIn();
+		}	
+		
 	    break;
     }
     m_board->redraw();
     update();
 }
 
+
 void KBounceGameWidget::generateOverlay()
 {
 	if ( size().isEmpty() )
 		return;
 	
-    int itemWidth = qRound( 0.8 * size().width() );
-    int itemHeight = qRound( 0.6 * size().height() );
+	QSizeF scaledSize = QSizeF();
+	if ( m_state == GameStarting )
+	{
+		scaledSize.setWidth( 0.4 );
+		scaledSize.setHeight( 0.3 );
+	}
+	else
+	{
+		scaledSize.setWidth( 0.8 );
+		scaledSize.setHeight( 0.6 );
+	}
 
+	int itemWidth = qRound( scaledSize.width() * size().width() );
+    int itemHeight = qRound( scaledSize.height() * size().height() );
+
 	QSize backgroundSize( itemWidth,itemHeight );
 
 	QPixmap px( backgroundSize );
@@ -409,6 +445,9 @@
 	case Paused:
 	    text = i18n( "Paused" );
 	    break;
+	case GameStarting:
+		text = i18n("Go.", m_lives);
+		break;
 	case BetweenLevels:
 	    text = i18n( "You have successfully cleared more than %1% of the board\n", \
MIN_FILL_PERCENT ) +  i18n( "%1 points: %2 points per remaining life\n", m_lives * \
POINTS_FOR_LIFE, POINTS_FOR_LIFE ) + @@ -416,11 +455,14 @@
 		i18n( "%1 points: Total score for this level\n", m_bonus + m_lives * \
POINTS_FOR_LIFE ) +  i18n( "On to level %1. Remember you get %2 lives this time!", \
m_level, m_level + 1 );  break;
+	case Suspended:
+		text = i18n("Game suspended");
+		break;
 	case GameOver:
 	    text = i18n( "Game over.\n Click to start a game" );
 	    break;
-	default:
-	    text = QString();
+	case Running:
+		break;
     }
 
     QFont font;
Index: mainwindow.h
===================================================================
--- mainwindow.h	(Revision 1122882)
+++ mainwindow.h	(Arbeitskopie)
@@ -63,7 +63,7 @@
 
    KStatusBar* m_statusBar;
 
-   KToggleAction *m_pauseAction, *m_backgroundShowAction, *m_soundAction;
+   KToggleAction *m_pauseAction, *m_soundAction;
    KAction *m_newAction;
 };
 
Index: overlay.cpp
===================================================================
--- overlay.cpp	(Revision 0)
+++ overlay.cpp	(Revision 0)
@@ -0,0 +1,102 @@
+/*
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program 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 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#include "overlay.h"
+#include <KColorScheme>
+#include <KLocale>
+#include <QPropertyAnimation>
+
+
+KBounceOverlay::KBounceOverlay(KGameCanvasAbstract* parent)
+: KGameCanvasGroup(parent)
+{
+	m_pOverlayPixmap = new KGameCanvasPixmap(this);
+	m_pOverlayPixmap->putInCanvas(this);
+	m_pOverlayPixmap->show();
+	m_bFadeOut=false;
+	m_bVisible=false;
+}
+
+void KBounceOverlay::setPixmap ( const QPixmap& pixmap )
+{
+	m_pOverlayPixmap->setPixmap(pixmap);
+	m_pOverlayPixmap->raise();
+}
+
+void KBounceOverlay::fadeOut()
+{
+	m_bFadeOut=true;
+	QPropertyAnimation* hideAnimation = new QPropertyAnimation(this,"opacity" );
+	hideAnimation->setDuration(1500);
+	hideAnimation->setStartValue(255);
+	hideAnimation->setEndValue(0);
+	hideAnimation->start();
+	connect(hideAnimation,SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimati \
on::State)),SLOT(animationStateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
 +}
+
+void KBounceOverlay::fadeIn()
+{
+	QPropertyAnimation* showAnimation = new QPropertyAnimation(this,"opacity" );
+	showAnimation->setDuration(2000);
+	showAnimation->setStartValue(0);
+	showAnimation->setEndValue(255);
+	showAnimation->start();
+	connect(showAnimation,SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimati \
on::State)),SLOT(animationStateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
 +}
+
+
+void KBounceOverlay::setOverlayOpacity ( int value )
+{
+	m_pOverlayPixmap->setOpacity(value);
+}
+
+void KBounceOverlay::animationStateChanged ( QAbstractAnimation::State newState , \
QAbstractAnimation::State oldState) +{
+	Q_UNUSED(oldState);
+	m_animationState=newState;
+	if (newState==QAbstractAnimation::Stopped && m_bFadeOut)
+	{
+		m_bFadeOut=false;
+		m_bVisible=false;
+	}
+	else
+	{
+		m_bVisible=true;
+	}
+}
+
+void KBounceOverlay::show()
+{
+	KGameCanvasGroup::show();
+	m_bVisible=true;
+}
+
+void KBounceOverlay::hide()
+{
+	KGameCanvasGroup::hide();
+	m_bVisible=false;
+}
+
+
+
+
+
+
+
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(Revision 1122882)
+++ CMakeLists.txt	(Arbeitskopie)
@@ -22,7 +22,8 @@
     renderer.cpp
 	sound.cpp
     wall.cpp 
-    backgroundselector.cpp)
+    backgroundselector.cpp
+	overlay.cpp)
 
 kde4_add_kcfg_files(kbounce_SRCS settings.kcfgc)
 kde4_add_ui_files(kbounce_SRCS  backgroundselector.ui )
Index: sound.h
===================================================================
--- sound.h	(Revision 1122882)
+++ sound.h	(Arbeitskopie)
@@ -42,9 +42,8 @@
 private:
 	void playSoundInternal(const QString& sound);
 	QHash<QString,Phonon::MediaObject*> m_hMedia;
-
-	bool m_playSounds;
 	QObject *m_parent;
+	bool m_playSounds;
 };
 
 #endif // KBOUNCESOUND_H
Index: mainwindow.cpp
===================================================================
--- mainwindow.cpp	(Revision 1122882)
+++ mainwindow.cpp	(Arbeitskopie)
@@ -70,6 +70,8 @@
 
 KBounceMainWindow::~KBounceMainWindow()
 {
+	delete m_gameWidget;
+	m_gameWidget = 0L;
 }
 
 /**
@@ -81,6 +83,9 @@
     m_newAction = KStandardGameAction::gameNew(this, SLOT(newGame()), \
                actionCollection());
     KStandardGameAction::end(this, SLOT(closeGame()), actionCollection());
     m_pauseAction = KStandardGameAction::pause(this, SLOT(pauseGame()), \
actionCollection()); +	m_pauseAction->setShortcut(Qt::Key_Space);
+	m_pauseAction->setEnabled( false );
+	
     KStandardGameAction::highscores(this, SLOT(showHighscore()), \
actionCollection());  KStandardGameAction::quit(this, SLOT(close()), \
actionCollection());  
@@ -123,12 +128,13 @@
 
 void KBounceMainWindow::closeGame()
 {
-	if ( m_gameWidget->state() == KBounceGameWidget::BeforeFirstGame || \
m_gameWidget->state() == KBounceGameWidget::GameOver ) +	KBounceGameWidget::State \
old_state = m_gameWidget->state(); +
+	if ( old_state == KBounceGameWidget::BeforeFirstGame || old_state == \
KBounceGameWidget::GameOver || old_state == KBounceGameWidget::BeforeFirstGame )  {
 		return;
 	}
 
-	KBounceGameWidget::State old_state = m_gameWidget->state();
 	if ( old_state == KBounceGameWidget::Running )
 		m_gameWidget->setPaused( true );
 	int ret = KMessageBox::questionYesNo( this, i18n( "Do you really want to close the \
running game?" ), QString(),  KStandardGuiItem::close(), KStandardGuiItem::cancel() \
); @@ -235,21 +241,27 @@
     switch ( state )
     {
 		case KBounceGameWidget::BeforeFirstGame :
+			m_pauseAction->setEnabled(false);
 			break;
+		case KBounceGameWidget::GameStarting:
+			KGameDifficulty::setEnabled( false );
+			m_statusBar->clearMessage();
+			break;
 		case KBounceGameWidget::BetweenLevels :
 			break;
 		case KBounceGameWidget::Suspended :
 			break;
 		case KBounceGameWidget::Paused :
+			m_pauseAction->setEnabled( true );
 		    m_pauseAction->setChecked( true );
 		    m_statusBar->clearMessage();
 		    break;
 		case KBounceGameWidget::Running :
-		    KGameDifficulty::setEnabled( false );
+			m_pauseAction->setEnabled( true );
 		    m_pauseAction->setChecked( false );
-		    m_statusBar->clearMessage();
 		    break;
 		case KBounceGameWidget::GameOver :
+			m_pauseAction->setEnabled( false );
 		    statusBar()->showMessage(  i18n("Game over. Click to start a game") );
 		    highscore();
 		    KGameDifficulty::setEnabled(true);
@@ -259,27 +271,18 @@
 
 void KBounceMainWindow::focusOutEvent( QFocusEvent *ev )
 {
-    // FIXME this event is triggered when right-clicking on QGraphicsView. Why?
-    // Need to find why :).
-    // Because it prevents a walls from being built.
-    // Commented for now
-    /*
-    if ( m_state==Running )
+	if ( m_gameWidget->state() == KBounceGameWidget::Running )
     {
-        stopLevel();
-        m_state = Suspend;
-        m_pauseButton->setChecked(true);
+		m_gameWidget->setSuspended( true );
         statusBar()->showMessage( i18n("Game suspended") );
-        // m_gameWidget->display( i18n("Game suspended") );
     }
 
-     */
     KXmlGuiWindow::focusOutEvent( ev );
 }
 
 void KBounceMainWindow::focusInEvent ( QFocusEvent *ev )
 {
-    //m_board->setSuspended( true );
+	m_gameWidget->setSuspended( false );
     KXmlGuiWindow::focusInEvent( ev );
 }
 
Index: gamewidget.h
===================================================================
--- gamewidget.h	(Revision 1122882)
+++ gamewidget.h	(Arbeitskopie)
@@ -29,6 +29,7 @@
 #include "board.h"
 #include "renderer.h"
 
+class KBounceOverlay;
 class KGameTheme;
 
 class KBounceGameWidget : public KGameCanvasWidget
@@ -36,7 +37,7 @@
 	Q_OBJECT
 
 	public:
-	enum State { BeforeFirstGame, Running, BetweenLevels, Paused, Suspended, GameOver \
}; +	enum State { BeforeFirstGame, GameStarting, Running, BetweenLevels, Paused, \
Suspended, GameOver };  
 	explicit KBounceGameWidget( QWidget* parent = 0 );
 	~KBounceGameWidget();
@@ -78,6 +79,7 @@
 	void renderBackground();
 	void closeLevel();
 	void newLevel();
+	int getLevelTotalTime() const;
 
 	void redraw();
 
@@ -93,8 +95,7 @@
 	int m_lives;
 	int m_time;
 	KGameDifficulty::standardLevel m_difficultyLevel;
-
-	KGameCanvasPixmap* m_overlay;
+	KBounceOverlay* m_overlay;
 	void generateOverlay();
 
 	bool m_vertical;
Index: overlay.h
===================================================================
--- overlay.h	(Revision 0)
+++ overlay.h	(Revision 0)
@@ -0,0 +1,52 @@
+/*
+* Copyright (C) 2010 Andreas Scherf <ascherfy@gmail.com>
+*
+* This file is part of the KDE project "KBounce"
+*
+* KBounce 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.
+*
+* KBounce 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 KBounce; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+* Boston, MA  02110-1301, USA.
+*/
+
+#ifndef OVERLAY_H
+#define OVERLAY_H
+
+#include <kgamecanvas.h>
+#include <gamewidget.h>
+#include <QAbstractAnimation>
+
+class KBounceOverlay : public QObject, public KGameCanvasGroup
+{
+Q_OBJECT
+Q_PROPERTY(int opacity WRITE setOverlayOpacity)
+	public:
+	KBounceOverlay(KGameCanvasAbstract* parent);
+	void setPixmap(const QPixmap& pixmap);
+	void setOverlayOpacity(int value);
+
+	void fadeOut();
+	void fadeIn();
+	bool isVisible() {return m_bVisible;}
+	virtual void show();
+	virtual void hide();
+public slots:
+	void animationStateChanged ( QAbstractAnimation::State,QAbstractAnimation::State );
+
+private:
+    bool m_bFadeOut;
+	bool m_bVisible;
+	KGameCanvasPixmap* m_pOverlayPixmap;
+};
+
+#endif // OVERLAY_H



_______________________________________________
kde-games-devel mailing list
kde-games-devel@kde.org
https://mail.kde.org/mailman/listinfo/kde-games-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic