Vector2, פיזיקת כדור, יריב מחשב, טיימרים וצלילים מסונתזים. בסוף המפגש מוסיפים צעד לפרויקט המלווה.Vector2, ball physics, a computer opponent, timers and synthesized sound. At the end we add a step to the companion project.
מה נעשה היוםToday's plan
מגרשCourt
כדורBall
זוויתAngle
יריבOpponent
dtdt
משחקGame
עוברים על סדר היום ומזכירים את הפרויקט המלווה.Walk through the plan and mention the companion project.
קו אמצע מקווקו בלולאהA dashed centre line in a loop
W, H כקבועים בראש הקובץW, H as constants at the top
Pong הוא אחד המשחקים הראשונים בהיסטוריה, ועדיין אחד הטובים ללמוד ממנו. מתחילים מהמגרש: שני מחבטים כמלבנים בצדדים, כדור קטן במרכז, וקו אמצע מקווקו שמצויר בלולאה. גודל החלון נשמר בקבועים W, H כדי שכל החישובים יתבססו עליהם:Pong is one of the first video games ever, and still one of the best to learn from. Start with the court: two paddles as rectangles at the sides, a small ball in the middle, and a dashed centre line drawn in a loop. The window size lives in constants W, H so every calculation is based on them:
אנלוגיה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.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
נושא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
Rect שומר רק מספרים שלמים. אם מוסיפים לו 2.5 בכל פריים, החלק העשרוני הולך לאיבוד והתנועה "נתקעת". הפתרון: שומרים מיקום עשרוני נפרד (bx, by), ומעתיקים ל-Rect אחרי עיגול. כך גם מהירות כמו 2.5 עובדת:A Rect stores only whole numbers. Add 2.5 to it every frame and the fraction is lost, so motion "sticks". The fix: keep a separate float position (bx, by), and copy into the Rect after rounding. That way even a speed like 2.5 works:
אנלוגיהAnalogy
מיקום עשרוני הוא כמו מד מרחק ברכב שסופר מטרים, בזמן שהשלט בצד הדרך מראה רק קילומטרים שלמים.A float position is like a car's odometer counting metres, while the roadside sign shows only whole kilometres.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
נושא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
אם הכדור תמיד חוזר באותה זווית, המשחק משעמם. הטריק של Pong: מחשבים איפה הכדור פגע במחבט, כמספר בין -1 (קצה עליון) ל-1 (קצה תחתון), וקובעים לפיו את vy. כך לשחקן יש שליטה, ופגיעה בקצה שולחת את הכדור בזווית חדה. מאיצים גם מעט (×1.05) בכל החזרה:If the ball always returns at the same rebound angle, the game is dull. Pong's trick: compute where the ball hit the paddle, as a number from -1 (top edge) to 1 (bottom edge), and set vy from it. That gives the player control, and an edge hit sends the ball off sharply. Also speed up a little (×1.05) on each return:
אנלוגיהAnalogy
זה כמו לחבוט בכדור טניס: פגיעה במרכז המחבט מחזירה ישר, ופגיעה בקצה שולחת אותו הצידה.It's like hitting a tennis ball: a centre hit returns it straight, an edge hit sends it sideways.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
נושאTopic 4
יריבOpponent
יריב ממוחשבAn AI opponent
עוקב אחרי הכדורFollows the ball
מהירות מוגבלת = אפשר לנצחLimited speed = beatable
"אזור מת" קטן מונע רטטA small "dead zone" prevents jitter
יריב ממוחשב פשוט: אם מרכז המחבט מעל הכדור, יורדים; אם מתחתיו, עולים. שני כוונונים הופכים אותו להוגן: מהירות מקסימלית קטנה מזו של הכדור (אחרת הוא בלתי מנוצח), ו"אזור מת" של כמה פיקסלים שבו לא זזים, כדי שהמחבט לא ירעד למעלה ולמטה:A simple AI opponent: if the paddle's centre is above the ball, move down; if below, move up. Two tweaks make it fair: a top speed lower than the ball's (otherwise it's unbeatable), and a "dead zone" of a few pixels where it doesn't move, so the paddle doesn't jitter up and down:
אנלוגיהAnalogy
יריב ממוחשב טוב הוא כמו מאמן טניס שמשחק עם ילד: הוא יכול להחזיר כל כדור, אבל משאיר מקום לנצח.A good AI opponent is like a tennis coach playing with a kid: could return every ball, but leaves room to win.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
נושאTopic 5
dtdt
זמן פריים ושקיפותDelta time and transparency
dt = שניות מאז הפריים הקודםdt = seconds since the last frame
מהירות בפיקסלים לשנייה × dtSpeed in pixels per second × dt
אם המהירות היא "5 פיקסלים לפריים", במחשב איטי (30 FPS) המשחק איטי פי שניים. פתרון: זמן פריים. dt = clock.tick(60) / 1000 נותן שניות, והמהירות היא בפיקסלים לשנייה: x += speed * dt. ולאפקט הניאון: מציירים צורות חצי-שקופות על Surface עם SRCALPHA, גדולות מעט מהמקור, ומניחים מעל:If the speed is "5 pixels per frame", on a slow computer (30 FPS) the game runs half as fast. Fix: delta time (dt). dt = clock.tick(60) / 1000 gives seconds, and speed is in pixels per second: x += speed * dt. For the neon effect: draw half-transparent shapes on a Surface with SRCALPHA, slightly larger than the original, and layer it on top:
אנלוגיה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.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
נושאTopic 6
משחקGame
Neon Pong: המשחקNeon Pong: the game
שני יריבים ממוחשבים (כאן)Two AI players (here)
ניקוד והגשה מחדשScoring and re-serving
זוהר ניאון בשכבה שקופהNeon glow on a transparent layer
כל החלקים יחד: מחבטים, כדור עם מיקום עשרוני, זווית לפי פגיעה, יריבים ממוחשבים (כאן שניהם ממוחשבים, השמאלי מהיר מעט), ניקוד, הגשה מחדש למי שספג, וזוהר ניאון. במחשב שלכם החליפו את המחבט השמאלי במקשי W/S:All the pieces together: paddles, a float-position ball, angle by hit point, AI players (here both are AI, the left one a bit faster), scoring, re-serving toward whoever conceded, and a neon glow. On your computer swap the left paddle for the W/S keys:
אנלוגיהAnalogy
שכבת הזוהר היא כמו נייר פרגמנט מעל ציור: הצבעים מאחור עוברים דרכו, רכים יותר.The glow layer is like tracing paper over a drawing: the colours behind show through, softened.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.