Advertisement
Kitomas

platformer's main.cpp as of 2024-04-26

Apr 26th, 2024
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.92 KB | None | 0 0
  1. #include <globals.hpp>
  2. #include <player.hpp>
  3. #include <tile.hpp>
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <math.h>
  8.  
  9. using namespace kit;
  10.  
  11.  
  12.  
  13. Player player;
  14.  
  15. #define SPCENTER_X 254
  16. #define SPCENTER_Y 177
  17. #define SPRANGE  250.0f //in pixels
  18. #define SPMAXVOL 0.125f
  19. #define SPMAXPAN 1.0f
  20.  
  21. f32 distanceToSpeaker(){
  22.   shape::fpoint diff(player.pos.x - SPCENTER_X,  player.pos.y - SPCENTER_Y);
  23.   return sqrtf(diff.x*diff.x + diff.y*diff.y);
  24.  
  25. }
  26.  
  27. f32 volumeFromDistance(f32 distance){
  28.   f32 rangeInverse = SPRANGE - CLAMP(distance, 0, SPRANGE);
  29.   f32 volume       = (rangeInverse/SPRANGE) * SPMAXVOL;
  30.   return volume;
  31.  
  32. }
  33.  
  34. f32 panFromXDifference(shape::fpoint a, shape::fpoint b){
  35.   f32 range = CLAMP(a.x-b.x, -SPRANGE, SPRANGE);
  36.   f32 pan   = (range/SPRANGE) * SPMAXPAN;
  37.   return pan;
  38.  
  39. }
  40.  
  41.  
  42.  
  43. #define T(_id_and_tileset) (u8)(_id_and_tileset) //lol
  44. Tile pattern_mg[] = {
  45.      //0       1       2       3       4       5       6       7       8       9       10      11      12      13      14      15      16      17      18      19      20      21      22      23      24      25      26      27      28      29      30      31
  46. /* 0*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  47. /* 1*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  48. /* 2*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  49. /* 3*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  50. /* 4*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x01),T(0x01),T(0x01),T(0x01),T(0x01),T(0x01),T(0x01),T(0x01),T(0x01),
  51. /* 5*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),
  52. /* 6*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),
  53. /* 7*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),
  54. /* 8*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),
  55. /* 9*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x21),T(0x00),T(0x22),T(0x00),T(0x00),T(0x00),T(0x00),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),T(0x02),
  56. /*10*/ T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x05),T(0x01),T(0x01),T(0x01),T(0x01),T(0x01),T(0x01),T(0x01),T(0x01),T(0x01),
  57. /*11*/ T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),T(0x04),
  58. /*12*/ T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),
  59. /*13*/ T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),
  60. /*14*/ T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),
  61. /*15*/ T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),
  62. /*16*/ T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),
  63. /*17*/ T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),T(0x14),
  64. };
  65.  
  66. Tile pattern_fg[] = {
  67.      //0       1       2       3       4       5       6       7       8       9       10      11      12      13      14      15      16      17      18      19      20      21      22      23      24      25      26      27      28      29      30      31
  68. /* 0*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  69. /* 1*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  70. /* 2*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  71. /* 3*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  72. /* 4*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  73. /* 5*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x06),T(0x00),T(0x00),T(0x06),T(0x00),T(0x00),T(0x06),T(0x00),T(0x00),
  74. /* 6*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x16),T(0x00),T(0x00),T(0x16),T(0x00),T(0x00),T(0x16),T(0x00),T(0x00),
  75. /* 7*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x16),T(0x00),T(0x00),T(0x16),T(0x00),T(0x00),T(0x16),T(0x00),T(0x00),
  76. /* 8*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x16),T(0x00),T(0x00),T(0x16),T(0x00),T(0x00),T(0x16),T(0x00),T(0x00),
  77. /* 9*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x21),T(0x00),T(0x00),T(0x22),T(0x00),T(0x26),T(0x00),T(0x00),T(0x26),T(0x00),T(0x00),T(0x26),T(0x00),T(0x00),
  78. /*10*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  79. /*11*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  80. /*12*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  81. /*13*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  82. /*14*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  83. /*15*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  84. /*16*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  85. /*17*/ T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),T(0x00),
  86. };
  87. #undef T
  88.  
  89.  
  90.  
  91.  
  92.  
  93. bool fullscreen = false;
  94.  
  95.  
  96. bool handleEvents(){
  97.   bool run = true;
  98.  
  99.  
  100.   WindowEvent e;
  101.   while(pollWindowEvent(&e))
  102.   switch(e.type){
  103.     case WINEVENT_WIN_CLOSE: _we_w_close: run = false; break;
  104.  
  105.     case WINEVENT_KEY_DOWN: {
  106.       if(e.key.repeat) break;
  107.       switch(e.key.vkey){
  108.         case VKEY_ESCAPE    : goto _we_w_close;
  109.         case VKEY_F11       : gl_win->setFullscreen(fullscreen^=1); break;
  110.         case VKEY_BSLASH    : player.confused^=1; break;
  111.         case VKEY_FSLASH    : player.enforceMaxVel^=1; break;
  112.         case VKEY_ENTER     : {
  113.           player.pos = shape::fpoint(CANVSIZ_X/2,CANVSIZ_Y/2-80);
  114.           player.vel = shape::fpoint(0,0);
  115.         }break;
  116.         case VKEY_LEFT : player.acc.x += -PLAYER_SPEED; break;
  117.         case VKEY_RIGHT: player.acc.x +=  PLAYER_SPEED; break;
  118.         case VKEY_UP   : {
  119.           if(player.ticksInAir < 2  &&  !player.jumped){
  120.             player.jumped = true;
  121.             player.vel.y = -PLAYER_JUMP_STRENGTH;
  122.             player.sfx_jumping->play();
  123.           }
  124.         } break;
  125.       }
  126.     } break;
  127.  
  128.     case WINEVENT_KEY_UP: {
  129.       switch(e.key.vkey){
  130.         case VKEY_LEFT : player.acc.x -= -PLAYER_SPEED; break;
  131.         case VKEY_RIGHT: player.acc.x -=  PLAYER_SPEED; break;
  132.         case VKEY_UP   : {
  133.           if(player.jumped && player.vel.y<0)
  134.             player.vel.y *= PLAYER_JUMP_CANCEL;
  135.         } break;
  136.       }
  137.     } break;
  138.  
  139.   }
  140.  
  141.  
  142.   return run;
  143. }
  144.  
  145.  
  146.  
  147.  
  148. #define DBG_TXT(_l, _fmt, ...) gl_textf(1,1+(_l)*9, _fmt, __VA_ARGS__)
  149.  
  150. int gameMain(int argc, char** argv){
  151.   gl_snd->musicLoadModule("dat/music/sine_half.mod");
  152.   gl_snd->musicSetUseNearest(false);
  153.   gl_snd->musicSetVolumeForced(0.0f, 0.0f);
  154.   gl_snd->musicSetCheckLoop(false); //this forces the module to loop
  155.   gl_snd->musicStart();
  156.  
  157.   Scene scene;
  158.   scene.bmp_bg = new Bitmap("dat/img/0_bg_gradient_black-cyan.qoi", gl_win);
  159.   scene.pat_mg = pattern_mg;
  160.   scene.pat_fg = pattern_fg;
  161.   scene.stretch_bg = false;
  162.  
  163.   player.sfx_footstep = new SoundEffect("dat/sfx/player_footstep.qoa", .02f, 0.1);
  164.   player.sfx_landing  = new SoundEffect("dat/sfx/player_landing.qoa",  .08f, 0.2);
  165.   player.sfx_jumping  = new SoundEffect("dat/sfx/player_jumping.qoa",  .05f);
  166.  
  167.   Bitmap siren("dat/img/siren0.qoi", gl_win);
  168.  
  169.  
  170.   player.pos.x = CANVSIZ_X/2;
  171.   player.pos.y = CANVSIZ_Y/2 - 80;
  172.  
  173.   bool run = true;
  174.   f64 timeStart = time::getUptime();
  175.   while(run){
  176.     gl_frameTimer->setTimer(0.25/60);
  177.  
  178.  
  179.     if(!handleEvents()) break;
  180.  
  181.  
  182.     player.vel.y += GRAVITY;
  183.     player.update();
  184.  
  185.  
  186.     if(     player.pos.x <          -PLAYER_HALF) player.pos.x = CANVSIZ_X+PLAYER_HALF;
  187.     else if(player.pos.x > CANVSIZ_X+PLAYER_HALF) player.pos.x = -PLAYER_HALF;
  188.  
  189.     if(player.pos.y < -PLAYER_HALF){
  190.       player.pos.y = CANVSIZ_Y/2;
  191.       player.vel.y = fabsf(player.vel.y);
  192.  
  193.     } else if(player.pos.y > (CANVSIZ_Y/2 + 24 - PLAYER_HALF)){
  194.       if(player.ticksInAir > 3) player.sfx_landing->play();
  195.       player.pos.y  = CANVSIZ_Y/2 + 24 - PLAYER_HALF;
  196.       player.vel.y  = 0.0f;
  197.       player.ticksInAir = 0;
  198.       player.jumped = false;
  199.  
  200.     } else if(player.pos.y < CANVSIZ_Y/2){
  201.       ++player.ticksInAir;
  202.  
  203.     }
  204.  
  205.  
  206.     //play footstep sound when feet touch ground
  207.     if(player.queryFootstep()) player.sfx_footstep->play();
  208.  
  209.  
  210.     //gl_win->clear(0x7f7f7f); //redundant, since drawBg fills the canvas anyway
  211.     scene.drawBg();
  212.     scene.drawTiles(false);
  213.     gl_text->print(9*0, 9*17, "(supposed to look like a siren)\n                            v");
  214.     siren.blit(24*9, 24*7, 1.0f, 0xff00ff);
  215.     player.blit(PLAYER_SCALE, PLAYER_SCALE);
  216.     scene.drawTiles(true);
  217.  
  218.  
  219.     f32 speakerDistance = distanceToSpeaker(); //relative to player's center
  220.     f32 newVolume = volumeFromDistance(speakerDistance);
  221.     f32 newPan = panFromXDifference(player.pos, {SPCENTER_X, SPCENTER_Y});
  222.     gl_snd->musicSetVolume(newVolume, newVolume);
  223.     gl_snd->musicSetPan(newPan);
  224.  
  225.  
  226.     DBG_TXT( 0, "controls: arrow keys, f11, enter, '\\', '/' (esc to quit)");
  227.     DBG_TXT( 2, ".pos           = {%6.2f, %6.2f}", player.pos.x, player.pos.y);
  228.     DBG_TXT( 3, ".vel           = {%6.2f, %6.2f}", player.vel.x, player.vel.y);
  229.     DBG_TXT( 4, ".acc           = {%6.2f, %6.2f}", player.acc.x, player.acc.y);
  230.     DBG_TXT( 5, ".ticksInAir    = %u", player.ticksInAir);
  231.     DBG_TXT( 6, ".runningState  = %6.4f", player.runningState);
  232.     DBG_TXT( 7, ".facingRight   = %s", (player.facingRight)?"true":"false");
  233.     DBG_TXT( 8, ".enforceMaxVel = %s", (player.enforceMaxVel)?"true":"false");
  234.     DBG_TXT( 9, ".confused      = %s", (player.confused)?"true":"false");
  235.     DBG_TXT(10, ".jumped        = %s", (player.jumped)?"true":"false");
  236.     DBG_TXT(12, "tick latency   = %.2fms", (time::getUptime()-timeStart)*1000);
  237.     DBG_TXT(13, "speaker dist.  = %.1fpx", speakerDistance);
  238.     DBG_TXT(14, "speaker volume = %.1f%%", newVolume*100);
  239.     DBG_TXT(15, "speaker pan    =%4.0f%%", newPan*100);
  240.  
  241.     gl_win->present();
  242.     timeStart = time::getUptime();
  243.  
  244.  
  245.     gl_frameTimer->wait();
  246.   }
  247.  
  248.  
  249.  
  250.   NULLDELETE(player.sfx_footstep);
  251.   NULLDELETE(player.sfx_jumping );
  252.   NULLDELETE(player.sfx_landing );
  253.  
  254.   delete scene.bmp_bg;
  255.  
  256.   return 0;
  257. }
  258.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement