Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

whats going on here?! *now with source*

This topic is 4953 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

my game is VERY near compleation but there is one thing standing in my way from releasing a kind of half game (right now there only one lvl but you get the idea of the machanics) and its this: when i run the game it works fine but the longer i run it the more strain i notice on the CPU (the load button flickers alot) i checked the task manager and it confirmed my suspition because the comit charge was raised also i think that it might have knocked out my wireless internet yesterday so i had to reboot the computer i also get a SDL problem error box thing that asks me if i should send it or not. right now i cant post any source but ill report back latter when i can. thanks[smile] ok i just got done doing a crap load of comments on this source so tada its only one file but i dont think the other ones are nessisary for the perposes of this thread
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <vector>
#include <stdlib.h>                                     // Include this to use system()
#include <iostream>										// Include our standard header
#include <string>										// Include this to use strings
#include <fstream>
#include <libiberty.h>
#include "Ship.h"
//#include "Particals.h"
#include "SDL.h"
#include "Input.h"
#include "Boss_Dec.h"
using namespace std;
typedef WORD GAME_STATE;
const GAME_STATE NORMAL = 1,
                 BOSS = 2,
                 OPENING = 3,
                 END = 5,
                 DEAD = 0;  

typedef WORD POWER_UP; 
const POWER_UP   RED = 1,
                 BLUE = 2,
                 GREEN = 3,
                 YELLOW = 4; 
       
   
/* The screen surface */
bool SCORE_WRITTEN = false;
string Master_Enemy_Files[] = "Enemy_One.txt"; //game has Odd dependancy on this line its really weird because the file isnt used any were
string Enemy_List[]= {"Enemy_1.bmp","Enemy_2.bmp","Enemy_3.bmp"};//list of enemy image files
const char* Enemy_List_C;// a variable that will later hold a random element of enemy list
const char* Enemy_List_CX;//see line above
GAME_STATE Game_State;//an easy way to change the way the game runs
int Life_List[] = {2,4,6};//life values for the corrosponding enemy_list images
vector<int> V_Enemy_Life;//vector of life corrosponding to the VR and VI Enemy vectors
bool Sprite_Collision(SDL_Rect R_Hitter,SDL_Surface* I_Hitter,SDL_Rect R_Hittee,SDL_Surface* I_Hittee);//basic sprite collision detection
SDL_Surface *screen = NULL;//some images used for blitting
SDL_Surface *I_Ship = NULL;//easyer to have the ship image global then a member of the ship class
SDL_Surface *I_Exaust=NULL;//as of right now it isnt used
SDL_Surface *BackGround=NULL;//the image that will serve as the background for the game
SDL_Surface *I_Laser;// the image that will be used for the laser surface
SDL_Rect R_BackGround; //the rect for the background
SDL_Rect R_Enemy;//the rect that will be used as a starting point for one of the enemys
int SDL_Keys[5];//a key array for storing key presses
int Partical_timer;//currently not used for prefomace issues would be used to determin when a partical gets shot out the back of the ship
Ship* a = new Ship;//decleration of your main ship object
Input SDL_KEY_HANDLER;//decleration of the key imput instance being used in this aplication
int Laser_Count;//used so that only a cerin number of lasers can be in the air at one time
SDL_Surface *CurWeapon = NULL;//could be used later if power ups are added
const char* Weapon_List[3]={"Stn_Laser.bmp","Exaust.bmp","E_Laser.bmp"};//list of weapons right now only the 0th element is used
const char* I_Health[11] = {"health_0.bmp","health_1.bmp","health_2.bmp","health_3.bmp","health_4.bmp","health_5.bmp","health_6.bmp","health_7.bmp","health_8.bmp","health_9.bmp","health_10.bmp"};//pictures for health bar display
const char* Current_Weapon;
vector<SDL_Rect> VR_Laser;//vector in whitch all rects of lasers shot by ship is stored
vector<SDL_Surface*> VI_Laser;//vector in whitch all surfaces of lasers shot by ship is stored
vector<SDL_Rect> VR_Partical;//currently not used for preformance issues would be used to store the rects of the particals shot out of the ship
vector<SDL_Surface*> VI_Partical;//currently not used for preformance issues would be used to store the images of the particals shot out of the ship
vector<int> Life;//currently not used because particals arnt used would be used to store the life of the particals
vector<SDL_Surface*> VI_Enemys;//used to store the surfaces of the enemys
vector<SDL_Rect> VR_Enemys;//used to store the rects of the enemys
vector<SDL_Surface*> EI_Lasers;//used to store the surfaces of the lasers that the enemys will shoot out
vector<SDL_Rect> ER_Lasers;//used to store the rects of the lasers that the enemy will shoot out
vector<POWER_UP> Power_Ups;//currrently not used because i dont know if i will further this project if so i would add weapon power ups
bool X_Edge = false;//used to determin if the ship is at the max X of the screeb
bool Y_Edge = false;//used to determin if the ship is at the max Y of the screen
void TempRectBlit(SDL_Surface* src,SDL_Surface* dst,SDL_Rect Parent_Rect);// a handly moded blit function that hardware accelerates and black coulor keys my images as well

