Question:
What's the way(s) to trigger an event in C++?
Change of Words ●๋•κℓaท dε saทтσš●๋•
2012-04-30 19:32:16 UTC
A_A
Three answers:
Shaithias
2012-04-30 19:43:55 UTC
include

#include

#include

#include

#include

#include

#include

#include

#include

#include



using namespace std;

/* classes */



int main(int argc,char **argv)



while(SDL_PollEvent(&event))

{

switch(event.type)

{

case SDL_QUIT:

run=1;

break;

case SDL_MOUSEBUTTONDOWN:

{

mouseclick(event,select,starships,loop_skip,missiles);

}

break;

case SDL_KEYDOWN:

if(event.key.keysym.sym == SDLK_m)

{

if(!musicPlaying)

{

Mix_PlayMusic(gameMusic,-1);

musicPlaying=!musicPlaying;

}

else

{

Mix_HaltMusic();

musicPlaying=!musicPlaying;

}

}

break;

}

}

void mouseclick(SDL_Event &event,selected_object &select, vector & starships,int &loop_skip,vector & missiles)

{

string MISSILE="MISSILE";

int mouse_press_x;

int mouse_press_y;

int accelx,accely;

unsigned int i=0;

float x=-1000;

float y=-1000;





if((event.button.button==SDL_BUTTON_LEFT)&&(select.select==true))

{

mouse_press_x=event.button.x;

mouse_press_y=event.button.y;

for (i=0;i
{

x=starships[i].x;

y=starships[i].y;

if(((click_compare(x,y,mouse_press_x,mouse_press_y,starships)==true)))

{

for(unsigned int j=0;j
{

if (starships[j].image_name=="pictures/selected.bmp")

{

select.j_carry=j;

break;

}

}

if(select.i_carry!=i)

{

if (starships[select.i_carry].x
accelx=30;

else

accelx=-30;

if (starships[select.i_carry].y
accely=30;

else

accely=-30;



starship unit("pictures/missile.bmp",(starships[select.i_carry].x+accelx+30),(starships[select.i_carry].y+accely)+30);

unit.modify((starships[i].x)+50, (starships[i].y)+50,"overload_LOL!!!");

unit.type="MISSILE";

missiles.push_back(unit);

}

loop_skip=i;

i=starships.size();

}

else

{

starships[loop_skip].modify(mouse_press_x-50,mouse_press_y-50);

}

}

}



else if(event.button.button==SDL_BUTTON_LEFT)

{

mouse_press_x=event.button.x;

mouse_press_y=event.button.y;

for (i=0;i
{

x=starships[i].x;

y=starships[i].y;

if(((click_compare(x,y,mouse_press_x,mouse_press_y,starships)==true)))

{

select.select=true;

select.i_carry=i;

for(unsigned int j=0;j
{

starships[j].modify_image("pictures/unselected.bmp");

select.j_carry=j;

}

starships[i].modify_image("pictures/selected.bmp");

loop_skip=i;

i=starships.size();

}

//if(((click_compare(x,y,mouse_press_x,mouse_press_y)==false))&&(select.select==true))

//{

// starships[loop_skip].modify(mouse_press_x-50,mouse_press_y-50);

//}

}

}



else //right button

{

loop_skip=0;

select.select=false;

std::cout << select.select<
for(unsigned int j=0;j
{

starships[j].modify_image("pictures/unselected.bmp");

}

}





}

selected_object selection(selected_object j)

{

return j;

}



bool click_compare(int x, int y, int mx, int my,vector &starships)

{

int width=starships[1].image->w;

int height=starships[1].image->h;

bool compare=false;

if (((mx>x-1)&&(mxy-1)&&(my
compare=true;

return compare;

}
Pipsy
2012-05-01 16:17:34 UTC
You Speak English well, little brother



hehehehehehhe nwn
Dennis
2012-05-01 04:29:04 UTC
I have gone through your question - I want to share: http://msdn.microsoft.com/en-us/library/windows/desktop/aa446886%28v=vs.85%29.aspx -- I could not write the whole answer for its length. Please go through that page and hopefully you will get your answer.



Best of Luck.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...