Add sound with audio.beep, draw your own sprites in microStudio's sprite editor, then finish a game of your own and decide how to share it safely.
The same game feels completely different with your own pictures and sounds: that is most of what makes a game yours.
Your catching game works. Now make it look and sound like your game. microStudio has a Sprites tab for drawing pictures pixel by pixel, and audio.beep() plays notes from a short piece of text, such as "C E G".
Make your prediction first. Help opens once you've locked it in.
def init():
global t, seconds
t = 0
seconds = 0
def update():
global t, seconds
t += 1
if t % 60 == 0:
seconds += 1
audio.beep("C E G")
def draw():
screen.clear("rgb(10,10,40)")
screen.drawText(str(seconds) + " seconds", 0, 0, 16, "#FFF")
t % 60 is what is left over when t is divided by 60. When is it 0?
The catching game, with a sound on every catch (turn your sound on). Put it in microStudio and run it there too.
import random
class Star:
def __init__(self, x):
self.x = x
self.y = 100
self.speed = random.randint(5, 15) / 10
def move(self):
self.y -= self.speed
if self.y < -100:
self.restart()
def touches(self, x, y):
return abs(self.x - x) < 12 and abs(self.y - y) < 8
def restart(self):
self.y = 100
self.x = random.randint(-90, 90)
def draw(self):
screen.fillRound(self.x, self.y, 8, 8, "rgb(255,210,0)")
def pressed(key):
return hasattr(keyboard, key) and keyboard[key] != 0
def init():
global stars, px, score
stars = []
for i in range(4):
stars.append(Star(-60 + i * 40))
px = 0
score = 0
def update():
global px, score
if pressed("LEFT"):
px -= 2
if pressed("RIGHT"):
px += 2
for star in stars:
star.move()
if star.touches(px, -80):
score += 1
audio.beep("E G")
star.restart()
def draw():
screen.clear("rgb(10,10,40)")
for star in stars:
star.draw()
screen.fillRect(px, -80, 24, 6, "rgb(100,200,255)")
screen.drawText("Score: " + str(score), 0, 88, 10, "#FFF")
import random
class Star:
def __init__(self, x):
self.x = x
self.y = 100
self.speed = random.randint(5, 15) / 10
def move(self):
self.y -= self.speed
if self.y < -100:
self.restart()
def touches(self, x, y):
return abs(self.x - x) < 12 and abs(self.y - y) < 8
def restart(self):
self.y = 100
self.x = random.randint(-90, 90)
def draw(self):
screen.fillRound(self.x, self.y, 8, 8, "rgb(255,210,0)")
def pressed(key):
return hasattr(keyboard, key) and keyboard[key] != 0
def init():
global stars, px, score
stars = []
for i in range(4):
stars.append(Star(-60 + i * 40))
px = 0
score = 0
def update():
global px, score
if pressed("LEFT"):
px -= 2
if pressed("RIGHT"):
px += 2
for star in stars:
star.move()
if star.touches(px, -80):
score += 1
audio.beep("E G")
star.restart()
def draw():
screen.clear("rgb(10,10,40)")
for star in stars:
star.draw()
screen.fillRect(px, -80, 24, 6, "rgb(100,200,255)")
screen.drawText("Score: " + str(score), 0, 88, 10, "#FFF")
Once, where it happens.
From shape to picture.
What a stranger can see.
import random
class Star:
def __init__(self, x):
self.x = x
self.y = 100
self.speed = random.randint(5, 15) / 10
def move(self):
self.y -= self.speed
if self.y < -100:
self.restart()
def touches(self, x, y):
return abs(self.x - x) < 12 and abs(self.y - y) < 8
def restart(self):
self.y = 100
self.x = random.randint(-90, 90)
def draw(self):
screen.fillRound(self.x, self.y, 8, 8, "rgb(255,210,0)")
def pressed(key):
return hasattr(keyboard, key) and keyboard[key] != 0
def init():
global stars, px, score
stars = []
for i in range(4):
stars.append(Star(-60 + i * 40))
px = 0
score = 0
def update():
global px, score
if pressed("LEFT"):
px -= 2
if pressed("RIGHT"):
px += 2
for star in stars:
star.move()
if star.touches(px, -80):
score += 1
audio.beep("E G")
star.restart()
def draw():
screen.clear("rgb(10,10,40)")
for star in stars:
star.draw()
screen.fillRect(px, -80, 24, 6, "rgb(100,200,255)")
screen.drawText("Score: " + str(score), 0, 88, 10, "#FFF")
Draw a star and a player in microStudio's Sprites tab, and draw them in the game instead of the dot and the box:
def draw():
screen.clear("rgb(10,10,40)")
for star in stars:
screen.drawSprite("star", star.x, star.y, 12, 12)
screen.drawSprite("player", px, -80, 24, 12)
In microStudio's Sprites tab, add a sprite and name it star; draw it (16 × 16 is plenty). Make another called player.
In the star's draw(), replace the fillRound line with screen.drawSprite("star", self.x, self.y, 12, 12). Do the same for the paddle in draw().
Give the game two different sounds: one for a catch and another for something else.
Play a different beep for a miss or a game over, where it happens in update().
Try "duration 100 C E G" for shorter notes, or "saw C2" for a growl.
Make a game of your own, starting from your catching game or from an empty project: dodge instead of catch, a maze, a racing game, a clicker. It needs a goal, a way to win or lose, and your own sprites and sounds. Then ask a friend to play it without telling them how, watch what they do, and change one thing.
Sharing. A microStudio project is private until you make it public: then anyone can play it, and copy its code, from microStudio's Explore page. Ask your teacher before you publish, use a nickname, and leave out your name, school and photos. A guest's projects are deleted after about 15 days, so if you are a guest, make an account or copy your code somewhere safe.
From here: microStudio's documentation (the Help tab) has maps, music, gamepads and multiplayer. The same ideas carry into bigger engines such as Godot, whose GDScript looks a lot like Python.
Students add sounds with audio.beep where things happen, draw their own sprites in microStudio and draw them with screen.drawSprite, then make and playtest a game of their own and decide how to share it safely. About 60 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
Read the unit primer first. Turn sound on (headphones help). audio.beep("C E G") plays notes from text; words such as duration 100, tempo 160, square, saw and sine change how. Sprites are drawn in microStudio's Sprites tab and named there; screen.drawSprite("name", x, y, width, height) draws one (our site's games cannot show students' sprites, so the Modify step has no game on the page). Sharing: a project is private until it is made public; a public project can be played and copied by anyone from microStudio's Explore page, under the student's nickname. Decide your rule before the lesson (for example: publish only with your OK, nicknames only). Guest projects are deleted after about 15 days, so guests should make an account or keep a copy of their code. The Make step can run as a longer project; the Python pathway's For teachers notes suit a showcase.
Finishing: a game of their own is open-ended. Agree a small goal first (one change to the rules, own sprites, two sounds), then add.
Stretch: Add a title screen: a mode variable ("title", "play", "over") that update() and draw() check first.
Support: Start the Make step from the catching game and change only the sprites, the sounds and one rule.
The Python pathway's other extensions (data, web apps) use the same Python. microStudio's Help tab covers maps, music and multiplayer; Godot's GDScript is a natural next engine.