Sign in to follow this  

making window move with C++ and allegro

This topic is 3041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So i am making a small game where objects fly at you and you have to point the mouse and click on them to "shoot" them before they hit you. Each object will start small and get bigger and bigger to look like it is flying at you. For the effect of hitting the player i got the idea of making the whole window "vibrate" by quickly moving the window back and forth and up and down a little bit. This game will not be full screen and just an open window on the computer. Using C++ and allegro how do i control the actual window the game is in? I'm am using windows. Thanks.

Share this post


Link to post
Share on other sites
Include winalleg.h and you can use the win_get_window function, to retrieve a HWND handle to the window. Then use SetWindowPos to change its position.

Simple example:

#include <allegro.h>
#include <winalleg.h>

#pragma comment (lib, "alleg.lib")

int main(int argc, char* argv[]) {
allegro_init();
install_timer();
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);

HWND hWnd = win_get_window();

RECT rect;
GetWindowRect(hWnd, &rect);

for(int i=0;i<100;i++) {
SetWindowPos(
hWnd,
NULL,
rect.left + rand()%5,
rect.top + rand()%5,
0,
0,
SWP_NOSIZE
);

rest(100);
}

return 0;
} END_OF_MAIN();

Share this post


Link to post
Share on other sites

This topic is 3041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this