So im learning SDL to get an idea on game programming for my career as a game developer.
I havent done any learning for a couple of months after getting stuck on this problem.
So im using a lazyfoo.net tutorial engine. that moves a player and has a collision with a wall.
All that works fine.
But then i tried adding my own feature, when you press space. It displays a box where you were when you pressed space and there is a collision with that box. I called the function "dropBox". But it doesnt work? i get no errors it just doesnt seem to like my code or something.
I appreciate all help, thanks so much so heres the MAIN parts of my scripts:d
//The attributes of the block
const int BLOCK_WIDTH = 30;
const int BLOCK_HEIGHT = 30;
bool load_files()
{
//Load the square image
square = load_image( "square.bmp" );
block = load_image( "block.bmp" );
//If there was a problem in loading the square
if( square == NULL )
{
return false;
}
//If everything loaded fine
return true;// makes the bool true meaning load_files() is true(completed succesfully)
}
Block::Block()
{
//Initialize the offsets
blockBox.x = 200;
blockBox.y = 300;
//Set the blocks dimentions
blockBox.w = BLOCK_WIDTH;
blockBox.h = BLOCK_HEIGHT;
bool drop = false;
}
void Block::input_drop()
{
//If a key was pressed
if( event.type == SDL_KEYDOWN )
{
//Adjust the velocity
switch( event.key.keysym.sym )
{
case SDLK_SPACE: drop == true; break;
}
}
//If a key was released
else if( event.type == SDL_KEYUP )
{
//Adjust the velocity
switch( event.key.keysym.sym )
{
case SDLK_SPACE: drop == false; break;
}
}
}
void Block::doDrop(){
oldx == 100;
oldy == 130;
//bool dropped = true;
}
void Block::showBlock(){
if (drop == true) {
apply_surface( blockBox.x, blockBox.y, block, screen );
drop == false;
}
}
int main( int argc, char* args[] )
{
//Quit flag
bool quit = false;
//The square
Square mySquare;
//The block
Block myBlock;
//The frame rate regulator
Timer fps;
//Initialize
if( init() == false )
{
return 1;
}
//Load the files
if( load_files() == false )
{
return 1;
}
//Set the right wall
wall.x = 300;
wall.y = 40;
wall.w = 40;
wall.h = 400;
//Set the top wall
wall2.x = 100;
wall2.y = 40;
wall2.w = 200;
wall2.h = 40;
//While the user hasn't quit
while( quit == false )
{
//Start the frame timer//COUNTS EACH FRAME?? SO THIS CODE RUNS ONCE PER FRAME?
fps.start();
//While there's events to handle
while( SDL_PollEvent( &event ) )
{
//Handle events for the square
mySquare.handle_input();
myBlock.input_drop();
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
//Move the square
mySquare.move();
//Do the drop stuff
myBlock.doDrop();
//Fill the screen white
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
//Show the wall
SDL_FillRect( screen, &wall, SDL_MapRGB( screen->format, 0x77, 0x77, 0x77 ) );
//Show the other wall
SDL_FillRect( screen, &wall2, SDL_MapRGB( screen->format, 0x77, 0x77, 0x77 ) );
//Show the square on the screen
mySquare.show();
//Show the dropped block on the screen
myBlock.showBlock();
//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
//Cap the frame rate
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
}
}
//Clean up
clean_up();
return 0;
}
and my drop class file
#include "SDL_image.h"
//The block
class Block
{
private:
//The collision box of the square
SDL_Rect blockBox;
int oldx, oldy;
bool drop;
public:
//Initializes the variables
Block();
//Takes key presses
void input_drop();
//Does the drop
void doDrop();
//Shows the dropped block
void showBlock();
};
So they are just snippets of code from my game that resemble the dropping of the block, the rest of my code is timers and junk, if you want the rest of the code its here: http://www.daniweb.com/software-development/cpp/threads/418054/need-help-with-simple-game
If anyone can figure this out, it will be absolutely amazing and will only fuel my ambitions to be a game developer.
Im 16 by the way and i suck at programming LOL but im alot better than when i started, i know this game script is a bit more complicated then what i should be learning at the moment but i cannot learn anything else until this is solved(im that kind of person) i need to know whats wrong or else il never learn and make the same mistake in the future.