-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
75 lines (54 loc) · 1.72 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <stdbool.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_ttf.h>
#include "tetris.h"
#include "render.h"
#include "util.h"
#include "random.h"
#include "scores.h"
#define RES_X 1366
#define RES_y 768
int main() {
srand(time(0));
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
IMG_Init(IMG_INIT_PNG);
TTF_Init();
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
Mix_Music *backgroundsound = Mix_LoadMUS("assets/tetris.wav");
SDL_Window *window = SDL_CreateWindow("Tetris", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1366, 768, SDL_WINDOW_OPENGL);
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
struct tetris_state state;
state.grid = malloc(sizeof(struct tetris_slot) * 16 * 10);
memset(state.grid, 0, sizeof(struct tetris_slot) * 16 * 10);
state.width = 10;
state.height = 16;
state.score = 0;
state.lines = 0;
state.level = 0;
state.res_x = 1366;
state.res_y = 768;
state.last_tick_ms = 0;
state.last_tick = 1;
state.gravity_period = 60;
state.speed_mult = 1;
state.time_stop = false;
state.just_stopped = false;
state.just_resumed = false;
state.time_stop_left = 500;
state.time_stop_max = 500;
state.next = standard_pieces[rand() % 7];
tetris_new_piece(&state);
bool loop = true;
Mix_PlayMusic(backgroundsound, -1);
//-1 plays in loop
while(loop) {
if(!tetris_step(&state)) loop = false;
tetris_render(&state, renderer);
}
Mix_FreeMusic(backgroundsound);
TTF_Quit();
return 0;
}