nea_iyut

Sabtu, 20 Juni 2009

Game JavaQ...

/* Game Sepak Bola
*catatan:Game ini menggunakan java applet.
*
*Gunakan panah pada keyboard untuk bergerak, gunakan spasi untuk
*pergantian pemain
*
* */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;

public class SoccerGame extends JApplet implements KeyListener
{
Ball b;
Paddles p1[] = new Paddles[3];
Paddles2 p2[] = new Paddles2[3];

int active = 0;
int pcactive;
int p1score = 0;
int pcscore = 0;

public void init()
{
addKeyListener(this);
b=new Ball();

//PEMAIN 1
p1[0] = new Paddles();
p1[0].x = 70;
p1[0].y = 250;
p1[1] = new Paddles();
p1[1].x = 70;
p1[1].y = 70;
p1[2] = new Paddles();
p1[2].x = 70;
p1[2].y = 450;

//KOMPUTER, PEMAIN 2
p2[0] = new Paddles2();
p2[0].x = 630;
p2[0].y = 260;
p2[1] = new Paddles2();
p2[1].x = 700;
p2[1].y = 70;
p2[2] = new Paddles2();
p2[2].x = 700;
p2[2].y = 450;
}

public void paint(Graphics g)
{
g.setColor(Color.blue);
g.fillRect(0,0,50,606);
g.fillRect(750,0,50,800);
g.fillRect(0,0,800, 50);
g.fillRect(0,550,800, 50);
g.setColor(Color.black);
g.drawRect(50, 50, 700, 500);
g.setColor(Color.GREEN);
g.fillRect(52, 52, 697, 498); //Lapangan Sepak Bola

//GAWANG!!!!!!!!!! PEMAIN 1
g.setColor(Color.black);
g.drawLine(150, 425, 150, 175);
g.drawLine(150, 426, 50, 426);
g.drawLine(150, 175, 50, 175);

//GAWANG!!!!!!!!!! PEMAIN 2
g.setColor(Color.black);
g.drawLine(650, 425, 650, 175);
g.drawLine(750, 426, 650, 426);
g.drawLine(750, 175, 650, 175);

//Untuk garis
g.setColor(Color.black);
g.drawLine(415, 50, 415, 550);
g.drawOval(365, 260, 100, 100);
g.setColor(b.ballColor);
p1[active].p1paddleColor = Color.white;

for (int i=0; i < p1paddlecolor =" Color.red;" i="0;" i="0;"> 2)
{
active = 0;
}
}
if (p1score == 2 )
{
if (e.getKeyCode()==16)
{
b.speedY = 15;
b.speedX = 15;
}
}

if (e.getKeyCode()==40)//atas
{
p1[active].mvUp=true;
p1[active].mvDwn=false;
}
else if (e.getKeyCode()==38)//bawah
{
p1[active].mvUp=false;
p1[active].mvDwn=true;
}

if (e.getKeyCode()==37) //kiri
{
p1[active].mvLft=true;
p1[active].mvRght=false;
}
else if (e.getKeyCode()==39) //kanan
{
p1[active].mvLft=false;
p1[active].mvRght=true;
}
}

//Untuk paddle


public void keyReleased(KeyEvent e)
{
for (int i=0; i < mvup="false;" mvdwn="false;" mvup="false;" mvdwn="false;" mvlft="false;" mvrght="false;" mvrght="false;" mvlft="false;" x="400;" y="300;" width="10;" height="10;" speedx =" 10;" speedy=" 10;" direction = "left" ballcolor="Color.orange;" x =" x" y =" y" i="0;"> 730)
{
if(speedX >0)
{
speedX = -speedX;
if (speedX < direction= "left"> 0)
{
direction = "right";
}
} //Pembatas Sisi kanan
}
else if (y > 530)
{
if(speedY>0)
{
speedY = -speedY;

} //Pembatas Bawah
}
else if (x < speedx =" -speedX;" direction= "left"> 0)
{
direction = "right";
}
} //Pembatas Sisi Kiri
}
else if (y < speedy =" -speedY;"> 180 && y <> 0 && x < pcscore =" pcscore" y =" 300;" x =" 400;"> 180 && y <>660 && x < p1score =" p1score" y =" 300;" x =" 400;"> 175)
{
speedY = -speedY; //Sudut kiri atas
}
else if (x <> 426)
{
speedY = -speedY; //Sudut kiri bawah
}
if (x + width > 650 && y <> 175)
{
speedY = -speedY; //Sudut kanan atas
}
else if (x + width > 650 && y <> 426)
{
speedY = -speedY; //Sudut kanan bawah
}
}

//Di sini pembagian pemain menjadi 3 area, sehingga pemain dapat bergerak dalam satu waktu
//Berdasarkan pemain yang sedang memiliki bola

public void compCheck()
{
//Komputer
if (x > 55 && x <> 55 && y < y =" p2[1].y"> b.y)
{
p2[1].y = p2[1].y - p2[1].speed;
}
if (p2[1].x > b.x)
{
p2[1].x = p2[1].x - p2[1].speed;
}
else if (p2[1].x < x =" p2[1].x"> 500 && x <> 175 && y < y =" p2[0].y"> b.y)
{
p2[0].y = p2[0].y - p2[0].speed;
}
}

if (x > 55 && x <> 350 && y < y =" p2[2].y"> b.y)
{
p2[2].y = p2[2].y - p2[2].speed;
}
if (p2[2].x > b.x)
{
p2[2].x = p2[2].x - p2[2].speed;
}
else if (p2[2].x < x =" p2[2].x" y =" 250;" x =" 100;" width =" 10;" height =" 50;" speed =" 10;" p1paddlecolor="Color.red;" direction ="=""> y)
{
if (b.y <> x)
{
if (b.x < speedx =" -b.speedX;" direction= "left"> 0)
{
b.direction = "right";
}
}
}
}
}
}
} // akhir checkpaddle

public void move()
{
if (mvUp == true)
{
y = y + speed;
mvDwn = false;
}
else if (mvDwn == true)
{
y = y - speed;
mvUp = false;
}
if (mvLft == true)
{
x = x - speed;
mvRght = false;
}
else if (mvRght == true)
{
x = x + speed;
mvLft = false;
}
}
} //akhir dari class paddles

public class Paddles2
{
int y = 250;
int x = 500;
int width = 10;
int height = 50;
int speed = 2;
Color p2paddleColor=Color.black;

public void checkPaddle2()
{
//cek jika bola mengenai paddle
if (b.direction == "right")
if (b.y + 20 > y)
{
if (b.y <> x)
{
if (b.x < speedx =" -b.speedX;" direction= "left"> 0)
{
b.direction = "right";
}
}
}
}
}
} // akhir checkpaddle
} // akhir class paddles2
} //akhir class soccer

//Untuk SoccerGame.htm
//Untuk Pemanggilan Soocergame.class













//Tampilan Game Menggunakan Java Applet

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda