ערכתי לאחרונה בתאריך 10.08.15 בשעה 13:17 בברכה, TooBigToFail
אני יותר מחפש דרך על איך להבין את כל החישובים שעושים במשחק עם הוקטורים ומשפטי ההתניה המורכבים שם.
אני מניח שאם אני אוכל לראות את הקוד בהתאם למה שקורה על המסך, תהיה לי הבנה טובה יותר לגבי מה רץ מתי..
אולי אני פשוט צריך הנחיה על איך להשתמש בDEBUGGER (איפה כדאי לשים את התנאי עצירה, באופן כללי) כדי להבין את הרצף של התוכנית טוב יותרב"רצף של התוכנית" אני מתכוון לאיזו מתודה נקראת מתי, ואחרי זה מתודה, ולאיזה מתודה היא קוראת בתוכה - כל אלה בהתאם למה שקורה על המסך.
הנה דוגמא:
הייתי רוצה להבין למה בתנאי הראשון אם המהירות קטנה מX, וגם הפוזיציה של X פחות הרדיוס (רדיוס של מה זה?) קטן מהרוחב של המחבט, וגם יש נגיעה במחבט, אז לבצע את השינויים למשתנים בפנים (שגם אותם לא ברור לי למה עושים)
public void draw(Canvas canvas) { if (reset) return; if (position == null) position = new Vector(getDisplayWidth() / 2, getDisplayHeight() / 2); if (velocity == null) velocity = new Vector(-(getDisplayWidth() / 92), 0); float radius = 5 * getDensity(); position.x += velocity.x; position.y += velocity.y; if (!gameover) { if (velocity.x < 0 && position.x - radius < paddleOne.getWidth() && touchedPaddle(paddleOne)) { velocity.x *= -1; velocity.y += getVelocityY(paddleOne, radius); position.x = paddleOne.getWidth() + radius * 2; } if (velocity.x > 0 && position.x + radius > getDisplayWidth() - paddleTwo.getWidth() && touchedPaddle(paddleTwo)) { velocity.x *= -1; velocity.y += getVelocityY(paddleTwo, radius); position.x = getDisplayWidth() - paddleTwo.getWidth(); } if (touchedWall(getDisplayHeight(), radius)) velocity.y *= -1; } canvas.drawCircle(position.x - radius, position.y, radius, paint); if (gameover && (position.x + radius < 0 || position.x - radius > getDisplayWidth())) { reset = true; if (velocity.x < 0) onPointListener.playerTwo(); else onPointListener.playerOne(); } if (position.x - radius < paddleOne.getWidth() - paddleOne.getThickness() || position.x + radius > getDisplayWidth() - paddleTwo.getWidth() + paddleTwo.getThickness()) gameover = true; }
|