example make the effect the distance between the shooting and plane

as an explanation about what I mean can be seen in the picture below

ok after you look the picture I hope you(reader) understand what i mean…:D

//this example code may be similar to code in c + + or C # because I have not tried maybe later after I download visual studio .. .. hiihi

try this code:

import com.golden.gamedev.Game;
import com.golden.gamedev.GameLoader;
import com.golden.gamedev.object.*;
import com.golden.gamedev.object.background.*;
import com.golden.gamedev.object.collision.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import com.golden.gamedev.object.sprite.AdvanceSprite;
import com.golden.gamedev.object.sprite.VolatileSprite;
import java.awt.event.MouseEvent;
/**
 *
 * @author me
 */
public class MoveOverMouse1 extends Game{

    // - game arena
    PlayField 	playfield;
    // - background
    Background	background;
    // - Sprite Group
    public SpriteGroup Fighter,MISSILE,ILLUSION;


    AdvanceSprite    sprite;
    GameFont          font;
    boolean mouse = false;
    private BufferedImage firing,pesawat,illusion;
    public Sprite shoot,shoot2,pesawat2,illusion2,iillusion;

    Timer refireRate = new Timer(300);
    private boolean CanFire = true;

    @Override
    public void initResources() {

        pesawat      = getImage("../../image/plane1.png");
        pesawat2     = new Sprite(pesawat, 275, 250);
        illusion     = getImage("../../image/Ilusion.png");
        illusion2    = new Sprite(illusion,275,250);
        iillusion    = new Sprite(illusion,275,250);
        playfield 	= new PlayField();
            // - background image
        BufferedImage img = getImage("../../image/backed.jpg", false);
            background = new ParallaxBackground(new Background[] {
            new ImageBackground(img)
            });
        //background = new ColorBackground(Color.BLUE, 800, 600);

        playfield = new PlayField(background);
        Fighter = playfield.addGroup(new SpriteGroup("jet"));
        MISSILE = playfield.addGroup(new SpriteGroup("Missile"));
        ILLUSION = playfield.addGroup(new SpriteGroup("tembok"));
        Fighter.add(pesawat2);
        ILLUSION.add(illusion2);
        ILLUSION.add(iillusion);
        font = fontManager.getFont(getImages("../../image/font.png", 20, 3),
                                   " !            .,0123" +
                                   "456789:   -? ABCDEFG" +
                                   "HIJKLMNOPQRSTUVWXYZ ");

        playfield.addCollisionGroup(MISSILE, ILLUSION, new MissileIllusion());
        
        hideCursor();
    }

    @Override
    public void update(long elapsedTime) {
        playfield.update(elapsedTime);

        background.move(0.1* elapsedTime, 0);

        int tileX = (int) (getMouseX() + background.getX());
        int tileY = (int) (getMouseY() + background.getY());
       
        pesawat2.setLocation(tileX-20, tileY-20);
        illusion2.setLocation(tileX+200, tileY-500);
        iillusion.setLocation(tileX-200, tileY-500);
        BufferedImage im = getImage("../../image/missle.png");
        shoot = new Sprite(im, tileX+30, tileY+10);
        shoot2 = new Sprite(im,tileX+30, tileY+20);

        if (CanFire == false) {
		CanFire = refireRate.action(elapsedTime);
	}

        if(bsInput.isMouseDown(MouseEvent.BUTTON1) && CanFire){
            shoot.setHorizontalSpeed(0.7);
            MISSILE.add(shoot);
            shoot2.setHorizontalSpeed(0.7);
            MISSILE.add(shoot2);          
            CanFire = false;
	    refireRate.refresh();

        }
        
        if (keyPressed(KeyEvent.VK_ESCAPE)) {
            finish();
        }

    }

    @Override
    public void render(Graphics2D g) {
        playfield.render(g);
          int tileX = (int) (getMouseX() / 24);
	  int tileY = (int) (getMouseY() / 24);
          font.drawString(g, "ORDINAT: "+tileX+", "+tileY,tileX*24-25, (tileY*24)-30);
          //pesawat2.render(g);
          
 
    }    // - Explosion Effect
    public void addExplosionEffect(double centerX, double centerY) {
	    BufferedImage[] image = getImages("../../image/Explosion.png", 5, 3);
            double x = centerX - (image[0].getWidth()/2),y = centerY - (image[0].getHeight()/2);
            VolatileSprite explosion = new VolatileSprite(image, x, y);
            explosion.getAnimationTimer().setDelay(50);
            playfield.add(explosion);
	}
    // - Collision Illusion Tile
    class MissileIllusion extends BasicCollisionGroup{

        @Override
        public void collided(Sprite s1, Sprite s2) {
            s1.setActive(false);
            int tileX = (int) (getMouseX() + background.getX());
            int tileY = (int) (getMouseY() + background.getY());
            addExplosionEffect(tileX+200, tileY);
            addExplosionEffect(tileX+200, tileY+30);
        }
    }


    public static void main(String[] args) {
        GameLoader game = new GameLoader();
        game.setup(new MoveOverMouse1(), new Dimension(640,480), true);
        game.start();
    }
}

result:

yeah, i LIke game…:D
Thank’s for reading..:D

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s