09.02.2017 Views

creez-des-applications-pour-android

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6 Exploiter les fonctionnalités d’Android<br />

private Type mType = null ;<br />

private RectF mRectangle = null ;<br />

public Type getType() {<br />

return mType;<br />

}<br />

public RectF getRectangle() {<br />

return mRectangle;<br />

}<br />

}<br />

public Bloc(Type pType, int pX, int pY) {<br />

this.mType = pType;<br />

this.mRectangle = new RectF(pX * SIZE, pY * SIZE, (pX + 1) * SIZE, (pY + 1) * S<br />

}<br />

Rien de spécial ici, je vous ai déjà parlé de tout auparavant. Remarquez le calcul qui permet de<br />

placer un bloc en fonction de sa position en tant que bloc et non en pixels.<br />

6.7.3.2.2 La boule<br />

import <strong>android</strong>.graphics.Color;<br />

import <strong>android</strong>.graphics.RectF;<br />

public class Boule {<br />

// Rayon de la boule<br />

public static final int RAYON = 10 ;<br />

// Couleur de la boule<br />

private int mCouleur = Color.GREEN ;<br />

public int getCouleur() {<br />

return mCouleur;<br />

}<br />

// Vitesse maximale autorisée <strong>pour</strong> la boule<br />

private static final float MAX_SPEED = 20.0f;<br />

// Permet à la boule d'accélérer moins vite<br />

private static final float COMPENSATEUR = 8.0f;<br />

// Utilisé <strong>pour</strong> compenser les rebonds<br />

private static final float REBOND = 1.75f;<br />

// Le rectangle qui correspond à la position de départ de la boule<br />

private RectF mInitialRectangle = null ;<br />

// A partir du rectangle initial on détermine la position de la boule<br />

public void setInitialRectangle(RectF pInitialRectangle) {<br />

454

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

Saved successfully!

Ooh no, something went wrong!