Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _GLOBALS_HPP
- #define _GLOBALS_HPP
- #include <kit/all.hpp>
- #include <kit/xmp_sfx.hpp>
- /* notes:
- always use a mutex when accessing soundengine, as it's used by >1 thread
- player should be able to step up on a half tile as if they were stairs
- scene states should be able to change tiles
- text boxes should appear when close to certain objects
- have thread that manages music and sfx
- add in cutscene image slideshow things
- be able to change scene after cutscene
- if ambient track fails to start, (while locked) stop a track to make space for it (use forced stop!)
- have player animation frame override
- add customizable friction coefficients for tilesets
- */
- #ifdef _DEBUG
- #include <stdio.h>
- #define _printf(_fmt, ...) printf(_fmt, __VA_ARGS__)
- #else
- #define _printf(_fmt, ...)
- #endif /* _DEBUG */
- #define _getnumallocs _printf("line %i: %llu\n",__LINE__,memory::getNumAllocations()-2);
- #define WINDOW_TITLE "platformer prototype"
- #define CANVSIZ_X 768 //32 tiles wide (assuming tiles are 24x24)
- #define CANVSIZ_Y 432 //18 tiles tall
- #define TILESIZ_X 32
- #define TILESIZ_Y 18
- #define lengthof(_array, _type) (sizeof(_array)/sizeof(_type))
- #define memset0( _array ) kit::memory::set((_array), 0, sizeof(_array))
- #define memset0s(_array, _size) kit::memory::set((_array), 0, (_size) )
- #define NULLDELETE(_ptr_to_thing) { delete _ptr_to_thing; _ptr_to_thing = nullptr; }
- #define PTR_OFFSET(_ptr, _offset, _type) ( \
- (_type*)( ((kit::u64)(_ptr)) + ((kit::s64)(_offset)) ) )
- //#define GRAVITY (0.0175f)
- #define GRAVITY (0.0195f)
- #define PLAYER_JUMP_STRENGTH (2.0f)
- #define PLAYER_JUMP_CANCEL (0.33f) //multiplier of vel.y when canceling a jump while ascending
- #define PLAYER_SPEED (0.020f)
- #define PLAYER_SCALE (2.0f)
- #define PLAYER_HALF ( (s32)((8*PLAYER_SCALE)/2) ) //half of the character's size, in pixels
- #define PLAYER_NEUTRAL (0.1f) //'what +/- range should be considered neutral for vel/acc'
- #define PLAYER_AIR_FRICTION (0.5f) //multiplier for acc.x when in mid-air
- #define PLAYER_GND_FRICTION (1.0f) //multiplier of PLAYER_SPEED for on-ground deceleration
- #define PLAYER_RUN_MUL (0.075f) //vel.x's multiplier when adding to runningState
- extern char falseStr[]; // = "false"
- extern char trueStr[]; // = "true"
- #define boolStr(_bool_value) ((_bool_value) ? trueStr : falseStr )
- //(gl_ as in [gl]obal, not open[gl])
- extern kit::TimerSimple* gl_frameTimer;
- extern kit::SoundEngine* gl_snd;
- extern kit::MutexSimple* gl_snd_lock;
- extern kit::Window* gl_win;
- extern kit::BitmapFont* gl_text;
- extern kit::FStr* gl_fstr;
- #define gl_textf(_x, _y, _fmt, ...) \
- gl_text->print((_x), (_y), gl_fstr->fmt(_fmt, __VA_ARGS__), 0)
- #define gl_textfs(_x, _y, _fmt, _maxLen, ...) \
- gl_text->print((_x), (_y), gl_fstr->fmt(_fmt, __VA_ARGS__), (_maxLen))
- extern kit::Bitmap* gl_spritesheetPlayer;
- struct Scene;
- struct SceneDescriptor;
- struct Object;
- typedef void (*Object_TickCallback)(Object* obj_a);
- #define gl_scenes_len 1
- #define gl_backgrounds_len 1
- #define gl_tilesets_len 1
- #define gl_ambience_len 0
- #define gl_music_len 1
- #define gl_objCallbacks_len 0
- //+1 for the length, since the first valid id is 1, not 0
- extern Scene gl_scene;
- extern SceneDescriptor* gl_scenes[gl_scenes_len+1];
- extern kit::Bitmap* gl_backgrounds[gl_backgrounds_len+1];
- extern kit::Bitmap* gl_tileset_missing;
- extern kit::Bitmap* gl_tilesets[gl_tilesets_len+1];
- extern kit::AudioData* gl_ambience[gl_ambience_len+1];
- extern char gl_music[gl_music_len+1][32]; //the music's file paths
- extern Object_TickCallback gl_objCallbacks[gl_objCallbacks_len+1];
- kit::f64 frand();
- kit::f32 frandf();
- kit::f64 frandRange(kit::f64 start, kit::f64 maxDeviation);
- struct SoundEffect { //40B (not including the size of the AudioData class)
- kit::AudioData* sfx = nullptr;
- kit::f32 volL = 1.0f;
- kit::f32 volR = 1.0f;
- kit::f64 speedBase = 1.0 ;
- kit::f64 speedRange = 0.0 ;
- kit::f32 pan = 0.0f;
- kit::u32 _padding32;
- SoundEffect(const char* filePath, kit::f32 volume = 1.0f,
- kit::f64 _speedRange = 0.0)
- {
- sfx = new kit::AudioData(filePath, gl_snd);
- volL = volume, volR = volume;
- speedRange = _speedRange;
- }
- ~SoundEffect(){ delete sfx; }
- kit::s32 play(){
- if(sfx != nullptr){
- gl_snd_lock->lock(true);
- if(speedRange < 0.0) speedRange = -speedRange;
- if(!speedRange) return gl_snd->sfxPlay(sfx, volL, volR, 1.0, pan);
- else return gl_snd->sfxPlay(sfx, volL, volR, frandRange(speedBase,speedRange), pan);
- gl_snd_lock->lock(false);
- } else {
- return -1;
- }
- }
- };
- #endif /* _GLOBALS_HPP */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement