Advertisement
Kitomas

globals.hpp as of 2024-04-26

Apr 26th, 2024
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.91 KB | None | 0 0
  1. #ifndef _GLOBALS_HPP
  2. #define _GLOBALS_HPP
  3.  
  4. #include <kit/all.hpp>
  5. #include <kit/xmp_sfx.hpp>
  6.  
  7. /* notes:
  8. always use a mutex when accessing soundengine, as it's used by >1 thread
  9. player should be able to step up on a half tile as if they were stairs
  10. scene states should be able to change tiles
  11. text boxes should appear when close to certain objects
  12. have thread that manages music and sfx
  13. add in cutscene image slideshow things
  14. be able to change scene after cutscene
  15. use RLE when storing scene data
  16. tweak "visited_before" to be a number that counts down deaths, instead of a bool
  17. if ambient track fails to start, (while locked) stop a track to make space for it (use forced stop!)
  18. have player animation frame override
  19. */
  20.  
  21.  
  22. #define _getnumallocs printf("line %i: %llu\n",__LINE__,memory::getNumAllocations()-2);
  23.  
  24.  
  25. #define WINDOW_TITLE "platformer prototype"
  26. #define CANVSIZ_X 768 //32 tiles wide (assuming tiles are 24x24)
  27. #define CANVSIZ_Y 432 //18 tiles tall
  28. #define TILESIZ_X 32
  29. #define TILESIZ_Y 18
  30. #define lengthof(_array, _type) (sizeof(_array)/sizeof(_type))
  31. #define memset0( _array       ) kit::memory::set((_array), 0, sizeof(_array))
  32. #define memset0s(_array, _size) kit::memory::set((_array), 0, (_size)       )
  33. #define NULLDELETE(_ptr_to_thing) { delete _ptr_to_thing;  _ptr_to_thing = nullptr; }
  34.  
  35. //#define GRAVITY (0.0175f)
  36. #define GRAVITY (0.0195f)
  37. #define PLAYER_JUMP_STRENGTH (2.0f)
  38. #define PLAYER_JUMP_CANCEL (0.33f) //multiplier of vel.y when canceling a jump while ascending
  39. #define PLAYER_SPEED (0.020f)
  40. #define PLAYER_SCALE (2.0f)
  41. #define PLAYER_HALF ( (s32)((8*PLAYER_SCALE)/2) ) //half of the character's size, in pixels
  42. #define PLAYER_NEUTRAL (0.1f) //'what +/- range should be considered neutral for vel/acc'
  43. #define PLAYER_AIR_FRICTION (0.5f) //multiplier for acc.x when in mid-air
  44. #define PLAYER_GND_FRICTION (1.0f) //multiplier of PLAYER_SPEED for on-ground deceleration
  45. #define PLAYER_RUN_MUL (0.075f) //vel.x's multiplier when adding to runningState
  46.  
  47.  
  48.  
  49.  
  50.  
  51. //(gl_ as in [gl]obal, not open[gl])
  52. extern kit::TimerSimple* gl_frameTimer;
  53. extern kit::SoundEngine* gl_snd;
  54. extern kit::MutexSimple* gl_snd_lock;
  55. extern kit::Window*      gl_win;
  56. extern kit::BitmapFont*  gl_text;
  57. extern kit::FStr*        gl_fstr;
  58. #define gl_textf(_x, _y, _fmt,           ...) \
  59.     gl_text->print((_x), (_y), gl_fstr->fmt(_fmt, __VA_ARGS__), 0)
  60. #define gl_textfs(_x, _y, _fmt, _maxLen, ...) \
  61.     gl_text->print((_x), (_y), gl_fstr->fmt(_fmt, __VA_ARGS__), (_maxLen))
  62. extern kit::Bitmap* gl_spritesheetPlayer;
  63.  
  64.  
  65. struct Scene;
  66.  
  67. #define             gl_scenes_len 1
  68. #define             gl_tilesets_len 1
  69. extern kit::u16     gl_sceneCurrent; //id for currently active scene
  70. extern Scene        gl_scenes[gl_scenes_len];
  71. extern kit::Bitmap* gl_tilesets[gl_tilesets_len];
  72. extern kit::Bitmap* gl_tileset_missing;
  73.  
  74.  
  75.  
  76.  
  77.  
  78. kit::f64 frand();
  79. kit::f32 frandf();
  80.  
  81. kit::f64 frandRange(kit::f64 start, kit::f64 maxDeviation);
  82.  
  83.  
  84.  
  85.  
  86.  
  87. struct SoundEffect { //40B (not including the size of the AudioData class)
  88.   kit::AudioData* sfx = nullptr;
  89.   kit::f32       volL = 1.0f;
  90.   kit::f32       volR = 1.0f;
  91.   kit::f64  speedBase = 1.0 ;
  92.   kit::f64 speedRange = 0.0 ;
  93.   kit::f32        pan = 0.0f;
  94.   kit::u32 _padding32;
  95.  
  96.   SoundEffect(const char* filePath, kit::f32 volume = 1.0f,
  97.                                     kit::f64 _speedRange = 0.0)
  98.   {
  99.     sfx = new kit::AudioData(filePath, gl_snd);
  100.     volL = volume,  volR = volume;
  101.     speedRange = _speedRange;
  102.   }
  103.  
  104.   ~SoundEffect(){ delete sfx; }
  105.  
  106.   kit::s32 play(){
  107.     if(sfx != nullptr){
  108.       gl_snd_lock->lock(true);
  109.  
  110.       if(speedRange < 0.0) speedRange = -speedRange;
  111.       if(!speedRange) return gl_snd->sfxPlay(sfx, volL, volR, 1.0, pan);
  112.       else return gl_snd->sfxPlay(sfx, volL, volR, frandRange(speedBase,speedRange), pan);
  113.  
  114.       gl_snd_lock->lock(false);
  115.  
  116.     } else {
  117.       return -1;
  118.     }
  119.   }
  120. };
  121.  
  122.  
  123.  
  124.  
  125. #endif /* _GLOBALS_HPP */
  126.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement