|
@@ -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;
|