diff options
Diffstat (limited to 'kue/localplayer.cpp')
-rw-r--r-- | kue/localplayer.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/kue/localplayer.cpp b/kue/localplayer.cpp new file mode 100644 index 00000000..51b157b3 --- /dev/null +++ b/kue/localplayer.cpp @@ -0,0 +1,82 @@ +#include <tdeapplication.h> +#include <kdebug.h> +#include <tqtimer.h> + +#include "localplayer.h" +#include "global.h" +#include "interface.h" +#include "physics.h" + + +KueLocalPlayer::KueLocalPlayer(TQString n, TQColor color) : KuePlayer(n), _dest(0) +{ + _color = color; +} + +// Rules' functions +void KueLocalPlayer::placeBilliard(int index, const KueBilliard &b, double line, TQObject *dest, const char *dest_slot) +{ + _dest = dest; + _dest_slot = dest_slot; + + connect(KueGlobal::glWidget(), TQ_SIGNAL(billiardPlaced(point &)), this, TQ_SLOT(billiardPlaced(point &))); + connect(KueGlobal::glWidget(), TQ_SIGNAL(previewBilliardPlace(point &)), this, TQ_SLOT(previewBilliardPlace(point &))); + + _index = index; + // We use the passed billiard as a template, and just move it around + KueGlobal::physics()->insertBilliard(index, b); + + KueGlobal::glWidget()->placeBilliard(line); +} + +void KueLocalPlayer::takeShot(int index, bool forward_only, TQObject *dest, const char *dest_slot) +{ + _dest = dest; + _dest_slot = dest_slot; + + connect(KueGlobal::glWidget(), TQ_SIGNAL(shotTaken(vector &)), this, TQ_SLOT(shotTaken(vector &))); + + _index = index; + KueGlobal::glWidget()->startShot(*KueGlobal::physics()->billiards()[index], _color, forward_only); +} + +// Called by the interface when the user has decided on a cue location +void KueLocalPlayer::billiardPlaced(point &location) +{ + KueGlobal::physics()->billiards()[_index]->setPosition(location); + KueGlobal::physics()->run(0); + + disconnect(); + callBack(); +} + +// Called by the interface when the user is deciding on a cue location +void KueLocalPlayer::previewBilliardPlace(point &location) +{ + // Inform the physics engine + KueGlobal::physics()->billiards()[_index]->setPosition(location); + + // Redraw + KueGlobal::glWidget()->updateGL(); +} + +void KueLocalPlayer::shotTaken(vector &velocity) +{ + KueGlobal::physics()->billiards()[_index]->setVelocity(velocity); + + disconnect(); + callBack(); +} + +void KueLocalPlayer::callBack() +{ + // Call the completion callback + if (_dest) + { + TQTimer::singleShot(0, _dest, _dest_slot); + _dest = 0; + } +} + + +#include "localplayer.moc" |