Ver código fonte

Player's 4-th stage

Change raw variables to vectors
Pabloader 4 anos atrás
pai
commit
555375ec58
12 arquivos alterados com 187 adições e 118 exclusões
  1. 1
    1
      Makefile
  2. 10
    0
      TODO.md
  3. 4
    0
      include/debuggers.h
  4. 12
    11
      include/entity.h
  5. 2
    2
      include/programmer.h
  6. BIN
      res/player.png
  7. 2
    3
      src/bonus.cpp
  8. 1
    1
      src/bug.cpp
  9. 72
    40
      src/debuggers.cpp
  10. 35
    15
      src/entity.cpp
  11. 6
    4
      src/player.cpp
  12. 42
    41
      src/programmer.cpp

+ 1
- 1
Makefile Ver arquivo

@@ -28,7 +28,7 @@ IMAGES=$(wildcard res/*.png)
28 28
 
29 29
 OBJECTS=$(SOURCES:.cpp=.o)
30 30
 SPRITES=$(IMAGES:.png=.pgs)
31
-RESOURCES=$(SPRITES) $(wildcard res/*.wav) src/debuggers.cpp
31
+RESOURCES=$(SPRITES) $(wildcard res/*.wav) src/programmer.cpp
32 32
 
33 33
 PACK=debuggers.pgp
34 34
 

+ 10
- 0
TODO.md Ver arquivo

@@ -0,0 +1,10 @@
1
+ # TODO
2
+ - [ ] Bugs only catchable by 2 programmers
3
+ - [ ] Bugs only catchable with debugger
4
+ - [ ] Bugs only catchable with unit tests
5
+ - [ ] Bugs immune to debugger
6
+ - [ ] Bugs immune to unit tests
7
+ - [ ] Reduce programmers spawn rate (maybe cubic function?)
8
+ - [ ] Add obstacles to prevent flying across the screen
9
+   - [ ] Edits by customer
10
+   - [ ] QA engineers

+ 4
- 0
include/debuggers.h Ver arquivo

@@ -24,6 +24,7 @@ private:
24 24
     std::map<BonusType, uint32_t> bonusesCatched;
25 25
 
26 26
     uint32_t bugsCatched = 0;
27
+    uint32_t bugsCatchedByPlayer = 0;
27 28
     uint32_t bugsMissed = 0;
28 29
 
29 30
     uint8_t linesOfCode = 5;
@@ -71,6 +72,9 @@ public:
71 72
     int bugCatchSample;
72 73
 
73 74
     const int gravity = 30;
75
+#ifdef _DEBUG
76
+    bool debug = true;
77
+#endif
74 78
 };
75 79
 }
76 80
 

+ 12
- 11
include/entity.h Ver arquivo

@@ -13,18 +13,16 @@ protected:
13 13
     Debuggers* game;
14 14
     olc::Sprite* sprite;
15 15
     olc::GFX2D::Transform2D transform;
16
-    float x, y;
17
-    float xv = 0, yv = 0;
18
-    int w, h;
16
+    olc::vf2d pos;
17
+    olc::vf2d vel;
18
+    olc::vi2d size;
19 19
 
20
-    uint8_t tileX = 0;
21
-    uint8_t tileY = 0;
22
-
23
-    uint8_t tileCols = 4;
24
-    uint8_t tileRows = 4;
20
+    olc::v2d_generic<uint8_t> tile{ 0, 0 };
21
+    olc::v2d_generic<uint8_t> tileDim{ 4, 4 };
25 22
 
26 23
     float rotation = 0;
27 24
     float rotationSpeed = 0;
25
+    bool alive = true;
28 26
 #ifdef _DEBUG
29 27
     olc::Pixel DEBUG_COLOR;
30 28
 #endif
@@ -36,13 +34,16 @@ public:
36 34
     virtual void Update(float dt);
37 35
     virtual void Draw();
38 36
 
39
-    float GetX() { return x; }
40
-    float GetY() { return y; }
37
+    float GetX() { return pos.x; }
38
+    float GetY() { return pos.y; }
39
+
40
+    bool IsInScreen();
41 41
 
42 42
     bool Collides(Entity* entity);
43
-    float Dist(Entity* entity) { return std::hypot(x - entity->x, y - entity->y); }
43
+    float Dist(Entity* entity) { return (pos - entity->pos).mag(); }
44 44
 
45 45
     virtual bool IsActive();
46
+    virtual bool IsAlive();
46 47
     virtual void ResetPosition();
47 48
     virtual void Kill();
48 49
 };

+ 2
- 2
include/programmer.h Ver arquivo

@@ -21,8 +21,8 @@ public:
21 21
     virtual void Update(float dt) override;
22 22
     virtual void Draw() override;
23 23
     bool IsOnGround() { return onGround; }
24
-    uint8_t GetSkin() { return tileX; }
25
-    void UpgradeLevel() { tileX = std::min(tileX + 1, tileCols - 1); }
24
+    uint8_t GetSkin() { return tile.x; }
25
+    void UpgradeLevel() { tile.x = std::min(tile.x + 1, tileDim.x - 1); }
26 26
 };
27 27
 }
28 28
 

BIN
res/player.png Ver arquivo


+ 2
- 3
src/bonus.cpp Ver arquivo

@@ -7,8 +7,7 @@ namespace pabloader {
7 7
 Bonus::Bonus(Debuggers* game)
8 8
     : Entity(game, &game->bonusesSprite)
9 9
 {
10
-    tileCols = 1;
11
-    tileRows = 3;
10
+    tileDim = { 1, 3 };
12 11
 #ifdef _DEBUG
13 12
     DEBUG_COLOR = olc::YELLOW;
14 13
 #endif
@@ -16,7 +15,7 @@ Bonus::Bonus(Debuggers* game)
16 15
 
17 16
 BonusType Bonus::GetType()
18 17
 {
19
-    return static_cast<BonusType>(tileX * 4 + tileY);
18
+    return static_cast<BonusType>(tile.x * 4 + tile.y);
20 19
 }
21 20
 
22 21
 void Bonus::ResetPosition()

+ 1
- 1
src/bug.cpp Ver arquivo

@@ -7,7 +7,7 @@ namespace pabloader {
7 7
 Bug::Bug(Debuggers* game)
8 8
     : Entity(game, &game->enemiesSprite)
9 9
 {
10
-    tileCols = 1;
10
+    tileDim.x = 1;
11 11
 #ifdef _DEBUG
12 12
     DEBUG_COLOR = olc::RED;
13 13
 #endif

+ 72
- 40
src/debuggers.cpp Ver arquivo

@@ -1,4 +1,5 @@
1 1
 #include "debuggers.h"
2
+#include <algorithm>
2 3
 #include <cmath>
3 4
 #include <ctime>
4 5
 #include <iostream>
@@ -11,6 +12,26 @@ std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
11 12
     return str;
12 13
 }
13 14
 
15
+template <>
16
+float Debuggers::GetRandom<float>(float from, float to)
17
+{
18
+    if (from > to) {
19
+        std::swap(from, to);
20
+    }
21
+    std::uniform_real_distribution<float> dist(from, to);
22
+    return dist(generator);
23
+}
24
+
25
+template <>
26
+int Debuggers::GetRandom<int>(int from, int to)
27
+{
28
+    if (from > to) {
29
+        std::swap(from, to);
30
+    }
31
+    std::uniform_int_distribution<int> dist(from, to - 1);
32
+    return dist(generator);
33
+}
34
+
14 35
 bool Debuggers::OnUserCreate()
15 36
 {
16 37
     SetPixelMode(olc::Pixel::MASK);
@@ -79,7 +100,7 @@ bool Debuggers::OnUserCreate()
79 100
         return false;
80 101
     }
81 102
 
82
-    fileName = "src/debuggers.cpp";
103
+    fileName = "src/programmer.cpp";
83 104
     auto streamBuffer = pack.GetStreamBuffer(fileName);
84 105
     if (streamBuffer.data == nullptr) {
85 106
         std::cerr << "[Load source] File " << fileName << " is not found" << std::endl;
@@ -117,6 +138,9 @@ bool Debuggers::OnUserUpdate(float fElapsedTime)
117 138
     DrawSprite(0, 0, &backgroundSprite);
118 139
 
119 140
     uint32_t bugsSize = bugs.size();
141
+    auto aliveBugs = std::count_if(bugs.begin(), bugs.end(), [](Bug* bug) { return bug->IsActive() && bug->IsAlive(); });
142
+
143
+    Programmer* player = programmers.at(0);
120 144
 
121 145
     for (auto bug : bugs) {
122 146
         if (bug->IsActive()) {
@@ -125,12 +149,15 @@ bool Debuggers::OnUserUpdate(float fElapsedTime)
125 149
             for (auto& programmer : programmers) {
126 150
                 if (programmer->Collides(bug)) {
127 151
                     bugsCatched++;
152
+                    if (programmer == player) {
153
+                        bugsCatchedByPlayer++;
154
+                    }
128 155
                     bug->Kill();
129 156
                     olc::SOUND::PlaySample(bugCatchSample);
130 157
                     SpawnBug();
131 158
                 }
132 159
             }
133
-        } else {
160
+        } else if (bug->IsAlive()) {
134 161
             bugsMissed++;
135 162
             sourceCode.erase(sourceCode.begin());
136 163
 
@@ -139,16 +166,29 @@ bool Debuggers::OnUserUpdate(float fElapsedTime)
139 166
         }
140 167
     }
141 168
 
142
-    Programmer* player = programmers.at(0);
143
-
144 169
     for (auto& bonus : bonuses) {
145 170
         if (bonus->IsActive()) {
146 171
             bonus->Update(fElapsedTime);
147 172
             bonus->Draw();
148 173
             if (player->Collides(bonus)) {
149
-                bonusesCatched[bonus->GetType()]++;
174
+                auto type = bonus->GetType();
175
+                if (type == BONUS_DOCUMENTATION) {
176
+                    if (aliveBugs > 1) {
177
+                        for (auto& bug : bugs) {
178
+                            if (bug->IsAlive() && bug->IsActive()) {
179
+                                bug->Kill();
180
+                                break;
181
+                            }
182
+                        }
183
+                    }
184
+                } else {
185
+                    bonusesCatched[type]++;
186
+                }
150 187
                 bonus->Kill();
188
+                // TODO play pickup sound
151 189
             }
190
+        } else {
191
+            bonus->Kill();
152 192
         }
153 193
     }
154 194
 
@@ -165,29 +205,41 @@ bool Debuggers::OnUserUpdate(float fElapsedTime)
165 205
         SpawnBug();
166 206
     }
167 207
 
168
-    if (bugsCatched >= 15 * bugsSize * programmers.size() && player->GetSkin() < bugsSize) {
208
+    auto programmersSize = programmers.size();
209
+    if (bugsCatchedByPlayer >= 15 * programmersSize * programmersSize && player->GetSkin() < programmersSize) {
169 210
         player->UpgradeLevel();
170 211
         SpawnBug();
171
-        SpawnBug();
172 212
         SpawnProgrammer();
173 213
     }
174 214
 
175
-#ifdef _DEBUG
176
-    DrawString(1, 37, "Bugs: " + std::to_string(bugs.size()));
177
-    DrawString(1, 46, "Progs: " + std::to_string(programmers.size()));
178
-    DrawString(1, 55, "Bonuses: " + std::to_string(bonuses.size()));
179
-    DrawString(1, 64, "DBG: " + std::to_string(bonusesCatched[BONUS_DEBUGGER]));
180
-    DrawString(1, 73, "UTS: " + std::to_string(bonusesCatched[BONUS_UNIT_TEST]));
181
-    DrawString(1, 82, "DOC: " + std::to_string(bonusesCatched[BONUS_DOCUMENTATION]));
182
-    
183
-    if (GetKey(olc::B).bPressed) {
215
+    if (bugsCatched > 10 * bugsSize) {
184 216
         SpawnBug();
185 217
     }
186
-    if (GetKey(olc::N).bPressed) {
218
+
219
+    if (GetRandom<float>() < 0.01 * fElapsedTime) {
187 220
         SpawnBonus();
188 221
     }
189
-    if (GetKey(olc::P).bPressed) {
190
-        SpawnProgrammer();
222
+
223
+#ifdef _DEBUG
224
+    if (debug) {
225
+        DrawString(1, 37, "Bg: " + std::to_string(bugs.size()) + " Ab: " + std::to_string(aliveBugs));
226
+        DrawString(1, 46, "Ps: " + std::to_string(programmers.size()) + " Bn: " + std::to_string(bonuses.size()));
227
+        DrawString(1, 55, "Cp: " + std::to_string(bugsCatchedByPlayer));
228
+        DrawString(1, 64, "DBG: " + std::to_string(bonusesCatched[BONUS_DEBUGGER]));
229
+        DrawString(1, 73, "UTS: " + std::to_string(bonusesCatched[BONUS_UNIT_TEST]));
230
+
231
+        if (GetKey(olc::B).bPressed) {
232
+            SpawnBug();
233
+        }
234
+        if (GetKey(olc::N).bPressed) {
235
+            SpawnBonus();
236
+        }
237
+        if (GetKey(olc::P).bPressed) {
238
+            SpawnProgrammer();
239
+        }
240
+    }
241
+    if (GetKey(olc::K0).bReleased) {
242
+        debug = !debug;
191 243
     }
192 244
 #endif
193 245
     DrawString(1, 1, "A,S,D - move; SPACE - jump", olc::CYAN);
@@ -240,7 +292,7 @@ void Debuggers::SpawnProgrammer()
240 292
 Bug* Debuggers::CreateBug()
241 293
 {
242 294
     for (auto bug : bugs) {
243
-        if (!bug->IsActive())
295
+        if (!bug->IsActive() || !bug->IsAlive())
244 296
             return bug;
245 297
     }
246 298
     auto bug = new Bug(this);
@@ -264,24 +316,4 @@ bool Debuggers::OnUserDestroy()
264 316
     olc::SOUND::DestroyAudio();
265 317
     return true;
266 318
 }
267
-
268
-template <>
269
-float Debuggers::GetRandom<float>(float from, float to)
270
-{
271
-    if (from > to) {
272
-        std::swap(from, to);
273
-    }
274
-    std::uniform_real_distribution<double> dist(from, to);
275
-    return dist(generator);
276
-}
277
-
278
-template <>
279
-int Debuggers::GetRandom<int>(int from, int to)
280
-{
281
-    if (from > to) {
282
-        std::swap(from, to);
283
-    }
284
-    std::uniform_int_distribution<int> dist(from, to - 1);
285
-    return dist(generator);
286
-}
287 319
 }

+ 35
- 15
src/entity.cpp Ver arquivo

@@ -2,55 +2,75 @@
2 2
 #include "debuggers.h"
3 3
 
4 4
 namespace pabloader {
5
-Entity::Entity(Debuggers* game, olc::Sprite* s): sprite(s), w(s->width / 4), h(s->height / 4)
5
+Entity::Entity(Debuggers* game, olc::Sprite* s)
6
+    : sprite(s)
7
+    , pos(0, 0)
8
+    , vel(0, 0)
9
+    , size(s->width / 4, s->height / 4)
6 10
 {
7 11
     Entity::game = game;
8 12
 }
9 13
 
10 14
 void Entity::Update(float dt)
11 15
 {
12
-    y += yv * dt;
13
-    yv += game->gravity * dt;
16
+    pos += vel * dt;
17
+    pos.y += game->gravity * dt;
14 18
 
15 19
     rotation += rotationSpeed * dt;
16 20
 
17 21
     transform.Reset();
18 22
     transform.Rotate(rotation);
19
-    transform.Translate(x, y);
23
+    transform.Translate(pos.x, pos.y);
20 24
 }
21 25
 
22 26
 bool Entity::Collides(Entity* entity)
23 27
 {
24
-    bool collidesX = (x - w / 2 < entity->x + entity->w / 2) && (entity->x - entity->w / 2 < x + w / 2);
25
-    bool collidesY = (y - h / 2 < entity->y + entity->h / 2) && (entity->y - entity->h / 2 < y + h / 2);
28
+    bool collidesX = (pos.x - size.x / 2 < entity->pos.x + entity->size.x / 2) && (entity->pos.x - entity->size.x / 2 < pos.x + size.x / 2);
29
+    bool collidesY = (pos.y - size.y / 2 < entity->pos.y + entity->size.y / 2) && (entity->pos.y - entity->size.y / 2 < pos.y + size.y / 2);
26 30
     return collidesX && collidesY;
27 31
 }
28 32
 
29 33
 void Entity::Draw()
30 34
 {
31 35
 #ifdef _DEBUG
32
-    game->DrawRect(x - w / 2, y - h / 2, w, h, DEBUG_COLOR);
36
+    if (game->debug) {
37
+        game->DrawRect(pos.x - size.x / 2, pos.y - size.y / 2, size.x, size.y, DEBUG_COLOR);
38
+    }
33 39
 #endif
34
-    olc::GFX2D::DrawPartialSprite(sprite, tileX * w, tileY * h, w, h, transform, true);
40
+    olc::GFX2D::DrawPartialSprite(sprite, tile.x * size.x, tile.y * size.y, size.x, size.y, transform, true);
35 41
 }
36 42
 
37 43
 bool Entity::IsActive()
38 44
 {
39
-    return y - h / 2 < game->GameScreenHeight();
45
+    return pos.y - size.y / 2 < game->GameScreenHeight();
46
+}
47
+bool Entity::IsInScreen()
48
+{
49
+    return pos.x > -size.x / 2 && pos.y > -size.y
50
+        && pos.x < game->ScreenWidth() + size.x / 2
51
+        && pos.x < game->ScreenHeight() + size.y / 2;
52
+}
53
+
54
+bool Entity::IsAlive()
55
+{
56
+    return alive;
40 57
 }
41 58
 
42 59
 void Entity::ResetPosition()
43 60
 {
44
-    y = game->GetRandom(-20, -game->ScreenHeight());
45
-    x = game->GetRandom(w, game->ScreenWidth() - w);
46
-    yv = 0;
47
-    tileX = game->GetRandom<int>(0, tileCols);
48
-    tileY = game->GetRandom<int>(0, tileRows);
61
+    pos.x = game->GetRandom(size.x, game->ScreenWidth() - size.x);
62
+    pos.y = game->GetRandom(-20, -game->ScreenHeight());
63
+    vel.x = 0;
64
+    vel.y = 0;
65
+    tile.x = game->GetRandom<int>(0, tileDim.x);
66
+    tile.y = game->GetRandom<int>(0, tileDim.y);
49 67
     rotationSpeed = game->GetRandom(-3.14f, 3.14f);
68
+    alive = true;
50 69
 }
51 70
 
52 71
 void Entity::Kill()
53 72
 {
54
-    y = game->ScreenHeight() + 100;
73
+    pos.y = game->ScreenHeight() + 100;
74
+    alive = false;
55 75
 }
56 76
 }

+ 6
- 4
src/player.cpp Ver arquivo

@@ -19,11 +19,13 @@ void Player::Think()
19 19
     walkRight = game->GetKey(olc::D).bHeld;
20 20
     moveDown = game->GetKey(olc::S).bHeld;
21 21
 #ifdef _DEBUG
22
-    // game->DrawString(1, 19, std::to_string(x) + " " + std::to_string(y));
23
-    // game->DrawString(1, 28, std::to_string(xv) + " " + std::to_string(yv));
22
+    if (game->debug) {
23
+        // game->DrawString(1, 19, std::to_string(x) + " " + std::to_string(y));
24
+        // game->DrawString(1, 28, std::to_string(xv) + " " + std::to_string(yv));
24 25
 
25
-    if (game->GetKey(olc::J).bPressed) {
26
-        tileX = (tileX + 1) % tileCols;
26
+        if (game->GetKey(olc::J).bPressed) {
27
+            tile.x = (tile.x + 1) % tileDim.x;
28
+        }
27 29
     }
28 30
 #endif
29 31
 }

+ 42
- 41
src/programmer.cpp Ver arquivo

@@ -7,9 +7,7 @@ namespace pabloader {
7 7
 Programmer::Programmer(Debuggers* game)
8 8
     : Entity(game, &game->playerSprite)
9 9
 {
10
-    x = (game->ScreenWidth() - w) / 2;
11
-    y = h / 2;
12
-    tileCols = 3;
10
+    pos = { (float)(game->ScreenWidth() - size.x) / 2, (float)size.y / 2 };
13 11
 
14 12
 #ifdef _DEBUG
15 13
     DEBUG_COLOR = olc::GREEN;
@@ -22,17 +20,17 @@ void Programmer::Think()
22 20
     float dist = 1e100;
23 21
     for (auto bug : game->bugs) {
24 22
         float d = bug->Dist(this);
25
-        if (d < dist && bug->GetY() > 0) {
23
+        if (d < dist && bug->IsInScreen() && bug->IsAlive()) {
26 24
             dist = d;
27 25
             closest = bug;
28 26
         }
29 27
     }
30 28
 
31 29
     if (closest != nullptr) {
32
-        doJump = closest->GetY() < y;
33
-        moveDown = closest->GetY() > y;
34
-        walkLeft = closest->GetX() < x;
35
-        walkRight = closest->GetX() > x;
30
+        doJump = closest->GetY() < pos.y;
31
+        moveDown = closest->GetY() > pos.y;
32
+        walkLeft = closest->GetX() < pos.x;
33
+        walkRight = closest->GetX() > pos.x;
36 34
     } else {
37 35
         doJump = false;
38 36
         walkLeft = false;
@@ -43,16 +41,15 @@ void Programmer::Think()
43 41
 
44 42
 void Programmer::Update(float dt)
45 43
 {
46
-    x += xv * dt;
47
-    y += yv * dt;
44
+    pos += vel * dt;
48 45
 
49
-    xv *= 1 - 0.2 * dt;
46
+    vel.x *= 1 - 0.2 * dt;
50 47
 
51 48
     if (!onGround) {
52
-        yv += (70 + tileX * 30) * dt;
53
-        yv *= 1 - 0.05 * dt;
49
+        vel.y += (70 + tile.x * 30) * dt;
50
+        vel.y *= 1 - 0.05 * dt;
54 51
     } else {
55
-        xv *= 1 - dt;
52
+        vel.x *= 1 - 3 * dt;
56 53
     }
57 54
 
58 55
     transform.Reset();
@@ -60,82 +57,86 @@ void Programmer::Update(float dt)
60 57
     bool userInput = false;
61 58
 
62 59
     if (doJump && onGround) {
63
-        yv = -100 - 50 * tileX;
60
+        vel.y = -100 - tile.x * 30;
64 61
         userInput = true;
65 62
     }
66 63
 
67 64
     if (walkLeft) {
68
-        xv -= (150 + tileX * 50) * dt;
65
+        vel.x -= (150 + tile.x * 30) * dt;
69 66
         userInput = true;
70 67
     }
71 68
 
72 69
     if (walkRight) {
73
-        xv += (150 + tileX * 50) * dt;
70
+        vel.x += (150 + tile.x * 30) * dt;
74 71
         userInput = true;
75 72
     }
76 73
 
77 74
     if (moveDown) {
78 75
         if (!onGround) {
79
-            yv += (150 + tileX * 50) * dt;
76
+            vel.y += (150 + tile.x * 30) * dt;
80 77
         }
81 78
         userInput = true;
82 79
     }
83 80
 
84
-    if (x > game->ScreenWidth() - w / 2) {
85
-        xv *= -0.3;
86
-        x = game->ScreenWidth() - w / 2;
81
+    if (pos.x > game->ScreenWidth() - size.x / 2) {
82
+        vel.x *= -0.3;
83
+        pos.x = game->ScreenWidth() - size.x / 2;
87 84
         olc::SOUND::PlaySample(game->playerFallSample);
88 85
     }
89 86
 
90
-    if (x < w / 2) {
91
-        xv *= -0.3;
92
-        x = w / 2;
87
+    if (pos.x < size.x / 2) {
88
+        vel.x *= -0.3;
89
+        pos.x = size.x / 2;
93 90
         olc::SOUND::PlaySample(game->playerFallSample);
94 91
     }
95 92
 
96
-    if (y > game->GameScreenHeight() - h / 2) {
97
-        yv *= -0.3;
93
+    auto groundLevel = game->GameScreenHeight() - size.y / 2 - 1;
98 94
 
99
-        if (std::abs(yv) < 2) {
100
-            yv = 0;
95
+    if (pos.y > groundLevel) {
96
+        vel.y *= -0.3;
97
+
98
+        if (std::abs(vel.y) < 2) {
99
+            vel.y = 0;
101 100
         }
102
-        y = game->GameScreenHeight() - h / 2;
101
+        pos.y = groundLevel;
103 102
     }
104 103
 
105
-    bool newOnGround = y >= game->GameScreenHeight() - h / 2;
104
+    bool newOnGround = pos.y >= groundLevel;
106 105
     if (newOnGround && !onGround) {
107 106
         olc::SOUND::PlaySample(game->playerFallSample);
108 107
     }
109 108
     onGround = newOnGround;
110 109
 
111 110
     if (onGround) {
112
-        tileY = 2;
111
+        tile.y = 2;
113 112
         tileCounter = static_cast<uint32_t>(0.1 / dt);
114 113
     } else if (tileCounter <= 0) {
115
-        tileY = 0;
114
+        tile.y = 0;
116 115
     } else {
117 116
         tileCounter--;
118 117
     }
119 118
 
120
-    if (!userInput && std::abs(xv) < 2) {
121
-        xv = 0;
119
+    if (!userInput && std::abs(vel.x) < 2) {
120
+        vel.x = 0;
122 121
     }
123
-    if (xv < 0) {
122
+    if (vel.x < 0) {
124 123
         transform.Scale(-1, 1);
125 124
     }
126
-    transform.Translate(x, y);
125
+    transform.Translate(pos.x, pos.y);
127 126
 }
128 127
 
129 128
 void Programmer::Draw()
130 129
 {
131
-    int xOff = xv < 0 ? -1 : 0;
132
-    if (std::abs(xv) < 1) {
133
-        olc::GFX2D::DrawPartialSprite(&game->playerSprite, tileX * w + xOff, h + tileY * h, w - xOff, h, transform, true);
130
+    int xOff = vel.x < 0 ? -1 : 0;
131
+    if (std::abs(vel.x) < 1) {
132
+        olc::GFX2D::DrawPartialSprite(&game->playerSprite, tile.x * size.x + xOff, size.y + tile.y * size.y, size.x - xOff, size.y, transform, true);
134 133
     } else {
135
-        olc::GFX2D::DrawPartialSprite(&game->playerSprite, tileX * w + xOff, 0 + tileY * h, w - xOff, h, transform, true);
134
+        olc::GFX2D::DrawPartialSprite(&game->playerSprite, tile.x * size.x + xOff, 0 + tile.y * size.y, size.x - xOff, size.y, transform, true);
136 135
     }
137 136
 #ifdef _DEBUG
138
-    game->DrawRect(x - w / 2, y - h / 2, w, h, DEBUG_COLOR);
137
+    if (game->debug) {
138
+        game->DrawRect(pos.x - size.x / 2, pos.y - size.y / 2, size.x, size.y, DEBUG_COLOR);
139
+    }
139 140
 #endif
140 141
 }
141 142
 }

Carregando…
Cancelar
Salvar