Total members 11895 |It is currently Sat Dec 21, 2024 6:24 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka






Project Name:ping pong game Sticker ball
 Programmer:   msi_333 & Casper
 Type:   Game
 Technology:  Java
IDE: NetBeans
 Description:   This is modified version for the original games,its not applet, its a stand alone application, i added some features like cheering sound at the start of the game, beside the other described features in this topic:
Code:
http://www.codemiles.com/viewtopic.php?f=130&t=625

java code
package stickerball_game;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;


public class Ball {

/** Creates a new instance of Ball */
private Sound mysound;
private int Reduis;
public int x;
public int y;
public int vx;
public int vy;
private int BALL_TOP;
private int BALL_LEFT;
private int BALL_RIGHT;
private int BALL_DOWN;

private int PLAYER_TOP;
private int PLAYER_DOWN;
private int PLAYER_RIGHT;

private int COMP_TOP;
private int COMP_DOWN;
private int COMP_LEFT;

private int max_vx=5;
private int max_vy=5;

public Component myBase;
private Color BallColor;

private Image myImg;
public Ball(int r, int x,int y,int vx,int vy,Color BallColor,Component newBase) {

Reduis=r;
this.x=x;
this.y=y;
this.vx=vx;
this.vy=vy;
myBase=newBase;
myImg=new ImageIcon("images/Ball.gif").getImage();
this.BallColor=BallColor;
}

public void move() {

if (vx > max_vx) vx = max_vx;
else if (vx < -max_vx) vx = -max_vx;
else if (vy > max_vy) vy = max_vy;
else if (vy < -max_vy) vy = -max_vy;
// else if (vx == 0 && !isStoped) vx = 1;

x += vx;
y += vy;
}
public int wheresBall() {
if (vy > 0) {
if (y > 280) {
vy = -vy;
return 0;
}
} else if (vy < 0) {
if (y < 40) {
vy = -vy;
return 0;
}
}
if(x<20)
return 1;
else if(x>375)
return 2;



return 0;

}
public void PCollision(Player PlayerStick) {

BALL_TOP = y - Reduis;
BALL_DOWN = y + Reduis;
BALL_LEFT = x - Reduis;
BALL_RIGHT = x + Reduis;


PLAYER_TOP = PlayerStick.y;
PLAYER_DOWN = PlayerStick.y + PlayerStick.sizey;


if ((BALL_TOP >= PLAYER_TOP - 10) && (BALL_DOWN <= PLAYER_DOWN + 10)) {

if (BALL_LEFT <= 30 ) {

mysound = new Sound("Sound/hit.wav");


vx = - vx;


if (PlayerStick.vy < 0) {
vy --;

} else if (PlayerStick.vy > 0) {
vy += PlayerStick.vy;

}
}
}
}

public void CCollision(Computer CompStick) {

BALL_TOP = y - Reduis;
BALL_DOWN = y + Reduis;
BALL_LEFT = x - Reduis;
BALL_RIGHT = x + Reduis;


COMP_TOP = CompStick.y;
COMP_DOWN= CompStick.y + CompStick.sizey;


if ((BALL_TOP >= COMP_TOP - 10) && (BALL_DOWN <= COMP_DOWN + 10)) {

if (BALL_RIGHT >= 370 ) {

mysound = new Sound("Sound/hit.wav");


vx = - vx;



if (CompStick.vy < 0) {
vy --;
} else if (CompStick.vy > 0) {
vy += CompStick.vy;
}

}
}
}
public void DrawBall(Graphics g) {
g.setColor(BallColor);

g.drawImage(myImg,x - Reduis, y - Reduis,myBase);

}

}

java code
package stickerball_game;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;


public class Sound {

AudioFormat audioFormat;
AudioInputStream audioInputStream;
SourceDataLine sourceDataLine;
String X;

//end main
/** Creates a new instance of Sound */
public Sound(String Wavname) {
new PlayThread().start();
X=Wavname;
}
class PlayThread extends Thread{
byte tempBuffer[] = new byte[10000];

public void run(){
File soundFile =new File(X);

try {
audioInputStream = AudioSystem.
getAudioInputStream(soundFile);
audioFormat = audioInputStream.getFormat();


DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class,audioFormat);

sourceDataLine =(SourceDataLine)AudioSystem.getLine(dataLineInfo);
sourceDataLine.open(audioFormat);
} catch (LineUnavailableException ex) {
ex.printStackTrace();
} catch (UnsupportedAudioFileException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
sourceDataLine.start();
try{
int cnt;
while((cnt = audioInputStream.read(
tempBuffer,0,tempBuffer.length)) != -1) {
if(cnt > 0){
sourceDataLine.write(tempBuffer, 0, cnt);
}
}
sourceDataLine.flush();
sourceDataLine.close();
Thread.sleep(2000);
}catch (Exception e) {
e.printStackTrace();
System.exit(0);
}

}

}//end inner class PlayThread
//======================//

}//end outer class AudioPlayer02.java





Attachments:
StickerBall_Game.rar [331 KiB]
Downloaded 2240 times

_________________
Please recommend my post if you found it helpful. ,
java,j2ee,ccna ,ccnp certified .
Author:
Expert
User avatar Posts: 838
Have thanks: 2 time

updated.


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : ping pong game - java-Sticker-ball game (modified v1.1)
 ping pong java code-Sticker-ball game     -  
 Ball Color Match 2D Java Game Version 1.0     -  
 fill all Squares of game board - 2d Java Game Example     -  
 Bouncing Coloring Ball Game(V1.0)     -  
 Applet Game To Shot a Random Ball     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 Sticker Ball     -  
 Ball Sticker{Applet}     -  
 Ball sticker applet     -  
 Chess Game in Java     -  



Topic Tags

Java Projects
cron






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com