my first Game project with GTGE java Framework…:D

tuing…tuing….mau cuap-cuap tentang pembuatan game dengan menggunakan GTGE Framework…Tw gak ne GTGE itu apa???GTGE itu framework untuk buat game java bikinan orang indo…loe. untuk keterangan lebih lengkap silahkan kunjungi http://goldenstudios.or.id/
Dengan mengunakan GTGE kita dapat membuat game 2D dengan sangat mudah karena semua lib yang kita perlukan untuk membuat game sudah tersedia…memang banyak framework-framework lain tapi menurut ane framework yang paling mudah untuk dipelajari ya GTGE. daripada mengunakan JMonkey. untuk pilihan framework sendiri itu tergantung ma yang gunain juga cie…ada yang enjoy pake framework a ada juga yang enjoy pake framework b…up to you..:D

nah ini sepotong code GTGE pada gambar game diatas…

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

package com.golden.ship2war;

import com.golden.gamedev.GameObject;
import com.golden.gamedev.object.AdvanceSpriteGroup;
import com.golden.gamedev.object.AnimatedSprite;
import com.golden.gamedev.object.Background;
import com.golden.gamedev.object.GameFont;
import com.golden.gamedev.object.PlayField;
import com.golden.gamedev.object.Sprite;
import com.golden.gamedev.object.SpriteGroup;
import com.golden.gamedev.object.Timer;
import com.golden.gamedev.object.background.ImageBackground;
import com.golden.gamedev.object.collision.AdvanceCollisionGroup;
import com.golden.gamedev.object.collision.BasicCollisionGroup;
import com.golden.gamedev.object.collision.CollisionGroup;
import com.golden.gamedev.object.collision.CollisionShape;
import com.golden.gamedev.object.collision.PreciseCollisionGroup;
import com.golden.gamedev.object.sprite.PatternSprite;
import com.golden.gamedev.object.sprite.VolatileSprite;
import com.golden.gamedev.util.FileUtil;
import com.golden.gamedev.util.ImageUtil;
import com.golden.ship2war.logic.*;
//import com.golden.ship2war.logic.LogicAttackFollow;
//import com.golden.ship2war.logic.LogicAttackFollow;
import com.golden.ship2war.menu.HighScore;
import java.awt.Graphics2D;
import java.awt.Transparency;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.StringTokenizer;

public class ship2war extends GameObject{

    public PlayField playfield;
    public Background background;

    public static final int CROSS_TILE = 1;

    SpriteGroup SHIP,TILE,GOAL,PATTERN,PROJECTILE,TILE2,WATERROLLING,ENEMY_GROUP,ENEMY_GROUP2,BONUS,PATTERN_BONUS,BONUS2,BONUS3;

    public static final int intro = 1; //show level description
    public static final int playing =2; //mulai bermain
    public static final int going_next_level=3; //pergi ke next level
    public static final int gameover=4; //kalah
    public static final int winner=5; //menang
    public static final int showtitle=6; //menampilkan title.


    public static final int musuh = 100;
    private int gamestatus;        
    Sprite Musuh;  
    public int level;
    Timer	levelTimer;			
    Sprite    levelImage;
    /*   variable font */
    public GameFont titlefont;
    private ship2wargame game;

     //enemy life
    private int lifemusuh;
    private int lifemusuh2;
    private int lifekapal;
     //timer
    public GameFont font;
    private int time = 100;
    private Timer	timerTime	= new Timer(1000);
    private String loseTitle;
    private int life;
    private int score;

    public Enemy31 enemy1;
    private boolean Exit;

    private BufferedImage[] player_image;

    public shipSprite player;
    public shipSprite player2;
    private Sprite bonusutama;
    private BufferedImage[] bombom;
    private BufferedImage[] cheese;
    private BufferedImage[] nyowo;
    private boolean nyowone;
    private BufferedImage[] special;

    public boolean win;
    BasicCollisionGroup cheesewithplayer;

