소스 검색

Separate Playes class

Pabloader 5 년 전
부모
커밋
c2b7985406
5개의 변경된 파일64개의 추가작업 그리고 25개의 파일을 삭제
  1. 1
    0
      .vscode/launch.json
  2. 2
    2
      pge/src/olcPGEX_Graphics2D.cpp
  3. BIN
      res/awoorwa.png
  4. 42
    17
      src/pabloader/awoorwae.cpp
  5. 19
    6
      src/pabloader/awoorwae.h

+ 1
- 0
.vscode/launch.json 파일 보기

@@ -4,6 +4,7 @@
4 4
     // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
5 5
     "version": "0.2.0",
6 6
     "configurations": [
7
+    
7 8
         {
8 9
             "name": "(gdb-win) Launch Packer",
9 10
             "type": "cppdbg",

+ 2
- 2
pge/src/olcPGEX_Graphics2D.cpp 파일 보기

@@ -33,7 +33,7 @@ namespace olc
33 33
 		sx = std::min(sx, px); sy = std::min(sy, py);
34 34
 		ex = std::max(ex, px); ey = std::max(ey, py);
35 35
 
36
-		transform.Forward((float)sprite->width, -y0, px, py);
36
+		transform.Forward((float)sprite->width-x0, -y0, px, py);
37 37
 		sx = std::min(sx, px); sy = std::min(sy, py);
38 38
 		ex = std::max(ex, px); ey = std::max(ey, py);
39 39
 
@@ -89,7 +89,7 @@ namespace olc
89 89
 		sx = std::min(sx, px); sy = std::min(sy, py);
90 90
 		ex = std::max(ex, px); ey = std::max(ey, py);
91 91
 
92
-		transform.Forward((float)w, -yOff, px, py);
92
+		transform.Forward((float)w-xOff, -yOff, px, py);
93 93
 		sx = std::min(sx, px); sy = std::min(sy, py);
94 94
 		ex = std::max(ex, px); ey = std::max(ey, py);
95 95
 

BIN
res/awoorwa.png 파일 보기


+ 42
- 17
src/pabloader/awoorwae.cpp 파일 보기

@@ -18,7 +18,7 @@ bool Awoorwae::OnUserCreate()
18 18
 
19 19
 bool Awoorwae::OnUserUpdate(float fElapsedTime)
20 20
 {
21
-    Clear(olc::BLACK);
21
+    Clear(olc::VERY_DARK_CYAN);
22 22
 
23 23
     player->Update(fElapsedTime);
24 24
     player->Draw();
@@ -29,17 +29,26 @@ Entity::Entity(Awoorwae* game_)
29 29
     : game(game_)
30 30
 {
31 31
     xv = 0;
32
-    yv = 30;
33
-    x = game->ScreenWidth() / 2;
34
-    y = game->ScreenHeight() / 2;
32
+    yv = 0;}
33
+
34
+Player::Player(Awoorwae* game_)
35
+    : Entity(game_)
36
+{
35 37
 }
36 38
 
37
-olc::rcode Entity::Load()
39
+olc::rcode Player::Load()
38 40
 {
39
-    return img.LoadFromPGESprFile("res/awoorwa.spr");
41
+    olc::rcode result = img.LoadFromPGESprFile("res/awoorwa.spr");
42
+    if (result) {
43
+        w = img.width / 4;
44
+        h = img.height / 4;
45
+    }
46
+    x = (game->ScreenWidth() - w) / 2;
47
+    y = game->ScreenHeight() / 2;
48
+    return result;
40 49
 }
41 50
 
42
-void Entity::Update(float dt)
51
+void Player::Update(float dt)
43 52
 {
44 53
     x += xv * dt;
45 54
     y += yv * dt;
@@ -49,6 +58,8 @@ void Entity::Update(float dt)
49 58
     if (!onGround) {
50 59
         yv += 50 * dt;
51 60
         yv *= 1 - 0.05 * dt;
61
+    } else {
62
+        xv *= 1 - 0.5 * dt;
52 63
     }
53 64
 
54 65
     transform.Reset();
@@ -76,26 +87,39 @@ void Entity::Update(float dt)
76 87
         userInput = true;
77 88
     }
78 89
 
79
-    if (x > game->ScreenWidth() - img.width / 2) {
90
+    if (game->GetKey(olc::J).bPressed) {
91
+        skin = 1 - skin;
92
+    }
93
+
94
+    if (x > game->ScreenWidth() - w / 2) {
80 95
         xv *= -0.3;
81
-        x = game->ScreenWidth() - img.width / 2;
96
+        x = game->ScreenWidth() - w / 2;
82 97
     }
83 98
 
84
-    if (x < img.width / 2) {
99
+    if (x < w / 2) {
85 100
         xv *= -0.3;
86
-        x = img.width / 2;
101
+        x = w / 2;
87 102
     }
88 103
 
89
-    if (y > game->ScreenHeight() - img.height / 4) {
104
+    if (y > game->ScreenHeight() - h / 2) {
90 105
         yv *= -0.3;
91 106
 
92 107
         if (std::abs(yv) < 2) {
93 108
             yv = 0;
94 109
         }
95
-        y = game->ScreenHeight() - img.height / 4;
110
+        y = game->ScreenHeight() - h / 2;
96 111
     }
97 112
 
98
-    onGround = y >= game->ScreenHeight() - img.height / 4;
113
+    onGround = y >= game->ScreenHeight() - h / 2;
114
+
115
+    if (onGround) {
116
+        tile = 2;
117
+        tileCounter = 30;
118
+    } else if (tileCounter <= 0) {
119
+        tile = 0;
120
+    } else {
121
+        tileCounter--;
122
+    }
99 123
 
100 124
     if (!userInput && std::abs(xv) < 2) {
101 125
         xv = 0;
@@ -106,12 +130,13 @@ void Entity::Update(float dt)
106 130
     transform.Translate(x, y);
107 131
 }
108 132
 
109
-void Entity::Draw()
133
+void Player::Draw()
110 134
 {
135
+    float xOff = xv < 0 ? -1: 0;
111 136
     if (std::abs(xv) < 1) {
112
-        olc::GFX2D::DrawPartialSprite(&img, 0, img.height / 2, img.width, img.height / 2, transform, true);
137
+        olc::GFX2D::DrawPartialSprite(&img, skin * w + xOff, h + tile * h, w, h, transform, true);
113 138
     } else {
114
-        olc::GFX2D::DrawPartialSprite(&img, 0, 0, img.width, img.height / 2, transform, true);
139
+        olc::GFX2D::DrawPartialSprite(&img, skin * w + xOff, 0 + tile * h, w, h, transform, true);
115 140
     }
116 141
 #ifdef _DEBUG
117 142
     float x, y;

+ 19
- 6
src/pabloader/awoorwae.h 파일 보기

@@ -8,31 +8,44 @@ namespace pabloader {
8 8
 class Awoorwae;
9 9
 
10 10
 class Entity {
11
-private:
11
+protected:
12 12
     Awoorwae* game;
13 13
     olc::Sprite img;
14 14
     olc::GFX2D::Transform2D transform;
15 15
     float x, y;
16 16
     float xv, yv;
17
+    int w, h;
18
+    int tile = 0;
19
+    int skin = 0;
20
+    int tileCounter = 0;
17 21
     bool onGround = false;
18 22
 
19 23
 public:
20 24
     Entity(Awoorwae* game_);
25
+    virtual ~Entity(){};
26
+
27
+    virtual olc::rcode Load() = 0;
28
+    virtual void Update(float dt) = 0;
29
+    virtual void Draw() = 0;
30
+};
21 31
 
22
-    void Update(float dt);
23
-    void Draw();
24
-    olc::rcode Load();
32
+class Player : public Entity {
33
+public:
34
+    Player(Awoorwae* game);
35
+    olc::rcode Load() override;
36
+    void Update(float dt) override;
37
+    void Draw() override;
25 38
 };
26 39
 
27 40
 class Awoorwae : public olc::PixelGameEngine {
28 41
 private:
29
-    Entity* player;
42
+    Player* player;
30 43
 
31 44
 public:
32 45
     Awoorwae()
33 46
     {
34 47
         sAppName = "Awoorwa";
35
-        player = new Entity(this);
48
+        player = new Player(this);
36 49
     }
37 50
 
38 51
     ~Awoorwae()

Loading…
취소
저장