📄 main.c
字号:
/************************/
/* Game Project for ACP */
/************************/
/***********************/
/* TETRIS */
/* Thomas Bluteau */
/***********************/
/************************
Main File
************************/
#include <SDL\SDL.h> /* Required by SDL */
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <malloc.h>
#include "CONST_DEFINE.h"
#include "function.h"
int SDL_main(int argc, char *argv[]) {
t_infos infos_globales;
object_t current,prev_current;
mov_t mov;
int previousTime;
/* Initialize the SDL library */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
SDL_WM_SetCaption("TETRIS", NULL);
/* Clean up on exit */
atexit(SDL_Quit);
/*
* Initialize the display in a 640x480 8-bit palettized mode,
* requesting a software surface
*/
infos_globales.screen = SDL_SetVideoMode(ABSMAX, ORDMAX, 8, SDL_SWSURFACE);
if ( infos_globales.screen == NULL ) {
fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
SDL_GetError());
exit(1);
}
init_Variables(&infos_globales,&mov); // The init function
initGround(&infos_globales);
createObjet(&infos_globales,&prev_current,SDL_GetTicks()%NB_PIECE);
while(!infos_globales.endGame){ // Main Loop
swapObject(&prev_current,¤t);
createObjet(&infos_globales,&prev_current,SDL_GetTicks()%NB_PIECE); // Add a piece
drawPrev(&infos_globales,prev_current);
SDL_UpdateRect(infos_globales.screen, prev_current.position_X*SQUARE,prev_current.position_Y*SQUARE, prev_current.x*SQUARE, prev_current.y*SQUARE);
infos_globales.fallCompleted = 0;
infos_globales.current_speed = infos_globales.speed_level;
while(!infos_globales.fallCompleted) // Till the piece is falling
{
previousTime = SDL_GetTicks();
mov.vY=1;
while((SDL_GetTicks() - previousTime)<infos_globales.current_speed) //Timing gestion
{
keyboard_Gest(&infos_globales,&mov); // Catch the controls
moveCurrent(&infos_globales,¤t,&mov); // Apply event
drawGround(&infos_globales); // Draw the game
SDL_UpdateRect(infos_globales.screen, 0, 0, GRID_WIDTH*SQUARE, GRID_HEIGHT*SQUARE); //refresh gaming screen
if(infos_globales.endGame)
break;
}
}
detect_line(&infos_globales); // detect and remove full line
endGame(&infos_globales,current); // Test and of game
free(¤t); //free the space allowed for current
}
SDL_FreeSurface(infos_globales.screen);
SDL_Quit();
return EXIT_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -