# Sub's coding pool party

**URL:** <https://forum.esforces.com/t/subs-coding-pool-party/77242>\
**Category:** Artwork\
**Tags:** general-artwork\
**Created:** [February 15, 2012, 7:30pm UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242 "2012-02-15T19:30:59Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Shaladanra](https://forum.esforces.com/user_avatar/forum.esforces.com/shaladanra/32/1580_2.png) [@Shaladanra](https://forum.esforces.com/u/Shaladanra)\
**Post date:** [February 17, 2012, 12:14pm UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/21 "2012-02-17T12:14:13Z")

</div>

This game is fun 😛 Especially when you get 1 hitted by last boos xD  
GJ Sub ^^

---

<div class="post-metadata">

**Author:** ![sg2](https://forum.esforces.com/user_avatar/forum.esforces.com/sg2/32/2083_2.png) [@sg2](https://forum.esforces.com/u/sg2)\
**Post date:** [February 17, 2012, 1:53pm UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/22 "2012-02-17T13:53:26Z")

</div>

I like the graphics.

Just kidding, good work.

---

<div class="post-metadata">

**Author:** ![DiebytheSword](https://forum.esforces.com/user_avatar/forum.esforces.com/diebythesword/32/64_2.png) [@DiebytheSword](https://forum.esforces.com/u/DiebytheSword)\
**Post date:** [February 20, 2012, 11:40pm UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/23 "2012-02-20T23:40:02Z")

</div>

> [@Intentionator](#):
>
> Good. You look smarter than I thought sub.

That will be the last of that kind of post I’ll allow in here. Constructive criticisms or comments, or find peace in silence.

---

<div class="post-metadata">

**Author:** ![sub](https://forum.esforces.com/user_avatar/forum.esforces.com/sub/32/573_2.png) [@sub](https://forum.esforces.com/u/sub)\
**Post date:** [February 21, 2012, 12:30am UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/24 "2012-02-21T00:30:30Z")

</div>

I changed the link in the original post. I added a tic tac toe game that I made a few days ago, a clone of the game drug wars that I made a while ago, and I fixed a few things in the original program I made. I actually think the drug wars one is kind of cool.

[https://rapidshare.com/files/3489981081/SubTicTacToe.7z](https://rapidshare.com/files/3489981081/SubTicTacToe.7z)

I had no idea how to make tic tac toe when I started it, so I’m pretty happy with that. The ‘ai’ chooses its moves randomly, but it’ll go for a win if it gets two O’s in a row, and it’ll block you most of the time if you’re about to win. It’ll also choose winning the game over blocking your win. I was going to implement a difficulty setting in it, but when I tried, the AI ended up taking all of it’s turns at once, and I kind of gave up on fixing that. Also, when the game ends, it’ll ask you if you want to play again. If you select no, the program is supposed to end, but for some reason it doesn’t. I have to figure out how to do that.

But right now I’m trying to make a console version of pong. Eventually, when I learn the win32api a bit and I can make windows programs instead of console ones, I’m going to remake the drug war game.

---

<div class="post-metadata">

**Author:** ![sub](https://forum.esforces.com/user_avatar/forum.esforces.com/sub/32/573_2.png) [@sub](https://forum.esforces.com/u/sub)\
**Post date:** [March 25, 2012, 3:21am UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/25 "2012-03-25T03:21:41Z")

</div>

So… Pong. I wanted to finish it tonight, but that wasn’t meant to be. This is what I have so far, though.

[https://rapidshare.com/#!download|623p3|601674714|SubPong.7z|259](https://rapidshare.com/#!download%7C623p3%7C601674714%7CSubPong.7z%7C259)

Arrow keys move left and right, press the up arrow key to start the initial shot. I still need to do a bunch of stuff, off the top of my head I want to:

- Add text to the screen saying “Press the left and right arrow keys to move. Press the up arrow key to begin.” Text would disappear when up is pressed
- Make it so that the ball follows along with the platform before you press up
- Make the top row of blocks functional. Right now only the bottom row works
- Make it so that when the ball lands on the bottom of the screen, the ball and your platform reset back to the initial position
- Add lives. If you lose the ball 3 times, game over
- Make it so that when the ball hits the platform, it’ll change direction depending on where it’s hit. If the platform hits the ball on the right, for example, the ball would move to the right instead of continuing its direction
- The ball/platform collision could be better

I started this on Friday at around 3 o’clock and I’ve been working on it all weekend. It’s been a frustrating weekend, but I’m almost done with it. I’m using SDL for the graphics and keyboard handling and all that good stuff. I used [this site](http://lazyfoo.net/SDL_tutorials/index.php)to wrap my mind around how SDL works. I also used the dot image from that site, though I don’t think he’d mind and it would have been trivial to make. I’m still extremely new at this, and this is the first non-console program I’ve attempted to make, so if anyone tries it out, keep that in mind.

---

<div class="post-metadata">

**Author:** ![sg2](https://forum.esforces.com/user_avatar/forum.esforces.com/sg2/32/2083_2.png) [@sg2](https://forum.esforces.com/u/sg2)\
**Post date:** [March 25, 2012, 6:22am UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/26 "2012-03-25T06:22:33Z")

</div>

Oh man, I have waited many decades for this!!!  
_click_

… What’s this…

WAIT SOME MORE?

---

<div class="post-metadata">

**Author:** ![Deverz](https://forum.esforces.com/user_avatar/forum.esforces.com/deverz/32/6_2.png) [@Deverz](https://forum.esforces.com/u/Deverz)\
**Post date:** [March 25, 2012, 8:51am UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/27 "2012-03-25T08:51:53Z")

</div>

Paddle moves too slow ☹

also

PONG  
[http://insomnia.ac/reviews/artistic\_art/pong/screenshot.jpg](http://insomnia.ac/reviews/artistic_art/pong/screenshot.jpg)

BREAK OUT  
[http://i1-scripts.softpedia-static.com/screenshots/Breakout-18265.png](http://i1-scripts.softpedia-static.com/screenshots/Breakout-18265.png)

---

<div class="post-metadata">

**Author:** ![dutchmeat](https://forum.esforces.com/user_avatar/forum.esforces.com/dutchmeat/32/1469_2.png) [@dutchmeat](https://forum.esforces.com/u/dutchmeat)\
**Post date:** [March 25, 2012, 2:04pm UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/28 "2012-03-25T14:04:44Z")

</div>

If you post your sourcecodes we can take a look at it.  
Making a picture move on a screen is one thing, making efficient code is another 🙂

---

<div class="post-metadata">

**Author:** ![sub](https://forum.esforces.com/user_avatar/forum.esforces.com/sub/32/573_2.png) [@sub](https://forum.esforces.com/u/sub)\
**Post date:** [March 25, 2012, 6:14pm UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/29 "2012-03-25T18:14:54Z")

</div>

Sounds good, I’ll post it when it’s done. I’m honestly just happy it works though.

---

<div class="post-metadata">

**Author:** ![sub](https://forum.esforces.com/user_avatar/forum.esforces.com/sub/32/573_2.png) [@sub](https://forum.esforces.com/u/sub)\
**Post date:** [March 30, 2012, 4:02am UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/30 "2012-03-30T04:02:58Z")

</div>

A bit more completed version of Breakout

[https://rapidshare.com/#!download|551p6|818537270|SubPong.7z|519](https://rapidshare.com/#!download%7C551p6%7C818537270%7CSubPong.7z%7C519)

I still want to add levels to it, add powerups to it (ie: A random number of blocks would spawn red. If you break a red block, a powerup drops. If you catch the powerup, you can obviously use it. A powerup might be something like 3 balls spawning, or the ability to shoot lazers from your platform.) Also want to make it so that the ball will bounce if it hits the top of a block instead of just going through them.

Anyway, this is half of the code, the other half will be in the next post. It’s too many characters for one post apparently. Please keep in mind that I have abolustely, positively no idea what I’m doing. I really can’t stress that enough. If anyone has anything constructive to tell me though, I’ll definitely try to learn from it / fix it in this code if it’s within my ability to comprehend how to fix it.

And yet again I’m going to mention that I based this on the tutorial from [this site](http://lazyfoo.net/SDL_tutorials/index.php). I also took the ball image and the rather horrible font from that site as well.

On a final note, this entire thing was written in one .cpp file. I realize that’s horrible, but I for the life of me could not figure out how to get SDL working spread across multiple files. I have no problem getting something that’s not using SDL working across multiple files, but it spits out 5 billion errors for me when I tried with SDL. I gave up on trying to fix that, although I’m sure I’m just doing something stupid.

[CODE]#include “SDL.h”  
#include “SDL\_image.h”  
#include “SDL\_ttf.h”  
#include

const int SCREEN\_WIDTH = 640;  
const int SCREEN\_HEIGHT = 480;  
const int SCREEN\_BPP = 32;

const int DOT\_WIDTH = 20;  
const int DOT\_HEIGHT = 20;

const int BLOCK\_WIDTH = 50;  
const int BLOCK\_HEIGHT = 10;

const int PLATFORM\_WIDTH = 100;  
const int PLATFORM\_HEIGHT = 15;  
const int PLATFORM\_VEL = 200;

SDL\_Event event;

SDL\_Surface \*dot = NULL;  
SDL\_Surface \*platform = NULL;  
SDL\_Surface \*block = NULL;  
SDL\_Surface \*screen = NULL;  
SDL\_Surface \*message = NULL;  
SDL\_Surface \*message2 = NULL;  
SDL\_Surface \*LivesMessage = NULL;  
TTF\_Font \*font = NULL;

SDL\_Color textColor = { 0, 0, 0 };

SDL\_Surface _load\_image( std::string filename )  
{  
//The image that’s loaded  
SDL\_Surface_ loadedImage = NULL;

```
//The optimized surface that will be used
SDL_Surface* optimizedImage = NULL;

//Load the image
loadedImage = IMG_Load( filename.c_str() );

//If the image loaded
if( loadedImage != NULL )
{
    //Create an optimized surface
    optimizedImage = SDL_DisplayFormat( loadedImage );

    //Free the old surface
    SDL_FreeSurface( loadedImage );

    //If the surface was optimized
    if( optimizedImage != NULL )
    {
        //Color key surface
        SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
    }
}

//Return the optimized surface
return optimizedImage;

```

}

void apply\_surface( int x, int y, SDL\_Surface\* source, SDL\_Surface\* destination, SDL\_Rect\* clip = NULL )  
{  
//Holds offsets  
SDL\_Rect offset;

```
//Get offsets
offset.x = x;
offset.y = y;

//Blit
SDL_BlitSurface( source, clip, destination, &offset );

```

}

bool init()  
{  
//Initialize all SDL subsystems  
if( SDL\_Init( SDL\_INIT\_EVERYTHING ) == -1 )  
{  
return false;  
}

```
//Set up the screen
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

//If there was an error in setting up the screen
if( screen == NULL )
{
    return false;
}

if( TTF_Init() == -1 )
{
    return false;
} 

//Set the window caption
SDL_WM_SetCaption( "Dan's Pong", NULL );

//If everything initialized fine
return true;

```

}

bool load\_files()  
{  
//Load the dot image  
dot = load\_image( “dot.png” );

```
//If there was a problem in loading the dot
if ( dot == NULL )
{
    return false;
}

platform = load_image( "platform.png" );

if (platform == NULL)
{
    return false;
}

block = load_image("block.png");

if (block == NULL)
{
    return false;
}

font = TTF_OpenFont( "lazy.ttf", 28 );

if( font == NULL ) 
{
    return false;
}

return true;

```

}

void clean\_up()  
{  
SDL\_FreeSurface( dot );  
SDL\_FreeSurface(platform);  
SDL\_FreeSurface(block);  
SDL\_FreeSurface( message );  
SDL\_FreeSurface( message2 );  
SDL\_FreeSurface( LivesMessage );  
TTF\_CloseFont( font );  
SDL\_Quit();  
}

class Block  
{  
private:  
float x, y;  
bool onscreen;

public:  
Block();  
void show();  
float GetLocation();  
bool GetOnScreen();  
void SetOnScreen(bool onoff);  
void SetXY(float Setx, float Sety);  
};

class Platform  
{  
private:  
float x, y;  
float xVel, yVel;

public:  
Platform();  
void handle\_input();  
void move( Uint32 deltaTicks);  
void show();  
float GetLocation();  
};

class Dot  
{  
private:  
float x, y;  
float xVel, yVel;

public:  
Dot();  
void Dot::move(Uint32 deltaTicks);  
int CheckBallCollision(Uint32 deltaTicks, float PlatformLocation, float BlockLocation, bool start);  
void show();  
void SetVelocity(float x, float y);  
};

class Timer  
{  
private:  
//The clock time when the timer started  
int startTicks;

```
//The ticks stored when the timer was paused
int pausedTicks;

//The timer status
bool paused;
bool started;

public:
//Initializes variables
Timer();

//The various clock actions
void start();
void stop();
void pause();
void unpause();

//Gets the timer's time
int get_ticks();

//Checks the status of the timer
bool is_started();
bool is_paused();

```

};

Block::Block()  
{  
onscreen = 1;  
}

void Block::show()  
{  
apply\_surface( (int)x, (int)y, block, screen);  
}

float Block::GetLocation()  
{  
float location1;  
location1 = x + 25;  
return location1;  
}

bool Block::GetOnScreen()  
{  
return onscreen;  
}

void Block::SetOnScreen(bool onoff)  
{  
onscreen = onoff;  
}

void Block::SetXY(float Setx, float Sety)  
{  
x = Setx;  
y = Sety;  
}

Platform::Platform()  
{  
//Initialize the offsets  
x = (SCREEN\_WIDTH / 2) - 50;  
y = 400;

```
//Initialize the velocity
xVel = 0;
yVel = 0;

```

}

float Platform::GetLocation()  
{  
float location;  
location = x + 50;  
return location;  
}

void Platform::handle\_input()  
{  
if (event.type == SDL\_KEYDOWN)  
{  
switch (event.key.keysym.sym)  
{  
case SDLK\_LEFT: xVel -= PLATFORM\_VEL; break;  
case SDLK\_RIGHT: xVel += PLATFORM\_VEL; break;  
}  
}

```
else if (event.type == SDL_KEYUP)
{
    switch (event.key.keysym.sym)
    {
        case SDLK_LEFT: xVel += PLATFORM_VEL; break;
        case SDLK_RIGHT: xVel -= PLATFORM_VEL; break;
    }
}

```

}

void Platform::move(Uint32 deltaTicks )  
{  
x += xVel \* ( deltaTicks / 1000.f);

```
if (x < 0)
{
    x = 0;
}

else if( x + PLATFORM_WIDTH > SCREEN_WIDTH)
{
    x = SCREEN_WIDTH - PLATFORM_WIDTH;
}

```

}

void Platform::show()  
{  
apply\_surface( (int)x, (int)y, platform, screen );  
}

Dot::Dot()  
{  
x = (SCREEN\_WIDTH / 2) - 10;  
y = 379;

```
xVel = 0;
yVel = 0;

```

}

void Dot::move(Uint32 deltaTicks)  
{  
y += yVel \* (deltaTicks / 1000.f);  
x += xVel \* (deltaTicks / 1000.f);  
}

int Dot::CheckBallCollision(Uint32 deltaTicks, float PlatformLocation, float BlockLocation, bool start)  
{  
//make the ball follow the platform  
if (start == false)  
{  
x = PlatformLocation - 10;  
}

```
//If the dot went too far to the left
if (x < 0)
{
    x = 0;
    return 1;
}

//or the right
else if (x + DOT_WIDTH > SCREEN_WIDTH)
{
    x = SCREEN_WIDTH - DOT_WIDTH;
    return 2;
}

//If the dot went too far up
if (y < 0)
{
    y = 0;
    return 3;
}

//or down
else if (y + DOT_HEIGHT > SCREEN_HEIGHT + DOT_HEIGHT)
{
    y = 379;
    x = PlatformLocation - 10;
    return 4;
}

//if we hit the platform 
else if (y <= 401 && y >= 386)
{
    //if we hit the left
    if (x >= (PlatformLocation - DOT_WIDTH) - 51 && x <= (PlatformLocation - 10) - 17)
        return 8;

    //If we hit the center
    if (x >= (PlatformLocation - DOT_WIDTH) - 16 && x < (PlatformLocation - 10) + 16)
        return 5;

    //If we hit the right
    if (x <= (PlatformLocation - DOT_WIDTH) + 51 && x >= (PlatformLocation - 10) + 17)
        return 9;
}

    
//if we hit blocks 1st row
else if (y <= 31 && y >= 20)
{
    if (x >= BlockLocation - 50 && x <= BlockLocation)
    {
        return 6;
    }
}

//if we hit the blocks 2nd row
else if (y >= 31 && y <= 41)
{
    if (x >= BlockLocation - 50 && x <= BlockLocation)
    {
        return 7;
    }
}

return 0;

```

}

void Dot::show()  
{  
//Show the dot  
apply\_surface( (int)x, (int)y, dot, screen );  
}

void Dot::SetVelocity(float x, float y)  
{  
xVel = x;  
yVel = y;  
}

Timer::Timer()  
{  
//Initialize the variables  
startTicks = 0;  
pausedTicks = 0;  
paused = false;  
started = false;  
}  
[/CODE]

---

<div class="post-metadata">

**Author:** ![sub](https://forum.esforces.com/user_avatar/forum.esforces.com/sub/32/573_2.png) [@sub](https://forum.esforces.com/u/sub)\
**Post date:** [March 30, 2012, 4:04am UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/31 "2012-03-30T04:04:20Z")

</div>

```auto

void Timer::start()
{
    //Start the timer
    started = true;

    //Unpause the timer
    paused = false;

    //Get the current clock time
    startTicks = SDL_GetTicks();
}

void Timer::stop()
{
    //Stop the timer
    started = false;

    //Unpause the timer
    paused = false;
}

void Timer::pause()
{
    //If the timer is running and isn't already paused
    if( ( started == true ) && ( paused == false ) )
    {
        //Pause the timer
        paused = true;

        //Calculate the paused ticks
        pausedTicks = SDL_GetTicks() - startTicks;
    }
}

void Timer::unpause()
{
    //If the timer is paused
    if( paused == true )
    {
        //Unpause the timer
        paused = false;

        //Reset the starting ticks
        startTicks = SDL_GetTicks() - pausedTicks;

        //Reset the paused ticks
        pausedTicks = 0;
    }
}

int Timer::get_ticks()
{
    //If the timer is running
    if( started == true )
    {
        //If the timer is paused
        if( paused == true )
        {
            //Return the number of ticks when the timer was paused
            return pausedTicks;
        }
        else
        {
            //Return the current time minus the start time
            return SDL_GetTicks() - startTicks;
        }
    }

    //If the timer isn't running
    return 0;
}

bool Timer::is_started()
{
    return started;
}

bool Timer::is_paused()
{
    return paused;
}

int main( int argc, char* args[] )
{
    bool quit = false;
    bool start = false;
    Dot myDot;
    Platform myPlatform;
    float x = 14;
    float y = 20;
    float rBlockLocation = -1;
    float &BlockLocation = rBlockLocation;
    int CollisionReturnAnswer = -1;
    int counter = 0;
    int TextWidth1 = 0;
    int TextWidth2 = 0;
    int TextWidth3 = 0;
    int h = 0;
    int h2 = 0;
    int BallLives = 3;

    Block BlockObject[24];
    for (counter = 0; counter < 24; counter++)
    {
        BlockObject[counter].SetXY(x, y);
        x = x + 51;
        if (counter == 11)
        {
            x = 14;
            y = 31;
        }
    }
    
    x = 0;
    y = 0;
    Timer delta;

    if( init() == false )
    {
        return 1;
    }

    if( load_files() == false )
    {
        return 1;
    }

    delta.start();
    Uint8 *keystates = SDL_GetKeyState( NULL );
    float PlatformLocation = 0;

    
    TTF_SizeText(font, "Press the left and right arrow keys to move.", &TextWidth1, &h);
    TTF_SizeText(font, "Press the up arrow key to begin.", &TextWidth2, &h2);
    TTF_SizeText(font, "Lives: 3", &TextWidth3, &h);

    message = TTF_RenderText_Solid( font, "Press the left and right arrow keys to move.", textColor );
    message2 = TTF_RenderText_Solid( font, "Press the up arrow key to begin.", textColor );

    TextWidth1 = (SCREEN_WIDTH - TextWidth1) / 2;
    TextWidth2 = (SCREEN_WIDTH - TextWidth2) / 2;
    TextWidth3 = (SCREEN_WIDTH - TextWidth3) - 5;

    while( quit == false )
    {
        while( SDL_PollEvent( &event ) )
        {
            myPlatform.handle_input();
            
            if( event.type == SDL_QUIT )
            {
               quit = true;
            }
        }
        

        if (start == false)
        {        
            if( keystates[SDLK_UP] )
            {
                x = -250, y = -250;
                start = true;
            }
        }
        
        CollisionReturnAnswer = (myDot.CheckBallCollision( delta.get_ticks(), PlatformLocation, BlockLocation, start));

        //left - Also, not sure how I'm supposed to really do collision. Should I put this into the function? I'm almost certain I'm doing it wrong in any case
        if (CollisionReturnAnswer == 1)
        {
            x = 250;
        }

        //right
        else if (CollisionReturnAnswer == 2)
        {
            x = -250;
        }

        //up
        else if (CollisionReturnAnswer == 3)
        {
            y = 250;
        }

         //down
        else if (CollisionReturnAnswer == 4)
        {
            myDot.SetVelocity(0, 0);
            y = 0;
            x = 0;
            myDot.move(delta.get_ticks());
            start = false;
            BallLives--;
            if (BallLives <= 0)
            {
                BallLives = 3;
                counter = 0;
                while (counter < 24)
                {
                    BlockObject[counter].SetOnScreen(1);
                    counter++;
                }
            }
        }

        //contact with platform center            
        else if (CollisionReturnAnswer == 5)
        {
            y = -250;
        }

        //contact with platform left
        else if (CollisionReturnAnswer == 8)
        {
            y = -250;
            x = -250;
        }

        //contact with platform right
        else if (CollisionReturnAnswer == 9)
        {
            y = -250;
            x = 250;
        }

        //check contact with block; if contact, don't show onsreen
        for (counter = 12; counter < 24; counter++)
        {
            BlockLocation = BlockObject[counter].GetLocation();
            if (myDot.CheckBallCollision(delta.get_ticks(), PlatformLocation, BlockLocation, start) == 7 && BlockObject[counter].GetOnScreen() == 1)
            {
                y = 250;
                BlockObject[counter].SetOnScreen(0);
            }
        }
        
        for (counter = 0; counter < 12; counter++)
        {
            BlockLocation = BlockObject[counter].GetLocation();
            if (myDot.CheckBallCollision(delta.get_ticks(), PlatformLocation, BlockLocation, start) == 6 && BlockObject[counter].GetOnScreen() == 1)
            {
                y = 250;
                BlockObject[counter].SetOnScreen(0);
            }
        }

        myPlatform.move(delta.get_ticks());
        PlatformLocation = myPlatform.GetLocation();

        myDot.SetVelocity(x, y);
        myDot.move(delta.get_ticks());
        delta.start();

        SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );

        myDot.show();
        myPlatform.show();

        if (start == false && BallLives == 3)
        {
            apply_surface( TextWidth1, 150, message, screen );
            apply_surface( TextWidth2, 180, message2, screen );
        }
        if (BallLives == 3)
        {
            SDL_FreeSurface( LivesMessage );
            LivesMessage = TTF_RenderText_Solid(font, "Lives: 3", textColor);
        }
        else if (BallLives == 2)
        {
            SDL_FreeSurface( LivesMessage );
            LivesMessage = TTF_RenderText_Solid(font, "Lives: 2", textColor);
        }
        else if (BallLives == 1)
        {
            SDL_FreeSurface( LivesMessage );
            LivesMessage = TTF_RenderText_Solid(font, "Lives: 1", textColor);
        }

        apply_surface( TextWidth3, 450, LivesMessage, screen);

        for (counter = 0; counter < 24; counter++)
        {
            if (BlockObject[counter].GetOnScreen() == 1)
            {
                BlockObject[counter].show();
            }
        }

        if( SDL_Flip( screen ) == -1 )
        {
            return 1;
        }
    
    }

    clean_up();
    return 0;
}

```

---

<div class="post-metadata">

**Author:** ![Deverz](https://forum.esforces.com/user_avatar/forum.esforces.com/deverz/32/6_2.png) [@Deverz](https://forum.esforces.com/u/Deverz)\
**Post date:** [March 30, 2012, 5:40am UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/32 "2012-03-30T05:40:18Z")

</div>

> [@Sub](#):
>
> I still want to add levels to it, add powerups to it (ie: A random number of blocks would spawn red. If you break a red block, a powerup drops. If you catch the powerup, you can obviously use it. A powerup might be something like 3 balls spawning, or the ability to shoot lazers from your platform.) Also want to make it so that the ball will bounce if it hits the top of a block instead of just going through them.

YES!!

---

<div class="post-metadata">

**Author:** ![sub](https://forum.esforces.com/user_avatar/forum.esforces.com/sub/32/573_2.png) [@sub](https://forum.esforces.com/u/sub)\
**Post date:** [April 27, 2012, 10:09pm UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/33 "2012-04-27T22:09:31Z")

</div>

[https://rapidshare.com/files/2661720388/SubTetris.7z  
 ](https://rapidshare.com/files/2661720388/SubTetris.7z)  
[http://i.imgur.com/8Un5t.png](http://i.imgur.com/8Un5t.png)

So I made Tetris. I spent the majority of my free time in the past two or three weeks working on this. I rather like how it turned out, although it’s still not 100% done. I want to add a slight pause and a visual cue when you clear a line, right now the line instantly disappears and it’s kind of jarring. I also want to make the random number generator better, right now it’s okay but it doesn’t give out the pink shape very much at all. You can pause the game by pressing backspace, but I’ll probably add a visual button you can click on to pause it. I’ll probably also add a button to restart it, right now you can only restart it if you lose and press enter on the game over screen.

This is the code. If anyone knows how to code and wants to point out anything at all that I’ve done wrong, I’ll greatly appreciate it and try to not make the same mistake in the future. The code started getting really sloppy towards the end when I was putting the text in, I was just really anxious to finish it.

classes.h  
[http://pastebin.com/NxKzkzdv](http://pastebin.com/NxKzkzdv)

constants.h  
[http://pastebin.com/7KqJqhJq](http://pastebin.com/7KqJqhJq)

functions.h  
[http://pastebin.com/xUW1gmy4](http://pastebin.com/xUW1gmy4)

globals.h  
[http://pastebin.com/N7tM6daA](http://pastebin.com/N7tM6daA)

blocks.cpp  
[http://pastebin.com/Pi93b7J8](http://pastebin.com/Pi93b7J8)

functions.cpp  
[http://pastebin.com/HhPxyCGy](http://pastebin.com/HhPxyCGy)

globals.cpp  
[http://pastebin.com/4ThFDwmi](http://pastebin.com/4ThFDwmi)

main.cpp  
[http://pastebin.com/Yt19HF6H](http://pastebin.com/Yt19HF6H)

timer.cpp  
[http://pastebin.com/bebFXxTV](http://pastebin.com/bebFXxTV)

---

<div class="post-metadata">

**Author:** ![Shadi](https://forum.esforces.com/user_avatar/forum.esforces.com/shadi/32/2165_2.png) [@Shadi](https://forum.esforces.com/u/Shadi)\
**Post date:** [April 27, 2012, 10:11pm UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/34 "2012-04-27T22:11:55Z")

</div>

Good job, Sub! Played it [noparse]:D[/noparse] 'Cept for the things we discussed on Steam that you in addition pointed out in the thread - A lot of Kudos!

---

<div class="post-metadata">

**Author:** ![sub](https://forum.esforces.com/user_avatar/forum.esforces.com/sub/32/573_2.png) [@sub](https://forum.esforces.com/u/sub)\
**Post date:** [April 27, 2012, 10:39pm UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/35 "2012-04-27T22:39:42Z")

</div>

I just realized that I never reset the score when the game resets. Ah well.

---

<div class="post-metadata">

**Author:** ![Denz](https://forum.esforces.com/user_avatar/forum.esforces.com/denz/32/728_2.png) [@Denz](https://forum.esforces.com/u/Denz)\
**Post date:** [April 27, 2012, 10:44pm UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/36 "2012-04-27T22:44:09Z")

</div>

you will be rich! continue developing your computer language, if you need better looking art, hit me up

---

<div class="post-metadata">

**Author:** ![vector](https://forum.esforces.com/letter_avatar_proxy/v4/letter/v/dc4da7/32.png) [@vector](https://forum.esforces.com/u/vector)\
**Post date:** [April 28, 2012, 12:37am UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/37 "2012-04-28T00:37:39Z")

</div>

> [@Sub](#):
>
> [https://rapidshare.com/files/2661720388/SubTetris.7z](https://rapidshare.com/files/2661720388/SubTetris.7z)
> 
> [http://i.imgur.com/8Un5t.png](http://i.imgur.com/8Un5t.png)
> 
> So I made Tetris. I spent the majority of my free time in the past two or three weeks working on this. I rather like how it turned out, although it’s still not 100% done. I want to add a slight pause and a visual cue when you clear a line, right now the line instantly disappears and it’s kind of jarring. I also want to make the random number generator better, right now it’s okay but it doesn’t give out the pink shape very much at all. You can pause the game by pressing backspace, but I’ll probably add a visual button you can click on to pause it. I’ll probably also add a button to restart it, right now you can only restart it if you lose and press enter on the game over screen.
> 
> This is the code. If anyone knows how to code and wants to point out anything at all that I’ve done wrong, I’ll greatly appreciate it and try to not make the same mistake in the future. The code started getting really sloppy towards the end when I was putting the text in, I was just really anxious to finish it.
> 
> classes.h  
> [http://pastebin.com/NxKzkzdv](http://pastebin.com/NxKzkzdv)
> 
> constants.h  
> [http://pastebin.com/7KqJqhJq](http://pastebin.com/7KqJqhJq)
> 
> functions.h  
> [http://pastebin.com/xUW1gmy4](http://pastebin.com/xUW1gmy4)
> 
> globals.h  
> [http://pastebin.com/N7tM6daA](http://pastebin.com/N7tM6daA)
> 
> blocks.cpp  
> [http://pastebin.com/Pi93b7J8](http://pastebin.com/Pi93b7J8)
> 
> functions.cpp  
> [http://pastebin.com/HhPxyCGy](http://pastebin.com/HhPxyCGy)
> 
> globals.cpp  
> [http://pastebin.com/4ThFDwmi](http://pastebin.com/4ThFDwmi)
> 
> main.cpp  
> [http://pastebin.com/Yt19HF6H](http://pastebin.com/Yt19HF6H)
> 
> timer.cpp  
> [http://pastebin.com/bebFXxTV](http://pastebin.com/bebFXxTV)

this isn’t working

says

program can’t start because MSVCP100.DLL is missing from your computer. try reinstall the program to fix this problem.

NVM got it working … now u wanna tell me what the controls are ? right now i have no idea how to turn the blocks 😕

---

<div class="post-metadata">

**Author:** ![Shadi](https://forum.esforces.com/user_avatar/forum.esforces.com/shadi/32/2165_2.png) [@Shadi](https://forum.esforces.com/u/Shadi)\
**Post date:** [April 28, 2012, 12:39am UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/38 "2012-04-28T00:39:53Z")

</div>

> [@vector](#):
>
> this isn’t working
> 
> says
> 
> program can’t start because MSVCP100.DLL is missing from your computer. try reinstall the program to fix this problem.

Weird when Sub gave me this link [https://rapidshare.com/files/2661720388/SubTetris.7z](https://rapidshare.com/files/2661720388/SubTetris.7z) it worked fine.. however the one before that didn’t work but he said this one fixed it O\_o

---

<div class="post-metadata">

**Author:** ![vector](https://forum.esforces.com/letter_avatar_proxy/v4/letter/v/dc4da7/32.png) [@vector](https://forum.esforces.com/u/vector)\
**Post date:** [April 28, 2012, 1:21am UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/39 "2012-04-28T01:21:02Z")

</div>

yteah i just had to download all teh C++ stuff n what not. well anyways

the game. u need to add instant drop button. i know right now u have down arrow doing that … but it’s not good cuz u accidently do it that way. slow down teh down arrow drop just a tad (very little bit not much at all) and add SPACE bar as instant drop. game will b much better. btw the whole adding something for a line being cleared is an overrated feature, tetris is quite cool without it. but anyways … maybe add some combo bonuses … say if u clear 4 lines with 1 drop … and if u clear lines with consecutively from drop to drop. well anyways. i got pretty damn far. random generator not too bad. but could use a little tweak …

and u need menu n what not … and option to play easier mode n harder mode (basically speeds up or down)

heck if u had it so that you can pick a speed from 0-100 that’s b badass … u can play any custom speed u want from 0-100 (like volume control is set up) well anyways AMAZING STUFF!!! keep at it. is surprisingly clean

OOO and add feature to SAVE a block in que … i always loved that feature \>\< hehehe

AND u ur missing a block shape. u need to make the reflection of the TEAL block.

and u need a HOW TO PLAY section

and PLEASE PLEASE PLEASE … add a pause button \>\<

---

<div class="post-metadata">

**Author:** ![Shadi](https://forum.esforces.com/user_avatar/forum.esforces.com/shadi/32/2165_2.png) [@Shadi](https://forum.esforces.com/u/Shadi)\
**Post date:** [April 28, 2012, 2:04am UTC](https://forum.esforces.com/t/subs-coding-pool-party/77242/40 "2012-04-28T02:04:30Z")

</div>

> [@vector](#):
>
> yteah i just had to download all teh C++ stuff n what not. well anyways
> 
> the game. u need to add instant drop button. i know right now u have down arrow doing that … but it’s not good cuz u accidently do it that way. slow down teh down arrow drop just a tad (very little bit not much at all) and add SPACE bar as instant drop. game will b much better. btw the whole adding something for a line being cleared is an overrated feature, tetris is quite cool without it. but anyways … maybe add some combo bonuses … say if u clear 4 lines with 1 drop … and if u clear lines with consecutively from drop to drop. well anyways. i got pretty damn far. random generator not too bad. but could use a little tweak …
> 
> and u need menu n what not … and option to play easier mode n harder mode (basically speeds up or down)
> 
> heck if u had it so that you can pick a speed from 0-100 that’s b badass … u can play any custom speed u want from 0-100 (like volume control is set up) well anyways AMAZING STUFF!!! keep at it. is surprisingly clean
> 
> OOO and add feature to SAVE a block in que … i always loved that feature \>\< hehehe
> 
> AND u ur missing a block shape. u need to make the reflection of the TEAL block.
> 
> and u need a HOW TO PLAY section
> 
> and PLEASE PLEASE PLEASE … add a pause button \>\<

It wasn’t meant to be that advanced, making a menu would do a lot of work.. and he’s planning to add VISUAL a pause button and increase the speed for every time you get like, 10 lines completed. You can already pause on backspace. In addition he plans to add that you can visually see the lines disappear instead of it being an instant action.. not sure if he bothers making the rest xD

[Previous page](https://forum.esforces.com/t/subs-coding-pool-party/77242.md?page=1)

[Next page](https://forum.esforces.com/t/subs-coding-pool-party/77242.md?page=3)
