You are on page 1of 2

UNIVERSIDAD PRIVADA TELESUP

Mobile games
Import javax.microedition.lcdui.game.*;
Import javax.microedition.lcdui.Graphics.*;
Import javax.microedition.lcdui.Image.*;
Public class Animacion extends Game Canvas implements Runnable (
Graphics g;
Thread Subproceso;
Image Fondo, Circulo;
Public Animacion ()
Super (True);
G=getgraphics ();
Try
Fondo=Image.createImage(/fondo.jpg);
Circulo= Image.createImage(/circulo.gif);
catch (Exception e) ()
Subproceso = new Thread (this);
Subproceso.start()
Public void run()

public void run ()


int coordx = 0;
int coordy = 0;
int velx = 5;
int vely = 3;
int alto = getHeight();
int ancho = getwidth ();
while (true)
g.drawImage(fondo, 0,0 graphics.TOP Graphics.Left);
g.drawImage(circulo, coordx, coordy, Graphics.TOP Graphics
try
subproceso.sleep(30);
catch (interruptedException e)
ValordeTecla =Getkey State();
If (ValordeTecla& UP_PRESSED) =0)
Coordy=Math.max(0, coordy vely);
If (ValordeTecla& DOWN_PRESSED) =0)
Roberto Carlos Tvara Zapata

Ing de Sistemas

UNIVERSIDAD PRIVADA TELESUP


If ((coordy + circulo.getHeight ()) alto)
Coordy = coordy + vely;

If (ValodeTecla & LEFT_PRESSED) =0)


coordx = Math.max(0, coordx velx);
If (ValordeTecla& RIGHT_PRESSED) =0)
IF (coordx + circulo.getHeight () ) alto)
Coordy = coordy + vely;
flushGraphics () ;

Roberto Carlos Tvara Zapata

Ing de Sistemas

You might also like