Sep 202000
You need Java to view this applet.
This I programmed a month after the Sept 11th and my website never knew so many hits. My SP asked me to remove the content. ehe, Anyway I did a quick test in Firefox and it didn’t run though it did in IE.
You can modify the images, in the jar. As long as they are the same size it will play with whoever you want to have beaten up. As someone has done here.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.Random;
import java.awt.image.ImageObserver;
import java.net.URL;
import java.util.Date;
public class Slap extends Applet implements Runnable, KeyListener, MouseListener
{
private Point p_limb[];
private int y_energy, h_energy, y_speed, m_speed, s_wobble, frameLeftCount, frameRightCount, frameMax, gameStage, faceStage, dodge, h_damage, y_damage;
private int m_left_off, m_right_off, m_left_h_off, m_right_h_off, h_left_off, h_right_off, h_head_off, h_body_off;
private Thread him, jog;
private Rectangle r_a_bounds;
private Image i_left_h, i_right_h, i_right, i_left, i_h_left, i_h_right, i_h_head[], i_h_body, i_win, i_lose, i_fist_a, i_fist_b;
private AudioClip ac_swing, ac_hit, ac_gong, ac_taunt, ac_lose;
private MediaTracker imageTracker;
private Graphics offpic, offpic_information, offpic_stats, offpic_mirror;
private Image buffer, buffer_information, buffer_stats, buffer_mirror;
private boolean left_punch, right_punch, y_l_punch, y_r_punch;
private long l_stamp[], mill_punchLimit, mill_fistMin;
public void init() {
//Cheack Prams for required prams
if (this.getParameter("Author").compareTo("AtPeace, www.somedodgywebsite.com")!=0){
System.out.println("Missing Applet Pram : Author = AtPeace, www.somedodgywebsite.com");
return;
}
if (this.getParameter("Copyright").compareTo("Slap, Copyright 2001, AtPeace")!=0){
System.out.println("Missing Applet Pram : Copyright = Slap, Copyright 2001, AtPeace");
return;
}
if (this.getParameter("Graphics").compareTo("Flapcats")!=0){
System.out.println("Missing Applet Pram : Graphics = Flapcats");
return;
}
//Game Vals
y_speed = 15;
s_wobble = 5;
m_speed = 25;
frameMax = 3;
dodge = 70;
h_damage=Integer.parseInt(this.getParameter("h_damage"));
y_damage=Integer.parseInt(this.getParameter("y_damage"));
// h_damage = 7;
// y_damage = 5;
mill_punchLimit = 500;
mill_fistMin = 50;
l_stamp = new long[3];
for (int a=0;a<l_stamp.length;a++)
l_stamp[a] = System.currentTimeMillis();
this.setBackground(Color.black);
//Create image buffers
buffer = createImage(this.getBounds().width,235);
offpic = buffer.getGraphics();
r_a_bounds = new Rectangle(buffer.getWidth(this),buffer.getHeight(this));
buffer_information = createImage(this.getBounds().width,20);
offpic_information = buffer_information.getGraphics();
buffer_stats = createImage(this.getBounds().width,this.getBounds().height-(r_a_bounds.height+buffer_information.getHeight(this)));
offpic_stats = buffer_stats.getGraphics();
//Load Audio then Images
ac_gong = getAudioClip(getCodeBase(),"gong.au");
ac_swing = getAudioClip(getCodeBase(),"swing.au");
ac_hit = getAudioClip(getCodeBase(),"hit.au");
ac_taunt = getAudioClip(getCodeBase(),"taunt.au");
ac_lose = getAudioClip(getCodeBase(),"lose.au");
i_left_h = getImage (getCodeBase(),"m_left_h.gif");
i_right_h = getImage (getCodeBase(),"m_right_h.gif");
i_left = getImage (getCodeBase(),"m_left.gif");
i_right = getImage (getCodeBase(),"m_right.gif");
i_h_left = getImage (getCodeBase(),"y_left.gif");
i_h_right = getImage (getCodeBase(),"y_right.gif");
i_h_body = getImage (getCodeBase(),"y_body.gif");
i_win = getImage (getCodeBase(),"y_win.gif");
i_lose = getImage (getCodeBase(),"y_lose.gif");
i_fist_a = getImage (getCodeBase(),"fist_a.gif");
i_fist_b = getImage (getCodeBase(),"fist_b.gif");
imageTracker = new MediaTracker(this);
i_h_head=new Image[5];
for (int a=0;a<i_h_head.length;a++){
i_h_head[a]=getImage (getCodeBase(),"y_head"+a+".gif");
imageTracker.addImage(i_h_head[a],a);
}
imageTracker.addImage(i_right_h,5);
imageTracker.addImage(i_left,6);
imageTracker.addImage(i_right,7);
imageTracker.addImage(i_h_left,8);
imageTracker.addImage(i_h_right,9);
imageTracker.addImage(i_h_body,10);
imageTracker.addImage(i_win,11);
imageTracker.addImage(i_lose,12);
imageTracker.addImage(i_fist_a,13);
imageTracker.addImage(i_fist_b,14);
imageTracker.addImage(i_left_h,15);
try {imageTracker.waitForAll();}
catch (Exception e){System.out.println(e);}
// System.out.println("Image error : "+imageTracker.isErrorAny());
i_fist_a = i_fist_a.getScaledInstance(i_fist_a.getWidth(this)*2,i_fist_a.getHeight(this)*2,Image.SCALE_FAST);
i_fist_b = i_fist_b.getScaledInstance(i_fist_b.getWidth(this)*2,i_fist_b.getHeight(this)*2,Image.SCALE_FAST);
h_left_off = 95;
h_right_off = 21;
h_head_off = i_h_head[0].getWidth(this)/2;
h_body_off = i_h_body.getWidth(this)/2;
m_left_h_off = i_left_h.getWidth(this)/2;
m_right_h_off = i_right_h.getWidth(this)/2;
m_left_off = i_left.getWidth(this)/2;
m_right_off = i_right.getWidth(this)/2;
int balls = 15;
offpic_information.setColor(Color.white);
offpic_information.drawString("Z",20,balls);
offpic_information.drawString("X",100,balls);
offpic_information.drawString("N",195,balls);
offpic_information.drawString("M",290,balls);
offpic_information.setColor(Color.green);
offpic_information.drawString("- move left",30,balls);
offpic_information.drawString("- move right",110,balls);
offpic_information.drawString("- throw left",205,balls);
offpic_information.drawString("- throw right",300,balls);
p_limb = new Point[6];
initVals();
}
private void placeItems(){
//Your Left Hand
// p_limb[0] = new Point(r_a_bounds.width/3,r_a_bounds.height-(i_h_left.getHeight(this)+s_wobble));
p_limb[0] = new Point(r_a_bounds.width/3,r_a_bounds.height+s_wobble-i_h_left.getHeight(this));
//Your Right Hand
p_limb[1] = new Point((r_a_bounds.width/3)*2,r_a_bounds.height+s_wobble-i_h_right.getHeight(this));
//Your Head
p_limb[2] = new Point(r_a_bounds.width/2,r_a_bounds.height-(i_h_head[0].getHeight(this)+(i_h_body.getHeight(this)/2)));
//Your Body
p_limb[5] = new Point(r_a_bounds.width/2,r_a_bounds.height+s_wobble-i_h_body.getHeight(this));
//My Left Hand
p_limb[3] = new Point(r_a_bounds.width/4,r_a_bounds.height+s_wobble-i_left.getHeight(this));
//My Right Hand
p_limb[4] = new Point((r_a_bounds.width/4)*3,r_a_bounds.height+s_wobble-i_right.getHeight(this));
}
private void initVals(){
y_energy = 215;
h_energy = 215;
// h_energy = 0;
left_punch = right_punch = y_r_punch = y_l_punch = false;
frameLeftCount = frameRightCount = 0;
faceStage = 0;
placeItems();
drawImages();
}
public void start(){
this.addKeyListener(this);
this.addMouseListener(this);
}
private void fight(){
initVals();
ac_gong.play();
ac_taunt.play();
him = new Thread(this,"@Him");
jog = new Thread(this,"@Jog");
jog.start();
him.start();
// y_energy=-10;
}
public void stop(){
try {
him.stop();
jog.stop();
} catch (Exception e){}
jog=null;
him=null;
}
public void mousePressed(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
public void keyPressed(KeyEvent ke){}
public void mouseClicked(MouseEvent me){
if (gameStage==0){
if (new Rectangle(125,270,127,16).contains(me.getPoint())){
gameStage = 1;
fight();
}
} else if (gameStage==4||gameStage==6){
if (new Rectangle(10,264,60,20).contains(me.getPoint())){
gameStage = 1;
clearImages();
fight();
}
else if (new Rectangle(10,289,60,20).contains(me.getPoint()))
author();
}
}
private void author(){
try {
URL docs = new URL ("http://www.somedodgywebsite.com");
this.getAppletContext().showDocument(docs, "_new");
}
catch (Exception e) {System.out.println(e.toString());}
}
public void keyReleased(KeyEvent ke){
if (gameStage == 1){
char key = ke.getKeyChar();
if ((key=='n'||key=='N')&&(!right_punch&&!left_punch)&!(System.currentTimeMillis()-l_stamp[0]<mill_punchLimit)){
l_stamp[0] = System.currentTimeMillis();
left_punch=true;
ac_swing.play();
drawImages();
punchDetection("left");
}
else if ((key=='m'||key=='M')&&(!right_punch&&!left_punch)&!(System.currentTimeMillis()-l_stamp[0]<mill_punchLimit)){
l_stamp[0] = System.currentTimeMillis();
right_punch=true;
ac_swing.play();
drawImages();
punchDetection("right");
}
}
}
private void punchDetection(String fist){
Rectangle r_head = new Rectangle( p_limb[2].x-h_head_off,p_limb[2].y,h_head_off*2,i_h_head[faceStage].getHeight(this));
if (fist=="left"){
Point p_strike = new Point(p_limb[3].x+30,p_limb[3].y);
if (r_head.contains(p_strike)){
// System.out.println("You Hit with "+fist);
h_energy = h_energy - y_damage;
ac_hit.play();
}
}
else if (fist == "right"){
Point p_strike = new Point(p_limb[4].x-30,p_limb[4].y);
if (r_head.contains(p_strike)){
// System.out.println("You Hit with "+fist);
h_energy = h_energy - y_damage;
ac_hit.play();
}
}
}
public void keyTyped(KeyEvent ke){
if (gameStage == 1){
char key = ke.getKeyChar();
if (((key=='x')||(key=='X'))&&p_limb[3].x < r_a_bounds.width){
p_limb[3].x=p_limb[3].x+m_speed;
p_limb[4].x=p_limb[4].x+m_speed;
drawImages();
}
else if (((key=='z')||(key=='Z'))&&(p_limb[4].x > 0)){
p_limb[3].x=p_limb[3].x-m_speed;
p_limb[4].x=p_limb[4].x-m_speed;
drawImages();
}
}
}
private void sleep(long rest_time){
try {Thread.sleep(rest_time);}
catch (Exception ex){System.out.println("ex");}
}
private boolean random(double chance){
if (new Random().nextDouble() < chance) return true;
else return false;
}
public void run(){
if (Thread.currentThread()==him)
him();
if (Thread.currentThread()==jog)
jog();
}
private void him(){
Point p_my_head = new Point(p_limb[4].x-p_limb[3].x+r_a_bounds.width/2,0);
Rectangle r_punch = new Rectangle(0,0,30,r_a_bounds.height);
int totalEnergy = h_energy;
int tempFace = faceStage;
do {
//Deduce players head position
p_my_head.x=(p_limb[4].x-p_limb[3].x)/2+p_limb[3].x;
//Move in direcion for quickest hit with nearest hand
if ((p_my_head.x<p_limb[0].x)&&p_my_head.x<p_limb[1].x)
moveBody(-y_speed);
else if ((p_my_head.x>p_limb[0].x)&&p_my_head.x>p_limb[1].x)
moveBody(y_speed);
else if ((p_my_head.x>p_limb[0].x)&&(p_my_head.x<p_limb[1].x)){
if (p_my_head.x<((p_limb[1].x-p_limb[0].x)/2)+p_limb[0].x)
moveBody(y_speed);
else if (p_my_head.x>((p_limb[1].x-p_limb[0].x)/2)+p_limb[0].x)
moveBody(-y_speed);
}
// Move away if opponent keeps punching
if (left_punch){
if (random(0.75)&&new Rectangle(p_limb[2].x-41,0,82,r_a_bounds.height).contains(p_limb[3].x+30,p_limb[3].y))
moveBody(-dodge);
}
if (right_punch){
if (random(0.75)&&new Rectangle(p_limb[2].x-41,0,82,r_a_bounds.height).contains(p_limb[4].x-30,p_limb[4].y))
moveBody(dodge);
}
//Punch if avaliable
r_punch.x=p_my_head.x-(r_punch.width/2);
if (r_punch.contains(p_limb[0])){
// System.out.println("Left");
y_energy = y_energy - h_damage;
y_l_punch = true;
}
if (r_punch.contains(p_limb[1])){
// System.out.println("Right");
y_energy = y_energy - h_damage;
y_r_punch = true;
}
//Degrade face due to energy, get lower
tempFace = faceStage;
if(h_energy>175){
faceStage=0;
}
else if(h_energy>135){
faceStage=1;}
else if(h_energy>85){
faceStage=2;}
else if(h_energy>35){
faceStage=3;}
else {
faceStage=4;}
if (tempFace!=faceStage){
p_limb[2].y=p_limb[2].y+5;}
sleep(500);
} while (y_energy > 1 && h_energy > 1);
}
private void moveBody(int distance){
Point proposed_destination = new Point(p_limb[5].x+distance,p_limb[5].y);
if (r_a_bounds.contains(proposed_destination)){
p_limb[5].x=p_limb[5].x+distance;
for (int a=0;a<3;a++)
p_limb[a].x=p_limb[a].x+distance;
} else {
if (proposed_destination.x>r_a_bounds.width){
p_limb[5].x=p_limb[5].x-r_a_bounds.width/5*4;
for (int a=0;a<3;a++)
p_limb[a].x=p_limb[a].x-r_a_bounds.width/5*4;
}
else {
p_limb[5].x=p_limb[5].x+r_a_bounds.width/5*4;
for (int a=0;a<3;a++)
p_limb[a].x=p_limb[a].x+r_a_bounds.width/5*4;
}
}
}
private void jog(){
Random ra_rand = new Random();
Rectangle r_bounds[] = new Rectangle[p_limb.length];
for (int a = 0;a<r_bounds.length;a++)
r_bounds[a] = new Rectangle(10,s_wobble);
Point p_position[] = new Point[p_limb.length];
Point p_temp[] = new Point[p_limb.length];
for (int a = 0;a<r_bounds.length;a++){
p_position[a]= new Point(5,s_wobble/2);
p_temp[a]=new Point();
}
do {
for (int a = 0 ; a < r_bounds.length; a++ ){
double random = ra_rand.nextDouble();
if ((random < 0.25)){
//Move Up
p_temp[a] = p_position[a];
p_position[a].y++;
if (r_bounds[a].contains(p_position[a])){
p_limb[a].y++;
} else {
p_position[a] = p_temp[a];
p_position[a].y--;
}
}
else if ((random > 0.25)&&(random <0.5)){
//Move Down
p_temp[a] = p_position[a];
p_position[a].y--;
if (r_bounds[a].contains(p_position[a])){
p_limb[a].y--;
} else {
p_position[a] = p_temp[a];
p_position[a].y++;
}
}
else if ((random > 0.5)&&(random < 0.75)){
//Move Left
p_temp[a] = p_position[a];
p_position[a].x--;
if (r_bounds[a].contains(p_position[a])){
p_limb[a].x--;
} else {
p_position[a] = p_temp[a];
p_position[a].x++;
}
}
else if (random > 0.75){
//Move Right
p_temp[a] = p_position[a];
p_position[a].x++;
if (r_bounds[a].contains(p_position[a])){
p_limb[a].x++;
} else {
p_position[a] = p_temp[a];
p_position[a].x--;
}
}
}
drawImages();
sleep(100);
} while (y_energy > 1 && h_energy > 1);
//End bit
endBit();
}
private void endBit(){
right_punch=false;
left_punch=false;
ac_gong.play();
if (h_energy < y_energy){
//You win
placeItems();
gameStage = 2;
//Draw victory
p_limb[3].y=r_a_bounds.height-(i_left.getHeight(this)/2);
p_limb[4].y=r_a_bounds.height-(i_right.getHeight(this)/2);
p_limb[3].x=p_limb[3].x+10;
p_limb[4].x=p_limb[4].x+10;
for (int a=0;p_limb[4].y<r_a_bounds.height;a++){
drawImages();
p_limb[3].y=p_limb[3].y-2;
p_limb[4].y=p_limb[4].y+2;
sleep(20);
}
sleep(200);
// p_limb[4].y=r_a_bounds.height;
for (int a=0;p_limb[4].y>r_a_bounds.height-i_right.getHeight(this);a++){
drawImages();
p_limb[3].y=p_limb[3].y+2;
p_limb[4].y=p_limb[4].y-2;
p_limb[3].x=p_limb[3].x-2;
p_limb[4].x=p_limb[4].x-2;
sleep(20);
}
ac_swing.play();
right_punch=true;
drawImages();
sleep(100);
ac_hit.play();
placeItems();
for (int b=0;b<100;b++){
drawImages();
p_limb[2].y=p_limb[2].y-2;
}
for (int a=15;a>0;a--){
p_limb[3].x=p_limb[0].x-a;
p_limb[4].x=p_limb[1].x+a;
drawImages();
sleep(50);
p_limb[3].x=p_limb[0].x+a;
p_limb[4].x=p_limb[1].x-a;
drawImages();
sleep(50);
}
gameStage = 4;
} else {
//You lose
gameStage = 5;
placeItems();
p_limb[3].x=r_a_bounds.x-100;
p_limb[4].x=r_a_bounds.x-100;
ac_lose.play();
for (int a=15;a>0;a--){
p_limb[0].x=p_limb[0].x-a;
p_limb[1].x=p_limb[1].x+a;
drawImages();
sleep(50);
p_limb[0].x=p_limb[0].x+a;
p_limb[1].x=p_limb[1].x-a;
drawImages();
sleep(50);
}
}
}
public void update(Graphics g){
paint(g);
}
public void paint (Graphics g){
g.drawImage(buffer,0,0,this);
g.drawImage(buffer_information,0,buffer.getHeight(this),this);
g.drawImage(buffer_stats,0,buffer.getHeight(this)+buffer_information.getHeight(this),this);
}
private void clearImages(){
offpic.fillRect(0,0,buffer.getWidth(this),buffer.getHeight(this));
offpic_stats.fillRect(0,0,buffer_stats.getWidth(this),buffer.getHeight(this));
// offpic_information.fillRect(0,0,buffer_information.getWidth(this),buffer.getHeight(this));
}
private synchronized void drawImages(){
//Draw the enemy at relevant limb position
// offpic.setColor(Color.red);
offpic.fillRect(0,0,r_a_bounds.width,240);
// offpic.setColor(Color.black);
offpic.drawImage(i_h_body,p_limb[5].x-h_body_off,p_limb[5].y,this);
offpic.drawImage(i_h_head[faceStage], p_limb[2].x-h_head_off,p_limb[2].y,this);
offpic.drawImage(i_h_left,p_limb[0].x-h_left_off,p_limb[0].y,this);
offpic.drawImage(i_h_right,p_limb[1].x-h_right_off,p_limb[1].y,this);
if(gameStage == 0){
//Start Match button ith click here
offpic_stats.setColor(Color.green);
offpic_stats.fillRoundRect(buffer_stats.getWidth(this)/3,(buffer_stats.getHeight(this)/3)-5,buffer_stats.getWidth(this)/3,15,5,5);
offpic_stats.setColor(Color.black);
offpic_stats.drawString("Start Match",(buffer_stats.getWidth(this)/3)+30,(buffer_stats.getHeight(this)/3)+7);
} else if (gameStage == 1){
//Draw stats with you me and power bars from energy
offpic_stats.setColor(Color.white);
offpic_stats.drawString("Bin Laden",70,24);
offpic_stats.drawString("You",70,44);
offpic_stats.setColor(Color.black);
offpic_stats.fillRect(120,15,250,40);
offpic_stats.setColor(Color.green);
offpic_stats.fillRoundRect(120,15,h_energy,10,2,2);
offpic_stats.fillRoundRect(120,35,y_energy,10,2,2);
drawMe();
} else if (gameStage == 2) {
drawPlayAgain();
offpic_stats.drawImage(i_win,(buffer_stats.getWidth(this)/2)-(i_win.getWidth(this)/2),15,this);
gameStage=3;
} else if (gameStage == 3){
drawMe();
} else if (gameStage == 5){
drawPlayAgain();
offpic_stats.drawImage(i_lose,(buffer_stats.getWidth(this)/2)-(i_lose.getWidth(this)/2),15,this);
gameStage = 6;
}
repaint();
}
private void drawPlayAgain(){
offpic_stats.setColor(Color.black);
offpic_stats.fillRect(0,0,buffer_stats.getWidth(this),buffer_stats.getHeight(this));
offpic_stats.setColor(Color.green);
offpic_stats.fillRoundRect(10,10,60,20,5,5);
offpic_stats.fillRoundRect(10,35,60,20,5,5);
offpic_stats.setColor(Color.black);
offpic_stats.drawString("Play Again",14,24);
offpic_stats.drawString("Author",25,50);
}
private void drawMe(){
//Draw own left hand, as punch or held
if (left_punch&&(frameLeftCount<frameMax)) {
offpic.drawImage(i_left_h,p_limb[3].x-m_left_h_off,r_a_bounds.height-i_left_h.getHeight(this),this);
frameLeftCount++;
} else {
offpic.drawImage(i_left,p_limb[3].x-m_left_off,p_limb[3].y,this);
left_punch = false;
frameLeftCount = 0;
}
//Draw own right hand, as punch or held
if (right_punch&&(frameRightCount<frameMax)) {
offpic.drawImage(i_right_h,p_limb[4].x-m_right_h_off,r_a_bounds.height-i_right_h.getHeight(this),this);
frameRightCount++;
} else {
offpic.drawImage(i_right,p_limb[4].x-m_right_off,p_limb[4].y,this);
right_punch = false;
frameRightCount = 0;
}
//Draw Enemy punch if required
if (y_l_punch||System.currentTimeMillis()-l_stamp[1]<mill_fistMin){
l_stamp[1] = System.currentTimeMillis();
offpic.drawImage(i_fist_b,r_a_bounds.width/2-i_fist_b.getWidth(this)/2,r_a_bounds.height-i_fist_b.getHeight(this),this);
if (y_l_punch) ac_hit.play();
y_l_punch = false;
}
if (y_r_punch||System.currentTimeMillis()-l_stamp[2]<mill_fistMin){
l_stamp[2] = System.currentTimeMillis();
offpic.drawImage(i_fist_a,r_a_bounds.width/2-i_fist_a.getWidth(this)/2,r_a_bounds.height-i_fist_a.getHeight(this),this);
if (y_r_punch) ac_hit.play();
y_r_punch = false;
}
}
}