summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormario <mario@notk.org>2011-11-29 14:34:01 +0100
committermario <mario@notk.org>2011-11-29 14:34:01 +0100
commitc82f2bfa593614f266bd67bc979f5ecbc5349774 (patch)
tree57f6bc8147acee45fc8f61305710fa9feaade6aa
parentea176fc6edd05eccfd79ddb7ce6a83c38b601e29 (diff)
parentf6e512372eae12830050e9f0dcdd64cf7a322fac (diff)
Fixed warnngs (implicit casts and float/double conversion
-rw-r--r--AIController.cpp5
-rw-r--r--Field.h4
-rw-r--r--Game.cpp19
-rw-r--r--MainWindow.cpp11
-rw-r--r--Player.cpp38
-rw-r--r--Player.h5
-rw-r--r--TrollTron.cpp3
7 files changed, 58 insertions, 27 deletions
diff --git a/AIController.cpp b/AIController.cpp
index fd74e63..d7c6b97 100644
--- a/AIController.cpp
+++ b/AIController.cpp
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include "AIController.h"
@@ -14,6 +15,8 @@ AIController::~AIController(void)
void AIController::think() {
Coordinates coord = m_player.getCoordinates();
VelocityVector velocity = m_player.getVelocity();
+
+ printf("player %d, coordinates: %d, %d; velocity: %d, %d\n", m_player.getNumber(), coord.x, coord.y, velocity.x, velocity.y);
int sgn_x = velocity.x >= 0 ? 1 : -1;
int sgn_y = velocity.y >= 0 ? 1 : -1;
@@ -25,7 +28,7 @@ void AIController::think() {
}
}
}
- if (rand() % 100 >=7) turnRandom();
+ if (rand() % 100 >= 7) turnRandom();
m_inhibit = max(0,m_inhibit-1);
}
diff --git a/Field.h b/Field.h
index 510dd3f..2c2f89e 100644
--- a/Field.h
+++ b/Field.h
@@ -22,8 +22,8 @@ public:
void setCell(Coordinates coord, Cell cell);
private:
- uint m_width;
- uint m_height;
+ int m_width;
+ int m_height;
std::vector<Cell> m_fieldCells;
};
diff --git a/Game.cpp b/Game.cpp
index 6ad4e02..bcd2ebe 100644
--- a/Game.cpp
+++ b/Game.cpp
@@ -1,14 +1,18 @@
+#include <stdio.h>
#include "Game.h"
#include "AIController.h"
+#define _USE_MATH_DEFINES
+#include <math.h>
+
Game::Game(int width, int height, PlayerNumber num):
m_Field(width, height)
{
- m_vPlayers.clear(); // is it possible to resize it without trying to fill it? (i.e. fill with null pointers)
+ m_vPlayers.resize(num); // is it possible to resize it without trying to fill it? (i.e. fill with null pointers)
for(PlayerNumber i = 0; i<num; ++i)
{
- int x = (int)(width * (0.5 + 0.3*cosf(2*M_PI*(float)i/num+M_PI)));
- int y = (int)(height * (0.5 + 0.3*sinf(2*M_PI*(float)i/num+M_PI)));
+ int x = (int)(width * (0.5f + 0.3f*cosf(2.f*M_PI*(float)i/num+M_PI)));
+ int y = (int)(height * (0.5f + 0.3f*sinf(2.f*M_PI*(float)i/num+M_PI)));
VelocityVector velocity;
if (abs(x-width/2) >= abs(y-height/2)) {
@@ -24,8 +28,11 @@ Game::Game(int width, int height, PlayerNumber num):
velocity = VelocityVector(0,1);
}
}
-
- m_vPlayers.push_back(Player(i, Coordinates(x,y), velocity));
+
+ m_vPlayers[i].setCoordinates(Coordinates(x,y));
+ m_vPlayers[i].setVelocityVector(velocity);
+ m_vPlayers[i].setNumber(i);
+ m_vPlayers[i].revive();
m_Field.getCell(Coordinates(x,y)).setState(PLAYER);
m_Field.getCell(Coordinates(x,y)).setPlayer(&m_vPlayers[i]);
@@ -73,7 +80,7 @@ void Game::updateGame(uint timeElapsedMs) {
// ask the AI if they wanna change something?
for(std::vector<Player>::iterator player = m_vPlayers.begin(); player != m_vPlayers.end(); ++player) {
if (player->getController()) {
- player->getController()->think();
+ player->getController()->think();
}
}
diff --git a/MainWindow.cpp b/MainWindow.cpp
index 13b4fad..c8403e1 100644
--- a/MainWindow.cpp
+++ b/MainWindow.cpp
@@ -1,8 +1,7 @@
#include "MainWindow.h"
#include "types.h"
-#define _USE_MATH_DEFINES
-#include <math.h>
+
#include <iostream>
#ifdef APPLE_NATIVE_GLUT
@@ -87,8 +86,8 @@ void MainWindow::onRenderScene() {
glEnd();
- uint lineX = 0;
- uint lineY = 0;
+ int lineX = 0;
+ int lineY = 0;
color = emptyColors[1];
hex2fColor(color, red, green, blue);
@@ -105,9 +104,9 @@ void MainWindow::onRenderScene() {
glVertex2f( 1, 2 * ((float) lineY / maxC.x) - 1);
}
glEnd();
- for(uint coordX = 0; coordX < maxC.x; ++coordX)
+ for(int coordX = 0; coordX < maxC.x; ++coordX)
{
- for(uint coordY = 0; coordY < maxC.y; ++coordY)
+ for(int coordY = 0; coordY < maxC.y; ++coordY)
{
Cell c = m_pField->getCell(Coordinates(coordX, coordY));
diff --git a/Player.cpp b/Player.cpp
index 6308839..a9c3ea9 100644
--- a/Player.cpp
+++ b/Player.cpp
@@ -1,5 +1,6 @@
-#include "Player.h"
+#include <stdio.h>
#include <iostream>
+#include "Player.h"
Player::Player(PlayerNumber PlayerID, Coordinates InitialPoint, VelocityVector initialVel) : m_playerID(PlayerID), m_currentCoordinates(InitialPoint), m_velocityVector(initialVel)
{
@@ -7,11 +8,30 @@ Player::Player(PlayerNumber PlayerID, Coordinates InitialPoint, VelocityVector i
// m_controller=KeyboardController(self);
}
+Player::Player()
+{
+ m_playerID = -1;
+ m_alive = false;
+}
+
Player::~Player(void)
{
+ printf("delete player %d\n", m_playerID);
// destroy m_pController
}
+void Player::setCoordinates(Coordinates c) {
+ m_currentCoordinates = c;
+}
+
+void Player::setNumber(PlayerNumber n) {
+ m_playerID = n;
+}
+
+void Player::revive() {
+ m_alive = true;
+}
+
std::vector<Coordinates> Player::move() {
std::vector<Coordinates> cases;
@@ -33,19 +53,15 @@ void Player::setVelocityVector(VelocityVector v) {
}
void Player::turnLeft() {
- std::cout << "turnLeft, player " << m_playerID << std::endl;
- std::cout << "x: " << m_velocityVector.x << " y: " << m_velocityVector.y << std::endl;
- int t = m_velocityVector.x;
- m_velocityVector.x = m_velocityVector.y;
- m_velocityVector.y = - m_velocityVector.x;
- std::cout << "x: " << m_velocityVector.x << " y: " << m_velocityVector.y << std::endl;
+ printf("turnLeft, player %d, velocity: %d, %d\n", m_playerID, m_velocityVector.x, m_velocityVector.y);
+ VelocityVector t = VelocityVector(m_velocityVector.y, - m_velocityVector.x);
+ m_velocityVector = t;
}
void Player::turnRight() {
- std::cout << "turnRight " << m_playerID << std::endl;
- int t = m_velocityVector.x;
- m_velocityVector.x = - m_velocityVector.y;
- m_velocityVector.y = m_velocityVector.x;
+ printf("turnRight, player %d, velocity: %d, %d\n", m_playerID, m_velocityVector.x, m_velocityVector.y);
+ VelocityVector t = VelocityVector(- m_velocityVector.y, m_velocityVector.x);
+ m_velocityVector = t;
}
diff --git a/Player.h b/Player.h
index 5798631..7f25a44 100644
--- a/Player.h
+++ b/Player.h
@@ -12,6 +12,7 @@ class Controller;
class Player
{
public:
+ Player(void);
Player(PlayerNumber PlayerID, Coordinates InitialPoint, VelocityVector initialVel);
virtual ~Player(void);
@@ -22,6 +23,10 @@ public:
**/
std::vector<Coordinates> move();
void setVelocityVector(VelocityVector v);
+ void setCoordinates(Coordinates c);
+ void setNumber(PlayerNumber n);
+ void revive();
+
/**
* Tries to change the direction the player is facing.
* Returns false and do nothing if the player is heading the opposite
diff --git a/TrollTron.cpp b/TrollTron.cpp
index 80df411..becb7b3 100644
--- a/TrollTron.cpp
+++ b/TrollTron.cpp
@@ -2,6 +2,7 @@
#include <iostream>
#include "MainWindow.h"
+#include <time.h>
int main(int argc, char **argv) {
@@ -11,7 +12,7 @@ int main(int argc, char **argv) {
// This will define the size and position, in pixel, of the window, originally. It can be moved and resized.
mainWindow.create("Troll Tron", 100, 100, 320, 320);
- srand(time(NULL));
+ srand((unsigned) time(NULL));
// This will define the grid
Game game(200, 200, 3);