-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
65 lines (51 loc) · 1.25 KB
/
main.cpp
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
#include<SDL/SDL_mixer.h>
#include "snake.h"
int main()
{
bool running;
int fps;
Mix_Music *music;
snake s(840,640,20);
Uint32 start;
while(1)
{
s.Init();
fps=6;
//Intro
Mix_OpenAudio(22050,AUDIO_S16SYS,2,128);
music=Mix_LoadMUS("Music/stronger.mp3");
Mix_PlayMusic(music,-1);
music=Mix_LoadMUS("Music/snake.wav");
s.Draw_Bg();
s.WaitKey();
Mix_PlayMusic(music,-1);
s.Draw_Bg();
s.Ready();
s.Fill_Screen();
SDL_Delay(2000);
running=true;
while(running)
{
start=SDL_GetTicks();
running=s.Go_To();
s.Draw_Bg();
s.Draw_Border();
s.Draw_Score();
s.Draw_Food(&fps);
s.Draw_Node();
s.Fill_Screen();
if(1000/fps>(int)(SDL_GetTicks()-start))
SDL_Delay(1000/fps -SDL_GetTicks() +start);
}
Mix_FreeMusic(music);
music=Mix_LoadMUS("Music/game_over.wav");
Mix_PlayMusic(music,-1);
SDL_Delay(800);
s.Draw_Bg();
s.Game_Over();
s.Fill_Screen();
SDL_Delay(4000);
Mix_FreeMusic(music);
Mix_CloseAudio();
}
}