This repository was archived by the owner on May 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
133 lines (97 loc) · 2.66 KB
/
Main.cpp
File metadata and controls
133 lines (97 loc) · 2.66 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "SDL/include/SDL.h"
#include "SDL_image/include/SDL_image.h"
#include "SDL_mixer/include/SDL_mixer.h"
#pragma comment( lib, "../SDL/libx86/SDL2.lib")
#pragma comment( lib, "../SDL/libx86/SDL2main.lib" )
#pragma comment( lib, "../SDL_image/libx86/SDL2_image.lib")
#pragma comment( lib, "../SDL_mixer/libx86/SDL2_mixer.lib")
#define SCREEN_WIDTH 1280
#define SCREEN_HEIGHT 720
enum game_status
{
GAME_CONTINUE = 1,
GAME_STOP,
GAME_ERROR
};
int main(int argc, char* argv[]) {
//Variables
game_status game_state = GAME_CONTINUE;
SDL_Surface* screen_surface = nullptr;
SDL_Surface* texture_surface = nullptr;
SDL_Surface* char_surface = nullptr;
SDL_Window* window = nullptr;
SDL_Texture* texture = nullptr ;
SDL_Texture* char_texture = nullptr;
SDL_Renderer* renderer = nullptr;
SDL_Rect rect , rect2, section, section2;
Mix_Music *main_music;
const Uint8 *keyboard = nullptr;
//Inits
SDL_Init(SDL_INIT_VIDEO);
IMG_Init(IMG_INIT_PNG);
Mix_Init(MIX_INIT_OGG);
//Window
window = SDL_CreateWindow ("Test",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH,
SCREEN_HEIGHT,
SDL_WINDOW_RESIZABLE);
screen_surface = SDL_GetWindowSurface(window);
//Render
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
//Mixer
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
main_music = Mix_LoadMUS("ugandan_sound.ogg");
Mix_VolumeMusic(40);
//Textures
//Backgroud
texture_surface = IMG_Load("test.png");
texture = SDL_CreateTextureFromSurface(renderer, texture_surface);
section.x = section.y = 0;
section.w = 2560;
section.h = 1707;
rect.x = rect.y = 0;
rect.w = SCREEN_WIDTH;
rect.h = SCREEN_HEIGHT;
//Character
char_surface = IMG_Load("ugandan.png");
char_texture = SDL_CreateTextureFromSurface(renderer, char_surface);
section2.x = section2.y = 0;
section2.w = 300;
section2.h = 300;
rect2.x = SCREEN_WIDTH/2;
rect2.y = SCREEN_HEIGHT/2;
rect2.w = 300;
rect2.h = 300;
Mix_PlayMusic(main_music, 2);
while (game_state == GAME_CONTINUE) {
SDL_PumpEvents();
keyboard = SDL_GetKeyboardState(NULL);
if (keyboard[SDL_SCANCODE_ESCAPE]) {
game_state = GAME_STOP;
}
if (keyboard[SDL_SCANCODE_A]) {
rect2.x -= 4;
}
if (keyboard[SDL_SCANCODE_D]) {
rect2.x += 4;
}
if (keyboard[SDL_SCANCODE_W]) {
rect2.y -= 4;
}
if (keyboard[SDL_SCANCODE_S]) {
rect2.y += 4;
}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, §ion, &rect);
SDL_RenderCopy(renderer, char_texture, §ion2, &rect2);
SDL_RenderPresent(renderer);
}
SDL_Quit();
IMG_Quit();
Mix_CloseAudio();
Mix_Quit();
return 0;
}