You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: 2-design-and-development/2.2.23-cycle-23.md
+91-7
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,21 @@
1
-
# 2.2.23 Cycle 23: Fixing bugs and improving stability
1
+
# 2.2.23 Cycle 23: Small changes
2
2
3
3
## Design
4
4
5
+
In this cycle, I am making some small changes I decided right at the end of my project. 
5
6
7
+
Firstly, I am changing the way chests are deleted from the world when a player collides with them. Previously the chest was removed from the world stored on the server and then the updated version of the world would be sent to all clients. However, when I began hosting my game using GoDaddy, a Raspberry Pi, and Cloudflare tunnel, I noticed significant lag spikes when picking up chests which I attributed to the server sending out a large world array to multiple clients each time. Therefore now the co-ordinates of the chest will be broadcasted to clients which will then make the changes themselves.
8
+
9
+
Secondly, I am changing the way chests are placed on the map. Previously they were randomly scattered but I decided I did not like this method as it results in large clusters of chests generating in random parts of the road and some areas being incredibly sparse of chests. I decided on a more equal distribution method, which would be to have chests in rows with equal space between them.
10
+
11
+
Finally, I am introducing checks for player movement to make sure no car goes off the road. I was concerned some players might wander outside of camera view and struggle to find where their car is. The player will not be able to go off the sides of the road.
6
12
7
13
### Objectives
8
14
9
-
*[ ] Show error if the player disconnects while playing.
10
-
*[] Fix lag when picking up chests.
11
-
*[ ] Remove player's name from waiting screen if they leave.
12
-
*[ ] Add chests in rows spaced equally apart rather than randomly scattered.
15
+
*[x] Add chests in rows spaced equally apart rather than randomly scattered.
16
+
*[x] Fix lag when picking up chests.
17
+
*[x] Stop player moving off the sides of the road.
18
+
*[x] Remove usernames of players who leave during waiting.
13
19
14
20
### Usability Features
15
21
@@ -28,9 +34,87 @@
28
34
29
35
### Outcome
30
36
37
+
On completion of this cycle, I have implemented a few small changes to the game that I saw would be beneficial to the user experience as well as stability.
38
+
39
+
Firstly, I have changed the way chests are placed on the road during world generation. In Cycle 8, I wrote chests to be randomly scattered on the road, as I initially liked the idea of the chests being in different places each time. However, I found this to often result in large clusters of chests in some places and a lack of them in others and so decided to change it. 
40
+
41
+
Instead of using addProps to put chests in the road, I created a new function known as scatterChest that places chests on the road of the world in rows with a specified number of blocks space between them. The Y co-ordinate of the starting row is a random number between 20 and 25 to ensure some variety, but the furthest row can be 960. The function then adds rows to the world up until the limit, with spacing in between. 
42
+
43
+
{% code title="server.js" %}
44
+
```javascript
45
+
functionscatterChests(world, space) {
46
+
conststart=Math.floor(Math.random() *5) +20
47
+
constend=960
48
+
49
+
for (let y = start; y < end; y += space) {
50
+
for (let x =8; x <13; x++) {
51
+
world.push({
52
+
x: x,
53
+
y: y,
54
+
z:2,
55
+
name:"chest"
56
+
})
57
+
}
58
+
}
59
+
}
60
+
```
61
+
{% endcode %}
62
+
63
+
The line using addProps to add chests is replaced by using the scatterChests function:
31
64
65
+
{% code title="server.js" %}
66
+
```javascript
67
+
scatterChests(world, 30)
68
+
```
69
+
{% endcode %}
70
+
71
+
Secondly, I have changed the system of picking up chests to solve lag when hosting on a domain. Previously the chest was deleted from the world stored on the server and an updated copy was sent to clients, but this resulted in lag. Instead, when the player collides with a chest, the game removes it from the local world and then sends an event to other clients with the position of the chest for them to do the same.
Thirdly, I have introduced measures to make sure the player does not move their car off of the road. This is intended to prevent the player losing track of their car in the case it does go off screen. 750 and 1250 are the X co-ordinates of each side of the road.
98
+
99
+
{% code title="public/sprites/car.js" %}
100
+
```javascript
101
+
functionaddMechanics(car) {
102
+
// setup properties
103
+
onUpdate(() => {
104
+
// movement
105
+
106
+
if (car.pos.x<750) {
107
+
car.pos.x=750
108
+
}
109
+
if (car.pos.x>1250) {
110
+
car.pos.x=1250
111
+
}
112
+
})
113
+
}
114
+
```
115
+
{% endcode %}
32
116
33
-
### Challenges
117
+
Finally, I have made so if a player leaves the room while they are still waiting to start the game, their username is removed and when the game starts, they are not counted or assigned a car. 
34
118
35
119
36
120
@@ -40,7 +124,7 @@ Evidence for testing
40
124
41
125
### Tests
42
126
43
-
<table><thead><tr><thwidth="95">Test</th><thwidth="158">Instructions</th><thwidth="171">What I expect</th><thwidth="174">What actually happens</th><th>Pass/Fail</th></tr></thead><tbody><tr><td>1</td><td>Run initial code</td><td></td><td></td><td></td></tr></tbody></table>
127
+
<table><thead><tr><th width="95">Test</th><th width="158">Instructions</th><th width="171">What I expect</th><th width="174">What actually happens</th><th>Pass/Fail</th></tr></thead><tbody><tr><td>1</td><td>Place rows of chests in the road during world generation.</td><td>Rows of chests in the road during world generation.</td><td>As expected</td><td>Pass</td></tr><tr><td>2</td><td>If player collides with chest, delete the chest from the world.</td><td>Chest disappears from road after player collides with it.</td><td>As expected</td><td>Pass</td></tr><tr><td>3</td><td>Stop player moving off the sides of the road.</td><td>Players cannot move off the side of the road.</td><td>As expected</td><td>Pass</td></tr><tr><td>4</td><td>If a player leaves during waiting, remove their username.</td><td>Username of player removed if they leave during waiting.</td><td>As expected</td><td>Pass</td></tr></tbody></table>
0 commit comments