Sprite sheet, אנימציית פריימים, Parallax ו-dt. בסוף המפגש מוסיפים צעד לפרויקט המלווה.Sprite sheets, frame animation, parallax and dt. At the end we add a step to the companion project.
מה נעשה היוםToday's plan
כבידהGravity
צינורותPipes
ניקודScore
סיבובRotation
פרלקסהParallax
משחקGame
עוברים על סדר היום ומזכירים את הפרויקט המלווה.Walk through the plan and mention the companion project.
נושאTopic 1
כבידהGravity
כבידה וקפיצהGravity and jumping
כבידה: vel += GRAVITY בכל פרייםGravity: vel += GRAVITY every frame
דחיפה: vel = FLAP בלחיצהImpulse: vel = FLAP on a press
y += vel הופך מהירות לתנועהy += vel turns velocity into motion
עד עכשיו המהירות הייתה קבועה. ב-Flappy המהירות האנכית משתנה: כבידה מוסיפה קבוע קטן בכל פריים, כך שהציפור נופלת מהר יותר ויותר. לחיצה נותנת דחיפה: קובעים את המהירות לערך שלילי (למעלה). התוצאה היא קשת טבעית. הגרף מראה את הגובה לאורך הזמן עם שלוש לחיצות:So far speed was constant. In Flappy the vertical velocity changes: gravity adds a small constant every frame, so the bird falls faster and faster. A press gives an impulse: set the velocity to a negative value (upward). The result is a natural arc. The chart shows the height over time with three presses:
אנלוגיהAnalogy
כבידה היא כמו מדרון בלתי נראה: כל רגע המהירות כלפי מטה גדלה קצת. קפיצה היא בעיטה כלפי מעלה, והמדרון מיד מתחיל להאט אותה.Gravity is like an invisible slope: every moment the downward speed grows a little. A jump is a kick upward, and the slope immediately starts slowing it.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
נושאTopic 2
צינורותPipes
צינורותPipes
צינור = x ומרכז רווחA pipe = x and a gap centre
מלבן עליון ומלבן תחתון מחושביםTop and bottom rects are computed
גלילה: הצינורות זזים, הציפור לאScrolling: pipes move, the bird doesn't
כל צינור הוא בעצם שני מלבנים עם רווח ביניהם. מספיק לשמור את המיקום האופקי ואת מרכז הרווח, ולחשב את שני המלבנים בזמן הציור. זו גלילה: הציפור נשארת באותו x, והעולם זז שמאלה. מרכז הרווח אקראי, אבל בגבולות שמשאירים אותו בתוך המסך:Every pipe is really two rectangles with a gap between them. It's enough to store the horizontal position and the gap's centre, and compute both rectangles when drawing. That's scrolling: the bird stays at the same x, and the world moves left. The gap centre is random, but within bounds that keep it on screen:
אנלוגיהAnalogy
צינורות הם כמו שערים במסלול סקי: לא מזיזים את הגולש, מזיזים את ההר מתחתיו.Pipes are like gates on a ski slope: you don't move the skier, you move the mountain under them.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
נושאTopic 3
ניקודScore
ניקוד והתנגשותScoring and collision
נקודה כשהצינור עובר את הציפורA point when the pipe passes the bird
דגל scored = פעם אחת בלבדA scored flag = only once
נקודה מקבלים כשצינור עבר את הציפור. אבל הבדיקה "הצינור משמאל לציפור" נכונה בכל פריים מאותו רגע, ולכן שומרים דגל scored שמונע לספור שוב. להתנגשות משתמשים בתיבת פגיעה קטנה מעט מהציור: נגיעה של פיקסל בכנף לא תסיים את המשחק, וזה מרגיש הוגן:You get a point when a pipe has passed the bird. But the check "the pipe is left of the bird" is true every frame from that moment on, so keep a scored flag to prevent counting again. For collisions use a hitbox slightly smaller than the drawing: a one-pixel wing touch won't end the game, and that feels fair:
אנלוגיהAnalogy
הדגל scored הוא כמו חותמת על כרטיס: אחרי שהחתימו, אותו כרטיס לא נותן כניסה שנייה.The scored flag is like a stamp on a ticket: once stamped, the same ticket doesn't get you in twice.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
זווית לפי המהירות, ממרכזים מחדשAngle from the velocity, re-centre
ציפור שמסתובבת לפי הכיוון נראית חיה: עולה = אף למעלה, נופלת = אף למטה. מציירים אותה פעם אחת על Surface שקוף, ובכל פריים מסובבים עם transform.rotate בזווית שתלויה במהירות. סיבוב משנה את גודל התמונה, ולכן ממקמים לפי המרכז (get_rect(center=...)), לא לפי הפינה:A bird that tilts with its direction looks alive: rising = beak up, falling = beak down. Draw it once on a transparent Surface, and each frame rotate with transform.rotate at an angle depending on the velocity. Rotation changes the image size, so position by the centre (get_rect(center=...)), not the corner:
אנלוגיהAnalogy
סיבוב הוא כמו להטות תמונה ממוסגרת על הקיר: המסגרת שצריך כדי להכיל אותה גדלה, אז תולים לפי המרכז.Rotation is like tilting a framed picture on the wall: the box needed to contain it gets bigger, so you hang it by the centre.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
גבעות במהירות 30% מהצינורותHills at 30% of the pipes' speed
% לגלילה אינסופית% for endless scrolling
כשאתם נוסעים ברכבת, העמודים ליד המסילה רצים והרים רחוקים כמעט עומדים. זו פרלקסה, והיא נותנת עומק למשחק דו-ממדי. כל שכבה זזה במהירות אחרת, ו-% גורם לה לחזור מהצד השני, כך שהרקע אינסופי:On a train, the poles by the track race past while distant mountains barely move. That's parallax, and it gives a 2D game depth. Each layer moves at a different speed, and % brings it back from the other side, so the background never ends:
אנלוגיהAnalogy
פרלקסה היא כמו לנסוע ולראות שהירח "נוסע" איתכם: כל מה שרחוק יותר זז פחות, והמוח מבין עומק.Parallax is like driving and seeing the moon "follow" you: the farther something is, the less it moves, and the brain reads depth.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
נושאTopic 6
משחקGame
Flappy: המשחקFlappy: the game
כבידה, דחיפה וצינורותGravity, flaps and pipes
ניקוד בצינור שעברA point per passed pipe
ציפור מסתובבת וגבעות ברקעA tilting bird and hills behind
המשחק כולו: ציפור עם כבידה ודחיפות, צינורות עם רווח אקראי כל 90 פריימים, ניקוד עם דגל, ציפור שמסתובבת לפי המהירות, וגבעות שזזות לאט מאחור. כאן "שחקן אוטומטי" דוחף כשהציפור מתחת לרווח הבא; במחשב שלכם רווח או לחיצת עכבר:The whole game: a bird with gravity and flaps, pipes with a random gap every 90 frames, scoring with a flag, a bird tilting with its velocity, and hills drifting slowly behind. Here an "auto-player" flaps when the bird is below the next gap; on your computer, space or a mouse click:
אנלוגיהAnalogy
Flappy מראה שמשחק ממכר לא צריך להיות מסובך: כבידה, לחיצה אחת, ומכשולים. השאר הוא כוונון של מספרים.Flappy shows an addictive game needn't be complicated: gravity, one button, obstacles. The rest is tuning numbers.
שואלים אם מישהו מכיר דוגמה נוספת מהחיים.Ask for another real-life example.
כבידה: vel += GRAVITY בכל פרייםGravity: vel += GRAVITY every frame
כבידה וקפיצהGravity and jumping
דחיפה: vel = FLAP בלחיצהImpulse: vel = FLAP on a press
כבידה וקפיצהGravity and jumping
y += vel הופך מהירות לתנועהy += vel turns velocity into motion
כבידה וקפיצהGravity and jumping
צינור = x ומרכז רווחA pipe = x and a gap centre
צינורותPipes
מלבן עליון ומלבן תחתון מחושביםTop and bottom rects are computed
צינורותPipes
גלילה: הצינורות זזים, הציפור לאScrolling: pipes move, the bird doesn't
צינורותPipes
נקודה כשהצינור עובר את הציפורA point when the pipe passes the bird
ניקוד והתנגשותScoring and collision
דגל scored = פעם אחת בלבדA scored flag = only once