DEV Community

cutieyunny-tech
cutieyunny-tech

Posted on

๐Ÿ’ฅ Day 2 of My Pygame Journey

๐Ÿ’ฅ Day 2 of My Pygame Journey: Smashing the Laptop and Learning File Names ๐Ÿ˜‚

Hey dev friends! ๐Ÿ˜†
Today was full of โ€œsmash the laptopโ€ moments while learning Pygame Zero. Hereโ€™s my detailed diary-style lesson learn with emojis ๐Ÿ“๐Ÿ’ป

โธป

๐Ÿ’ฅ Smash Laptop #1: File Names, WHY?!
Computers are super picky:
โ€ข .jpeg โ‰  .jpg โŒ
โ€ข .png โ‰  .jpg โŒ

Tip: File names in your code MUST match the actual file name.
hero = Actor(โ€œnew_char.pngโ€) # if your file is hero.png

Smash Laptop Alert: Wrong file name โ†’ hero disappears ๐Ÿ˜ญ๐Ÿ’ฅ

โธป

๐Ÿ›  Step 1: Create Character (Placeholder First)
hero = Actor(โ€œnew_char.pngโ€) # create first!

Notes:
โ€ข Placeholder = space for hero in memory ๐Ÿงฉ
โ€ข Hero cannot move yet ๐Ÿšซ
โ€ข Drawing before creating โ†’ Smash Laptop #2 ๐Ÿ’ฅ

โธป

๐ŸŽจ Step 2: Background & Resize
1. Find gamer images on Unsplash ๐ŸŽฎ
2. Resize with external editor โœ‚๏ธ
3. Save all images in one game folder ๐Ÿ“

screen.blit(โ€œdiner.jpgโ€, (0,0)) # draw background

Smash Laptop Alert:
โ€ข Background not fitting โ†’ hero disappears / weird layout ๐Ÿ˜ญ๐Ÿ’ฅ

Tip: Background image = game screen size ๐Ÿ–ผ๏ธ

โธป

โšก Step 3: Sequence Draw (Super Important!)
Pygame Zero draws top โ†’ bottom:
screen.clear() # clear screen ๐Ÿงน
screen.blit(โ€œdiner.jpgโ€,(0,0)) # background first ๐Ÿ–ผ๏ธ
hero.draw() # hero on top ๐Ÿฆธโ€โ™‚๏ธ

Smash Laptop #3: Wrong order โ†’ hero gets covered ๐Ÿ˜ญ๐Ÿ’ฅ

โธป

๐Ÿ”ง Step 4: Update Function (Movement Logic)
def update():
if keyboard.left:
hero.x -= 5 โฌ…๏ธ
if keyboard.right:
hero.x += 5 โžก๏ธ
if keyboard.up:
hero.y -= 5 โฌ†๏ธ
if keyboard.down:
hero.y += 5 โฌ‡๏ธ

Must come after creating character. If not โ†’ Smash Laptop #4 ๐Ÿ’ฅ

โธป

๐Ÿ—‚ Step 5: Organize Folder (Save Sanity)
โ€ข Delete duplicate files ๐Ÿ—‘๏ธ
โ€ข Keep all images in one folder โ†’ NadhirahGame ๐Ÿ–ฅ๏ธ
โ€ข File names = consistent โœ”๏ธ

Smash Laptop #5 avoided! ๐ŸŽ‰

โธป

๐Ÿ’ก Step 6: Wireframe โ†’ Action โ†’ Draw
Nadhirah Analogy:
1. Placeholder โ†’ wireframe โ†’ hero = Actor(โ€ฆ) ๐Ÿงฉ
2. Update โ†’ script/action โ†’ def update(): โ€ฆ ๐ŸŽฌ
3. Draw โ†’ visual โ†’ def draw(): โ€ฆ ๐Ÿ–Œ๏ธ

Create โ†’ Action โ†’ Display = life of your hero ๐Ÿฆธโ€โ™‚๏ธ
Wrong order = Smash Laptop #6 ๐Ÿ’ฅ

โธป

๐Ÿ”ฅ Step 7: Final Checklist
โ€ข File names match code ๐Ÿ“›
โ€ข Background resized & fit screen ๐Ÿ–ผ๏ธ
โ€ข Draw sequence correct: background โ†’ hero ๐ŸŽจ
โ€ข Update function after create character ๐Ÿƒโ€โ™‚๏ธ
โ€ข All images in one folder ๐Ÿ“‚

Smash Laptop Risk = Zero โœ…

โธป

Have you ever smashed your laptop because of a file name mismatch? ๐Ÿ˜†๐Ÿ’ฅ
Share your story in the comments! ๐Ÿ‘‡

Top comments (0)