Blitting Image With Mouse Click

OK I got another problem now.

186 C:\Users\Documents\TowerDefense\main.cpp request for member Draw' ingTower’, which is of non-class type `Tower ()()’

^ That is the error I am getting now. What I want to do is, is so that when the user clicks somewhere within the screen bounds, a tower will be drawn onto the location of the screen, while also subtracting money from the player.

Code:

#include “main.h”
#include “tower.h”

SDL_Surface* Screen;
SDL_Event event;
TTF_Font* Font;

stack Towers;
int gtowers;

Tower gTower();

int ThisTime = 0;
int LastTime = 0;
float DeltaTime = 0.0f;

const int WIDTH = 800;
const int HEIGHT = 600;
const int DEPTH = 32;
const char* TITLE = “Tower Defense”;

SDL_Color textColor = {255,255,0};

int TowerHealth = 100;
int Points = 0;

int Money = 1000;
int EnemyHealth = 50;

int Bullet_Damage = 15;
int TowerCost = 200;

SDLKey keyPressed;
SDLKey keyReleased;

bool keysHeld[323] = {false};

bool GameRunning = true;
bool GameOver = false;

SDL_Surface* Backdrop;
SDL_Rect BackdropRect;

SDL_Surface* FPS;
SDL_Rect FPSRect;
char fps[10];

SDL_Surface* POINT;
SDL_Rect POINTRect;
char point[10];

int Damage_Frames;
int Current_Frame;
const int Total_Frames = 4;

SDL_Surface* HEALTH;
SDL_Rect HealthRect;
char health[10];

SDL_Surface* MONEY;
SDL_Rect MoneyRect;
char money[10];

int mx = 0;
int my = 0;

SDL_Surface* Bullet;
SDL_Rect BulletRect;

SDL_Surface* Enemy;
SDL_Rect EnemyRect;

bool GameScreen = true;

