Android Open Source - AllBinary-Platform-Game Test Game Demo Game Canvas






From Project

Back to project page AllBinary-Platform-Game.

License

The source code is released under:

AllBinary Open License Version 1.0 Copyright (c) 2011 AllBinary. By agreeing to this license you and any business entity you represent are legally bound to this legal agreement. You may transmit, m...

If you think the Android project AllBinary-Platform-Game listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
* AllBinary Open License Version 1/*from www  .  j a v  a 2 s .c  o m*/
* Copyright (c) 2011 AllBinary
* 
* By agreeing to this license you and any business entity you represent are
* legally bound to the AllBinary Open License Version 1 legal agreement.
* 
* You may obtain the AllBinary Open License Version 1 legal agreement from
* AllBinary or the root directory of AllBinary's AllBinary Platform repository.
* 
* Created By: Travis Berthelot
* 
*/
package org.allbinary.game.testgamedemo.canvas;

import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Graphics;

import org.allbinary.game.testgamedemo.init.TestGameDemoStaticInitializerFactory;
import org.allbinary.game.testgamedemo.level.TestGameDemoLevelBuilder;
import org.allbinary.input.accelerometer.AccelerometerSensorFactory;
import org.allbinary.input.gyro.AllBinaryOrientationSensor;
import org.allbinary.input.gyro.GyroSensorFactory;
import org.allbinary.media.audio.TestGameDemoSoundsFactoryFactory;
import org.allbinary.media.audio.TestSound;
import org.allbinary.util.BasicArrayList;

import org.allbinary.logic.basic.string.CommonStrings;
import org.allbinary.logic.basic.string.StringUtil;
import org.allbinary.logic.communication.log.LogFactory;
import org.allbinary.logic.communication.log.LogUtil;
import org.allbinary.ai.OptimizedArtificialIntelligenceLayerProcessorForCollidableLayer;
import org.allbinary.game.GameInfo;
import org.allbinary.game.GameTypeFactory;
import org.allbinary.game.IntermissionFactory;
import org.allbinary.game.collision.OptimizedAllBinaryCollisionLayerProcessorForCollidableLayer;
import org.allbinary.game.configuration.GameSpeed;
import org.allbinary.game.configuration.event.ChangedGameFeatureListener;
import org.allbinary.game.configuration.feature.Features;
import org.allbinary.game.configuration.feature.GameFeature;
import org.allbinary.game.configuration.feature.GameFeatureFactory;
import org.allbinary.game.configuration.feature.TouchFeatureFactory;
import org.allbinary.game.displayable.canvas.AllBinaryGameCanvas;
import org.allbinary.game.displayable.canvas.GamePerformanceInitUpdatePaintable;
import org.allbinary.game.displayable.canvas.StartIntermissionPaintable;
import org.allbinary.game.input.OptimizedGameInputLayerProcessorForCollidableLayer;
import org.allbinary.game.layer.AllBinaryGameLayerManager;
import org.allbinary.game.layer.PlayerGameInputGameLayer;
import org.allbinary.game.layer.identification.GroupLayerManagerListener;
import org.allbinary.game.score.BasicHighScoresFactory;
import org.allbinary.game.state.GameState;
import org.allbinary.game.tick.OptimizedTickableLayerProcessor;
import org.allbinary.graphics.canvas.transition.progress.ProgressCanvas;
import org.allbinary.graphics.canvas.transition.progress.ProgressCanvasFactory;
import org.allbinary.graphics.color.BasicColorFactory;
import org.allbinary.graphics.displayable.DisplayInfoSingleton;
import org.allbinary.graphics.displayable.command.MyCommandsFactory;
import org.allbinary.input.motion.button.BaseTouchInput;
import org.allbinary.input.motion.button.TestGameDemoNeededTouchButtonsBuilder;
import org.allbinary.input.motion.button.TestGameDemoTouchButtonsBuilder;
import org.allbinary.media.AllBinaryVibration;
import org.allbinary.media.audio.AllBinaryMediaManager;
import org.allbinary.media.audio.PlayerQueue;
import org.allbinary.media.audio.PrimaryPlayerQueueFactory;
import org.allbinary.media.audio.SecondaryPlayerQueueFactory;
import org.allbinary.time.TimeDelayHelper;

public class TestGameDemoGameCanvas extends AllBinaryGameCanvas
{
    private final int WAIT = GameSpeed.getInstance().getDelay();

    private final int portion = 4;
    
    public TestGameDemoGameCanvas(CommandListener commandListener,
            AllBinaryGameLayerManager allBinaryGameLayerManager) throws Exception
    {
        super(commandListener, allBinaryGameLayerManager, 
                new BasicHighScoresFactory(TestGameDemoSoftwareInfo.getInstance()),
                new TestGameDemoStaticInitializerFactory(),
           //new BasicBuildGameInitializerFactory(),
           false);
    }

    public TestGameDemoGameCanvas(AllBinaryGameLayerManager allBinaryGameLayerManager)
    throws Exception
    {
        this(null, allBinaryGameLayerManager);
    }
    
    protected void initSpecialPaint()
    {
        super.initSpecialPaint();

        this.setStartIntermissionPaintable(new StartIntermissionPaintable(
                this, new String[] {StringUtil.getInstance().EMPTY_STRING}, new int[] {0}, BasicColorFactory.getInstance().RED));
    }

    public void mediaInit() throws Exception
    {
        LogUtil.put(LogFactory.getInstance(CommonStrings.getInstance().START, this, "mediaInit"));
        AllBinaryMediaManager.init(TestGameDemoSoundsFactoryFactory.getInstance());
    }

    //Don't Auto Hide instead update the list
    protected  void updateTouch()
    throws Exception
    {
        GameInfo gameInfo = this.gameLayerManager.getGameInfo();
        
        if(gameInfo.getGameType() != GameTypeFactory.getInstance().BOT)
        {
            BaseTouchInput nextTouchInputFactory =
                TestGameDemoTouchButtonsBuilder.getInstance(
                        this.getSensorGameUpdateProcessor());

            if(Features.getInstance().isFeature(
                    TouchFeatureFactory.getInstance().AUTO_HIDE_SHOW_SCREEN_BUTTONS))
            {
                if(gameInfo.getCurrentLevel() - getStartLevel() >= 1)
                {
                    nextTouchInputFactory = 
                        TestGameDemoNeededTouchButtonsBuilder.getInstance(
                                this.getSensorGameUpdateProcessor());
                }
            }
            this.updateCurrentTouchInputFactory(nextTouchInputFactory);
        }
    }

    protected synchronized void initConfigurable()
    {
        try
        {

          ProgressCanvas progressCanvas = ProgressCanvasFactory.getInstance();

            if (ChangedGameFeatureListener.getInstance().isChanged())
            {
                super.initConfigurable();

                progressCanvas.addPortion(portion, "Group Manager");
                GroupLayerManagerListener.getInstance().init(3);

                AllBinaryVibration.init();

                //super.initConfigurable(portion);

                ChangedGameFeatureListener.getInstance().setChanged(false);

                if (!this.isRunning())
                {
                    return;
                }
            } else
            {
              progressCanvas.addPortion(4, "Skipping Configurable");
            }
            
        } catch (Exception e)
        {
            LogUtil.put(LogFactory.getInstance(CommonStrings.getInstance().EXCEPTION, this, "initConfigurable", e));
        }
    }

    protected void threadInit() throws Exception
    {
        try
        {
            final int portion = 60;
            super.init();

            if (!this.isRunning())
            {
                return;
            }

            if (!this.isInitialized())
            {
                if (!this.isRunning())
                {
                    return;
                }

                ProgressCanvas progressCanvas = 
                    ProgressCanvasFactory.getInstance();
                
                progressCanvas.addPortion(portion, "Main Processors");

                this.setWait(WAIT);
                this.loadState();

                BasicArrayList list = new BasicArrayList();

                Features features = Features.getInstance();
                
                GameFeatureFactory gameFeatureFactory = GameFeatureFactory.getInstance();
                
                if (features.isFeature(gameFeatureFactory.ARTIFICIAL_INTELLEGENCE_PROCESSOR))
                {
                    list.add(new OptimizedArtificialIntelligenceLayerProcessorForCollidableLayer());
                }

                if (features.isFeature(gameFeatureFactory.GAME_INPUT_LAYER_PROCESSOR))
                {
                    list.add(new OptimizedGameInputLayerProcessorForCollidableLayer());
                }

                if (features.isFeature(gameFeatureFactory.COLLIDABLE_INTERFACE_LAYER_PROCESSOR))
                {
                    list.add(new OptimizedAllBinaryCollisionLayerProcessorForCollidableLayer());
                }

                if (features.isFeature(gameFeatureFactory.TICKABLE_LAYER_PROCESSOR))
                {
                    list.add(new OptimizedTickableLayerProcessor());
                }

                gameLayerManager.setLayerProcessorList(list);

                progressCanvas.addPortion(portion, "Initializing Game");
            }

            this.buildGame(false);

        } catch (Exception e)
        {
            LogUtil.put(LogFactory.getInstance(CommonStrings.getInstance().EXCEPTION, this, "_init", e));
        }
    }

