aboutsummaryrefslogtreecommitdiff
path: root/original/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'original/main.c')
-rw-r--r--original/main.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/original/main.c b/original/main.c
new file mode 100644
index 0000000..1bd96fb
--- /dev/null
+++ b/original/main.c
@@ -0,0 +1,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;
+}