     public ship2war (ship2wargame parent){
        super(parent);
        game = parent;
     }
//    // @Override
//        protected void initEngine() {
//        //super.initEngine();
//        bsSound.setBaseRenderer(new JavaLayerMp3Renderer());
//        bsMusic.setBaseRenderer(new JavaLayerMp3Renderer());
//
//    }
    
    @Override
    public void initResources() {
        //playMusic("sound/difficulties.mp3");
        titlefont = fontManager.getFont(getImage("image/BitmapFont.png"));
        font = fontManager.getFont(getImages("image/output/Font.png", 8, 12));
        player_image = getImages("image/player_walk.png",8,1);
        cheese = getImages("image/Date & Regional Settings 2.png",1,1);
        nyowo = getImages("image/Favorites.png",1,1);
        special = getImages("image/Favourites.png",1,1);
	levelTimer = new Timer(2500);
	levelImage = new Sprite();
	levelImage.setHorizontalSpeed(1.25);
        level = 1;
        initLevel();
        life = 3;
        score = 0;
        lifekapal = 3;
        win = false;
        nyowone = false;
    }
    private void initLevel() {   
        gamestatus = intro;
        player = new shipSprite(this, player_image, time, time);
        player2 = new shipSprite(this, player_image, time, time);
    //memulai initialisasi terhadap file level
        String levelFile = "level/Level" + level + ".txt";
	String[] content = FileUtil.fileRead(bsIO.getStream(levelFile));

        //membaca file dari intro
        StringTokenizer token = new StringTokenizer(content[0], "+");
        String desc[] = new String[token.countTokens()];
            for (int i=0;i<desc.length;i++){
                desc[i] = token.nextToken();
            }
        //membuat file description
        BufferedImage tem = getImage("image/dialog.png");
        BufferedImage image = ImageUtil.createImage(tem.getWidth()+300,tem.getHeight(),Transparency.BITMASK);

        Graphics2D g =  image.createGraphics();
            //draw panel
        g.drawImage(tem, 50, 0, null);
            //draw title level title
        titlefont.drawString(g, "LEVEL " + level , GameFont.CENTER, 80,30,tem.getWidth());
        titlefont.drawString(g, "------" , GameFont.CENTER, 80,47,tem.getWidth());
            //mengambar description dari map
        for (int i=0;i<desc.length;i++){
                titlefont.drawString(g, desc[i], GameFont.CENTER, 80,70+(i*20),tem.getWidth());
            }
        g.dispose();

        levelImage.setImage(image);
        levelImage.setLocation(-image.getWidth(), 150);
        levelTimer.setActive(true);

	token = new StringTokenizer(content[1], " x ");
	int w = Integer.parseInt(token.nextToken()), 	
            h = Integer.parseInt(token.nextToken());	
        playfield 	= new PlayField();
	background = new ImageBackground(getImage("image/backgrounddalem.jpg"), 1024, 768);
      
	playfield.setBackground(background);
        TILE  	= playfield.addGroup(new AdvanceSpriteGroup("Tile", 768));
        TILE2 = playfield.addGroup(new AdvanceSpriteGroup("Tile2", 768));
	GOAL	= playfield.addGroup(new SpriteGroup("Objective Goal"));
	PATTERN = playfield.addGroup(new SpriteGroup("Pattern"));
        PATTERN_BONUS = playfield.addGroup(new SpriteGroup("war"));
        ENEMY_GROUP = playfield.addGroup(new SpriteGroup("enemy"));
        ENEMY_GROUP2 = playfield.addGroup(new SpriteGroup("enemy"));
        SHIP 	= playfield.addGroup(new SpriteGroup("SHIP"));
        WATERROLLING = playfield.addGroup(new SpriteGroup("rollingwater"));
     
        PROJECTILE 	= playfield.addGroup(new SpriteGroup("Projectile"));
        BONUS = playfield.addGroup(new SpriteGroup("bonus"));
        BONUS2 = playfield.addGroup(new SpriteGroup("bonus2"));
        BONUS3 = playfield.addGroup(new SpriteGroup("bonus3"));

        BufferedImage[] waterrolling = getImages("image/com.golden copy.png",1,16);
        AnimatedSprite roll = new AnimatedSprite(waterrolling,-100,100);
        roll.setAnimate(true);
        roll.setLoopAnim(true);
        PATTERN.add(roll);
        //*************************************************/
        //
        //inisialisasi musuh
        //
        //***************************************************/
        BufferedImage[] imag = getImages("image/enemy_walk.png", 8, 1);
        double speed = 0.023;
	long animationDelay = 300;
        Enemy31 enemy;
        enemy = new FollowYourShip(this, imag, speed, animationDelay, player);
        //enemy inisialisasi 2
        Enemy31 enemy2;
        enemy2 = new FollowYourShip(this, imag, speed, animationDelay, player);

        Enemy31 enemy3;
        enemy3 = new UpDownPatrol(this, imag, speed, animationDelay);

        Enemy31 enemy4;
        enemy4 = new FollowYourShip(this, imag, speed, animationDelay, player);

        Enemy31 enemy5;
        enemy5 = new LeftRightPatrol(this, imag, speed, animationDelay);

        Enemy31 enemy6;
        enemy6 = new LeftRightPatrol(this, imag, speed, animationDelay);

        Enemy31 enemy7;
        enemy7 = new LeftRightPatrol(this, imag, speed, animationDelay);

        Enemy31 enemy8;
        enemy8 = new FollowYourShip(this, imag, speed, animationDelay, player);

        Enemy31 enemy9;
        enemy9 = new FollowYourShip(this, imag, speed, animationDelay, player);

        Enemy31 enemy10;
        enemy10 = new UpDownPatrol(this, imag, speed, animationDelay);

        
        //***********************************************/
        //
        //INisialisasi bonus
        //
        //***********************************************/
        cheesewithplayer = new BasicCollisionGroup(){
        @Override
        public void collided(Sprite s1, Sprite s2) {
            s2.setActive(false);
            win = true;
            }

        };
        playfield.addCollisionGroup(SHIP, BONUS2, cheesewithplayer);
        

        for (int y=0;y < h;y++) {
		for (int x=0;x = 0){
                parent.nextGameID = ship2wargame.main_menu;
                //gamestatus = intro;
                initLevel();
                }
                Exit = false;

		} else if (keyPressed(KeyEvent.VK_C) || keyPressed(KeyEvent.VK_ENTER)) {
		// resume game
                    initLevel();
                    Exit = false;
		}
		return;
		}
                if(score >= 50){
                     BONUS2.setActive(true);
                     BONUS3.setActive(true);
                }
                
                
                if (keyDown(KeyEvent.VK_SPACE))
                    {
                    Sprite playerMissle = new Sprite( getImage( "image/Projectile.png" ));
                    playerMissle.setLocation(  player.getX()+25, player.getY()+10 );
                    //playerMissle.setVerticalSpeed( -0.5 );
                    playerMissle.setHorizontalSpeed(0.5);
                    playerMissle.setActive(win);
                    PROJECTILE.add(playerMissle);
                    }
                
         
        //..................................GAME STATUS
        switch(gamestatus){
            //INTRO SAAT MEMBUKA GAME
            case intro:
                
            levelImage.update(elapsedTime);
            if (levelTimer.isActive()) {
		if (levelImage.getX() > 40) {
			levelImage.setX(40);
			levelImage.setHorizontalSpeed(0);
                } else if (levelImage.getX() == 40) {
                    if (levelTimer.action(elapsedTime)) {
			levelImage.setHorizontalSpeed(25*50/1000);
			levelTimer.setActive(false);
                        }
                    }
            }

           //SWITCH SAAT MELAKUKKAN PERMAINAN
           case playing:
               if (keyPressed(KeyEvent.VK_ESCAPE)) {
                   Exit = true;
                   ENEMY_GROUP.setActive(false);
                   ENEMY_GROUP2.setActive(false);
               }
             //momoy.update(elapsedTime);
           if (levelImage.getX() > 768) {
		gamestatus = playing;
           }
           if (timerTime.action(elapsedTime)) {
		time--;
		if (time <= 0) {
			timeUp();
		} else if (time  0){
                player.addHorizontalSpeed(elapsedTime, 0.1, 0);
                player.setStatus(player.STAND);
            } else if (game.keyDown(KeyEvent.VK_RIGHT)) {
            //moveX(playerSpeed * elapsedTime);
                player.addHorizontalSpeed(elapsedTime, 0.1, maxSpeed);
                player.setDirection(player.RIGHT);
                player.setStatus(player.WALKING);
                game.playSound("sound/movegood.wav");
            }else if (player.getHorizontalSpeed() < 0) {
                player.addHorizontalSpeed(elapsedTime, 0.1, 0);
                player.setStatus(player.STAND);
            }else if (game.keyDown(KeyEvent.VK_UP) && game.keyDown(KeyEvent.VK_DOWN)) {
                player.setFrame(0);
                player.setDirection(player.UP);
                player.setStatus(player.STAND);
            }else if (game.keyDown(KeyEvent.VK_DOWN) && game.keyDown(KeyEvent.VK_RIGHT)) {
                player.setFrame(0);
                player.setDirection(player.RIGHT);
                player.setStatus(player.STAND);
                //setDirection(BOTTOM);
            }else if (game.keyDown(KeyEvent.VK_RIGHT) && game.keyDown(KeyEvent.VK_DOWN)) {
                player.setFrame(0);
                player.setDirection(player.BOTTOM);
                player.setStatus(player.STAND);
                //setDirection(BOTTOM);
            }else if (game.keyDown(KeyEvent.VK_DOWN) && game.keyDown(KeyEvent.VK_LEFT)) {
                player.setFrame(0);
                player.setDirection(player.BOTTOM);
                player.setStatus(player.STAND);
                //setDirection(BOTTOM);
            }else if (game.keyDown(KeyEvent.VK_LEFT) && game.keyDown(KeyEvent.VK_DOWN)) {
                player.setFrame(0);
                player.setDirection(player.BOTTOM);
                //setDirection(BOTTOM);
            }else if (game.keyDown(KeyEvent.VK_UP)) {
                // moveY(-playerSpeed * elapsedTime);
                player.addVerticalSpeed(elapsedTime, -0.1, -maxSpeed);
                player.setAnimate(true);
                player.setDirection(player.UP);
                player.setStatus(player.WALKING);
                game.playSound("sound/movegood.wav");
            }else if(player.getVerticalSpeed()  0) {
                player.addVerticalSpeed(elapsedTime, 0.1,-maxSpeed);
                player.setStatus(player.STAND);
            }
            if (keyPressed(KeyEvent.VK_CONTROL) && player.fireTimer.isActive() == false) {
                player.fireTimer.setActive(true);
                game.playSound("sound/sound1.wav");
                // add projectile and fire animation
                BufferedImage image = (player.getDirection() == player.LEFT) ?player.projectileImage[0] : player.projectileImage[1];
                BufferedImage image2 = (player.getDirection() == player.RIGHT) ? player.projectileImage[0] : player.projectileImage[1];
                BufferedImage image3 = (player.getDirection() == player.UP) ? player.projectileImage2[0] : player.projectileImage2[1];
                BufferedImage image4 = (player.getDirection() == player.BOTTOM) ? player.projectileImage2[0] : player.projectileImage2[1];
                PROJECTILE.add(new Projectile(player));
                playfield.add(new FireAnimation(player));
            }
            break;

            case going_next_level:
                
            break;

            case gameover:
                if (time >= 0){
                    if (life >= 0) {
			gamestatus = playing;
				initLevel();
                                loseTitle = "you can try again";
			} else {
                            
                            showHiScore();
			}
                }
            break;

            case winner:
                
            break;

            case showtitle:

            break;
            }



    }