char *msg;//used for error reporting
SDL_Surface* I_Image= NULL;//used to store the image of a random Enemy[] element
int RAND_NUM=0;//number used for all the rand()% calls and is later set to the ticks of the game
SDL_Rect RX_Enemy;//rect used for initial enemy placement
SDL_Surface* IX_Image = NULL;//image used for initial enemy
long int Enemy_Timer;//used so that initail enemys wont come all at the same time
SDL_Rect R2_Enemy;//rect used for imitial enemy position setting
int ET = 0;//used so that the enemy move only ever other frame
SDL_Rect RX_Laser;//used for initial enemy placement
int AI =10;//used for random shooting of enemys later
SDL_Surface* I_LaserX= NULL;//image used to store the enemy laser surfaces
int BOSS_NUM = 0;//used to determin what bosses[] element that were working with
int MAX_E = 3;//maximum number of enemys that will be shown on the screen
SDL_Rect Text_1;//used to display the you lost or you won messages at the end
SDL_Surface* I_Text_1;//see line above
SDL_Rect Text_2;//used to set position of health bar
SDL_Surface* I_Text_2;//what the health bar image will be... a surface with the I_Health[a->health]
int Score = 0;//used to store you score
ofstream fout;//used for reading high score date and comparing it 
ifstream fin;//used for writing your score data into the high score .txt file
string High_Score = "";//used to by pass the rest of lines of file so that i can get to the part were the high score is
int HIGH_SCORE;// the int that will store the score read through fout 
static void draw();//used for most of the code and all the drawing (DUH)
/* This function draws to the screen; replace this with your own code! */

  

