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)

MapSetup.java
006 package org.deken.sidescroller.setup;
007 
008 import java.awt.Color;
009 import java.awt.event.KeyEvent;
010 import org.deken.game.animation.RectangleShapeAnimation;
011 import org.deken.game.background.LayeredBackground;
012 import org.deken.game.background.ParallaxBackground;
013 import org.deken.game.background.ParallaxWrapBackground;
014 import org.deken.game.collision.Simple2DCollisionDetection;
015 import org.deken.game.map.GameLocation;
016 import org.deken.game.map.renderer.ScrollTileMapRenderer;
017 import org.deken.game.motion.Motion;
018 import org.deken.game.motion.StaticMotion;
019 import org.deken.game.movement.GameVector;
020 import org.deken.game.movement.Movement;
021 import org.deken.game.movement.NoMovement;
022 import org.deken.game.movement.SimpleMovement;
023 import org.deken.game.sound.Sound;
024 import org.deken.game.sprites.Actor;
025 import org.deken.game.sprites.BaseActor;
026 import org.deken.game.sprites.SpriteSize;
027 import org.deken.gameDoc.document.GameDocument;
028 import org.deken.sidescroller.AdventureMap;
029 import org.deken.sidescroller.movement.JumpMovement;
030 import org.deken.sidescroller.sprites.FireBall;
031 import org.deken.sidescroller.sprites.Jumper;
032 
033 /**
034  <p>
035  * Title: MapSetup</p>
036  *
037  <p>
038  * Description: </p>
039  *
040  * Copyright: Copyright (c) Aug 15, 2014
041  *
042  @author Gary Deken <gary@abberkeep.us>
043  @version 1.0
044  */
045 public class MapSetup {
046    private GameDocument gameDocument;
047 
048    public MapSetup(GameDocument gameDocument) {
049       this.gameDocument = gameDocument;
050    }
051 
052    public AdventureMap buildBaseMap() {
053       gameDocument.addClassMapping("BaseMap", GameDocument.ELEMENT.GAMEMAP, AdventureMap.class);
054       AdventureMap playMap = (AdventureMapgameDocument.getGameMap("BaseMap");
055       ScrollTileMapRenderer renderer = new ScrollTileMapRenderer(playMap);
056       playMap.setMapRenderer(renderer);
057       Simple2DCollisionDetection collisionDetect = new Simple2DCollisionDetection(playMap);
058       playMap.setCollisionMap(collisionDetect);
059       return playMap;
060    }
061 
062    public AdventureMap buildGameMap() {
063       AdventureMap playMap = buildBaseMap();
064       playMap.setLayout(gameDocument.getLayout("BaseLayout"));
065       Jumper player = getPlayer(playMap);
066       playMap.setPlayer(player, new GameLocation(119));
067       gameDocument.addClassMapping("FireBall", GameDocument.ELEMENT.SPRITE, FireBall.class);
068 
069       for (int i = 0; i < 10; i++) {
070          playMap.addFireball(getFireBall());
071       }
072       setupBackgrounds(playMap, player);
073       // states
074 
075       return playMap;
076    }
077 
078    public Actor buildNullPlayer() {
079       Actor a = new BaseActor(new SpriteSize(11));
080       RectangleShapeAnimation an = new RectangleShapeAnimation(11, Color.BLUE, true);
081       Movement m = new NoMovement();
082       Motion mo = new StaticMotion(an);
083 
084       a.setMotion(mo);
085       a.setMovement(m);
086 
087       return a;
088    }
089 
090    public void setupBackgrounds(AdventureMap playMap, Actor player) {
091       LayeredBackground background = new LayeredBackground();
092       ParallaxBackground mountainBackground = (ParallaxBackgroundgameDocument.getBackground("Mountains");
093 
094       mountainBackground.setControllingSprite(player);
095       background.addBackground(mountainBackground);
096 
097       ParallaxWrapBackground housesBackground = (ParallaxWrapBackgroundgameDocument.getBackground("Houses");
098 
099       housesBackground.setControllingActor(player);
100       housesBackground.setSpeed(.4);
101       background.addBackground(housesBackground);
102 
103       ParallaxWrapBackground treesBackground = (ParallaxWrapBackgroundgameDocument.getBackground("Trees");
104       treesBackground.setControllingActor(player);
105       treesBackground.setSpeed(.8);
106       background.addBackground(treesBackground);
107 
108       playMap.setBackground(background);
109    }
110 
111    private FireBall getFireBall() {
112       // add FireBalls
113       FireBall fireBall = (FireBallgameDocument.getSprite("FireBall");
114       // add movement. Movement will move across the screen in one direction, right to left.
115       SimpleMovement movement = new SimpleMovement(new GameVector(GameVector.WEST, 0.3));
116 
117       fireBall.setMovement(movement);
118 
119       return fireBall;
120    }
121 
122    private Jumper getPlayer(AdventureMap playMap) {
123       // create Jumper Player.
124       gameDocument.addClassMapping("Guy", GameDocument.ELEMENT.SPRITE, Jumper.class);
125       Jumper player = (JumpergameDocument.getSprite("Guy");
126       player.setPlayMap(playMap);
127       Sound jumpSound = gameDocument.getSound("Jump");
128       JumpMovement movement = new JumpMovement(KeyEvent.VK_RIGHT, KeyEvent.VK_LEFT, KeyEvent.VK_SPACE, player);
129       movement.setSpeed(.2);
130       movement.setJumpSound(jumpSound);
131       player.setMovement(movement);
132       return player;
133    }
134 
135 }
Back