    @Override
    public void render(Graphics2D g) {
        playfield.render(g);

        if (Exit) {
		font.drawString(g, "[C]ONTINUE", 400, 300);
		font.drawString(g, "[R]ESTART", 400, 330);
		font.drawString(g, "[Q]UIT", 400, 360);

		return;
	}

        switch (gamestatus) {
	// level title
		case intro:
			levelImage.render(g);
                        
                break;
                case playing:
                      font.drawString(g, "Time :" + time, 64, 50);
                      font.drawString(g, "PLAYER LIFE  :" + String.valueOf(life), 64, 20);
                      //font.drawString(g, "EnemyLife : " + String.valueOf(lifekapal), 500,20);
                      font.drawString(g, "GerbangLife :" + String.valueOf(lifemusuh), 500, 50);
                      font.drawString(g, "Score :" + String.valueOf(score),300,50);
                break;
                case going_next_level:
                
                break;

                case gameover:
                if (time == 0 ){
                   font.drawString(g, loseTitle, GameFont.CENTER, 0, 224, getWidth());
                }else {
                   font.drawString(g, "Sory your lose", GameFont.CENTER, 0, 224, getWidth());
                }
                break;

                case winner:
                
                break;

                case showtitle:

                break;
       }
    }

    public void timeUp() {
		life--;
		gamestatus = gameover;
		loseTitle = "WAKTU ANDA HABIS!!!";

		if (time == 0) {
			finish();
		}
	}


public void getCaught() {
		life--;
		gamestatus = gameover;
		loseTitle = "Oops! They got you..";

                if(time <= 20){
                    BONUS3.setActive(true);
                    time += 10;
                }

	}







    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(80);
            playfield.add(explosion);
	}
    void shiprounded(double X,double Y){
            BufferedImage[] image = getImages("image/Kapaltenggelam.png",9, 1);
            double x = X - (image[0].getWidth()/2),y = Y - (image[0].getHeight()/2);
            VolatileSprite round = new VolatileSprite(image,x,y);
            round.getAnimationTimer().setDelay(80);
            playfield.add(round);
        }
    void shiprounded2(double X,double Y){
            BufferedImage[] image = getImages("image/musuh_kandas.png",9, 1);
            double x = X - (image[0].getWidth()/2),y = Y - (image[0].getHeight()/2);
            VolatileSprite round = new VolatileSprite(image,x,y);
            round.getAnimationTimer().setDelay(80);
            playfield.add(round);
        }
    void addExplosionEffect2(double centerX, double centerY) {
	    BufferedImage[] image = getImages("image/explode.png", 15, 1);
            double x = centerX - (image[0].getWidth()/2),y = centerY - (image[0].getHeight()/2);
            VolatileSprite explosion = new VolatileSprite(image, x, y);
            explosion.getAnimationTimer().setDelay(80);
            playfield.add(explosion);
	}
   void addBonusEffect (double X,double Y){
            BufferedImage[] image = getImages("image/Date & Regional Settings 2.png",1,1);
            double x = X - (image[0].getWidth()/2),y = Y - (image[0].getHeight()/2);
            VolatileSprite cling = new VolatileSprite(image,x,y);
            cling.getAnimationTimer().setDelay(80);
   }

