BITMAP *tower = load_bitmap ("Data/square.bmp",NULL); BITMAP *tow[7];
tow[0]=tower;
tow[1]=tower; while (!key[KEY_ESC])
{
//check if mouse button one is clicked
getMouseInfo();
mouseclick=mouse_b;
if (mouseclick == 1 && cursor_x <= 663 && cursor_x >= 623 && cursor_y >= 283 && cursor_y <= 323)
{
menu_towerclick=1;
}
else if (mouseclick == 1 && menu_towerclick == 1)
{
menu_towerclick=0;
placetower=1;
placetower2++;
} if (placetower == 1)
{
static int static_x=mouse_x,static_y=mouse_y;
draw_sprite(buffer, tow[0], static_x, static_y);
}
if (placetower2 == 2)
{
static int static_x=mouse_x,static_y=mouse_y;
draw_sprite(buffer, tow[1], static_x, static_y); if (menu_towerclick != 1) //only show mouse if no item selected
{
draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y); //!Alternate Mouse Draw to avoid graphics glitches!
}
blit(buffer,screen,0,0,0,0,800,600); //DRAW BUFFER
release_screen(); //RELEASE SCREEN
C++/allegro tower defence question
I'm trying to place multiple towers with the same image, so far I managed to figure out how to place two.
Also this is being done with the mouse pointer, here is some code I tried to test it out.
// A tower object can look like this.Class Tower{ int x,y; // X and Y position of the tower BITMAP *img; // A pointer to the tower image.};/*If there is a max number of towers that can be placed then just declare an array of tower objects.*/Tower towers[MAX];/*If there is not a limit to how many towers can be placed or very many towers can be placed, then you can create new tower objects as they are needed, using a data structure of your choice, such as a vector.*/vector<Tower> towers;//Then in your drawing function just iterate through the vector and draw all the towers that are in it.for(int i=0;i<towers.size();i++) draw_sprite(buffer,towers.img,towers.x,towers.y)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement