PlaneMambo GTGE part-2 Action Object Plane

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package PlaneMambo.game;

import com.golden.gamedev.Game;
import com.golden.gamedev.object.AnimatedSprite;
import com.golden.gamedev.object.Background;
import com.golden.gamedev.object.Sprite;
import com.golden.gamedev.object.SpriteGroup;
import com.golden.gamedev.object.background.ColorBackground;
import com.golden.gamedev.object.sprite.AdvanceSprite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.Timer;

/**
 *
 * @author me
 */
public class MamboGame extends Game {

    //background
    public Background ground;
    
    
    //grouping pemain
    private SpriteGroup Lakon; //untuk pemain



    //Gambar insteance of
    public AdvanceSprite pesawat,kapal;
    public AnimatedSprite fireleft,fireleft2,fireright,fireright2
                          ,fireup,fireup2,firedown,firedown2
                          ,jetFl,jetFl_2,jetF2,jetF2_2,jetF3,jetF3_2,jetF4,jetF4_2;



    //direction name
    public static final int left =0,
                            right=1,
                            up=2,
                            down=3;


    //constructor
    public MamboGame(){
        //background image
    }

    @Override
    public void initResources() {
        ground = new ColorBackground(Color.BLUE);
        //lokasi gambar
        BufferedImage[] images = getImages("../image/kekuatan_1.png",17, 1);
        BufferedImage[] fire = getImages("../image/bomb1.png",3,1);
        BufferedImage[] fire2 = getImages("../image/bomb2.png",1,3);
        BufferedImage[] jetflash = getImages("../image/JetHoriz.png",4,1, 0, 1);
        BufferedImage[] jetflash2 = getImages("../image/JetHoriz.png",4,1, 2, 3);
        BufferedImage[] jetflas = getImages("../image/flashjet.png",1,2,0,1);
        BufferedImage[] jetflas2 = getImages("../image/flashjet2.png",1,2,0,1);
        BufferedImage[] imgkapal = getImages("../image/kapal.png",2,1);
        
        //pemain
        pesawat = new AdvanceSprite(images, 275, 250);
        kapal = new AdvanceSprite(imgkapal,150,0);
        fireleft = new AnimatedSprite(fire, -150, -150);
        fireleft2 = new AnimatedSprite(fire,-150,-150);
        fireright = new AnimatedSprite(fire,-150,-150);
        fireright2 = new AnimatedSprite(fire, -150,-150);
        fireup = new AnimatedSprite(fire2, -150,-150);
        fireup2 = new AnimatedSprite(fire2, -150,-150);
        firedown = new AnimatedSprite(fire2,-150,-150);
        firedown2 = new AnimatedSprite(fire2,-150,-150);
        jetFl = new AnimatedSprite(jetflash,-150,-150);
        jetFl_2 = new AnimatedSprite(jetflash,-150,-150);
        jetF2 = new AnimatedSprite(jetflash2,-150,-150);
        jetF2_2 = new AnimatedSprite(jetflash2,-150,-150);
        jetF3 = new AnimatedSprite(jetflas,-150,-150);
        jetF3_2 = new AnimatedSprite(jetflas,-150,-150);
        jetF4 = new AnimatedSprite(jetflas2,-150,-150);
        jetF4_2 = new AnimatedSprite(jetflas2,-150,-150);
        //memasang pesawat diatas background
        pesawat.setBackground(ground);
        
    }

