Pabloader 4 лет назад
Родитель
Сommit
10fc788141
6 измененных файлов: 30 добавлений и 16 удалений
  1. 1
    0
      .gitignore
  2. 2
    0
      include/bug.h
  3. 8
    5
      pge/src/olcPGEX_Graphics2D.cpp
  4. 11
    4
      src/bug.cpp
  5. 4
    3
      src/debuggers.cpp
  6. 4
    4
      src/programmer.cpp

+ 1
- 0
.gitignore Просмотреть файл

4
 *.o
4
 *.o
5
 *.pgp
5
 *.pgp
6
 *.pgs
6
 *.pgs
7
+*.res

+ 2
- 0
include/bug.h Просмотреть файл

15
 
15
 
16
 private:
16
 private:
17
     int kind = 0;
17
     int kind = 0;
18
+    float rotation = 0;
19
+    int8_t rotationSpeed;
18
 };
20
 };
19
 }
21
 }
20
 
22
 

+ 8
- 5
pge/src/olcPGEX_Graphics2D.cpp Просмотреть файл

8
 			return;
8
 			return;
9
 
9
 
10
 		// Work out bounding rectangle of sprite
10
 		// Work out bounding rectangle of sprite
11
-		float ex, ey;
12
-		float sx, sy;		
11
+		float ex=-1, ey=-1;
12
+		float sx, sy;
13
 		float px, py;
13
 		float px, py;
14
 
14
 
15
 		float x0 = 0;
15
 		float x0 = 0;
63
 			return;
63
 			return;
64
 
64
 
65
 		// Work out bounding rectangle of sprite
65
 		// Work out bounding rectangle of sprite
66
-		float ex, ey;
67
-		float sx, sy;		
66
+		float ex=-1, ey=-1;
67
+		float sx, sy;
68
 		float px, py;
68
 		float px, py;
69
 
69
 
70
 		float xOff = 0;
70
 		float xOff = 0;
108
 			{
108
 			{
109
 				float ox, oy;
109
 				float ox, oy;
110
 				transform.Backward(i, j, ox, oy);
110
 				transform.Backward(i, j, ox, oy);
111
-				pge->Draw((int32_t)i, (int32_t)j, sprite->GetPixel((int32_t)(xOff+x0+ox+0.5f), (int32_t)(yOff+y0+oy+0.5f)));
111
+				int32_t xx = (int32_t)(xOff+x0+ox+0.5f);
112
+				int32_t yy = (int32_t)(yOff+y0+oy+0.5f);
113
+				if (xx >= x0 && xx < x0 + w && yy >= y0 && yy < y0 + h) 
114
+					pge->Draw((int32_t)i, (int32_t)j, sprite->GetPixel(xx, yy));
112
 			}
115
 			}
113
 		}
116
 		}
114
 	}
117
 	}

+ 11
- 4
src/bug.cpp Просмотреть файл

4
 #include <random>
4
 #include <random>
5
 
5
 
