Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2009
    Posts
    37

    Question Errors, errors and more... you guessed it... ERRORS!!

    I'm doing the third VTM, on the Enemy class, and I get these errors when I compile.

    Code:
    c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\sprite.h(8) : error C2365: 'SPRITE_CLASSID' : redefinition; previous definition was 'enumerator'
            c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\sprite.h(8) : see declaration of 'SPRITE_CLASSID'
    c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\sprite.h(9) : error C2365: 'CHAR_CLASSID' : redefinition; previous definition was 'enumerator'
            c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\sprite.h(9) : see declaration of 'CHAR_CLASSID'
    c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\sprite.h(10) : error C2365: 'ENEMY_CLASSID' : redefinition; previous definition was 'enumerator'
            c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\sprite.h(10) : see declaration of 'ENEMY_CLASSID'
    c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\sprite.h(16) : error C2011: 'vector' : 'struct' type redefinition
            c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\sprite.h(16) : see declaration of 'vector'
    c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\sprite.h(22) : error C2011: 'sprite' : 'class' type redefinition
            c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\sprite.h(22) : see declaration of 'sprite'
    c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\character.h(7) : error C2504: 'sprite' : base class undefined
    c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\enemy.cpp(10) : error C2027: use of undefined type 'sprite'
            c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\sprite.h(22) : see declaration of 'sprite'
    c:\documents and settings\fubergang\my documents\visual studio 2008\projects\evilmonkies\evilmonkies\enemy.cpp(10) : fatal error C1903: unable to recover from previous error(s); stopping compilation
    My code:

    enemy.h
    Code:
    #ifndef ENEMY_H
    #define ENEMY_H
    
    #include "sprite.h"
    
    class Level;
    class Character;
    
    class Enemy : public sprite
    {
    public:
    	Enemy(Level *l, drawEngine *de, int s_index, float x = 1, float y = 1,
    		int i_lives = 1);
    
    	void addGoal(Character *g);
    	bool move(float x, float y);
    	void idleUpdate();
    
    private:
    protected:
    	void simulateAI();
    	Character *goal;
    };
    
    #endif
    enemy.cpp
    Code:
    #include "enemy.h"
    #include "character.h"
    #include "level.h"
    
    #include <iostream>
    #include <math.h>
    
    Enemy::Enemy(Level *l, drawEngine *de, int s_index, float x, float y,
    			 int i_lives) : sprite(l, de, s_index, x, y, i_lives)
    {
    	goal = 0;
    	classID = ENEMY_CLASSID;
    }
    
    void Enemy::move(float x, float y)
    {
    	int xpos = (int)(pos.x + x);
    	int ypos = (int)(pos.y + y);
    
    	if(isValidLevelMove(xpos, ypos))
    	{
    		//make sure we dont run into otehr enemies
    		//erase sprite
    	    erase(pos.x, pos.y);
    
    	    pos.x += x;
    	    pos.y += y;
    
    	    facingDirection.x = x;
    	    facingDirection.y = y;
    
    	    //draw sprite
    	    draw(pos.x, pos.y);
    
    	    return true;
    	}
    
    	return false;
    }
    
    void Enemy::idleUpdate()
    {
    	if(goal)
    		sinulateAI();
    }
    
    void Enemy::addGoal(Character *g)
    {
    	goal = g;
    }
    
    void Enemy::simulateAI()
    {
    	vector goal_pos = goal->getPosition();
    	vector direction;
    
    	direction.x = goal_pos.x - pos.x;
    	direction.y = goal_pos.y - pos.y;
    
    	float mag = sqrt(direction.x * direction.x + direction.y * direction.y);
    
    	direction.x = direction.x / mag;
    	direction.y = direction.y / mag;
    
    	if(!move(direction.x, direction.y))
    	{
    		while(!move(float(rand() % 3 - 1), float(rand() % 3 - 1)))
    		{
    		}
    	}
    }
    sprite.h
    Code:
    #ifndef SPRITE_H
    #define SPRITE H
    
    #include "drawEngine.h"
    
    enum
    {
    	SPRITE_CLASSID,
    	CHAR_CLASSID,
    	ENEMY_CLASSID,
    };
    
    class Level;
    
    struct vector
    {
    	float x;
    	float y;
    };
    
    class sprite
    {
    public:
    	sprite(Level *l, drawEngine *de, int s_index, float x = 1, float y = 1, int i_lives = 1);
    	~sprite();
    
    	vector getPosition(void);
    
    	float getX(void);
    	float getY(void);
    
    	virtual void addLives(int num = 1);
    	int getLives(void);
    	bool isAlive(void);
    
    	virtual void idleUpdate();
    
    	virtual bool move(float x, float y);
    
    private:
    protected:
    
    	Level *level;
    
    	void draw(float x, float y);
    	void erase(float x, float y);
    
    	vector facingDirection;
    
    	int classID;
    
    	drawEngine *drawArea;
    	vector pos;
    	int spriteIndex;
    	int numLives;
    
    	bool isValidLevelMove(int xpos, int ypos);
    
    };
    
    #endif
    sprite.cpp
    Code:
    #include "sprite.h"
    #include "level.h"
    
    sprite::sprite(Level *l, drawEngine *de, int s_index, float x, float y, int i_lives)
    {
    	drawArea = de;
    
    	pos.x = x;
    	pos.y = y;
    
    	spriteIndex = s_index;
    
    	numLives = i_lives;
    
    	facingDirection.x = 0;
    	facingDirection.y = 1;
    
    	classID = SPRITE_CLASSID;
    
    	level = l;
    }
    
    sprite::~sprite()
    {
    	//erase the dying sprite
    	erase(pos.x, pos.y);
    }
    
    vector sprite::getPosition()
    {
    	return pos;
    }
    
    float sprite::getX()
    {
    	return pos.x;
    }
    
    float sprite::getY()
    {
    	return pos.y;
    }
    
    void sprite::addLives(int num)
    {
    	numLives += num;
    }
    
    int sprite::getLives()
    {
    	return numLives;
    }
    
    bool sprite::isAlive()
    {
    	return (numLives > 0);
    
    	/*
    	if (numLives <= 0)
    		return false;
    	else
    		return*/
    }
    
    bool sprite::move(float x, float y)
    {
    	int xpos = (int)(pos.x + x);
    	int ypos = (int)(pos.y + y);
    
    	if(isValidLevelMove(xpos, ypos))
    	{
    	//erase sprite
    	erase(pos.x, pos.y);
    
    	pos.x += x;
    	pos.y += y;
    
    	facingDirection.x = x;
    	facingDirection.y = y;
    
    	//draw sprite
    	draw(pos.x, pos.y);
    
    	return true;
    	}
    
    	return false;
    }
    
    void sprite::draw(float x, float y)
    {
    	drawArea->drawSprite(spriteIndex, (int)x, (int)y);
    }
    
    void sprite::erase(float x, float y)
    {
    	drawArea->eraseSprite((int)x, (int)y);
    }
    
    bool sprite::isValidLevelMove(int xpos, int ypos)
    {
    	if(level->level[xpos][ypos] != TILE_WALL)
    	{
    		return true;
    	}
    
    	return false;
    }
    
    void sprite::idleUpdate()
    {
    	//for furture
    }
    character.h
    Code:
    #ifndef CHAR_H
    #define CHAR_H
    
    #include "sprite.h"
    
    class Character : public sprite
    {
    public:
    	Character(Level *lvl, drawEngine *de, int s_index, float x = 1, float y = 1, int lives = 3, char u = 'w', char d = 's', char l = 'a', char r = 'd');
    
    	virtual bool keyPress(char c);
    
    protected:
    	char upKey;
    	char downKey;
    	char leftKey;
    	char rightKey;
    };
    
    #endif
    character.cpp
    Code:
    #include "character.h"
    
    Character::Character(Level *lvl, drawEngine *de, int s_index, float x, float y, int lives, char u,
    					 char d, char l, char r)
    					 : sprite(lvl, de, s_index, x, y, numLives)
    {
    	upKey = u;
    	downKey = d;
    	leftKey = l;
    	rightKey = r;
    
    	classID = CHAR_CLASSID;
    }
    
    bool Character::keyPress(char c)
    {
    	if(c == upKey)
    	{
    		return move(0, -1);
    	}
    	else if(c == downKey)
    	{
    		return move(0, 1);
    	}
    	else if(c == leftKey)
    	{
    		return move(-1, 0);
    	}
    	else if(c == rightKey)
    	{
    		return move(1, 0);
    	}
    
    	return false;
    }
    Again, HELLLLLLLLLLLLLLLLLLP?

  2. #2
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    Easy:

    Code:
    #ifndef SPRITE_H
    #define SPRITE H
    In your sprite.h you define SPRITE as H you missed the _
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

  3. #3
    Join Date
    Jan 2009
    Posts
    37
    Ah, right.

    Thanks.

    I make too many stupid errors.

    Meh, I'm still learning...

  4. #4
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    Always fix the first thing it whines about. Ignore the rest until you fixed the first.
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

  5. #5
    Join Date
    Jun 2005
    Location
    NY
    Posts
    1,374
    Quote Originally Posted by Lord Orechale View Post
    Ah, right.

    Thanks.

    I make too many stupid errors.

    Meh, I'm still learning...
    Don't fret, it happens all the time. You just forget a single character, I do it all the time.

    Just remember when searching for stuff never just assume you didn't make a mistake in a simple statement, I have a problem with that, I'll just be like "I'm positive I put that there!" then "Oh, guess I didn't." lol
    CodeGuru: DLL Tutorial For Beginners by me. Rated 4 1/2 out of 5.

  6. #6
    Join Date
    Jul 2007
    Location
    Minnesota
    Posts
    234
    Quote Originally Posted by Notsosuperhero View Post
    I'll just be like "I'm positive I put that there!" then "Oh, guess I didn't." lol
    Happens about 100 times a day... save my changes, run my page... simple error. *Types 1-3 characters in IDE*, save my changes, Alt+Tab, F5, repeat...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •