Delete Function error

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

37 Replies - 7245 Views - Last Post: 06 February 2013 - 06:27 AM Rate Topic: -----

#31 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Re: Delete Function error

Posted 05 February 2013 - 06:48 PM

That made more problems..

ok here is all the things that i have in the project

Character.h
#ifndef CHARACTER_H
#define CHARACTER_H
#define MAX_X 620
#define MIN_X 0
#define MAX_Y 460
#define MIN_Y 0


class Character{

public:
       Character();

       int GetX();
       void SetX( int newValue, BITMAP* tempBitmap, BITMAP* spriteToDraw);
       
       int GetY();
       void SetY( int newValue, BITMAP* tempBitmap, BITMAP* spriteToDraw);
       
       void EraseOldSprite( BITMAP* tempBitmap);
       void DrawNewSprite( BITMAP* tempBitmap, BITMAP* spriteToDraw);
       
       bool IsDead();
       void SetDead( bool newValue, BITMAP* tempBitmap);

protected:
        int x;
        int y;
        
        bool visible;
        bool dead;

};

#endif



Laser.h

#ifndef LASER_H
#define LASER_H 


class Laser: public Character{

public:
       Laser();
       void CheckCollision(Character objectsToCheck[], BITMAP* tempBitmap);
       bool CheckCollision(Character player, BITMAP* tempBitmap);
       

};

#endif



Ship.h

#ifndef SHIP_H
#define SHIP_H
#include "Character.h"

class Ship: public Character
{

public:
       Ship();
       
       int GetLives();
       void SetLives( int newValue);
       

private:
        int lives;

};

#endif



Character.cpp

#include "Character.h"

Character::Character( ){

    x = 0;
    y = 0;
    
    visible = true;
    dead = false;

}

int Character::GetX(){

    return x;

}

int Character::GetY(){

    return y;

}

void Character::SetX( int newValue, BITMAP* tempBitmap, BITMAP* spriteToDraw){

    if( newValue <= MAX_X && newValue >= MIN_X && visible){
        EraseOldSprite( tempBitmap);
        x = newValue;
        DrawNewSprite( tempBitmap, spriteToDraw);
    } else {
    
        x = newValue;
           
    }

}

void Character::SetY( int newValue, BITMAP* tempBitmap, BITMAP* spriteToDraw){

    if( newValue <= MAX_Y && newValue >= MIN_Y && visible){
        EraseOldSprite( tempBitmap);
        y = newValue;
        DrawNewSprite( tempBitmap, spriteToDraw);
    } else {
    
        y = newValue;
           
    }

}

bool Character::IsDead(){

    return dead;
}

void Character::SetDead(bool newValue, BITMAP* tempBitmap){

    visible = (!newValue);
    dead = newValue;

    if(dead){
        EraseOldSprite( tempBitmap);
        SetY( 700, NULL, NULL);
        SetX( 700, NULL, NULL);
    }

}

void Character::EraseOldSprite( BITMAP* tempBitmap){

    rectfill( tempBitmap, GetX(), GetY(), GetX() + 20, GetY() + 20, makecol ( 0, 0, 0));

}

void Character::DrawNewSprite( BITMAP* tempBitmap, BITMAP* spriteToDraw){

    draw_sprite( tempBitmap, spriteToDraw, GetX(), GetY());

}



Laser.cpp

#include "Laser.h"
 
Laser::Laser(){
               
}

void Laser::CheckCollision(Character objectsToCheck[], BITMAP* tempBitmap){

    for( int i = 0; i <= 9; i++){
    
        if( GetX() == objectsToCheck[i].GetX() && GetY() == objectsToCheck[i].GetY()){
        
            SetDead( true, tempBitmap);
            objectsToCheck[i].SetDead( true, tempBitmap);
            break;
        
        } else if ( GetY() == MIN_Y ){
        
            SetDead( true, tempBitmap);
            break;
        }
        
    
    }
    

}

bool Laser::CheckCollision(Character player, BITMAP* tempBitmap){

    if( GetX() == player.GetX() && GetY() == player.GetY()){
    
        SetDead( true, tempBitmap);
        player.SetDead( true, tempBitmap);
        return true;
            
    } else if ( GetY() == MAX_Y){
    
        SetDead( true, tempBitmap);
        return false;
    
    }

    return false;
}



Ship.cpp

#include "Ship.h"

Ship::Ship(){

}

int Ship::GetLives(){

    return lives;

}

void Ship::SetLives( int newValue){

    lives = newValue;

}




Game Main.cpp

#include <allegro.h>
#include <stdlib.h>
#include <time.h>
#include "Character.h"
#include "Ship.h"
#include "Laser.h"


Character *myEnemies = new Character[5];



Ship myShip;
Laser myLaser;


Laser enemyLasers[10];

BITMAP* buffer;
BITMAP* ship;
BITMAP* enemy;
BITMAP* laser;
BITMAP* enemyLaser;

bool update = true;

void Draw(){

    acquire_screen();
    draw_sprite( screen, buffer, 0, 0);
    release_screen();

    update = false;

    rest(50);

}

void SetRandSeed(){

    time_t secs;
    time(&secs);
    srand( (unsigned int)secs);

}

void updateLives(){

    char tempStr[2];
    itoa(myShip.GetLives(), tempStr, 10);
    textout_ex( buffer, font, tempStr, 70, 460, makecol( 255, 0, 0), makecol( 0, 0, 0));

}

void SetupGame(){

    SetRandSeed();

    myLaser.SetDead( true, buffer);

    for( int i= 0; i <=9; i++){
        if( i < 5)
            myEnemies[i].SetY( 20, buffer, enemy);
        else
            myEnemies[i].SetY( 40, buffer, enemy);
        if( i < 5)
            myEnemies[i].SetX( ((20* i) + 240), buffer, enemy);
        else
            myEnemies[i].SetX( ((20* (i - 5)) + 240), buffer, enemy);
    }

    for( int i= 0; i <=9; i++){

        enemyLasers[i].SetDead(true, buffer);

    }

    myShip.SetX( ((640/2) - 40), buffer, ship);
    myShip.SetY( (480 - 40), buffer, ship);
    myShip.SetLives( 4);
    textout_ex( buffer, font, "Lives: ", 10, 460, makecol( 255, 0, 0), makecol( 0, 0, 0));
    updateLives();


    Draw();
}

void movePlayer(){

    if( key[KEY_RIGHT]){

        myShip.SetX( (myShip.GetX() + 20), buffer, ship);
        update = true;

    } else if( key[KEY_LEFT]){

        myShip.SetX( (myShip.GetX() - 20), buffer, ship);
        update = true;

    } else if( key[KEY_SPACE]){

        if( myLaser.IsDead()){

            myLaser.SetDead(false, buffer);
            myLaser.SetX( myShip.GetX(), buffer, laser);
            myLaser.SetY( (myShip.GetY() - 20), buffer, laser);
            update = true;

        }

    }

}

void moveLaser(){

    if( !(myLaser.IsDead()) ){

        myLaser.SetY( (myLaser.GetY() - 20), buffer, laser);

        myLaser.CheckCollision(myEnemies, buffer);

        update = true;

    }

}

void moveEnemy(){

    int shoot;

    for( int i = 0; i <= 9; i++){

        if(!myEnemies[i].IsDead()){

            shoot = rand() % 1000 + 1;

            if( shoot == 25){

                enemyLasers[i].SetDead( false, buffer);
                enemyLasers[i].SetX( myEnemies[i].GetX(),buffer, enemyLaser);
                enemyLasers[i].SetY( 60, buffer, enemyLaser);
                update = true;

            }

        }

    }

}

void moveEnemyLaser(){

    for( int i = 0; i <= 9; i++){

        if( !enemyLasers[i].IsDead()){

            enemyLasers[i].SetY( (enemyLasers[i].GetY() + 20), buffer, enemyLaser);
            if( (enemyLasers[i].CheckCollision(myShip, buffer))){

                myShip.SetLives(myShip.GetLives() - 1);
                updateLives();


            }
            update = true;

        }

    }

}

bool checkPlayerLives(){

    if ( myShip.GetLives() <= 0){

         textout_ex( screen, font, "GAME OVER", 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0));

         while(!key[KEY_ESC]){}

         return true;
    }

    return false;

}

bool checkEnemyLives(){

    int enemiesDead = 0;

    for( int i = 0; i <= 9; i++){

        if(myEnemies[i].IsDead())
            ++enemiesDead;

    }

    if(enemiesDead >= 10){

        textout_ex( screen, font, "YOU WIN!!!!", 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0));

         while(!key[KEY_ESC]){}

         return true;
    }

    return false;

}

int main(){
Character *myEnemies = new Character[5];
    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);

    buffer = create_bitmap( 640, 480);
    ship = load_bitmap( "ship.bmp", NULL);
    enemy = load_bitmap( "enemy.bmp", NULL);
    laser = load_bitmap( "laser.bmp", NULL);
    enemyLaser = load_bitmap( "enemyLaser.bmp", NULL);

    SetupGame();

    while(!key[KEY_ESC]){

        movePlayer();
        moveLaser();
        moveEnemy();
        moveEnemyLaser();
        if(checkPlayerLives())
            break;
        if(checkEnemyLives())
            break;

        if(update)
            Draw();

    }

     delete []  myEnemies;

    destroy_bitmap( buffer);
    destroy_bitmap( ship);
    destroy_bitmap( enemy);

    return 0;

}
END_OF_MAIN();




I do have the windows app thing that will make the window.
Was This Post Helpful? 0
  • +
  • -

#32 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,469
  • Joined: 05-May 12

Re: Delete Function error

Posted 05 February 2013 - 07:16 PM

What are the "more problems"? Post your new errors.
Was This Post Helpful? 0
  • +
  • -

#33 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Re: Delete Function error

Posted 05 February 2013 - 07:47 PM

1 C:\Users\think\Desktop\EthernetDrivers\hw\Ship.h:3, from Ship.cpp In file included from Ship.h:3, from Ship.cpp

1 C:\Users\think\Desktop\EthernetDrivers\hw\Ship.cpp from Ship.cpp

15 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h `BITMAP' has not been declared
15 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h `BITMAP' has not been declared
15 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h ISO C++ forbids declaration of `tempBitmap' with no type
15 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h ISO C++ forbids declaration of `spriteToDraw' with no type
18 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h `BITMAP' has not been declared
18 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h `BITMAP' has not been declared
18 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h ISO C++ forbids declaration of `tempBitmap' with no type
18 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h ISO C++ forbids declaration of `spriteToDraw' with no type
20 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h variable or field `EraseOldSprite' declared void
20 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h expected `;' before '(' token
21 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h variable or field `DrawNewSprite' declared void
21 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h expected `;' before '(' token
24 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h `BITMAP' has not been declared
24 C:\Users\think\Desktop\EthernetDrivers\hw\Character.h ISO C++ forbids declaration of `tempBitmap' with no type
C:\Users\think\Desktop\EthernetDrivers\hw\Makefile.win [Build Error] [Ship.o] Error 1
Was This Post Helpful? 0
  • +
  • -

#34 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,469
  • Joined: 05-May 12

Re: Delete Function error

Posted 05 February 2013 - 10:12 PM

Looks like your Character class depends on BITMAP which is declared in allegro. So you need to include the allegro header files in your character.h.
Was This Post Helpful? 0
  • +
  • -

#35 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Re: Delete Function error

Posted 05 February 2013 - 10:30 PM

it now just says multiple definition of `WinMain@16'

first defined here
ld returned 1 exit status
C:\Users\think\Desktop\EthernetDrivers\hw\Makefile.win [Build Error] ["The] Error 1
Was This Post Helpful? 0
  • +
  • -

#36 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,469
  • Joined: 05-May 12

Re: Delete Function error

Posted 06 February 2013 - 05:38 AM

Can you show your updated code to show us how you fixed things?
Was This Post Helpful? 0
  • +
  • -

#37 asasas3354  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-January 13

Re: Delete Function error

Posted 06 February 2013 - 05:53 AM

i just added allegro.h at the character.h. nothing else

Character.h

#ifndef CHARACTER_H
#define CHARACTER_H
#define MAX_X 620
#define MIN_X 0
#define MAX_Y 460
#define MIN_Y 0
#include <allegro.h>

class Character{

public:
       Character();

       int GetX();
       void SetX( int newValue, BITMAP* tempBitmap, BITMAP* spriteToDraw);
       
       int GetY();
       void SetY( int newValue, BITMAP* tempBitmap, BITMAP* spriteToDraw);
       
       void EraseOldSprite( BITMAP* tempBitmap);
       void DrawNewSprite( BITMAP* tempBitmap, BITMAP* spriteToDraw);
       
       bool IsDead();
       void SetDead( bool newValue, BITMAP* tempBitmap);

protected:
        int x;
        int y;
        
        bool visible;
        bool dead;

};

#endif


Was This Post Helpful? 0
  • +
  • -

#38 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,469
  • Joined: 05-May 12

Re: Delete Function error

Posted 06 February 2013 - 06:27 AM

Congratulations! No more compile errors. Now just have link errors.

I don't use Allegro, but from what I've managed to scan on google results about using Allegro and multiple WinMain@16, the common error seems to be they have both their "Game Main.cpp" and a "main.cpp" as a result of the IDE they use. Killing the second main.cpp seemed to fix things for them.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3