Skip to content

Commit 9bf0f9b

Browse files
authored
Merge pull request #61 from Renardjojo/feature/global_balancing
Global balancing and fix collision display mode
2 parents 6ad7d1b + 1e90bdd commit 9bf0f9b

File tree

5 files changed

+97
-60
lines changed

5 files changed

+97
-60
lines changed

content/setting/animation.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ Nodes:
1212
sprite: idle2.png
1313
sizeFactor: 2
1414
tileCount: 14
15-
framerate: 8
15+
framerate: 7
1616
loop: true
1717
AnimationNode:
1818
name: sleep
1919
sprite: sleep.png
2020
sizeFactor: 2
2121
tileCount: 6
22-
framerate: 6
22+
framerate: 4
2323
loop: true
2424
GrabNode:
2525
name: grab
@@ -75,9 +75,9 @@ Transitions:
7575
to: grab
7676
RandomDelayTransition:
7777
from: idle1
78-
to: [walk, jump, sleep, fly]
79-
duration: 3000
80-
interval: 1000
78+
to: [walk, walk, jump, sleep]
79+
duration: 4000
80+
interval: 2000
8181
IsNotGroundedTransition:
8282
from: idle1
8383
to: air
@@ -86,8 +86,8 @@ Transitions:
8686
to: grab
8787
RandomDelayTransition:
8888
from: idle2
89-
to: [walk, jump, sleep, fly]
90-
duration: 3000
89+
to: [walk, jump, jump, fly]
90+
duration: 2000
9191
interval: 1000
9292
IsNotGroundedTransition:
9393
from: idle2
@@ -101,8 +101,8 @@ Transitions:
101101
RandomDelayTransition:
102102
from: walk
103103
to: [idle1, idle2]
104-
duration: 3000
105-
interval: 500
104+
duration: 2000
105+
interval: 1000
106106
TouchScreenEdgeTransition:
107107
from: fly
108108
to: [idle1, idle2]
@@ -112,8 +112,8 @@ Transitions:
112112
RandomDelayTransition:
113113
from: fly
114114
to: [idle1, idle2]
115-
duration: 5000
116-
interval: 1000
115+
duration: 6000
116+
interval: 2000
117117
StartLeftClicTransition:
118118
from: jump
119119
to: grab
@@ -135,5 +135,5 @@ Transitions:
135135
RandomDelayTransition:
136136
from: sleep
137137
to: [idle1, idle2]
138-
duration: 9000
139-
interval: 1000
138+
duration: 30000
139+
interval: 15000

content/setting/setting.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ Physic:
77
Friction: 0.85 # [0, 1] : 0 no friction, 1 max friction
88
GravityX: 0
99
GravityY: 9.81
10-
Bounciness: 0.7 # [0, 1] : 0 no bounciness, 1 full energie restitution
10+
Bounciness: 0.6 # [0, 1] : 0 no bounciness, 1 full energie restitution
1111
ContinuousCollisionMaxVelocity: 40 # min 0
12-
FootBasementWidth: 4 # min 2
12+
FootBasementWidth: 6 # min 2
1313
FootBasementHeight: 2 # min 2
1414
CollisionPixelRatioStopMovement: 0.3 # min 0, max 1. Ratio of pixel with collision to detect a real collision
1515
IsGroundedDetection: 1.0 # min 0
16-
InputReleaseImpulse: 3.0 # min 0
16+
InputReleaseImpulse: 1.0 # min 0. Velocity factor after release the pet
1717
GamePlay:
18-
CoyoteTimeCursorMovement: 0.1 # min 0
18+
CoyoteTimeCursorMovement: 0.05 # min 0. Record duration of the velocity before released the pet to preserve velocity with the mouse movement
1919
Window:
2020
ShowFrameBufferBackground: false
21-
UseForwardWindow: true
22-
ShowWindow: false
23-
UseMousePassThoughWindow: true
21+
UseForwardWindow: true # Define if the application should be displayed in forground
22+
ShowWindow: false # Display the window edge or not
23+
UseMousePassThoughWindow: true # Define if user can selection pet only with selected pixel or with the entire windows
2424
Debug:
25-
ShowEdgeDetection: false
25+
ShowEdgeDetection: false # Debug mode to display the result of the collision alogyrthm on the entire window

include/Engine/TimeManager.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class TimeManager
5858
m_timerQueue.emplace(functionToExecute, delay, delay + datas.timeAcc, isLooping);
5959
}
6060