    public void buildGame(boolean isProgress) throws Exception
    {
        this.loadResources(gameLayerManager.getGameInfo().getCurrentLevel());
        
        ProgressCanvas progressCanvas = ProgressCanvasFactory.getInstance();
        
        int portion = 30;
        if (isProgress && this.isMainCanvas())
        {            
            progressCanvas.start();

            this.getCustomCommandListener().commandAction(
                    MyCommandsFactory.getInstance().SET_DISPLAYABLE,
                    progressCanvas);
            //progressCanvas.waitUntilDisplayed();
            portion = 4;
        }

        //Combat games
        //this.cleanupGame();
        PrimaryPlayerQueueFactory.getInstance().clear();
        SecondaryPlayerQueueFactory.getInstance().clear();
        gameLayerManager.cleanup();

        if (!this.isRunning())
        {
            return;
        }

        //this.getLayerManager().append(new PlayerGameInputGameLayer());

        //DestroyedEventHandler.getInstance().removeAllListeners();

        //Some games update intermission here

        progressCanvas.addPortion(portion, "Building Game Level");

        new TestGameDemoLevelBuilder(this).build();

        progressCanvas.addPortion(portion, "Set Background");

        //Some games update backgrounds here

        //this.playerLayer = ((TestGameDemoLayerManager) this.getLayerManager()).getPlayerLayer();

        //DestroyedEventHandler.getInstance().addListener((EventListenerInterface) playerLayer);

        if (!this.isRunning())
        {
            return;
        }

        gameLayerManager.append(new PlayerGameInputGameLayer(0));

        progressCanvas.addPortion(portion, "Ending Custom Build");

        if (gameLayerManager.getGameInfo().getGameType() != GameTypeFactory.getInstance().BOT)
        {
            //PrimaryPlayerQueueFactory.getInstance().add(
                    //GameSounds.getBegin());
        }

        super.buildGame(portion);

        this.getStartIntermissionInterface().setEnabled(true);
        this.getEndLevelIntermissionInterface().setEnabled(false);
        
        // A canvas not in GameState.PLAYING_GAME_STATE will not appear in
        // democanvas
        this.setGameState(GameState.PLAYING_GAME_STATE);
    }

    public void setGameState(GameState gameState) throws Exception
    {
        super.setGameState(gameState);

        IntermissionFactory intermissionFactory = IntermissionFactory.getInstance();
        
        if (this.getGameState() == GameState.PLAYING_GAME_STATE)
        {
            this.setMainStateProcessor(this.getProcessGameProcessor());
        }
        else if (this.getGameState() == intermissionFactory.WAIT_LEVEL_INTERMISSION_GAME_STATE
                || this.getGameState() == intermissionFactory.SHOW_RESULTS_LEVEL_INTERMISSION_GAME_STATE
                || this.getGameState() == intermissionFactory.SHOW_HIGH_SCORE_LEVEL_INTERMISSION_GAME_STATE)
        {
            //GameKeyEventHandler.getInstance().addListener(this.getIntermissionPlayerGameInput());
            
            //this.setMainStateProcessor(this.processEndIntermissionProcessor);
        }
        else
        {
            // Game plays in non intermission and after death
            this.setMainStateProcessor(this.getProcessGameProcessor());
        }
    }
    
    private final GamePerformanceInitUpdatePaintable gamePerformanceInitUpdatePaintable = 
        new GamePerformanceInitUpdatePaintable();

    private final AllBinaryOrientationSensor gyroOrientationSensor = GyroSensorFactory.getInstance();
    private final AllBinaryOrientationSensor accelerometerOrientationSensor = AccelerometerSensorFactory.getInstance();
    
    private final int halfHeight = DisplayInfoSingleton.getInstance().getLastHalfHeight();

    //private String soundQueue = PrimaryPlayerQueueFactory.getInstance().toString();
    
