Commit ffa04f00 authored by Waldo Bastian's avatar Waldo Bastian

CCMAIL: 43166-done@bugs.kde.org, 45646-done@bugs.kde.org, 46656-done@bugs.kde.org

Fix keyboard direction problems. (BR43166, BR45646, BR46656)

svn path=/trunk/kdegames/ktron/; revision=176160
parent 22272ab6
......@@ -2,7 +2,7 @@
bin_PROGRAMS = ktron
INCLUDES = -I$(top_srcdir)/libkdegames $(all_includes)
LDFLAGS = $(all_libraries) $(KDE_RPATH)
LDADD = $(LIB_KSYCOCA) $(LIB_KFILE) $(LIB_KDEGAMES)
LDADD = $(LIB_KIO) $(LIB_KDEGAMES)
ktron_SOURCES = ktoptdlg.cpp tron.cpp player.cpp ktron.cpp main.cpp
......
......@@ -27,21 +27,18 @@ player::player()
score=0;
reset();
dir=Up;
last_dir=None;
}
void player::reset()
{
alive=true;
accelerated=false;
if(computer)
keyPressed=true;
else
keyPressed=false;
}
void player::setCoordinates(int x, int y)
......
......@@ -26,7 +26,7 @@
#include <config.h>
#endif
enum Direction{ Up, Down, Left, Right};
enum Direction{ None, Up, Down, Left, Right};
/**
* @short This class represents a player with current position and several flags
......@@ -43,6 +43,7 @@ public:
int score;
bool alive;
Direction dir;
Direction last_dir;
bool accelerated;
bool keyPressed;
bool computer;
......
......@@ -175,7 +175,8 @@ void Tron::stopGame()
{
timer->stop();
gameEnded=true;
players[0].last_dir = None;
players[1].last_dir = None;
}
void Tron::togglePause() // pause or continue game
......@@ -603,13 +604,13 @@ void Tron::switchDir(int playerNr,Direction newDirection)
if (oppositeDirCrashes()==false)
{
if (newDirection==::Up && players[playerNr].dir==::Down)
if (newDirection==::Up && players[playerNr].last_dir==::Down)
return;
if (newDirection==::Down && players[playerNr].dir==::Up)
if (newDirection==::Down && players[playerNr].last_dir==::Up)
return;
if (newDirection==::Left && players[playerNr].dir==::Right)
if (newDirection==::Left && players[playerNr].last_dir==::Right)
return;
if (newDirection==::Right && players[playerNr].dir==::Left)
if (newDirection==::Right && players[playerNr].last_dir==::Left)
return;
}
......@@ -642,6 +643,7 @@ void Tron::updateDirections(int playerNr)
playfield[x][y] &= (~LEFT);
break;
}
players[0].last_dir = players[0].dir;
}
if(playerNr==-1 || playerNr==1)
......@@ -668,6 +670,7 @@ void Tron::updateDirections(int playerNr)
playfield[x][y] &= (~LEFT);
break;
}
players[1].last_dir = players[1].dir;
}
......@@ -813,24 +816,22 @@ void Tron::keyPressEvent(QKeyEvent *e)
e->ignore(); // if key is unknown: ignore
// if both players press keys at the same time, start game...
if(gameEnded && !gameBlocked)
{
if(players[0].keyPressed && players[1].keyPressed)
{
reset();
startGame();
}
if(gameEnded && !gameBlocked)
{
if(players[0].keyPressed && players[1].keyPressed)
{
reset();
startGame();
}
// ...or continue
else if(gamePaused)
{
if(players[0].keyPressed && players[1].keyPressed)
{
togglePause();
}
}
// ...or continue
else if(gamePaused)
{
if(players[0].keyPressed && players[1].keyPressed)
{
togglePause();
}
}
}
void Tron::keyReleaseEvent(QKeyEvent * e)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment