|
Main Page Data Structures File List Globals
process_input.c File ReferenceConverts mouse_drag messages into game moves or button presses.
More...
#include "white_interface.h"
#include "e:\AndrewWorkspace\Stratego\input.h"
Go to the source code of this file.
Detailed Description
Converts mouse_drag messages into game moves or button presses.
This block receives mouse_drag messages from the receive_input block, which tell it where the user has dragged the mouse on the screen. It reads these messages and decides what the user was inteding to do. For example, they may have been placing a piece on the game board, moving an existing piece from one square to another or clicking one of the buttons at the bottom of the screen. Messages are then send to the output_move or output_button blocks, which will send move or button messages to the game core.
Definition in file process_input.c.
Function Documentation
int calc_x_square |
( |
int |
x, |
|
|
int |
square_width |
|
) |
|
|
|
Calculates the x value of the board square at the supplied screen coordinates.
-
Parameters:
-
x |
The x screen coordinate for which you need the corresponding grid square number. |
square_width |
The width of one board square (in screen pixels). |
-
Returns:
-
an integer specifying the x value of the board square.
Definition at line 235 of file process_input.c.
Referenced by process_button, process_move, and process_placing.
00236 {
00237 return (x / square_width);
00238 }
|
int calc_y_square |
( |
int |
y, |
|
|
int |
square_height, |
|
|
int |
zero_pixel |
|
) |
|
|
|
Calculates the y value of the board square at the supplied screen coordinates.
-
Parameters:
-
y |
The y screen coordinate for which you need the corresponding grid square number. |
square_height |
The height of one board square (in screen pixels). |
zero_pixel |
The y screen coordinate of the bottom edge of the row of squares with y value 0. |
-
Returns:
-
an integer specifying the y value of the board square.
Definition at line 241 of file process_input.c.
Referenced by process_move, and process_placing.
00242 {
00243 int new_y;
00244 int square;
00245
00246
00247
00248 new_y = y - zero_pixel;
00249
00250
00251 square = new_y / square_height;
00252
00253
00254
00255
00256 if (new_y < 0 && new_y % square_height != 0)
00257 square = square - 1;
00258
00259 return (square);
00260 }
|
|
VCC Init function.
This function runs when the VCC simulation is first started.
Definition at line 95 of file process_input.c.
|
|
VCC Run function.
This runs whenever a message arrives at the process_input block's in port.
Definition at line 103 of file process_input.c.
References BOARD_PLACE_BOUNDARY, down_x, down_y, PLACE_BUTTONS_BOUNDARY, process_button, process_move, process_placing, SCREEN_HEIGHT, SCREEN_WIDTH, up_x, and up_y.
|
void process_button |
( |
void |
|
) |
|
|
void process_move |
( |
void |
|
) |
|
|
|
Determines the starting and finishing board squares of a move.
process_move examines the start and end coordinates of where the user dragged the mouse and calculates the starting and finishing board squares. If the move is legal (i.e. between 2 different squares that fit on the screen) a temp_move message is sent to the output_move block. Otherwise the move is ignored.
Definition at line 146 of file process_input.c.
References BOARD_HEIGHT, BOARD_PLACE_BOUNDARY, BOARD_WIDTH, BOARD_X_SQUARES, BOARD_Y_SQUARES, calc_x_square, calc_y_square, down_x, down_y, up_x, and up_y.
Referenced by poin_entry_Run.
00147 {
00148 int start_x_square, start_y_square, end_x_square, end_y_square;
00149 int square_width, square_height;
00150
00151 temp_move move;
00152
00153
00154 square_width = BOARD_WIDTH / BOARD_X_SQUARES;
00155 square_height = BOARD_HEIGHT / BOARD_Y_SQUARES;
00156
00157
00158
00159
00160 start_x_square = calc_x_square(down_x, square_width);
00161 end_x_square = calc_x_square(up_x, square_width);
00162
00163 start_y_square = calc_y_square(down_y, square_height, BOARD_PLACE_BOUNDARY);
00164 end_y_square = calc_y_square(up_y, square_height, BOARD_PLACE_BOUNDARY);
00165
00166
00167
00168
00169 if ((start_x_square != end_x_square) || (start_y_square != end_y_square))
00170 {
00171 move.start_x = start_x_square;
00172 move.start_y = start_y_square;
00173 move.end_x = end_x_square;
00174 move.end_y = end_y_square;
00175 move_out_Post(&move);
00176 }
00177 }
|
void process_placing |
( |
void |
|
) |
|
|
|
Determines the starting square in the placing panel and the finishing square on the main game board.
process_placing examines the start and end coordinates of where the user dragged the mouse and calculates the starting square on the placing panel and the finishing square on the main game board. A piece must be dragged from the placing panel to the main board. If it is dropped somewhere else on the placing panel or on a button the placing will be ignored. If the placing is legal, a temp_move message will be send to the output_move block. Note that the starting square y value is negative to indicate that it refers to a square on the placing panel.
Definition at line 180 of file process_input.c.
References BOARD_HEIGHT, BOARD_PLACE_BOUNDARY, BOARD_WIDTH, BOARD_X_SQUARES, BOARD_Y_SQUARES, calc_x_square, calc_y_square, down_x, down_y, PLACE_HEIGHT, PLACE_WIDTH, PLACE_X_SQUARES, PLACE_Y_SQUARES, up_x, and up_y.
Referenced by poin_entry_Run.
00181 {
00182 int start_x_square, start_y_square, end_x_square, end_y_square;
00183 int board_square_width, board_square_height;
00184 int place_square_width, place_square_height;
00185
00186 temp_move placing;
00187
00188
00189 board_square_width = BOARD_WIDTH / BOARD_X_SQUARES;
00190 board_square_height = BOARD_HEIGHT / BOARD_Y_SQUARES;
00191 place_square_width = PLACE_WIDTH / PLACE_X_SQUARES;
00192 place_square_height = PLACE_HEIGHT / PLACE_Y_SQUARES;
00193
00194
00195
00196 start_x_square = calc_x_square(down_x, place_square_width);
00197 end_x_square = calc_x_square(up_x, board_square_width);
00198
00199 start_y_square = calc_y_square(down_y, place_square_height, BOARD_PLACE_BOUNDARY);
00200 end_y_square = calc_y_square(up_y, board_square_height, BOARD_PLACE_BOUNDARY);
00201
00202
00203
00204 placing.start_x = start_x_square;
00205 placing.start_y = start_y_square;
00206 placing.end_x = end_x_square;
00207 placing.end_y = end_y_square;
00208 move_out_Post(&placing);
00209 }
|
Variable Documentation
|
|