Revista JogosPro e-Magazine No. 2 (Versão Antiga)

Page 42

ARTIGO Exemplo de Código: Jogo Ping.java public void onGameStart() { onBounce();

}

{

// reset the racket position & the ball settings (position & speed) racket.setPos(racketX,racketY=Settings.screenHeight>>1,false); ball.reinit(); level=score=0;

public void onBounce() { if (USE_BACKGROUND) { // pass null to disable an automatic background displaying useBackground(logo.nextFrame()); //fdie@420_26 } }

// we got a pen event, store the Y coordinate as the next racket Y position racketY=evt.y; // refresh the racket position racket.setPos(racketX,racketY,true);

}

/** * overrideable function called by the framework when the game stops running.<br> * The game is stopped by the the framework stop() function.<br> */ public void onGameStop() { // when the game stops, popup the GameOver window swap(GameOver.getInstance(this,highScores,score,optUserName. value)); } /** * overload Superwaba’s painting function. * @param gfx Graphics to draw at. */ public final void onPaint(Graphics gfx) { if (gameIsRunning) { int sk = Vm.getSystemKeysPressed(); if (sk != 0) { if ((sk & (Vm.SK_PAGE_UP | Vm.SK_HARD1)) != 0) racket.move(true); if ((sk & (Vm.SK_PAGE_DOWN | Vm.SK_HARD2)) != 0) racket.move(false); }

/** * overrideable function called by the framework when the pen moves.<br> * @param evt */ public final void onPenDrag (PenEvent evt) { // we got a pen event, store the Y coordinate as the next racket Y position racketY=evt.y; // refresh the racket position and cancel the keyboard mode racket.setPos(racketX,racketY,true);

}

}

// draw the ball ball.show(); // Increase the game level each time the scores is a multiple of SCORE_NEXT_LEVEL if ((score & SCORE_NEXT_LEVEL-1) == 0) { // increase the level and the ball speed level++; ball.increaseSpeed(SPEED_INCR_PERC); }

/** * display the game ending screen (hiscores screen). */ public void showHighScores() { swap(GameOver.getInstance(this,highScores,0,null)); }

score++; // render level & score levelRenderer.display(16,2,level,false); scoreRenderer.display(Settings.screenWidth>>1,2,score,false);

/** * overrideable function called by the framework when the pen touches the screen.<br> * @param evt event that occurs. */ public final void onPenDown (PenEvent evt) http://www.jogospro.com.br

// if non arcade game is selected, redrawings have to be called explicitly. if (!ARCADE_GAME) refresh();

Container blankContainer; /** Creates and places a blank container in the screen. */ public void blankScreen() { if (blankContainer == null) { blankContainer = new Container(); blankContainer.setRect(getRect()); blankContainer.setBackColor(backColor); } swap(blankContainer); }

// move the ball, that’s the hard work ball.move();

}

// if non arcade game is selected, redrawings have to be called explicitly. if (!ARCADE_GAME) refresh();

/** * overrideable function called by the framework when a key is pressed.<br> * @param evt */ public final void onKey (KeyEvent evt) { if (evt.key==IKeys.PAGE_UP || evt.key==IKeys.UP) racket.move(true); else if (evt.key==IKeys.PAGE_DOWN || evt.key==IKeys.DOWN) racket.move(false);

// redisplay the racket racket.show();

}

// if non arcade game is selected, redrawings have to be called explicitly. if (!ARCADE_GAME) refresh();

}

/** * display the game introduction screen. */ public final void showIntroduction() { Introduction.swapTo(this); }

NOVEMBRO 2004

JOGOSPRO e-magazine


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.