0

Hiya!

Im not new to programming but sometimes i can be really noobie so im sure this is probably really silly. I have an undecleared indentifier that only shows up in the main but is fine in the header and cpp files. I thought it might be an include loop but it doesnt seem to be. It can find the draw function but not its parameter. What have i forgotten?

Creature.h

#ifndef CREATURE_H
#define CREATURE_H
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <string>
using std::string;

class Creatures
{
private:
    int xPos;
    int yPos;;
    ALLEGRO_BITMAP* sprite;

public:
    Creatures(int x, int y, string s); // constructor

    void draw(ALLEGRO_BITMAP* s);   
};

#endif

Creature.cpp

#include "Creatures.h"
#include <iostream>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

Creatures::Creatures(int x, int y, string s)
{
    xPos = x;
    yPos = y;
    sprite = al_load_bitmap(s.c_str());
}

void Creatures::draw(ALLEGRO_BITMAP* s)
{
    al_convert_mask_to_alpha(s, al_map_rgb(255,0,255));
    al_draw_bitmap(s, getX(), getY(), 0);
}

Player.h (astroid and enemy are the same so i didnt include them)

#ifndef PLAYER_H
#define PLAYER_H
#include "Creatures.h"

class Player:public Creatures
{
private:

public:
    Player(int x, int y, string s); //constructor
};

#endif

Player.cpp (astroid and enemy are the same so i didnt include them either)

#include "Player.h"
#include "Creatures.h"

Player::Player(int x, int y, string s):Creatures(x, y, s)
{
}

main

#include <iostream>
#include <conio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include "Player.h"
#include "Enemy.h"
#include "Astroid.h"

int main()
{
    //create objects
    Player* player = new Player(50, 50, "Assets/playerSprite.bmp");
    Enemy* enemy = new Enemy(100, 100, "Assets/enemySprite.bmp");
    Astroid* astroid = new Astroid(200, 200, "Assets/astroidSprite.bmp");

    while(!keys_pressed[KEY_ESCAPE])
    {
        player->draw(s); //errors are these 3 lines, s is an undeclared identifier
        enemy->draw(s);
        astroid->draw(s);
    }

    //destroy stuff
    al_destroy_display(display);
    getch();
    return 0;
}
}

errors

Error   1   error C2065: 's' : undeclared identifier

I only included what i thought was relevant so tell me if you need more info.

4
Contributors
6
Replies
7
Views
4 Years
Discussion Span
Last Post by MiniApocalypse
0

In the creature constructor here

Creatures(int x, int y, string s);

then the filename is converted into a string

Creatures::Creatures(int x, int y, string s) //s comes through here
{
    xPos = x;
    yPos = y;
    sprite = al_load_bitmap(s.c_str()); //converted here
}

which then is inherited into player

Player::Player(int x, int y, string s):Creatures(x, y, s)
{
}

and the bitmap filename comes from here

    Player* player = new Player(50, 50, "Assets/playerSprite.bmp");

at least thats how i thought it worked :S

0

Its meant to be creatures.h I've change them all now (see noobie things!) Thanks for noticing but it still has the same error.

1

Just get rid of the paramater in the function so it looks like this void draw(); and then change the function like this

void Creatures::draw()
{
    al_convert_mask_to_alpha(sprite, al_map_rgb(255,0,255));
    al_draw_bitmap(sprite, getX(), getY(), 0);
}

This will let you use the sprite variable of the class.

0

Omg of course, im not sure why i was trying to pass s in when it already had sprite. It made sence when i wrote it lol. Thanks guys!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.