Old Style Game Framework How To..

Creating a Game with Old Style Game Framework.

This walk through create a side scroller game, where the player runs across the screen and jumps over obstacles. The walk through uses the Old Style Game Framework (1.0.2), Game Doc (1.2.3) and Game Designer (1.2.2).

Updated versions: Old Style Framework (1.1), Game Doc (1.3) and Game Designer (1.3)

006 package org.deken.sidescroller.states;
007 
008 import org.deken.game.component.GLabel;
009 import org.deken.game.component.layout.Layout;
010 import org.deken.game.input.InputAction;
011 import org.deken.game.input.InputListener;
012 import org.deken.game.input.InputMouseAction;
013 import org.deken.game.map.GameLocation;
014 import org.deken.game.sprites.Actor;
015 import org.deken.game.state.GameState;
016 import org.deken.gameDoc.document.GameDocument;
017 import org.deken.sidescroller.AdventureMap;
018 import org.deken.sidescroller.setup.MapSetup;
019 
020 /**
021  <p>
022  * Title: Start</p>
023  *
024  <p>
025  * Description: </p>
026  *
027  * Copyright: Copyright (c) Apr 29, 2015
028  *
029  @author Gary Deken <gary@abberkeep.us>
030  @version 1.0
031  */
032 public class Start extends GameState implements InputListener {
033    private MapSetup mapSetup;
034    private Playing playing;
035    private AdventureMap playMap;
036    private GLabel lblPress;
037    private boolean active = false;
038    private long time = 0;
039 
040    public Start(GameDocument gameDocument) {
041       mapSetup = new MapSetup(gameDocument);
042       playing = new Playing(gameDocument, mapSetup, this);
043       playMap = mapSetup.buildBaseMap();
044       Actor a = mapSetup.buildNullPlayer();
045       Layout l = gameDocument.getLayout("Title");
046 
047       mapSetup.setupBackgrounds(playMap, a);
048       playMap.setPlayer(a, new GameLocation(22));
049       playMap.setLayout(l);
050       playMap.getActions().addAnyKeyListener(this);
051 
052       lblPress = (GLabelgameDocument.getComponent("lblPressEnter");
053       lblPress.setLocation(new GameLocation(350450));
054    }
055 
056    @Override
057    public void activateState() {
058       gameCanvas.setGameMap(playMap);
059    }
060 
061    @Override
062    public void deactivateState() {
063       playMap.removeComponent(lblPress);
064       active = false;
065       time = 0;
066    }
067 
068    @Override
069    public void update(long elapseTime) {
070       time += elapseTime;
071       if (time > 1000) {
072          active = true;
073          playMap.addComponents(lblPress);
074       }
075    }
076 
077    @Override
078    public String getName() {
079       return "Start";
080    }
081 
082    public void notifyListener(InputMouseAction inputMouseAction) {
083    }
084 
085    @Override
086    public int[] getInputActionIds() {
087       return new int[0];
088    }
089 
090    @Override
091    public void notifyListener(InputAction inputAction) {
092       if (active) {
093          changeState(playing);
094       }
095    }
096 
097    @Override
098    public void addInputAction(InputAction inputAction) {
099       //
100    }
101 
102 }
Back