61+
void setFrameRate(int FPS)
62+
{
63+
m_fixedDeltaTime = 1. / FPS;
64+
}
65+
6166
void update(std::function<void(double deltaTime)> unlimitedUpdateFunction,
6267
std::function<void(double deltaTime)> limitedUpdateFunction)
6368
{

include/Game/Game.hpp

Lines changed: 67 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
#include "Engine/SpriteSheet.hpp"
1313
#include "Engine/Texture.hpp"
1414
#include "Engine/TimeManager.hpp"
15+
#include "Engine/Updater.hpp"
1516
#include "Engine/Utilities.hpp"
1617
#include "Engine/Vector2.hpp"
1718
#include "Engine/Window.hpp"
18-
#include "Engine/Updater.hpp"
1919

2020
#include <GLFW/glfw3.h>
2121
#include <glad/glad.h>
@@ -58,10 +58,10 @@ class Game
5858

5959
glfwSetMonitorCallback(setMonitorCallback);
6060
datas.monitors.init();
61-
Vec2i monitorSize = datas.monitors.getMonitorsSize();
61+
Vec2i monitorSize = datas.monitors.getMonitorsSize();
6262
Vec2i monitorsSizeMM = datas.monitors.getMonitorPhysicalSize();
6363

64-
datas.windowSize = {1, 1};
64+
datas.windowSize = {1, 1};
6565

6666
// Evaluate pixel distance based on dpi and monitor size
6767
datas.pixelPerMeter = {(float)monitorSize.x / (monitorsSizeMM.x * 0.001f),
@@ -121,18 +121,8 @@ class Game
121121

122122
createResources();
123123

124-
Vec2i mainMonitorPosition;
125-
Vec2i mainMonitorSize;
126-
datas.monitors.getMainMonitorWorkingArea(mainMonitorPosition, mainMonitorSize);
127-
128-
datas.windowPos = mainMonitorPosition + mainMonitorSize / 2;
129-
datas.petPos = datas.windowPos;
130-
glfwSetWindowPos(datas.window, datas.windowPos.x, datas.windowPos.y);
131-
132124
glfwShowWindow(datas.window);
133-
134125
glfwSetWindowUserPointer(datas.window, &datas);
135-
136126
glfwSetMouseButtonCallback(datas.window, mousButtonCallBack);
137127
glfwSetCursorPosCallback(datas.window, cursorPositionCallback);
138128

@@ -159,8 +149,64 @@ class Game
159149
glfwTerminate();
160150
}
161151

152+
void runCollisionDetectionMode()
153+
{
154+
const std::function<void(double)> unlimitedUpdate{[&](double deltaTime) {
155+
// poll for and process events
156+
glfwPollEvents();
157+
}};
158+
159+
int frameCount = 0;
160+
const std::function<void(double)> limitedUpdateDebugCollision{[&](double deltaTime) {
161+
++frameCount;
162+
163+
// render
164+
initDrawContext();
165+
166+
if (!(frameCount & 1) && datas.pImageGreyScale && datas.pEdgeDetectionTexture && datas.pFullScreenQuad)
167+
{
168+
datas.pImageGreyScale->use();
169+
datas.pImageGreyScale->setInt("uTexture", 0);
170+
datas.pFullScreenQuad->use();
171+
datas.pEdgeDetectionTexture->use();
172+
datas.pFullScreenQuad->draw();
173+
}
174+
175+
// swap front and back buffers
176+
glfwSwapBuffers(datas.window);
177+
178+
if (frameCount & 1)
179+
{
180+
Vec2 newPos;
181+
physicSystem.CatpureScreenCollision(datas.windowSize, newPos);
182+
}
183+
}};
184+
185+
// fullscreen
186+
Vec2i monitorSize;
187+
datas.monitors.getMonitorSize(0, monitorSize);
188+
datas.windowSize = monitorSize;
189+
glfwSetWindowSize(datas.window, datas.windowSize.x, datas.windowSize.y);
190+
glfwSetWindowPos(datas.window, 0, 0);
191+
glfwSetWindowAttrib(datas.window, GLFW_MOUSE_PASSTHROUGH, true);
192+
glfwSetWindowAttrib(datas.window, GLFW_TRANSPARENT_FRAMEBUFFER, true);
193+
mainLoop.setFrameRate(1);
194+
195+
mainLoop.start();
196+
while (!glfwWindowShouldClose(datas.window))
197+
{
198+
mainLoop.update(unlimitedUpdate, limitedUpdateDebugCollision);
199+
}
200+
}
201+
162202
void run()
163203
{
204+
if (datas.debugEdgeDetection)
205+
{
206+
runCollisionDetectionMode();
207+
return;
208+
}
209+
164210
Pet pet(datas);
165211

166212
const std::function<void(double)> unlimitedUpdate{[&](double deltaTime) {
@@ -172,6 +218,7 @@ class Game
172218
// poll for and process events
173219
glfwPollEvents();
174220
}};
221+
175222
const std::function<void(double)> limitedUpdate{[&](double deltaTime) {
176223
pet.update(deltaTime);
177224

@@ -188,35 +235,20 @@ class Game
188235
}
189236
}};
190237

191-
const std::function<void(double)> limitedUpdateDebugCollision{[&](double deltaTime) {
192-
// fullscreen
193-
Vec2i monitorSize = datas.monitors.getMonitorsSize();
194-
datas.windowSize = monitorSize;
195-
glfwSetWindowSize(datas.window, datas.windowSize.x, datas.windowSize.y);
196-
197-
// render
198-
initDrawContext();
199-
200-
if (datas.pImageGreyScale && datas.pEdgeDetectionTexture && datas.pFullScreenQuad)
201-
{
202-
datas.pImageGreyScale->use();
203-
datas.pImageGreyScale->setInt("uTexture", 0);
204-
datas.pFullScreenQuad->use();
205-
datas.pEdgeDetectionTexture->use();
206-
datas.pFullScreenQuad->draw();
207-
}
208-
209-
// swap front and back buffers
210-
glfwSwapBuffers(datas.window);
211-
}};
238+
Vec2i mainMonitorPosition;
239+
Vec2i mainMonitorSize;
240+
datas.monitors.getMainMonitorWorkingArea(mainMonitorPosition, mainMonitorSize);
241+
datas.windowPos = mainMonitorPosition + mainMonitorSize / 2;
242+
datas.petPos = datas.windowPos;
243+
glfwSetWindowPos(datas.window, datas.windowPos.x, datas.windowPos.y);
212244

213245
mainLoop.emplaceTimer([&]() { physicSystem.update(1.f / datas.physicFrameRate); }, 1.f / datas.physicFrameRate,
214246
true);
215247

216248
mainLoop.start();
217249
while (!glfwWindowShouldClose(datas.window))
218250
{
219-
mainLoop.update(unlimitedUpdate, datas.debugEdgeDetection ? limitedUpdateDebugCollision : limitedUpdate);
251+
mainLoop.update(unlimitedUpdate, limitedUpdate);
220252
}
221253
}
222254
};