    public void draw(Graphics graphics)
    {
        this.clear(graphics);

        this.getBasicColorUtil().setBasicColor(graphics, gameLayerManager.getForegroundBasicColor());

        //graphics.drawString(TEXT, 0, halfHeight, 0);

        /*
        graphics.drawString(soundQueue, 0, halfHeight + 15, 0);
        */

      gameLayerManager.paint(graphics, 0, 0);

      nonBotPaintable.paint(graphics);

        gameSpecificPaintable.paint(graphics);      

      gamePerformanceInitUpdatePaintable.paint(graphics);
        
        touchPaintable.paint(graphics);
        
        screenCapture.saveFrame();

        graphics.drawString(this.gyroOrientationSensor.toString(), 0, halfHeight + 30 + 60, 0);
        graphics.drawString(this.accelerometerOrientationSensor.toString(), 0, halfHeight + 30 + 75, 0);

        this.getTouchPaintable().paint(graphics);
    }

    private TimeDelayHelper playerTimeDelayHelper = new TimeDelayHelper(2000);
            //890);

    private final PlayerQueue primaryPlayerQueue = PrimaryPlayerQueueFactory.getInstance();
    private final PlayerQueue secondaryPlayerQueue = SecondaryPlayerQueueFactory.getInstance();
    
    private final Features features = Features.getInstance();
    
    private final GameFeature soundGameFeature = GameFeatureFactory.getInstance().SOUND;
    
    protected void processGame() throws Exception
    {
        if (playerTimeDelayHelper.isTime())
        {
            if(this.features.isFeature(soundGameFeature))
            {
                this.primaryPlayerQueue.add(TestSound.getInstance());
            }
        }
      
        super.processGame();
        
        /*
        if (playerTimeDelayHelper.isTime())
        {
            if (!this.primaryPlayerQueue.process())
            {
                if (this.secondaryPlayerQueue.process())
                {
                    playerTimeDelayHelper.setStartTime();
                }
            } else
            {
                playerTimeDelayHelper.setStartTime();
            }
        }

        
        if (!this.primaryPlayerQueue.process())
        {
            this.secondaryPlayerQueue.process();
        }
        
        */
        
        //soundQueue = this.primaryPlayerQueue.toString();
        
        this.gamePerformanceInitUpdatePaintable.update();
    }
}




Java Source Code List