/***********************************/
/*************************************************/
/**************************************************/
/*                                        ALL ABOUT COLLISION                                               */
/**********************************************/
/*********************************************/
/************************************************/
/*******************************************/
   
    class PlayerTileCollision extends AdvanceCollisionGroup {
        @Override
            public CollisionShape getCollisionShape1(Sprite s1) {
		rect1.setBounds(s1.getX(), s1.getY(),s1.getWidth(), s1.getHeight());
                return rect1;
	    }

        @Override
	    public boolean isCollide(Sprite s1, Sprite s2,CollisionShape shape1, CollisionShape shape2) {
		boolean ignoreCollision = false;
                    if (shape1.intersects(shape2)) {
                       }
                    return (ignoreCollision) ? false :
                    super.isCollide(s1, s2, shape1, shape2);
		}
		public void collided(Sprite s1, Sprite s2) {
                    revertPosition1();
                    if (collisionSide == LEFT_RIGHT_COLLISION ||collisionSide == RIGHT_LEFT_COLLISION) {
			s1.setHorizontalSpeed(0);
			}
		}
	}
/////////////////////////////////////////////////////////////////////////////
// SHIP DENGAN ROLLING WATER.......................  
/////////////////////////////////////////////////////////////////////////////
class PlayerWaterCollision extends AdvanceCollisionGroup {
    public boolean exit;
        @Override
        public CollisionShape getCollisionShape1(Sprite s1) {
		// robo collision offset, cut 6 pixels at each side
		rect1.setBounds(s1.getX() - 25, s1.getY() -25,s1.getWidth() - 25, s1.getHeight());
	        return rect1;
	    }       
        @Override
        public void collided(Sprite s1, Sprite s2) {
           revertPosition1();
           s1.setActive(false);
           shiprounded(s1.getX() + (s1.getWidth()/2), s1.getY() + (s1.getHeight()/2));
           playSound("sound/whirlin.wav");
           life -= 1;
           if(life == 0){
                  s2.setActive(false);
                   initLevel();
               } else {
                    s2.setActive(true);
               }
           if(life == 1){
                s2.setActive(false);
                initLevel();
           }
        }
}
/////////////////////////////////////////////////////////////////////////////
//KAPAL KARO TILE
////////////////////////////////////////////////////////////////////////////
 class ShiptileCollision extends AdvanceCollisionGroup{

        @Override
	public CollisionShape getCollisionShape1(Sprite s1) {
            rect1.setBounds(s1.getX() + 6, s1.getY(),s1.getWidth() - 12, s1.getHeight());
            return rect1;
	    }

        @Override
        public boolean isCollide(Sprite s1, Sprite s2,CollisionShape shape1, CollisionShape shape2) {
             boolean ignoreCollision = false;

			if (shape1.intersects(shape2)) {

			}

			return (ignoreCollision) ? false :
				   super.isCollide(s1, s2, shape1, shape2);
        }


        @Override
        public void collided(Sprite s1, Sprite s2) {
           revertPosition1();
           s1.setActive(false);
           }
        }
