use pgzero to run code wasd to move go to notes and credits for code.
import os import pgzrun # Keep our ultimate folder fix working! downloads_path = os.path.expanduser(r"~\Downloads\platformer") os.chdir(downloads_path) # 1. CREATE THE WINDOW # This sets the size of your game screen and the title at the top WIDTH = 480 HEIGHT = 360 TITLE = "Platformer" # 2. CREATE A SPRITE (Actor) # This looks for 'triangle.png' inside your game2/images folder player = Actor('player') player.pos = (240, 180) # Starts right in the middle of the screen land = Actor('land (1)') land.x = 240 # Dead center from left to right (480 / 2) land.bottom = 360 # Aligns the absolute bottom of the sprite with the bottom of the window y_vel = 0 # 3. THE FOREVER LOOP (Draw & Update) # Pygame Zero runs these two functions over and over automatically! def draw(): # This clears the screen every frame so things don't leave trails screen.fill((40, 20, 60)) # A cool dark purple background land.draw() player.draw() def update(): global y_vel # 1. Left and Right Movement if keyboard.d: player.x += 8 if keyboard.a: player.x -= 8 # 2. Apply Gravity y_vel += 1 if y_vel > 10: y_vel = 10 player.y += y_vel # 3. Hardcoded Floor Collision (No land actor needed!) # Since HEIGHT is 360, let's make the floor at Y = 320 if player.colliderect(land): while player.colliderect(land): player.y -= 1 y_vel = 0 # 4. Jumping if keyboard.w: y_vel = -15 # Launch up into the air # Start the game! pgzrun.go()