Skip to content

Instantly share code, notes, and snippets.

@gamesbyangelina
Created April 3, 2012 13:29
Show Gist options
  • Save gamesbyangelina/2291987 to your computer and use it in GitHub Desktop.
Save gamesbyangelina/2291987 to your computer and use it in GitHub Desktop.
APACE Game Example (work in progress)
package ccg.angelina.staticgame;
import org.newdawn.slick.Animation;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import apace.PACGame;
import apace.model.Hotspot;
import apace.model.Item;
import apace.model.Location;
import apace.model.cast.CastManager;
import apace.model.cast.Character.ANIMTYPE;
import apace.model.cast.Character.DIR;
import apace.model.cast.NPC;
import apace.model.cast.PlayerCharacter;
import apace.model.conversation.ConversationManager;
import apace.model.conversation.ConversationNode;
import apace.model.script.ScriptBuilder;
import apace.model.script.ScriptedSequence;
import apace.model.world.WalkableArea;
public class MurderAtTheManor extends PACGame {
public MurderAtTheManor(String title){
super(title);
}
public static void main(String[] args) throws SlickException
{
AppGameContainer app =
new AppGameContainer(new MurderAtTheManor("Murder At The Manor - An APACE Mystery"));
app.setDisplayMode(640, 480, false);
app.setVSync(true);
app.setShowFPS(false);
app.setFullscreen(false);
app.start();
}
@Override
public void setupGameData(){
try{
setupPlayer();
setupRooms();
}
catch(Exception e){
e.printStackTrace();
}
}
public void setupPlayer() throws SlickException{
PlayerCharacter ego = new PlayerCharacter(200, 200, 16, 16);
//Single-frame walking animations for all four directions.
Animation right = new Animation(false);
right.addFrame(new Image("resources/player_r.png"), 150);
Animation left = new Animation(false);
left.addFrame(new Image("resources/player_r.png"), 150);
Animation down = new Animation(false);
down.addFrame(new Image("resources/player_r.png"), 150);
Animation up = new Animation(false);
up.addFrame(new Image("resources/player_r.png"), 150);
ego.addAnimation(ANIMTYPE.WALKING, right, left, up, down);
ego.addAnimation(ANIMTYPE.STANDING, right, left, up, down);
ego.setCurrentAnimation(ANIMTYPE.STANDING);
setPlayerCharacter(ego);
}
public void setupRooms() throws SlickException{
WalkableArea walk = new WalkableArea(640, 480, 32);
walk.makeWalkable(96,96, 480, 320);
Location hall = new Location("The Grand Hall", new Image("resources/room1.png"));
locationList.put(0, hall);
hall.addWalkable(walk);
/*
* The Hall
*
* The Hall is where our suspects congregate, as well as Detective Cahill. It also
* serves as a hub for the other rooms in the game.
*
*/
Hotspot doorToDiningRoom = new Hotspot("diningroom_door", 7*32, 2*32, 32, 32);
doorToDiningRoom.walktox = 7*32 + 16;
doorToDiningRoom.walktoy = 3*32;
doorToDiningRoom.walkTo = true;
doorToDiningRoom.setUse(new ScriptBuilder().enterRoomAt(1, 9*32, 11*32).buildScript());
hall.hotspots.add(doorToDiningRoom);
/*
* Detective Cahill - introduces the crime scene to the player.
*/
NPC detective = CastManager.newNPC("c_detective", "Cahill", 200, 100, 8, 8);
Image frame = new Image("resources/detective.png");
Animation det_right = new Animation(false);
det_right.addFrame(frame, 150);
Animation det_left = new Animation(false);
det_left.addFrame(frame, 150);
Animation det_down = new Animation(false);
det_down.addFrame(frame, 150);
Animation det_up = new Animation(false);
det_up.addFrame(frame, 150);
detective.addAnimation(ANIMTYPE.WALKING, det_right, det_left, det_up, det_down);
detective.addAnimation(ANIMTYPE.STANDING, det_right, det_left, det_up, det_down);
detective.setCurrentAnimation(ANIMTYPE.STANDING);
detective.currentDirection = DIR.RIGHT;
ScriptBuilder examineNPC = new ScriptBuilder()
.say("It's Detective Cahill. He secures all my crime scenes.");
detective.examine = examineNPC.buildScript();
ScriptBuilder talkToNPC = new ScriptBuilder()
.say("Hey, Cahill.")
.say("Detective.", detective.code)
.startConversation(0);
detective.talkTo = talkToNPC.buildScript();
/*
* Eddie describes the crime to the player.
*/
ConversationNode cahill_root = ConversationManager.newNode();
ScriptBuilder brief = new ScriptBuilder()
.say("Victim is a Lord Edward Avon.", detective.code)
.say("Body's in the dining room, on the left.", detective.code)
.say("Any witnesses?")
.say("Lady Avon says she heard a scream, claims she was in the study at the time.", detective.code)
.say("She's over there if you want to talk to her.", detective.code)
.say("Thanks, Eddie.")
.say("Don't mention it.", detective.code)
.disableOption(0, "What's the situation?")
.startConversation(0);
cahill_root.addOption("What's the situation?", brief.buildScript());
ScriptBuilder endConv = new ScriptBuilder().say("Sure thing.", detective.code);
cahill_root.addOption("Nothing else for now, Eddie.", endConv.buildScript());
hall.npcs.add(detective);
/*
* Lady Avon, our prime suspect.
*/
NPC lady = CastManager.newNPC("c_lady", "Lady Avon", 500, 150, 16, 16);
Image ladyimg = new Image("resources/lady.png");
Animation lady_right = new Animation(false);
lady_right.addFrame(ladyimg, 150);
Animation lady_left = new Animation(false);
lady_left.addFrame(ladyimg, 150);
Animation lady_down = new Animation(false);
lady_down.addFrame(ladyimg, 150);
Animation lady_up = new Animation(false);
lady_up.addFrame(ladyimg, 150);
lady.addAnimation(ANIMTYPE.WALKING, lady_right, lady_left, lady_up, lady_down);
lady.addAnimation(ANIMTYPE.STANDING, lady_right, lady_left, lady_up, lady_down);
lady.setCurrentAnimation(ANIMTYPE.STANDING);
lady.currentDirection = DIR.RIGHT;
lady.examine = new ScriptBuilder().say("It's Lady Avon, the socialite and columnist.").buildScript();
lady.talkTo = new ScriptBuilder().say("Good evening, Ma'am").startConversation(1).buildScript();
ConversationNode avon_root = ConversationManager.newNode();
ScriptBuilder give_statement = new ScriptBuilder()
.say("I already told Detective Cahill.", lady.code)
.say("I appreciate that, Ma'am, but it would help if you told me one more time.")
.say("I was writing a letter to my son in the study when I heard my husband scream.", lady.code)
.say("I ran in and found him like that. I called the police immediately.", lady.code)
.enableOption(1, "Ma'am, you don't seem very concerned.")
.enableOption(1, "You didn't disturb the body in any way?")
.disableOption(1, "Could you tell me what happened?")
.startConversation(1);
avon_root.addOption("Could you tell me what happened?", give_statement.buildScript());
ScriptBuilder disturb = new ScriptBuilder().say("Absolutely not.", lady.code).startConversation(1);
avon_root.addOption("You didn't disturb the body in any way?", disturb.buildScript(), false);
ScriptBuilder concern = new ScriptBuilder()
.say("How dare you!", lady.code)
.say("This was all very sudden. I am still in shock.", lady.code)
.startConversation(1);
avon_root.addOption("Ma'am, you don't seem very concerned.", concern.buildScript(), false);
avon_root.addOption("Thankyou for your time, Ma'am.", new ScriptedSequence());
hall.npcs.add(lady);
/*
* The Dining Room
*
* This is our crime scene. Lord Avon has been found dead here.
*
*/
Location diningRoom = new Location("The Dining Room", new Image("resources/dining_room.png"));
locationList.put(1, diningRoom);
diningRoom.addWalkable(walk);
Item lordAvonBody = new Item("i_corpse", "Lord Avon's Body", new Image("resources/lord.png"), 10*32, 8*32);
diningRoom.items.add(lordAvonBody);
Location study = new Location("The Study", new Image("resources/room2.png"));
locationList.put(2, study);
study.addWalkable(walk);
currentLocation = hall;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment