Você está na página 1de 18

//hecho por jassael alfredo ruiz serratos

package Unidad_4;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class PacMan_V2 extends Applet implements KeyListener


{
Image pacman;
int cordx=500,cordy=350,x=30,t,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,angi=120,rad=240,puntaje,ban[]= new int[8],ind;
String titulo="* JUEGO COMENZADO *",score="SCORE: ",imagen="pacman left.png";

public void init()


{
setSize(1000,650);
setBackground(Color.BLACK);
setForeground(Color.orange);
addKeyListener(this);
requestFocus();
pacman=getImage(getDocumentBase(),imagen);
}

public void start()


{
for(ind=0;ind<8;ind++)

ban[ind]=0;
}

public void paint(Graphics g)


{
if(c1==0)
g.fillOval(225, 225, 50, 50);//comida 1
if(c2==0)
g.fillOval(425, 225, 50, 50);//comida 2
if(c3==0)
g.fillOval(625, 225, 50, 50);//comida 3
if(c4==0)
g.fillOval(825, 225, 50, 50);//comida 4
if(c5==0)
g.fillOval(225, 475, 50, 50);//comida 5
if(c6==0)
g.fillOval(425, 475, 50, 50);//comida 6
if(c7==0)
g.fillOval(625, 475, 50, 50);//comida 7
if(c8==0)
g.fillOval(825, 475, 50, 50);//comida 8

Font fb1 = new Font("TimesNewRoman",Font.BOLD,20);


g.setFont(fb1);
g.drawString(score+" "+puntaje, 50, 50);
if(puntaje==80000)

{
g.setColor(Color.WHITE);
Font fb2 = new Font("TimesNewRoman",Font.BOLD,20);
g.setFont(fb2);
g.drawString("GAME OVER PRESIONA F1 PARA COMENZAR DE NUEVO",
100, 100);
}

g.setColor(Color.BLUE);
Font fb = new Font("TimesNewRoman",Font.BOLD,50);
g.setFont(fb);
if(t==1)
{
g.drawString(titulo, 300,50);
Retardo(2000);
t=0;
}
g.setColor(Color.YELLOW);
g.drawImage(pacman,cordx,cordy,100,100,this);//pacman
//g.fillArc(cordx, cordy, 100, 100,angi,rad); // dibuja a pacman
g.setColor(Color.red);
g.fillRect(300,200,100,100);// cuadro 1
g.fillRect(700,200,100,100);// cuadro 2
g.fillRect(300,450,100,100);// cuadro 3
g.fillRect(700,450,100,100);// cuadro 4
}

public void keyPressed(KeyEvent k)


{
showStatus("Caminando...");
int key = k.getKeyCode();

switch(key)
{
case KeyEvent.VK_UP:
imagen="pacman up.png";
pacman=getImage(getDocumentBase(),imagen);
if((cordx>=250 && cordx<=350) && cordy==300 || (cordx>=650
&& cordx<=750) && cordy==300 ||(cordx>=250 && cordx<=350) && cordy==550 || (cordx>=650
&& cordx<=750) && cordy==550)

// cuadro 3

{ // cuadro 1
// cuadro 4

// cuadro 2

}
else
{
cordy-=50;
angi=30;
rad=-240;
}

if(cordx==200 && cordy==200)//validacion comida 1


{
c1=1;

if(ban[0]==0)
{
puntaje+=10000;
ban[0]=1;
}
}
if(cordx==400 && cordy==200) //validacion comida 2
{
c2=1;
if(ban[1]==0)
{
puntaje+=10000;
ban[1]=1;
}
}
if(cordx==600 && cordy==200) //validacion comida 3
{
c3=1;
if(ban[2]==0)
{
puntaje+=10000;
ban[2]=1;
}
}
if(cordx==800 && cordy==200) //validacion comida 4
{

c4=1;
if(ban[3]==0)
{
puntaje+=10000;
ban[3]=1;
}
}
if(cordx==200 && cordy==450) //validacion comida 5
{
c5=1;
if(ban[4]==0)
{
puntaje+=10000;
ban[4]=1;
}
}
if(cordx==400 && cordy==450) //validacion comida 6
{
c6=1;
if(ban[5]==0)
{
puntaje+=10000;
ban[5]=1;
}
}
if(cordx==600 && cordy==450) //validacion comida 7

{
c7=1;
if(ban[6]==0)
{
puntaje+=10000;
ban[6]=1;
}
}
if(cordx==800 && cordy==450) //validacion comida 8
{
c8=1;
if(ban[7]==0)
{
puntaje+=10000;
ban[7]=1;
}
}

if(cordy<=getHeight()-(getHeight()+100)) // validacion para que


salga al lado opuesto de la pantalla
cordy=getHeight()-50;

break;

case KeyEvent.VK_DOWN:
imagen="pacman down.png";

pacman=getImage(getDocumentBase(),imagen);
if((cordx>=250 && cordx<=350) && cordy==100 || (cordx>=650
&& cordx<=750) && cordy==100 ||(cordx>=250 && cordx<=350) && cordy==350 || (cordx>=650
&& cordx<=750) && cordy==350)

// cuadro 3

{ // cuadro 1
// cuadro 4

// cuadro 2

}
else
{
cordy+=50;
angi=-30;
rad=240;
}

if(cordx==200 && cordy==200)//validacion comida 1


{
c1=1;
if(ban[0]==0)
{
puntaje+=10000;
ban[0]=1;
}
}
if(cordx==400 && cordy==200) //validacion comida 2
{
c2=1;
if(ban[1]==0)

{
puntaje+=10000;
ban[1]=1;
}
}
if(cordx==600 && cordy==200) //validacion comida 3
{
c3=1;
if(ban[2]==0)
{
puntaje+=10000;
ban[10]=1;
}
}
if(cordx==800 && cordy==200) //validacion comida 4
{
c4=1;
if(ban[3]==0)
{
puntaje+=10000;
ban[3]=1;
}
}
if(cordx==200 && cordy==450) //validacion comida 5
{
c5=1;

if(ban[4]==0)
{
puntaje+=10000;
ban[4]=1;
}
}
if(cordx==400 && cordy==450) //validacion comida 6
{
c6=1;
if(ban[5]==0)
{
puntaje+=10000;
ban[5]=1;
}
}
if(cordx==600 && cordy==450) //validacion comida 7
{
c7=1;
if(ban[6]==0)
{
puntaje+=10000;
ban[6]=1;
}
}
if(cordx==800 && cordy==450) //validacion comida 8
{

c8=1;
if(ban[7]==0)
{
puntaje+=10000;
ban[7]=1;
}
}

if(cordy>=getHeight()) // validacion para que salga al lado opuesto


de la pantalla
cordy=getHeight()-(getHeight()+50);
break;

case KeyEvent.VK_LEFT:
imagen="pacman left.png";
pacman=getImage(getDocumentBase(),imagen);
if(cordx==400 && (cordy>=150 && cordy<=250) || cordx==800 &&
(cordy>=150 && cordy<=250) || cordx==400 && (cordy>=400 && cordy<=500) || cordx==800 &&
(cordy>=400 && cordy<=500))

// cuadro 3

{ // cuadro 1
// cuadro 4
}
else
{
cordx-=50;
angi=120;
rad=-240;

// cuadro 2

if(cordx==400 && cordy==200) //validacion comida 2


{
c2=1;
if(ban[1]==0)
{
puntaje+=10000;
ban[1]=1;
}
}
if(cordx==800 && cordy==200) //validacion comida 4
{
c4=1;
if(ban[3]==0)
{
puntaje+=10000;
ban[3]=1;
}
}
if(cordx==400 && cordy==450) //validacion comida 6
{
c6=1;
if(ban[5]==0)
{
puntaje+=10000;

ban[5]=1;
}
}
if(cordx==800 && cordy==450) //validacion comida 8
{
c8=1;
if(ban[7]==0)
{
puntaje+=10000;
ban[7]=1;
}
}

if(cordx<=getWidth()-(getWidth()+100)) // validacion para que


salga al lado opuesto de la pantalla
cordx=getWidth()-50;
break;

case KeyEvent.VK_RIGHT:
imagen="pacman right.png";
pacman=getImage(getDocumentBase(),imagen);
if(cordx==200 && (cordy>=150 && cordy<=250) || cordx==600 &&
(cordy>=150 && cordy<=250) || cordx==200 && (cordy>=400 && cordy<=500) || cordx==600 &&
(cordy>=400 && cordy<=500))

// cuadro 3

{ // cuadro 1
// cuadro 4
}

// cuadro 2

else
{
cordx+=50;
angi=60;
rad=240;
}

if(cordx==200 && cordy==200)//validacion comida 1


{
c1=1;
if(ban[0]==0)
{
puntaje+=10000;
ban[0]=1;
}
}
if(cordx==600 && cordy==200) //validacion comida 3
{
c3=1;
if(ban[2]==0)
{
puntaje+=10000;
ban[2]=1;
}
}
if(cordx==200 && cordy==450) //validacion comida 5

{
c5=1;
if(ban[4]==0)
{
puntaje+=10000;
ban[4]=1;
}
}
if(cordx==600 && cordy==450) //validacion comida 7
{
c7=1;
if(ban[6]==0)
{
puntaje+=10000;
ban[6]=1;
}
}

if(cordx>=getWidth()) // validacion para que salga al lado opuesto


de la pantalla
cordx=getWidth()-(getWidth()+50);
break;
case KeyEvent.VK_F1:

c1=0;c2=0;c3=0;c4=0;c5=0;c6=0;c7=0;c8=0;puntaje=0;t=1;cordx=500;cordy=350;
for(ind=0;ind<8;ind++)

ban[ind]=0;

}
repaint();

public void Retardo (int tiempo)


{
try
{
Thread.sleep( tiempo );
}
catch( Exception e)
{

}
}

public void keyReleased(KeyEvent k)


{
showStatus("Caminando...");
int key = k.getKeyCode();

switch(key)

{
case KeyEvent.VK_UP:
angi=60;
rad=-300;
break;

case KeyEvent.VK_DOWN:
angi=-60;
rad=300;

break;

case KeyEvent.VK_LEFT:
angi=150;
rad=-300;

break;

case KeyEvent.VK_RIGHT:
angi=30;
rad=300;
}
repaint();
}

public void keyTyped(KeyEvent arg0) {

// TODO Auto-generated method stub

Você também pode gostar