Compare commits
12 Commits
7e5fb1c83a
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| a182c0f30a | |||
| ade88dff84 | |||
| 9f0a8a2692 | |||
| 6837f227d3 | |||
| 50ec708f9c | |||
| 8b21274d49 | |||
| 2f266c7949 | |||
| c4bb2e8eee | |||
| b5fda06f31 | |||
| 1bea67f658 | |||
| 789873f263 | |||
| f7a2c15717 |
+24
-7
@@ -8,15 +8,28 @@ if(CMAKE_BUILD_TYPE MATCHES DEBUG)
|
||||
add_link_options(-fsanitize=address)
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wmaybe-uninitialized -Wno-unused-variable")
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g -Werror -O0")
|
||||
set(CMAKE_C_FLAGS_RELEASE "")
|
||||
if(EMSCRIPTEN)
|
||||
set(CMAKE_C_FLAGS "-s USE_SDL=2 -s USE_SDL_IMAGE=2 -s USE_SDL_TTF=2 -s USE_SDL_MIXER=2 -s SDL2_IMAGE_FORMATS='[\"png\"]' -s USE_OGG=1 -sALLOW_MEMORY_GROWTH --use-preload-plugins --preload-file assets")
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O2")
|
||||
set(CMAKE_EXECUTABLE_SUFFIX_C ".html")
|
||||
#help with clangd
|
||||
add_definitions(-D__EMSCRIPTEN__ -DEXIT_RUNTIME=1 -DMUSIC_WAV)
|
||||
elseif(MINGW)
|
||||
set(CMAKE_C_FLAGS "-Wno-undef --static")
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O2")
|
||||
else()
|
||||
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wmaybe-uninitialized -Wno-unused-variable")
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g -Werror -O0")
|
||||
set(CMAKE_C_FLAGS_RELEASE "")
|
||||
endif()
|
||||
|
||||
# generate the compile_commands for vscode / clang
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
|
||||
|
||||
# set the project name
|
||||
project(FLOPPE_FION)
|
||||
project(LEGEND_OF_ADAME)
|
||||
|
||||
|
||||
set(SRC
|
||||
@@ -32,13 +45,17 @@ set(SRC
|
||||
)
|
||||
|
||||
# add the executable
|
||||
add_executable(FLOPPE_FION ${SRC})
|
||||
add_executable(LEGEND_OF_ADAME ${SRC})
|
||||
|
||||
|
||||
target_link_libraries(FLOPPE_FION SDL2 SDL2_image SDL2_ttf SDL2_mixer m)
|
||||
target_link_libraries(LEGEND_OF_ADAME SDL2 SDL2_image SDL2_ttf SDL2_mixer m)
|
||||
|
||||
|
||||
set_property(TARGET FLOPPE_FION PROPERTY C_STANDARD 23)
|
||||
set_property(TARGET LEGEND_OF_ADAME PROPERTY C_STANDARD 23)
|
||||
|
||||
|
||||
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR})
|
||||
|
||||
if(MINGW)
|
||||
target_link_libraries(LEGEND_OF_ADAME ws2_32)
|
||||
endif()
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-1
@@ -20,7 +20,7 @@ void cinematic_staticRender(void) {
|
||||
text_renderText(&AdamesLegend, 8, 0.8f, white, "./assets/fonts/Quinquefive.ttf", 40, "Adame est l'eleve modele de Polytech,\n Membre de plusieurs associations il est connu de tous.\n Lors de l'edition 21.2 de la Nantarena,\n Adame s'est retrouve a engeuler des joueurs pour leur demander de mettre leur putain de masque.\n\n L'edition finie, Adame a kidnappe l'ensemble des joueurs qui forcaient pour leur apprendre a respecter l'autorite a coup de coup de pied au cul.\n\n Press space to continue");
|
||||
scene_addRenderObject(&cinematicScene, AdamesLegend, 10, 80);
|
||||
|
||||
music = Mix_LoadMUS("./assets/music/chinese rap.mp3");
|
||||
music = Mix_LoadMUS("./assets/music/chinese rap.ogg");
|
||||
if(music == NULL) {
|
||||
fprintf(stderr, "Chinese rap not found!\n");
|
||||
exit(1);
|
||||
|
||||
+117
-29
@@ -6,14 +6,24 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include "scaller.h"
|
||||
#include "scene.h"
|
||||
#include "text.h"
|
||||
#include "input.h"
|
||||
|
||||
//Web asembly
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define SLIDER_SPEED 1.f/5000
|
||||
#define GRAVITY 10000.f
|
||||
|
||||
static Mix_Music * music;
|
||||
static Mix_Chunk * petMusic;
|
||||
static Mix_Chunk * koMusic;
|
||||
|
||||
|
||||
Scene_t gameScene;
|
||||
|
||||
@@ -36,6 +46,8 @@ RenderObject_t scoreText;
|
||||
static RenderId_t scoreTextId = -1;
|
||||
static int victimHeight;
|
||||
|
||||
static RenderId_t pressSpaceShadowId;
|
||||
static RenderId_t pressSpaceTextId;
|
||||
|
||||
#define VICTIME_COUNT 4
|
||||
#define VICTIME_SIZE 0.5f
|
||||
@@ -56,7 +68,6 @@ static RenderId_t strengthBarId;
|
||||
static float strength = 0.f;
|
||||
static bool increaseStrength = true;
|
||||
|
||||
|
||||
static float adameStrength = 2.f; // this value is not const as it will be possible to improve the strenght of Adame.
|
||||
|
||||
static RenderObject_t strengthBarSlider;
|
||||
@@ -64,26 +75,48 @@ static float strengthBarSliderDistance = 0.f;
|
||||
static RenderId_t strengthBarSliderId;
|
||||
static bool increaseStrengthBarSlider = true;
|
||||
|
||||
#define STEROIDS_POSITION CAMERA_WIDTH * 0.4f
|
||||
#define SLIDER_SPEED ((adameStrength *0.5f)/5000)
|
||||
|
||||
void game_handleFKeyInput(void);
|
||||
|
||||
static RenderId_t backgrounds[2];
|
||||
static int currentBackground = 0;
|
||||
static int backgroundOffset = 0;
|
||||
static int backgroundStep;
|
||||
|
||||
RenderId_t steroidText;
|
||||
|
||||
|
||||
static void playMusic(){
|
||||
music = Mix_LoadMUS("./assets/music/jojo arab.mp3");
|
||||
music = Mix_LoadMUS("./assets/music/game.ogg");
|
||||
if(music == NULL) {
|
||||
fprintf(stderr, "Jojo arab not found!\n");
|
||||
fprintf(stderr, "Game audio not found! %s\n", Mix_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// if(Mix_PlayMusic(music, 0) != 0){
|
||||
// printf("Music sound could not be played!\n"
|
||||
// "SDL_Error: %s\n", Mix_GetError());
|
||||
// Mix_FreeMusic(music);
|
||||
// running = false;
|
||||
// }
|
||||
petMusic = Mix_LoadWAV("./assets/music/pet.ogg");
|
||||
if(petMusic == NULL){
|
||||
fprintf(stderr, "Pet audio not found! %s\n", Mix_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
koMusic = Mix_LoadWAV("./assets/music/ko-effect-gain.ogg");
|
||||
if(koMusic == NULL){
|
||||
fprintf(stderr, "ko effect audio not found %s\n", Mix_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(Mix_PlayMusic(music, -1) != 0){
|
||||
printf("Music sound could not be played!\n"
|
||||
"SDL_Error: %s\n", Mix_GetError());
|
||||
Mix_FreeMusic(music);
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
int game_staticRender(void){
|
||||
input_listenKeyDown(SDL_SCANCODE_F, game_handleFKeyInput);
|
||||
playMusic();
|
||||
srand(time(NULL));
|
||||
|
||||
@@ -92,10 +125,15 @@ int game_staticRender(void){
|
||||
|
||||
SDL_Surface* gameBackgroundSurface = IMG_Load("./assets/img/game_bg.png");
|
||||
if(gameBackgroundSurface == NULL){
|
||||
printf("cannot load background");
|
||||
printf("cannot load background\n");
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_pause_main_loop();
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
SDL_Surface* gameBackgroundSurface2 = IMG_Load("./assets/img/game_bg.png");
|
||||
|
||||
RenderObject_t gameBackground = EMPTY_RENDER_OBJECT;
|
||||
strcpy(gameBackground.name, "gameBackground");
|
||||
@@ -103,7 +141,10 @@ int game_staticRender(void){
|
||||
gameBackground.surface = gameBackgroundSurface;
|
||||
scaller(gameBackground.surface, 1, &gameBackground.width, &gameBackground.height);
|
||||
gameBackground.height = 1;
|
||||
scene_addRenderObject(&gameScene, gameBackground, 0, 0);
|
||||
backgrounds[0] = scene_addRenderObject(&gameScene, gameBackground, 0, 0);
|
||||
gameBackground.surface = gameBackgroundSurface2;
|
||||
backgrounds[1] = scene_addRenderObject(&gameScene, gameBackground, gameBackground.width * CAMERA_WIDTH, 0);
|
||||
backgroundStep = gameBackground.width * CAMERA_WIDTH;
|
||||
|
||||
SDL_Surface* buildingSurface = IMG_Load("./assets/img/building.png");
|
||||
RenderObject_t building = EMPTY_RENDER_OBJECT;
|
||||
@@ -223,7 +264,7 @@ int game_staticRender(void){
|
||||
scoreText = EMPTY_RENDER_OBJECT;
|
||||
strcpy(scoreText.name, "scoreText");
|
||||
SDL_Color black = {0, 0, 0, 255};
|
||||
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %d", (unsigned)jetons);
|
||||
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %lu", (unsigned long)jetons);
|
||||
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||
|
||||
|
||||
@@ -244,21 +285,34 @@ int game_staticRender(void){
|
||||
strengthBarSlider.height = 0.05f;
|
||||
strengthBarSliderId = scene_addRenderObject(&gameScene, strengthBarSlider, 0.30f * CAMERA_WIDTH, 0.89f * CAMERA_HEIGHT);
|
||||
|
||||
text_renderText(&scoreText, 50, 1.f, black, "./assets/fonts/Quinquefive.ttf", 20, "Press F to buy steroids for 200J");
|
||||
steroidText = scene_addRenderObject(&gameScene, scoreText, STEROIDS_POSITION, 0);
|
||||
|
||||
RenderObject_t pressSpaceShadow = EMPTY_RENDER_OBJECT;
|
||||
strcpy(pressSpaceShadow.name, "pressSpaceShadow");
|
||||
text_renderText(&pressSpaceShadow, 50, 1, black, "./assets/fonts/Quinquefive.ttf", 20, "Press space to teach respect");
|
||||
pressSpaceShadowId = scene_addRenderObject(&gameScene, pressSpaceShadow, 0.30f * CAMERA_WIDTH, 0.8f * CAMERA_HEIGHT);
|
||||
|
||||
|
||||
RenderObject_t pressSpaceText = EMPTY_RENDER_OBJECT;
|
||||
strcpy(pressSpaceText.name, "pressSpaceText");
|
||||
SDL_Color white = {255, 255, 255, 255};
|
||||
text_renderText(&pressSpaceText, 50, 1, white, "./assets/fonts/Quinquefive.ttf", 20, "Press space to teach respect");
|
||||
pressSpaceTextId = scene_addRenderObject(&gameScene, pressSpaceText, 0.295f * CAMERA_WIDTH, 0.82f * CAMERA_HEIGHT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int game_render([[maybe_unused]] float delta){
|
||||
int game_render(float delta){
|
||||
deltaAccu += delta;
|
||||
|
||||
if(personPositionX - backgroundOffset > backgroundOffset * 0.1f) {
|
||||
currentBackground = 1 - currentBackground;
|
||||
backgroundOffset += backgroundStep;
|
||||
scene_moveRenderObject(&gameScene, backgrounds[currentBackground], backgroundOffset, 0);
|
||||
}
|
||||
|
||||
if(!isSpaceKeypressed && !crashed && deltaAccu >= SLIDER_SPEED){
|
||||
// if(increaseStrength && strength >= 2.f)
|
||||
// increaseStrength = false;
|
||||
// else if(increaseStrength)
|
||||
// strength += 0.1;
|
||||
// else if(!increaseStrength && strength <= 0.f)
|
||||
// increaseStrength = true;
|
||||
// else
|
||||
// strength -= 0.1;
|
||||
if(increaseStrengthBarSlider && strengthBarSliderDistance >= 0.50f)
|
||||
increaseStrengthBarSlider = false;
|
||||
else if(increaseStrengthBarSlider){
|
||||
@@ -284,6 +338,20 @@ int game_render([[maybe_unused]] float delta){
|
||||
scene_moveRenderObject(&gameScene, adame[0], ADAME_X, ADAME_Y);
|
||||
adame_id = 0;
|
||||
kicked = true;
|
||||
if(strength > 1.5){
|
||||
if(Mix_PlayChannel(-1, koMusic, 0) != 0){
|
||||
printf("Music sound could not be played!\n"
|
||||
"SDL_Error: %s\n", Mix_GetError());
|
||||
Mix_FreeChunk(koMusic);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(Mix_PlayChannel(-1, petMusic, 0) != 0){
|
||||
printf("Music sound could not be played!\n"
|
||||
"SDL_Error: %s\n", Mix_GetError());
|
||||
Mix_FreeChunk(petMusic);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
adame_id++;
|
||||
scene_moveRenderObject(&gameScene, adame[adame_id], ADAME_X, ADAME_Y);
|
||||
@@ -302,22 +370,22 @@ int game_render([[maybe_unused]] float delta){
|
||||
|
||||
personPositionY += personVelocityY * delta;
|
||||
jetons += distance;
|
||||
if(jetons > (float)ULONG_MAX)
|
||||
jetons = (float)ULONG_MAX;
|
||||
scene_moveRenderObject(&gameScene, scoreTextId, gameScene.x + 2, 0);
|
||||
|
||||
if(personPositionY + CAMERA_HEIGHT * victimHeight >= CAMERA_HEIGHT - 18){
|
||||
crashed = true;
|
||||
scene_removeRenderObject(&gameScene, scoreTextId);
|
||||
SDL_Color black = {0, 0, 0, 255};
|
||||
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %d", (unsigned)jetons);
|
||||
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %lu", (unsigned long)jetons);
|
||||
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
scene_moveRenderObject(&gameScene, steroidText, STEROIDS_POSITION + gameScene.x, 0);
|
||||
scene_moveRenderObject(&gameScene, personId, personPositionX, personPositionY);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -326,8 +394,20 @@ void game_remove(void){
|
||||
Mix_FreeMusic(music);
|
||||
}
|
||||
|
||||
void game_handleFKeyInput(void) {
|
||||
printf("coucou %f\n", jetons);
|
||||
if(jetons > 200) {
|
||||
jetons -= 200;
|
||||
adameStrength += 0.5f;
|
||||
scene_removeRenderObject(&gameScene, scoreTextId);
|
||||
SDL_Color black = {0, 0, 0, 255};
|
||||
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %lu", (unsigned long)jetons);
|
||||
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void game_handleSpaceKeyInput(void){
|
||||
if(isSpaceKeypressed == true && !crashed)return;
|
||||
if(crashed){
|
||||
crashed = false;
|
||||
personPositionX = startPersonPositionX;
|
||||
@@ -343,13 +423,21 @@ void game_handleSpaceKeyInput(void){
|
||||
scene_moveRenderObject(&gameScene, personId, 0, CAMERA_HEIGHT * 2);
|
||||
personId = victims[rand() % 4];
|
||||
kicked=false;
|
||||
}
|
||||
else{
|
||||
|
||||
backgroundOffset = 0;
|
||||
currentBackground = 0;
|
||||
scene_moveRenderObject(&gameScene, backgrounds[0], 0, 0);
|
||||
scene_moveRenderObject(&gameScene, backgrounds[1], backgroundStep, 0);
|
||||
} else{
|
||||
isSpaceKeypressed = true;
|
||||
strength = - 32 * powf(fabs(strengthBarSliderDistance - 0.5f/2), 2) + 2;
|
||||
personVelocityX *= strength * adameStrength;
|
||||
scene_moveRenderObject(&gameScene, strengthBarId, 0, CAMERA_HEIGHT * 2);
|
||||
scene_moveRenderObject(&gameScene, strengthBarSliderId, 0, CAMERA_HEIGHT * 2);
|
||||
|
||||
scene_removeRenderObject(&gameScene, pressSpaceShadowId);
|
||||
scene_removeRenderObject(&gameScene, pressSpaceTextId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// press space to teach respect
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
#include "input.h"
|
||||
#include <SDL2/SDL_scancode.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
@@ -23,6 +24,7 @@ void input_pollKeyDown(SDL_Scancode code) {
|
||||
printf("Scancode: %d\n", code);
|
||||
keyEvent_t * handlers = eventsKeyDown[code];
|
||||
for(int i = 0; i < eventKeyDown_counts[code]; i++) {
|
||||
printf("Given\n");
|
||||
handlers[i]();
|
||||
}
|
||||
}
|
||||
@@ -81,4 +83,3 @@ void input_removeKeyUpListener(SDL_Scancode code, keyEvent_t handler) {
|
||||
}
|
||||
eventKeyUp_counts[code]--;
|
||||
}
|
||||
|
||||
|
||||
+16
-8
@@ -12,6 +12,12 @@
|
||||
#include <unistd.h>
|
||||
#include "cinematic.h"
|
||||
#include "scaller.h"
|
||||
#include "main.h"
|
||||
|
||||
//Web asembly
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
clock_t timecode;
|
||||
long iter;
|
||||
@@ -40,14 +46,10 @@ static void game_setup(void) {
|
||||
RenderObject_t text = EMPTY_RENDER_OBJECT;
|
||||
SDL_Color white = {255, 255, 255, 255};
|
||||
TTF_Init();
|
||||
if(text_renderText(&text, 1000, 1, white, "./assets/fonts/arial.ttf", 25, "Hello World") < 0){
|
||||
printf("error");
|
||||
exit(1);
|
||||
}
|
||||
input_listenKeyDown(SDL_SCANCODE_SPACE, space);
|
||||
}
|
||||
|
||||
static void game_loop(void) {
|
||||
void game_loop(void) {
|
||||
float delta = ((float)(clock() - timecode)) / CLOCKS_PER_SEC;
|
||||
|
||||
//update time
|
||||
@@ -62,8 +64,7 @@ static void game_loop(void) {
|
||||
timecode = clock();
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
int main(int argc, char ** argv) {
|
||||
TTF_Init();
|
||||
if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) != 0){
|
||||
printf("Music sound could not be open!\n"
|
||||
@@ -75,8 +76,15 @@ int main(void) {
|
||||
timecode = clock();
|
||||
|
||||
Mix_Init(MIX_INIT_MP3);
|
||||
renderer_main(game_setup, game_loop);
|
||||
renderer_main(argc, argv, game_setup);
|
||||
|
||||
Mix_CloseAudio();
|
||||
text_freeFontCache();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
int WinMain(int argc, char ** argv) {
|
||||
main(argc, argv);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef __MAIN_H__
|
||||
#define __MAIN_H__
|
||||
|
||||
void game_loop(void);
|
||||
|
||||
#endif
|
||||
+13
-4
@@ -20,21 +20,30 @@ static Mix_Music * music;
|
||||
|
||||
Scene_t menuScene = { NULL, 0, 0, 0, 0, 0 };
|
||||
|
||||
//Web asembly
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
|
||||
int menu_staticRender(void){
|
||||
|
||||
MonitorSize_t size = renderer_getMonitorSize();
|
||||
float aspectRatio = (float)size.width / size.height;
|
||||
|
||||
|
||||
SDL_Surface* backgroundImageSurface = IMG_Load("./assets/img/menu_bg.png");
|
||||
SDL_Surface* backgroundImageSurface = IMG_Load("assets/img/menu_bg.png");
|
||||
if(backgroundImageSurface == NULL){
|
||||
printf("cannot load background");
|
||||
printf("Could not load menu background\n");
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_pause_main_loop();
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
music = Mix_LoadMUS("./assets/music/menu.wav");
|
||||
music = Mix_LoadMUS("assets/music/menu.ogg");
|
||||
if(music == NULL) {
|
||||
fprintf(stderr, "Menu music not found!\n");
|
||||
fprintf(stderr, "Menu music not found!: %s\n", Mix_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
+77
-29
@@ -4,7 +4,9 @@
|
||||
#include <SDL2/SDL_error.h>
|
||||
#include <SDL2/SDL_rect.h>
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include <SDL2/SDL_scancode.h>
|
||||
#include <SDL2/SDL_timer.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -12,6 +14,12 @@
|
||||
#include <math.h>
|
||||
#include "input.h"
|
||||
#include "scene.h"
|
||||
#include "main.h"
|
||||
|
||||
//Web asembly
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
bool running;
|
||||
MonitorSize_t monitorSize;
|
||||
@@ -19,35 +27,22 @@ SDL_Window* win;
|
||||
SDL_Renderer * renderer;
|
||||
const Scene_t * scene;
|
||||
int scenesCount = 0;
|
||||
bool fullscreen = false;
|
||||
|
||||
//int (*compar)(const void [.size], const void [.size], void *)
|
||||
void renderer_main(void(*game_setup)(void), void(*game_loop)(void)) {
|
||||
// returns zero on success else non-zero
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
||||
printf("error initializing SDL: %s\n", SDL_GetError());
|
||||
|
||||
static void toggleFullscreen(void) {
|
||||
printf("Toggling\n");
|
||||
if(!fullscreen) {
|
||||
SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN);
|
||||
fullscreen = true;
|
||||
}
|
||||
win = SDL_CreateWindow("The legend of ADAM", // creates a window
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
1280, 720, 0);
|
||||
|
||||
Uint32 render_flags = SDL_RENDERER_ACCELERATED;
|
||||
|
||||
// creates a renderer to render our images
|
||||
renderer = SDL_CreateRenderer(win, -1, render_flags);
|
||||
|
||||
if(renderer == NULL) {
|
||||
fprintf(stderr, "Could not create renderer\n");
|
||||
else {
|
||||
SDL_SetWindowFullscreen(win, 0);
|
||||
fullscreen = false;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GetRendererOutputSize(renderer, &monitorSize.width, &monitorSize.height);
|
||||
|
||||
input_init();
|
||||
|
||||
running = true;
|
||||
|
||||
game_setup();
|
||||
while(running) {
|
||||
static bool main_loop(void) {
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
game_loop();
|
||||
@@ -74,17 +69,70 @@ void renderer_main(void(*game_setup)(void), void(*game_loop)(void)) {
|
||||
}
|
||||
}
|
||||
|
||||
//no need to make an extra render pass
|
||||
if(!running) break;
|
||||
if(!running)
|
||||
return false;
|
||||
|
||||
if(scene != NULL)
|
||||
scene_render(scene);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
SDL_Delay(1000 / 400); //400fps or u a pussy
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
SDL_Delay(1000 / 60);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//int (*compar)(const void [.size], const void [.size], void *)
|
||||
void renderer_main(int argc, char ** argv, void(*game_setup)(void)) {
|
||||
// returns zero on success else non-zero
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
||||
printf("error initializing SDL: %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
int width = 1280;
|
||||
int height = 720;
|
||||
|
||||
if(argc > 2) {
|
||||
width = atoi(argv[1]);
|
||||
height = atoi(argv[2]);
|
||||
}
|
||||
|
||||
|
||||
win = SDL_CreateWindow("The legend of ADAM", // creates a window
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
width, height, 0);
|
||||
|
||||
Uint32 render_flags = SDL_RENDERER_ACCELERATED;
|
||||
|
||||
input_init();
|
||||
input_listenKeyDown(SDL_SCANCODE_F11, toggleFullscreen);
|
||||
|
||||
// creates a renderer to render our images
|
||||
renderer = SDL_CreateRenderer(win, -1, render_flags);
|
||||
|
||||
if(renderer == NULL) {
|
||||
fprintf(stderr, "Could not create renderer\n");
|
||||
}
|
||||
|
||||
SDL_GetRendererOutputSize(renderer, &monitorSize.width, &monitorSize.height);
|
||||
|
||||
|
||||
running = true;
|
||||
|
||||
game_setup();
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop((em_callback_func)main_loop, 0, true);
|
||||
#else
|
||||
while(main_loop());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
void renderer_setScene(const Scene_t * newScene) {
|
||||
scene = newScene;
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ typedef struct MonitorSize {
|
||||
int width, height;
|
||||
} MonitorSize_t;
|
||||
|
||||
void renderer_main(void(*game_setup)(void), void(*game_loop)(void));
|
||||
void renderer_main(int argc, char ** argv, void(*game_loop)(void));
|
||||
MonitorSize_t renderer_getMonitorSize(void);
|
||||
void renderer_setScene(const Scene_t * newScene);
|
||||
const Scene_t * renderer_getScene(void);
|
||||
|
||||
+10
-5
@@ -5,8 +5,11 @@
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include <SDL2/SDL_surface.h>
|
||||
#include <float.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
const RenderObject_t EMPTY_RENDER_OBJECT = { 0, 0.f, 0.f, 0.f, 0.f, 0.f, NULL, "Undefined" };
|
||||
|
||||
@@ -62,8 +65,6 @@ RenderId_t scene_addRenderObject(Scene_t * scene, RenderObject_t object, int x,
|
||||
scene->objectCount++;
|
||||
RenderId_t itemId = scene->lastId++;
|
||||
|
||||
printf("adding item: %s: %d\n", object.name, itemId);
|
||||
|
||||
if(scene->objectCount * sizeof(SceneObject_t) > scene->objectArraySize) {
|
||||
scene->objectArraySize = scene->objectCount * sizeof(SceneObject_t);
|
||||
scene->objects = realloc(scene->objects, scene->objectArraySize);
|
||||
@@ -84,7 +85,11 @@ RenderId_t scene_addRenderObject(Scene_t * scene, RenderObject_t object, int x,
|
||||
scene->objects[scene->objectCount - 1] = item;
|
||||
|
||||
//the objects are sorted
|
||||
#if defined(__MINGW32__) || defined(__EMSCRIPTEN__)
|
||||
qsort(scene->objects, scene->objectCount, sizeof(SceneObject_t), (int (__cdecl *)(const void *,const void *))compartSort);
|
||||
#else
|
||||
qsort(scene->objects, scene->objectCount, sizeof(SceneObject_t), (__compar_fn_t)compartSort);
|
||||
#endif
|
||||
return itemId;
|
||||
}
|
||||
|
||||
@@ -121,11 +126,11 @@ void scene_removeRenderObject(Scene_t * scene, RenderId_t id) {
|
||||
if(index < 0)
|
||||
return;
|
||||
|
||||
printf("removing item: %s: %d\n", scene->objects[index].renderObj.name, id);
|
||||
|
||||
|
||||
scene->objectCount--;
|
||||
|
||||
SDL_DestroyTexture(scene->objects[index].cache);
|
||||
SDL_FreeSurface(scene->objects[index].renderObj.surface);
|
||||
|
||||
for(int i = index; i < scene->objectCount; i++) {
|
||||
scene->objects[i] = scene->objects[i + 1];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user