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
|
#include "main.h"
void gravity(GameState *gameState)
{
gameState->man.y += gameState->man.dy;
gameState->man.dy += GRAVEDAD;
}
int main(int argc, char *argv[])
{
GameState gameState;
SDL_Window *window = NULL; // Declare a window
SDL_Renderer *renderer = NULL; // Declare a renderer
SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
gameState.man.x = 44;
gameState.man.y = 100;
gameState.man.dy = 0;
gameState.man.dx = 0;
gameState.man.w = 42;
gameState.man.h = 53;
gameState.salto = 0;
gameState.man.facing_left = 0;
for(int i = 0; i < 3; i++)
{
gameState.camara[i].x = i*43 + 1;
gameState.camara[i].y = 1;
gameState.camara[i].w = gameState.man.w;
gameState.camara[i].h = gameState.man.h;
}
for (int i; i < NUM_CAJAS; i++)
{
gameState.suelo[i].x = i*44;
gameState.suelo[i].y = 400;
gameState.suelo[i].w = 44;
gameState.suelo[i].h = 44;
}
gameState.suelo[9].x = 0;
gameState.suelo[9].y = 356;
gameState.suelo[8].x = 0;
gameState.suelo[8].y = 312;
//Create an application window with the following settings:
window = SDL_CreateWindow("Game Window", // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
640, // width, in pixels
480, // height, in pixels
0 // flags
);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if(window == NULL || renderer == NULL)
{
printf("SDL no pudo ejecutarse o no esta instalado");
}
gameState.renderer = renderer;
loadScreen(&gameState,renderer);
// The window is open: enter program loop (see SDL_PollEvent)
int done = 0;
//Event loop
while(!done)
{
//Check for events
done = processEvents(window, &gameState);
///Ejecutar gravedad
gravity(&gameState);
///Deteccion de Coliciones
collisionDetect(&gameState);
if(gameState.i / 3 >= 3)
gameState.i = 0;
//Render display
doRender(renderer, &gameState);
if(gameState.man.walking == 1)
{
gameState.i++;
gameState.man.walking = 0;
}
else
gameState.i = 0;
}
SDL_DestroyTexture(gameState.player);
// Close and destroy the window
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
// Clean up
SDL_Quit();
return 0;
}
|