I have a level class and a Enemy_control class that is based off an vector that takes in Enemys as values. in my level constructor I have:
Enemy tmp( 1200 );
enemys.Add_enemy( tmp ); // this adds tmp to the vector in Enemy_control
enemys being a variable of type Enemy_control. My program crashes after these statements complaining about some destructor problem in level and enemy_control and enemy.
Level1::Level1() : Levels()
{
bgX1 = -60; // -60
bgX2 = -130; // -110
bgX3 = -240; // -
bgY=0; // is this used anymore?
// characterY=330;
max_right_movement=500;
max_left_movement=300;
// More test
jump_max = 110;
player_current_y = 340;
jump_spd = 4;
player_current_floor_y = 340;
//CONST_LEVEL1_MAIN_Y = new int( 340 );
scrolling = true;
scrolling_right = true; // this var is in levels
level_alive = true;
restart_level = false;
player_level_x = 300;
player_screen_x = 300;
level_end_point = 1035 * 10;
level_start_point = 0;
// create enemys in the level
Enemy tmp( 1200 );
enemys.Add_enemy( tmp );
// tmp.Set_enemy( 4600 );
// enemys.Add_enemy( tmp );
scoreTitle = new MyText(25);
score = new MyText(25);
high_score=0;
//onblock=0;
load( "grafx/level1/clouds.png", "grafx/level1/mountain.png", "grafx/level1/ground.png", "sounds/level1music.ogg" );
}
and enemy.h:
/* Enemy.h
* obg
* 1-13-10
*/
#ifndef ENEMY_H
#define ENEMY_H
#include "Character.h"
#include <vector>
class Enemy : public Character
{
private:
int enemy_speed,
DRAW_X,
spawn_x,
distance_to_enemy,
frame_left,
frame_right,
death_frame_x,
death_frame_y;
int bullet_fire_rate;
bool following_player;
private:
void Draw_enemy_going_right( SDL_Surface *video_surface );
void Draw_enemy_going_left( SDL_Surface *video_surface );
void Draw_death( int bgX3, int y, SDL_Surface *video_surface );
void Move_frame_left();
void Move_frame_right();
void Draw_me( int bgX3, int y, SDL_Surface *video_surface, int player_level_x, int player_screen_x );
void Fire_bullet();
public:
Enemy( int spawn_x );
~Enemy();
//void Set_enemy( int spawn_x );
void Draw( int bgX3, int y, SDL_Surface *video_surface, int player_level_x, int player_screen_x );
bool Following_player();
};
class Enemy_control
{
private:
vector< Enemy > enemy_vector; // change this to a vector
public:
Enemy_control();
~Enemy_control();
void Add_enemy( Enemy a_enemy );
void Draw( int bgX3, int y, SDL_Surface *video_surface, int player_level_x, int player_screen_x );
//void Free_list_from_memory();
};
Enemy constructor:
Enemy::Enemy( int spawn_x ) : Character() {
character_image.load( "grafx/enemy1.gif" );
health = 400;
damage = 20;
DRAW_X = spawn_x;
this->spawn_x = spawn_x;
distance_to_enemy = 230;
enemy_speed = 3;
frame_left = 0;
frame_right = 0;
death_frame_x = 390;
death_frame_y = 0;
following_player = false;
bullet_fire_rate = 0;
sprite_info.w = 63;
sprite_info.h = 74;
cout << "enemy built please call Set_enemy()\n";
}
Any ideas?