Blog: 2024-11-03
Alright time to wrap👏🏼it👏🏼up and get to bed so I can be ... awake for tomorrow ...
I think it's worth giving the kids a big scratch project like the flappy bird one, printed out, and ask them to make it. Maybe to make a little simpler one first ... nim ? Turn based games are good to explain logic ... most games have too many rules tho.
I have my amoung us text adventure game but it's not done ... it's not that fun but could have some humor and interest
import random splash = """ @@@@@@@@@@@@ @@@@@ @@@@@@ @@@ @@@@ @@@ @@@@@@@@@@@@@@ @@@ @@@@ @@@@@@ @@@ @@ @@@@ @@@@ @@@ @@@ @@@@@@@@ @@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@@ @@@@ @@ @@@ @@@@@ @@@@@@@ @@ @@ @@@@@@@@@@@@ @@ @@@ @@ @@ @@@ @@ @@@ @@ @@ @@@ @@ @@@ @@@ @@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@ @@@ @@@ @@ @@@@@@@ @@@@@@@@ @@ @@ @@ @@ @@@ @@ @@@ @@ @@@ @@@ @@@ @@ @@@ @@@ @@@ @@ @@@ @@@ @@@ @@@@@@@@@@@ @@@@@@@@@@@@ """ def main(): print(splash) print('Welcome to ascii amogus.') room = 'cafeteria' reported = False print(f'You are at the {room}.') while True: try: command = input('What do you do? > ') except EOFError: break if command == 'help': commands = ['cafeteria', 'engine', 'storage'] if room == 'storage' and not reported: commands += ['report'] commands.remove(room) available = ', '.join(commands) print(f'Available commands: {available}') elif command == 'cafeteria': room = 'cafeteria' elif command == 'engine': room = 'engine' elif command == 'storage': room = 'storage' elif command == 'report': if room == 'storage': print('You reported the body of the red player.') print('(todo: add logic for red player reporting here)') else: print('Nothing to report here.') else: print('Command not recognized. Try "help".') print(f'You are now in the {room}.') if room == 'storage' and not reported: print('The body of the red player is on the floor.') if __name__ == '__main__': main()
I have my number guessing game:
import random number = random.randint(1, 10) guess = int(input('Guess a number between 1 and 10! ')) if guess < number: print('Too low!') elif guess > number: print('Too high!') else: print('Got it!') exit() guess = int(input('Guess again! ')) if guess < number: print('Too low!') elif guess > number: print('Too high!') else: print('Got it!') exit() guess = int(input('One last try! ')) if guess < number: print('Too low!') elif guess > number: print('Too high!') else: print('Got it!') exit() print('The number was ...') print(number)
The nice thing here is that there are no functions, barely variables.
I have my incomplete flappy bird clone (needs sprites from https://github.com/lordmauve/pgzero/tree/stable/examples/flappybird)
import pgzrun import random WIDTH = 400 HEIGHT = 708 GAP = 130 SPEED = 3 FLAP_VELOCITY = -6.5 GRAVITY = 0.3 bird = Actor('bird1', (75, 200)) bird.dead = False bird.vy = 0 bird.x = 75 pipe_top = Actor('top', anchor=('left', 'bottom')) pipe_bottom = Actor('bottom', anchor=('left', 'top')) def reset_pipes(): pipe_gap_y = random.randint(200, HEIGHT - 200) pipe_top.pos = (WIDTH, pipe_gap_y - GAP / 2) pipe_bottom.pos = (WIDTH, pipe_gap_y + GAP / 2) def update_pipes(): pipe_top.left -= SPEED pipe_bottom.left -= SPEED if pipe_top.right < 0: reset_pipes() def update_bird(): bird.vy += GRAVITY bird.y += bird.vy def update(): update_pipes() update_bird() def draw(): screen.blit('background', (0, 0)) pipe_top.draw() pipe_bottom.draw() bird.draw() def on_key_down(): if not bird.dead: bird.vy = FLAP_VELOCITY pgzrun.go()
Pretty good, already interactive, it wants to be coded fully !!
Awesome https://www.youtube.com/watch?v=uyMKWJ5e1kg
Exciting https://www.youtube.com/watch?v=d_hZeheKSVo
Good for me https://www.udemy.com/course/scratch-game-programming/learn/lecture/5338014
Honestly Scratch is probably the most approachable for younger audiences
Now that there's no more https://en.wikipedia.org/wiki/Stagecast_Creator :O
Al Sweigart is giving a lot of stuff away https://inventwithscratch.com/ https://alsweigart.com/ https://inventwithpython.com/pygame/
Also good to consider https://wiki.python.org/moin/BeginnersGuide/NonProgrammers
ok all done