נבנה על ידיBuilt by Ariel Yohimovich

חזרה למפגשBack
PythonPython

Space Shooter: יורה חללSpace Shooter

מפגש 43: pygame.sprite, Groups, Mask, ירושה, גלים ובוס.Session 43: pygame.sprite, Groups, Mask, inheritance, waves and a boss.

מה נעשה היוםToday's plan

  • SpritesSprites
  • יריShooting
  • פגיעותHits
  • גליםWaves
  • חלקיקיםParticles
  • משחקGame
נושאTopic 1

SpritesSprites

Sprite וקבוצותSprites and groups

  • Sprite = image + rect + updateA Sprite = image + rect + update
  • קבוצה: group.update(), group.draw(screen)A group: group.update(), group.draw(screen)
  • sprite.kill() מוציא מכל הקבוצותsprite.kill() removes it from every group

אנלוגיהAnalogy

קבוצת Sprites היא כמו מנצח על תזמורת: אומר "עכשיו כולם" פעם אחת, וכל נגן מנגן את התפקיד שלו.A sprite group is like a conductor: says "everyone, now" once, and each player plays their own part.
נושאTopic 2

יריShooting

יריות עם המתנהShooting with a cooldown

  • cooldown: ירייה כל N פריימיםA cooldown: a shot every N frames
  • ירייה = Sprite שזז למעלהA bullet = a Sprite moving up
  • kill() כשיצאה מהמסךkill() when it leaves the screen

אנלוגיהAnalogy

cooldown הוא כמו מכונת קפה שצריכה להתחמם בין כוס לכוס: אפשר ללחוץ כמה שרוצים, היא תמזוג רק כשהיא מוכנה.A cooldown is like a coffee machine that has to reheat between cups: press as much as you like, it pours only when ready.
נושאTopic 3

פגיעותHits

פגיעות בין קבוצותHits between groups

  • groupcollide(a, b, kill_a, kill_b)groupcollide(a, b, kill_a, kill_b)
  • מחזיר מילון: מי פגע במיReturns a dict: who hit whom
  • spritecollide לאחד מול קבוצהspritecollide for one against a group

אנלוגיהAnalogy

groupcollide הוא כמו שופט במשחק כדור-מחניים: עובר על כל הזוגות, מכריז מי נפגע, ושולח אותם החוצה.groupcollide is like a dodgeball referee: checks every pair, announces who was hit, and sends them off.
נושאTopic 4

גליםWaves

גלי אויביםEnemy waves

  • גל = מערך של אויביםA wave = a formation of enemies
  • זזים יחד, יורדים בקצהMove together, drop at the edge
  • הגל הבא מהיר יותרThe next wave is faster

אנלוגיהAnalogy

גל אויבים הוא כמו להקת ציפורים: כולן פונות יחד כשהראשונה מגיעה לקצה.An enemy wave is like a flock of birds: they all turn together when the first reaches the edge.
נושאTopic 5

חלקיקיםParticles

חלקיקים ורקע כוכביםParticles and a starfield

  • חלקיק: מיקום, מהירות, זמן חייםA particle: position, velocity, lifetime
  • פיצוץ = 12 חלקיקים בכיוונים אקראייםAn explosion = 12 particles in random directions
  • כוכבים במהירויות שונות = עומקStars at different speeds = depth

אנלוגיהAnalogy

חלקיקים הם כמו זיקוקים: כל ניצוץ טס לבד, דועך, ונעלם, ויחד הם נראים כמו פיצוץ אחד.Particles are like fireworks: each spark flies alone, fades and vanishes, and together they look like one burst.
נושאTopic 6

משחקGame

Space Shooter: המשחקSpace Shooter: the game

  • חללית, יריות ואויבים כ-SpritesShip, bullets and enemies as Sprites
  • groupcollide לפגיעותgroupcollide for hits
  • חלקיקים וכוכביםParticles and stars

אנלוגיהAnalogy

המשחק הזה הוא מה שקורה כשמחלקות, קבוצות ורשימות עובדות יחד: כל עצם יודע מה לעשות, והלולאה רק מתזמרת.This game is what happens when classes, groups and lists work together: each object knows what to do, and the loop just conducts.

Sprite = image + rect + updateA Sprite = image + rect + update

קבוצה: group.update(), group.draw(screen)A group: group.update(), group.draw(screen)

sprite.kill() מוציא מכל הקבוצותsprite.kill() removes it from every group

cooldown: ירייה כל N פריימיםA cooldown: a shot every N frames

ירייה = Sprite שזז למעלהA bullet = a Sprite moving up

kill() כשיצאה מהמסךkill() when it leaves the screen

groupcollide(a, b, kill_a, kill_b)groupcollide(a, b, kill_a, kill_b)

מחזיר מילון: מי פגע במיReturns a dict: who hit whom

spritecollide לאחד מול קבוצהspritecollide for one against a group

גל = מערך של אויביםA wave = a formation of enemies

זזים יחד, יורדים בקצהMove together, drop at the edge

הגל הבא מהיר יותרThe next wave is faster

חלקיק: מיקום, מהירות, זמן חייםA particle: position, velocity, lifetime

פיצוץ = 12 חלקיקים בכיוונים אקראייםAn explosion = 12 particles in random directions

כוכבים במהירויות שונות = עומקStars at different speeds = depth

חללית, יריות ואויבים כ-SpritesShip, bullets and enemies as Sprites

groupcollide לפגיעותgroupcollide for hits

חלקיקים וכוכביםParticles and stars

מה למדנוWhat we learned

  • Sprite = image + rect + updateA Sprite = image + rect + update
  • cooldown: ירייה כל N פריימיםA cooldown: a shot every N frames
  • groupcollide(a, b, kill_a, kill_b)groupcollide(a, b, kill_a, kill_b)
  • גל = מערך של אויביםA wave = a formation of enemies
  • חלקיק: מיקום, מהירות, זמן חייםA particle: position, velocity, lifetime
  • חללית, יריות ואויבים כ-SpritesShip, bullets and enemies as Sprites

עכשיו לתרגולNow, practice

5 תרגילים ו-2 אתגרים, עם בדיקה אוטומטית5 exercises and 2 challenges, auto-checked
הערות מרצהSpeaker notes

נבנה על ידיBuilt by Ariel Yohimovich