09.02.2017 Views

creez-des-applications-pour-android

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6.7 TP : un labyrinthe<br />

}<br />

this.mInitialRectangle = pInitialRectangle;<br />

this.mX = pInitialRectangle.left + RAYON;<br />

this.mY = pInitialRectangle.top + RAYON;<br />

// Le rectangle de collision<br />

private RectF mRectangle = null ;<br />

// Coordonnées en x<br />

private float mX;<br />

public float getX() {<br />

return mX;<br />

}<br />

public void setPosX(float pPosX) {<br />

mX = pPosX;<br />

}<br />

// Si la boule sort du cadre, on rebondit<br />

if(mX < RAYON) {<br />

mX = RAYON;<br />

// Rebondir, c'est changer la direction de la balle<br />

mSpeedY = -mSpeedY / REBOND;<br />

} else if(mX > mWidth - RAYON) {<br />

mX = mWidth - RAYON;<br />

mSpeedY = -mSpeedY / REBOND;<br />

}<br />

// Coordonnées en y<br />

private float mY;<br />

public float getY() {<br />

return mY;<br />

}<br />

public void setPosY(float pPosY) {<br />

mY = pPosY;<br />

if(mY < RAYON) {<br />

mY = RAYON;<br />

mSpeedX = -mSpeedX / REBOND;<br />

} else if(mY > mHeight - RAYON) {<br />

mY = mHeight - RAYON;<br />

mSpeedX = -mSpeedX / REBOND;<br />

}<br />

}<br />

// Vitesse sur l'axe x<br />

private float mSpeedX = 0 ;<br />

// Utilisé quand on rebondit sur les murs horizontaux<br />

public void changeXSpeed() {<br />

455

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!