.TestGameDemoMIDlet.java
.TestGameDemoMIDlet.java
.TestGameDemoMIDlet.java
.TestGameDemoMIDlet.java
.TestGameDemoMIDlet.java
org.allbinary.AndroidResources.java
org.allbinary.AndroidResources.java
org.allbinary.AndroidResources.java
org.allbinary.animation.image.TestGameDemoEarlyResourcesImageBasedAnimationInterfaceFactoryInterfaceFactory.java
org.allbinary.animation.image.TestGameDemoEarlyResourcesOpenGLESImageBasedAnimationInterfaceFactoryInterfaceFactory.java
org.allbinary.animation.image.TestGameDemoGameResourcesImageBasedAnimationInterfaceFactoryInterfaceFactory.java
org.allbinary.animation.image.TestGameDemoImageBasedAnimationInterfaceFactoryInterfaceFactory.java
org.allbinary.animation.image.TestGameDemoOpenGLESImageBasedAnimationInterfaceFactoryInterfaceFactory.java
org.allbinary.game.testgamedemo.TestDemoGameAndroidActivity.java
org.allbinary.game.testgamedemo.TestDemoGameMIDletFactory.java
org.allbinary.game.testgamedemo.TestGameDemoAndroidActivity.java
org.allbinary.game.testgamedemo.TestGameDemoAndroidOpenGLESView.java
org.allbinary.game.testgamedemo.TestGameDemoAndroidView.java
org.allbinary.game.testgamedemo.TestGameDemoMIDletFactory.java
org.allbinary.game.testgamedemo.TestGameDemoMIDlet.java
org.allbinary.game.testgamedemo.canvas.TestDemoPaintable.java
org.allbinary.game.testgamedemo.canvas.TestGameDemoGameCanvas.java
org.allbinary.game.testgamedemo.canvas.TestGameDemoHelpPaintable.java
org.allbinary.game.testgamedemo.canvas.TestGameDemoInputMappingHelpPaintable.java
org.allbinary.game.testgamedemo.canvas.TestGameDemoSoftwareInfo.java
org.allbinary.game.testgamedemo.canvas.TestGameDemoStartCanvas.java
org.allbinary.game.testgamedemo.canvas.TitleAnimationFactory.java
org.allbinary.game.testgamedemo.canvas.TitleVectorData.java
org.allbinary.game.testgamedemo.configuration.TestGameDemoGameFeatures.java
org.allbinary.game.testgamedemo.configuration.TestGameDemoGameFeatures.java
org.allbinary.game.testgamedemo.configuration.TestGameDemoGameFeatures.java
org.allbinary.game.testgamedemo.configuration.TestGameDemoGameFeatures.java
org.allbinary.game.testgamedemo.init.J2METestGameDemoStaticInitializer.java
org.allbinary.game.testgamedemo.init.J2METestGameDemoStaticInitializer.java
org.allbinary.game.testgamedemo.init.J2METestGameDemoStaticInitializer.java
org.allbinary.game.testgamedemo.init.TestGameDemoAndroidAnimationInterfaceFactoryEarlyResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoAndroidAnimationInterfaceFactoryResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoAndroidStaticInitializer.java
org.allbinary.game.testgamedemo.init.TestGameDemoJ2MEAnimationInterfaceFactoryEarlyResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoJ2MEAnimationInterfaceFactoryEarlyResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoJ2MEAnimationInterfaceFactoryEarlyResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoJ2MEAnimationInterfaceFactoryResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoJ2MEAnimationInterfaceFactoryResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoJ2MEAnimationInterfaceFactoryResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoResourceInitialization.java
org.allbinary.game.testgamedemo.init.TestGameDemoStaticInitializerFactory.java
org.allbinary.game.testgamedemo.init.TestGameDemoStaticInitializerFactory.java
org.allbinary.game.testgamedemo.init.TestGameDemoStaticInitializerFactory.java
org.allbinary.game.testgamedemo.init.TestGameDemoStaticInitializerFactory.java
org.allbinary.game.testgamedemo.init.TestGameDemoStaticInitializer.java
org.allbinary.game.testgamedemo.input.TestGameDemoGameInputMappingFactory.java
org.allbinary.game.testgamedemo.layer.TestGameDemoLayerManager.java
org.allbinary.game.testgamedemo.level.TestGameDemoLevelBuilder.java
org.allbinary.game.testgamedemo.resource.TestGameDemoAndroidEarlyResourceInitialization.java
org.allbinary.game.testgamedemo.resource.TestGameDemoAndroidResourceInitialization.java
org.allbinary.game.testgamedemo.resource.TestGameDemoJ2MEEarlyResourceInitialization.java
org.allbinary.game.testgamedemo.resource.TestGameDemoJ2MEEarlyResourceInitialization.java
org.allbinary.game.testgamedemo.resource.TestGameDemoJ2MEEarlyResourceInitialization.java
org.allbinary.game.testgamedemo.resource.TestGameDemoJ2MEResourceInitialization.java
org.allbinary.game.testgamedemo.resource.TestGameDemoJ2MEResourceInitialization.java
org.allbinary.game.testgamedemo.resource.TestGameDemoJ2MEResourceInitialization.java
org.allbinary.input.motion.button.TestGameDemoMultiTouchButtonsBuilder.java
org.allbinary.input.motion.button.TestGameDemoNeededMultiTouchButtonsBuilder.java
org.allbinary.input.motion.button.TestGameDemoNeededTouchButtonsBuilder.java
org.allbinary.input.motion.button.TestGameDemoNeededTouchButtonsBuilder.java
org.allbinary.input.motion.button.TestGameDemoNeededWithSensorTouchButtonsBuilder.java
org.allbinary.input.motion.button.TestGameDemoTouchButtonsBuilder.java
org.allbinary.input.motion.button.TestGameDemoTouchButtonsBuilder.java
org.allbinary.input.motion.button.TestGameDemoWithSensorTouchButtonsBuilder.java
org.allbinary.input.motion.button.TouchButtonAllStopResource.java
org.allbinary.logic.system.security.licensing.AbeClientInformationInterfaceFactory.java
org.allbinary.logic.system.security.licensing.AbeClientInformationInterfaceFactory.java
org.allbinary.logic.system.security.licensing.TestGameDemoAndroidMobileClientInformation.java
org.allbinary.logic.system.security.licensing.TestGameDemoPCClientInformation.java
org.allbinary.media.audio.TestGameDemoSoundsFactoryFactory.java
org.allbinary.media.audio.TestGameDemoSoundsFactoryFactory.java
org.allbinary.media.audio.TestGameDemoSoundsFactoryFactory.java
org.allbinary.media.audio.TestGameDemoSoundsFactoryFactory.java
org.allbinary.media.audio.TestGameDemoSoundsFactory.java
org.allbinary.media.audio.TestSound.java
playn.core.TestGameDemoMidletFactory.java
playn.core.TestGameDemoProcessor.java
playn.core.TestGameDemo.java
playn.html.TestGameDemoGameHtml.java
playn.java.TestGameDemoJ2SE.java
playn.shared.Protocol.java