Got the fps problem fixed, was the array checking as far as I could track down. The scrolling stays smooth, the rockets launch at any of the speeds I would want them to, I have only the sprites not deleting when they are past a certain point, i.e the X cord and or the y cord ( think off screen ) so they get "repasted" at their last x's.
#pragma once
const int ROW = 10;
const int COL = 160;
int Level[ROW][COL] =
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 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, 0 ,0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0 ,2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 ,0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 2, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 2},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
bool rocketsAlive[ROW][COL]; // are they created and not destroyed
bool rocketLaunched = true; // has the ground rocket been launched
bool waitToLaunch = false; // check to see if the wait time is up to launch
const float GrdRocketXSpeed = .1; // holds the ground rocket x speed
const int WindowW = 800, WindowH = 600, SprW = 32, SprH = 32; // screen settings .. sprite settings
const int TriggerPoint = 300; // this sets the trigger point where the rockest will launch at
const int MaxNumberOfGrdRockets = 20; // the most grd rockets available per level
float ScrollSpeed = 1.0; // set the scroll speed of the tiles to start the game
float GrdRocketYSpeed = 8.0; // holds the ground rockey y speed
int imgBigRocket = 2; // the rocket image id
int imgTrigger = 500; // trigger sprite to act as a mechanic to launch the ground rockets
int imgLaunched = 1500; // the launched image left after the rocket takes off
struct GroundRocket
{
int X; // holds the x location of the scrolling sprites
int Y; // holds the y location of the scrolling sprites
};
GroundRocket* grdRocket;
int RocketCounter; // will hold the number of rockets in the level works with MaxNumberOfGrdRockets
//////////////////////////////////////////////
// Classes starting with the GameMap Class //
//////////////////////////////////////////////
class GameMap
{
public:
GameMap(); // d'ctor
~GameMap(); // d'dtor
void LoadTiles(); // load the sprites Rockets for now
void ScrollingTiles( int Level[ROW][COL],int); // paste the tiles for the environment sprites and rockets
void SetMapSpeed( int speed ){ MapSpeed = speed;}; // sets the scrolling tile speed
int GetMapSpeed() { return MapSpeed; } // returns the current tile map speed
void SetMapLength() { MaxMapLength = 5120; } // sets the map length. can do this also with the default c'tor
int GetRocketXPos() {return GrdRocketPosX;} ; // will return the current location of the sprites - x on the scrolling field
void SetRocketXPos(int& rocketid){ GrdRocketPosX = dbSpriteX(rocketid);}; // set the rocket x pos
int GetRocketYPos() {return grdRocket->Y ;}; // will return the current location of the sprites - y on the scrolling field
void DeleteRockets(int& rocketid){ dbDeleteSprite(rocketid);}; // deletes the rockets when no longer needed..ie off screen
void LaunchRocket(int&, bool rocketLaunched); // launches the desired ground rocket and passes the isalive flag
void UpDateRockets(void); // updates the rockets and checks if still on screen
void FillRocketData(); // files the rocket data for the X and Y values
void SetTriggerPoint(){dbSprite(imgTrigger,300,10,imgTrigger);}; // sets a trigger point for sprite collisions
private:
int MapSpeed; // how fast the game map moves
int MaxMapLength; // holds the max length the map is, can stop the scrolling or reverse it with this
float GrdRocketPosX, GrdRocketPosY, GrdRocketSpeedX, GrdRocketSpeedY; // holds values for the ground rockets
float GrdRocketLastPosX, GrdRocketLastPosY, GrdRocketStartPosX, GrdRocketStartPosY; // holds values for the ground rockets
};
GameMap::GameMap(): MapSpeed(1)
{
}
GameMap::~GameMap()
{
}
void GameMap::LoadTiles()
{
if (dbFileExist("./bigrocket.bmp"))
{
dbLoadImage("bigrocket.bmp",imgBigRocket);
} else {
MessageBoxW( NULL,L"Warning ROCKET.BMP not found \n NO ROCKET SPRITE AVAILABLE.", L"Game Warning",MB_ICONWARNING | MB_DEFBUTTON2 );
}
if (dbFileExist("./trigger.bmp"))
{
dbLoadImage("trigger.bmp",imgTrigger);
} else {
MessageBoxW( NULL,L"Warning TRIGGER.BMP not found \n ROCKETS WILL NOT LAUNCH .", L"Game Warning",MB_ICONWARNING | MB_DEFBUTTON2 );
}
if (dbFileExist("./launched.bmp"))
{
dbLoadImage("launched.bmp",imgLaunched);
} else {
MessageBoxW( NULL,L"Warning LAUNCHED.BMP not found \n NO AFTER LAUNCHED IMAGE.", L"Game Warning",MB_ICONWARNING | MB_DEFBUTTON2 );
}
}
void GameMap::ScrollingTiles(int Level[ROW][COL], int )
{
char strRocketPosX [50]; //~~ debug
char strFrames [50]; //~~ debug
sprintf(strRocketPosX ,"Rocket X Position = %d ",dbSpriteX(2)); // useing just the first rocket found for now
dbText( 80,80,strRocketPosX );
sprintf(strFrames ,"FPS = %d ",dbScreenFPS()); //
dbText( 80,110,strFrames );
int spriteNumber = 2; // number of the grdrocket image/id
int x = 0, y = 0;
for (int row =0; row < ROW; row++)
{
x = 0;
for (int col = 0; col < COL; col++)
{
ScrollSpeed += GetMapSpeed() / float(WindowW * 1.5);// ~~~~~~ -= makes it go the other way
if(Level[row][col] == 2 ) // rockets on the ground
{
rocketsAlive[row][col] = true; // assigne the grd rockets sprites to "alive" if found on the map
dbSprite(spriteNumber, x - ScrollSpeed, y , Level[row][col]);
if(dbSpriteCollision(spriteNumber , imgTrigger) ) // see if it is at the launching point, check collision
{
dbHideSprite(spriteNumber);
LaunchRocket(spriteNumber,rocketLaunched);
}
dbSetSpritePriority ( spriteNumber , 3 );
spriteNumber ++;
}
x += 32;
}
y += 32;
}
}
void GameMap::LaunchRocket(int& rocketid, bool rocketLaunched)
{
dbHideSprite(rocketid);
if (dbSpriteExist(rocketid) == 1)
{
for( int row = 0; row < ROW; row++)
{
for( int col = 0; col < COL; col++)
{
if (rocketsAlive[row][col] = true && rocketLaunched == true) // is the launch flag true if so move it
{
dbSprite(rocketid,TriggerPoint, dbSpriteY(rocketid) - GrdRocketYSpeed, imgBigRocket);//Level[row][col]);
}
if(Level[row][col] == 2 && dbSpriteX(rocketid) < TriggerPoint)
{
rocketsAlive[row][col] = false;
rocketLaunched = false;
dbHideSprite(rocketid);
dbDeleteSprite(rocketid);
}
if ( dbSpriteY(rocketid) <= 5 ) // is it off the screen well close to off so i can see if this is working
{
rocketLaunched = false;
rocketsAlive[row][col] = false; // Reset the rocketLaunched flag.
dbHideSprite(rocketid);
dbDeleteSprite(rocketid);
}
rocketid++;
}
}
}
}
// main is down here
include "DarkGDK.h"
#include "map.h"
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbDisableEscapeKey ( );
dbSetWindowLayout(1, 1, 0);
dbSetDisplayMode(WindowW, WindowH, 32);
dbMaximiseWindow();
dbSetImageColorKey ( 255, 0, 255 );
GameMap gameMap;
gameMap.LoadTiles();
while ( LoopGDK ( ) )
{
if ( dbEscapeKey ( ) )
break;
gameMap.SetTriggerPoint();
gameMap.ScrollingTiles(Level,gameMap.GetMapSpeed());
//dbCLS(); // un rem to see the debug info
dbSync ( );
}
for ( int s = 1; s < 15; s++ ) dbDeleteSprite ( s ); // delete sprites
for ( int i = 1000; i < 1015; i++) dbDeleteImage ( i ); // delete images
return;
}