Files
thepool/source/jgame.cpp
Raimon Zamora e009aef341 - [CHG] Retocat el mòdul JAudio per a adaptar-se a les necesitats del joc.
- [NEW] audio::getCurrentMusic()
- [NEW] audio::stopAllChannels()
- [FIX] El JAudio i JInput han de inicialitzarse abans de entrar al Init del joc
- Afegides músiques i alguns sons
- Comence a fer que sone cada musica i so en el seu lloc
- [TOFIX] LAG EN EL AUDIO!
2024-10-03 13:09:44 +02:00

86 lines
2.1 KiB
C++

#include "jgame.h"
#include "jdraw.h"
#include "jinput.h"
#include "jaudio.h"
#include <SDL2/SDL.h>
namespace game
{
static int param_count = 0;
static char **params = nullptr;
static bool should_exit = false;
static unsigned int ticks_per_frame = 1000/60;
void setUpdateTicks(const int ticks)
{
ticks_per_frame = ticks;
}
void exit()
{
should_exit = true;
}
const char* getParams(const int index)
{
if (index<param_count) return params[index];
return nullptr;
}
}
int main(int argc, char *argv[])
{
game::param_count = argc;
game::params = argv;
input::init();
audio::init();
game::init();
static unsigned int current_ticks = SDL_GetTicks();
SDL_Event e;
while (!game::should_exit)
{
while(SDL_PollEvent(&e))
{
if (e.type==SDL_QUIT) { game::should_exit = true; break; }
if (e.type==SDL_KEYDOWN)
{
input::updateKey(e.key.keysym.scancode);
}
if (e.type==SDL_KEYUP)
{
input::updateKeypressed(e.key.keysym.scancode);
}
if (e.type==SDL_MOUSEBUTTONUP)
{
input::updateClk(e.button.button);
}
if (e.type==SDL_MOUSEWHEEL)
{
input::updateWheel(e.wheel.y);
}
if (e.type==SDL_CONTROLLERBUTTONDOWN) {
input::updatePadBtn(e.cbutton.button);
}
if (e.type==SDL_CONTROLLERBUTTONUP) {
input::updatePadBtnPressed(e.cbutton.button);
}
}
if (SDL_GetTicks()-current_ticks >= game::ticks_per_frame)
{
if (!game::loop()) game::should_exit = true;
input::updateKey(SDL_SCANCODE_UNKNOWN);
input::updateKeypressed(SDL_SCANCODE_UNKNOWN);
input::updateClk(0);
input::updateWheel(0);
input::updatePadBtn(SDL_CONTROLLER_BUTTON_INVALID);
input::updatePadBtnPressed(SDL_CONTROLLER_BUTTON_INVALID);
current_ticks = SDL_GetTicks();
}
}
return 0;
}