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

חזרה למפגשBack
PythonPython

Crystal Quest, חלק 2 ופרסוםCrystal Quest, part 2 & publishing

מפגש 48: חפצים, אויבים עם AI, קרבות, בוס, שמירה ב-JSON ופרסום לדפדפן עם pygbag.Session 48: Items, enemies with AI, combat, a boss, saving to JSON and publishing to the browser with pygbag.

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

  • בינהAI
  • שמירהSave
  • חלקיקיםParticles
  • נכסיםAssets
  • פרסוםPublish
  • משחקGame
נושאTopic 1

בינהAI

אויבים עם מצביםEnemies with states

  • מצבים: patrol, chase, returnStates: patrol, chase, return
  • מעבר לפי מרחק לשחקןSwitch by distance to the player
  • טווח יציאה גדול מטווח כניסהExit range larger than entry range

אנלוגיהAnalogy

זה כמו כלב שמירה: מסתובב בחצר, נובח ורץ כשמישהו מתקרב לגדר, וכשהאורח הלך רחוק הוא חוזר למלונה.It's like a guard dog: wanders the yard, barks and runs when someone nears the fence, and when the visitor is far away it goes back to its kennel.
נושאTopic 2

שמירהSave

שמירה וטעינהSaving and loading

  • מצב המשחק → מילון → JSONGame state → dict → JSON
  • כותבים לקובץ זמני ואז מחליפיםWrite to a temp file, then replace
  • קובץ חסר או פגום = משחק חדשMissing or broken file = a new game

אנלוגיהAnalogy

שמירה דרך קובץ זמני היא כמו להעתיק מחברת לדף חדש ורק בסוף לזרוק את הישן: אם משהו קורה באמצע, הישן עדיין שלם.Saving via a temp file is like copying a notebook onto a fresh page and only then throwing out the old one: if something happens midway, the old one is still whole.

טעות נפוצהCommon mistake

save.py
import json
state = {"bag": {"crystal", "key"}}
json.dumps(state)
מה Python עונהWhat Python says
TypeError: Object of type set is not JSON serializable
TypeError: Object of type set is not JSON serializable: JSON מכיר רשימות ומילונים, לא set או Vector2. ממירים: sorted(bag) או [v.x, v.y].TypeError: Object of type set is not JSON serializable: JSON knows lists and dicts, not set or Vector2. Convert: sorted(bag) or [v.x, v.y].
נושאTopic 3

חלקיקיםParticles

חלקיקיםParticles

  • חלקיק = מיקום, מהירות, חייםA particle = position, velocity, life
  • חיכוך: vel *= 0.95Friction: vel *= 0.95
  • מוחקים כשהחיים נגמריםDelete when life runs out

אנלוגיהAnalogy

חלקיקים הם כמו זיקוקים: כל ניצוץ פשוט לגמרי, נע ודועך, אבל מאות ביחד יוצרים רגע של חגיגה.Particles are like fireworks: each spark is utterly simple, moving and fading, but hundreds together make a moment of celebration.
נושאTopic 4

נכסיםAssets

קבצי משחק ונתיביםGame files and paths

  • נתיב יחסי לקובץ הקוד: Path(__file__).parentPaths relative to the code file: Path(__file__).parent
  • תיקיית assets מסודרתA tidy assets folder
  • קובץ חסר? תחליף זמני ולא קריסהMissing file? A placeholder, not a crash

אנלוגיהAnalogy

נתיב יחסי לתיקיית ההרצה הוא כמו להגיד "המפתח במגירה השנייה" בלי להגיד באיזה בית. __file__ הוא הכתובת המלאה.A path relative to where you ran from is like saying "the key is in the second drawer" without saying which house. __file__ is the full address.
נושאTopic 5

פרסוםPublish

פרסום המשחקPublishing the game

  • pygbag: לולאה async עם await asyncio.sleep(0)pygbag: an async loop with await asyncio.sleep(0)
  • pygbag . → אתר, למשל ל-itch.iopygbag . → a website, for example for itch.io
  • PyInstaller → קובץ הרצהPyInstaller → an executable

אנלוגיהAnalogy

פרסום הוא כמו להעביר מתכון לחבר: אצלכם הכול במקום, אבל צריך לכתוב בדיוק איזה מצרכים לקנות ואיפה הם, אחרת אצלו זה לא יעבוד.Publishing is like handing a recipe to a friend: in your kitchen everything's in place, but you must write exactly which ingredients to buy and where they are, or it won't work for them.
נושאTopic 6

משחקGame

Crystal Quest: הגרסה המלאהCrystal Quest: the full version

  • רוחות עם מצביםGhosts with states
  • קריסטלים עם פיצוץ חלקיקיםCrystals with a particle burst
  • חיים, הבהוב פגיעה ושורת מצבHealth, a hurt flash and a status line

אנלוגיהAnalogy

משחק גמור הוא לא רעיון גדול אחד אלא מאה רעיונות קטנים שעובדים יחד. כל מה שבניתם בחלק הזה הוא אחד מהם.A finished game isn't one big idea but a hundred small ones working together. Everything you built in this part is one of them.

מצבים: patrol, chase, returnStates: patrol, chase, return

מעבר לפי מרחק לשחקןSwitch by distance to the player

טווח יציאה גדול מטווח כניסהExit range larger than entry range

מצב המשחק → מילון → JSONGame state → dict → JSON

כותבים לקובץ זמני ואז מחליפיםWrite to a temp file, then replace

קובץ חסר או פגום = משחק חדשMissing or broken file = a new game

חלקיק = מיקום, מהירות, חייםA particle = position, velocity, life

חיכוך: vel *= 0.95Friction: vel *= 0.95

מוחקים כשהחיים נגמריםDelete when life runs out

נתיב יחסי לקובץ הקוד: Path(__file__).parentPaths relative to the code file: Path(__file__).parent

תיקיית assets מסודרתA tidy assets folder

קובץ חסר? תחליף זמני ולא קריסהMissing file? A placeholder, not a crash

pygbag: לולאה async עם await asyncio.sleep(0)pygbag: an async loop with await asyncio.sleep(0)

pygbag . → אתר, למשל ל-itch.iopygbag . → a website, for example for itch.io

PyInstaller → קובץ הרצהPyInstaller → an executable

רוחות עם מצביםGhosts with states

קריסטלים עם פיצוץ חלקיקיםCrystals with a particle burst

מה למדנוWhat we learned

  • מצבים: patrol, chase, returnStates: patrol, chase, return
  • מצב המשחק → מילון → JSONGame state → dict → JSON
  • חלקיק = מיקום, מהירות, חייםA particle = position, velocity, life
  • נתיב יחסי לקובץ הקוד: Path(__file__).parentPaths relative to the code file: Path(__file__).parent
  • pygbag: לולאה async עם await asyncio.sleep(0)pygbag: an async loop with await asyncio.sleep(0)
  • רוחות עם מצביםGhosts with states

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

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

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