summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.h11
-rw-r--r--src/main.cpp16
-rw-r--r--src/timer.h32
3 files changed, 57 insertions, 2 deletions
diff --git a/src/game.h b/src/game.h index f0385ee..c489afc 100644 --- a/src/game.h +++ b/src/game.h
@@ -7,6 +7,7 @@
7#include <list> 7#include <list>
8#include "map.h" 8#include "map.h"
9#include "muxer.h" 9#include "muxer.h"
10#include "timer.h"
10 11
11const int GAME_WIDTH = 640*2; 12const int GAME_WIDTH = 640*2;
12const int GAME_HEIGHT = 480*2; 13const int GAME_HEIGHT = 480*2;
@@ -43,6 +44,14 @@ struct Input {
43 bool right = false; 44 bool right = false;
44 bool up = false; 45 bool up = false;
45 bool down = false; 46 bool down = false;
47
48 bool operator==(const Input& rhs) const {
49 return std::tie(left, right, up, down) == std::tie(rhs.left, rhs.right, rhs.up, rhs.down);
50 }
51
52 bool operator!=(const Input& rhs) const {
53 return !(*this == rhs);
54 }
46}; 55};
47 56
48using coord = std::tuple<int, int>; 57using coord = std::tuple<int, int>;
@@ -110,6 +119,8 @@ public:
110 119
111 bool firstInput = false; 120 bool firstInput = false;
112 Input lastInput; 121 Input lastInput;
122 bool alreadyBumped = false;
123 Timer bumpCooldown = {500};
113 124
114}; 125};
115 126
diff --git a/src/main.cpp b/src/main.cpp index 25da94f..cd1a8c2 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -106,7 +106,11 @@ bool movePlayer(Game& game, int x, int y)
106 106
107 return true; 107 return true;
108 } else { 108 } else {
109 //game.muxer.playSoundAtPosition("bump", game.player_x, game.player_y); 109 if (!game.alreadyBumped) {
110 game.muxer.playSoundAtPosition("bump", x, y);
111 game.alreadyBumped = true;
112 game.bumpCooldown.reset();
113 }
110 114
111 return false; 115 return false;
112 } 116 }
@@ -409,7 +413,7 @@ void setZoom(Game& game, size_t zoom)
409 { 413 {
410 game.curBoundY = game.map.getBottom() - zoom * ZOOM_Y_FACTOR; 414 game.curBoundY = game.map.getBottom() - zoom * ZOOM_Y_FACTOR;
411 } 415 }
412 416
413 int zoomLevel = getZoomLevel(game); 417 int zoomLevel = getZoomLevel(game);
414 if (zoomLevel == 0) { 418 if (zoomLevel == 0) {
415 game.muxer.setMusicLevel(0); 419 game.muxer.setMusicLevel(0);
@@ -538,6 +542,7 @@ int main(int, char**)
538 game.numLamps++; 542 game.numLamps++;
539 game.dirtyLighting = true; 543 game.dirtyLighting = true;
540 kickUpDust(game, game.player_x, game.player_y, 0); 544 kickUpDust(game, game.player_x, game.player_y, 0);
545 game.muxer.playSoundAtPosition("drop", game.player_x, game.player_y);
541 546
542 if (game.firstInput) 547 if (game.firstInput)
543 { 548 {
@@ -576,6 +581,8 @@ int main(int, char**)
576 std::get<0>(moveTo), 581 std::get<0>(moveTo),
577 std::get<1>(moveTo)); 582 std::get<1>(moveTo));
578 } 583 }
584
585 //game.muxer.playSoundAtPosition("dash", game.player_x, game.player_y);
579 } 586 }
580 } 587 }
581 } 588 }
@@ -592,6 +599,11 @@ int main(int, char**)
592 keystate.up = state[SDL_SCANCODE_UP]; 599 keystate.up = state[SDL_SCANCODE_UP];
593 keystate.down = state[SDL_SCANCODE_DOWN]; 600 keystate.down = state[SDL_SCANCODE_DOWN];
594 601
602 game.bumpCooldown.accumulate(frameTime);
603 if (game.alreadyBumped && keystate != game.lastInput && game.bumpCooldown.step()) {
604 game.alreadyBumped = false;
605 }
606
595 if (keystate.left || keystate.right || keystate.up || keystate.down) 607 if (keystate.left || keystate.right || keystate.up || keystate.down)
596 { 608 {
597 game.firstInput = true; 609 game.firstInput = true;
diff --git a/src/timer.h b/src/timer.h new file mode 100644 index 0000000..ec34f3e --- /dev/null +++ b/src/timer.h
@@ -0,0 +1,32 @@
1#ifndef TIMER_H_45E2F1F9
2#define TIMER_H_45E2F1F9
3
4class Timer {
5public:
6
7 Timer(int dt) : dt_(dt) {}
8
9 void accumulate(int t) {
10 acc_ += t;
11 }
12
13 bool step() {
14 if (acc_ > dt_) {
15 acc_ -= dt_;
16 return true;
17 } else {
18 return false;
19 }
20 }
21
22 void reset() {
23 acc_ = 0;
24 }
25
26private:
27
28 int dt_;
29 int acc_ = 0;
30};
31
32#endif /* end of include guard: TIMER_H_45E2F1F9 */