megainformatic - Веселый Буквоежка - онлайн комикс - страница 21 Веселый Буквоежка - онлайн комикс - страница 21
представляем Веселый Буквоежка - онлайн комикс.
Я давно уже сам собирался его поменять, да всё времени не было.
3) Learning to control the movement of the scene - so she moved with mouse movements.
To implement the control component DirectInput is used in the game. It is part of DirectX and serves to control the game. The standard is supported by the device keyboard and mouse.
We need something to move around the screen in order to see our actions. Let us first learn how to move around the screen, our jumping ball. And only then will move the action on scene - forcing it to move, but not the ball.
Thus, you will learn several things: how to move around the screen sprites, how to perform control the game through DirectInput and finally, how to move the gaming scene.
In fact, tracking the mouse movements do not even want to use DirectInput. It is, in principle, it can carry out, but you can do without it. DirectInput will be needed mainly for tracking clicks the left mouse button, when we do something linked with it. As long as we do not need it, we leave this question in the near future.
Thus, to track mouse movement in module start.h add the following code
void LoadGameDataBlock();//this code, which must be added after
//move the mouse pointer
void ChangeGameCursorPos(); //is the code that you need to add
And in module start.cpp add
UpdateInput( &m_UserInput ); //this code, which must be added after
//move the mouse pointer
ChangeGameCursorPos(); //is the code that you need to add
and at the very end of the module start.cpp
add the implementation of this method -
LONG cursor_at_window_x = CursorPos.x - rcClip.left;
LONG cursor_at_window_y = CursorPos.y - rcClip.top;
LONG cursor_spr_left_limit = 0;
LONG cursor_spr_top_limit = 0;
LONG cursor_spr_right_limit = (LONG)m_dwScreenWidth;
LONG cursor_spr_bottom_limit = (LONG)m_dwScreenHeight;
if ( cursor_at_window_x < cursor_spr_left_limit )
cursor_at_window_x = cursor_spr_left_limit;
if ( cursor_at_window_x > cursor_spr_right_limit )
cursor_at_window_x = cursor_spr_right_limit;
if ( cursor_at_window_y < cursor_spr_top_limit )
cursor_at_window_y = cursor_spr_top_limit;
if ( cursor_at_window_y > cursor_spr_bottom_limit )
cursor_at_window_y = cursor_spr_bottom_limit;
All - now with the mouse movements of our ball moving with it. What we need, and not for the ball, but for most scenes.
Now you know how to move sprites, it may be useful to you to create other games.
Now disable the movement of the ball with the mouse - to comment out this line of code -
//g_AI_Ball_Sprite.m_v2Pos = m_scrCursorPos;
Save changes to the project, recompile the application. And we see that the ball does not move when you move the mouse.
To implement the move game scene, I think you have guessed, it is necessary to substitute instead of coordinates used for the sprite ball ... right! - To substitute the coordinates of the scene. The only question is how to do it.
If there was a certain object in a scene, and he would have been the property of storing the global position of the scene on the screen, changing which we could achieve the desired effect.
Save changes to the project, recompile the application. And we see that now when you move the mouse moves game scene.
We have achieved the desired !!!
However, as you can see, there are some drawbacks.
1) This is when the scene leaves the screen in its place is empty - blue background.
2) The fact that the ball is not always beautiful falls in a hole. If he is a little below the hole or slightly to the left or to the right - it turns out is not beautiful. Part of the ball overlaps background simulating upper visible part of the hole.
To solve the first problem, you can either increase the size of the stage, or on top of the scene to impose a rectangle with a slot through which is visible only a small part of it.
But to solve the second problem, you can come up with more clever ways. On them will be discussed on the next page. Stay with us ! :)