    @Override
    public void update(long elapsedTime) {
        //inisialisasi update sprite
        pesawat.update(elapsedTime);
        kapal.update(elapsedTime);
        fireleft.update(elapsedTime);fireleft2.update(elapsedTime);
        fireright.update(elapsedTime);fireright2.update(elapsedTime);
        fireup.update(elapsedTime);fireup2.update(elapsedTime);
        firedown.update(elapsedTime);firedown2.update(elapsedTime);
        jetFl.update(elapsedTime);jetFl_2.update(elapsedTime);
        jetF2.update(elapsedTime);jetF2_2.update(elapsedTime);
        jetF3.update(elapsedTime);jetF3_2.update(elapsedTime);
        jetF4.update(elapsedTime);jetF4_2.update(elapsedTime);

        //controlling
        if(keyDown(KeyEvent.VK_LEFT)) {
            pesawat.moveX(-0.1*elapsedTime);
            pesawat.setAnimationFrame(4,1);
            jetFl.setLocation(pesawat.getX()+55, pesawat.getY()+10);
            jetFl.setAnimate(true);
            jetFl.setLoopAnim(true);
            jetFl_2.setLocation(pesawat.getX()+55, pesawat.getY()+40);
            jetFl_2.setAnimate(true);
            jetFl_2.setLoopAnim(true);
        }else if(keyDown(KeyEvent.VK_RIGHT)){
            pesawat.moveX(0.1*elapsedTime);
            pesawat.setAnimationFrame(12,1);
            jetF2.setLocation(pesawat.getX()-30, pesawat.getY()+10);
            jetF2.setAnimate(true);
            jetF2.setLoopAnim(true);
            jetF2_2.setLocation(pesawat.getX()-30, pesawat.getY()+40);
            jetF2_2.setAnimate(true);
            jetF2_2.setLoopAnim(true);
        }else if(keyDown(KeyEvent.VK_UP)){
            pesawat.moveY(-0.1*elapsedTime);
            pesawat.setAnimationFrame(8,1);
            jetF3.setLocation(pesawat.getX()+10, pesawat.getY()+55);
            jetF3.setAnimate(true);
            jetF3.setLoopAnim(true);
            jetF3_2.setLocation(pesawat.getX()+43, pesawat.getY()+55);
            jetF3_2.setAnimate(true);
            jetF3_2.setLoopAnim(true);
        }else if(keyDown(KeyEvent.VK_DOWN)){
            pesawat.moveY(0.1*elapsedTime);
            pesawat.setAnimationFrame(16,1);
            jetF4.setLocation(pesawat.getX()+10, pesawat.getY()-30);
            jetF4.setAnimate(true);
            jetF4.setLoopAnim(true);
            jetF4_2.setLocation(pesawat.getX()+43, pesawat.getY()-30);
            jetF4_2.setAnimate(true);
            jetF4_2.setLoopAnim(true);
        }

        //TEMBAKAN Fire Bolt
        if(keyDown(KeyEvent.VK_LEFT) && keyDown(KeyEvent.VK_CONTROL)) {
            fireleft.setLocation(pesawat.getX(),pesawat.getY());    
            fireleft2.setLocation(pesawat.getX(),pesawat.getY()+35);
            fireleft2.setAnimate(true);
            fireleft.setAnimate(true);
            fireleft.setLoopAnim(true);fireleft2.setLoopAnim(true);
            fireleft.setHorizontalSpeed(-1);
            fireleft2.setHorizontalSpeed(-1);   
        }else if(keyDown(KeyEvent.VK_RIGHT) && keyDown(KeyEvent.VK_CONTROL)){
            fireright.setLocation(pesawat.getX()+40, pesawat.getY());
            fireright.setAnimate(true);
            fireright.setLoopAnim(true);
            fireright.setHorizontalSpeed(1);    
            fireright2.setLocation(pesawat.getX()+40, pesawat.getY()+35);
            fireright2.setAnimate(true);
            fireright2.setLoopAnim(true);
            fireright2.setHorizontalSpeed(1);
        }else if(keyDown(KeyEvent.VK_UP)&& keyDown(KeyEvent.VK_CONTROL)){
            fireup.setLocation(pesawat.getX(), pesawat.getY()-10);
            fireup.setAnimate(true);
            fireup.setLoopAnim(true);
            fireup.setVerticalSpeed(-1);
            fireup2.setLocation(pesawat.getX()+40, pesawat.getY()-10);
            fireup2.setAnimate(true);
            fireup2.setLoopAnim(true);
            fireup2.setVerticalSpeed(-1);
        }else if(keyDown(KeyEvent.VK_DOWN) && keyDown(KeyEvent.VK_CONTROL)){
            firedown.setLocation(pesawat.getX(),pesawat.getY()+40);
            firedown.setAnimate(true);
            firedown.setLoopAnim(true);
            firedown.setVerticalSpeed(1);
            firedown2.setLocation(pesawat.getX()+35, pesawat.getY()+40);
            firedown2.setAnimate(true);
            firedown2.setLoopAnim(true);
            firedown2.setVerticalSpeed(1);
        }

        //MUSUH
        for(int i=0;i<10;i++){
            kapal.setAnimate(true);
            kapal.setLoopAnim(true);
            kapal.setVerticalSpeed(0.1);
        }
    }

    @Override
    public void render(Graphics2D g) {
        g.setBackground(Color.BLACK);
        ground.render(g);
        pesawat.render(g);
        kapal.render(g);
        fireleft.render(g);fireleft2.render(g);
        fireright.render(g);fireright2.render(g);
        fireup.render(g);fireup2.render(g);
        firedown.render(g);firedown2.render(g);

        //efek dari jet
        if(keyDown(KeyEvent.VK_LEFT)){
            jetFl.render(g);
            jetFl_2.render(g);
        }else if(keyDown(KeyEvent.VK_RIGHT)){
            jetF2.render(g);
            jetF2_2.render(g);
        }else if(keyDown(KeyEvent.VK_DOWN)){
            jetF4.render(g);
            jetF4_2.render(g);
        }else if(keyDown(KeyEvent.VK_UP)){
            jetF3.render(g);
            jetF3_2.render(g);
        }
    }

    public void kapalFunction(){      
    }
}

Fungsi panggil sama seperti PlaneMambo GTGE part-1 karena belum ada menu game…silahkan tunggu artikel selanjutnya jika sempat..:p
Hasilnya :

pada gambar diatas sprite plane sudah mengeluarkan jet dan tembakan jika kita mengklik control….lanjutan ada pada artikel selanjutnya jika sempat..

2 thoughts on “PlaneMambo GTGE part-2 Action Object Plane

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