include/Game/Pet.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class NeedUpdator
117117
NeedUpdator(GameData& datas, DialoguePopUp& dialoguePopup, UtilitySystem& utilitySystem)
118118
: m_datas{datas}, m_dialoguePopup{dialoguePopup}, m_utilitySystem{utilitySystem}
119119
{
120-
nexTimeDisplayPopup = randNum(5000, 10000) / 1000.f;
120+
nexTimeDisplayPopup = randNum(10000, 30000) / 1000.f;
121121
}
122122

123123
void update(float deltaTime)
@@ -131,7 +131,7 @@ class NeedUpdator
131131
m_dialoguePopup.display(1.f, EPopupType::Dialogue, ENeed::Angry);
132132
displayPopupCurrentTimer = 0;
133133
lastNeed = currentNeedIndex;
134-
nexTimeDisplayPopup = randNum(5000, 10000) / 1000.f;
134+
nexTimeDisplayPopup = randNum(10000, 30000) / 1000.f;
135135
}
136136
else
137137
{
@@ -140,7 +140,7 @@ class NeedUpdator
140140
if (displayPopupCurrentTimer > nexTimeDisplayPopup)
141141
{
142142
displayPopupCurrentTimer -= nexTimeDisplayPopup;
143-
nexTimeDisplayPopup = randNum(5000, 10000) / 1000.f;
143+
nexTimeDisplayPopup = randNum(10000, 30000) / 1000.f;
144144
m_dialoguePopup.display(2.f, EPopupType::Dialogue, ENeed::Angry);
145145
}
146146
}
@@ -152,7 +152,7 @@ class NeedUpdator
152152
if (displayPopupCurrentTimer > nexTimeDisplayPopup)
153153
{
154154
displayPopupCurrentTimer -= nexTimeDisplayPopup;
155-
nexTimeDisplayPopup = randNum(5000, 10000) / 1000.f;
155+
nexTimeDisplayPopup = randNum(10000, 30000) / 1000.f;
156156
m_dialoguePopup.display(2.f, EPopupType::Dialogue, ENeed::Love);
157157
}
158158
}

0 commit comments

Comments
 (0)