PLIRO / Project
Make a short melody for your game
Four notes can announce a victory. Program a short chiptune, change one note and hear the difference. You do not need a sound file or a musical instrument.
Start the working example01
What you will practise
- Read a melody as a sequence of notes.
- Change pitch while keeping the rhythm the same.
- Connect a short melody to a moment in a game.
02
What you need
- An internet-connected device, an up-to-date browser and working sound.
- Headphones or speakers at a low volume.
- Press Run yourself: browsers may block sound that starts automatically.
Preparation
- Test sound in advance and turn the device volume down.
- Read the four notes C4, E4, G4 and C5 in the example code.
- The :1 after each note means one beat. At 120 beats per minute, the melody takes about two seconds.
Project
Step by step
Hear the starting melody
Open the project and press Run yourself. Four rising notes play once. If you hear nothing, check your device and browser volume.
Read the notes in Code
C4:1 E4:1 G4:1 C5:1 describes four one-beat notes. The number after the note letter sets the octave; C5 is higher than C4.
Change one note
Replace only the final C5:1 with G4:1. Leave the tempo, wait time and other code alone. Run again and listen to the different ending.
Design a game moment
Choose a moment such as finding a key or winning a round. Make a variation with four one-beat notes, so the two-second wait still fits.
Save and compare
Download your code using the button inside the project. Play both versions to someone and ask which fits your game moment better.
Try it yourself
This starting code works. Open the project, choose Code, then Text, to change something, then press Run.
# language: en
setVolume(40)
let melody = "C4:1 E4:1 G4:1 C5:1"
startMelody("win", melody, 120, "chip", false)
wait(2)
stopTrack("win")
say "Your victory music is ready."
The example result
The starting version plays C4, E4, G4 and C5 with a chip sound, once, at 120 beats per minute. Output then says your victory music is ready.
Discuss what you discovered
Which note changed and what difference did you hear? A different musical preference is not a programming error.
A next step
