๐ฅ 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)