// This header is used to define the member variables and functions of the Rock class.#include <SFML/Graphics.hpp>#include "Missile.h"using namespace sf;#ifndef ROCK_H#define ROCK_Henum {TINY, SMALL, MEDIUM, BIG}class Rock{ private: Sprite rockSprite; int x, y; bool isFloor; int rockType; int collisions[2][4]; public: Rock(int, bool, Image&, Image&, Image&, Image&); ~Rock(); void increaseX(int); void initializeCoords(); bool testCollision(const Helicopter&); void returnCollisions(int[][4]); bool onFloor(); int whatType();};#endif
// This header file defines all of the member variables and functions for the Missile class.#include <SFML/Graphics.hpp>using namespace sf;#ifndef MISSILE_H#define MISSILE_Hclass Missile{ private: Sprite missileSprite; int x, y; int collisions[2][4]; public: Missile(int, int, Image&); ~Missile(); void increaseX(int); void increaseY(int); bool testCollision(const Missile&);};#endif
// This implementation holds all of the details for the Rock class.#include <SFML/Graphics.hpp>#include "Rock.h"#include "Helicopter.h"using namespace sf;// ConstructorRock::Rock(int type, bool floor, Image &rock1, Image &rock2, Image &rock3, Image &rock4){ rockType = type; isFloor = floor; if (isFloor) { switch (rockType) { case TINY: rockSprite.SetImage(rock1); x = 1200; y = 690; break; case SMALL: rockSprite.SetImage(rock2); x = 1200; y = 640; break; case MEDIUM: rockSprite.SetImage(rock3); x = 1200; y = 590; case BIG: rockSprite.SetImage(rock4); x = 1200; y = 575; break; } } else { switch (rockType) { case TINY: rockSprite.SetImage(rock1); rockSprite.FlipX(true); x = 1200; y = 50; break; case SMALL: rockSprite.SetImage(rock2); rockSprite.FlipX(true); x = 1200; y = 100; break; case MEDIUM: rockSprite.SetImage(rock3); rockSprite.FlipX(true); x = 1200; y = 150; case BIG: rockSprite.SetImage(rock4); rockSprite.FlipX(true); x = 1200; y = 175; break; } } this->initializeCoords(); rockSprite.SetX(x); rockSprite.SetY(y);}// DestructorRock::~Rock(){}// Add to or decrease the X coordinate and bounding box coordsvoid Rock::increaseX(int increaser){ x += increaser; rockSprite.SetX(x); collisions[0][0] = x - 21; collisions[0][1] = x + 21; collisions[0][2] = x - 21; collisions[0][3] = x + 21;}// Initialize the bounding box coordinates of the Rock objectvoid Rock::initializeCoords(){ switch (rockType) { case TINY: collisions[0][0] = x - 21; collisions[0][1] = x + 21; collisions[0][2] = x - 21; collisions[0][3] = x + 21; collisions[1][0] = y - 50; collisions[1][1] = y - 50; collisions[1][2] = y + 50; collisions[1][3] = y + 50; break; case SMALL: collisions[0][0] = x - 43; collisions[0][1] = x + 43; collisions[0][2] = x - 43; collisions[0][3] = x + 43; collisions[1][0] = y - 100; collisions[1][1] = y - 100; collisions[1][2] = y + 100; collisions[1][3] = y + 100; break; case MEDIUM: collisions[0][0] = x - 64; collisions[0][1] = x + 64; collisions[0][2] = x - 64; collisions[0][3] = x + 64; collisions[1][0] = y - 150; collisions[1][1] = y - 150; collisions[1][2] = y + 150; collisions[1][3] = y + 150; break; case BIG: collisions[0][0] = x - 75; collisions[0][1] = x + 75; collisions[0][2] = x - 75; collisions[0][3] = x + 75; collisions[1][0] = y - 175; collisions[1][1] = y - 175; collisions[1][2] = y + 175; collisions[1][3] = y + 175; break; }}// Function to test for a helicopter collisionbool Rock::testCollision(const Helicopter &player){ int heliCollisions[2][4]; player.returnCollisions(heliCollisions); return !(collisions[0][1] < heliCollisions[0][0] || // Fully to the left collisions[0][0] > heliCollisions[0][1] || // Fully to the right collisions[1][2] > heliCollisions[1][0] || // Fully above collisions[1][0] < heliCollisions[1][2]); // Fully below}// Function to copy collision box into a passed-by-reference arrayvoid Rock::returnCollisions(int passedCollisions[0][4]){ passedCollisions[0][0] = collisions[0][0]; passedCollisions[0][1] = collisions[0][1]; passedCollisions[0][2] = collisions[0][2]; passedCollisions[0][3] = collisions[0][3]; passedCollisions[1][0] = collisions[1][0]; passedCollisions[1][1] = collisions[1][1]; passedCollisions[1][2] = collisions[1][2]; passedCollisions[1][3] = collisions[1][3];}// Returns whether it's on the floor or ceilingbool Rock::onFloor(){ if (isFloor) { return true; } else { return false; }}// Returns the type of rockint Rock::whatType(){ return rockType;}
// This class implementation file holds the details of the Missile class.#include <SFML/Graphics.hpp>#include "Missile.h"#include "Rock.h"using namespace sf;// Constructor for the Missile class; also initializes collision boxMissile::Missile(int xCoord, int yCoord, Image &missileImage){ x = xCoord; y = yCoord; missileSprite.SetX(x); missileSprite.SetY(y); missileSprite.SetImage(missileImage); collisions[0][0] = x - 23; collisions[0][1] = x + 23; collisions[0][2] = x - 23; collisions[0][3] = x + 23; collisions[1][0] = y - 9; collisions[1][1] = y - 9; collisions[1][2] = y + 9; collisions[1][3] = y + 9;}// DestructorMissile::~Missile(){}// Function to test the intersection of collision boxesbool Missile::testCollision(const Rock::Rock &testRock){ int rockCollisions[2][4]; testRock.returnCollisions(rockCollisions); return !(collisions[0][1] < rockCollisions[0][0] || // Fully to the left collisions[0][0] > rockCollisions[0][1] || // Fully to the right collisions[1][2] > rockCollisions[1][0] || // Fully above collisions[1][0] < rockCollisions[1][2]); // Fully below}// Function to increase the x coordinate by value passedvoid Missile::increaseX(int increaser){ x += increaser; missileSprite.SetX(x); collisions[0][0] += increaser; collisions[0][1] += increaser; collisions[0][2] += increaser; collisions[0][3] += increaser;}// Function to increase the y coordinate by value passedvoid Missile::increaseY(int increaser){ y += increaser; missileSprite.SetY(y); collisions[1][0] += increaser; collisions[1][1] += increaser; collisions[1][2] += increaser; collisions[1][3] += increaser;}
The errors I'm getting come from both of the implementation files. Here's the example from the Rock class:
prototype for 'bool Rock::testCollision(const Helicopter&)' does not match any in class 'Rock'
But I did put that prototype in the header file! :p That's why I'm confused. Then it says this for a function within that function definition:
passing 'const Helicopter' as 'this' argument of 'void Helicopter::returnCollisions(int (*)[4])' discards qualifiers
In the Missile class, it does the exact same thing as that whole function except it's on the testCollision function.
Any help, guidance, or even code advice in general given the above source would be very appreciated :] Thank you all very much in advance.
Colton