/////////////////////////////////////////////////////////////////////////////
//ship dengan pohon
/////////////////////////////////////////////////////////////////////////////
 class PlayerWithPohon extends AdvanceCollisionGroup{

    @Override
	public CollisionShape getCollisionShape1(Sprite s1) {
            rect1.setBounds(s1.getX() + 6, s1.getY(),s1.getWidth() - 12, s1.getHeight());
	    return rect1;
	    }
    
        @Override
        public void collided(Sprite s1, Sprite s2) {
            revertPosition1();
            s1.setHorizontalSpeed(0);
        }

}
/////////////////////////////////////////////////////////////////////////////
//projectile kapal dengan pohon
/////////////////////////////////////////////////////////////////////////////
class ProjectilePohonCollision extends PreciseCollisionGroup{

        @Override
        public void collided(Sprite s1, Sprite s2) {
            revertPosition1();
            s1.setActive(false);
            addExplosionEffect(s1.getX() + (s1.getWidth()/2), s1.getY() + (s1.getHeight()/2));
        }

}
/////////////////////////////////////////////////////////////////////////////
//PROJECTILE DENGAN TILE
/////////////////////////////////////////////////////////////////////////////
class ProjectileTileCollision extends PreciseCollisionGroup {
		public void collided(Sprite s1, Sprite s2) {
			revertPosition1();
			s1.setActive(false);
			// explosion animation
		    addExplosionEffect(s1.getX() + (s1.getWidth()/2), s1.getY() + (s1.getHeight()/2));
		}
        }
