📄 event.c
字号:
/************************/
/* 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -