summaryrefslogtreecommitdiffstats
path: root/kue/physics.h
blob: e1affc8b0c21044098b0d54d3d82d16e0c492bd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef _PHYSICS_H
#define _PHYSICS_H

#include "main.h"
#include "billiard.h"
#include "pocket.h"
#include "circle.h"
#include "point.h"
#include "vector.h"

#include <ntqptrvector.h>

const int TIME_CHUNK = 10;

class KuePhysics : public TQObject {
  TQ_OBJECT

  public:
	KuePhysics();
	~KuePhysics();

	// Start the physics engine
	void start() { _running = true; startTimer(TIME_CHUNK); }
	// Full stop
	void stop() { _running = false; killTimers(); }

	bool running() { return _running; }

	// Run the physics state for a set number of milliseconds
	// You should really only pass this 0, to seperate billiards on demand
	// If you can think of a clever use for it, go right ahead, though
	bool run(int milliseconds);

	// Inserts a billard at a specific location
	void insertBilliard(unsigned int billiard, const KueBilliard &b);

	// Removes a given billiard
	void removeBilliard(unsigned int billiard) { _billiards.remove(billiard); }

	// Inserts pocket at a specific location
	void insertPocket(unsigned int pocket, const KuePocket &p);
	
	// Removes a given pocket
	void removePocket(unsigned int pocket) { _pockets.remove(pocket); }

	TQPtrVector<KueBilliard> & billiards() { return _billiards; }
	TQPtrVector<KuePocket> & pockets() { return _pockets; }

	double fieldWidth() { return _field_width; }
	double fieldHeight() { return _field_height; }

	void setFieldWidth(double field_width) { _field_width = field_width; }
	void setFieldHeight(double field_height) { _field_height = field_height; }

  signals:
	void billiardHit(unsigned int b1, unsigned int b2);
	void billiardSunk(unsigned int b, unsigned int p);
	void motionStopped();

  protected:
	void doPocketing();
	void timerEvent ( TQTimerEvent * );

	bool _running;
	void seperate(KueBilliard *a, KueBilliard *b);

	bool allStop();

	TQPtrVector<KueBilliard> _billiards;
	TQPtrVector<KuePocket> _pockets;

	double _field_width;
	double _field_height;
};

#endif