/////////////////////////////////////////////////////////////////////////////
//PROJECTILE DENGAN GOAL COLLISIONS
/////////////////////////////////////////////////////////////////////////////
class ProjectiGoalCollision extends AdvanceCollisionGroup {

		public void collided(Sprite s1, Sprite s2) {
                    revertPosition1();
                    s1.setActive(false);
                    playSound("sound/explose.wav");
                    s2.setActive(true);
                    if (lifekapal == 0){
                        lifemusuh -= 50;
                    }
                    lifemusuh -= 1;
                    score += 1;
                    if(lifemusuh == 0){
                        s2.setActive(false);
                        level++;
                        if(level <= 4){
                        time += 100;
                        initLevel();
                        }   
                    } 

                    addExplosionEffect(s1.getX() + (s1.getWidth()/2), s1.getY() + (s1.getHeight()/2));
		}

	}
/////////////////////////////////////////////////////////////////////////////
//PROCETILE DENGANG GOAL 2
/////////////////////////////////////////////////////////////////////////////
class ProjectiGoalCollision2 extends AdvanceCollisionGroup {

        @Override
        public void collided(Sprite s1, Sprite s2) {
            revertPosition1();
                    s1.setActive(false);
                    playSound("sound/explose.wav");
                    s2.setActive(true);
                    lifemusuh2 -= 1;
                    score += 10;
                    s2.setActive(false);
                   addExplosionEffect(s1.getX() + (s1.getWidth()/2), s1.getY() + (s1.getHeight()/2));
        }
}
/////////////////////////////////////////////////////////////////////////////
//BONUS PLAYER COLLISION
/////////////////////////////////////////////////////////////////////////////
class BonusPlayerCollision1 extends AdvanceCollisionGroup{
        @Override
        public void collided(Sprite s1, Sprite s2) {
            s2.setActive(false);
            //revertPosition1();
            score += 20;
            
        }
}
/////////////////////////////////////////////////////////////////////////////
//MUSUH DAN PLAYER
/////////////////////////////////////////////////////////////////////////////
class MusuhPlayerCollision extends AdvanceCollisionGroup{
        public void collided(Sprite s1, Sprite s2) {
            revertPosition1();
            s2.setActive(false);
            s1.setActive(false);
            lifekapal -= 1;
            life -= 1;
            loseTitle = "you can try again";
            if(life == 2){         
                initLevel();
                score -= 40;
                cheesewithplayer.setActive(false);
                getCaught();
                
            } else if (life == 1){
                initLevel();
                gamestatus = gameover;
                loseTitle = "you can try again";
            }else if (life == 0){
                parent.nextGameID = ship2wargame.main_menu;
            }
             addExplosionEffect2(s1.getX() + (s1.getWidth()/2), s1.getY() + (s1.getHeight()/2));
    }

}
/////////////////////////////////////////////////////////////////////////////
//MUSUH DENGAN WATERROLLING
/////////////////////////////////////////////////////////////////////////////
class MusuhWatterolling extends AdvanceCollisionGroup{
        @Override
        public void collided(Sprite s1, Sprite s2) {
            revertPosition1();
            s1.setActive(false);
            lifekapal -= 1;
            shiprounded2(s1.getX() + (s1.getWidth()/2), s1.getY() + (s1.getHeight()/2));
        }
}
/////////////////////////////////////////////////////////////////////////////
//MUSUH DENGAN POHON
/////////////////////////////////////////////////////////////////////////////
class MusuhPohonCollision extends AdvanceCollisionGroup{

