נבנה על ידיBuilt by Ariel Yohimovich
JavaJava
התנגשויות ו-spritesCollisions & sprites
מפגש 45: מלבנים ועיגולים שמתנגשים, sprites מתמונות, אנימציה מפריימים וניקוד.Session 45: Rectangles and circles that collide, sprites from images, frame animation and scoring.
מלבנים ועיגולים שמתנגשים, sprites מתמונות, אנימציה מפריימים וניקוד. בסוף המפגש מוסיפים צעד לפרויקט המלווה.Rectangles and circles that collide, sprites from images, frame animation and scoring. At the end we add a step to the companion project.מה נעשה היוםToday's plan
- מונחיםTerms
- התנגשות, מצוירתA collision, drawn
- AABB בלי ספריותAABB with no libraries
- איזה פריים עכשיו?Which frame now?
- פרויקט מדףShelf project
עוברים על סדר היום ומזכירים את הפרויקט המלווה.Walk through the plan and mention the companion project.המונחים של המפגשThis session's terms
- AABB: התנגשות בין שני מלבנים ישרים:AABB: A collision between two upright rectangles:
- sprite: תמונה קטנה של דמות או עצם במשחק.sprite: A small picture of a character or object in a game.
- אנימציה מפריימים: מחליפים פריים כל כמה מאיות שנייה:frame animation: Switch the frame every few hundredths of a second:
- broad phase: שלב סינון לפני בדיקת התנגשות מדויקת:broad phase: A filtering step before exact collision checks:
לפני הקוד, המילים. כל מונח כאן מקושר גם במילון של הקורס.Before the code, the words. Every term here is also linked in the course glossary.נושאTopic 2
התנגשות, מצוירתA collision, drawn
התנגשות, מצוירתA collision, drawn
Rectangle.intersects בודק חפיפה.Rectangle.intersects checks for overlap.- הכוכב שנוגע במשוט מצויר באדום.The star touching the paddle is drawn in red.
- התמונה נוצרה באמת בזמן בניית האתר.The picture was really made while building the site.
Rectangle.intersects בודק חפיפה. הכוכב שנוגע במשוט מצויר באדום. התמונה נוצרה באמת בזמן בניית האתר.Rectangle.intersects checks for overlap. The star touching the paddle is drawn in red. The picture was really made while building the site.נושאTopic 3
AABB בלי ספריותAABB with no libraries
AABB בלי ספריותAABB with no libraries
- שני מלבנים חופפים אם כל אחד מתחיל לפני שהשני נגמר, בשני הצירים.Two rectangles overlap if each starts before the other ends, on both axes.
- בסימולציה רואים את ארבע ההשוואות.In the simulation you see the four comparisons.
שני מלבנים חופפים אם כל אחד מתחיל לפני שהשני נגמר, בשני הצירים. בסימולציה רואים את ארבע ההשוואות.Two rectangles overlap if each starts before the other ends, on both axes. In the simulation you see the four comparisons.נושאTopic 4
איזה פריים עכשיו?Which frame now?
איזה פריים עכשיו?Which frame now?
- 4 פריימים, כל אחד 0.1 שנייה.4 frames, each 0.1 seconds.
- הזמן קובע את הפריים, לא מספר הסיבובים של הלולאה, כך שהאנימציה באותה מהירות בכל מחשב.The time decides the frame, not the number of loop rounds, so the animation runs at the same speed on every computer.
4 פריימים, כל אחד 0.1 שנייה. הזמן קובע את הפריים, לא מספר הסיבובים של הלולאה, כך שהאנימציה באותה מהירות בכל מחשב.4 frames, each 0.1 seconds. The time decides the frame, not the number of loop rounds, so the animation runs at the same speed on every computer.נושאTopic 5
פרויקט מדףShelf project
הצעד של היום בפרויקט מדףToday's step in the Shelf project
- משחק 3: לתפוס כוכביםGame 3: catch the stars
שלושה כוכבים נופלים 10 בכל טיק. כוכב שנוגע במשוט (40,90,30,5) נותן 10 נקודות ונעלם; כוכב שעבר את 100 נחשב פספוס ונעלם. אחרי 12 טיקים: score 20, missed 1, left 0.Three stars fall 10 per tick. A star touching the paddle (40,90,30,5) gives 10 points and disappears; a star past 100 counts as missed and disappears. After 12 ticks: score 20, missed 1, left 0.AABB: התנגשות בין שני מלבנים ישרים:AABB: A collision between two upright rectangles:
המונחים של המפגשThis session's termssprite: תמונה קטנה של דמות או עצם במשחק.sprite: A small picture of a character or object in a game.
המונחים של המפגשThis session's termsאנימציה מפריימים: מחליפים פריים כל כמה מאיות שנייה:frame animation: Switch the frame every few hundredths of a second:
המונחים של המפגשThis session's termsbroad phase: שלב סינון לפני בדיקת התנגשות מדויקת:broad phase: A filtering step before exact collision checks:
המונחים של המפגשThis session's termsRectangle.intersects בודק חפיפה.Rectangle.intersects checks for overlap.
התנגשות, מצוירתA collision, drawnהכוכב שנוגע במשוט מצויר באדום.The star touching the paddle is drawn in red.
התנגשות, מצוירתA collision, drawnהתמונה נוצרה באמת בזמן בניית האתר.The picture was really made while building the site.
התנגשות, מצוירתA collision, drawnשני מלבנים חופפים אם כל אחד מתחיל לפני שהשני נגמר, בשני הצירים.Two rectangles overlap if each starts before the other ends, on both axes.
AABB בלי ספריותAABB with no librariesבסימולציה רואים את ארבע ההשוואות.In the simulation you see the four comparisons.
AABB בלי ספריותAABB with no libraries4 פריימים, כל אחד 0.1 שנייה.4 frames, each 0.1 seconds.
איזה פריים עכשיו?Which frame now?הזמן קובע את הפריים, לא מספר הסיבובים של הלולאה, כך שהאנימציה באותה מהירות בכל מחשב.The time decides the frame, not the number of loop rounds, so the animation runs at the same speed on every computer.
איזה פריים עכשיו?Which frame now?משחק 3: לתפוס כוכביםGame 3: catch the stars
הצעד של היום בפרויקט מדףToday's step in the Shelf projectשני מלבנים חופפים בציר x אבל לא בציר y. מתנגשים?Two rectangles overlap on x but not on y. Do they collide?
- לא: צריך חפיפה בשני הציריםNo: they must overlap on both axes
- כןYes
- תלוי בגודלIt depends on size
- רק אם הם ריבועיםOnly if they're squares
שואלים את הכיתה ומצביעים. התשובה בשקופית הבאה.Ask the class and take a vote. The answer is on the next slide.לא: צריך חפיפה בשני הציריםNo: they must overlap on both axes
נכון.Right.למה משווים dx*dx + dy*dy ל-r*r ולא מחשבים שורש?Why compare dx*dx + dy*dy with r*r instead of taking a square root?
- זה נותן אותה תשובה ובלי שורש איטיIt gives the same answer without a slow square root
- כי שורש לא קיים ב-JavaBecause Java has no square root
- זה מדויק יותרIt's more exact
- סתם הרגלJust habit
שואלים את הכיתה ומצביעים. התשובה בשקופית הבאה.Ask the class and take a vote. The answer is on the next slide.זה נותן אותה תשובה ובלי שורש איטיIt gives the same answer without a slow square root
נכון.Right.מוחקים מרשימה בזמן לולאה עם אינדקס. מאיזה כיוון כדאי לרוץ?Removing from a list in an index loop. Which direction should you run?
- מהסוף להתחלהFrom the end to the start
- מההתחלה לסוףFrom the start to the end
- לא משנהDoesn't matter
- אסור למחוקYou can't remove
שואלים את הכיתה ומצביעים. התשובה בשקופית הבאה.Ask the class and take a vote. The answer is on the next slide.מהסוף להתחלהFrom the end to the start
נכון: מחיקה לא מזיזה את מה שעוד לא בדקתם.Right: removing doesn't shift what you haven't checked yet.מלבניםRectangles
- עם
Box.intersects מהתזכורת:With Box.intersects from the refresher:
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.עיגוליםCircles
circles(x1, y1, r1, x2, y2, r2):circles(x1, y1, r1, x2, y2, r2):
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.פריים לפי זמןA frame by time
- 3 פריימים של 0.2 שנייה.3 frames of 0.2 seconds.
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.צייד באגים: נגיעה בקצהBug hunter: touching at the edge
- שני מלבנים שרק נוגעים בקצה (אחד נגמר ב-10 והשני מתחיל ב-10) נחשבים כאן התנגשות, כי הבדיקה משתמשת ב-
<=.Two rectangles that only touch at the edge (one ends at 10, the other starts at 10) count as a collision here, because the check uses <=.
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.משחק 3: לתפוס כוכביםGame 3: catch the stars
- שלושה כוכבים נופלים 10 בכל טיק.Three stars fall 10 per tick.
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.תא ב-sprite sheetA cell in a sprite sheet
- sprite sheet עם 4 עמודות של 32 פיקסלים.A sprite sheet with 4 columns of 32 pixels.
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.רשת חוסכת בדיקותA grid saves checks
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.השחקן נגמר ב-x=30; (30,30) מתחיל בדיוק שם, ולכן לא חופף.The player ends at x=30; (30,30) starts exactly there, so no overlap.
מלבניםRectanglesבלי Math.sqrt: משווים ריבועים.No Math.sqrt: compare squares.
עיגוליםCircles(int) (time / frameSeconds) % frames(int) (time / frameSeconds) % frames
פריים לפי זמןA frame by timeמה למדנוWhat we learned
- AABB: התנגשות בין שני מלבנים ישרים:AABB: A collision between two upright rectangles:
Rectangle.intersects בודק חפיפה.Rectangle.intersects checks for overlap.- שני מלבנים חופפים אם כל אחד מתחיל לפני שהשני נגמר, בשני הצירים.Two rectangles overlap if each starts before the other ends, on both axes.
- 4 פריימים, כל אחד 0.1 שנייה.4 frames, each 0.1 seconds.
- משחק 3: לתפוס כוכביםGame 3: catch the stars
כל אחד אומר דבר אחד שלמד היום.Everyone says one thing they learned today.עכשיו לתרגולNow, practice
5 תרגילים ו-2 אתגרים, עם בדיקה אוטומטית5 exercises and 2 challenges, auto-checked
מפנים לעמוד התרגול.Point to the practice page.