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: projects/build-a-conversational-game-in-p5js/build-a-conversational-game-in-p5js.mdx
+18-15Lines changed: 18 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,9 +33,9 @@ tags:
33
33
uid={true}
34
34
/>
35
35
36
-
**Prerequisites**: p5.js, JavaScript
37
-
**Version**: p5@1.11.2, JavaScript ES2023
38
-
**Read Time**: 30 minutes
36
+
**Prerequisites**: p5.js, JavaScript
37
+
**Version**: p51.11.2
38
+
**Read Time**: 30 minutes
39
39
40
40
## Introduction
41
41
@@ -88,10 +88,12 @@ Hi, my name is ✨Julien✨, and I’m the new Senior Curriculum Developer here
88
88
</p>
89
89
</div>
90
90
91
-
Since this is my first project tutorial here at Codédex, I’m revisiting the first coding project I ever finished. I made it ten years ago using [Processing](https://processing.org) (the Java-based precursor to p5.js).
91
+
Since this is my first project tutorial here at Codédex, I’m revisiting the first coding project I ever finished. I made it ten years ago using [Processing](https://processing.org) (the Java-based precursor to the p5.js library).
92
92
93
93
## A Conversation
94
94
95
+
Here's the project:
96
+
95
97
The game is called *A Conversation*, and it’s a two-player game of Pong, but with a twist. Instead of each paddle, I drew a person’s head facing toward the center, and instead of a ball, I drew a speech bubble. As players hit the speech bubble back and forth, the text inside the speech bubble changes to form a conversation.
96
98
97
99
<RoundedImage
@@ -117,11 +119,11 @@ I spent a lot of 2014 thinking about the ways people communicate nonverbally whi
117
119
The conversation itself was…hm…it was pretty dramatic. I wasn’t sure if I was going to make this tutorial, because I was a little embarrassed by the narrative stylings of nineteen-year-old Julien. But honestly? I think it’s important to honor our past selves. I was learning to code for the first time after a lifetime of considering myself An Artist Not A Programmer.
118
120
119
121
<RoundedImage
120
-
link="https://i.imgur.com/cA4UduS.png"
122
+
link="https://i.imgur.com/XyJaet1.png"
121
123
description=""
122
124
/>
123
125
124
-
<divstyle={{ textAlign: "center"}}>
126
+
<divstyle={{ textAlign: "center"}}>
125
127
[@WarronBebster](https://x.com/warronbebster)
126
128
</div>
127
129
@@ -136,7 +138,7 @@ I found this email to my community college professor where I gave her some conte
136
138
description=""
137
139
/>
138
140
139
-
Omg,,,,
141
+
Omg....
140
142
Anyway, let’s dive in!
141
143
142
144
@@ -157,7 +159,7 @@ For this year’s iteration of Pong, I decided to have a conversation with my pa
157
159
158
160
### Upgrading From Simple Pong
159
161
160
-
There were a few elements I added to upgrade the sketch from the WASD (Pong) exercise in our p5.js tutorial. Here is a link to the [Codédex Exercise](https://www.codedex.io/p5js/05-wasd) that features single-player Pong. Here is the [starter code](https://www.codedex.io/@Julien/build/pong-as-a-conversation-starter-code) for a basic two-player pong game, which looks a bit different from the Codédex exercise.
162
+
There were a few elements I added to upgrade the sketch from the WASD (Pong) exercise in our p5.js tutorial. Here is a link to the [Codédex exercise](https://www.codedex.io/p5js/05-wasd) that features single-player Pong. Here is the [starter code](https://www.codedex.io/@Julien/build/pong-as-a-conversation-starter-code) for a basic two-player pong game, which looks a bit different from the Codédex exercise.
161
163
162
164
<RoundedImage
163
165
link="https://i.imgur.com/leVbTL9.gif"
@@ -168,11 +170,11 @@ There were a few elements I added to upgrade the sketch from the WASD (Pong) exe
168
170
169
171
So, how do we go from a screensaver to a conversation? I find it helpful to break down the process into smaller steps. I’m gonna show you three things that can personalize our basic Pong game. 🕹️
170
172
171
-
🎧**Step 1: Add a looping soundtrack**
173
+
🎧**Step 1: Add a looping soundtrack**
172
174
173
-
The first thing I want to do is add a soundtrack, to give the game ambiance. To play sound files in p5.js in the Codédex IDE, you’ll need to link to a url containing a .ogg audio file. You can find a ton of .ogg files with varying moods [here](https://developers.google.com/assistant/tools/sound-library). I chose an ambient outdoor summer track since I’ve always loved laying in the grass while reading a book in the park!
175
+
The first thing I want to do is add a soundtrack, to give the game ambiance. To play sound files in p5.js in the Codédex IDE, you’ll need to link to a url containing a **.ogg** audio file. You can find a ton of .ogg files with varying moods [here](https://developers.google.com/assistant/tools/sound-library). I chose an ambient outdoor summer track since I’ve always loved laying in the grass while reading a book in the park!
174
176
175
-
Declare a `gameSoundtrack` variable and define it in the preload function, where audio (and images!) load before the setup function.
177
+
Declare a `gameSoundtrack` variable and define it in the preload function, where audio (and images!) load before the `setup()` function.
176
178
177
179
```js
178
180
let gameSoundtrack;
@@ -193,7 +195,7 @@ function setup(){
193
195
}
194
196
```
195
197
196
-
🕺🏻**Step 2: Replace paddles with player images**
198
+
🕺🏻**Step 2: Replace paddles with player images**
197
199
198
200
To add images for the players, you’ll need to draw or find transparent PNGs. Since I decided to have a conversation with my younger self this time, I found a recent photo of me posing in a way that’s similar to a photo of me posing as a kid. Then, I removed their backgrounds with [Adobe’s Free Image Background Remover](https://www.adobe.com/express/feature/image/remove-background) and did some light editing in Adobe Express.
199
201
@@ -231,7 +233,7 @@ function preload() {
231
233
}
232
234
```
233
235
234
-
I replaced the paddle rectangles with images in the showPaddle function.
236
+
I replaced the paddle rectangles with images in the `showPaddle()` function.
235
237
236
238
```js
237
239
functionshowPaddle(playerNumber){
@@ -283,8 +285,9 @@ In the `drawGame()` function, I draw the text, and position it with the ball coo
283
285
textSize(20);
284
286
fill(255);
285
287
textAlign(CENTER);
288
+
286
289
if (showBall ==true){
287
-
text(convoText[phrase], ball.h, ball.v);
290
+
text(convoText[phrase], ball.h, ball.v);
288
291
}
289
292
pop();
290
293
```
@@ -294,7 +297,7 @@ In the `moveBall()` function, I cycle through the text array each time the ball
0 commit comments