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) |
001 package org.deken.sidescroller.sprites; 002 003 import java.awt.Graphics2D; 004 import org.deken.game.map.MapElement; 005 import org.deken.game.map.MapSize; 006 import org.deken.game.sprites.BaseActor; 007 import org.deken.game.sprites.Sprite; 008 import org.deken.game.sprites.SpriteSize; 009 import org.deken.sidescroller.AdventureMap; 010 import org.deken.sidescroller.movement.JumpMovement; 011 012 /** 013 * <p> 014 * Title: Jumper</p> 015 * 016 * <p> 017 * Description: </p> 018 * 019 * Copyright: Copyright (c) Jul 29, 2014 020 * 021 * @author Gary Deken <gary@abberkeep.us> 022 * @version 1.0 023 */ 024 public class Jumper extends BaseActor { 025 private AdventureMap playMap; 026 private static final int MOTION_RUN = 0; 027 private static final int MOTION_JUMP = 1; 028 private boolean active = true; 029 030 public Jumper(SpriteSize size) { 031 super(size); 032 } 033 034 @Override 035 public BaseActor copy() { 036 Jumper newJumper = new Jumper(size.copy()); 037 copyBase(newJumper); 038 return newJumper; 039 } 040 041 @Override 042 public void draw(Graphics2D graphics, int xOffset, int yOffset) { 043 if (((JumpMovement) movement).isJumping() || ((JumpMovement) movement).isFalling()) { 044 int x = (int) Math.round(getXLocation()) + xOffset; 045 int y = (int) Math.round(getYLocation()) + yOffset; 046 moveMotion[1].draw(graphics, x, y); 047 } 048 else { 049 super.draw(graphics, xOffset, yOffset); 050 } 051 } 052 053 public void setActive(boolean active) { 054 this.active = active; 055 ((JumpMovement) movement).setActive(active); 056 } 057 058 public void setPlayMap(AdventureMap playMap) { 059 this.playMap = playMap; 060 } 061 062 @Override 063 public void update(long elaspeTime) { 064 if (active) { 065 if (! ((JumpMovement) movement).isAirBorne()) { 069 moveMotion[MOTION_JUMP].setDirection(movement.getDirection()); 070 // if the player is not jumping check if tile below him. 071 if (isNoTileBelow()) { 072 ((JumpMovement) movement).setFalling(true); 073 } 074 } 075 super.update(elaspeTime); 076 } 077 } 078 079 @Override 080 protected void updateCurrentMotion() { 081 if (((JumpMovement) movement).isAirBorne()) { 082 currentMoveMotion = MOTION_JUMP; 083 } 084 else { 085 currentMoveMotion = MOTION_RUN; 086 } 087 } 088 089 private boolean isNoTileBelow() { 090 MapSize mapSize = playMap.getMapSize(); 091 // player is two tiles tall. 092 int yTile = mapSize.getYTileFromPixels(getLocation().y) + 1; 093 int xTile = mapSize.getXTileFromPixels(getLocation().x); 094 MapElement mapEl = playMap.getTile(xTile, yTile + 1, 0); 095 if (mapEl == null) { 096 mapEl = playMap.getTile(xTile + 1, yTile + 1, 0); 097 if (mapEl == null) { 098 mapEl = playMap.getTile(xTile + 2, yTile + 1, 0); 099 } 100 } 101 return mapEl == null; 102 } 103 104 @Override 105 protected void spriteCollison(Sprite collideSprite) { 106 if (collideSprite instanceof FireBall) { 107 FireBall fireBall = (FireBall) collideSprite; 108 fireBall.setMissed(false); 109 } 111 } 112 113 } |
Back |