event.c
来自「TETRIS GAME, AUTO-PLAYER AND ARTIFICIAL 」· C语言 代码 · 共 92 行
C
92 行
/************************/
/* Game Project for ACP */
/************************/
/***********************/
/* TETRIS */
/* Thomas Bluteau */
/***********************/
/*********************************************
EVENT.C contains functions to perform action
required by external events.
*********************************************/
#include "function.h"
#include <SDL\SDL.h>
/**********
Manage the keyboard
**********/
void keyboard_Gest(t_infos *infos, mov_t *mov)
{
SDL_Event event;
int Kdown = 0;
while( SDL_PollEvent(&event)) {
switch (event.type)
{
case SDL_KEYDOWN: // When a key is pressed
if (Kdown)
{
switch (event.key.keysym.sym)
{
/* The following case change the movement vector*/
case SDLK_RIGHT:
mov->vX = 1;
break;
case SDLK_LEFT:
mov->vX = -1;
break;
case SDLK_UP:
mov->R = 1;
break;
case SDLK_DOWN:
infos->current_speed = 30;
/* Space key is used to accelrate the fall*/
case SDLK_SPACE:
infos->current_speed = 1;
break;
}
}
else
{
Kdown = 1;
}
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE: // Escape to quit
infos->endGame = 1;
break;
}
case SDL_KEYUP: // When a key is release
if(Kdown) // if it was already pressed
{
Kdown = 0;
switch (event.key.keysym.sym)
{
/* The following case change the movement vector*/
case SDLK_RIGHT:
mov->vX = 1;
break;
case SDLK_LEFT:
mov->vX = -1;
break;
case SDLK_UP:
mov->R = 1;
break;
case SDLK_DOWN:
infos->current_speed = 30;
/* Space key is used to accelrate the fall*/
case SDLK_SPACE:
infos->current_speed = 1;
break;
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?