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

חזרה למפגשBack
PythonPython

Tower Defense: הגנת מגדליםTower Defense

מפגש 46: מסלול עם BFS, גלים, בחירת מטרה, כלכלה וממשק כפתורים.Session 46: Pathing with BFS, waves, targeting, an economy and a button UI.

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

  • מסלולPath
  • טווחRange
  • קצבRate
  • קליעיםBullets
  • גליםWaves
  • משחקGame
נושאTopic 1

מסלולPath

מסלול נקודות ציוןA waypoint path

  • מסלול = רשימת נקודות ציוןA path = a list of waypoints
  • צעד לעבר הנקודה הבאה בכיוון מנורמלStep toward the next point in a normalised direction
  • מגיעים? מתקדמים לנקודה הבאהArrived? Move to the next point

אנלוגיהAnalogy

נקודות ציון הן כמו שלטים בשביל טיול: לא צריך לדעת את כל הדרך, רק לאן השלט הבא מצביע.Waypoints are like trail markers: you don't need the whole route, just where the next marker points.
נושאTopic 2

טווחRange

טווח ובחירת מטרהRange and targeting

  • בטווח = math.dist(...) <= rangeIn range = math.dist(...) <= range
  • בחירה: הראשון במסלולChoosing: the first on the path
  • max(..., key=...)max(..., key=...)

אנלוגיהAnalogy

זה כמו שוער שבוחר באיזה כדור לטפל: לא בכל מה שבמגרש, רק במה שקרוב לשער, ובדרך כלל במה שהכי קרוב להבקיע.It's like a goalkeeper choosing which ball to handle: not everything on the pitch, just what's near the goal, usually whatever's closest to scoring.
נושאTopic 3

קצבRate

קצב אשFire rate

  • זמן טעינה יורד בכל פרייםA cooldown counts down each frame
  • יורים רק ב-0, ומאפסיםFire only at 0, then reset
  • קצב = 60 / cooldown יריות בשנייהRate = 60 / cooldown shots a second

אנלוגיהAnalogy

זמן טעינה הוא כמו מכונת קפה: לוחצים, מקבלים כוס, ועד שהיא מוכנה שוב שום לחיצה לא תעזור.A cooldown is like a coffee machine: press, get a cup, and until it's ready again no press will help.
נושאTopic 4

קליעיםBullets

קליעים מונחיםHoming projectiles

  • קליע מונחה מכוון מחדש בכל פרייםA homing bullet re-aims every frame
  • פגיעה = מרחק קטן מסףA hit = distance below a threshold
  • המטרה מתה בדרך? הקליע נעלםTarget died on the way? The bullet vanishes

אנלוגיהAnalogy

קליע מונחה הוא כמו כלב שרודף אחרי כדור מתגלגל: הוא לא מחשב מראש, רק מסתכל שוב ושוב איפה הכדור עכשיו.A homing bullet is like a dog chasing a rolling ball: no planning ahead, just looking again and again at where the ball is now.

טעות נפוצהCommon mistake

homing.py
enemies = ["slime"]
hits = ["slime", "slime"]
for target in hits:
    enemies.remove(target)
מה Python עונהWhat Python says
ValueError: list.remove(x): x not in list
ValueError: list.remove(x): x not in list: שני קליעים פגעו באותו אויב באותו פריים. בודקים if target in enemies: לפני remove.ValueError: list.remove(x): x not in list: two bullets hit the same enemy in one frame. Check if target in enemies: before remove.
נושאTopic 5

גליםWaves

גלים וכלכלהWaves and economy

  • גל = כמה אויבים, מרווח, עוצמהA wave = how many, the gap, the strength
  • כל גל קשה יותרEach wave is harder
  • זהב על הריגה, מגדל עולה זהבGold per kill, a tower costs gold

אנלוגיהAnalogy

גלים הם כמו שיעורי כושר: מתחילים קל, מוסיפים משקל בהדרגה, ונותנים מנוחה קצרה בין סטים.Waves are like a workout: start light, add weight gradually, and rest briefly between sets.
נושאTopic 6

משחקGame

Tower Defense: המשחקTower Defense: the game

  • אויבים במסלול, מגדלים בצדדיםEnemies on the path, towers beside it
  • ירי מונחה, פסי חייםHoming shots, health bars
  • חיים, זהב והריגותLives, gold and kills

אנלוגיהAnalogy

Tower Defense הוא כמו לתכנן מחסומים בכביש: אתם לא שולטים במכוניות, רק בוחרים איפה להציב את השוטרים.Tower Defense is like planning checkpoints on a road: you don't control the cars, you only choose where to station the officers.

מסלול = רשימת נקודות ציוןA path = a list of waypoints

צעד לעבר הנקודה הבאה בכיוון מנורמלStep toward the next point in a normalised direction

מגיעים? מתקדמים לנקודה הבאהArrived? Move to the next point

בטווח = math.dist(...) <= rangeIn range = math.dist(...) <= range

בחירה: הראשון במסלולChoosing: the first on the path

max(..., key=...)max(..., key=...)

זמן טעינה יורד בכל פרייםA cooldown counts down each frame

יורים רק ב-0, ומאפסיםFire only at 0, then reset

קצב = 60 / cooldown יריות בשנייהRate = 60 / cooldown shots a second

קליע מונחה מכוון מחדש בכל פרייםA homing bullet re-aims every frame

פגיעה = מרחק קטן מסףA hit = distance below a threshold

המטרה מתה בדרך? הקליע נעלםTarget died on the way? The bullet vanishes

גל = כמה אויבים, מרווח, עוצמהA wave = how many, the gap, the strength

כל גל קשה יותרEach wave is harder

זהב על הריגה, מגדל עולה זהבGold per kill, a tower costs gold

אויבים במסלול, מגדלים בצדדיםEnemies on the path, towers beside it

ירי מונחה, פסי חייםHoming shots, health bars

מה למדנוWhat we learned

  • מסלול = רשימת נקודות ציוןA path = a list of waypoints
  • בטווח = math.dist(...) <= rangeIn range = math.dist(...) <= range
  • זמן טעינה יורד בכל פרייםA cooldown counts down each frame
  • קליע מונחה מכוון מחדש בכל פרייםA homing bullet re-aims every frame
  • גל = כמה אויבים, מרווח, עוצמהA wave = how many, the gap, the strength
  • אויבים במסלול, מגדלים בצדדיםEnemies on the path, towers beside it

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

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

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