int
main (int argc,char *argv[])
{
    fin.open("High_Scores.txt");//opens the file
    getline(fin,High_Score);//bypas 1st
    getline(fin,High_Score);//2nd
    getline(fin,High_Score);//3rd
    getline(fin,High_Score); //4th
    getline(fin,High_Score);//and 5th lines
    fin >> HIGH_SCORE;//read the 6th line into this int
    fin.close();//close the file as no further reading is nessisary
    fout.open("High_Scores.txt");//open the file for writing
    Intialize();  //calls all the initatialization code for the bosses
    
    R_BackGround.x=0;//backgroud will be set at 0,0
    R_BackGround.y=0;
    R_Enemy.x = 700;//all enemys will start at 700 x and a rand Y the first enemy willll start at 0 y 
    R_Enemy.y = 0;
    RX_Enemy.x = 700;
    RX_Enemy.y = 400;//2nd enemy starts at 400 y to space things out
    R2_Enemy.x = 700;
    R2_Enemy.y = 250; //3rd enemy starts at 250
    Text_1.x = 250;//when the text is show it will be at 250,250
    Text_1.y = 200;
    Text_2.x = 0;//the health bar will be in the top corner
    Text_2.y = 0;
    
  
    
   
    int done;//int used as a switch to close down

    /* Initialize SDL */
    if (SDL_Init (SDL_INIT_VIDEO) < 0)
    {
        asprintf (&msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());
        MessageBox (0, msg, "Error", MB_ICONHAND);
       
        exit (1);
    }
    
    atexit (SDL_Quit);    

    /* Set 640x480 16-bits video mode */
    screen = SDL_SetVideoMode (640, 480, 16, SDL_FULLSCREEN | SDL_DOUBLEBUF);
    if (screen == NULL)
    {
       asprintf (&msg, "Couldn't set 640x480x16 video mode: %s\n",
       SDL_GetError ());
        MessageBox (0, msg, "Error", MB_ICONHAND);
        free (msg);
        exit (2);
    }
    SDL_WM_SetCaption ("Ship", NULL);//sets name of window
    I_Ship = SDL_LoadBMP("Ship.bmp");//initializes I_Ship to the ship bmp file
    I_Exaust = SDL_LoadBMP("Exaust.bmp");//currently not used because particals are not used
    BackGround = SDL_LoadBMP("background.bmp");//initializes the background image
    Weapon_List[0] = "Stn_Laser.bmp";//the elements of
    Weapon_List[1] = "Exaust.bmp";//the weapon list only the 0th is used
    Weapon_List[2] = "E_Laser.bmp";//
    I_Laser = SDL_LoadBMP(Weapon_List[a->GetWeaponBMP()]);//returns a weapon number that the ship is using default is 0 and currently is never modifyed
    SDL_SetColorKey(I_Ship, SDL_SRCCOLORKEY | SDL_PREALLOC, SDL_MapRGB(I_Ship->format, 0, 0,0) ); //format the ship image
       

    done = 0;//if it were 1 we would never get to see the app
    while (!done)
    {
        if(I_Text_2 != SDL_LoadBMP(I_Health[a->health]))//update the image if it isnt already the right one
        {
        I_Text_2 = SDL_LoadBMP(I_Health[a->health]);
        };    
        if(Boss_Timer == 0)//set the boss game state requirements
        {
            Game_State = BOSS;
        }
        if(Boss_Timer > 0 && a->health > 0)//set the dead gamestate requirements
        {
            Game_State = NORMAL;
        }
        if(a->health <= 0)//sets the normal gamestate requirements
        {
            Game_State = DEAD;
        };  
        if(BOSS_NUM > 0)//sets the end requrirements currently the game ends after the first boss
        {
            Game_State = END;
            if(a->health >= 1)//as long as your still alive
            {
            if(I_Text_1 != SDL_LoadBMP("You_Won.bmp"))//set the text image to a you won image if it isnt already
            {
           I_Text_1 = SDL_LoadBMP("You_Won.bmp");
            };    
              if(SCORE_WRITTEN != true)// dont right more then once
                      {
                              fout<<"You Score is\n\n" << Score << "\n";
                               fout<<"The High Score is\n\n" << HIGH_SCORE << "\n";
                              SCORE_WRITTEN = true;
                      };    
            TempRectBlit(I_Text_1,screen,Text_1);// blit the text message on the screen
            };    
        };             
        
    srand(RAND_NUM);//seed the rand num generator
    if(Enemy_Timer == 800)//space out the enemy apperances
    {
    Enemy_List_C =Enemy_List[rand()%3].c_str();//load a random enemy list element
    I_Image = SDL_LoadBMP(Enemy_List_C);//initailize a surface to it
    VI_Enemys.push_back(I_Image);//store it in a vector
    VR_Enemys.push_back(R_Enemy);//store the initail enemy rect in a vecotr
    V_Enemy_Life.push_back(1);//make the life of the first enemy one
    };
    if(Enemy_Timer == 100)//repeat with diffrent rects
    {
    Enemy_List_C =Enemy_List[rand()%3].c_str();
    I_Image = SDL_LoadBMP(Enemy_List_C);
    VI_Enemys.push_back(I_Image);
    VR_Enemys.push_back(RX_Enemy);
    V_Enemy_Life.push_back(1);
    };  
      if(Enemy_Timer == 400)//repeat with diffrent rects
    {
    Enemy_List_C =Enemy_List[rand()%3].c_str();
    I_Image = SDL_LoadBMP(Enemy_List_C);
    VI_Enemys.push_back(I_Image);
    VR_Enemys.push_back(R2_Enemy);
    V_Enemy_Life.push_back(1);
    };  
        Uint8 *keys = SDL_GetKeyState(SDL_Keys);
        SDL_Event event;
           
        
  
    /* Initialise SDL and video modes and all that */
    /* Main game loop */
    /* Check for events */
    while( SDL_PollEvent( &event ) ){
          SDL_KEY_HANDLER.Update();//update the key handler


          if(SDL_KEY_HANDLER.Key_Down(SDLK_ESCAPE))//if the escape key is pressed get out
         {

                done = 1;
         }; 
                         
        switch( event.type ){
            /* Look for a keypress */
            case(SDL_KEYDOWN):// use our own key press methods
                /* Check the SDLKey values and move change the coords */
                break;
            case SDL_QUIT:
                fout.close();//do a little clean up
             VR_Partical.clear();
             VI_Partical.clear();
             VI_Laser.clear();
             VR_Laser.clear();
             VR_Enemys.clear();
             VI_Enemys.clear();
             ER_Lasers.clear();
             EI_Lasers.clear();
             delete I_Ship;
             delete IX_Image;
             delete BackGround;
             delete screen;

             delete a;
                done = 1;
                break;
            default:
                break;
            }
        } /* Draw to screen */
        draw ();
    }
  
    return 0;
}
static void
draw ()
{
    if(Score > HIGH_SCORE)//make the high score the score if its higher
    {
        HIGH_SCORE = Score;
    };    
    
      if(I_Laser != SDL_LoadBMP(Weapon_List[a->GetWeaponBMP()]))//if the image isnt already make it the weapon that the image of the weapon the ship is using
      {
       I_Laser = SDL_LoadBMP(Weapon_List[a->GetWeaponBMP()]);
      };    
     
       SDL_BlitSurface(BackGround,NULL,screen,&R_BackGround);//draw the background   
    if(Game_State != DEAD)// if were not dead
     {
         if(SDL_KEY_HANDLER.Key_Down(SDLK_RIGHT) > 0|| SDL_KEY_HANDLER.Key_Still_Down(SDLK_RIGHT) > 0)//just some moving if the arrow keys are pressed
         {
             a->R_Ship.x+=1;
         }; 
         
           if(SDL_KEY_HANDLER.Key_Down(SDLK_LEFT) > 0|| SDL_KEY_HANDLER.Key_Still_Down(SDLK_LEFT) > 0)
         {
             a->R_Ship.x-=1;
         };     
           if(SDL_KEY_HANDLER.Key_Down(SDLK_UP) > 0|| SDL_KEY_HANDLER.Key_Still_Down(SDLK_UP) > 0)
         {
             a->R_Ship.y-=1;
         };  
           if(SDL_KEY_HANDLER.Key_Down(SDLK_DOWN) > 0|| SDL_KEY_HANDLER.Key_Still_Down(SDLK_DOWN) > 0)
         {
             a->R_Ship.y+=1;
         }; 
          if(SDL_KEY_HANDLER.Key_Down(SDLK_SPACE) > 0|| SDL_KEY_HANDLER.Key_Still_Down(SDLK_SPACE) > 0 )//hhoots a laser when space is pressed
         {
             if( Laser_Count == 0)//if its not too soon
             {
             a->Shoot(&VR_Laser,&VI_Laser,I_Laser,false,&Life);//use the shoot method to shoot our lasers
             Laser_Count = 100;// we gota wait until we fire again
             };     
         };          
         
     };       
          if(a->R_Ship.x > 500)//dont exceede your boudries
          {
              X_Edge = true;
          }
          else X_Edge = false;
          if(a->R_Ship.x > 490)
          {
              a->R_Ship.x = 490;
          };        
          if(a->R_Ship.y >480)
          {
              Y_Edge = true;
          }
          else Y_Edge = false;
          if(a->R_Ship.y >380)
          {
              a->R_Ship.y = 380;
          }; 
              //now for the meat and potatos of the game
        for(int i=0; i < VI_Laser.size(); i++)//display all lasers and if its way off the screen then delete it
         {
             TempRectBlit(VI_Laser,screen,VR_Laser);
             VR_Laser.x+=2;//make it go 2 pixles a cycle
             if(VR_Laser.x > 800)
             {
                VI_Laser.erase(VI_Laser.begin());//delete both the images and the rects
                VR_Laser.erase(VR_Laser.begin());
             }; 
                    
                 
         };      
       if(Game_State == NORMAL)//if we are in a normal gamestate
       {  
       /*//none of this is currently used because of performance issues
        if(Partical_timer == 2) 
         {
         a->Shoot(&VR_Partical,&VI_Partical,I_Exaust,true,&Life); 
         };                   
        for(int i=0; i < VR_Partical.size(); i++)
         {  
             TempRectBlit(VI_Partical,screen,VR_Partical);
             VR_Partical.x-=2;
             Life-=1;
             if(VR_Partical.front().x  < a->R_Ship.x-70 )
             {
                VI_Partical.erase(VI_Partical.begin());
                VR_Partical.erase(VR_Partical.begin());
              
             };
             if(Life == 0)
             {
                VI_Partical.erase(VI_Partical.begin());
                VR_Partical.erase(VR_Partical.begin());
                
             };
             if(VR_Partical.size() > 100)
             {
                 VI_Partical.erase(VI_Partical.begin());
                 VR_Partical.erase(VR_Partical.begin());              
             };
         }; */
     };      
         for(int j=0; j < VI_Enemys.size(); j++)//show the enemys 
          {
           TempRectBlit(VI_Enemys[j],screen,VR_Enemys[j]);//draw enemys
           
             if(AI == rand()%1000)//if the number is 10 then shoot
               {
               if(I_LaserX != SDL_LoadBMP(Weapon_List[2]))//right now the enemys only use the 2nd element
               {
                   I_LaserX = SDL_LoadBMP(Weapon_List[2]);
               };    
                   EI_Lasers.push_back(I_LaserX);//if we shoot put it in the EI_Laser vector and let them take care of it
                   RX_Laser = VR_Enemys[j];// the lasers gatta start were the enemy is
                   ER_Lasers.push_back(RX_Laser);
               };    
           if(VR_Enemys[j].x < (0-VI_Enemys[j]->w))//if its off the screen erase it
           {
              VI_Enemys.erase(VI_Enemys.begin()+j);                                   
              VR_Enemys.erase(VR_Enemys.begin()+j);
              V_Enemy_Life.erase(V_Enemy_Life.begin()+j);
           };
           if(VI_Enemys.size() < MAX_E)// if theres not enough enemys out there draw more or if its empty
           {    
              
               int C = rand()%3;//make a random number
               Enemy_List_C = Enemy_List[C].c_str();//create an enemy
               V_Enemy_Life.push_back(Life_List[C]);
               if(I_Image != SDL_LoadBMP(Enemy_List_C))//dont reassign if you dont have to
               {
               I_Image = SDL_LoadBMP(Enemy_List_C);
               };    
               VI_Enemys.push_back(I_Image);
               R_Enemy.y = rand()%400;//set the y to a random value
               VR_Enemys.push_back(R_Enemy);
           };    
               
           if(ET == 5)//move the enemys every 5th frame
             {
             VR_Enemys[j].x-=1;
             };     
           };     
         for(int i = 0; i < ER_Lasers.size(); i++)//
          {
              ER_Lasers.x-=2;//move those lasers 2 pixles every frame
              TempRectBlit(EI_Lasers,screen,ER_Lasers);//draw 'em
              if(ER_Lasers.x < (0-EI_Lasers->w))//if there of the screen erase 'em
              {
                  EI_Lasers.erase(EI_Lasers.begin());
                  ER_Lasers.erase(ER_Lasers.begin());                    
              };    
          };
        for(int i = 0; i < VR_Laser.size(); i++)//now for the ships lasers collision detection
         {
             for(int j = 0; j < VR_Enemys.size(); j++)
             {
                 
                 if(Sprite_Collision(VR_Laser,VI_Laser,VR_Enemys[j],VI_Enemys[j]) == true)//check each laser against ever enemy and if the collide its true
                 {
                     VI_Laser.erase(VI_Laser.begin()+i);//erase the laser
                     VR_Laser.erase(VR_Laser.begin()+i);
                     V_Enemy_Life[j]--;//lower the enemy life
                     if(V_Enemy_Life[j] == 0)//if its 0 you get points and the enemy is erased
                     {
                         Score+=5;
                         V_Enemy_Life.erase(V_Enemy_Life.begin()+j);
                          VI_Enemys.erase(VI_Enemys.begin()+j); 
                          VR_Enemys.erase(VR_Enemys.begin()+j);
                     };    
                      
                 };
             };
         };
         TempRectBlit(I_Text_2,screen,Text_2);//draw the health bar
      if(Game_State != DEAD)//dont do the collision if your dead
       {   
        for(int m = 0; m < ER_Lasers.size(); m++)
        {
                if(Sprite_Collision(ER_Lasers[m],EI_Lasers[m],a->R_Ship,I_Ship) == true)// cheack evey enemy laser against the ship rect if it hit return true                 
                {
                 ER_Lasers.erase(ER_Lasers.begin()+m);//delete the laser
                 EI_Lasers.erase(EI_Lasers.begin()+m);
                 a->health--;//subtract the health            
               };       
         
        }; 
       }  
        if(Game_State == DEAD)//if you ARE dead
                 {
                     if(I_Text_1 != SDL_LoadBMP("You_Died.bmp"))//assign the dead message to the text surface only if you havnt already
                     {
                      I_Text_1 = SDL_LoadBMP("You_Died.bmp");
                     };    
                      TempRectBlit(I_Text_1,screen,Text_1);//draw the text
                      if(SCORE_WRITTEN != true)//dont write the score more then once
                      {
                              fout<<"You Score is\n\n" << Score << "\n";
                              SCORE_WRITTEN = true;
                              fout<<"The High Score is\n\n" << HIGH_SCORE << "\n";
                      };
                      if(I_Ship != SDL_LoadBMP("Ship_Dead.bmp"))//if the ship image isnt the ship dead bmp asssign it now
                      {
                              
                       I_Ship = SDL_LoadBMP("Ship_Dead.bmp");
                      };    
                      
                        TempRectBlit(I_Ship,screen,a->R_Ship); // draw the image
                }    
                                
         SDL_BlitSurface(I_Ship,NULL,screen,&a->R_Ship);   
     
                  
                   
      
   /*  if(Partical_timer >= -1)//not used because particals arnt used
    {
        Partical_timer = 0;
    } 
    else Partical_timer++;   */
    if(Laser_Count > 0)// if were waiting to shoot
    {
    Laser_Count--; //our wait is getting shorter
    };   
    if(Game_State == BOSS)//if were in a boss fight
    {
           if(Boss_Weapons[BOSS_NUM].health != 0)//if the boss isnt dead
           {
               
               if(rand()%500 == 2 && Boss_Weapons[BOSS_NUM].I_Gun1 != NULL)//randomly fire the bosses guns
               {
                   ER_Lasers.push_back(Boss_Weapons[BOSS_NUM].Gun1);
                   EI_Lasers.push_back(Boss_Weapons[BOSS_NUM].I_Gun1);
               };
               if(rand()%500 == 2 && Boss_Weapons[BOSS_NUM].I_Gun2 != NULL)
               {
                   ER_Lasers.push_back(Boss_Weapons[BOSS_NUM].Gun2);
                   EI_Lasers.push_back(Boss_Weapons[BOSS_NUM].I_Gun2);
               };
               if(rand()%3000 == 10 && Boss_Weapons[BOSS_NUM].I_Gun3 != NULL)
               {
                   ER_Lasers.push_back(Boss_Weapons[BOSS_NUM].Gun3);
                   EI_Lasers.push_back(Boss_Weapons[BOSS_NUM].I_Gun3);
               };
               TempRectBlit(Bosses[BOSS_NUM],screen,Boss_Weapons[BOSS_NUM].R_Boss);      //draw the boss
               for(int i = 0; i < VR_Laser.size(); i++)//do collision with the boss
                 {     
                         if(Sprite_Collision(VR_Laser,VI_Laser,Boss_Weapons[BOSS_NUM].R_Boss,Bosses[BOSS_NUM]) == true)
                         {
                             VI_Laser.erase(VI_Laser.begin()+i);
                             VR_Laser.erase(VR_Laser.begin()+i);
                            Boss_Weapons[BOSS_NUM].health--;
                             if( Boss_Weapons[BOSS_NUM].health <= 0)//if its dead
                             {
                            
                                 BOSS_NUM++;// that triggers that game end
                             };
                              if(Game_State == DEAD)//draw the messages (you should rember them from above
                                 {
                                                if(I_Text_1 != SDL_LoadBMP("You_Died.bmp"))
                                                     {
                                                      I_Text_1 = SDL_LoadBMP("You_Died.bmp");
                                                     };    
                                                      TempRectBlit(I_Text_1,screen,Text_1);
                                                      if(SCORE_WRITTEN != true)
                                                      {
                                                              fout<<"You Score is\n\n" << Score << "\n";
                                                              SCORE_WRITTEN = true;
                                                              fout<<"The High Score is\n\n" << HIGH_SCORE << "\n";
                                                      };
                                                      if(I_Ship != SDL_LoadBMP("Ship_Dead.bmp"))
                                                      {
                                                              
                                                       I_Ship = SDL_LoadBMP("Ship_Dead.bmp");
                                                      };
                                                      TempRectBlit(I_Ship,screen,a->R_Ship);    
                      
                                 }    
                         };
                 };
                  for(int m = 0; m < ER_Lasers.size(); m++)//do collision detection with the bosses lasers against the ship
                    {
                       if(Sprite_Collision(ER_Lasers[m],EI_Lasers[m],a->R_Ship,I_Ship) == true)                 
                         {
                             ER_Lasers.erase(ER_Lasers.begin()+m);
                             EI_Lasers.erase(EI_Lasers.begin()+m);
                             a->health--;            
                         };       
         
                    }; 
         };                
        
    };       
                    
    if(Game_State != BOSS)//if were not in a boss battle
    {
    Boss_Timer--;// were getting closer to one    
    };        
        
     
      
     
    RAND_NUM = SDL_GetTicks();// make the rand num = the time 
    Enemy_Timer++;//++ the enemy timer
    ET++;//++ the number that determins if the enemy moves or not
    if(ET > 5)//cap the variable at 5
    {
        ET = 0;
    };    
                                       
    SDL_Flip (screen);//finally flip the buffer
    /* Don't run too fast */
    SDL_Delay (1);
    
};
bool Sprite_Collision(SDL_Rect R_Hitter,SDL_Surface* I_Hitter,SDL_Rect R_Hittee,SDL_Surface* I_Hittee)
{     
    int left1, left2;
    int right1, right2;
    int top1, top2;
    int bottom1, bottom2;

    left1 = R_Hitter.x;
    left2 = R_Hittee.x;
      if( I_Hitter != NULL && I_Hittee != NULL)
    {
    right1 = R_Hitter.x + I_Hitter->w;
    right2 = R_Hittee.x + I_Hittee->w;
    top1 = R_Hitter.y;
    top2 = R_Hittee.y;
    bottom1 = R_Hitter.y + I_Hitter->h;
    bottom2 = R_Hittee.y + I_Hittee->h;
    }    
   
    if (bottom1 < top2) return false;
    if (top1 > bottom2) return false;
    if (right1 < left2) return false;
    if (left1 > right2) return false;

    else return true;

};
void TempRectBlit(SDL_Surface* src,SDL_Surface* dst,SDL_Rect Parent_Rect)
{
    SDL_Rect TempRect = Parent_Rect;
     SDL_SetColorKey(src, SDL_SRCCOLORKEY | SDL_HWACCEL | SDL_DOUBLEBUF  , SDL_MapRGB(src->format, 0, 0,0));
    SDL_BlitSurface(src,NULL,dst,&TempRect);  
};



ooo thought id add this too is just some initailazation and its uncommented but you never know
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <vector>
#include <stdlib.h>                                     // Include this to use system()
#include <iostream>										// Include our standard header
#include <string>										// Include this to use strings
#include <fstream>
#include <libiberty.h>
#include "SDL.h"
struct Boss_Guns
{
    SDL_Rect R_Boss;    
    SDL_Rect Gun1;
    SDL_Surface* I_Gun1;
    SDL_Rect Gun2;
    SDL_Surface* I_Gun2;
    SDL_Rect Gun3;
    SDL_Surface* I_Gun3;
    SDL_Rect Gun4;
    SDL_Surface* I_Gun4;
    int health;
}; 
extern double Boss_Timer = 10000 ;
SDL_Surface* Bosses[1];
Boss_Guns Boss_Weapons[1];

bool Boss;
bool Emptyed;
void Intialize();
void Intialize()
{
Boss_Weapons[0].R_Boss.x = 550;
Boss_Weapons[0].R_Boss.y = 50;
Bosses[0] = SDL_LoadBMP("Boss_1.bmp");
Boss_Weapons[0].Gun1.x = 550;
Boss_Weapons[0].Gun1.y = 90;
Boss_Weapons[0].I_Gun1 = SDL_LoadBMP("Boss-1-1.bmp");
Boss_Weapons[0].Gun2.x = 550;
Boss_Weapons[0].Gun2.y = 350 ;
Boss_Weapons[0].I_Gun2 = SDL_LoadBMP("Boss-1-2.bmp");
Boss_Weapons[0].Gun3.x = 550;
Boss_Weapons[0].Gun3.y = 120; 
Boss_Weapons[0].I_Gun3 = SDL_LoadBMP("Boss-1-3.bmp");
Boss_Weapons[0].health = 30;
Boss_Weapons[1].R_Boss.x = 530;
Boss_Weapons[1].R_Boss.y = 50;
Bosses[1] = SDL_LoadBMP("Boss_2.bmp");
Boss_Weapons[1].I_Gun1 = SDL_LoadBMP("Boss-2-1.bmp");
Boss_Weapons[1].Gun1.x = 520;
Boss_Weapons[1].Gun1.y = 100;
Boss_Weapons[1].I_Gun2 = SDL_LoadBMP("Boss-2-2.bmp");
Boss_Weapons[1].Gun2.x = 520;
Boss_Weapons[1].Gun2.y = 250;
Boss_Weapons[1].health = 20;
};


IM OPEN TO COUSTRUCTIVE CRITSISM NO FLAMERS [Edited by - raptorstrike on November 27, 2004 2:05:12 PM]

Share this post


Link to post
Share on other sites
Advertisement
0.o.

Nobody is going to read through that.

If it is using 100% of your system resources, then you game is doing it's job.
I'm thinking if you are progressively using more and more system resources, you have a bad pointer somewhere. You are probably reusing a pointer w/o freeing it.

Share this post


Link to post
Share on other sites
lol good point i wouldnt read through that either.

any way i almost positive its a memory leak that happens every cycle so that it gets worse and worse as time gose on.

i just dont know were. i run the debugger it says i have a segmentation fault but it wont tell me were it is :(

thanks for the reply [smile]

Share this post


Link to post
Share on other sites
let me guess which compiler.... dev-c++, right?


SDL_SetColorKey(src, SDL_SRCCOLORKEY | SDL_HWACCEL | SDL_DOUBLEBUF , SDL_MapRGB(src->format, 0, 0,0));


What the hell are you doing to SDL_SetColorKey ?

Share this post


Link to post
Share on other sites
Quote:
Original post by PnP Bios
let me guess which compiler.... dev-c++, right?


SDL_SetColorKey(src, SDL_SRCCOLORKEY | SDL_HWACCEL | SDL_DOUBLEBUF , SDL_MapRGB(src->format, 0, 0,0));


What the hell are you doing to SDL_SetColorKey ?
he almost seems to be treating it as SDL_SetVideoMode... the second argument only supports SDL_RLEACCEL and SDL_SRCCOLORKEY constants, that might be part of the problem.

btw, you don't need to include windows.h, from what I can tell. If you don't include it, it will probably be able to compile, with out any code changes, on many other OSes, including macosx and linux

Share this post


Link to post
Share on other sites
umm yeah this is my first SDL game and i wasnt sure how to use those flags lol so should i have that line in there at all?
i want it to still do the coulor key blitting and ive moved the other 2 to the set video mode()

it still gives me the same segmentation fault error and still shows nothing

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!