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

חזרה למפגשBack
PythonPython

ברוכים הבאים ל-Pygame: בועות קופצותWelcome to Pygame: Bubble Bounce

מפגש 37: התקנת pygame-ce, לולאת המשחק, ציור, תנועה, כבידה ואירועי עכבר.Session 37: Installing pygame-ce, the game loop, drawing, movement, gravity and mouse events.

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

  • חלוןWindow
  • לולאהLoop
  • צורותShapes
  • תנועהMotion
  • הקפצהBounce
  • משחקGame
נושאTopic 1

חלוןWindow

חלון ראשוןA first window

  • pip install pygame-cepip install pygame-ce
  • pygame.display.set_mode((w, h))pygame.display.set_mode((w, h))
  • צבע = (אדום, ירוק, כחול), 0 עד 255Colour = (red, green, blue), 0 to 255

אנלוגיהAnalogy

החלון הוא כמו לוח ציור, ו-flip() הוא הרגע שבו מסובבים את הלוח לקהל: כל מה שציירתם מופיע בבת אחת.The window is like an easel, and flip() is the moment you turn the canvas to the audience: everything you drew appears at once.
נושאTopic 2

לולאהLoop

לולאת המשחקThe game loop

  • אירועים → עדכון → ציורEvents → update → draw
  • QUIT סוגר את החלוןQUIT closes the window
  • clock.tick(60) = 60 פריימים בשנייהclock.tick(60) = 60 frames per second

אנלוגיהAnalogy

לולאת משחק היא כמו ספר דפדוף: כל דף הוא פריים, וכשמדפדפים מהר העין רואה תנועה.A game loop is like a flip book: each page is a frame, and flipping fast makes the eye see motion.
נושאTopic 3

צורותShapes

קואורדינטות וצורותCoordinates and shapes

  • (0, 0) בפינה השמאלית העליונה(0, 0) is the top-left corner
  • y גדל כלפי מטה!y grows downward!
  • circle, rect, line, polygoncircle, rect, line, polygon

אנלוגיהAnalogy

מסך מחשב הוא כמו דף במחברת: מתחילים לכתוב בפינה העליונה, ושורה חדשה היא למטה, לא למעלה.A computer screen is like a notebook page: you start writing at the top corner, and a new line is lower down, not higher up.
נושאTopic 4

תנועהMotion

תנועה ומהירותMotion and velocity

  • מהירות: vx, vy בכל פרייםvelocity: vx, vy per frame
  • מיקום += מהירותposition += velocity
  • מהירות שלילית = שמאלה/למעלהNegative velocity = left/up

אנלוגיהAnalogy

מהירות היא כמו הוראה לצב: "כל צעד, 5 משבצות ימינה ו-3 למעלה". אחרי 10 צעדים יודעים בדיוק איפה הוא.Velocity is like an instruction to a robot turtle: "each step, 5 squares right and 3 up". After 10 steps you know exactly where it is.
נושאTopic 5

הקפצהBounce

להקפיץ מהקירותBouncing off the walls

  • פגיעה בקיר = הופכים את סימן המהירותHitting a wall = flip the velocity's sign
  • בודקים את הקצה, לא את המרכז: x + rCheck the edge, not the centre: x + r
  • מחזירים פנימה כדי לא להיתקעPush back inside so it doesn't get stuck

אנלוגיהAnalogy

להקפיץ זה כמו כדור שולחן: הוא פוגע בדופן, והכיוון מתהפך, אבל המהירות נשארת אותה מהירות.Bouncing is like a pool ball: it hits the cushion and the direction flips, but the speed stays the same.
נושאTopic 6

משחקGame

Bubble Bounce: המשחקBubble Bounce: the game

  • מחלקת Bubble עם update ו-drawA Bubble class with update and draw
  • רשימה של בועותA list of bubbles
  • MOUSEBUTTONDOWN → פוצציםMOUSEBUTTONDOWN → pop

אנלוגיהAnalogy

כל בועה היא כמו שחקן שמכיר את התפקיד שלו: המשחק רק אומר לכולם "זוזו" ו"ציירו את עצמכם", וכל אחד יודע איך.Each bubble is like an actor who knows its part: the game just tells everyone "move" and "draw yourselves", and each knows how.

pip install pygame-cepip install pygame-ce

pygame.display.set_mode((w, h))pygame.display.set_mode((w, h))

צבע = (אדום, ירוק, כחול), 0 עד 255Colour = (red, green, blue), 0 to 255

אירועים → עדכון → ציורEvents → update → draw

QUIT סוגר את החלוןQUIT closes the window

clock.tick(60) = 60 פריימים בשנייהclock.tick(60) = 60 frames per second

(0, 0) בפינה השמאלית העליונה(0, 0) is the top-left corner

y גדל כלפי מטה!y grows downward!

circle, rect, line, polygoncircle, rect, line, polygon

מהירות: vx, vy בכל פרייםvelocity: vx, vy per frame

מיקום += מהירותposition += velocity

מהירות שלילית = שמאלה/למעלהNegative velocity = left/up

פגיעה בקיר = הופכים את סימן המהירותHitting a wall = flip the velocity's sign

בודקים את הקצה, לא את המרכז: x + rCheck the edge, not the centre: x + r

מחזירים פנימה כדי לא להיתקעPush back inside so it doesn't get stuck

מחלקת Bubble עם update ו-drawA Bubble class with update and draw

רשימה של בועותA list of bubbles

MOUSEBUTTONDOWN → פוצציםMOUSEBUTTONDOWN → pop

מה למדנוWhat we learned

  • pip install pygame-cepip install pygame-ce
  • אירועים → עדכון → ציורEvents → update → draw
  • (0, 0) בפינה השמאלית העליונה(0, 0) is the top-left corner
  • מהירות: vx, vy בכל פרייםvelocity: vx, vy per frame
  • פגיעה בקיר = הופכים את סימן המהירותHitting a wall = flip the velocity's sign
  • מחלקת Bubble עם update ו-drawA Bubble class with update and draw

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

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

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