int main(int argc, char* argv[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}

Screen = SDL_SetVideoMode(WIDTH,HEIGHT,DEPTH, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption(TITLE,NULL);

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

if(Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096) == -1)
{
    return 1;
}

Backdrop = IMG_Load("Backdrop.png");
BackdropRect.x = 0;
BackdropRect.y = 0;
BackdropRect.w = 800;
BackdropRect.h = 600;

//Bullet = IMG_Load("Bullet.png");
//SDL_SetColorKey(Bullet,SDL_SRCCOLORKEY,SDL_MapRGB(Bullet->format,255,255,255));

//Enemy = IMG_Load("Enemy.png");
//SDL_SetColorKey(Enemy,SDL_SRCCOLORKEY,SDL_MapRGB(Enemy->format,255,255,255));

Font = TTF_OpenFont("Arial.ttf",20);

FPSRect.x = 1;
FPSRect.y = 1;
FPSRect.w = 0;
FPSRect.h = 0;

POINTRect.x = 1;
POINTRect.y = 20;
POINTRect.w = 0;
POINTRect.h = 0;

HealthRect.x = 1;
HealthRect.y = 40;
HealthRect.w = 0;
HealthRect.h = 0;

MoneyRect.x = 1;
MoneyRect.y = 60;
MoneyRect.w = 0;
MoneyRect.h = 0;

while(GameRunning)
{
    ThisTime = SDL_GetTicks();
    DeltaTime = (float)(ThisTime - LastTime) / 1000 / 30;
    LastTime = ThisTime;

    sprintf(fps,"FPS: %.4f", DeltaTime);
    FPS = TTF_RenderText_Solid(Font,fps,textColor);

    sprintf(point,"Points: %.2d", Points);
    POINT = TTF_RenderText_Solid(Font,point,textColor);

    sprintf(health,"Health: %.3d",TowerHealth);
    HEALTH = TTF_RenderText_Solid(Font,health,textColor);

    sprintf(money,"Money: %.4d",Money);
    MONEY = TTF_RenderText_Solid(Font,money,textColor);

    while(SDL_PollEvent(&event))
    {
        if(event.type == SDL_QUIT)
        {
            GameRunning = false;
        }

        if(event.type == SDL_KEYDOWN)
        {
            keyPressed = event.key.keysym.sym;
            keysHeld[event.key.keysym.sym] = true;

            if(keyPressed == SDLK_ESCAPE)
            {
                GameRunning = false;
            }
        }

        if(event.type == SDL_KEYUP)
        {
            keyReleased = event.key.keysym.sym;
            keysHeld[event.key.keysym.sym] = false;
        }

        if(event.type == SDL_MOUSEMOTION)
        {
            mx = event.motion.x;
            my = event.motion.y;
        }

        if(event.type == SDL_MOUSEBUTTONDOWN)
        {
            if(event.button.button == SDL_BUTTON_LEFT)
            {
                mx = event.button.x;
                my = event.button.y;

                if(mx < 0 && mx < WIDTH)
                {
                    gTower(gTower.Draw());
                }
            }
        }
    }

    SDL_FillRect(Screen,NULL,SDL_MapRGB(Screen->format,0,0,0));

    SDL_BlitSurface(Backdrop,NULL,Screen,&BackdropRect);
    SDL_BlitSurface(FPS,NULL,Screen,&FPSRect);
    SDL_BlitSurface(POINT,NULL,Screen,&POINTRect);
    SDL_BlitSurface(HEALTH,NULL,Screen,&HealthRect);
    SDL_BlitSurface(MONEY,NULL,Screen,&MoneyRect);

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

SDL_FreeSurface(MONEY);
SDL_FreeSurface(HEALTH);
SDL_FreeSurface(FPS);
SDL_FreeSurface(Backdrop);
SDL_FreeSurface(POINT);

TTF_CloseFont(Font);
TTF_Quit();
Mix_CloseAudio();
SDL_Quit();

return 0;

}

We know you would like to draw the image when the user clicks, but it
appears that you are having trouble with the C++ part a bit. If you don’t
understand those, you will only run into more or the same problems later.

The source files are not as an attachment so I cannot even try to compile
them. I assume you are posting this through the forum rather than the
mailing list.

First, the line:

Tower gTower();

seems out of place to me considering you didn’t pass any arguments to it at
time of initialization. It’s possible that you added another constructor to
the Tower class afterwards that I don’t know about but whether or not this
is actually legal in C++ (which I would say no), it is bad programming
practice. In C, this is equivalent to calling a function that takes
parameters but supplying no arguments.

Whether or not the constructor was your problem above, you are commiting
the same sin below by calling the Draw function with no arguments. You
should be passing in a pointer to an SDL_Surface.
Such as this:

gTower(gTower.Draw(Screen));

Hope that helps.

At global scope…
Tower gTower();
…is a declaration of a function that takes no arguments and returns a
Tower. That’s not what you want.

Jonny D

I see. OOP is something I don’t something fully understand. Just seems like more code for better organization, organization is fine for large projects and all, but this was meant to be a small project. Its the OOP I’m having trouble with, with the Tower class and stuff. Like how do I use the tower class in the main game code?

I see. OOP is something I don’t something fully understand. Just seems
like more code for better organization, organization is fine for large
projects and all, but this was meant to be a small project. Its the OOP
I’m having trouble with, with the Tower class and stuff. Like how do I
use the tower class in the main game code?

You don’t need OOP if you’re not OK with it (I personally can’t abide it
and think some of it is the world of the devil, however), but I would at
least suggest starting to use procedures/functions in your code rather
than one huge main() block.

while (poll-event)
{
if (event == keydown)
handleKeydown () ;
else if (event == keyup)
handleKeyup () ;

and so on.

If nothing else it might help you break your program down into smaller,
more managable sections.

You might even want to look at someone else’s code too - there was a good
little game posted here by H. Peter Anvin a few weeks back and the soruces
are all online under the GPL, so if you’re relatively new to coding, then
have a look and get ideas off others.

GordonOn Sun, 25 Mar 2012, GameCoder wrote:

Well I’m not necessarily new to coding, but I could use some ideas or rather look at some good code, espcially when it comes to game programming. It would help even more if it is well commented and easy to understand. Also, if anyone can help with the dilema I am having right now, that would be great. I’m pretty close to acheiveing what I want.

Message-ID: <1332645696.m2f.32366 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

OK, I’ll post all the code and the error.

Tower.cpp

Code:

#include “main.h”
#include “tower.h”

Tower::Tower(SDL_Surface* Image, int x, int y)
: Image(Image),x(x),y(y);
{}

Ok, you see where you initialize y? Two things:

  1. You immediately followed that with a semi-colon. THEN the curly
    brackets. That’s bad syntax.
  2. I’d really suggest adding a underscore to either the names of the
    instance variables, or the arguments.

main.cpp

        if(event.type == SDL_MOUSEBUTTONDOWN)
        {
            if(event.button.button == SDL_BUTTON_LEFT)
            {
                mx = event.button.x;
                my = event.button.y;
            }
        }

If you decide to go with multiple towers, stored in a container, then
this would probably be the right place to add them to the container.

    SDL_BlitSurface(Backdrop,NULL,Screen,&BackdropRect);
    SDL_BlitSurface(FPS,NULL,Screen,&FPSRect);
    SDL_BlitSurface(POINT,NULL,Screen,&POINTRect);
    SDL_BlitSurface(HEALTH,NULL,Screen,&HealthRect);
    SDL_BlitSurface(MONEY,NULL,Screen,&MoneyRect);

Right between rendering the Backdrop and the FPS would probably be the
right place to render the towers.> Date: Sat, 24 Mar 2012 20:21:36 -0700

From: “GameCoder” <g_andy at live.com>
To: sdl at lists.libsdl.org
Subject: Re: [SDL] Blitting Image With Mouse Click

OK I think I almost have it done. I just need to figure out how, when the user clicks it draws the tower image on the screen. So far, the image is already on the screen, before the user clicks. Note: I got rid of the OOP code I had.

Code:

#include “main.h”
#include “tower.h”

SDL_Surface* Screen;
SDL_Event event;
TTF_Font* Font;

stack Towers;
Tower tower();
int gtowers;

int ThisTime = 0;
int LastTime = 0;
float DeltaTime = 0.0f;

const int WIDTH = 800;
const int HEIGHT = 600;
const int DEPTH = 32;
const char* TITLE = “Tower Defense”;

SDL_Color textColor = {255,255,0};

int TowerHealth = 100;
int Points = 0;

int Money = 1000;
int EnemyHealth = 50;

int Bullet_Damage = 15;
int TowerCost = 200;

SDLKey keyPressed;
SDLKey keyReleased;

bool keysHeld[323] = {false};

bool GameRunning = true;
bool GameOver = false;

SDL_Surface* Backdrop;
SDL_Rect BackdropRect;

SDL_Surface* FPS;
SDL_Rect FPSRect;
char fps[10];

SDL_Surface* POINT;
SDL_Rect POINTRect;
char point[10];

int Damage_Frames;
int Current_Frame;
const int Total_Frames = 4;

SDL_Surface* HEALTH;
SDL_Rect HealthRect;
char health[10];

SDL_Surface* MONEY;
SDL_Rect MoneyRect;
char money[10];

int mx = 0;
int my = 0;

SDL_Surface* Bullet;
SDL_Rect BulletRect;

SDL_Surface* Enemy;
SDL_Rect EnemyRect;

stack Enemies;
int genemies;

SDL_Surface* Tower;
SDL_Rect TowerRect;

bool GameScreen = true;

int main(int argc, char* argv[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}

Screen = SDL_SetVideoMode(WIDTH,HEIGHT,DEPTH, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption(TITLE,NULL);

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

if(Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096) == -1)
{
    return 1;
}

Backdrop = IMG_Load("Backdrop.png");
BackdropRect.x = 0;
BackdropRect.y = 0;
BackdropRect.w = 800;
BackdropRect.h = 600;

Tower = IMG_Load("Tower.png");
SDL_SetColorKey(Tower,SDL_SRCCOLORKEY,SDL_MapRGB(Tower->format,255,255,255));
TowerRect.x = mx;
TowerRect.y = my;
TowerRect.w = 150;
TowerRect.h = 150;

//Bullet = IMG_Load("Bullet.png");
//SDL_SetColorKey(Bullet,SDL_SRCCOLORKEY,SDL_MapRGB(Bullet->format,255,255,255));

//Enemy = IMG_Load("Enemy.png");
//SDL_SetColorKey(Enemy,SDL_SRCCOLORKEY,SDL_MapRGB(Enemy->format,255,255,255));

Font = TTF_OpenFont("Arial.ttf",20);

FPSRect.x = 1;
FPSRect.y = 1;
FPSRect.w = 0;
FPSRect.h = 0;

POINTRect.x = 1;
POINTRect.y = 20;
POINTRect.w = 0;
POINTRect.h = 0;

HealthRect.x = 1;
HealthRect.y = 40;
HealthRect.w = 0;
HealthRect.h = 0;

MoneyRect.x = 1;
MoneyRect.y = 60;
MoneyRect.w = 0;
MoneyRect.h = 0;

while(GameRunning)
{
    ThisTime = SDL_GetTicks();
    DeltaTime = (float)(ThisTime - LastTime) / 1000 / 30;
    LastTime = ThisTime;

    sprintf(fps,"FPS: %.4f", DeltaTime);
    FPS = TTF_RenderText_Solid(Font,fps,textColor);

    sprintf(point,"Points: %.2d", Points);
    POINT = TTF_RenderText_Solid(Font,point,textColor);

    sprintf(health,"Health: %.3d",TowerHealth);
    HEALTH = TTF_RenderText_Solid(Font,health,textColor);

    sprintf(money,"Money: %.4d",Money);
    MONEY = TTF_RenderText_Solid(Font,money,textColor);

    while(SDL_PollEvent(&event))
    {
        if(event.type == SDL_QUIT)
        {
            GameRunning = false;
        }

        if(event.type == SDL_KEYDOWN)
        {
            keyPressed = event.key.keysym.sym;
            keysHeld[event.key.keysym.sym] = true;

            if(keyPressed == SDLK_ESCAPE)
            {
                GameRunning = false;
            }
        }

        if(event.type == SDL_KEYUP)
        {
            keyReleased = event.key.keysym.sym;
            keysHeld[event.key.keysym.sym] = false;
        }

        if(event.type == SDL_MOUSEMOTION)
        {
            mx = event.motion.x;
            my = event.motion.y;
        }

        if(event.type == SDL_MOUSEBUTTONDOWN)
        {
            if(event.button.button == SDL_BUTTON_LEFT)
            {
                mx = event.button.x;
                my = event.button.y;

                Money -= 200;

                if(Money != 0)
                {
                    Towers.push(gtowers);
                }
            }
        }
    }

    SDL_FillRect(Screen,NULL,SDL_MapRGB(Screen->format,0,0,0));

    SDL_BlitSurface(Backdrop,NULL,Screen,&BackdropRect);

    SDL_BlitSurface(FPS,NULL,Screen,&FPSRect);
    SDL_BlitSurface(POINT,NULL,Screen,&POINTRect);
    SDL_BlitSurface(HEALTH,NULL,Screen,&HealthRect);
    SDL_BlitSurface(MONEY,NULL,Screen,&MoneyRect);

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

SDL_FreeSurface(MONEY);
SDL_FreeSurface(HEALTH);
SDL_FreeSurface(FPS);
SDL_FreeSurface(Backdrop);
SDL_FreeSurface(POINT);

TTF_CloseFont(Font);
TTF_Quit();
Mix_CloseAudio();
SDL_Quit();

return 0;

}

I can’t believe that I forgot to read the other digests before sending
that last message…> Date: Sat, 24 Mar 2012 21:33:37 -0700

From: “GameCoder” <g_andy at live.com>
To: sdl at lists.libsdl.org
Subject: Re: [SDL] Blitting Image With Mouse Click
Message-ID: <1332650017.m2f.32370 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

What I want to do is, is so that when
the user clicks somewhere within the screen bounds, a tower will be drawn
onto the location of the screen, while also subtracting money from the
player.

stack Towers;
int gtowers;

What is this? What does this do? You have a stack of integers, which
is named Towers, and you have an int named gTowers, and no real
indication of what either is for. Just for reference, if you call
size() on Towers, it should return the number of ints that it
currently has inside itself.

Tower gTower();

In C++, Tower gTower() means that gTower returns a Tower instance, and
DOES NOT take any arguments.

int TowerHealth = 100;

TowerHealth? That means that towers can be damaged, correct? Unless
ALL of the towers are supposed to just explode when their group-health
drops to zero, this should be a variable that each tower has it’s own
version of.

int Points = 0;

int Money = 1000;

Ok, so you have a global variable that records how much money the
player can spend, and another that records how many points the player
has earned, that works. However, if you decide to make this a
two-player game in the future, then you’ll need to change it.

int EnemyHealth = 50;

That thing about TowerHealth? If you’re going to have more than one
enemy on the screen at once, then it applies to EnemyHealth too.

        if(event.type == SDL_MOUSEBUTTONDOWN)
        {
            if(event.button.button == SDL_BUTTON_LEFT)
            {
                mx = event.button.x;
                my = event.button.y;

                if(mx < 0 && mx < WIDTH)
                {
                    gTower(gTower.Draw());
                }

This seems to be the only time in the entire game that you display a
tower. The problem is, the
SDL_FillRect(Screen,NULL,SDL_MapRGB(Screen->format,0,0,0)) below will
erase the image of the tower. As a result, the tower will only display
for 1 single frame, and then never again.

Also, what is gTower(gTower.Draw()) supposed to do? I can tell you
what it actually does: it calls gTower(), calls Draw() on the return
value of that gTower call, then uses Draw’s return value as an
argument to gTower(). Unfortunately, this clashes with the definition
of gTower, which does not take any arguments. Were you attempting
operator chaining?

Incidentally, I would subtract the money here, in the SDL_BUTTON_LEFT
handler, instead of making the Tower class deal with it. Two reasons:

  1. That restricts all uses of the Money variable to the same file
    where it’s declared. This is a good idea.
  2. If the player doesn’t have enough money, then you can refuse to
    build a tower without calling the tower’s constructor. Also a good
    idea.
    SDL_BlitSurface(Backdrop,NULL,Screen,&BackdropRect);
    SDL_BlitSurface(FPS,NULL,Screen,&FPSRect);
    SDL_BlitSurface(POINT,NULL,Screen,&POINTRect);
    SDL_BlitSurface(HEALTH,NULL,Screen,&HealthRect);
    SDL_BlitSurface(MONEY,NULL,Screen,&MoneyRect);

Once again, you should draw all of the towers after drawing the
Backdrop, but PROBABLY before drawing the FPS.

Date: Sun, 25 Mar 2012 09:17:34 -0700
From: “GameCoder” <g_andy at live.com>
To: sdl at lists.libsdl.org
Subject: Re: [SDL] Blitting Image With Mouse Click
Message-ID: <1332692254.m2f.32374 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

I see. OOP is something I don’t something fully understand. Just seems like
more code for better organization, organization is fine for large projects
and all, but this was meant to be a small project. Its the OOP I’m having
trouble with, with the Tower class and stuff.

I once read in a C book (I think it might have been the K&R book,
actually) that a function is just a small program.

And thinking about it, that’s right.

And thinking about it, an object is the exact same thing (just
implemented differently).

Basically, objects are 0 or more pieces of data and 0 or more
functions that act like a single, individual THING. Hence why they’re
called objects: objects are things & vice-versa. The basic idea is
that you take something that can be considered a THING (such as your
towers, or a video card, or a mailing list, or whatever else), and you
design a GROUPING of data & functions that behaves like that THING
behaves.

Like how do I use the tower
class in the main game code?

I think you’re approaching it from the wrong perspective. ‘How do I
use this?’ comes SECOND, first you need to know what a tower is. A
tower is, at the very minimum, a THING that has a POSITION (expressed
as a X position & a Y position), and an APPEARANCE (which is provided
by a SDL_Surface).

Now, do all towers look the same? If so, then you only need one
SDL_Surface for all of them. Otherwise, you’ll need more than one
surface.

Can towers be damaged? Do they get damaged as a group (like Star
Trek’s exploding control consoles), or individually? If they get
damaged individually, then they all need their own health variable.

Keep asking yourself questions about towers, until you completely know
what a tower is, then put all of the appropriate variables into your
Tower class. Don’t go insane with this; if you aren’t certain (or even
currently trying) to USE a particular trait that towers have, then
don’t add it. You might want to leave /* ADD THIS */ notes to yourself
about certain tower traits, but it’s easier to get something small
working than something big.

After you have all of the variables placed into the Tower class, THEN
you ask yourself “How do I use this?”. The answers to THAT will tell
you two things:

  1. What member-functions to add to the class, and
  2. What extra variables you need to add into the class for those
    member-functions to work.

For example, you’ll need to draw the tower, so you’ll need a draw
function, which will need some way to figure out WHERE to draw to. If
towers have health you’ll need a function to modify their health. Etc.

Looks like some bad timing.> Date: Sun, 25 Mar 2012 17:13:08 -0700

From: “GameCoder” <g_andy at live.com>
To: sdl at lists.libsdl.org
Subject: Re: [SDL] Blitting Image With Mouse Click
Message-ID: <1332720788.m2f.32378 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

OK I think I almost have it done. I just need to figure out how, when the
user clicks it draws the tower image on the screen. So far, the image is
already on the screen, before the user clicks. Note: I got rid of the OOP
code I had.

stack Towers;
Tower tower();
int gtowers;

Once again, what does this do? From looking at this:

        if(event.type == SDL_MOUSEBUTTONDOWN)
        {
            if(event.button.button == SDL_BUTTON_LEFT)
            {
                mx = event.button.x;
                my = event.button.y;

                Money -= 200;

                if(Money != 0)
                {
                    Towers.push(gtowers);
                }
            }
        }

It looks like you intend to track the number of elements in Towers
with gtowers, despite the fact that the stack<> template should
provide a size() function for that purpose. Also, I didn’t notice
gtowers being modified anywhere. In short, it looks like this bit of
code is completely confused. I advise that you replace

stack Towers

with:

stack Towers

then do something like:

        if(event.type == SDL_MOUSEBUTTONDOWN)
        {
            if(event.button.button == SDL_BUTTON_LEFT)
            {
                mx = event.button.x;
                my = event.button.y;

                Money -= 200;

                if(Money != 0)
                {
                    Towers.push( Tower( mx, my ) );
                }
            }
        }

After that, you’d simply have to iterate over the Towers variable when
you wanted to draw them.

OK. I got it to draw a tower on the screen, when the user clicks, however, it only draws one instance of the tower. I need it to draw multiple instances of towers, as the player has money. Here is my updated code.

Code:

#include “main.h”
//#include “tower.h”

SDL_Surface* Screen;
SDL_Event event;
TTF_Font* Font;

stack Towers;
int gtowers;

int ThisTime = 0;
int LastTime = 0;
float DeltaTime = 0.0f;

const int WIDTH = 800;
const int HEIGHT = 600;
const int DEPTH = 32;
const char* TITLE = “Tower Defense”;

SDL_Color textColor = {255,255,0};

int TowerHealth = 100;
int Points = 0;

int Money = 1000;
int EnemyHealth = 50;

int Bullet_Damage = 15;
int TowerCost = 200;

SDLKey keyPressed;
SDLKey keyReleased;

bool keysHeld[323] = {false};

bool GameRunning = true;
bool GameOver = false;

SDL_Surface* Backdrop;
SDL_Rect BackdropRect;

SDL_Surface* FPS;
SDL_Rect FPSRect;
char fps[10];

SDL_Surface* POINT;
SDL_Rect POINTRect;
char point[10];

int Damage_Frames;
int Current_Frame;
const int Total_Frames = 4;

SDL_Surface* HEALTH;
SDL_Rect HealthRect;
char health[10];

SDL_Surface* MONEY;
SDL_Rect MoneyRect;
char money[10];

int mx = 0;
int my = 0;

SDL_Surface* Bullet;
SDL_Rect BulletRect;

SDL_Surface* Enemy;
SDL_Rect EnemyRect;

stack Enemies;
int genemies;

SDL_Surface* Tower;
SDL_Rect TowerRect;

bool GameScreen = true;

int main(int argc, char* argv[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}

Screen = SDL_SetVideoMode(WIDTH,HEIGHT,DEPTH, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption(TITLE,NULL);

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

if(Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096) == -1)
{
    return 1;
}

Backdrop = IMG_Load("Backdrop.png");
BackdropRect.x = 0;
BackdropRect.y = 0;
BackdropRect.w = 800;
BackdropRect.h = 600;

Tower = IMG_Load("Tower.png");
SDL_SetColorKey(Tower,SDL_SRCCOLORKEY,SDL_MapRGB(Tower->format,255,255,255));
TowerRect.x = mx;
TowerRect.y = my;
TowerRect.w = 150;
TowerRect.h = 150;

//Bullet = IMG_Load("Bullet.png");
//SDL_SetColorKey(Bullet,SDL_SRCCOLORKEY,SDL_MapRGB(Bullet->format,255,255,255));

//Enemy = IMG_Load("Enemy.png");
//SDL_SetColorKey(Enemy,SDL_SRCCOLORKEY,SDL_MapRGB(Enemy->format,255,255,255));

Font = TTF_OpenFont("Arial.ttf",20);

FPSRect.x = 1;
FPSRect.y = 1;
FPSRect.w = 0;
FPSRect.h = 0;

POINTRect.x = 1;
POINTRect.y = 20;
POINTRect.w = 0;
POINTRect.h = 0;

HealthRect.x = 1;
HealthRect.y = 40;
HealthRect.w = 0;
HealthRect.h = 0;

MoneyRect.x = 1;
MoneyRect.y = 60;
MoneyRect.w = 0;
MoneyRect.h = 0;

while(GameRunning)
{
    ThisTime = SDL_GetTicks();
    DeltaTime = (float)(ThisTime - LastTime) / 1000 / 30;
    LastTime = ThisTime;

    sprintf(fps,"FPS: %.4f", DeltaTime);
    FPS = TTF_RenderText_Solid(Font,fps,textColor);

    sprintf(point,"Points: %.2d", Points);
    POINT = TTF_RenderText_Solid(Font,point,textColor);

    sprintf(health,"Health: %.3d",TowerHealth);
    HEALTH = TTF_RenderText_Solid(Font,health,textColor);

    sprintf(money,"Money: %.4d",Money);
    MONEY = TTF_RenderText_Solid(Font,money,textColor);

    while(SDL_PollEvent(&event))
    {
        if(event.type == SDL_QUIT)
        {
            GameRunning = false;
        }

        if(event.type == SDL_KEYDOWN)
        {
            keyPressed = event.key.keysym.sym;
            keysHeld[event.key.keysym.sym] = true;

            if(keyPressed == SDLK_ESCAPE)
            {
                GameRunning = false;
            }
        }

        if(event.type == SDL_KEYUP)
        {
            keyReleased = event.key.keysym.sym;
            keysHeld[event.key.keysym.sym] = false;
        }

        if(event.type == SDL_MOUSEMOTION)
        {
            mx = event.motion.x;
            my = event.motion.y;
        }

        if(event.type == SDL_MOUSEBUTTONDOWN)
        {
            if(event.button.button == SDL_BUTTON_LEFT)
            {
                mx = event.button.x;
                my = event.button.y;

                Money -= TowerCost;

                if(Money != 0)
                {
                    Towers.push(gtowers);
                }
            }
        }
    }

    //SDL_FillRect(Screen,NULL,SDL_MapRGB(Screen->format,0,0,0));
    SDL_BlitSurface(Backdrop,NULL,Screen,&BackdropRect);
    SDL_BlitSurface(FPS,NULL,Screen,&FPSRect);
    if(Towers.size() > 0)
    {
        SDL_BlitSurface(Tower,NULL,Screen,&TowerRect);
    }
    SDL_BlitSurface(POINT,NULL,Screen,&POINTRect);
    SDL_BlitSurface(HEALTH,NULL,Screen,&HealthRect);
    SDL_BlitSurface(MONEY,NULL,Screen,&MoneyRect);

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

SDL_FreeSurface(MONEY);
SDL_FreeSurface(HEALTH);
SDL_FreeSurface(FPS);
SDL_FreeSurface(Backdrop);
SDL_FreeSurface(POINT);

TTF_CloseFont(Font);
TTF_Quit();
Mix_CloseAudio();
SDL_Quit();

return 0;

}

Note: looking up the current email via the mailing list archive, so no
headers this time.

Once again, what is this:

stack Towers;
int gtowers;

supposed to do? This:

            if(event.button.button == SDL_BUTTON_LEFT)
            {
                mx = event.button.x;
                my = event.button.y;

                Money -= TowerCost;

                if(Money != 0)
                {
                    Towers.push(gtowers);
                }
            }

makes it look like you expect Towers to store useful data, but it
doesn’t! All that you’re doing with Towers is storing some
unpredictable value into it. If you want to display multiple towers,
then you need to store their positions. At this point in time, you are
NOT doing that. Towers is the obvious place to store the positions of
your towers, but you need to be storing event.button.x &
event.button.y into it (note: two numbers, so the current template
argument to Towers is the wrong type), instead of storing whatever
random value happens to be in gtowers.

As for displaying the towers, this is in the right place:

    if(Towers.size() > 0)
    {
        SDL_BlitSurface(Tower,NULL,Screen,&TowerRect);
    }

but you need some iteration code there, so that you can iterate
through all of the tower information that you SHOULD BE storing, but
currently aren’t.

Phrases you need to research:
Template argument
Iteration

Your stack needs to hold a Tower object, so change it to this:

Code:
stack Towers;

You’ll need to create a Tower class / object that can hold an x and y integer.

You then need to add a new tower to the stack when you click the mouse, so something like this

Code:
if (event.type == SDL_MOUSEBUTTONDOWN)
{
if(event.button.button == SDL_BUTTON_LEFT)
{
mx = event.button.x;
my = event.button.y;

    /* Enough money to add a new tower? */

    if (Money - TowerCost >= 0)
    {
    	/* Take away the money */
    
    	Money -= TowerCost;
    	
    	/* Create a new tower */
    	
    	Tower tower = new Tower();
    	
    	/* Set its x and y to the mouse coordinates */
    	
    	t.x = mx;
    	t.y = my;
    	
    	/* Add it to the array */
    
	Towers.push(tower);
    }
}

}

When you go to draw the towers, iterate through your stack (I don’t know how you do this), get each tower out and draw it to the screen based upon its x and y coordinates:

Code:
if (Towers.size() > 0)
{
/* Begin iterator */

Tower tower = (Next value from the iterator)

/* Blit the image according to the tower's coordinates */

TowerRect.x = tower.x;
TowerRect.y = tower.y;
TowerRect.w = 150;
TowerRect.h = 150;

SDL_BlitSurface(Tower,NULL,Screen,&TowerRect); 

/* End iterator */

}

Does this make sense?------------------------
The Legend of Edgar. A 2D platformer for Windows and Linux. (http://www.parallelrealities.co.uk/p/legend-of-edgar.html)

Yes it makes sense. I will try and add iteration and try this.

None of this has to do with SDL, can this be moved elsewhere? I don’t mean
to be rude, but at this point it seems people are tutoring on general
concepts of C/C++ and game development and the relevance to SDL is none.

PatrickOn Mon, Mar 26, 2012 at 1:29 PM, GameCoder <g_andy at live.com> wrote:

**
Yes it makes sense. I will try and add iteration and try this.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

OK I know this dosen’t relate to SDL anymore, and is more of a C++ thing now, but I would like one piece of help before I go on. I have made the vectors and the iterations, however when it is placed on the screen, it only moves the tower to the mouse coordinates, it dosen’t make multiple instances of towers, as it should. What I am doing wrong?

Code:

#include “main.h”
//#include “tower.h”

SDL_Surface* Screen;
SDL_Event event;
TTF_Font* Font;

vector Towers;
int gtowers;

int ThisTime = 0;
int LastTime = 0;
float DeltaTime = 0.0f;

const int WIDTH = 800;
const int HEIGHT = 600;
const int DEPTH = 32;
const char* TITLE = “Tower Defense”;

SDL_Color textColor = {255,255,0};

int TowerHealth = 100;
int Points = 0;

int Money = 1000;
int EnemyHealth = 50;

int Bullet_Damage = 15;
int TowerCost = 200;

SDLKey keyPressed;
SDLKey keyReleased;

int towerx,towery;

bool keysHeld[323] = {false};

bool GameRunning = true;
bool GameOver = false;

SDL_Surface* Backdrop;
SDL_Rect BackdropRect;

SDL_Surface* FPS;
SDL_Rect FPSRect;
char fps[10];

SDL_Surface* POINT;
SDL_Rect POINTRect;
char point[10];

int Damage_Frames;
int Current_Frame;
const int Total_Frames = 4;

SDL_Surface* HEALTH;
SDL_Rect HealthRect;
char health[10];

SDL_Surface* MONEY;
SDL_Rect MoneyRect;
char money[10];

int mx = 0;
int my = 0;

SDL_Surface* Bullet;
SDL_Rect BulletRect;

SDL_Surface* Enemy;
SDL_Rect EnemyRect;

stack Enemies;
int genemies;

int enemyx,enemyy;

SDL_Surface* Tower;
SDL_Rect TowerRect;

bool GameScreen = true;

int main(int argc, char* argv[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}

Screen = SDL_SetVideoMode(WIDTH,HEIGHT,DEPTH, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption(TITLE,NULL);

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

if(Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096) == -1)
{
    return 1;
}

Backdrop = IMG_Load("Backdrop.png");
BackdropRect.x = 0;
BackdropRect.y = 0;
BackdropRect.w = 800;
BackdropRect.h = 600;

Tower = IMG_Load("Tower.png");
SDL_SetColorKey(Tower,SDL_SRCCOLORKEY,SDL_MapRGB(Tower->format,255,255,255));

//Bullet = IMG_Load("Bullet.png");
//SDL_SetColorKey(Bullet,SDL_SRCCOLORKEY,SDL_MapRGB(Bullet->format,255,255,255));

//Enemy = IMG_Load("Enemy.png");
//SDL_SetColorKey(Enemy,SDL_SRCCOLORKEY,SDL_MapRGB(Enemy->format,255,255,255));

Font = TTF_OpenFont("Arial.ttf",20);

FPSRect.x = 1;
FPSRect.y = 1;
FPSRect.w = 0;
FPSRect.h = 0;

POINTRect.x = 1;
POINTRect.y = 20;
POINTRect.w = 0;
POINTRect.h = 0;

HealthRect.x = 1;
HealthRect.y = 40;
HealthRect.w = 0;
HealthRect.h = 0;

MoneyRect.x = 1;
MoneyRect.y = 60;
MoneyRect.w = 0;
MoneyRect.h = 0;

while(GameRunning)
{
    ThisTime = SDL_GetTicks();
    DeltaTime = (float)(ThisTime - LastTime) / 1000 / 30;
    LastTime = ThisTime;

    sprintf(fps,"FPS: %.4f", DeltaTime);
    FPS = TTF_RenderText_Solid(Font,fps,textColor);

    sprintf(point,"Points: %.2d", Points);
    POINT = TTF_RenderText_Solid(Font,point,textColor);

    sprintf(health,"Health: %.3d",TowerHealth);
    HEALTH = TTF_RenderText_Solid(Font,health,textColor);

    sprintf(money,"Money: %.4d",Money);
    MONEY = TTF_RenderText_Solid(Font,money,textColor);

    while(SDL_PollEvent(&event))
    {
        if(event.type == SDL_QUIT)
        {
            GameRunning = false;
        }

        if(event.type == SDL_KEYDOWN)
        {
            keyPressed = event.key.keysym.sym;
            keysHeld[event.key.keysym.sym] = true;

            if(keyPressed == SDLK_ESCAPE)
            {
                GameRunning = false;
            }
        }

        if(event.type == SDL_KEYUP)
        {
            keyReleased = event.key.keysym.sym;
            keysHeld[event.key.keysym.sym] = false;
        }

        if(event.type == SDL_MOUSEMOTION)
        {
            mx = event.motion.x;
            my = event.motion.y;
        }

        if(event.type == SDL_MOUSEBUTTONDOWN)
        {
            if(event.button.button == SDL_BUTTON_LEFT)
            {
                mx = event.button.x;
                my = event.button.y;

               if(Money - TowerCost >= 0)
               {
                    Money -= TowerCost;

                    Towers.push_back(gtowers);

                    towerx = mx;
                    towery = my;
               }

            }
        }
    }

    //SDL_FillRect(Screen,NULL,SDL_MapRGB(Screen->format,0,0,0));
    SDL_BlitSurface(Backdrop,NULL,Screen,&BackdropRect);
    SDL_BlitSurface(FPS,NULL,Screen,&FPSRect);

    if(Towers.size() > 0)
    {
        vector <int>::iterator it;

        for(it = Towers.begin(); it < Towers.end(); it++)
        {
            TowerRect.x = towerx;
            TowerRect.y = towery;
            TowerRect.w = 100;
            TowerRect.h = 100;

            SDL_BlitSurface(Tower,NULL,Screen,&TowerRect);
        }
    }

    SDL_BlitSurface(POINT,NULL,Screen,&POINTRect);
    SDL_BlitSurface(HEALTH,NULL,Screen,&HealthRect);
    SDL_BlitSurface(MONEY,NULL,Screen,&MoneyRect);

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

SDL_FreeSurface(MONEY);
SDL_FreeSurface(HEALTH);
SDL_FreeSurface(FPS);
SDL_FreeSurface(Backdrop);
SDL_FreeSurface(POINT);

TTF_CloseFont(Font);
TTF_Quit();
Mix_CloseAudio();
SDL_Quit();

return 0;

}

Hi,
I’m not a C++ expert, but it doesn’t look to me like you’re saving the
coordinates of each individual tower, you’re just saving the latest one,
so you’re blitting them all in the same location.

I’d suggest that your ‘Towers’ vector needs to have the coordinates
pushed onto it, and then iterated over in your blit iterator at the bottom.

Use something like:

struct Coordinate
{
int x, y;

Coordiate(int paramx, int paramy) : x(paramx), y(paramy) {}

};

std::vector Towers;

Towers.push_back(Coordinate(x, y));

Then when you iterate over it, you can cast it & get the x/y coordinates
out for the blit location.

Regards,
AndreOn 27/03/12 13:44, GameCoder wrote:

OK I know this dosen’t relate to SDL anymore, and is more of a C++ thing
now, but I would like one piece of help before I go on. I have made the
vectors and the iterations, however when it is placed on the screen, it
only moves the tower to the mouse coordinates, it dosen’t make multiple
instances of towers, as it should. What I am doing wrong?

Code:

#include “main.h”
//#include “tower.h”

SDL_Surface* Screen;
SDL_Event event;
TTF_Font* Font;

vector Towers;
int gtowers;

int ThisTime = 0;
int LastTime = 0;
float DeltaTime = 0.0f;

const int WIDTH = 800;
const int HEIGHT = 600;
const int DEPTH = 32;
const char* TITLE = “Tower Defense”;

SDL_Color textColor = {255,255,0};

int TowerHealth = 100;
int Points = 0;

int Money = 1000;
int EnemyHealth = 50;

int Bullet_Damage = 15;
int TowerCost = 200;

SDLKey keyPressed;
SDLKey keyReleased;

int towerx,towery;

bool keysHeld[323] = {false};

bool GameRunning = true;
bool GameOver = false;

SDL_Surface* Backdrop;
SDL_Rect BackdropRect;

SDL_Surface* FPS;
SDL_Rect FPSRect;
char fps[10];

SDL_Surface* POINT;
SDL_Rect POINTRect;
char point[10];

int Damage_Frames;
int Current_Frame;
const int Total_Frames = 4;

SDL_Surface* HEALTH;
SDL_Rect HealthRect;
char health[10];

SDL_Surface* MONEY;
SDL_Rect MoneyRect;
char money[10];

int mx = 0;
int my = 0;

SDL_Surface* Bullet;
SDL_Rect BulletRect;

SDL_Surface* Enemy;
SDL_Rect EnemyRect;

stack Enemies;
int genemies;

int enemyx,enemyy;

SDL_Surface* Tower;
SDL_Rect TowerRect;

bool GameScreen = true;

int main(int argc, char* argv[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}

Screen = SDL_SetVideoMode(WIDTH,HEIGHT,DEPTH, SDL_HWSURFACE |

SDL_DOUBLEBUF);
SDL_WM_SetCaption(TITLE,NULL);

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

if(Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096) == -1)
{
    return 1;
}

Backdrop = IMG_Load("Backdrop.png");
BackdropRect.x = 0;
BackdropRect.y = 0;
BackdropRect.w = 800;
BackdropRect.h = 600;

Tower = IMG_Load("Tower.png");

SDL_SetColorKey(Tower,SDL_SRCCOLORKEY,SDL_MapRGB(Tower->format,255,255,255));

//Bullet = IMG_Load("Bullet.png");

//SDL_SetColorKey(Bullet,SDL_SRCCOLORKEY,SDL_MapRGB(Bullet->format,255,255,255));

//Enemy = IMG_Load("Enemy.png");

//SDL_SetColorKey(Enemy,SDL_SRCCOLORKEY,SDL_MapRGB(Enemy->format,255,255,255));

Font = TTF_OpenFont("Arial.ttf",20);

FPSRect.x = 1;
FPSRect.y = 1;
FPSRect.w = 0;
FPSRect.h = 0;

POINTRect.x = 1;
POINTRect.y = 20;
POINTRect.w = 0;
POINTRect.h = 0;

HealthRect.x = 1;
HealthRect.y = 40;
HealthRect.w = 0;
HealthRect.h = 0;

MoneyRect.x = 1;
MoneyRect.y = 60;
MoneyRect.w = 0;
MoneyRect.h = 0;

while(GameRunning)
{
    ThisTime = SDL_GetTicks();
    DeltaTime = (float)(ThisTime - LastTime) / 1000 / 30;
    LastTime = ThisTime;

    sprintf(fps,"FPS: %.4f", DeltaTime);
    FPS = TTF_RenderText_Solid(Font,fps,textColor);

    sprintf(point,"Points: %.2d", Points);
    POINT = TTF_RenderText_Solid(Font,point,textColor);

    sprintf(health,"Health: %.3d",TowerHealth);
    HEALTH = TTF_RenderText_Solid(Font,health,textColor);

    sprintf(money,"Money: %.4d",Money);
    MONEY = TTF_RenderText_Solid(Font,money,textColor);

    while(SDL_PollEvent(&event))
    {
        if(event.type == SDL_QUIT)
        {
            GameRunning = false;
        }

        if(event.type == SDL_KEYDOWN)
        {
            keyPressed = event.key.keysym.sym;
            keysHeld[event.key.keysym.sym] = true;

            if(keyPressed == SDLK_ESCAPE)
            {
                GameRunning = false;
            }
        }

        if(event.type == SDL_KEYUP)
        {
            keyReleased = event.key.keysym.sym;
            keysHeld[event.key.keysym.sym] = false;
        }

        if(event.type == SDL_MOUSEMOTION)
        {
            mx = event.motion.x;
            my = event.motion.y;
        }

        if(event.type == SDL_MOUSEBUTTONDOWN)
        {
            if(event.button.button == SDL_BUTTON_LEFT)
            {
                mx = event.button.x;
                my = event.button.y;

               if(Money - TowerCost >= 0)
               {
                    Money -= TowerCost;

                    Towers.push_back(gtowers);

                    towerx = mx;
                    towery = my;
               }

            }
        }
    }

    //SDL_FillRect(Screen,NULL,SDL_MapRGB(Screen->format,0,0,0));
    SDL_BlitSurface(Backdrop,NULL,Screen,&BackdropRect);
    SDL_BlitSurface(FPS,NULL,Screen,&FPSRect);

    if(Towers.size() > 0)
    {
        vector ::iterator it;

        for(it = Towers.begin(); it < Towers.end(); it++)
        {
            TowerRect.x = towerx;
            TowerRect.y = towery;
            TowerRect.w = 100;
            TowerRect.h = 100;

            SDL_BlitSurface(Tower,NULL,Screen,&TowerRect);
        }
    }

    SDL_BlitSurface(POINT,NULL,Screen,&POINTRect);
    SDL_BlitSurface(HEALTH,NULL,Screen,&HealthRect);
    SDL_BlitSurface(MONEY,NULL,Screen,&MoneyRect);

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

SDL_FreeSurface(MONEY);
SDL_FreeSurface(HEALTH);
SDL_FreeSurface(FPS);
SDL_FreeSurface(Backdrop);
SDL_FreeSurface(POINT);

TTF_CloseFont(Font);
TTF_Quit();
Mix_CloseAudio();
SDL_Quit();

return 0;

}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Bluewater Systems - An Aiotec Company

Andre Renaud
@Andre_Renaud 5 Amuri Park, 404 Barbadoes St
www.bluewatersys.com PO Box 13 889, Christchurch 8013
www.aiotec.co.nz New Zealand
Phone: +64 3 3779127 Freecall: Australia 1800 148 751
Fax: +64 3 3779135 USA 1800 261 2934

OK I know this dosen’t relate to SDL anymore, and is more of a
C++ thing now, but I would like one piece of help before I go on.
I have made the vectors and the iterations, however when it is
placed on the screen, it only moves the tower to the mouse
coordinates, it dosen’t make multiple instances of towers, as it
should. What I am doing wrong?

? ? ? ? if(Towers.size() > 0)
? ? ? ? {
? ? ? ? ? ? vector ::iterator it;

? ? ? ? ? ? for(it = Towers.begin(); it < Towers.end(); it++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? TowerRect.x = towerx;
? ? ? ? ? ? ? ? TowerRect.y = towery;
? ? ? ? ? ? ? ? TowerRect.w = 100;
? ? ? ? ? ? ? ? TowerRect.h = 100;

? ? ? ? ? ? ? ? SDL_BlitSurface(Tower,NULL,Screen,&TowerRect);
? ? ? ? ? ? }
? ? ? ? }

You are drawing multiple towers, they just happen to all be blitting
to the exact same spot on the screen. You need save the x,y position
of each tower and then update the appropriate one on the mouse click.

Regards,
HartleyOn Monday, March 26, 2012 5:44 PM, GameCoder wrote:

OK I get what you’re saying, but could you give me a visual example? I need to see it done, before I can underatand, yes I’m a visual learner, no joke.

Message-ID: <1332809042.m2f.32392 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

OK I know this dosen’t relate to SDL anymore, and is more of a C++ thing
now, but I would like one piece of help before I go on. I have made the
vectors and the iterations, however when it is placed on the screen, it only
moves the tower to the mouse coordinates, it dosen’t make multiple instances
of towers, as it should. What I am doing wrong?

Once again what does this:

                    Towers.push_back(gtowers);

do?

Go read this email THAT I ALREADY SENT:
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2012-March/084256.html

For at least 3 emails I have tried to get you to pay attention to this
issue, and you didn’t seem to notice even once.

Different post, that I haven’t gotten the digest for yet:

OK I get what you’re saying, but could you give me a visual example? I need
to see it done, before I can underatand, yes I’m a visual learner, no joke.

No, you need to actually learn it yourself (more importantly, with
every post you seem to me more like someone trying to get other people
to do his homework for him). The link I posted above describes most of
what you are doing wrong. To summarize: you aren’t storing the
location data from the clicks. What you ARE storing is something that
does absolutely nothing useful.

Once you start storing that position info, THEN you can display the towers.> Date: Mon, 26 Mar 2012 17:44:02 -0700

From: “GameCoder” <g_andy at live.com>
To: sdl at lists.libsdl.org
Subject: Re: [SDL] Blitting Image With Mouse Click