SubKorea > CYBER JAVA GAME > º®µ¹±ú±â2 (Javanoid v1.45) > ¼Ò½º #6 |
// ## JAVANOID BULLET CLASS ################################
// This class represents the paddle
bullets : They are very similar to
// pills except they move from
bottom to top and hit the blocks.
final static int defaultSpeed = 6;
final static int defaultWidth = 4;
final static int defaultHeight = 6;
jnsoundserver soundSrv;
jnlevel level;
//
Constructor
public jnbullet(jnimageserver i,
jnsoundserver s, jngame c, int px, int py, jnlevel l) {
super(c, i.bulletImage(0), defaultWidth,
defaultHeight, px, py, 0, - defaultSpeed);
soundSrv = s; level = l;
}
// À§·Î
public void live() {
super.live();
if ((dY > 0) || (level.hitBlock(X + width
/ 2, Y, false))) { die(); }
}
}
// À§·Î
// ## JAVANOID PADDLE CLASS ####################################
// This class represents the paddle
in the game : It a 'static' object
// that can be moved to a position
(ex : mouse position). It gives the
// direction of the ball it hits,
and has different aspects and attitudes
// (small, large, firing)
final static int defaultWidth
= 40; // default
attributes
final static int defaultWidthBig = 48;
final static int defaultWidthSmall = 32;
final static int defaultHeight = 12;
final static int defaultImage = 0;
protected int minX, maxX;
protected int newX;
// Mouse position save
protected boolean demo;
jnsoundserver soundSrv;
jnimageserver imageSrv;
//
Constructor
public jnpaddle (jnimageserver i,
jnsoundserver s, jngame c, int alt, boolean d) {
super(c, i.paddleImage(0), defaultWidth,
defaultHeight, (c.getWidth() - defaultWidth) / 2,
c.getHeight() - alt);
imageSrv = i; soundSrv = s;
minX = 0; maxX = c.getWidth() - defaultWidth;
newX = X;
demo = d;
}
// À§·Î
// Paddle life (move to the
saved position)
public void live() {
setX(newX); super.live(); }
// Paddle settings
public int hit(int bx, int bdx,
int s) {
int ndx = 2 * s * (bx - X - width / 2)
/ width;
soundSrv.playTouch();
return (ndx==0) ? bdx : ndx;
}
// À§·Î
// methods of controls
public void followBall (int bx)
{ newX = bx - width / 2; }
public void followMouse (int mx)
{ newX = mx - width / 2; }
public void followArrows (int dx)
{ newX = newX + dx; }
// À§·Î
// paddle settings
public void setNormal() {
change(imageSrv.paddleImage(0), defaultWidth, defaultHeight); }
public void setSmall () {
change(imageSrv.paddleImage(1), defaultWidthSmall, defaultHeight); }
public void setBig () {
change(imageSrv.paddleImage(2), defaultWidthBig, defaultHeight); }
public void setFire () {
change(imageSrv.paddleImage(3), defaultWidth, defaultHeight); }
}
// À§·Î
// ## JAVANOID BLOCK CLASS #####################################
// Blocks are basic 'static object',
except they die after a certain
// number of hits. As they don't
move at all, they are drawn or erased on
// the third buffer
final static int defaultWidth = 32;
final static int defaultHeight = 20;
final static int defaultImage = 0;
//
i.e. nb hits before it dies
protected int resistance;
// position in the level
protected int column, row;
jnsoundserver soundSrv;
jnimageserver imageSrv;
// Constructor
public jnblock (jnimageserver i,
jnsoundserver s, jngame c, int color, int col, int row) {
super(c, i.blockImage(color), defaultWidth,
defaultHeight, col * defaultWidth, row * defaultHeight);
imageSrv = i; soundSrv = s;
if (color==11) { resistance = -1; }
// The resistance is linked
to the color
else if (color==10) { resistance = 2;
}
else { resistance = 0; }
}
// À§·Î
// Life : no drawing there
!!!
public void live() {
}
// Blocks are "permanent"
images --> draw on the background & erase
public void draw() {
buffer.drawPermanentImage(image, X, Y); }
// À§·Î
public void clear() {
buffer.clearPermanentImage(X, Y, width, height); }
// death depends on resistance
public void die() {
if (resistance==0) { clear(); super.die();
}
else { resistance--;}
}
// À§·Î
//
hit method (tells if it dies or not)
public boolean hit() {
die();
if (alive) { soundSrv.playTouch(); } else
{ soundSrv.playHit(); }
return alive ? false : true;
}
// À§·Î
// kill method (dies &
tells if it's a gold one)
public boolean kill() {
clear();
super.die();
return (resistance >= 0);
}
}
// À§·Î