        @Override
        public void collided(Sprite s1, Sprite s2) {
            revertPosition1();
            s1.setActive(true);
            lifekapal -= 1;
            //addExplosionEffect2(s1.getX() + (s1.getWidth()/2), s1.getY() + (s1.getHeight()/2));
        }
    
}
class MusuhMusuhCollision extends AdvanceCollisionGroup{

        @Override
        public void collided(Sprite s1, Sprite s2) {
            revertPosition1();
            s1.setActive(false);
            lifekapal -= 1;
            addExplosionEffect2(s1.getX() + (s1.getWidth()/2), s1.getY() + (s1.getHeight()/2));
        }
    
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
class EnemyTileCollision extends CollisionGroup {

        @Override
	public CollisionShape getCollisionShape1(Sprite s1) {
		rect1.setBounds(s1.getX(), s1.getY(), s1.getWidth(), s1.getHeight());
		return rect1;
        }
        
        @Override
        public void collided(Sprite s1, Sprite s2) {
            //revertPosition1();

            if(collisionSide == BOTTOM_TOP_COLLISION ){
                ((shipSprite) s1).hitWall();
               // s2.setActive(true);
            }
        }

}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//digunakan untuk melakukkan atau mengetahui collision antar enemy tile dengan
// zombie
// enemy32
class EnemyTileCollisionZombie extends CollisionGroup{

        	// player bounding box
    @Override
    public CollisionShape getCollisionShape1(Sprite s1) {
		rect1.setBounds(s1.getX()+4, s1.getY()+18, s1.getWidth()-8, s1.getHeight()-18);
		return rect1;
    }


    // tile bounding box
    @Override
    public CollisionShape getCollisionShape2(Sprite s2) {
		rect2.setBounds(s2.getX(), s2.getY()+8, s2.getWidth(), s2.getHeight()-8);
		return rect2;
    }


        @Override
        public void collided(Sprite s1, Sprite s2) {
            if (isCollide(s1, s2, getCollisionShape1(s1), getCollisionShape2(s2)) == false) {
				// sprite not stuck
				((shipSprite) s1).hitWall();
            }
        }

}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//digunakan untuk melakukkan atau mengetahui collision antara tile collision left right
//enemy33
/////////////////////////////////////////////////////////////////////////////
class EnemyTileCollisionLeftRight extends CollisionGroup{

        @Override
        public void collided(Sprite s1, Sprite s2) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//digunakan untuk melakukkan atau mengetahui colllision antara tile turner
// enemy 34
/////////////////////////////////////////////////////////////////////////////
class EnemyTileCollisionTurner extends CollisionGroup{

        @Override
        public void collided(Sprite s1, Sprite s2) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//digunakan untuk mengetahui collision turn left always
//enemy 35
/////////////////////////////////////////////////////////////////////////////
class EnemyTileCollisionTurnLeftAlways extends CollisionGroup{

    @Override
	public CollisionShape getCollisionShape1(Sprite s1) {
		rect1.setBounds(s1.getX(), s1.getY()+18, s1.getWidth(), s1.getHeight()+18);
		return rect1;
        }
//        public CollisionShape getCollisionShape2(Sprite s1) {
//		rect2.setBounds(s1.getX(), s1.getY()+18, s1.getWidth(), s1.getHeight()+18);
//		return rect2;
//        }

        @Override
        public void collided(Sprite s1, Sprite s2) {
//           if (collisionSide == TOP_BOTTOM_COLLISION ) {
//                ((shipSprite) s1).hitWall();
//            }
           if (collisionSide == LEFT_RIGHT_COLLISION ||
		    		   collisionSide == RIGHT_LEFT_COLLISION) {
			((shipSprite) s1).hitWall();
                        s2.setActive(true);
            }
        }

}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//digunakam untuk mengetahui collisison antara turn right always
/////////////////////////////////////////////////////////////////////////////
//enemy 36
class EnemyTileCollisionTurnRightAlways extends CollisionGroup{

        @Override
        public void collided(Sprite s1, Sprite s2) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

}
//class Bonus2ShipCollision
}



/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//
//  LOGIC FOR CHEESE
//
/////////////////////////////////////////////////////////////////////////

class PlayerCheeseCollision extends BasicCollisionGroup{

    boolean win;
    @Override
    public void collided(Sprite s1, Sprite s2) {


        s2.setActive(false);
        win = true;
      
    }


}

nah code diatas cuman sepotong…kenapa sepotong coz potongan code lainnya belum sempurna. file yang sempurna lupa naroh…hihihihi, game ini dibuat dalam waktu kurang dari 3 bulan + belajar awal GTGE…karena tuntutan tugas kul…untungnya selesai walaupun sambil berdarah-darah…:(. insyallah klo ketemu filenya yang sempurna tak bagi dech…,untuk penjelasan code diatas akan saya jelaskan lain waktu karena aku bener2 males buat nulis….tp diatas ada sedikit comment mengenai fungsi dari setiap code….

3 thoughts on “my first Game project with GTGE java Framework…: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