Erm... I am still having a problem....
Here is my Block.h and GrassBlock.h
I define Draw as a virtual function... But when I go through the Block[][] and call Draw, it calls it on the block side. Even though the value stored in teh array is a GrassBlock, or StoneBlock, or even WoodBlock it all calls the Draw of the Block class.
#pragma once
#include "SFML/Graphics.hpp"
class Block
{
public:
void SetBoundingBox(int offSetX, int offSetY, int width, int height);
void SetPosition(int x, int y);
Block();
virtual void Initialize(sf::Image &image);
virtual void Update(sf::RenderWindow &window);
virtual void Draw(sf::RenderWindow &window);
virtual bool ContainsPoint(int x, int y); //doesn't check if the edges are hit
virtual bool CollidesWithPoint(int x, int y); //checks edges and inside
void output();
bool active;
protected:
sf::Sprite blockSprite;
int hardness, objId, health, maxHealth;
int offsetX, offsetY, width, height; //bounding box
int positionX, positionY;
};
#pragma once
#include "Block.h"
class GrassBlock : public Block
{
public:
void Initialize(sf::Image &image);
void Draw(sf::RenderWindow &window);
void Update(sf::RenderWindow &window);
};