6
 namespace pabloader {
6
 namespace pabloader {
7
-Bug::Bug(Debuggers* game_)
8
-    : Entity(game_)
7
+Bug::Bug(Debuggers* game)
8
+    : Entity(game)
9
 {
9
 {
10
     w = game->enemiesSprite.width / 4;
10
     w = game->enemiesSprite.width / 4;
11
     h = game->enemiesSprite.height / 4;
11
     h = game->enemiesSprite.height / 4;
15
 {
15
 {
16
     y += yv * dt;
16
     y += yv * dt;
17
     yv += 30 * dt;
17
     yv += 30 * dt;
18
+
19
+    rotation += 3.14 / 8 * rotationSpeed * dt;
20
+
21
+    transform.Reset();
22
+    transform.Rotate(rotation);
23
+    transform.Translate(x, y);
18
 }
24
 }
19
 
25
 
20
 void Bug::Draw()
26
 void Bug::Draw()
22
 #ifdef _DEBUG
28
 #ifdef _DEBUG
23
     game->DrawRect(x - w / 2, y - h / 2, w, h, olc::RED);
29
     game->DrawRect(x - w / 2, y - h / 2, w, h, olc::RED);
24
 #endif
30
 #endif
25
-    game->DrawPartialSprite(x, y, &game->enemiesSprite, 0, kind * h, w, h, 1, true);
31
+    olc::GFX2D::DrawPartialSprite(&game->enemiesSprite, 0, kind * h, w, h, transform, true);
26
 }
32
 }
27
 
33
 
28
 bool Bug::IsActive()
34
 bool Bug::IsActive()
32
 
38
 
33
 void Bug::ResetPosition()
39
 void Bug::ResetPosition()
34
 {
40
 {
35
-    y = -20 - std::rand() % 100;
41
+    y = -20 - std::rand() % game->ScreenHeight();
36
     x = w + std::rand() % (game->ScreenWidth() - w * 2);
42
     x = w + std::rand() % (game->ScreenWidth() - w * 2);
37
     yv = 0;
43
     yv = 0;
38
     kind = std::rand() % 4;
44
     kind = std::rand() % 4;
45
+    rotationSpeed = -8 + rand()%17;
39
 }
46
 }
40
 
47
 
41
 void Bug::Kill()
48
 void Bug::Kill()

+ 4
- 3
src/debuggers.cpp Просмотреть файл

1
 #include "debuggers.h"
1
 #include "debuggers.h"
2
 #include <cmath>
2
 #include <cmath>
3
+#include <ctime>
3
 #include <iostream>
4
 #include <iostream>
4
 #include <random>
5
 #include <random>
5
-#include <ctime>
6
 
6
 
7
 namespace pabloader {
7
 namespace pabloader {
8
 std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
8
 std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
140
         programmer->Draw();
140
         programmer->Draw();
141
     }
141
     }
142
 
142
 
143
-    Player* player = dynamic_cast<Player*>(programmers.at(0));
143
+    Programmer* player = programmers.at(0);
144
 
144
 
145
     if (bugsSize == 0 && player->IsOnGround()) {
145
     if (bugsSize == 0 && player->IsOnGround()) {
146
         SpawnBug();
146
         SpawnBug();
147
     }
147
     }
148
 
148
 
149
-    if (bugsCatched >= bugsSize * (15 * programmers.size()) && player->GetSkin() < bugsSize) {
149
+    if (bugsCatched >= 15 * bugsSize * programmers.size() && player->GetSkin() < bugsSize) {
150
         player->UpgradeLevel();
150
         player->UpgradeLevel();
151
         SpawnBug();
151
         SpawnBug();
152
+        SpawnBug();
152
         SpawnProgrammer();
153
         SpawnProgrammer();
153
     }
154
     }
154
 
155
 

+ 4
- 4
src/programmer.cpp Просмотреть файл

10
     w = game->playerSprite.width / 4;
10
     w = game->playerSprite.width / 4;
11
     h = game->playerSprite.height / 4;
11
     h = game->playerSprite.height / 4;
12
     x = (game->ScreenWidth() - w) / 2;
12
     x = (game->ScreenWidth() - w) / 2;
13
-    y = game->GameScreenHeight() / 2;
13
+    y = h / 2;
14
 }
14
 }
15
 
15
 
16
 void Programmer::Think()
16
 void Programmer::Think()
49
         yv += (70 + skin * 30) * dt;
49
         yv += (70 + skin * 30) * dt;
50
         yv *= 1 - 0.05 * dt;
50
         yv *= 1 - 0.05 * dt;
51
     } else {
51
     } else {
52
-        xv *= 1 - 0.5 * dt;
52
+        xv *= 1 - dt;
53
     }
53
     }
54
 
54
 
55
     transform.Reset();
55
     transform.Reset();
127
 {
127
 {
128
     int xOff = xv < 0 ? -1 : 0;
128
     int xOff = xv < 0 ? -1 : 0;
129
     if (std::abs(xv) < 1) {
129
     if (std::abs(xv) < 1) {
130
-        olc::GFX2D::DrawPartialSprite(&game->playerSprite, skin * w + xOff, h + tile * h, w, h, transform, true);
130
+        olc::GFX2D::DrawPartialSprite(&game->playerSprite, skin * w + xOff, h + tile * h, w - xOff, h, transform, true);
131
     } else {
131
     } else {
132
-        olc::GFX2D::DrawPartialSprite(&game->playerSprite, skin * w + xOff, 0 + tile * h, w, h, transform, true);
132
+        olc::GFX2D::DrawPartialSprite(&game->playerSprite, skin * w + xOff, 0 + tile * h, w - xOff, h, transform, true);
133
     }
133
     }
134
 #ifdef _DEBUG
134
 #ifdef _DEBUG
135
     game->DrawRect(x - w / 2, y - h / 2, w, h, olc::GREEN);
135
     game->DrawRect(x - w / 2, y - h / 2, w, h, olc::GREEN);

Загрузка…
Отмена
Сохранить