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

חזרה למפגשBack
PythonPython

Flappy: ציפור מעופפתFlappy

מפגש 42: Sprite sheet, אנימציית פריימים, Parallax ו-dt.Session 42: Sprite sheets, frame animation, parallax and dt.

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

  • כבידהGravity
  • צינורותPipes
  • ניקודScore
  • סיבובRotation
  • פרלקסהParallax
  • משחקGame
נושא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

אנלוגיה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.
נושא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

אנלוגיהAnalogy

צינורות הם כמו שערים במסלול סקי: לא מזיזים את הגולש, מזיזים את ההר מתחתיו.Pipes are like gates on a ski slope: you don't move the skier, you move the mountain under them.
נושאTopic 3

ניקודScore

ניקוד והתנגשותScoring and collision

  • נקודה כשהצינור עובר את הציפורA point when the pipe passes the bird
  • דגל scored = פעם אחת בלבדA scored flag = only once
  • תיבת פגיעה קטנה מהציורA hitbox smaller than the drawing

אנלוגיהAnalogy

הדגל scored הוא כמו חותמת על כרטיס: אחרי שהחתימו, אותו כרטיס לא נותן כניסה שנייה.The scored flag is like a stamp on a ticket: once stamped, the same ticket doesn't get you in twice.
נושאTopic 4

סיבובRotation

סיבוב הציפורRotating the bird

  • ציור על Surface שקוףDraw on a transparent Surface
  • pygame.transform.rotate(surf, angle)pygame.transform.rotate(surf, angle)
  • זווית לפי המהירות, ממרכזים מחדשAngle from the velocity, re-centre

אנלוגיה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.
נושאTopic 5

פרלקסהParallax

רקע בשכבותA layered background

  • פרלקסה: רחוק = איטיParallax: far = slow
  • גבעות במהירות 30% מהצינורותHills at 30% of the pipes' speed
  • % לגלילה אינסופית% for endless scrolling

אנלוגיהAnalogy

פרלקסה היא כמו לנסוע ולראות שהירח "נוסע" איתכם: כל מה שרחוק יותר זז פחות, והמוח מבין עומק.Parallax is like driving and seeing the moon "follow" you: the farther something is, the less it moves, and the brain reads depth.
נושאTopic 6

משחקGame

Flappy: המשחקFlappy: the game

  • כבידה, דחיפה וצינורותGravity, flaps and pipes
  • ניקוד בצינור שעברA point per passed pipe
  • ציפור מסתובבת וגבעות ברקעA tilting bird and hills behind

אנלוגיהAnalogy

Flappy מראה שמשחק ממכר לא צריך להיות מסובך: כבידה, לחיצה אחת, ומכשולים. השאר הוא כוונון של מספרים.Flappy shows an addictive game needn't be complicated: gravity, one button, obstacles. The rest is tuning numbers.

כבידה: vel += GRAVITY בכל פרייםGravity: vel += GRAVITY every frame

דחיפה: vel = FLAP בלחיצהImpulse: vel = FLAP on a press

y += vel הופך מהירות לתנועהy += vel turns velocity into motion

צינור = x ומרכז רווחA pipe = x and a gap centre

מלבן עליון ומלבן תחתון מחושביםTop and bottom rects are computed

גלילה: הצינורות זזים, הציפור לאScrolling: pipes move, the bird doesn't

נקודה כשהצינור עובר את הציפורA point when the pipe passes the bird

דגל scored = פעם אחת בלבדA scored flag = only once

תיבת פגיעה קטנה מהציורA hitbox smaller than the drawing

ציור על Surface שקוףDraw on a transparent Surface

pygame.transform.rotate(surf, angle)pygame.transform.rotate(surf, angle)

זווית לפי המהירות, ממרכזים מחדשAngle from the velocity, re-centre

פרלקסה: רחוק = איטיParallax: far = slow

גבעות במהירות 30% מהצינורותHills at 30% of the pipes' speed

% לגלילה אינסופית% for endless scrolling

כבידה, דחיפה וצינורותGravity, flaps and pipes

ניקוד בצינור שעברA point per passed pipe

ציפור מסתובבת וגבעות ברקעA tilting bird and hills behind

מה למדנוWhat we learned

  • כבידה: vel += GRAVITY בכל פרייםGravity: vel += GRAVITY every frame
  • צינור = x ומרכז רווחA pipe = x and a gap centre
  • נקודה כשהצינור עובר את הציפורA point when the pipe passes the bird
  • ציור על Surface שקוףDraw on a transparent Surface
  • פרלקסה: רחוק = איטיParallax: far = slow
  • כבידה, דחיפה וצינורותGravity, flaps and pipes

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

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

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