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

חזרה למפגשBack
PythonPython

Neon PongNeon Pong

מפגש 39: Vector2, פיזיקת כדור, יריב מחשב, טיימרים וצלילים מסונתזים.Session 39: Vector2, ball physics, a computer opponent, timers and synthesized sound.

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

  • מגרשCourt
  • כדורBall
  • זוויתAngle
  • יריבOpponent
  • dtdt
  • משחקGame
נושאTopic 1

מגרשCourt

המגרש והמחבטיםThe court and paddles

  • שני מחבטים כ-RectTwo paddles as Rects
  • קו אמצע מקווקו בלולאהA dashed centre line in a loop
  • W, H כקבועים בראש הקובץW, H as constants at the top

אנלוגיהAnalogy

קבועים כמו W ו-H הם כמו מידות המגרש בספר החוקים: כל השחקנים נמדדים לפיהם, ואם מגדילים את המגרש, הכול מתעדכן.Constants like W and H are like the court dimensions in the rule book: every player is measured against them, and if you enlarge the court, everything follows.
נושאTopic 2

כדורBall

כדור במהירות עשרוניתA ball with float speed

  • מיקום עשרוני bx, by לתנועה חלקהA float position bx, by for smooth motion
  • ה-Rect מקבל round לציורThe Rect gets round for drawing
  • קיר עליון/תחתון: vy = -vyTop/bottom wall: vy = -vy

אנלוגיהAnalogy

מיקום עשרוני הוא כמו מד מרחק ברכב שסופר מטרים, בזמן שהשלט בצד הדרך מראה רק קילומטרים שלמים.A float position is like a car's odometer counting metres, while the roadside sign shows only whole kilometres.
נושאTopic 3

זוויתAngle

זווית לפי נקודת הפגיעהAngle by hit point

  • פגיעה במרכז = ישר, בקצה = חדA centre hit = straight, an edge hit = sharp
  • offset בין -1 ל-1offset from -1 to 1
  • מאיצים מעט בכל החזרהSpeed up slightly on each return

אנלוגיהAnalogy

זה כמו לחבוט בכדור טניס: פגיעה במרכז המחבט מחזירה ישר, ופגיעה בקצה שולחת אותו הצידה.It's like hitting a tennis ball: a centre hit returns it straight, an edge hit sends it sideways.
נושאTopic 4

יריבOpponent

יריב ממוחשבAn AI opponent

  • עוקב אחרי הכדורFollows the ball
  • מהירות מוגבלת = אפשר לנצחLimited speed = beatable
  • "אזור מת" קטן מונע רטטA small "dead zone" prevents jitter

אנלוגיהAnalogy

יריב ממוחשב טוב הוא כמו מאמן טניס שמשחק עם ילד: הוא יכול להחזיר כל כדור, אבל משאיר מקום לנצח.A good AI opponent is like a tennis coach playing with a kid: could return every ball, but leaves room to win.
נושאTopic 5

dtdt

זמן פריים ושקיפותDelta time and transparency

  • dt = שניות מאז הפריים הקודםdt = seconds since the last frame
  • מהירות בפיקסלים לשנייה × dtSpeed in pixels per second × dt
  • שקיפות עם SRCALPHATransparency with SRCALPHA

אנלוגיהAnalogy

dt הוא כמו לחשב מהירות של מכונית בקמ"ש ולא ב"קפיצות": לא משנה כמה פעמים בודקים את המד, המרחק לשעה זהה.dt is like measuring a car's speed in km/h rather than "jumps": however often you check the meter, the distance per hour is the same.
נושאTopic 6

משחקGame

Neon Pong: המשחקNeon Pong: the game

  • שני יריבים ממוחשבים (כאן)Two AI players (here)
  • ניקוד והגשה מחדשScoring and re-serving
  • זוהר ניאון בשכבה שקופהNeon glow on a transparent layer

אנלוגיהAnalogy

שכבת הזוהר היא כמו נייר פרגמנט מעל ציור: הצבעים מאחור עוברים דרכו, רכים יותר.The glow layer is like tracing paper over a drawing: the colours behind show through, softened.

שני מחבטים כ-RectTwo paddles as Rects

קו אמצע מקווקו בלולאהA dashed centre line in a loop

W, H כקבועים בראש הקובץW, H as constants at the top

מיקום עשרוני bx, by לתנועה חלקהA float position bx, by for smooth motion

ה-Rect מקבל round לציורThe Rect gets round for drawing

קיר עליון/תחתון: vy = -vyTop/bottom wall: vy = -vy

פגיעה במרכז = ישר, בקצה = חדA centre hit = straight, an edge hit = sharp

offset בין -1 ל-1offset from -1 to 1

מאיצים מעט בכל החזרהSpeed up slightly on each return

עוקב אחרי הכדורFollows the ball

מהירות מוגבלת = אפשר לנצחLimited speed = beatable

"אזור מת" קטן מונע רטטA small "dead zone" prevents jitter

dt = שניות מאז הפריים הקודםdt = seconds since the last frame

מהירות בפיקסלים לשנייה × dtSpeed in pixels per second × dt

שקיפות עם SRCALPHATransparency with SRCALPHA

שני יריבים ממוחשבים (כאן)Two AI players (here)

ניקוד והגשה מחדשScoring and re-serving

זוהר ניאון בשכבה שקופהNeon glow on a transparent layer

מה למדנוWhat we learned

  • שני מחבטים כ-RectTwo paddles as Rects
  • מיקום עשרוני bx, by לתנועה חלקהA float position bx, by for smooth motion
  • פגיעה במרכז = ישר, בקצה = חדA centre hit = straight, an edge hit = sharp
  • עוקב אחרי הכדורFollows the ball
  • dt = שניות מאז הפריים הקודםdt = seconds since the last frame
  • שני יריבים ממוחשבים (כאן)Two AI players (here)

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

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

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