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)

AdventureMap.java
006 package org.deken.sidescroller;
007 
008 import java.util.ArrayList;
009 import java.util.List;
010 import org.deken.game.component.GLabel;
011 import org.deken.game.map.GameLocation;
012 import org.deken.game.map.MapSize;
013 import org.deken.game.map.TileMap;
014 import org.deken.sidescroller.sprites.FireBall;
015 import org.deken.sidescroller.sprites.Jumper;
016 import org.deken.sidescroller.states.PlayerHit;
017 import org.deken.sidescroller.states.Playing;
018 
019 /**
020  <p>
021  * Title: AdventureMap</p>
022  *
023  <p>
024  * Description: </p>
025  *
026  * Copyright: Copyright (c) Aug 15, 2014
027  *
028  @author Gary Deken <gary@abberkeep.us>
029  @version 1.0
030  */
031 public class AdventureMap extends TileMap {
032    private List<FireBall> fireBalls = new ArrayList<FireBall>();
033    private int fireOnScreen = 0;
034    private int totalFirePassed = 0;
035    private int totalFire;
036    private Playing playing;
037    private PlayerHit playerHit;
038 
039    public AdventureMap(MapSize mapSize) {
040       super(mapSize);
041    }
042 
043    public void addFireball(FireBall fireBall) {
044       fireBalls.add(fireBall);
045       totalFire++;
046    }
047 
048    public void increaseFireballsPassed() {
049       totalFirePassed++;
050       setFireBallCounter(totalFirePassed);
051    }
052 
053    public void fireBallHit() {
054       playing.changeState(playerHit);
055    }
056 
057    public void setStates(Playing game, PlayerHit hit) {
058       this.playing = game;
059       this.playerHit = hit;
060    }
061 
062    @Override
063    public synchronized void update(long elapseTime) {
064       super.update(elapseTime);
065       if (fireOnScreen < 1) {
066          addFireBall();
067       }
068       for (FireBall fireball : fireBalls) {
069          if (fireball.isActive()) {
070             int x = mapRenderer.getEdgeLeft();
071             if (fireball.getXLocation() < x - 50) {
072                removeFireBall(fireball);
073             }
074          }
075       }
076    }
077 
078    private void addFireBall() {
079       if (fireOnScreen < fireBalls.size()) {
080          int x = getMapSize().getXTileFromPixels(mapRenderer.getEdgeRight()) 2;
081          int y = getMapSize().getYTileFromPixels(getPlayer().getYLocation());
082          FireBall fireBall = fireBalls.get(fireOnScreen);
083 
084          fireBall.setActive(true);
085          fireBall.setUp((JumpergetPlayer()this);
086          addSprite(fireBall, new GameLocation(x, y));
087          fireOnScreen++;
088       }
089    }
090 
091    private void removeFireBall(FireBall fireball) {
092       fireball.setActive(false);
093       removeSprite(fireball);
094       fireOnScreen--;
095    }
096 
097    private void setFireBallCounter(int count) {
098       GLabel lbl = (GLabelgetComponentByName("lblFireCount");
099       lbl.setText(Integer.toString(count));
100    }
101 
102 }
Back