global, helper, state code

This commit is contained in:
Melos Han-Tani 2020-04-04 19:53:31 +09:00
parent ad9514e54b
commit 27f3b0d47b
28 changed files with 14342 additions and 0 deletions

537
intra/src/global/Keys.as Normal file
View File

@ -0,0 +1,537 @@
package global
{
import org.flixel.FlxSprite;
import org.flixel.FlxG;
import org.flixel.system.FlxDebugger;
//import flash.ui.GameInput;
//import flash.events.GameInputEvent;
//import flash.ui.GameInputControl;
//import flash.ui.GameInputDevice;
/* A handy dandy "sprite" that keeps track of keypresses,
* and allows easy, global modification of what keypresses do what
* (as to welcome alternate control schemes without heavy rewriting!) */
public class Keys extends FlxSprite
{
// Read by the game for determinig actions
public var UP:Boolean = false;
public var DOWN:Boolean = false;
public var LEFT:Boolean = false;
public var RIGHT:Boolean = false;
public var JP_RIGHT:Boolean = false;
public var JP_LEFT:Boolean = false;
public var JP_DOWN:Boolean = false;
public var JP_UP:Boolean = false;
public var JR_RIGHT:Boolean = false;
public var JR_LEFT:Boolean = false;
public var JR_UP:Boolean = false;
public var JR_DOWN:Boolean = false;
public var JUST_PRESSED_PAUSE:Boolean = false;
public var JUST_RELEASED_PAUSE:Boolean = false;
public var ACTION_1:Boolean = false;
public var ACTION_2:Boolean = false;
public var JP_ACTION_1:Boolean = false;
public var JP_ACTION_2:Boolean = false;
// For joypad crap
public var ALLOW_JP_RIGHT:Boolean = false;
public var ALLOW_JP_LEFT:Boolean = false;
public var ALLOW_JP_DOWN:Boolean = false;
public var ALLOW_JP_UP:Boolean = false;
public var ALLOW_JP_ACTION_1:Boolean = false;
public var ALLOW_JP_ACTION_2:Boolean = false;
public var ALLOW_JP_PAUSE:Boolean = false;
// Bools for mobile input
public var SIG_JP_RIGHT:Boolean = false;
public var SIG_JP_LEFT:Boolean = false;
public var SIG_JP_DOWN:Boolean = false;
public var SIG_JP_UP:Boolean = false;
public static var FORCE_ACTION_1:Boolean = false;
public static var FORCE_ACTION_2:Boolean = false;
public static var FORCE_RIGHT:Boolean = false;
public static var FORCE_DOWN:Boolean = false;
public static var FORCE_UP:Boolean = false;
public static var FORCE_LEFT:Boolean = false;
public static var FORCE_PAUSE:Boolean = false;
/* Index into the serialized controls array to figure out key bindings */
public static var IDX_UP:int = 0;
public static var IDX_DOWN:int = 1;
public static var IDX_LEFT:int = 2;
public static var IDX_RIGHT:int = 3;
public static var IDX_ACTION_1:int = 4;
public static var IDX_ACTION_2:int = 5;
public static var IDX_PAUSE:int = 7;
public function Keys()
{
//initGameInput();
super(-5000, 0);
}
/*
public function initGameInput() {
if (!gameInputInitialized) {
gameInputInitialized = true;
gameInput = new GameInput();
trace("Initialized gameinput");
gameInput.addEventListener(GameInputEvent.DEVICE_ADDED, handleDeviceAdded);
gameInput.addEventListener(GameInputEvent.DEVICE_REMOVED, handleDeviceRemovedEvent);
}
}
public static var gameInputDevice:GameInputDevice;
public static var gameInput:GameInput;
public static var gameInputExists:Boolean = false;
public static var gameInputID:String = "";
public static var gameInputName:String = "";
public static var gameInputInitialized:Boolean = false;
public function handleDeviceAdded(e:GameInputEvent):void {
trace(11111);
if (gameInputExists) return;
gameInputDevice = e.device;
gameInputName = gameInputDevice.name;
gameInputID = gameInputDevice.id;
gameInputExists = true;
trace("Added " + gameInputName+" with ID: " + gameInputID);
}
public function handleDeviceRemovedEvent(e:GameInputEvent):void {
trace("Trying to remove " + e.device.name +" with ID: " + e.device.id);
if (e.device.name == gameInputName && e.device.id == gameInputID) {
trace("Removed!");
gameInputExists = false;
gameInputDevice = null;
} else {
trace("Didn't remove.");
}
}
*/
public static var has_joypad:Boolean = false;
public static var nr_axes:int = 0;
public static var nr_btns:int = 0;
public static function init_joypad():void {
if (Intra.IS_WINDOWS) {
nr_axes = Main.joy.getTotalAxes(0);
nr_btns = Main.joy.getTotalButtons(0);
trace("Joypad 0 has ", nr_axes, " axes ", nr_btns, " buttons");
} else if (Intra.IS_MAC) {
nr_axes = Main.mac_joy_manager.joysticks[0].axes.length;
nr_btns = Main.mac_joy_manager.joysticks[0].buttons.length;
trace("Joypad 0 has ", nr_axes, " axes ", nr_btns, " buttons");
}
if (nr_axes > 4) nr_axes = 4;
}
// Give the state of a certain control binding, based on an index into the joybinds array
public static function get_joy_state(idx:int):Boolean {
if (Intra.IS_WINDOWS || Intra.IS_MAC) {
// Hacky way to ignore uninitizliaed controls
if (Registry.joybinds[IDX_ACTION_1] == Registry.joybinds[IDX_DOWN]) {
return false;
}
// axes first (one state for each dir), then buttons
// ID is an axis state
var id:int = Registry.joybinds[idx];
if (Math.abs(id) - 1 < 2 * nr_axes) {
var axis_state:Number;
var new_id:int = Math.abs(id) - 1;
if (Intra.IS_WINDOWS) {
axis_state = Main.joy.getAxis(0, int(new_id / 2));
} else if (Intra.IS_MAC) {
axis_state = Main.mac_joy_manager.joysticks[0].getAxis(int(new_id / 2));
}
if (id < 0) { // Threshold is negative
if (axis_state < -0.25) {
return true;
}
} else {
if (axis_state > 0.25) {
return true;
}
}
} else {
var button_state:Boolean;
id = id - 1 - 2 * nr_axes;
if (Intra.IS_WINDOWS) {
return Main.joy.buttonIsDown(0, id);
} else if (Intra.IS_MAC) {
return Main.mac_joy_manager.joysticks[0].getButton(id);
}
}
} else if (Intra.is_ouya) {
//if (Main.game_input_device != null) {
//var min:Number = Main.game_input_device.getControlAt(Registry.joybinds[idx]).minValue;
//var max:Number = Main.game_input_device.getControlAt(Registry.joybinds[idx]).maxValue;
//var val:Number = Main.game_input_device.getControlAt(Registry.joybinds[idx]).value;
//
// BLIND GUESS!!!
//if (val > min) {
//return true;
//}
//}
//if (idx == IDX_UP) {
//if (joypad.DPAD_UP || joypad.STICK_UP) {
//return true;
//}
//} else if (idx == IDX_RIGHT) {
//return joypad.DPAD_RIGHT || joypad.STICK_RIGHT;
//} else if (idx == IDX_DOWN) {
//return joypad.DPAD_DOWN || joypad.STICK_DOWN;
//} else if (idx == IDX_LEFT) {
//return joypad.DPAD_LEFT || joypad.STICK_LEFT;
//} else if (idx == IDX_ACTION_1) {
//return joypad.BUTTON_O;
//} else if (idx == IDX_ACTION_2) {
//return joypad.BUTTON_U;
//} else if (idx == IDX_PAUSE) {
//if (joypad.BUTTON_Y) {
//return true;
//}
//}
}
return false;
}
public static function joy_any_button():Boolean {
if (Intra.IS_WINDOWS) {
for (var i:int = 0; i < nr_btns; i++) {
if (Main.joy.buttonIsDown(0, i)) {
return true;
}
}
} else if (Intra.IS_MAC) {
for (i = 0; i < nr_btns; i++) {
if (Main.mac_joy_manager.joysticks[0].getButton(i)) {
return true;
}
}
}
return false;
}
public static function joy_any_axis():int {
if (Intra.IS_WINDOWS) {
for (var i:int = 0; i < nr_axes; i++) {
if (Math.abs(Main.joy.getAxis(0, i)) > 0.25) {
if (Main.joy.getAxis(0, i) < 0) {
return -1;
} else {
return 1;
}
}
}
} else if (Intra.IS_MAC) {
for (i = 0; i < nr_axes; i++) {
if (Math.abs(Main.mac_joy_manager.joysticks[0].getAxis(i)) > 0.25) {
if (Main.mac_joy_manager.joysticks[0].getAxis(i) < 0) {
return -1;
} else {
return 1;
}
}
}
}
return 0;
}
// Returns the button ID as ready for serialization (offset by 1, shifted over for being a button)
public static function joy_get_first_active_button_id():int {
var i:int = 0;
if (Intra.IS_WINDOWS) {
for (i = 0; i < nr_btns; i++) {
if (Main.joy.buttonIsDown(0, i)) {
return i + 1 + 2 * nr_axes;
}
}
} else if (Intra.IS_MAC) {
for (i = 0; i < nr_btns; i++) {
if (Main.mac_joy_manager.joysticks[0].getButton(i)) {
return i + 1 + 2 * nr_axes;
}
}
}
return 0;
}
public static function joy_get_first_active_axis_id():int {
var i:int = 0;
if (Intra.IS_WINDOWS) {
for (i = 0; i < nr_axes; i++) {
if (Math.abs(Main.joy.getAxis(0, i)) > 0.7) {
if (Main.joy.getAxis(0, i) < 0) {
return -(1 + i*2); // OFFSET - usually left or down
} else {
return 2 + i*2; // OFFSET + 1 - usually right or up
}
}
}
} else if (Intra.IS_MAC) {
for (i = 0; i < nr_axes; i++) {
if (Math.abs(Main.mac_joy_manager.joysticks[0].getAxis(i)) > 0.7) {
if (Main.mac_joy_manager.joysticks[0].getAxis(i) < 0) {
return -(1 + i * 2);
} else {
return 2 + i * 2;
}
}
}
}
return 0;
}
public static function get_axis_stats():String {
var s:String = "";
var axis_state:Number = 0;
for (var i:int = 0; i < nr_axes; i++) {
if (Intra.IS_WINDOWS) {
axis_state = Main.joy.getAxis(0, i);
} else if (Intra.IS_MAC) {
axis_state = Main.mac_joy_manager.joysticks[0].getAxis(i);
}
if (axis_state < -0.7) {
s += "-";
} else if (axis_state > 0.7) {
s += "+";
} else {
s += "0";
}
}
return s;
}
public static function get_btn_stats():String {
var s:String = "";
var bs:Boolean = false;
for (var i:int = 0; i < nr_btns; i++) {
if (Intra.IS_WINDOWS) {
bs = Main.joy.buttonIsDown(0, i);
} else if (Intra.IS_MAC) {
bs = Main.mac_joy_manager.joysticks[0].getButton(i);
}
if (bs){
s += "1";
} else {
s += "0";
}
if (i == 15) {
s += "\n ";
}
}
return s;
}
override public function update():void {
//if (!Intra.is_ouya) {
UP = FlxG.keys.pressed(Registry.controls[IDX_UP]);
DOWN = FlxG.keys.pressed(Registry.controls[IDX_DOWN]);
LEFT = FlxG.keys.pressed(Registry.controls[IDX_LEFT]);
RIGHT = FlxG.keys.pressed(Registry.controls[IDX_RIGHT]);
JP_UP = FlxG.keys.justPressed(Registry.controls[IDX_UP]);
JP_DOWN = FlxG.keys.justPressed(Registry.controls[IDX_DOWN]);
JP_LEFT = FlxG.keys.justPressed(Registry.controls[IDX_LEFT]);
JP_RIGHT = FlxG.keys.justPressed(Registry.controls[IDX_RIGHT]);
JR_UP = FlxG.keys.justReleased(Registry.controls[IDX_UP]);
JR_RIGHT = FlxG.keys.justReleased(Registry.controls[IDX_RIGHT]);
JR_LEFT = FlxG.keys.justReleased(Registry.controls[IDX_LEFT]);
JR_DOWN = FlxG.keys.justReleased(Registry.controls[IDX_DOWN]);
JUST_PRESSED_PAUSE = FlxG.keys.justPressed(Registry.controls[IDX_PAUSE]);
if (Registry.disable_menu) {
JUST_PRESSED_PAUSE = false;
}
if (FORCE_PAUSE && false == Registry.disable_menu) {
FORCE_PAUSE = false;
JUST_PRESSED_PAUSE = true;
}
JUST_RELEASED_PAUSE = FlxG.keys.justReleased(Registry.controls[IDX_PAUSE]);
JP_ACTION_1 = FlxG.keys.justPressed(Registry.controls[IDX_ACTION_1]);
JP_ACTION_2 = FlxG.keys.justPressed(Registry.controls[IDX_ACTION_2]);
ACTION_1 = FlxG.keys.pressed(Registry.controls[IDX_ACTION_1]);
ACTION_2 = FlxG.keys.pressed(Registry.controls[IDX_ACTION_2]);
//}
if ((Intra.IS_WINDOWS && Main.joy != null && Keys.has_joypad) || (Intra.IS_MAC && Keys.has_joypad && Main.mac_joy_manager.joysticks[0] != null) || (0 && Intra.is_ouya)) {
if (get_joy_state(IDX_LEFT)) {
if (!LEFT && ALLOW_JP_LEFT) {
JP_LEFT = true;
ALLOW_JP_LEFT = false;
}
LEFT = true;
} else {
if (!ALLOW_JP_LEFT) {
JR_LEFT = true;
}
ALLOW_JP_LEFT = true;
}
if (get_joy_state(IDX_RIGHT)) {
if (!RIGHT && ALLOW_JP_RIGHT) {
JP_RIGHT = true;
ALLOW_JP_RIGHT = false;
}
RIGHT = true;
} else {
if (!ALLOW_JP_RIGHT) {
JR_RIGHT = true;
}
ALLOW_JP_RIGHT = true;
}
if (get_joy_state(IDX_DOWN)) {
if (!DOWN && ALLOW_JP_DOWN) {
JP_DOWN = true;
ALLOW_JP_DOWN= false;
}
DOWN = true;
} else {
if (!ALLOW_JP_DOWN) {
JR_DOWN = true;
}
ALLOW_JP_DOWN = true;
}
if (get_joy_state(IDX_UP)) {
if (!UP && ALLOW_JP_UP) {
JP_UP = true;
ALLOW_JP_UP = false;
}
UP = true;
} else {
if (!ALLOW_JP_UP) {
JR_UP = true;
}
ALLOW_JP_UP = true;
}
if (get_joy_state(IDX_ACTION_1)) {
if (!ACTION_1 && ALLOW_JP_ACTION_1) {
JP_ACTION_1 = true;
ALLOW_JP_ACTION_1 = false;
}
ACTION_1 = true;
} else {
ALLOW_JP_ACTION_1 = true;
}
if (get_joy_state(IDX_ACTION_2)) {
if (!ACTION_2 && ALLOW_JP_ACTION_2) {
JP_ACTION_2 = true;
ALLOW_JP_ACTION_2 = false;
}
ACTION_2 = true;
} else {
ALLOW_JP_ACTION_2 = true;
}
if (get_joy_state(IDX_PAUSE)) {
if (ALLOW_JP_PAUSE) {
ALLOW_JP_PAUSE = false;
JUST_PRESSED_PAUSE = true;
}
} else {
ALLOW_JP_PAUSE = true;
}
//var a:Array = new Array();
//var asdf:int = 0;
//for (var asdf:int = 0; asdf < nr_btns; asdf++) {
//a.push(int(Main.joy.buttonIsDown(0, asdf)));
//}
//for (asdf = 0; asdf < nr_axes + 2; asdf++) {
//a.push(Main.joy.getAxis(0, asdf));
//}
//trace(a);
}
if (Intra.is_ouya) {
if (FORCE_ACTION_2) {
ACTION_2 = true;
JP_ACTION_2 = true;
FORCE_ACTION_2 = false;
}
}
if (Intra.is_mobile) {
if (FORCE_ACTION_1) {
ACTION_1 = true;
JP_ACTION_1 = true;
FORCE_ACTION_1 = false;
}
if (FORCE_ACTION_2) {
ACTION_2 = true;
JP_ACTION_2 = true;
FORCE_ACTION_2 = false;
}
if (SIG_JP_DOWN) {
SIG_JP_DOWN = false;
JP_DOWN = true;
}
if (SIG_JP_UP) {
SIG_JP_UP = false;
JP_UP = true;
}
if (SIG_JP_RIGHT) {
SIG_JP_RIGHT = false;
JP_RIGHT = true;
}
if (SIG_JP_LEFT) {
SIG_JP_LEFT = false;
JP_LEFT = true;
}
if (FORCE_RIGHT) {
RIGHT = true;
}
if (FORCE_DOWN) {
DOWN = true;
}
if (FORCE_UP) {
UP = true;
}
if (FORCE_LEFT) {
LEFT = true;
}
}
if (Intra.allow_fuck_it_mode && FlxG.keys.justPressed("SPACE")) {
Registry.FUCK_IT_MODE_ON = !Registry.FUCK_IT_MODE_ON;
}
super.update();
}
}
}

File diff suppressed because one or more lines are too long

161
intra/src/helper/ANEFix.as Normal file
View File

@ -0,0 +1,161 @@
package helper
{
import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
import flash.events.IOErrorEvent;
import flash.events.NativeProcessExitEvent;
import flash.events.ProgressEvent;
import flash.external.ExtensionContext;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
/**
* ...
* @author Melos Han-Tani
*/
public class ANEFix
{
private static var
callback_error:Function = null,
callback_ioerror:Function = null,
callback_output:Function = null;
/** @param extensionID:String id of the ane extension to fix
* @param onExit:Function callback function with first arguments the value of extensionID and for the second the boolean state of the fix operation
**/
public static function fixANE(extensionID:String, onExit:Function = null,is_steam:Boolean = false):Boolean {
if (!NativeProcess.isSupported) {
if (onExit != null) {
trace("Nope! 30");
onExit(extensionID, false);
}
trace("Nope! 33");
return false;
}
// init event listners
if (callback_output==null)
callback_output =
function(event:ProgressEvent):void {
var process:NativeProcess = event.target as NativeProcess;
trace("OUT -", process.standardOutput.readUTFBytes(process.standardError.bytesAvailable));
};
if (callback_error==null)
callback_error =
function(event:ProgressEvent):void {
var process:NativeProcess = event.target as NativeProcess;
trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable));
};
if (callback_ioerror==null)
callback_ioerror =
function(event:IOErrorEvent):void {
trace(event.toString());
};
var ext_dir:File;
try {
ext_dir = ExtensionContext.getExtensionDirectory(extensionID);
} catch (e:*) {
if (onExit != null) {
trace("Nope! 59");
onExit(extensionID, false);
}
trace("Nope! 63");
return false;
}
if (!ext_dir.isDirectory) {
if (onExit != null) {
trace("Nope! 64");
onExit(extensionID, false);
}
trace("Nope! 71");
return false;
}
var ane_dir:File = ext_dir.resolvePath("META-INF/ANE/");
var ext_stream:FileStream = new FileStream();
ext_stream.open(ane_dir.resolvePath("extension.xml"), FileMode.READ);
var ext_xml:XML = XML(ext_stream.readUTFBytes(ext_stream.bytesAvailable));
ext_stream.close();
var defaultNS:Namespace = ext_xml.namespace("");
var framework:String = ext_xml.defaultNS::platforms.defaultNS::platform.(@name=="MacOS-x86").defaultNS::applicationDeployment.defaultNS::nativeLibrary.text();
if (!framework) {
if (onExit != null) {
trace("Nope! 80");
onExit(extensionID, false);
}
trace("Nope! 85");
return false;
}
var framework_dir:File = ane_dir.resolvePath('MacOS-x86/'+framework);
// list of symlink files
var symlink:Vector.<String> = new Vector.<String>(3, true);
symlink[0] = 'Resources';
symlink[1] = framework_dir.name.substr(0, framework_dir.name.length-framework_dir.extension.length-1);
symlink[2] = 'Versions/Current';
var fileToFix:int = symlink.length,
fileFixed:int = 0,
fileFailed:int = 0;
symlink.every(
function(item:String, index:int, a:Vector.<String>):Boolean {
var f:File = framework_dir.resolvePath(item);
if (!f.isSymbolicLink) {
var fs:FileStream = new FileStream();
fs.open(f, FileMode.READ);
var lnk:String = fs.readUTFBytes(fs.bytesAvailable);
fs.close();
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = new File('/bin/ln');
nativeProcessStartupInfo.workingDirectory = f.parent;
nativeProcessStartupInfo.arguments = new Vector.<String>(3, true);
nativeProcessStartupInfo.arguments[0] = "-Fs";
nativeProcessStartupInfo.arguments[1] = lnk;
nativeProcessStartupInfo.arguments[2] = f.name;
var process:NativeProcess = new NativeProcess();
process.start(nativeProcessStartupInfo);
//process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, callback_output);
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, callback_error);
process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, callback_ioerror);
process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, callback_ioerror);
process.addEventListener(
NativeProcessExitEvent.EXIT,
function (event:NativeProcessExitEvent):void {
if (event.exitCode==0)
fileFixed++;
else
fileFailed++
if (fileFixed+fileFailed==fileToFix) {
if (fileFailed==0) {
trace('ANE '+extensionID+' fixed.');
} else {
trace('Unable to fix ANE ' + extensionID + '!');
}
if (onExit != null) {
trace("Nope! 133");
onExit(extensionID, fileFailed == 0);
}
}
}
);
} else {
trace("A file fixed.? 146");
fileFixed++;
}
return true;
}
);
if (fileFixed == 3) {
if (onExit != null) {
onExit(extensionID, true);
}
}
trace("Exiting: 150");
return true;
}
}
}

View File

@ -0,0 +1,255 @@
package helper
{
import com.amanitadesign.steam.FRESteamWorks;
import com.amanitadesign.steam.SteamConstants;
import com.amanitadesign.steam.SteamEvent;
import flash.desktop.NativeApplication;
import flash.utils.ByteArray;
import global.Registry;
import org.flixel.FlxG;
import org.flixel.FlxGame;
public class Achievements
{
private static var IS_NEWGROUNDS:Boolean = false;
public static var IS_KONG:Boolean = false;
public static var KONG_LOADED:Boolean = false;
public static var IS_STEAM:Boolean = true;
public static const Card_1:int = 0;
public static const Card_7:int = 1;
public static const Extra_health_1:int = 2;
public static const Fast_fields:int = 3;
public static const No_damage_sunguy:int = 4;
public static const Trophy_1:int = 5;
public static const Greenlit:int = 6;
public static const Website:int = 7;
public static const A_GET_BROOM:int = 8;
public static const A_GET_WINDMILL_CARD:int = 9;
public static const A_DEFEAT_BRIAR:int = 10;
public static const A_100_PERCENT_ANY_TIME:int = 11;
public static const A_200_PERCENT:int = 12;
public static const A_GET_RED_CUBE:int = 13;
public static const A_GET_GREEN_CUBE:int = 14;
public static const A_GET_BLUE_CUBE:int = 15;
public static const A_GET_BW_CUBES:int = 16;
public static const A_CONSOLE:int = 17;
public static const A_GET_GOLDEN_POO:int = 18;
public static const A_GET_48_CARDS:int = 19;
public static const A_GET_49TH_CARD:int = 20;
public static const A_ENDING_SUB_15_M:int = 21;
public static const A_100_PERCENT_SUB_3_HR:int = 22;
public static const achvname:Object = { 8:"broom", 9: "windmill", 10: "briar",
11: "100" , 12: "200" , 13: "red", 14: "green", 15: "blue", 16: "bw",
17: "console", 18: "poo", 19: "48", 20: "49", 21: "fast", 22:"100fast"};
public static var Steamworks:FRESteamWorks;
private static var did_init:Boolean = false;
public static var DEBUG_TEXT:String = "";
public static function init(root:*):void {
if (did_init) return;
did_init = true;
}
public static function kong_loaded():void {
KONG_LOADED = true;
}
public static function init_steam():void {
DEBUG_TEXT += "In Init Steam\n";
if (IS_STEAM && Steamworks == null) {
if (Intra.IS_LINUX) {
//return;
}
DEBUG_TEXT += "LOADING STEAM\n";
Steamworks = new FRESteamWorks();
Steamworks.addEventListener(SteamEvent.STEAM_RESPONSE, onSteamResponse);
if (Steamworks.init()) {
if (Steamworks.isReady) {
if (false == Intra.IS_LINUX) {
Steamworks.setCloudEnabledForApp(true);
}
DEBUG_TEXT += "STEAM LOADED\n";
}
//DEBUG_TEXT = DEBUG_TEXT + "atest: " + Steamworks.setAchievement("ACH_WIN_ONE_GAME").toString() + "\n";
//Steamworks.clearAchievement("ACH_WIN_ONE_GAME");
//Steamworks.setStatFloat('FeetTraveled', 42.42);
//Steamworks.storeStats();
//DEBUG_TEXT = DEBUG_TEXT + Steamworks.getStatFloat('FeetTraveled').toString() + "\n";
//
} else {
DEBUG_TEXT += "FAILED\n";
}
}
}
public static function get_completion_rate():int {
// 36 Cards (+2) = 72
// 10 health ups (+1) = 10
// 4 broom upgrades (+4) = 16
// Jump shoes (+2) = 2
// 12 Cards
// 13 weird items - all + 5
var rate:int = 0;
for (var i:int = 0; i < 48; i++) {
if (Registry.card_states[i] == 1) {
if (i < 36) {
rate += 2;
} else {
rate += 4;
}
}
}
rate += (Registry.MAX_HEALTH - 6);
if (Registry.inventory[Registry.IDX_BROOM]) rate += 4;
if (Registry.inventory[Registry.IDX_WIDEN]) rate += 4;
if (Registry.inventory[Registry.IDX_LENGTHEN]) rate += 4;
if (Registry.inventory[Registry.IDX_TRANSFORMER]) rate += 4;
if (Registry.inventory[Registry.IDX_JUMP]) rate += 2;
for (i = 11; i <= Registry.IDX_WHITE; i++) {
if (Registry.inventory[i]) {
rate += 4;
}
}
Achievements.DEBUG_TEXT += rate.toString() + "\n";
return rate;
}
public static function set_steam_achievements():void {
if (IS_STEAM && Steamworks != null && Steamworks.isReady) {
trace("Steam achievement state:", Registry.achivement_state);
for (var i:int = 8; i < 23; i++) {
if (Registry.achivement_state[i]) {
Steamworks.setAchievement(achvname[i]);
}
}
}
}
public static function writeFileToCloud(fileName:String, data:Object):Boolean {
var dataOut:ByteArray = new ByteArray();
dataOut.writeObject(data);
return Steamworks.fileWrite(fileName, dataOut);
}
public static function readFileFromCloud(fileName:String):Object {
var dataIn:ByteArray = new ByteArray();
var dataOut:Object = new Object();
dataIn.position = 0;
dataIn.length = Steamworks.getFileSize(fileName);
DEBUG_TEXT += dataIn.length.toString();
if(dataIn.length>0 && Steamworks.fileRead(fileName,dataIn)){
return dataIn.readObject();
}
return null;
}
public static function is_100_percent():Boolean {
if (Registry.MAX_HEALTH >= 16 && Registry.inventory[Registry.IDX_TRANSFORMER] && Registry.inventory[Registry.IDX_WIDEN] && Registry.inventory[Registry.IDX_LENGTHEN] && Registry.nr_growths >= 37) {
Achievements.unlock(Achievements.A_100_PERCENT_ANY_TIME);
if (Registry.playtime < 3 * 60 * 60) {
Achievements.unlock(Achievements.A_100_PERCENT_SUB_3_HR);
}
return true;
}
return false;
}
public static function is_200_percent():Boolean {
var a:Array = Registry.inventory;
if (is_100_percent() && Registry.nr_growths >= 49 && a[Registry.IDX_BLUE] && a[Registry.IDX_GREEN] && a[Registry.IDX_RED] && a[Registry.IDX_BLACK] && a[Registry.IDX_WHITE] && a[Registry.IDX_KITTY] && a[Registry.IDX_POO] && a[Registry.IDX_AUS_HEART] && a[Registry.IDX_ELECTRIC] && a[Registry.IDX_MARINA] && a[Registry.IDX_MELOS] && a[Registry.IDX_MISSINGNO] && a[Registry.IDX_SPAM]) {
Achievements.unlock(Achievements.A_200_PERCENT);
return true;
}
return false;
}
public static function onSteamResponse(e:SteamEvent):void {
//Achievements.DEBUG_TEXT = DEBUG_TEXT + "STEAMresponse type:" + e.req_type + " response:" + e.response + "\n";
switch(e.req_type){
case SteamConstants.RESPONSE_OnUserStatsStored:
//DEBUG_TEXT = DEBUG_TEXT + "RESPONSE_OnUserStatsStored: " + e.response + "\n";
break;
case SteamConstants.RESPONSE_OnUserStatsReceived:
//DEBUG_TEXT = DEBUG_TEXT + "RESPONSE_OnUserStatsReceived: " + e.response + "\n";
break;
case SteamConstants.RESPONSE_OnAchievementStored:
//DEBUG_TEXT = DEBUG_TEXT + "RESPONSE_OnAchievementStored: " + e.response + "\n";
break;
case 3:
//case SteamConstants.RESPONSE_OnGameOverlayActivated:
//FlxGame.HARD_PAUSED = !FlxGame.HARD_PAUSED; // This is probably not the right hting to do.
break;
default:
}
}
public static function unlock_all():void {
for (var i:int = 8; i < 23; i++) {
unlock(i);
}
}
public static function unlock(id:int):void {
if (!IS_STEAM && false == Intra.is_web) return;
if (IS_STEAM) {
trace("Achievement: ", id, achvname[id]);
if (Steamworks != null && Steamworks.isReady) {
switch (id) {
case A_GET_BROOM://**
Registry.achivement_state[id] = true;
Steamworks.setAchievement(achvname[id]);
break;
case A_GET_WINDMILL_CARD: //**
Registry.achivement_state[id] = true;
Steamworks.setAchievement(achvname[id]);
break;
Registry.achivement_state[id] = true;
Steamworks.setAchievement(achvname[id]);
break;
case A_100_PERCENT_ANY_TIME:// **
Registry.achivement_state[id] = true;
Steamworks.setAchievement(achvname[id]);
break;
case A_100_PERCENT_SUB_3_HR:// **
Registry.achivement_state[id] = true;
Steamworks.setAchievement(achvname[id]);
break;
case A_GET_48_CARDS://
Registry.achivement_state[id] = true;
Steamworks.setAchievement(achvname[id]);
break;
}
}
}
}
}
}

View File

@ -0,0 +1,469 @@
package helper
{
import data.Common_Sprites;
import data.CSV_Data;
import data.TileData;
import entity.decoration.Solid_Sprite;
import entity.interactive.Dungeon_Statue;
import entity.interactive.Terminal_Gate;
import flash.geom.Point;
import global.Registry;
import org.flixel.FlxG;
import org.flixel.FlxGroup;
import org.flixel.FlxPoint;
import org.flixel.FlxSprite;
import org.flixel.FlxTileblock;
import org.flixel.FlxTilemap;
import org.flixel.FlxU;
import states.PushableFlxState;
public class Cutscene extends PushableFlxState
{
/* Cutscene types */
public static const Red_Cave_Left:int = 0;
public static const Red_Cave_Right:int = 1;
public static const Red_Cave_North:int = 2;
public static const Terminal_Gate_Bedroom:int = 3;
public static const Terminal_Gate_Redcave:int = 4;
public static const Terminal_Gate_Crowd:int = 5;
public static const Windmill_Opening:int = 6;
// pointers to functions for transitioning in and out of the cutscene
private var transition_in:Function;
private var transition_out:Function;
private var step_cutscene:Function;
// parameters you set that will be used in the above functions
private var tran_in_args:Array = new Array(1, 2);
private var tran_out_args:Array = new Array(3, 4);
public const s_transition_in:int = -1;
public const s_in_progress:int = 0;
public const s_transition_out:int = 2;
public const s_done:int = 3;
public var state:int = -1;
public var timer:Number;
public var timer_max:Number;
public var pushdown:int = 0;
public var pushee:FlxSprite;
public var entity_1:FlxSprite;
public var entity_2:FlxSprite;
public var entity_3:FlxSprite;
private var ctr_cutscene:int = 0;
private var _parent:*;
public var scene_1:FlxTilemap;
public var scene_2:FlxTilemap;
public var scene_3:FlxTilemap;
public var fade:FlxSprite;
public function Cutscene(v_parent:*) {
_parent = v_parent;
create();
}
/* Initialize the entities with each cutscene */
override public function create():void
{
transition_in = do_nothing;
transition_out = do_nothing;
switch (Registry.CURRENT_CUTSCENE) {
case Red_Cave_Left:
transition_in = red_in;
transition_out = red_out;
step_cutscene = step_red_cave;
timer = timer_max = 0.02;
inst_red_cave_left();
//Load the sprites and store 'em
//Pick a section of map to load from the right map and load it
break;
case Red_Cave_North:
transition_in = red_in;
transition_out = red_out;
step_cutscene = step_red_cave;
timer = timer_max = 0.02;
inst_red_cave_north();
break;
case Red_Cave_Right:
transition_in = red_in;
transition_out = red_out;
step_cutscene = step_red_cave;
timer = timer_max = 0.02;
inst_red_cave_right();
break;
case Terminal_Gate_Bedroom:
case Terminal_Gate_Crowd:
case Terminal_Gate_Redcave:
transition_in = terminal_gate_in;
transition_out = terminal_gate_out;
step_cutscene = step_terminal_gate;
inst_terminal_gate();
break;
case Windmill_Opening:
transition_in = windmill_in;
transition_out = windmill_out;
step_cutscene = step_windmill_opening;
inst_windmill();
break;
}
}
override public function update():void
{
if (state == s_transition_in) {
transition_in.apply(null, tran_in_args);
} else if (state == s_in_progress) {
step_cutscene();
} else if (state == s_transition_out) {
transition_out.apply(null, tran_out_args);
} else if (state == s_done) {
}
super.update();
}
public function do_nothing():void {
}
private function windmill_in(a:int, b:int):void {
state = s_in_progress;
}
private function windmill_out(a:int, b:int):void {
state = s_done;
}
private function step_windmill_opening():void {
switch (ctr_cutscene) {
case 0:
Registry.volume_scale -= 0.01;
Registry.sound_data.current_song.volume = FlxG.volume * Registry.volume_scale;
if (Registry.volume_scale <= 0) {
Registry.volume_scale = 0;
Registry.sound_data.wb_tap_ground.play();
ctr_cutscene += 2;
} else {
Registry.volume_scale = 0;
}
break;
case 1:
break;
case 2:
ctr_cutscene++;
fade.exists = true;
fade.alpha = 0;
break;
case 3:
fade.alpha += 0.01;
if (fade.alpha == 1) {
ctr_cutscene++;
entity_1.exists = scene_1.exists = true;
}
break;
case 4: // Move bedroom satue
fade.alpha -= 0.01;
if (fade.alpha <= 0.45 && fade.alpha > 0.43) {
Registry.sound_data.red_cave_rise.play();
}
if (fade.alpha == 0) {
if (EventScripts.send_property_to(entity_1, "y", 20, 0.2)) {
Registry.sound_data.wb_hit_ground.play();
FlxG.shake(0.05, 0.5);
ctr_cutscene++;
}
}
break;
case 5:
fade.alpha += 0.01;
if (fade.alpha == 1) {
entity_1.exists = scene_1.exists = false;
entity_2.exists = scene_2.exists = true;
ctr_cutscene++;
}
break;
case 6: // move red stat
fade.alpha -= 0.01;
if (fade.alpha <= 0.45 && fade.alpha > 0.43) {
Registry.sound_data.red_cave_rise.play();
}
if (fade.alpha == 0) {
if (EventScripts.send_property_to(entity_2, "x", 4 * 16 + 32, 0.2)) {
Registry.sound_data.wb_hit_ground.play();
FlxG.shake(0.05, 0.5);
ctr_cutscene++;
}
}
break;
case 7:
fade.alpha += 0.01;
if (fade.alpha == 1) {
entity_2.exists = scene_2.exists = false;
entity_3.exists = scene_3.exists = true;
ctr_cutscene++;
}
break;
case 8: // move blue stat
fade.alpha -= 0.01;
if (fade.alpha <= 0.45 && fade.alpha > 0.43) {
Registry.sound_data.red_cave_rise.play();
}
if (fade.alpha == 0) {
if (EventScripts.send_property_to(entity_3, "x", 4 * 16 + 32, 0.2)) {
Registry.sound_data.wb_hit_ground.play();
FlxG.shake(0.05, 0.5);
ctr_cutscene++;
}
}
break;
case 9:
fade.alpha += 0.01;
if (fade.alpha == 1) {
ctr_cutscene++;
entity_3.exists = scene_3.exists = false;
}
break;
case 10:
fade.alpha -= 0.01;
if (Registry.volume_scale < 1) {
Registry.volume_scale += 0.01;
} else {
Registry.volume_scale = 1;
}
Registry.sound_data.current_song.volume = FlxG.volume * Registry.volume_scale;
if (fade.alpha == 0 && Registry.volume_scale == 1) {
state = s_transition_out;
Registry.sound_data.start_song_from_title("WINDMILL");
}
break;
}
}
private function red_out(a:int, b:int):void {
state = s_done;
switch (Registry.CURRENT_CUTSCENE) {
case Cutscene.Red_Cave_Left:
Registry.CUTSCENES_PLAYED[Cutscene.Red_Cave_Left] = 1; break;
case Cutscene.Red_Cave_Right:
Registry.CUTSCENES_PLAYED[Cutscene.Red_Cave_Right] = 1; break;
case Cutscene.Red_Cave_North:
Registry.CUTSCENES_PLAYED[Cutscene.Red_Cave_North] = 1; break;
}
}
private function red_in(a:int, b:int):void {
state = s_in_progress;
Registry.sound_data.red_cave_rise.play();
}
private function step_red_cave():void {
//perform the rise effect.
if (ctr_cutscene == 0) {
timer -= FlxG.elapsed;
if (timer < 0) {
pushdown--;
pushee.framePixels_y_push = pushdown;
timer = timer_max;
FlxG.shake(0.05);
if (pushdown == 0) {
ctr_cutscene = 1;
timer = 1.5;
}
}
} else if (ctr_cutscene == 1) {
timer -= FlxG.elapsed;
if (timer < 0) {
ctr_cutscene++;
}
} else {
state = s_transition_out;
}
}
private function terminal_gate_out(a:int, b:int):void {
state = s_done;
switch (Registry.CURRENT_CUTSCENE) {
case Cutscene.Terminal_Gate_Bedroom:
Registry.CUTSCENES_PLAYED[Cutscene.Terminal_Gate_Bedroom] = 1;
break;
case Cutscene.Terminal_Gate_Redcave:
Registry.CUTSCENES_PLAYED[Cutscene.Terminal_Gate_Redcave] = 1;
break;
case Cutscene.Terminal_Gate_Crowd:
Registry.CUTSCENES_PLAYED[Cutscene.Terminal_Gate_Crowd] = 1;
break;
}
}
private function terminal_gate_in(a:int, b:int):void {
state = s_in_progress;
}
private function step_terminal_gate():void {
var tg:Terminal_Gate = entity_1 as Terminal_Gate;
switch (Registry.CURRENT_CUTSCENE) {
case Cutscene.Terminal_Gate_Bedroom:
tg.gate_bedroom.alpha -= 0.005;
if (tg.gate_bedroom.alpha == 0) {
state = s_transition_out;
}
break;
case Cutscene.Terminal_Gate_Redcave:
tg.gate_redcave.alpha -= 0.005;
if (tg.gate_redcave.alpha == 0) {
state = s_transition_out;
}
break;
case Cutscene.Terminal_Gate_Crowd:
tg.gate_crowd.alpha -= 0.005;
if (tg.gate_crowd.alpha == 0) {
state = s_transition_out;
}
break;
}
}
/**
* loads a cutscenes view
* @param map_name The name of the map
* @param tileset the reference to the embedded tileste
* @param gx the top left grid coordinate of the view.
* @param gy see gx
* @param w width of the view in tiles
* @param h height ...
* @param off_gx grid offset for the view to start.
* @param off_gy see off_gx
* @return the requested tilemap for viewin'.
*/
public function load_cutscene_view(map_name:String, tileset:Class, gx:int,gy:int, w:int=10,h:int=10,off_gx:int=0,off_gy:int=0):FlxTilemap {
var CSV:String = CSV_Data.getMap(map_name);
var tilemap:FlxTilemap = new FlxTilemap();
tilemap.loadMap(CSV, tileset, 16, 16);
var submap_data:Array = new Array();
for (var i:int = 0; i < w*h; i++) {
submap_data.push(tilemap.getTile(gx * 10 + (i % w), gy * 10 + (i / h)));
}
tilemap.destroy();
tilemap = new FlxTilemap();
tilemap.loadMap(FlxTilemap.arrayToCSV(submap_data, 10), tileset, 16, 16);
tilemap.scrollFactor.x = tilemap.scrollFactor.y = 0;
tilemap.y = Registry.HEADER_HEIGHT;
return tilemap;
}
private function inst_red_cave_left():void {
add (load_cutscene_view("REDSEA", TileData.Red_Sea_Tiles, 2, 4));
var ss:Solid_Sprite = new Solid_Sprite(EventScripts.fake_xml("Solid_Sprite","48", "68", "red_cave_r_ss"), true);
add(ss);
pushee = ss;
pushdown = ss.framePixels_y_push = 64;
var overlay:FlxSprite = new FlxSprite(0, 20, Common_Sprites.redsea_blend);
overlay.scrollFactor.x = overlay.scrollFactor.y = 0;
overlay.blend = "hardlight";
add(overlay);
}
private function inst_red_cave_right():void {
add (load_cutscene_view("REDSEA", TileData.Red_Sea_Tiles, 4, 4));
var ss:Solid_Sprite = new Solid_Sprite(EventScripts.fake_xml("Solid_Sprite", "48", "68", "red_cave_r_ss"), true);
add(ss);
var overlay:FlxSprite = new FlxSprite(0, 20, Common_Sprites.redsea_blend);
add(overlay);
overlay.blend = "hardlight";
overlay.scrollFactor.x = overlay.scrollFactor.y = 0;
pushee = ss;
pushdown = ss.framePixels_y_push = 64;
}
private function inst_red_cave_north():void {
add (load_cutscene_view("REDSEA", TileData.Red_Sea_Tiles, 3, 3));
var ss:Solid_Sprite = new Solid_Sprite(EventScripts.fake_xml("Solid_Sprite", "48",
"68", "red_cave_n_ss"), true);
add(ss);
pushee = ss;
var overlay:FlxSprite = new FlxSprite(0, 20, Common_Sprites.redsea_blend);
add(overlay);
overlay.blend = "hardlight";
overlay.scrollFactor.x = overlay.scrollFactor.y = 0;
pushdown = ss.framePixels_y_push = 64;
}
private function inst_terminal_gate():void {
add(load_cutscene_view("WINDMILL", TileData.Terminal_Tiles, 0, 2));
var tg:Terminal_Gate = new Terminal_Gate(EventScripts.fake_xml("Terminal_Gate", "30", "50", "n"), _parent.player, _parent,true);
var grp:FlxGroup = new FlxGroup();
grp.add(tg.button);
grp.add(tg.gate_bedroom);
grp.add(tg.gate_crowd);
grp.add(tg.gate_redcave);
grp.setAll("scrollFactor", new FlxPoint(0, 0));
add(grp);
entity_1 = tg;
}
private function inst_windmill():void {
Registry.CUTSCENES_PLAYED[Cutscene.Windmill_Opening] = 1;
scene_1 = load_cutscene_view("BEDROOM", TileData._Bedroom_Tiles, 4, 0, 10, 10, 0, 0);
entity_1 = new FlxSprite(5 * 16, 2 * 16 + 20);
entity_1.loadGraphic(Dungeon_Statue.statue_bedroom_embed, true, false, 32, 48);
entity_1.frame = 0;
scene_2 = load_cutscene_view("REDCAVE", TileData.REDCAVE_Tiles, 6, 2, 10, 10, 0, 0);
entity_2 = new FlxSprite(4 * 16, 4 * 16 + 20);
entity_2.loadGraphic(Dungeon_Statue.statue_bedroom_embed, true, false, 32, 48);
entity_2.frame = 1;
scene_3 = load_cutscene_view("CROWD", TileData._Crowd_Tiles, 9, 4, 10, 10);
entity_3 = new FlxSprite(4 * 16, 2 * 16 + 20);
entity_3.loadGraphic(Dungeon_Statue.statue_bedroom_embed, true, false, 32, 48);
entity_3.frame = 2;
fade = new FlxSprite(0, 20);
fade.makeGraphic(160, 160, 0xff000000);
fade.alpha = 1;
add(scene_1); add(entity_1);
add(scene_2); add(entity_2);
add(scene_3); add(entity_3);
add(fade);
setAll("scrollFactor", new FlxPoint(0, 0));
setAll("exists", false);
}
override public function destroy():void
{
entity_1 = null;
entity_2 = null;
entity_3 = null;
pushee = null;
tran_in_args = null;
tran_out_args = null;
transition_in = null;
transition_out = null;
step_cutscene = null;
scene_1 = null;
scene_2 = null;
scene_3 = null;
super.destroy();
}
}
}

630
intra/src/helper/DH.as Normal file
View File

@ -0,0 +1,630 @@
package helper
{
import data.NPC_Data_EN;
import data.NPC_Data_ES;
import data.NPC_Data_JP;
import data.NPC_Data_KR;
import data.NPC_Data_PT;
import data.NPC_Data_IT;
import data.NPC_Data_ZHS;
import entity.player.Player;
import flash.utils.ByteArray;
import flash.utils.describeType;
import global.Registry;
import org.flixel.FlxObject;
import org.flixel.FlxSprite;
import states.DialogueState;
/**
* Dialogue Helper (DH)
* Contains helper functions to query the Dialogue state object
*/
public class DH
{
// A copy of the raw dialogue state. Used for updating
// Dialogue state in patches
public static var RAW_DIALOGUE_STATE:Object;
public static const name_card:String = "card";
public static const name_arthur:String = "arthur";
public static const name_briar:String = "briar";
public static const name_javiera:String = "javiera";
public static const name_mitra:String = "mitra";
public static const name_sage:String = "sage";
public static const name_statue:String = "statue";
public static const name_test:String = "test";
public static const name_sun_guy:String = "sun_guy";
public static const name_rock:String = "rock";
public static const name_sadbro:String = "sadbro";
public static const name_dungeon_statue:String = "dungeon_statue";
public static const name_splitboss:String = "splitboss";
public static const name_wallboss:String = "wallboss";
public static const name_eyeboss:String = "eyeboss";
public static const name_redboss:String = "redboss";
public static const name_circus_folks:String = "circus_folks";
public static const name_suburb_walker:String = "suburb_walker";
public static const name_suburb_blocker:String = "suburb_blocker";
public static const name_cube_king:String = "cube_king";
public static const name_cliff_dog:String = "cliff_dog";
public static const name_generic_npc:String = "generic_npc";
public static const name_forest_npc:String = "forest_npc";
public static const name_geoms:String = "geoms";
public static const name_miao:String = "miao";
public static const name_shopkeeper:String = "shopkeeper";
public static const name_goldman:String = "goldman";
public static const name_happy_npc:String = "happy_npc";
// For card popups, treasure dialogs
public static var area_etc:String = "ETC";
public static var scene_arthur_circus_alone:String = "alone";
public static var scene_briar_go_before_fight:String = "before_fight";
public static var scene_briar_go_after_fight:String = "after_fight";
public static var scene_card_one:String = "one";
public static var scene_cliff_dog_top_left:String = "top_left";
public static var scene_dungeon_statue_bedroom_one:String = "one";
public static var scene_dungeon_statue_bedroom_two:String = "two";
public static var scene_forest_npc_bunny:String = "bunny";
public static var scene_forest_npc_thorax:String = "thorax";
public static var scene_snowman_one:String = "one";
public static var scene_goldman_etc:String = "etc";
public static var scene_goldman_inside:String = "inside";
public static var scene_goldman_outside:String = "outside";
public static var scene_generic_npc_any_quest_normal:String = "quest_normal";
public static var scene_generic_npc_any_second:String = "second";
public static var scene_generic_npc_any_first:String = "first";
public static var scene_generic_npc_any_quest_event:String = "quest_event";
public static var scene_generic_npc_any_easter_egg:String = "easter_egg";
public static var scene_rank_bush:String = "bush";
public static var scene_happy_npc_beautiful:String = "beautiful";
public static var scene_happy_npc_drink:String = "drink";
public static var scene_happy_npc_hot:String = "hot";
public static var scene_happy_npc_dump:String = "dump";
public static var scene_happy_npc_gold:String = "gold";
public static var scene_happy_npc_briar:String = "briar";
public static var scene_javiera_circus_alone:String = "alone";
public static var scene_miao_init:String = "init";
public static var scene_miao_randoms:String = "randoms";
public static var scene_miao_philosophy:String = "philosophy";
public static var scene_mitra_overworld_initial_overworld:String = "initial_overworld";
public static var scene_mitra_blue_one:String = "one";
public static var scene_mitra_fields_init:String = "init";
public static var scene_mitra_fields_game_hints:String = "game_hints";
public static var scene_mitra_fields_card_hints:String = "card_hints";
public static var scene_mitra_fields_general_banter:String = "general_banter";
public static var scene_mitra_fields_quest_event:String = "quest_event";
public static var scene_rock_one:String = "one";
public static var scene_rock_two:String = "two";
public static var scene_rock_three:String = "three";
public static var scene_rock_four:String = "four";
public static var scene_rock_five:String = "five";
public static var scene_rock_six:String = "six";
public static var scene_shopkeeper_init:String = "init";
public static var scene_suburb_walker_words_adult:String = "words_adult";
public static var scene_suburb_walker_words_teen:String = "words_teen";
public static var scene_suburb_walker_words_kid:String = "words_kid";
public static var scene_suburb_walker_family:String = "family";
public static var scene_suburb_walker_hanged:String = "hanged";
public static var scene_suburb_walker_festive:String = "festive";
public static var scene_suburb_walker_paranoid:String = "paranoid";
public static var scene_suburb_walker_dead:String = "dead";
public static var scene_suburb_walker_older_kid:String = "older_kid";
public static const scene_suburb_blocker_one:String = "one";
public static var scene_sadbro_overworld_initial_forced:String = "initial_forced";
public static var scene_sadbro_overworld_bedroom_done:String = "bedroom_done";
public static var scene_sadbro_overworld_bedroom_not_done:String = "bedroom_not_done";
public static var scene_sage_blank_intro:String = "intro";
public static var scene_sage_nexus_enter_nexus:String = "enter_nexus";
public static var scene_sage_nexus_after_ent_str:String = "after_ent_str";
public static var scene_sage_nexus_after_bed:String = "after_bed";
public static var scene_sage_nexus_before_windmill:String = "before_windmill";
public static var scene_sage_nexus_after_windmill:String = "after_windmill";
public static var scene_sage_nexus_all_card_first:String = "all_card_first";
public static var scene_sage_overworld_bedroom_entrance:String = "bedroom_entrance";
public static var scene_sage_bedroom_after_boss:String = "after_boss";
public static var scene_sage_redcave_one:String = "one";
public static var scene_sage_crowd_one:String = "one";
public static var scene_sage_terminal_before_fight:String = "before_fight";
public static var scene_sage_terminal_after_fight:String = "after_fight";
public static var scene_sage_terminal_entrance:String = "entrance";
public static var scene_sage_terminal_etc:String = "etc";
public static var scene_sage_happy_posthappy_sage:String = "posthappy_sage";
public static var scene_sage_happy_posthappy_mitra:String = "posthappy_mitra";
public static var scene_splitboss_before_fight:String = "before_fight";
public static var scene_splitboss_after_fight:String = "after_fight";
public static var scene_redboss_before_fight:String = "before_fight";
public static var scene_redboss_after_fight:String = "after_fight";
public static var scene_eyeboss_before_fight:String = "before_fight";
public static var scene_eyeboss_after_fight:String = "after_fight";
public static var scene_wallboss_before_fight:String = "before_fight";
public static var scene_wallboss_after_fight:String = "after_fight";
public static var scene_circus_folks_before_fight:String = "before_fight";
public static var scene_circus_folks_after_fight:String = "after_fight";
public static var scene_sun_guy_before_fight:String = "before_fight";
public static var scene_sun_guy_after_fight:String = "after_fight";
public static var scene_statue_nexus_enter_nexus:String = "enter_nexus";
public static var scene_statue_bedroom_after_boss:String = "after_boss";
public static var scene_statue_overworld_bedroom_entrance:String = "bedroom_entrance";
public static var scene_cube_king_space_color:String = "color";
public static var scene_cube_king_space_gray:String = "gray";
public static var scene_geoms_space_color:String = "color";
public static var scene_geoms_space_gray:String = "gray";
public static var scene_test_debug_scene_1:String = "scene_1";
private static var property_resettable:String = "does_reset";
private static var scenes_to_reset_on_map_change:Array = new Array();
private static var current_active_scene:Object;
private static var current_active_dialogue:Array;
/**
* Whether or not a chunk of dialogue has finished playing. Reset whenever
* a new chunk is fetched.
*/
private static var recently_finished_chunk:Boolean = false;
private static var chunk_is_playing:Boolean = false;
private static var most_recently_played_chunk_pos:int;
/**
* Start a dialogue popup given the parameters. Increments the chosen scene's pos parameter,
* or loops it to its loop point. Marks this scene as dirty (i.e., "read at least once").
* @param name The name of the npc. Use constants in DH.as when you can - DH.name_sage, etc.
* @param scene The name of the scene. Use constants in DH.as when you can - DH.scene_sage_blank_intro, etc.
* @param area What map this occurs in. Defaults to current player's map.
* @param pos which dialogue to show. If -1, reads the next one and increments the position state. Otherwise returns the requested chunk
* @param has_alternate Whether this NPC has altenrate text based on state from helper.S_NPC.as
* @return true on success (read a dialogue chunk), crash the game otherwise
*/
public static function start_dialogue(name:String, scene:String, _area:String = "", pos:int = -1,has_alternate:Boolean=false):Boolean {
if (true == a_chunk_is_playing() || (Registry.GAMESTATE != null && Registry.GAMESTATE.dialogue_latency > 0)) {
return false;
}
recently_finished_chunk = false;
// Maybe get an alternate text.
if (has_alternate == true) {
// S_NPC.something...
}
// Grab the area of the dialogue to take place
var area:String = (_area == "") ? Registry.CURRENT_MAP_NAME : _area;
// Grab the scene associated with this area
var cur_scene_state:Object = Registry.DIALOGUE_STATE[name][area][scene];
var cur_scene_dialogue:Array = Registry.DIALOGUE[name][area][scene].dialogue;
cur_scene_state.dirty = true;
// Make the box at top or bottom
if (cur_scene_state.hasOwnProperty("top")) {
DialogueState.set_dialogue_box_align(FlxObject.UP);
} else {
DialogueState.set_dialogue_box_align(FlxObject.DOWN);
}
// Grab the dialogue chunk, if we hit the end, loop, otherwise increment position counter
if (pos == -1) {
most_recently_played_chunk_pos = cur_scene_state.pos;
Registry.cur_dialogue = cur_scene_dialogue[cur_scene_state.pos];
if (cur_scene_state.pos == cur_scene_dialogue.length - 1) {
cur_scene_state.pos = cur_scene_state.loop;
} else {
cur_scene_state.pos++;
}
} else {
most_recently_played_chunk_pos = pos;
Registry.cur_dialogue = cur_scene_dialogue[pos];
}
// If resettable, add its reference to list of references to reset dialogue position on map change
if (Registry.DIALOGUE_STATE[name].hasOwnProperty(property_resettable) && Registry.DIALOGUE_STATE[name][property_resettable]) {
scenes_to_reset_on_map_change.push(cur_scene_state);
}
if (Registry.GAMESTATE != null) {
Registry.GAMESTATE.load_dialogue = true;
}
current_active_scene = cur_scene_state;
current_active_dialogue = cur_scene_dialogue;
chunk_is_playing = true;
return true;
}
public static function dialogue_popup_misc_any(scene:String, pos:int):void {
dialogue_popup(DH.lookup_string("misc", "any", scene, pos));
}
/**
* Make a dialogue popup with 'words'.
* @param words
*/
public static function dialogue_popup(words:String):void {
Registry.cur_dialogue = words;
Registry.GAMESTATE.load_dialogue = true;
}
/**
* Get the dialogue position in a given scene.
* @param name
* @param scene
* @param _area
* @return an integer >= 0 denoting the position, or -1 if not found
*/
public static function get_scene_position(name:String, scene:String, _area:String = ""):int {
_area = (_area == "") ? Registry.CURRENT_MAP_NAME : _area;
return Registry.DIALOGUE_STATE[name][_area][scene].pos;
}
/**
* Check if the scene had any dialogue started at any point in time. Useful if you don't want to add in
* another boolean to wherever the dialogue is being played from, and the call originally sits in a block
* that is iterated over.
* @param name
* @param scene
* @param _area
* @return
*/
public static function scene_is_dirty(name:String, scene:String, _area:String = ""):Boolean {
_area = (_area == "") ? Registry.CURRENT_MAP_NAME : _area;
return Registry.DIALOGUE_STATE[name][_area][scene].dirty;
}
/**
* Check if the scene has finished completely. Useful for say, boss intro dialogue which blocks scripting of an intro sequence
* @param name
* @param scene
* @param _area
* @return
*/
public static function scene_is_finished(name:String, scene:String, _area:String = ""):Boolean {
_area = (_area == "") ? Registry.CURRENT_MAP_NAME : _area;
return Registry.DIALOGUE_STATE[name][_area][scene].finished;
}
/**
* Updates current scene to be "finished" if all dialogue is played from that scene.
* Also sets "recently_finished_chunk" to true, and "chunk_is_playing" to false;
*/
public static function update_current_scene_on_chunk_finish():void {
if (current_active_scene == null) return;
if (most_recently_played_chunk_pos == current_active_dialogue.length - 1) {
current_active_scene.finished = true;
}
current_active_dialogue = null;
current_active_scene = null;
recently_finished_chunk = true;
chunk_is_playing = false;
}
public static function get_scene_length(name:String, scene:String, _area:String = ""):int {
_area = (_area == "") ? Registry.CURRENT_MAP_NAME : _area;
return Registry.DIALOGUE[name][_area][scene].dialogue.length;
}
/**
* Called when transitioning out of a Roam or Playstate.
*/
public static function reset_scenes_on_map_change():void {
while (scenes_to_reset_on_map_change.length > 0) {
var scene:Object = scenes_to_reset_on_map_change.pop() as Object;
scene.pos = 0;
}
}
public static function a_chunk_just_finished():Boolean {
if (recently_finished_chunk) {
recently_finished_chunk = false;
return true;
}
return false;
}
public static function dont_need_recently_finished():void {
recently_finished_chunk = false;
}
public static function a_chunk_is_playing():Boolean {
return chunk_is_playing;
}
/**
* Fill Registry.DIALOGUE with all the game's dialogue, make a copy of the initial dialogue state
* into Registry.DIALOGUE_STATE
*/
public static function init_dialogue_state(only_change_dialogue:Boolean=false):void {
Registry.DIALOGUE = { };
var varList:XMLList = null;
if (language_type == LANG_ja) {
varList = describeType(NPC_Data_JP)..variable;
} else if (language_type == LANG_ko) {
varList = describeType(NPC_Data_KR)..variable;
} else if (language_type == LANG_es) {
varList = describeType(NPC_Data_ES)..variable;
} else if (language_type == LANG_it) {
varList = describeType(NPC_Data_IT)..variable;
} else if (language_type == LANG_pt) {
varList = describeType(NPC_Data_PT)..variable;
} else if (language_type == LANG_zhs) {
varList = describeType(NPC_Data_ZHS)..variable;
} else {
varList = describeType(NPC_Data_EN)..variable;
}
var d:Object = { };
for (var i:int = 0; i < varList.length(); i++) {
if (varList[i].@name.toXMLString().indexOf("_state") == -1) {
if (language_type == LANG_ja) {
Registry.DIALOGUE[varList[i].@name] = NPC_Data_JP[varList[i].@name];
} else if (language_type == LANG_ko) {
Registry.DIALOGUE[varList[i].@name] = NPC_Data_KR[varList[i].@name];
} else if (language_type == LANG_es) {
Registry.DIALOGUE[varList[i].@name] = NPC_Data_ES[varList[i].@name];
} else if (language_type == LANG_it) {
Registry.DIALOGUE[varList[i].@name] = NPC_Data_IT[varList[i].@name];
} else if (language_type == LANG_pt) {
Registry.DIALOGUE[varList[i].@name] = NPC_Data_PT[varList[i].@name];
} else if (language_type == LANG_zhs) {
Registry.DIALOGUE[varList[i].@name] = NPC_Data_ZHS[varList[i].@name];
} else {
Registry.DIALOGUE[varList[i].@name] = NPC_Data_EN[varList[i].@name];
}
} else { // Add the bob npc object state, with all of its areas and scenes
if (language_type == LANG_ja) {
d[varList[i].@name.toXMLString().split("_state")[0]] = NPC_Data_JP[varList[i].@name];
} else if (language_type == LANG_ko) {
d[varList[i].@name.toXMLString().split("_state")[0]] = NPC_Data_KR[varList[i].@name];
} else if (language_type == LANG_pt) {
d[varList[i].@name.toXMLString().split("_state")[0]] = NPC_Data_PT[varList[i].@name];
} else if (language_type == LANG_es) {
d[varList[i].@name.toXMLString().split("_state")[0]] = NPC_Data_ES[varList[i].@name];
} else if (language_type == LANG_it) {
d[varList[i].@name.toXMLString().split("_state")[0]] = NPC_Data_IT[varList[i].@name];
} else if (language_type == LANG_zhs) {
d[varList[i].@name.toXMLString().split("_state")[0]] = NPC_Data_ZHS[varList[i].@name];
} else {
d[varList[i].@name.toXMLString().split("_state")[0]] = NPC_Data_EN[varList[i].@name];
}
}
}
if (false == only_change_dialogue) {
var myBA:ByteArray = new ByteArray();
myBA.writeObject(d);
myBA.position = 0;
// dialogue state doesnt hold any "dialogue" just state
Registry.DIALOGUE_STATE = myBA.readObject();
myBA.position = 0;
RAW_DIALOGUE_STATE = myBA.readObject();
}
}
public static function isZH():Boolean {
if (language_type == LANG_zhs) return true;
return false;
}
public static var language_type:String = "en";
public static const LANG_en:String = "en";
public static const LANG_ja:String = "ja";
public static const LANG_ko:String = "ko";
public static const LANG_es:String = "es";
public static const LANG_pt:String = "pt";
public static const LANG_zhs:String = "zh-CN";
public static const LANG_it:String = "it";
public static function set_language(lang_string:String):void {
if (lang_string == LANG_ja) {
trace("Japanese Language set.");
DialogueState.Max_Line_Size = 18;
language_type = LANG_ja;
} else if (lang_string == LANG_ko) {
trace("Korean language set.");
DialogueState.Max_Line_Size = 18;
language_type = LANG_ko;
} else if (lang_string == LANG_es) {
trace("Spanish language set.");
DialogueState.Max_Line_Size = 24;
language_type = LANG_es;
} else if (lang_string == LANG_it) {
trace("Italian language set.");
DialogueState.Max_Line_Size = 24;
language_type = LANG_it;
} else if (lang_string == LANG_pt) {
trace("pt-br language set.");
DialogueState.Max_Line_Size = 24;
language_type = LANG_pt;
} else if (lang_string == LANG_zhs || lang_string == "zh" || lang_string == "zh-TW") {
trace("zh-CN langage set.");
DialogueState.Max_Line_Size = 13;
language_type = LANG_zhs;
} else {
trace("English Language set.");
language_type = LANG_en;
DialogueState.Max_Line_Size = 21;
}
// When called a 2nd time in game or after loading or whatever
if (Registry.PLAYSTATE != null && Registry.PLAYSTATE.dialogue_state != null) {
Registry.PLAYSTATE.dialogue_state.create_bitmap_text();
}
// Change the pointer to the new object but don't update the state.
init_dialogue_state(true);
// Update these strings after re-initializing dialogue state
if (Registry.PLAYSTATE != null && Registry.PLAYSTATE.pause_state != null) {
Registry.PLAYSTATE.pause_state.set_pausemenu_labels();
}
}
// Patches the save file's dialogue state
// with the raw dialogue state.
// Useful if we add an NPC or somethin' .
public static function patch_dialogue_state():void {
var debug:Boolean = false;
var npc_ctr:int = 0;
var area_ctr:int = 0;
var scene_ctr:int = 0;
if (debug) trace("Patching dialogue state.");
for (var npc:String in RAW_DIALOGUE_STATE) {
npc_ctr++;
// If the save file already has this NPC then we need to check its areas
if (Registry.DIALOGUE_STATE.hasOwnProperty(npc)) {
// Check the NPC's areas.
for (var area:String in RAW_DIALOGUE_STATE[npc]) {
area_ctr++;
if (area == "does_reset") continue;
// Check its scenes.
if (Registry.DIALOGUE_STATE[npc].hasOwnProperty(area)) {
for (var scene:String in RAW_DIALOGUE_STATE[npc][area]) {
scene_ctr++;
// If this scene exists, just update its loop property
if (Registry.DIALOGUE_STATE[npc][area].hasOwnProperty(scene)) {
Registry.DIALOGUE_STATE[npc][area][scene]["loop"] = RAW_DIALOGUE_STATE[npc][area][scene]["loop"]
if (RAW_DIALOGUE_STATE[npc][area][scene].hasOwnProperty("top")) {
Registry.DIALOGUE_STATE[npc][area][scene]["top"] = true;
}
} else {
if (debug) trace("New scene: " + scene + " , " + area + " , " + npc)
Registry.DIALOGUE_STATE[npc][area][scene] = RAW_DIALOGUE_STATE[npc][area][scene];
}
}
} else {
if (debug) trace("New Area: " + area+" , "+npc);
Registry.DIALOGUE_STATE[npc][area] = RAW_DIALOGUE_STATE[npc][area];
}
}
// Otherwise just add it in!
} else {
if (debug) trace("New NPC: " + npc);
Registry.DIALOGUE_STATE[npc] = RAW_DIALOGUE_STATE[npc];
}
}
if (debug) trace("And now for # of things we had to check...");
if (debug) trace("NPCs: " + npc_ctr.toString() + " Areas: " + area_ctr.toString() + " scenes: " + scene_ctr.toString());
}
/**
* Increments an integer property on this ENTIRE NPC by one
* Creates the property if it doesn't exist, inits to 1.
* @return 1 if property exists, 0 otherswise
*/
public static function increment_property(name:String,property:String):int {
if (!Registry.DIALOGUE_STATE[name].hasOwnProperty(property)) {
Registry.DIALOGUE_STATE[name][property] = 1;
} else {
Registry.DIALOGUE_STATE[name][property]++;
return 1;
}
return 0;
}
/**
* Get an integer property of the NPC ENTIRE NPC
* @param name
* @param property
* @return
*/
public static function get_int_property(name:String, property:String):int {
if (Registry.DIALOGUE_STATE[name].hasOwnProperty(property)) {
return Registry.DIALOGUE_STATE[name][property];
}
return -1;
}
public static function enable_menu():void {
Registry.disable_menu = false;
}
public static function disable_menu():void {
Registry.disable_menu = true;
}
/**
* Specify what chunk of dialogue to play next, by the "pos" var
* @param pos
* @return the new position in this scene, or -1 if current scene null
*/
public static function set_scene_to_pos(name:String,scene:String,pos:int):int {
if (Registry.DIALOGUE_STATE[name][Registry.CURRENT_MAP_NAME][scene] == null) return -1;
Registry.DIALOGUE_STATE[name][Registry.CURRENT_MAP_NAME][scene].pos = pos;
return pos;
}
/**
* Set pos to the last chunk of dialogue.
* @param pos
* @return the new position in this scene, or or -1 if current scene null
*/
public static function set_scene_to_end(name:String,scene:String):int {
if (Registry.DIALOGUE_STATE[name][Registry.CURRENT_MAP_NAME][scene] == null) return -1;
var new_pos:int = Registry.DIALOGUE[name][Registry.CURRENT_MAP_NAME][scene].dialogue.length - 1;
Registry.DIALOGUE_STATE[name][Registry.CURRENT_MAP_NAME][scene].pos = new_pos;
return new_pos;
}
/**
* Macro: "Normal Condition" Does the conditional checks for entering a dialogue, covers 95% of cases
* @param p - player reference
* @param ar - active region of the sprites talking to
* @return whether to talk or not
*/
public static function nc(player:Player, active_region:FlxObject):Boolean {
if (player.overlaps(active_region) && DH.a_chunk_is_playing() == false && player.state == player.S_GROUND && Registry.keywatch.JP_ACTION_1) {
player.be_idle();
return true;
}
return false;
}
public static function lookup_string(name:String, map:String, scene:String, pos:int):String {
var retval:String = Registry.DIALOGUE[name][map][scene].dialogue[pos];
return retval;
}
public static function lk(scene:String, pos:int):String {
var retval:String = Registry.DIALOGUE["misc"]["any"][scene].dialogue[pos];
return retval;
}
}
}

View File

@ -0,0 +1,569 @@
package helper
{
/**
* ...
* @author seagaia
*/
import data.CLASS_ID;
import data.Common_Sprites;
import entity.enemy.etc.Briar_Boss;
import entity.player.HealthPickup;
import flash.geom.Point;
import global.Registry;
import mx.core.FlexSprite;
import org.flixel.FlxPoint;
import org.flixel.FlxSprite;
import org.flixel.FlxG;
import org.flixel.FlxTilemap;
import org.flixel.FlxU;
import org.flixel.plugin.photonstorm.FlxBitmapFont;
import org.flixel.system.FlxTile;
import states.DialogueState;
import states.PlayState;
public class EventScripts extends FlxSprite
{
[Embed (source = "../res/sprites/enemies/enemy_explode_2.png")] public static var small_explosion_sprite:Class;
public var xml:XML;
public var cid:int = CLASS_ID.EVENT_SCRIPT;
public function EventScripts() {
super(0, 0);
makeGraphic(1, 1, 0x00ffffff);
xml = <event></event>;
}
public static function move_to_x_and_stop(o:FlxSprite, vel:Number, x:Number):void {
if (vel > 0 && o.x > x) {
o.velocity.x = 0;
} else if (vel < 0 && o.x < x) {
o.velocity.x = 0;
} else {
o.velocity.x = vel;
}
return;
}
public static function move_to_x(o:FlxSprite, vel:Number, x:Number):Boolean {
o.velocity.x = vel;
if (vel < 0) {
if (o.x <= x) return true;
} else {
if (o.x >= x) return true;
}
return false;
}
public static function check_x_zero(...args):Boolean {
var next:FlxSprite;
var ret:Boolean = true;
for (var i:int = 0; i < args.length; i++) {
next = args[i];
if (next.velocity.x != 0) {
ret = false;
break;
}
}
return ret;
}
/**
* Decreases or increases the given FlxSprite's alpha at rate to a target value.
* -rate for decrease, +rate for increase.
* @return true if the alpha reached the target value, false otherwise
*/
public static function send_alpha_to(o:FlxSprite, target:Number, rate:Number):Boolean {
if (rate > 0) {
if (o.alpha >= target) return true;
o.alpha = Math.min(1, o.alpha + rate);
} else {
if (o.alpha <= target) return true;
o.alpha = Math.max(0, o.alpha + rate);
}
return false;
}
public static function send_property_to(o:Object, property:String, target:Number, rate:Number):Boolean {
if (rate < 0) rate *= -1;
if (o[property] > target) {
o[property] = Math.max(target, o[property] - rate);
} else if (o[property] < target) {
o[property] = Math.min(target, o[property] + rate);
}
if (o[property] == target) return true;
return false;
}
/**
*
* @param chance A number from 0 to 1, the probability of the health dropping
*/
public static function drop_small_health(x:int,y:int,chance:Number):void {
var hp:HealthPickup = new HealthPickup(x, y, HealthPickup.HP_1, Registry.GAMESTATE);
if (Math.random() > (1 - chance)) {
if (Registry.is_playstate) {
Registry.GAMESTATE.otherObjects.push(hp); //So we remove these on screen transition
Registry.GAMESTATE.bg_sprites.add(hp); //So these are immediately drawn
} else {
Registry.GAMESTATE.entities.push(hp);
Registry.GAMESTATE.add(hp);
}
}
}
public static function drop_big_health(x:int,y:int,chance:Number):void {
var hp:HealthPickup = new HealthPickup(x, y, HealthPickup.HP_3, Registry.GAMESTATE);
if (Math.random() > (1 - chance)) {
if (Registry.is_playstate) {
Registry.GAMESTATE.otherObjects.push(hp);
Registry.GAMESTATE.bg_sprites.add(hp);
} else {
Registry.GAMESTATE.entities.push(hp);
}
}
}
/**
* Create an explosion sprite and add it to the current draw group.
* @param enemy The enemy that's exploding - used for deciding the explosion
*/
/* Images for explosions are embedded at the top of EventScripts.as */
/* Sounds are managed in SoundData.as */
public static function make_explosion_and_sound(enemy:FlxSprite,ignore:int=0,this_parameter:int=0):void {
var class_name:String = FlxU.getClassName(enemy, true);
var explosion:FlxSprite = new FlxSprite(enemy.x, enemy.y);
/* Make the explosion */
/* Later, load the explosion and sound based on the class name. */
switch (class_name) { // e.g., "Dog", "Lion", "Contort"
case "Velociraptor X3000":
// load the graphic, add animation, offset the explosion, play a sound
break;
default: // Executed when there is no case statement for the enemy
if (ignore == 1) {
explosion.loadGraphic(Briar_Boss.embed_dust_explosion, true, false, 48, 48);
explosion.addAnimation("explode", [0, 1, 2, 3, 4, 5], 12, false);
explosion.x += enemy.width * Math.random();
explosion.y += enemy.height * Math.random();
} else if (ignore == 2) {
explosion.loadGraphic(Briar_Boss.embed_ice_explosion, true, false, 24, 24);
explosion.addAnimation("explode", [0, 1, 2, 3,4], 15, false);
explosion.x += enemy.width * Math.random();
explosion.y += enemy.height * Math.random();
} else if (ignore == 3) {
explosion.loadGraphic(small_explosion_sprite, true, false, 24, 24);
explosion.addAnimation("explode", [0, 1, 2, 3, 4], 12, false);
explosion.x += enemy.width * Math.random();
explosion.y += enemy.height * Math.random();
} else if (Registry.CURRENT_MAP_NAME == "TRAIN") {
explosion.loadGraphic(small_explosion_sprite, true, false, 24, 24);
explosion.addAnimation("explode", [5,6,7,8,9], 10, false);
explosion.x -= 4;
explosion.y -= 4;
} else {
explosion.loadGraphic(small_explosion_sprite, true, false, 24, 24);
explosion.addAnimation("explode", [0, 1, 2, 3, 4], 12, false);
explosion.x -= 4;
explosion.y -= 4;
}
Registry.sound_data.play_sound_group(Registry.sound_data.enemy_explode_1_group);
break;
}
if (ignore > 0) {
Registry.GAMESTATE.fg_sprites.add(explosion);
} else {
Registry.GAMESTATE.bg_sprites.add(explosion);
}
explosion.play("explode");
/* Play sound */
}
public static function boss_drop_health_up(x:int, y:int):void {
trace("Boss dropping health up");
var hp:HealthPickup = new HealthPickup(x, y, HealthPickup.HP_EXTEND,Registry.GAMESTATE);
hp.xml = fake_xml("HealthPickup", x.toString(), y.toString(), HealthPickup.HP_EXTEND.toString(), "true", "2");
Registry.GAMESTATE.stateful_gridXML.appendChild(hp.xml);
Registry.GAMESTATE.bg_sprites.add(hp);
}
/**
* Create a fake xml to be used for some sprite that wasnte
* exported with dame
* @param name name of the node
* @param x x value
* @param y y value
* @param type_attr value of "type" if relevant
* @return the new xml objet
*/
public static function fake_xml(name:String,x:String,y:String,type_attr:String="",alive:String="true",p:String="0",frame:String="0"):XML {
var xml:XML = < Root x = "0" y = "0" p = "" alive = "" type = "" frame = "" /> ;
trace(xml.toXMLString());
xml.setName(name);
xml.@p = p;
xml.@["x"] = x;
xml.@y = y;
xml.@frame = frame;
xml.@alive = alive;
xml.@type = type_attr;
trace(xml.toXMLString());
return xml;
}
/**
* Rotates ROTATEE about PIVOT's top-left pt with offset (off_x,off_y),
* at some velocity (per game tick), at a radius of...radius!
*
* ROTATEE NEEDS A rotate_angle PROPERTY.
*/
public static function rotate_about_center_of_sprite(pivot:FlxSprite,rotatee:*,radius:Number,velocity:Number,off_x:int=-8,off_y:int=-5):void {
var pivot_x:Number = pivot.x + pivot.width / 2;
var pivot_y:Number = pivot.y + pivot.height / 2;
rotatee.x = Math.cos(rotatee.rotate_angle) * (radius) + pivot_x + off_x;
rotatee.y = Math.sin(rotatee.rotate_angle) * (radius) + pivot_y + off_y;
rotatee.rotate_angle = (rotatee.rotate_angle + velocity) % 6.28;
}
/**
* Gives the angle swept from the x axis to ((x1,y1),(x2,y2)) by treating x1,y1 as the origin
* */
public static function get_angle(x1:Number, y1:Number, x2:Number, y2:Number):Number {
var x:Number = x2 - x1;
var y:Number = y2 - y1;
return Math.atan2(y, x);
}
/**
* Set "out" to be a vector in the direction of to - from,
* with magnitude new_mag.
* @param from
* @param to
* @param out
* @param new_mag
* @return
*/
public static function scale_vector(from:*, to:*, out:*, new_mag:Number ):FlxPoint {
var dx:Number = to.x - from.x;
var dy:Number = to.y - from.y;
var mag:Number = Math.sqrt(dx * dx + dy * dy);
var scale:Number = new_mag / mag;
out.x = scale * dx;
out.y = scale * dy;
return out;
}
/**
* Return the distance between two points.
* Input is any objects with an x and y property.
*/
public static function distance(a:*, b:*):Number {
var dx:Number = a.x - b.x;
var dy:Number = a.y - b.y;
return Math.sqrt(dx * dx + dy * dy);
}
public static function prevent_leaving_map(playstate:PlayState,o:FlxSprite):void {
if (o.y < playstate.upperBorder) o.y = playstate.upperBorder;
if (o.y + o.height > playstate.lowerBorder) o.y = playstate.lowerBorder - o.height;
if (o.x + o.width > playstate.rightBorder) o.x = playstate.rightBorder - o.width;
if (o.x < playstate.leftBorder) o.x = playstate.leftBorder;
}
/**
* Inits a bitmap font object with the default
* variables for Anodyne
* Types: black apple_black apple_white
*/
public static function init_bitmap_font(text:String = " ", alignment:String = "center", x:int = 0, y:int = 0, scrollFactor:Point = null, type:String="black"):FlxBitmapFont {
var b:FlxBitmapFont;
switch (type) {
case "apple_black":
if (DH.language_type == DH.LANG_ja) {
b = new FlxBitmapFont(Registry.C_FONT_JP_WHITE,8,8, Registry.jp_string, 50, 0, 0, 0,0);
} else if (DH.language_type == DH.LANG_ko) {
b = new FlxBitmapFont(Registry.C_FONT_KO_WHITE, 8, 8, Registry.ko_string, 64, 0, 0, 0, 0);
} else if (DH.language_type == DH.LANG_zhs) {
b = new FlxBitmapFont(Registry.C_FONT_ZHS_WHITE, 11, 12, Registry.zhs_string, 72, 0, 0, 0, 0);
} else if (DH.language_type == DH.LANG_es || DH.language_type == DH.LANG_pt || DH.language_type == DH.LANG_it) {
b = new FlxBitmapFont(Registry.C_FONT_ES_WHITE, 6, 8, Registry.es_string, 27, 0, 0, 0, 0);
} else { // english, normal font
b = new FlxBitmapFont(Registry.C_FONT_APPLE_BLACK, Registry.APPLE_FONT_w, Registry.FONT_h, Registry.C_FONT_APPLE_BLACK_STRING, Registry.FONT_cpl, 0, 0, 0, 1);
}
break;
case "apple_white":
if (DH.language_type == DH.LANG_ja) {
b = new FlxBitmapFont(Registry.C_FONT_JP_WHITE, 8, 8, Registry.jp_string, 50, 0, 0, 0, 0);
} else if (DH.language_type == DH.LANG_ko) {
b = new FlxBitmapFont(Registry.C_FONT_KO_WHITE, 8, 8, Registry.ko_string, 64, 0, 0, 0, 0);
} else if (DH.language_type == DH.LANG_zhs) {
b = new FlxBitmapFont(Registry.C_FONT_ZHS_WHITE, 11, 12, Registry.zhs_string, 72, 0, 0, 0, 0);
}else if (DH.language_type == DH.LANG_es || DH.language_type == DH.LANG_pt || DH.language_type == DH.LANG_it) {
b = new FlxBitmapFont(Registry.C_FONT_ES_WHITE, 6, 8, Registry.es_string, 27, 0, 0, 0, 0);
} else { // english, normal font
b = new FlxBitmapFont(Registry.C_FONT_APPLE_WHITE, Registry.APPLE_FONT_w, Registry.FONT_h, Registry.C_FONT_APPLE_WHITE_STRING, Registry.FONT_cpl, 0, 0, 0, 1);
}
break;
case "apple_white_OLD":
b = new FlxBitmapFont(Registry.C_FONT_APPLE_WHITE, Registry.APPLE_FONT_w, Registry.FONT_h, Registry.C_FONT_APPLE_WHITE_STRING, Registry.FONT_cpl, 0, 0, 0, 1);
break;
case "black":
default:
b = new FlxBitmapFont(Registry.C_FONT_BLACK, Registry.FONT_w, Registry.FONT_h, Registry.C_FONT_BLACK_STRING, Registry.FONT_cpl, 0, 0, 0, 0);
break;
}
b.setText(text, true, 0, 0, alignment, true);
b.x = x;
b.y = y;
if (scrollFactor == null) {
b.scrollFactor.x = b.scrollFactor.y = 0;
} else {
b.scrollFactor.x = scrollFactor.x;
b.scrollFactor.y = scrollFactor.y;
}
return b;
}
/**
* This function keeps a sprite's hitbox entirely in the specified
* box, and flips its velocities when needed to keep it inside the box.
* @return RES, where RES = X_FLIP | Y_FLIP, where X_FLIP = 0b01, Y_FLIP = 0b10
*/
public static function bounce_in_box(o:FlxSprite, x_max:int, x_min:int, y_max:int, y_min:int):int {
var res:int = 0;
if (o.velocity.x < 0) {
if (o.x < x_min) {
o.velocity.x *= -1; res |= 1;
}
} else {
if (o.x + o.width > x_max) {
o.velocity.x *= -1; res |= 1;
}
}
if (o.velocity.y < 0) {
if (o.y < y_min) {
o.velocity.y *= -1; res |= 2;
}
} else {
if (o.y + o.height > y_max) {
o.velocity.y *= -1; res |= 2;
}
}
return res;
}
/**
* Lookup the tile at (x,y) of map, and then check its properties according to submap.
* @param x
* @param y
* @param map
* @param submap
* @return
*/
public static function get_tile_collision_flags(x:int, y:int, map:FlxTilemap,submap:FlxTilemap):uint {
var tile_type:int = map.getTile(x / 16, (y - Registry.HEADER_HEIGHT) / 16);
if (submap._tileObjects[tile_type] == null) return NONE;
return submap._tileObjects[tile_type].allowCollisions;
}
/**
* Get the direction from entity 1's position (e1x,e1y) to entity
* 2's position (e2x,e2y), using the rotated quadrants method.
*
* @param e1x
* @param e1y
* @param e2x
* @param e2y
* @return The FlxObject constant showing where the 2nd entity is relative to entity 1
*/
public static function get_entity_to_entity_dir(e1x:int, e1y:int, e2x:int, e2y:int):uint {
var dx:int = e2x - e1x;
var dy:int = e2y - e1y;
if (dx > 0) {
if (Math.abs(dy) < dx) {
return RIGHT;
}
} else {
if (Math.abs(dy) < Math.abs(dx)) {
return LEFT;
}
}
return ((dy > 0) ? DOWN : UP);
}
/**
* Makes e1's facing flag set towards e2. Also then plays the associated directional
* animation - prefix+"_"+{d,u,r,l}
*/
public static function face_and_play(e1:*, e2:*, prefix:String = "idle"):String {
e1.facing = get_entity_to_entity_dir(e1.x, e1.y, e2.x, e2.y);
switch (e1.facing) {
case UP:
e1.play(prefix + "_u");
break;
case DOWN:
e1.play(prefix + "_d");
break;
case LEFT:
e1.play(prefix + "_l");
break;
case RIGHT:
e1.play(prefix + "_r");
break;
}
return (e1._curAnim == null) ? "" : e1._curAnim.name;
}
public static function play_based_on_facing(e1:*,prefix:String = "idle"):String {
switch (e1.facing) {
case UP:
e1.play(prefix + "_u");
break;
case DOWN:
e1.play(prefix + "_d");
break;
case LEFT:
e1.play(prefix + "_l");
break;
case RIGHT:
e1.play(prefix + "_r");
break;
}
return (e1._curAnim == null) ? "" : e1._curAnim.name;
}
/**
* Checks if e1 and e2's facing flags are directional opposites.
* @param e1
* @param e2
* @return True or False.
*/
public static function are_facing_opposite(e1:*, e2:*):Boolean {
if (e1.facing == UP && e2.facing == DOWN) return true;
if (e2.facing == UP && e1.facing == DOWN) return true;
if (e1.facing == LEFT && e2.facing == RIGHT) return true;
if (e2.facing == LEFT && e1.facing == RIGHT) return true;
return false;
}
/**
* Create a shadow specified by name, and adds the animations get_big and get_small,
* and also makes it invisible. You still need to add it to the parent.
* @param name : 8_small
* @return the shadow
*/
public static function make_shadow(name:String,visible:Boolean=false,fps:int=8):FlxSprite {
var shadow:FlxSprite = new FlxSprite;
switch (name) {
case "8_small":
default:
shadow.loadGraphic(Common_Sprites.shadow_sprite_8_8, true, false, 8, 8);
shadow.addAnimation("get_big", [0, 1, 2, 3], fps, false);
shadow.addAnimation("get_small", [3, 2, 1, 0], fps, false);
shadow.play("get_big");
shadow.visible = visible;
break;
}
return shadow;
}
/**
* Called by create() in PlayState and roamstate, this returns a reference to the loaded
* autosave icon. Gives it an animation, to boot.
* @param autosave_icon
* @param autosave_icon_embed
* @return
*/
public static function init_autosave_icon(autosave_icon:FlxSprite, autosave_icon_embed:Class):FlxSprite {
autosave_icon = new FlxSprite(160 - 80 - 32, 20);//(160 - 2 - 64, 20 + 160 - 2 - 64);
autosave_icon.loadGraphic(autosave_icon_embed, true, false, 64, 16);
autosave_icon.visible = false;
autosave_icon.addAnimation("a", [0, 1, 2, 3, 4, 5], 8, true);
autosave_icon.play("a");
autosave_icon.scrollFactor.x = autosave_icon.scrollFactor.y = 0;
return autosave_icon;
}
/**
* Gets the tile's collision flags at (x,y) (default screenspace coords)
* @param x
* @param y
* @param map
* @param screen_coords
* @return
*/
public static function get_tile_allow_collisions(x:int, y:int, map:FlxTilemap, screen_coords:Boolean = true):uint {
if (screen_coords) {
var _x:int = (x % 160) / 16; //FCK IT
var _y:int = ((y - 20) % 160) / 16;
var tile_idx:int = map.getTileByIndex(_y * 10 + _x);
var tile:FlxTile = map._tileObjects[tile_idx];
return tile.allowCollisions;
}
return NONE;
}
public static function get_tile_nr(x:int, y:int, map:FlxTilemap):int {
var _x:int = (x % 160) / 16; //FCK IT
var _y:int = ((y - 20) % 160) / 16;
var tile_idx:int = map.getTileByIndex(_y * 10 + _x);
return tile_idx;
}
public static function fade_and_switch(name:String):void {
Registry.E_FADE_AND_SWITCH = true;
Registry.E_FADE_AND_SWITCH_SONG = name;
Registry.E_FADED = false;
}
/**
* Increments timer until it reaches timer_max, then sets timer to 0.
* @param timer
* @param timer_max
* @return false if timer < timer_max, true otherwise
*/
public static function time_cond(ref:*,timer:String, timer_max:String):Boolean {
ref[timer] += FlxG.elapsed;
if (ref[timer] > ref[timer_max]) {
ref[timer] = 0;
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,296 @@
package helper
{
import global.Keys;
import global.Registry;
import org.flixel.FlxG;
import org.flixel.FlxGroup;
import org.flixel.FlxPoint;
import org.flixel.FlxSprite;
import org.flixel.plugin.photonstorm.FlxBitmapFont;
import states.PauseState;
/**
* ...
* @author Melos Han-Tani
*/
public class Joypad_Config_Group extends FlxGroup
{
public var controls:FlxBitmapFont = EventScripts.init_bitmap_font("JOYPAD CONFIG", "left", 5, 20, null, "apple_white");
public var instructions:FlxBitmapFont = EventScripts.init_bitmap_font("h", "left", 5, 65, null, "apple_white");
public var yesno:FlxBitmapFont = EventScripts.init_bitmap_font("Yes No", "center", 20, 140, null, "apple_white");
public var debugtext:FlxBitmapFont = EventScripts.init_bitmap_font(".", "left", 2, 150, null, "apple_white");
public var selector:FlxSprite = new FlxSprite;
public static var REAL_JOYBINDS:Array;
private var state:int = 0;
private var cursor_state:int = 0;
private const S_DETECTED:int = 0;
private const S_INPUT:int = 1;
private const S_IDLE:int = -1;
private const S_DONE:int = 2;
private const S_TEST:int = 3;
private var move_square:FlxSprite = new FlxSprite(100, 110);
private var goal_square:FlxSprite = new FlxSprite(20, 130);
private var blackscrn:FlxSprite = new FlxSprite(0, 0);
public function Joypad_Config_Group()
{
blackscrn.makeGraphic(160, 180, 0xff000000);
blackscrn.scrollFactor = new FlxPoint(0, 0);
add(blackscrn);
add(controls);
add(instructions);
add(yesno);
add(debugtext);
set_instructions_text();
selector.loadGraphic(PauseState.arrows_sprite, true, false, 7, 7);
selector.frame = 2;
selector.scrollFactor = new FlxPoint(0, 0);
selector.x = yesno.x - 8;
selector.y = yesno.y;
add(selector);
move_square.scrollFactor.x = goal_square.scrollFactor.x = 0;
move_square.scrollFactor.y = goal_square.scrollFactor.y = 0;
move_square.makeGraphic(16, 16, 0xfff0f0f0);
goal_square.makeGraphic(16, 16, 0xffff0000);
add(move_square);
add(goal_square);
move_square.visible = goal_square.visible = false;
}
// keys_idx is 0 to 7
// so earlier it was checking input_id != keys_idx
// that person was having errors with action 1 + 2, which are keys_idx = 4 and 5
// it wasn't detecting a duplicate when keys_idx = 5
// they had two axes, meaning button input_id would be from 5 to ...
// meaning the checkk is 5 != 5. his controller probably double-inputs presses?
// this should work now..
private function no_dups(input_id:int,keys_idx:int):Boolean {
for (var i:int = 0; i < 8; i++) {
if (Registry.joybinds[i] == input_id && i != keys_idx) {
return false;
}
}
return true;
}
private var delay:Number = 1;
private var timeout:Number = 15;
private var wait_time:Number = 4;
override public function update():void
{
// Force an exit out of the config if we d/c while configing
if (Keys.has_joypad == false || (Intra.IS_MAC && Main.mac_joy_manager.joysticks[0] == null)) {
state = S_DONE;
return;
}
if (Main.mac_joy_manager != null) {
for (var a:int = 1; a < Main.mac_joy_manager.joysticks.length; a++) {
if (Main.mac_joy_manager.joysticks[a] != null) {
Main.mac_joy_manager.joysticks[0] = Main.mac_joy_manager.joysticks[a];
break;
}
}
}
debugtext.text = "Axes " + Keys.get_axis_stats() + "\n" + "Btns " + Keys.get_btn_stats() + "\n" + Keys.nr_axes.toString() + "/" + Keys.nr_btns.toString();
if (state == S_DETECTED) {
if (FlxG.keys.justPressed("SPACE")) {
state = S_DONE;
cursor_state = 0;
selector.x -= 40;
} else if (cursor_state == 0 && (1 == Keys.joy_any_axis() || Registry.keywatch.JP_RIGHT)) {
cursor_state = 1;
selector.x += 40;
} else if (cursor_state == 1 && (-1 == Keys.joy_any_axis() || Registry.keywatch.JP_LEFT)) {
cursor_state = 0;
selector.x -= 40;
} else if (Keys.joy_any_button() || FlxG.keys.any()) {
if (Registry.keywatch.RIGHT || Registry.keywatch.LEFT) return;
if (cursor_state == 0) {
for (var j:int = 0; j < 8; j++) {
Registry.joybinds[j] = 0;
}
yesno.visible = false;
selector.visible = false;
instructions.visible = false;
state = S_IDLE;
} else {
trace(Registry.joybinds);
state = S_DONE;
cursor_state = 0;
selector.x -= 40;
}
}
} else if (state == S_IDLE) {
controls.text = "Don't press anything.\n\nConfig starting in\n\n" + wait_time.toFixed(2);
wait_time -= FlxG.elapsed;
if (wait_time < 0) {
wait_time = 4;
controls.text = "Press input for\nUP.";
state = S_INPUT;
}
} else if (state == S_INPUT) {
if (delay > 0) {
delay -= FlxG.elapsed;
return;
}
if (Keys.joy_get_first_active_button_id() != 0 || Keys.joy_get_first_active_axis_id() != 0) {
var next_id:int = Keys.joy_get_first_active_button_id();
if (next_id == 0) {
next_id = Keys.joy_get_first_active_axis_id();
}
debugtext.text += "(" + next_id.toString() + ")";
if (cursor_state == 0) {
if (no_dups(next_id, Keys.IDX_UP) == false) return;
Registry.joybinds[Keys.IDX_UP] = next_id;
controls.text = "Press input for\nRIGHT.";
} else if (cursor_state == 1) {
if (no_dups(next_id, Keys.IDX_RIGHT) == false) return;
Registry.joybinds[Keys.IDX_RIGHT] = next_id;
controls.text = "Press input for\nDOWN.";
} else if (cursor_state == 2) {
if (no_dups(next_id, Keys.IDX_DOWN) == false) return;
Registry.joybinds[Keys.IDX_DOWN] = next_id;
controls.text = "Press input for\nLEFT.";
} else if (cursor_state == 3) {
if (no_dups(next_id, Keys.IDX_LEFT) == false) return;
Registry.joybinds[Keys.IDX_LEFT] = next_id;
controls.text = "Press input for\nConfirm.";
} else if (cursor_state == 4) {
if (no_dups(next_id, Keys.IDX_ACTION_1) == false) return;
Registry.joybinds[Keys.IDX_ACTION_1] = next_id;
controls.text = "Press input for\nCancel.";
} else if (cursor_state == 5) {
if (no_dups(next_id, Keys.IDX_ACTION_2) == false) return;
Registry.joybinds[Keys.IDX_ACTION_2] = next_id;
controls.text = "Press input for\nPause.";
} else if (cursor_state == 6) {
if (no_dups(next_id, Keys.IDX_PAUSE) == false) return;
Registry.joybinds[Keys.IDX_PAUSE] = next_id;
}
cursor_state++;
if (cursor_state == 7) {
cursor_state = 0;
controls.text = "Move the white square\nto the red square\nto confirm.\n\nOr, wait for the timer\nto run out\nto rebind the controls.";
instructions.visible = true;
instructions.y += 24;
goal_square.visible = move_square.visible = true;
state = S_TEST; //Need to do test thing
}
}
} else if (state == S_TEST) {
timeout -= FlxG.elapsed;
instructions.y = 89;
instructions.text = timeout.toFixed(2);
if (timeout < 10) instructions.text += " ";
if (Keys.get_joy_state(Keys.IDX_ACTION_1)) {
instructions.text += " CONFIRM: ON\n";
} else {
instructions.text += " CONFIRM: OFF\n";
}
if (Keys.get_joy_state(Keys.IDX_ACTION_2)) {
instructions.text += " CANCEL: ON\n";
} else {
instructions.text += " CANCEL: OFF\n";
}
if (Keys.get_joy_state(Keys.IDX_PAUSE)) {
instructions.text += " PAUSE: ON\n";
} else {
instructions.text += " PAUSE: OFF\n";
}
if (timeout <= 0) {
reset_before_leave();
state = S_DETECTED;
return;
}
if (Registry.keywatch.LEFT) {
move_square.velocity.x = -20;
} else if (Registry.keywatch.RIGHT) {
move_square.velocity.x = 20;
} else {
move_square.velocity.x = 0;
}
if (Registry.keywatch.UP) {
move_square.velocity.y = -20;
} else if (Registry.keywatch.DOWN) {
move_square.velocity.y = 20;
} else {
move_square.velocity.y = 0;
}
if (move_square.overlaps(goal_square)) {
REAL_JOYBINDS = Registry.joybinds;
state = S_DONE;
}
} else if (state == S_DONE) {
}
super.update();
}
public function is_done():Boolean {
if (state == S_DONE) {
state = S_DETECTED;
reset_before_leave();
return true;
}
return false;
}
private function set_instructions_text():void
{
if (Registry.GE_States[Registry.GE_DID_JOYPAD_CONFIG_ONCE] == false) {
instructions.text = "Joypad detected for\nthe first time.\n\nConfiguration is\nnecessary!\n\nConfigure?\n(Skip w/ SPACE)";
Registry.GE_States[Registry.GE_DID_JOYPAD_CONFIG_ONCE] = true;
} else {
instructions.text = "Joypad detected.\n\nReconfigure?\n(Skip w/ SPACE)\n";
}
}
private function reset_before_leave():void
{
timeout = 15;
goal_square.visible = move_square.visible = false;
move_square.velocity.x = move_square.velocity.y = 0;
move_square.x = 100; move_square.y = 110;
set_instructions_text();
yesno.visible = true;
delay = 1;
selector.visible = true;
instructions.y -= 24;
controls.text = "JOYPAD CONFIG";
}
}
}

View File

@ -0,0 +1,108 @@
package helper
{
import org.flixel.FlxG;
import org.flixel.FlxSprite;
/**
* ...
* @author Seagaia
*/
public class Parabola_Thing
{
/**
*/
/**
* helper class for making stuff move like a parabola. when tick is called it will
* change the given PROPERTY. changes it over a PERIOD of time, reaches MAX value..
* up to you to use the return stuff blahbalh
* DOESNT CHECK FOR ERRORS so get your values right. ia m lazy
* @param s
* @param max
* @param period
* @param property
*/
private var sprite_ref:FlxSprite;
private var height:Number;
public var period:Number;
public var t:Number;
private var coeff:Number;
private var prop:String;
private var subprop:String;
private var shadow_fall_anim:String;
private var has_fallen:Boolean = true;
public var OFFSET:int = 0;
public function Parabola_Thing(s:FlxSprite,_height:Number,_period:Number,_property:String,_subprop:String="")
{
sprite_ref = s;
height = _height;
period = _period;
prop = _property;
subprop = _subprop;
t = 0;
coeff = get_parabola_coeff(height, period);
}
public function destroy():void {
sprite_ref = null;
}
/**
* Set an animation for the shadow to play when it falls.
* (Falls = current t > period/2)
* @param name
*/
public function set_shadow_fall_animation(name:String):void {
shadow_fall_anim = name;
has_fallen = false;
}
/**
* changes its set property according to the parabola and blah blah.
* @return 1 if done, 0 if not. might be useful, but this sets "done" for you anyways
*/
public function tick():int {
if (t > period) {
return 1;
}
if (!has_fallen && (t > period/2)) {
has_fallen = true;
sprite_ref.my_shadow.play(shadow_fall_anim);
}
if (subprop != "") {
sprite_ref[prop][subprop] = OFFSET + get_next_parabola_param(t, period, coeff);
} else {
sprite_ref[prop] = OFFSET + get_next_parabola_param(t, period, coeff);
}
t += FlxG.elapsed;
return 0;
}
public function reset_time():void {
t = 0;
}
/* Returns the coefficient for a parameterization of parabola-like path */
public static function get_parabola_coeff(h:Number, period:Number):Number {
return (-4*h)/(period*period);
}
/**
* given current time, period, and coeff, return the next value of
* what ever value is being changed
* @return next value yo
*/
public static function get_next_parabola_param(t:Number,period:Number,coeff:Number):Number {
return coeff * t * (t - period);
}
}
}

128
intra/src/helper/S_NPC.as Normal file
View File

@ -0,0 +1,128 @@
package helper
{
import global.Registry;
/**
* Helper functions for stateful npcs.
* @author Melos Han-Tani
*/
public class S_NPC
{
public static var states:Array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
public static const IDX_TEST:int = 0;
public static const IDX_LOBSTER:int = 1;
public static const IDX_HAIR:int = 2;
public static const IDX_BEAR:int = 3;
public static const IDX_GOLEM:int = 4;
private static const BIT_DIRTY:uint = 1 << 9;
private static const BIT_SECOND_PLAYED:uint = 1 << 8;
private static const BIT_BEDROOM_BOSS:uint = 1 << 7;
private static const BIT_REDCAVE_BOSS:uint = 1 << 6;
private static const BIT_CROWD_BOSS:uint = 1 << 5;
private static const BIT_APARTMENT_BOSS:uint = 1 << 4;
private static const BIT_HOTEL_BOSS:uint = 1 << 3;
private static const BIT_CIRCUS_BOSS:uint = 1 << 2;
private static const MAX_STATE:uint = 0xfc;
//Dirty bit, read_second bit, bits on bosses.
// Set state, based on index into state and current Boss states.
public static function test():void {
// WOOO INCOMPREHENSIBLE TESTS!!!
trace(check_to_play_second(DH.name_test), "FALSE!"); // Playing when clean plays first
trace(check_to_play_second(DH.name_test), "FALSE!"); // Playing when dirty but no state change doesnt play 2nd
Registry.GE_States[Registry.GE_Bedroom_Boss_Dead_Idx] = true;
trace(check_to_play_second(DH.name_test), "TRUE!"); // Make sure state changing plays the 2nd
Registry.GE_States[Registry.GE_Redcave_Boss_Dead_Idx] = true;
trace(check_to_play_second(DH.name_test), "TRUE!"); // Make sure playing the 2nd once makes any further play the 2nd
states[IDX_TEST] = 0;
trace(check_to_play_second(DH.name_test), "FALSE!"); // Check that starting clean but with state plays 1st
trace(check_to_play_second(DH.name_test), "FALSE!"); // Dirty and state plays 1st (state donst change)
Registry.GE_States[Registry.GE_Crowd_Boss_Dead_Idx] = true;
trace(check_to_play_second(DH.name_test), "TRUE!");
states[IDX_TEST] = 0;
Registry.GE_States[Registry.GE_Bedroom_Boss_Dead_Idx] = true;
Registry.GE_States[Registry.GE_Redcave_Boss_Dead_Idx] = true;
Registry.GE_States[Registry.GE_Crowd_Boss_Dead_Idx] = true;
Registry.GE_States[Registry.GE_Apartment_Boss_Dead_Idx] = true;
Registry.GE_States[Registry.GE_Hotel_Boss_Dead_Idx] = true;
Registry.GE_States[Registry.GE_Circus_Boss_Dead_Idx] = true;
trace(check_to_play_second(DH.name_test), "FALSE!"); // PLaying hwen clena plays first
trace(check_to_play_second(DH.name_test), "TRUE!"); // play with all state set plays 2nd
}
/**
* check if you need to play the 2nd dialogue choice.
* if you leave 'scene' blank, then the functiond only relies on
* the stored state of the npc rather than the state of the scene too
* @param name
* @param scene
* @param map
* @return
*/
public static function check_to_play_second(name:String, scene:String = "", map:String = ""):Boolean {
var res:Boolean = false;
if (name == DH.name_test) {
res = update(IDX_TEST);
} else if (name == DH.name_generic_npc && map == "BEACH") { // Lobster
res = update(IDX_LOBSTER);
} else if (name == DH.name_generic_npc && map == "REDSEA") {
res = update(IDX_HAIR);
} else if (name == DH.name_generic_npc && map == "FOREST") {
res = update(IDX_BEAR);
} else if (name == DH.name_generic_npc && map == "CLIFF") {
res = update(IDX_GOLEM);
}
if (scene != "" && DH.scene_is_finished(name, scene, map) == false) return false; // We want all of the first set of dialogue to play at least once
// Put the call after the update because we
// always want to record state
return res;
}
// Returns true if: All event-bits set, or new result greater than current and dirty is set
private static function update(idx:int):Boolean {
if (states[idx] & BIT_DIRTY) {
var s_new:uint = get_current_states() | states[idx];
// i.e., if we've done all the events and talked to the NPC once, then play its second dialogue set
// OR if the new state is newer then try to play the 2nd
// or if we've tried to play the 2nd.
var sidx:uint = states[idx];
//trace("S_NPC.update: New: ", s_new, " Old: ", states[idx]);
if ((sidx & MAX_STATE) == MAX_STATE || s_new > sidx || s_new & BIT_SECOND_PLAYED) {
states[idx] = s_new;
states[idx] |= BIT_SECOND_PLAYED;
return true;
}
} else {
states[idx] |= BIT_DIRTY;
states[idx] |= get_current_states();
return false;
}
return false;
}
static private function get_current_states():uint
{
var s_new:uint = 0;
Registry.GE_States[Registry.GE_Bedroom_Boss_Dead_Idx] ? s_new |= BIT_BEDROOM_BOSS : 1;
Registry.GE_States[Registry.GE_Redcave_Boss_Dead_Idx] ? s_new |= BIT_REDCAVE_BOSS : 1;
Registry.GE_States[Registry.GE_Crowd_Boss_Dead_Idx] ? s_new |= BIT_CROWD_BOSS : 1;
Registry.GE_States[Registry.GE_Apartment_Boss_Dead_Idx] ? s_new |= BIT_APARTMENT_BOSS: 1;
Registry.GE_States[Registry.GE_Hotel_Boss_Dead_Idx] ? s_new |= BIT_HOTEL_BOSS : 1;
Registry.GE_States[Registry.GE_Circus_Boss_Dead_Idx] ? s_new |= BIT_CIRCUS_BOSS : 1;
//trace("S_NPC.get_current_states returns ", s_new);
return s_new;
}
}
}

View File

@ -0,0 +1,175 @@
package helper
{
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.utils.ByteArray;
import org.flixel.FlxG;
import org.flixel.FlxState;
public class ScreenFade
{
public var base:BitmapData;
public var old:BitmapData;
public var thing_to_draw:Bitmap;
public var parent:FlxState;
private var timer:Number;
public var timer_max:Number;
private var type:int;
public var rate:int;
private var cur:int = 1;
public static var T_RECT:int = 0;
public static var T_DS:int = 1; //downsample
public static var T_US:int = 2; //upsample
public static var DONE:int = 0;
public static var NOT_DONE:int = 1;
public var width:int = 160;
public var height:int = 180; //change as needed
public var offset:int = 0;
public var ADDED_CHILD:Boolean = false;
public function ScreenFade(width:int,height:int,_parent:FlxState,_type:int)
{
base = new BitmapData(width, height, true,0x00000000);
old = new BitmapData(width, height, true,0x00000000);
thing_to_draw = new Bitmap(base);
type = _type;
switch (type) {
case T_RECT:
FlxG.stage.addChild(thing_to_draw);
rate = 8;
timer = timer_max = 0.02;
break;
case T_DS:
rate = 10;
cur = 1;
thing_to_draw = new Bitmap(FlxG.camera.buffer);
timer = timer_max = 0.01;
break;
case T_US:
rate = 1; //min
cur = 10; //start
thing_to_draw = new Bitmap(FlxG.camera.buffer);
timer = timer_max = 0.01;
break;
}
parent = _parent;
}
public function reset():void {
if (type == T_DS) {
rate = 10;
cur = 1;
} else if (type == T_US) {
rate = 1;
cur = 10;
}
}
public function do_effect():int {
timer -= FlxG.elapsed;
if (timer < 0) {
timer = timer_max;
switch (type) {
case T_RECT:
return fx_rect(rate);
break;
case T_DS:
FlxG.camera.buffer.copyPixels(thing_to_draw.bitmapData, thing_to_draw.bitmapData.rect, thing_to_draw.bitmapData.rect.topLeft);
cur++;
return fx_downsample(cur,rate);
break;
case T_US:
FlxG.camera.buffer.copyPixels(thing_to_draw.bitmapData, thing_to_draw.bitmapData.rect, thing_to_draw.bitmapData.rect.topLeft);
cur--;
return fx_downsample(cur, rate);
}
} else {
if (type == T_DS) {
return fx_downsample(cur,rate);
} else if (type == T_US) {
return fx_downsample(cur, rate);
}
}
return NOT_DONE;
}
private function fx_rect(rate:int):int {
for (var i:int = offset; i < offset + rate; i++) {
for (var j:int = 0; j < base.width; j++) {
base.setPixel32(j, i, 0xff000000);
}
}
offset += rate;
if (offset >= base.height) return DONE;
return NOT_DONE;
}
/*
* Downsamples the camera buffer with a from-top-left-square-downsample effect.
* This is a post-processing effect. The camera's buffer is copied to thing_to_draw,
* then on every iteration it copies a downsampled version on top
**/
private function fx_downsample(stride:int, max:int):int {
var next_color:uint;
if (stride < 1) stride = 1; //prevent infinite loop
for (var y:int = 0; y < height; y += stride) {
for (var x:int = 0; x < width; x += stride) {
next_color = thing_to_draw.bitmapData.getPixel32(x,y);
for (var _x:int = x; _x < x + stride; _x++) {
for (var _y:int = y; _y < y + stride; _y++) {
thing_to_draw.bitmapData.setPixel32(_x, _y, next_color);
}
}
}
}
FlxG.camera.buffer.copyPixels(thing_to_draw.bitmapData, thing_to_draw.bitmapData.rect, thing_to_draw.bitmapData.rect.topLeft);
if (type == T_DS) {
if (stride > max) return DONE;
} else if (type == T_US) {
if (stride <= max) return DONE;
}
return NOT_DONE;
}
/* Downsamples buf based on the top-left squares method.
* Internal locking of buf.
* This should be called before this buffer gets copied out to
* flash. */
public static function dumsample(stride:int, buf:BitmapData):void {
var next_color:uint;
buf.lock();
for (var y:int = 0; y < buf.height; y += stride) {
for (var x:int = 0; x < buf.width; x += stride) {
next_color = buf.getPixel32(x,y);
for (var _x:int = x; _x < x + stride; _x++) {
for (var _y:int = y; _y < y + stride; _y++) {
buf.setPixel32(_x, _y, next_color);
}
}
}
}
buf.unlock();
}
public function destroy():void {
if (type == T_RECT) {
FlxG.stage.removeChild(thing_to_draw);
}
base = old = null;
thing_to_draw = null;
parent = null
}
}
}

View File

@ -0,0 +1,540 @@
package helper
{
import entity.decoration.*;
import entity.enemy.apartment.*;
import entity.enemy.bedroom.*;
import entity.enemy.circus.*;
import entity.enemy.crowd.*;
import entity.enemy.etc.*;
import entity.enemy.hotel.*;
import entity.enemy.redcave.*;
import entity.enemy.suburb.Suburb_Killer;
import entity.enemy.suburb.Suburb_Walker;
import entity.gadget.*;
import entity.interactive.*;
import entity.interactive.npc.Forest_NPC;
import entity.interactive.npc.Happy_NPC;
import entity.interactive.npc.Huge_Fucking_Stag;
import entity.interactive.npc.Mitra;
import entity.interactive.npc.Redsea_NPC;
import entity.interactive.npc.Sage;
import entity.interactive.npc.Shadow_Briar;
import entity.interactive.npc.Space_NPC;
import entity.interactive.npc.Trade_NPC;
import entity.player.*;
import flash.geom.Point;
import global.*;
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;
import states.*;
public class SpriteFactory {
public static var P_GRID_LOCAL:int = 0;
public static var P_MAP_LOCAL:int = 1;
public static var P_GLOBAL:int = 2;
// HI
// TODO
/* Events come from one spritesheet and the frames */
public static var EVENT_TYPE_DARKNESS_ALPHA:int = 0;
public static var EVENT_TYPE_SCALE_VOLUME:int = 1;
public static var EVENT_TYPE_SET_ENTRANCE:int = 2;
public static var EVENT_TYPE_TEXT:int = 3;
public static var EVENT_TYPE_STATIC_OFF:int = 4;
[Embed (source = "../res/sprites/enemies/enemy_explode_2.png")] public static var SPRITE_ENEMY_EXPLODE_2:Class;
/**
*
* @param sprite the xml reference for this object
* @param id deprecated?
* @param gridObjects array ofs tateless/stateful sprites
* @param otherObjects
* @param player player object
* @param parent_state sometimes we directly add stuff
* @return -1 if no sprite made, otherwise the number of subsprites in addition to main sprites
*/
public static function makeSprite(sprite:XML, id:int, gridObjects:Array, otherObjects:Array = null, player:Player=null, parent_state:*=null, darkness:FlxSprite = null):int {
var newSprite:FlxSprite;
var x:int = parseInt(sprite.@x);
var y:int = parseInt(sprite.@y) + Registry.HEADER_HEIGHT;
var frame_type:int = parseInt(sprite.@frame);
var permanence:int = parseInt(sprite.@p);
var name:String = sprite.name();
if (permanence == 0 && sprite.@alive == "false") sprite.@alive = "true";
if (name == "Slime") {
if (sprite.@alive == "false") {
Registry.GRID_ENEMIES_DEAD++;
return -1;
}
if (frame_type == Slime.KEY_T) sprite.@p = P_GLOBAL;
newSprite = new Slime(x, y, id, frame_type,sprite,player,parent_state);
gridObjects.push(newSprite);
return 0;
} else if (name == "SinglePushBlock") {
var spb:SinglePushBlock = new SinglePushBlock(x, y, sprite,player);
gridObjects.push(spb);
otherObjects.push(spb.sentinel);
return 0;
} else if (name == "Door") {
newSprite = new Door(x, y, sprite, parent_state);
parent_state.bg_sprites.add(newSprite);
if (parseInt(sprite.@type.toXMLString()) == Door.NEXUS_PAD) {
trace("Faking nexus pad");
var _npc:NPC = new NPC(EventScripts.fake_xml("NPC",x.toString(),y.toString(),"generic","true","0","2"), parent_state,player);
gridObjects.push(_npc);
otherObjects.push(_npc.active_region);
return 1;
}
return -1;
} else if (name == "Wall_Laser") {
var newerSprite:Wall_Laser = new Wall_Laser(x, y, sprite.@type, id);
gridObjects.push(newerSprite);
otherObjects.push(newerSprite.laser);
return 1;
} else if (name == "Eye_Light") {
var eye_light:Eye_Light = new Eye_Light(x, y, sprite, darkness);
gridObjects.push(eye_light);
otherObjects.push(eye_light.light);
return 0;
} else if (name == "Mover") {
var mover:Mover = new Mover(x, y, player, 1.0,sprite,player,parent_state);
gridObjects.push(mover); return 0;
} else if (name == "KeyBlock") {
if (sprite.@alive == "false") return -1;
var keyBlock:KeyBlock = new KeyBlock(x, y, frame_type,player, sprite);
gridObjects.push(keyBlock); return 0;
} else if (name == "Key") {
var key:Key = new Key(x, y,player,parent_state,sprite);
gridObjects.push(key);
} else if (name == "Hole") {
var hole:Hole = new Hole(x, y, sprite,player);
parent_state.bg_sprites.add(hole); return -1;
} else if (name == "Gate") {
sprite.@p = "2";
var gate:Gate = new Gate(x, y, sprite,player);
gridObjects.push(gate); return 0;
} else if (name == "Treasure") {
var treasure:Treasure = new Treasure(x, y, sprite,parent_state as FlxState);
sprite.@p = "2";
parent_state.fg_sprites.add(treasure.item);
gridObjects.push(treasure); return 0;
} else if (name == "CrackedTile") {
var cracked_tile:CrackedTile = new CrackedTile(x, y, sprite,player);
parent_state.anim_tiles_group.add(cracked_tile.hole);
parent_state.anim_tiles_group.add(cracked_tile); //will get drawn because anim tiles added later
return -1;
} else if (name == "Button") {
var button:Button = new Button(x, y, sprite,parent_state);
parent_state.anim_tiles_group.add(button);
return -1;
} else if (name == "Sun_Guy") {
if (sprite.@alive == "false") {
Registry.GRID_ENEMIES_DEAD++;
return -1;
}
var sun_guy:Sun_Guy = new Sun_Guy(x, y, darkness, parent_state as PlayState, sprite,player);
gridObjects.push(sun_guy);
return 0;
} else if (name == "Dust") {
var dust:Dust = new Dust(x, y, sprite, parent_state);
parent_state.bg_sprites.add(dust);
return -1;
} else if (name == "Event") {
//var event_script:EventScripts = new EventScripts();
//gridObjects.push(event_script); //For consistency
deal_with_event(sprite, parent_state);
return -1;
} else if (name == "Shieldy") {
if (sprite.@alive == "false") {
Registry.GRID_ENEMIES_DEAD++;
return -1;
}
var shieldy:Shieldy = new Shieldy(x, y, sprite,parent_state as PlayState);
gridObjects.push(shieldy); return 0;
} else if (name == "Pew_Laser") {
var pew_laser:Pew_Laser = new Pew_Laser(x, y, sprite, parent_state as PlayState);
gridObjects.push(pew_laser); return 0;
} else if (name == "Annoyer") {
var annoyer:Annoyer = new Annoyer(x, y, sprite, player,parent_state);
gridObjects.push(annoyer); return 0;
} else if (name == "Console") {
var console:Console = new Console(x, y, sprite,player);
gridObjects.push(console);
return 0;
} else if (name == "Follower_Bro") {
var fb:Follower_Bro = new Follower_Bro(sprite, player);
fb.y += Registry.HEADER_HEIGHT;
gridObjects.push(fb);
return 0;
} else if (name == "Sadbro") {
var sadbro:Sadbro = new Sadbro(sprite, player);
sadbro.y += Registry.HEADER_HEIGHT;
gridObjects.push(sadbro);
return 0;
} else if (name == "Red_Walker") {
var redwalker:Red_Walker = new Red_Walker(sprite,player);
redwalker.y += Registry.HEADER_HEIGHT;
gridObjects.push(redwalker);
return 0;
} else if (name == "Four_Shooter") {
var fsht:Four_Shooter = new Four_Shooter(sprite, parent_state as PlayState, player);
fsht.y += Registry.HEADER_HEIGHT;
gridObjects.push(fsht);
return 0;
} else if (name == "Slasher") {
var slasher:Slasher = new Slasher(sprite, parent_state as PlayState, player);
slasher.y += Registry.HEADER_HEIGHT;
gridObjects.push(slasher);
return 0;
} else if (name == "On_Off_Laser") {
var oolasser:On_Off_Laser = new On_Off_Laser(sprite,player);
oolasser.y += Registry.HEADER_HEIGHT;
oolasser.laser.y += Registry.HEADER_HEIGHT;
gridObjects.push(oolasser);
otherObjects.push(oolasser.laser);
return 0;
} else if (name == "Red_Pillar") {
var red_pillar:Red_Pillar = new Red_Pillar(sprite,player,parent_state);
red_pillar.y += Registry.HEADER_HEIGHT;
gridObjects.push(red_pillar);
return 0;
} else if (name == "Solid_Sprite") {
var ss:Solid_Sprite = new Solid_Sprite(sprite,false,player);
ss.y += Registry.HEADER_HEIGHT;
gridObjects.push(ss);
ss.y += 0;
return 0;
} else if (name == "Big_Door") {
var bigdoor:Big_Door = new Big_Door(sprite, player);
bigdoor.y += Registry.HEADER_HEIGHT;
otherObjects.push(bigdoor.active_region);
gridObjects.push(bigdoor);
parent_state.fg_sprites.add(bigdoor.locked_squares);
parent_state.fg_sprites.add(bigdoor.white_flash);
parent_state.fg_sprites.add(bigdoor.score_text_1);
parent_state.fg_sprites.add(bigdoor.score_text_2);
return 0;
} else if (name == "Fisherman") {
var fisherman:Fisherman = new Fisherman(sprite, player);
fisherman.y += Registry.HEADER_HEIGHT;
gridObjects.push(fisherman);
return 0;
} else if (name == "Jump_Trigger" || name == "Spring_Pad") {
var jt:Jump_Trigger = new Jump_Trigger(sprite, player,parent_state);
jt.y += Registry.HEADER_HEIGHT;
gridObjects.push(jt);
return 0;
} else if (name == "NPC") {
var npc:NPC = new NPC(sprite, parent_state,player);
npc.y += Registry.HEADER_HEIGHT;
gridObjects.push(npc);
otherObjects.push(npc.active_region);
return 0;
} else if (name == "Red_Boss") {
var redboss:Red_Boss = new Red_Boss(sprite, parent_state as PlayState, player);
redboss.y += Registry.HEADER_HEIGHT;
gridObjects.push(redboss);
return 0;
} else if (name == "Propelled") {
var propelled:Propelled = new Propelled(sprite, player, parent_state);
propelled.y += Registry.HEADER_HEIGHT;
parent_state.bg_sprites.add(propelled);
return -1;
} else if (name == "Stop_Marker") {
var stopmarker:Stop_Marker = new Stop_Marker(sprite, parent_state);
stopmarker.y += Registry.HEADER_HEIGHT;
gridObjects.push(stopmarker);
return 0;
} else if (name == "Person") {
var person:Person = new Person(sprite, player, parent_state);
person.y += Registry.HEADER_HEIGHT;
gridObjects.push(person);
return 0;
} else if (name == "Rotator") {
var rotator:Rotator = new Rotator(sprite, player);
rotator.y += Registry.HEADER_HEIGHT;
gridObjects.push(rotator);
otherObjects.push(rotator.sprite_ball);
return 0;
} else if (name == "Frog") {
var frog:Frog = new Frog(sprite, player, parent_state);
frog.y += Registry.HEADER_HEIGHT;
gridObjects.push(frog);
return 0;
}else if (name == "Spike_Roller") {
var spike_roller:Spike_Roller = new Spike_Roller(sprite, player, parent_state);
spike_roller.y += Registry.HEADER_HEIGHT;
gridObjects.push(spike_roller);
//adding done inside class
return 0;
} else if (name == "Dog") {
var dog:Dog = new Dog(sprite, player, parent_state);
dog.y += Registry.HEADER_HEIGHT;
gridObjects.push(dog);
return 0;
} else if (name == "WallBoss") {
var wallboss:WallBoss = new WallBoss(sprite, player, parent_state);
gridObjects.push(wallboss);
return 0;
} else if (name == "Pillar_Switch") {
var psw:Pillar_Switch = new Pillar_Switch(sprite, player, parent_state);
psw.y += 20; gridObjects.push(psw); return 0;
} else if (name == "Switch_Pillar") {
var ssss:Switch_Pillar = new Switch_Pillar(sprite, player, parent_state);
ssss.y += 20; parent_state.bg_sprites.add(ssss); return -1;
} else if (name == "Silverfish") {
var silverfish:Silverfish = new Silverfish(sprite, player, parent_state);
silverfish.y += Registry.HEADER_HEIGHT; gridObjects.push(silverfish); return 0;
} else if (name == "Rat") {
var rat:Rat = new Rat(sprite, player, parent_state);
rat.y += Registry.HEADER_HEIGHT; gridObjects.push(rat); return 0;
} else if (name == "Teleguy") {
var teleguy:Teleguy = new Teleguy(sprite, player, parent_state);
teleguy.y += Registry.HEADER_HEIGHT; gridObjects.push(teleguy); return 0;
} else if (name == "Dash_Trap") {
var dashtrap:Dash_Trap = new Dash_Trap(sprite, player, parent_state);
dashtrap.y += Registry.HEADER_HEIGHT; gridObjects.push(dashtrap); return 0;
} else if (name == "Gasguy") {
var gasguy:Gasguy = new Gasguy(sprite, player, parent_state);
gasguy.y += Registry.HEADER_HEIGHT; gridObjects.push(gasguy); return 0;
} else if (name == "Terminal_Gate") {
var tgate:Terminal_Gate = new Terminal_Gate(sprite, player, parent_state);
tgate.y += Registry.HEADER_HEIGHT; gridObjects.push(tgate); return 0;
} else if (name == "Dustmaid") {
var dustmaid:Dustmaid = new Dustmaid(sprite, player, parent_state);
dustmaid.y += Registry.HEADER_HEIGHT; gridObjects.push(dustmaid); return 0;
} else if (name == "Splitboss") {
var splitboss:Splitboss = new Splitboss(sprite, player, parent_state);
splitboss.y += Registry.HEADER_HEIGHT; gridObjects.push(splitboss); return 0;
} else if (name == "Nonsolid") {
var nonsolid:Nonsolid = new Nonsolid(sprite);
nonsolid.y += Registry.HEADER_HEIGHT; gridObjects.push(nonsolid); return 0;
} else if (name == "Steam_Pipe") {
var steam_pipe:Steam_Pipe = new Steam_Pipe(sprite, player, parent_state);
steam_pipe.y += Registry.HEADER_HEIGHT; gridObjects.push(steam_pipe); return 0;
} else if (name == "Burst_Plant") {
var burstplant:Burst_Plant = new Burst_Plant(sprite, player, parent_state);
burstplant.y += Registry.HEADER_HEIGHT; gridObjects.push(burstplant); return 0;
} else if (name == "Dash_Pad") {
var dashpad:Dash_Pad = new Dash_Pad(sprite, player, parent_state);
dashpad.y += Registry.HEADER_HEIGHT; parent_state.bg_sprites.add(dashpad); return -1;
} else if (name == "Elevator") {
var elevator:Elevator = new Elevator(sprite, player, parent_state);
elevator.y += Registry.HEADER_HEIGHT; parent_state.fg_sprites.add(elevator);
return -1;
} else if (name == "Eye_Boss") {
var eyeboss:Eye_Boss = new Eye_Boss(sprite, player, parent_state);
eyeboss.y += Registry.HEADER_HEIGHT;
if (Eye_Boss.global_state != eyeboss.gs_water) {
gridObjects.push(eyeboss);
} else {
parent_state.bg_sprites.add(eyeboss);
}
return -1;
} else if (name == "HealthPickup") {
var healthpickup:HealthPickup = new HealthPickup(x, y + 20, parseInt(sprite.@type), parent_state, sprite);
gridObjects.push(healthpickup); return 0; //broken
} else if (name == "Contort") {
var contort:Contort = new Contort(sprite, player, parent_state);
contort.y += Registry.HEADER_HEIGHT;
gridObjects.push(contort); return 0;
} else if (name == "Lion") {
var lion:Lion = new Lion(sprite, player, parent_state);
lion.y += Registry.HEADER_HEIGHT;
gridObjects.push(lion); return 0;
} else if (name == "Circus_Folks") {
var circus_folk:Circus_Folks = new Circus_Folks(sprite, player, parent_state);
circus_folk.y += Registry.HEADER_HEIGHT;
gridObjects.push(circus_folk); return 0;
} else if (name == "Fire_Pillar") {
var fire_pillar:Fire_Pillar = new Fire_Pillar(sprite, player, parent_state);
fire_pillar.y += Registry.HEADER_HEIGHT;
gridObjects.push(fire_pillar); return 0;
} else if (name == "solid_tile") {
var g:FlxTilemap;
var tx:int;
var ty:int;
g = parent_state.curMapBuf;
tx = int((x % 160) / 16);
ty = int(((y - 20) % 160) / 16);
g.setTileByIndex(10 * ty + tx,1, false);
// Now set the BG2 and FG2 layers since they don't load dynamically.
tx = int(x / 16);
ty = int((y - 20)/ 16);
g = parent_state.map_bg_2;
g.setTileByIndex(g.widthInTiles * ty + tx, 1, false);
g = parent_state.map_fg;
g.setTileByIndex(g.widthInTiles * ty + tx, 1, false);
} else if (name == "Sage") {
var sage:Sage = new Sage(player, parent_state, sprite);
sage.y += Registry.HEADER_HEIGHT;
gridObjects.push(sage); return 0;
} else if (name == "Mitra") {
var mitra:Mitra = new Mitra(player, parent_state, sprite);
mitra.y += Registry.HEADER_HEIGHT;
gridObjects.push(mitra); return 0;
} else if (name == "Health_Cicada") {
var hc:Health_Cicada = new Health_Cicada(player, parent_state, sprite);
hc.y += Registry.HEADER_HEIGHT;
parent_state.header_group.add(hc.boxes);
parent_state.header_group.add(hc);
Registry.subgroup_destroyems.push(hc);
return -1;
} else if (name == "Dungeon_Statue") {
var dunst:Dungeon_Statue = new Dungeon_Statue(player, parent_state, sprite);
dunst.y += Registry.HEADER_HEIGHT;
gridObjects.push(dunst);
return 0;
} else if (name == "Chaser") {
var chaser:Chaser = new Chaser(sprite, player, parent_state);
chaser.y += Registry.HEADER_HEIGHT;
gridObjects.push(chaser);
return 0;
} else if (Registry.CURRENT_MAP_NAME == "SUBURB") {
if (name == "Suburb_Walker") {
var subwalk:Suburb_Walker = new Suburb_Walker(new Array(sprite, player, parent_state,true));
gridObjects.push(subwalk);
return 0;
} else if (name == "Suburb_Killer") {
var subkiller:Suburb_Killer = new Suburb_Killer(new Array(sprite, player, parent_state,true));
gridObjects.push(subkiller);
return 0;
}
} else if (name == "Space_Face") {
var space_face:Space_Face = new Space_Face(new Array(sprite, player, parent_state,true));
gridObjects.push(space_face);
return 0;
} else if (name == "Water_Anim") {
var waternaim:Water_Anim = new Water_Anim(new Array(sprite, player, parent_state));
gridObjects.push(waternaim);
return 0;
} else if (name == "Go_Detector") {
var gd:Go_Detector = new Go_Detector(new Array(sprite, player, parent_state,true));
gridObjects.push(gd);
return 0;
} else if (name == "Sage_Boss") {
var sbb:Sage_Boss = new Sage_Boss(new Array(sprite, player, parent_state, true));
gridObjects.push(sbb);
return 0;
} else if (name == "Shadow_Briar") {
if (Registry.CURRENT_MAP_NAME == "GO") {
var briarboss:Briar_Boss = new Briar_Boss(new Array(sprite, player, parent_state, true));
gridObjects.push(briarboss);
return 0;
}
var sbri:Shadow_Briar = new Shadow_Briar(new Array(sprite, player, parent_state, true));
gridObjects.push(sbri);
return 0;
} else if (name == "Trade_NPC") { //cat, monster, shopkeeper - in FIELDS
var tradenpc:Trade_NPC = new Trade_NPC(new Array(sprite, player, parent_state, true));
// only add to statelesses or wahetvver if it isnt the cat
if (parseInt(sprite.@frame) != 0) {
gridObjects.push(tradenpc);
return 0;
}
return -1;
} else if (name == "Forest_NPC") {
var forestnpc:Forest_NPC = new Forest_NPC(new Array(sprite, player, parent_state, true));
gridObjects.push(forestnpc);
return 0;
} else if (name == "Redsea_NPC") {
var redseanpc:Redsea_NPC = new Redsea_NPC(new Array(sprite, player, parent_state, true));
gridObjects.push(redseanpc);
return 0;
} else if (name == "Happy_NPC") {
var hapnpc:Happy_NPC = new Happy_NPC(new Array(sprite, player, parent_state, true));
gridObjects.push(hapnpc);
return 0;
} else if (name == "Space_NPC") {
var spacenpc:Space_NPC = new Space_NPC(new Array(sprite, player, parent_state, true));
gridObjects.push(spacenpc);
return 0;
} else if (name == "Huge_Fucking_Stag") {
var hfs:Huge_Fucking_Stag = new Huge_Fucking_Stag(new Array(sprite, player, parent_state, true));
gridObjects.push(hfs);
return 0;
} else if (name == "Black_Thing") {
var blackthing:Black_Thing = new Black_Thing(new Array(sprite, player, parent_state, true));
gridObjects.push(blackthing);
}
return -1;
}
public static function deal_with_event(e:XML,parent:*=null):int {
var event_type:int = parseInt(e.@frame);
switch (event_type) {
case EVENT_TYPE_DARKNESS_ALPHA:
Registry.EVENT_CHANGE_DARKNESS_ALPHA = true;
Registry.EVENT_CHANGE_DARKNESS_ALPHA_TARGET = parseFloat(e.@type);
break;
case EVENT_TYPE_SCALE_VOLUME:
Registry.EVENT_CHANGE_VOLUME_SCALE = true;
Registry.EVENT_CHANGE_VOLUME_SCALE_TARGET = parseFloat(e.@type);
break;
case EVENT_TYPE_SET_ENTRANCE:
var checkpoint:Checkpoint = new Checkpoint(parent.player, parent, e);
checkpoint.y += Registry.HEADER_HEIGHT;
parent.bg_sprites.add(checkpoint);
break;
case EVENT_TYPE_TEXT:
var font:FlxBitmapFont;
if (e.@type.toString() == "street1") {
font = EventScripts.init_bitmap_font(" ", "center", 0, 0, new Point(1, 1), "apple_white");
} else {
font = EventScripts.init_bitmap_font(" ", "center", 0, 0, new Point(1, 1), "apple_black");
}
font.setText(set_text_event(e.@type.toString()),true,0,0,"center",true);
font.x = parseInt(e.@x);
font.y = parseInt(e.@y);
parent.bg_sprites.add(font);
//parent.sortables.add(font);
font.y += Registry.HEADER_HEIGHT;
return 1;
break;
case EVENT_TYPE_STATIC_OFF:
PlayState.GFX_STATIC_ALWAYS_ON = false;
parent.dec_over.exists = false;
break;
}
return 0;
}
public static function set_text_event(type:String):String {
if (type == "blank1") {
return " \nMove with \n" + Registry.controls[Keys.IDX_UP] +", " + Registry.controls[Keys.IDX_DOWN]
+ ",\n" + Registry.controls[Keys.IDX_LEFT] + ", " + Registry.controls[Keys.IDX_RIGHT];
} else if (type == "blank2") {
return "Interact with\nthe " + Registry.controls[Keys.IDX_ACTION_1] + " key.";
} else if (type == "blank3") {
if (!Intra.is_demo) {
return "Press " + Registry.controls[Keys.IDX_PAUSE] + " \nto open the menu \nand save the game.\n";
} else {
return " ";
}
} else if (type == "street1") {
return "Attack to pick up\nand drop dust.";
}
return "a";
}
}
}

View File

@ -0,0 +1,18 @@
package helper
{
import com.amanitadesign.steam.FRESteamWorks;
/**
* ...
* @author Melos Han-Tani
*/
public class SteamThing
{
public var SteamWorks:FRESteamWorks;
public function init():void {
SteamWorks = new FRESteamWorks();
}
}
}

View File

@ -0,0 +1,172 @@
package helper
{
import flash.geom.Point;
import flash.geom.Rectangle;
import org.flixel.FlxG;
/**
* ...
* @author Copyright Melos Han-Tani, Developer of Analgesic Productions LLC, 2013 - ? , www.twitter.com/seagaia2
*/
public class UI_Offsets
{
public function UI_Offsets()
{
// Set defaults
}
public var save_array:Array;
public var portrait_dpad:Point = new Point();
public var portrait_x_a1:Point = new Point();
public var portrait_c_a2:Point = new Point();
public var portrait_pause:Point = new Point();
public var portrait_game:Point = new Point();
public var landscape_dpad:Point = new Point();
public var landscape_x_a1:Point = new Point();
public var landscape_c_a2:Point = new Point();
public var landscape_pause:Point = new Point();
public var landscape_game:Point = new Point();
public var scale_portrait_dpad:Number = 1;
public var scale_portrait_x_a1:Number = 1;
public var scale_portrait_c_a2:Number = 1;
public var scale_portrait_pause:Number = 1;
public var scale_portrait_game:Number = 1;
public var scale_landscape_dpad:Number = 1;
public var scale_landscape_x_a1:Number = 1;
public var scale_landscape_c_a2:Number = 1;
public var scale_landscape_pause:Number = 1;
public var scale_landscape_game:Number = 1;
public function get_save_array():Array {
var a:Array = new Array(
portrait_dpad.x, portrait_dpad.y, scale_portrait_dpad,
portrait_x_a1.x, portrait_x_a1.y, scale_portrait_x_a1,
portrait_c_a2.x, portrait_c_a2.y, scale_portrait_c_a2,
portrait_pause.x, portrait_pause.y, scale_portrait_pause,
portrait_game.x,portrait_game.y,scale_portrait_game,
landscape_dpad.x, landscape_dpad.y, scale_landscape_dpad,
landscape_x_a1.x, landscape_x_a1.y, scale_landscape_x_a1,
landscape_c_a2.x, landscape_c_a2.y, scale_landscape_c_a2,
landscape_pause.x, landscape_pause.y, scale_landscape_pause,
landscape_game.x,landscape_game.y,scale_landscape_game);
return a;
}
public function load_save_array(a:Array):void {
if (a == null) return;
save_array = a;
portrait_dpad.x = a[0]; portrait_dpad.y = a[1]; scale_portrait_dpad = a[2];
portrait_x_a1.x = a[3]; portrait_x_a1.y = a[4]; scale_portrait_x_a1 = a[5];
portrait_c_a2.x = a[6]; portrait_c_a2.y = a[7]; scale_portrait_c_a2 = a[8];
portrait_pause.x = a[9]; portrait_pause.y = a[10]; scale_portrait_pause = a[11];
portrait_game.x = a[12]; portrait_game.y = a[13]; scale_portrait_game = a[14];
landscape_dpad.x = a[15]; landscape_dpad.y = a[16]; scale_landscape_dpad = a[17];
landscape_x_a1.x = a[18]; landscape_x_a1.y = a[19]; scale_landscape_x_a1 = a[20];
landscape_c_a2.x = a[21]; landscape_c_a2.y = a[22]; scale_landscape_c_a2 = a[23];
landscape_pause.x = a[24]; landscape_pause.y = a[25]; scale_landscape_pause = a[26];
landscape_game.x = a[27]; landscape_game.y = a[28]; scale_landscape_game = a[29];
}
public function set_defaults(sw:int, sh:int,fsw:int,fsh:int,only_land:Boolean=false,only_portrait:Boolean=false):void {
var l:int = sw > sh ? sw : sh;
var s:int = sw > sh ? sh : sw;
trace(s, l);
//Landscape
//scale_landscape_game = int(3 * (s / 540.0)) / 3.0;
if (!only_portrait) {
scale_landscape_game = (s / 540.0);
var margin_w:int = (l - 480.0 * scale_landscape_game) / 2;
scale_landscape_dpad = int(4 * ((margin_w - 8) / 144.0)) / 4.0;
if (scale_landscape_dpad <= 0.85) {
scale_landscape_dpad = 1;
}
landscape_dpad.x = (margin_w - 144.0 * scale_landscape_dpad) / 2.0;
if (s < 600) {
landscape_dpad.y = (s - 144.0 * scale_landscape_dpad);
} else {
landscape_dpad.y = (s - 144.0 * scale_landscape_dpad) / 2.0;
}
if (landscape_dpad.x < 0) landscape_dpad.x = 0;
scale_landscape_x_a1 = scale_landscape_c_a2 = int (4 * ((margin_w - 6 ) / (2 * 48.0))) / 4.0;
if (scale_landscape_c_a2 < 1) {
scale_landscape_c_a2 = scale_landscape_x_a1 = 1;
}
landscape_x_a1.x = (l - margin_w) + ((margin_w / 2) - (48.0 * scale_landscape_x_a1)) / 2.0;
landscape_c_a2.x = landscape_x_a1.x + (margin_w / 2);
var action_bottom:int = 3 * (s / 5.0);
landscape_x_a1.y = action_bottom - 96.0 * scale_landscape_x_a1;
landscape_c_a2.y = action_bottom - 96.0 * scale_landscape_c_a2;
scale_landscape_pause = int (4 * ((margin_w - 6 ) / 96.0)) / 4.0;
landscape_pause.x = (l - margin_w) + (margin_w - (scale_landscape_pause * 96.0)) / 2;
landscape_pause.y = s - 4.0 - 48 * scale_landscape_pause;
landscape_game.x = (l - 480.0 * scale_landscape_game) / 2;
landscape_game.x /= scale_landscape_game; // ???
landscape_game.y = (s - 540.0 * scale_landscape_game) / 2;
landscape_game.y /= scale_landscape_game;
}
// Portrait
//scale_portrait_game = int(3*((2*l / 3) / 480.0))/3.0;
if (!only_land) {
scale_portrait_game =Math.min((2 * l / 3) / 480.0, s / 480.0);
var game_bottom:int = scale_portrait_game * 540.0;
var margin_h:int = l - game_bottom;
action_bottom = (game_bottom + (3 / 4) * margin_h);
margin_w = s / 2;
scale_portrait_dpad = int(3 * ((Math.min(margin_h, margin_w) * 0.9) / 144.0)) / 3.0;
if (scale_portrait_dpad <= 1) {
scale_portrait_dpad = 0.85;
}
portrait_dpad.x = (margin_w - 144.0 * scale_portrait_dpad) / 2.0;
portrait_dpad.y = ((margin_h - scale_portrait_dpad * 144.0) / 2) + game_bottom;
scale_portrait_c_a2 = scale_portrait_x_a1 = Math.min( int(4 * ((margin_w * 0.8) / (2 * 48.0))) / 4.0, int(4 * (((3 / 4) * margin_h - 6) / 96.0)) / 4.0);
if (scale_portrait_c_a2 < 1) { // on a fucking iphone
scale_portrait_c_a2 = 0.86;
scale_portrait_x_a1 = 0.86;
}
portrait_x_a1.x = (margin_w) + ((margin_w / 2.0) - (48.0 * scale_portrait_x_a1)) / 2.0;
portrait_c_a2.x = portrait_x_a1.x + (margin_w / 2.0);
portrait_c_a2.y = portrait_x_a1.y = game_bottom + ((action_bottom - game_bottom) - (scale_portrait_c_a2 * 96.0)) / 2.0;
scale_portrait_pause = Math.min(int(((margin_w * 0.8) / 96.0) * 2) / 2.0, int(((margin_h * 0.9 * .25) / 48.0) * 2) / 2.0);
if (scale_portrait_pause < 1) scale_portrait_pause = 0.77;
portrait_pause.x = ((margin_w - 96.0 * scale_portrait_pause) / 2) + margin_w;
portrait_pause.y = action_bottom + ((l - action_bottom) - (48.0 * scale_portrait_pause)) / 2.0;
if (scale_portrait_pause < 1) {
portrait_pause.y -= 2;
}
portrait_game.x = (s - 480.0 * scale_portrait_game) / 2;
portrait_game.x /= scale_portrait_game;
portrait_game.y = 0;
}
//scale_portrait_game = int(3*((2*l / 3) / 480.0))/3.0;
//scale_landscape_game = int(3 * (s / 540.0)) / 3.0;
//Intra.scale_ctr = Intra.SCALE_TYPE_FIT;
//var i:Intra = FlxG._game as Intra;
//i.resize_mobile_game();
}
}
}

Binary file not shown.

BIN
intra/src/helper/static.pbj Normal file

Binary file not shown.

View File

@ -0,0 +1,234 @@
package states
{
import helper.DH;
import helper.EventScripts;
import org.flixel.FlxPoint;
import org.flixel.FlxSprite;
import org.flixel.FlxText;
import global.Registry;
import org.flixel.plugin.photonstorm.FlxBitmapFont;
import global.Keys;
import org.flixel.FlxG;
import flash.events.KeyboardEvent;
/**
* ...
* @author Seagaia
*/
public class ControlsState extends PushableFlxState
{
[Embed (source = "../res/sprites/inventory/controls.png")] public static var S_CONTROLS:Class;
public var bg:FlxSprite = new FlxSprite(0, 0);
public var instruction:FlxBitmapFont;
public var controls:FlxBitmapFont;
public var i:int = 0;
private var input:String;
private var recent_key_code:uint = 1000;
public var updating:Boolean = false;
private var filler:String = " \n";
public var is_blank_world:Boolean = false;
public function ControlsState() {
create();
}
override public function create():void {
controls = EventScripts.init_bitmap_font(" ", "center", 8,16, null, "apple_white");
instruction = EventScripts.init_bitmap_font(" ", "center", 22, 102, null, "apple_white");
//instruction.setText("Press " + Registry.controls[Keys.IDX_LEFT] + "\nto set controls.\n"+Registry.controls[Keys.IDX_PAUSE]+"\n to cancel.", true, 0, 0, "center", true);
instruction.setText(DH.lk("controls",0) + " "+Registry.controls[Keys.IDX_LEFT] + "\n"+DH.lk("controls",1)+"\n"+Registry.controls[Keys.IDX_PAUSE]+"\n "+DH.lk("controls",2), true, 0, 0, "center", true);
instruction.x = 25; instruction.y = 102; instruction.scrollFactor = new FlxPoint(0, 0);
bg.scrollFactor = new FlxPoint(0, 0);
bg.x = 16;
bg.y = 16;
bg.loadGraphic(S_CONTROLS, false, false, 135, 125);
add(bg);
controls.setText(filler, true, 0, 0, "center", true);
controls.x = 18; controls.y = 16; controls.scrollFactor = new FlxPoint(0, 0);
instruction.color = controls.color = 0xffffff;
instruction.drop_shadow = controls.drop_shadow = true;
FlxG.stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
add(controls);
add(instruction);
}
override public function destroy():void {
FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
controls.destroy();
controls = null;
instruction.destroy();
instruction = null;
bg = null;
super.destroy();
}
public function change_text():void {
remove(controls, true);
remove(instruction, true);
controls = EventScripts.init_bitmap_font(" ", "center", 8,16, null, "apple_white");
instruction = EventScripts.init_bitmap_font(" ", "center", 22, 102, null, "apple_white");
if (DH.language_type == DH.LANG_ko) {
instruction.setText(Registry.controls[Keys.IDX_LEFT] + "\n" + DH.lk("controls", 1) + "\n" + Registry.controls[Keys.IDX_PAUSE] + "\n " + DH.lk("controls", 2), true, 0, 0, "center", true);
} else {
instruction.setText(DH.lk("controls", 0) + " " + Registry.controls[Keys.IDX_LEFT] + "\n" + DH.lk("controls", 1) + "\n" + Registry.controls[Keys.IDX_PAUSE] + "\n " + DH.lk("controls", 2), true, 0, 0, "center", true);
}
instruction.x = 25; instruction.y = 102; instruction.scrollFactor = new FlxPoint(0, 0);
controls.setText(filler, true, 0, 0, "center", true);
controls.x = 18; controls.y = 16; controls.scrollFactor = new FlxPoint(0, 0);
instruction.color = controls.color = 0xffffff;
instruction.drop_shadow = controls.drop_shadow = true;
add(controls);
add(instruction);
}
public function reportKeyDown(event:KeyboardEvent):void {
recent_key_code = event.keyCode;
}
override public function update():void {
if (is_blank_world) {
controls.setText(filler+DH.lk("controls",3)+": " + Registry.controls[Keys.IDX_UP] +
"\n"+DH.lk("controls",4)+": " + Registry.controls[Keys.IDX_DOWN] +
"\n"+DH.lk("controls",5)+": " + Registry.controls[Keys.IDX_LEFT] +
"\n"+DH.lk("controls",6)+": " + Registry.controls[Keys.IDX_RIGHT], true, 0, 0, "center", true);
} else {
var jump:String = "???";
if (Registry.inventory[Registry.IDX_JUMP]) {
jump = DH.lk("controls",7);
}
controls.setText(filler+DH.lk("controls",3)+": " + Registry.controls[Keys.IDX_UP] +
"\n"+DH.lk("controls",4)+": " + Registry.controls[Keys.IDX_DOWN] +
"\n"+DH.lk("controls",5)+": " + Registry.controls[Keys.IDX_LEFT] +
"\n"+DH.lk("controls",6)+": " + Registry.controls[Keys.IDX_RIGHT] +
"\n"+DH.lk("controls",8)+": " + Registry.controls[Keys.IDX_ACTION_1] +
"\n"+jump+": " + Registry.controls[Keys.IDX_ACTION_2] +
"\n"+DH.lk("controls",9)+": " + Registry.controls[Keys.IDX_PAUSE], true, 0, 0, "center", true);
}
if (recent_key_code != 1000) {
if (i != 0) {
Registry.sound_data.play_sound_group(Registry.sound_data.menu_select_group);
input = FlxG.keys.getKeyName(recent_key_code);
recent_key_code = 1000;
}
}
if (i < 3 && FlxG.keys.justPressed("ESCAPE")) {
updating = false;
return;
}
if (Registry.keywatch.LEFT && (i == 0)) {
Registry.sound_data.play_sound_group(Registry.sound_data.menu_select_group);
i += 2;
//instruction.setText("Press key for\nUp", true, 0, 0, "center", true);
instruction.setText(DH.lk("controls",0)+"\n"+DH.lk("controls",3), true, 0, 0, "center", true);
recent_key_code = 1000;
updating = true;
return;
}
switch (i) {
case 2:
instruction.setText(DH.lk("controls",0)+"\n"+DH.lk("controls",3), true, 0, 0, "center", true);
if (input != "") {
if (is_valid(Keys.IDX_UP, input)) break;
Registry.controls[Keys.IDX_UP] = input;
i++;
}
break;
case 3:
instruction.setText(DH.lk("controls",0)+"\n"+DH.lk("controls",4), true, 0, 0, "center", true);
if (input != "") {
if (is_valid(Keys.IDX_DOWN, input)) break;
Registry.controls[Keys.IDX_DOWN] = input;
i++;
}
break;
case 4:
instruction.setText(DH.lk("controls",0)+"\n"+DH.lk("controls",5), true, 0, 0, "center", true);
if (input != "") {
if (is_valid(Keys.IDX_LEFT, input)) break;
Registry.controls[Keys.IDX_LEFT] = input;
i++;
}
break;
case 5:
instruction.setText(DH.lk("controls",0)+"\n"+DH.lk("controls",6),true, 0, 0, "center", true);
if (input != "") {
if (is_valid(Keys.IDX_RIGHT, input)) break;
Registry.controls[Keys.IDX_RIGHT] = input;
i++;
if (is_blank_world) i = 10;
}
break;
case 6:
instruction.setText(DH.lk("controls",0)+"\n"+DH.lk("controls",8), true, 0, 0, "center", true);
if (input != "") {
if (is_valid(Keys.IDX_ACTION_1, input)) break;
Registry.controls[Keys.IDX_ACTION_1] = input;
i++;
}
break;
case 7:
var jump_2:String = "???";
if (Registry.inventory[Registry.IDX_JUMP]) {
jump_2 = DH.lk("controls", 7);
}
instruction.setText(DH.lk("controls",0)+"\n"+jump_2+"\n", true, 0, 0, "center", true);
if (input != "") {
if (is_valid(Keys.IDX_ACTION_2, input)) break;
Registry.controls[Keys.IDX_ACTION_2] = input;
i++;
}
break;
case 8:
i++;
break;
case 9:
instruction.setText(DH.lk("controls",0)+"\n"+DH.lk("controls",9), true, 0, 0, "center", true);
if (input != "") {
if (is_valid(Keys.IDX_PAUSE, input)) break;
Registry.controls[Keys.IDX_PAUSE] = input;
i++;
}
break;
case 10:
instruction.setText(DH.lk("controls",0)+" "+Registry.controls[Keys.IDX_PAUSE]+"\n "+DH.lk("controls",11),true, 0, 0, "center", true);
if (input != "") {
i = 0;
updating = false;
instruction.setText(DH.lk("controls",0)+" " + Registry.controls[Keys.IDX_LEFT] + "\n"+DH.lk("controls",12)+"\n"
+Registry.controls[Keys.IDX_PAUSE]+" "+DH.lk("controls",2), true, 0, 0, "left", true);
}
break;
}
input = "";
}
public function is_valid(index:int, input:String):int {
if (index == 0) return (input == "ESCAPE") ? 1 : 0;
for (var i:int = 0; i < index; i++) {
if (input == "ESCAPE") return 1;
if (Registry.controls[i] == input) return 1;
}
return 0;
}
}
}

View File

@ -0,0 +1,425 @@
package states
{
import global.Registry;
import helper.DH;
import helper.EventScripts;
import org.flixel.FlxG;
import org.flixel.FlxObject;
import org.flixel.FlxPoint;
import org.flixel.FlxSprite;
import org.flixel.FlxState;
import org.flixel.plugin.photonstorm.FlxBitmapFont;
/**
* ...
* @author Seagaia
*/
public class DialogueState extends PushableFlxState
{
public var dialogue_box:FlxSprite = new FlxSprite(0, 0);
public var dialogue:FlxBitmapFont;
public var dialogue_shadow:FlxBitmapFont;
public var is_finished:Boolean = false;
private var next_char_timer_max:Number = 0.022;
private var next_char_timer:Number = 0.022;
private var chunked_dialogue:Boolean = false;
private var cur_line_nr:int = 0;
private var cur_char_nr:int = 0;
private var nr_lines_in_buffer:int = 0;
private var lines:Array;
private var Max_Lines_In_Buffer:int = 3;
public static var Max_Line_Size:int = 21;
private var s_writing:int = 0;
private var max_lines_since_last_wait:int = 3;
// Counter # of lines since the last time the player had a non-forced required input.
private var lines_since_last_wait:int = 0;
// Whether the first X lines were read.
private var did_initial_read:Boolean = false;
// Whether a ^ was read, meaning the player needs to input to proceed
private var forced_input:Boolean = false;
private var s_bumping_up:int = 1;
private var bump_timer_max:Number = 0.2;
private var bump_timer:Number = 0.2;
private var nr_bumps:int = 0;
private var bump_state_ctr:int = 0;
private var s_waiting:int = 2;
private var s_done:int = 3;
private var state:int = s_writing;
private var base_y:int; //y-coord of the text when displayed.
private var bumped_y:int; //y-coord of text when moving up.
public var blinky_box:FlxSprite = new FlxSprite(0, 0);
private var blinky_box_timer_max:Number = 0.4;
private var blinky_box_timer:Number = 0.4;
private static var box_align:uint = FlxObject.DOWN;
[Embed (source = "../res/sprites/menu/dialogue_box.png")] public static var menu_dialogue_box:Class;
[Embed(source = "../res/sprites/menu/menudialogue_box.png")] public static var real_menu_dialogue_Box:Class;
[Embed (source = "../res/sprites/menu/dialogue_blinky_box.png")] public static var menu_dialogue_blinky_box:Class;
public function DialogueState()
{
create();
}
public function create_bitmap_text():void {
var idx_1:int = members.indexOf(dialogue);
var idx_2:int = members.indexOf(dialogue_shadow);
dialogue = EventScripts.init_bitmap_font(" ", "left", dialogue_box.x + 4, dialogue_box.y + 7, null, "apple_white");
dialogue_shadow = EventScripts.init_bitmap_font(" ", "left", dialogue_box.x + 4, dialogue_box.y + 7, null, "apple_white");
if (idx_1 != -1 && idx_2 != -1) {
members[idx_1] = dialogue;
members[idx_2] = dialogue_shadow;
}
dialogue_shadow.customSpacingY = 2;
dialogue.customSpacingY = 2;
set_dialogue_box();
}
override public function create():void
{
dialogue_box.loadGraphic(menu_dialogue_box, false, false, 156, 44);
add(dialogue_box);
create_bitmap_text();
add(dialogue_shadow);
add(dialogue);
// Blinky box for dialogue
blinky_box.loadGraphic(menu_dialogue_blinky_box, true, false, 8, 8);
blinky_box.addAnimation("a", [0], 10, true);
blinky_box.play("a");
blinky_box.visible = false;
add(blinky_box);
change_visibility(false);
setAll("scrollFactor", new FlxPoint(0, 0));
set_box_position(FlxObject.DOWN);
}
override public function draw():void
{
super.draw();
}
public function set_dialogue_box():void {
if (Registry.GAMESTATE != null && Registry.GAMESTATE.state == Registry.GAMESTATE.S_PAUSED) {
dialogue.color = 0xFFFFFF;
dialogue_shadow.color = 0x000000;
dialogue_box.loadGraphic(real_menu_dialogue_Box, false, false, 156, 44);
} else if (Registry.CURRENT_MAP_NAME == "TRAIN" && Registry.GAMESTATE != null) {
dialogue.color = 0xffffff;
dialogue_box.makeGraphic(156, 44, 0xff000000);
} else {
dialogue.color = 0xFFFFFF;
dialogue_shadow.color = 0x000000;
dialogue_box.loadGraphic(menu_dialogue_box, false, false, 156, 44);
}
}
public static function set_dialogue_box_align(direction:uint):void {
box_align = direction;
}
override public function update():void
{
if (!chunked_dialogue && !is_finished) {
set_box_position(box_align);
lines = get_chunks(Registry.cur_dialogue);
chunked_dialogue = true;
did_initial_read = false;
change_visibility(true);
blinky_box.visible = false;
}
switch (state) {
case s_writing:
next_char_timer -= FlxG.elapsed;
if (next_char_timer < 0) {
next_char_timer = next_char_timer_max;
if ( Registry.keywatch.ACTION_1 || Registry.keywatch.ACTION_2) { //impatient!!
next_char_timer /= 2;
}
if (cur_line_nr == 0 && cur_char_nr == 0) {
dialogue.text = get_next_char(lines);
} else {
Registry.sound_data.play_sound_group(Registry.sound_data.dialogue_blip_group);
dialogue.text = dialogue.text + get_next_char(lines);
if (Registry.FUCK_IT_MODE_ON) {
for (var asdf:int = 0; asdf < 10; asdf++) {
if (state != s_writing) break;
dialogue.text = dialogue.text + get_next_char(lines);
}
}
}
}
break;
case s_bumping_up: // onnly enter this state with at least 2 or 3 lines.
//bump
//wait
//bump
//wait
if (bump_state_ctr == 0) {
var chunks:Array = dialogue.text.split("\n");
dialogue.text = " \n";
for (var i:int = 1; i < Max_Lines_In_Buffer; i++) {
dialogue.text += chunks[i];
dialogue.text += "\n";
}
dialogue.y = bumped_y;
bump_state_ctr = 1;
} else {
bump_timer -= FlxG.elapsed;
if (bump_timer < 0) {
bump_timer = bump_timer_max;
if (Registry.FUCK_IT_MODE_ON) {
bump_timer = 0.01;
}
// Prevent empty string breaking FLxBitmapFont
dialogue.text = dialogue.text.substring(2);
dialogue.y = base_y;
state = s_writing;
bump_state_ctr = 0;
}
}
break;
case s_waiting:
blinky_box_timer -= FlxG.elapsed;
if (blinky_box_timer < 0) {
blinky_box_timer = blinky_box_timer_max;
blinky_box.visible = !blinky_box.visible;
}
if ( Registry.keywatch.ACTION_1 || Registry.keywatch.ACTION_2) {
// When done
Registry.sound_data.dialogue_bloop.play();
if (cur_line_nr == lines.length && ( Registry.keywatch.JP_ACTION_1 || Registry.keywatch.JP_ACTION_2)) {
is_finished = true;
chunked_dialogue = false;
cur_line_nr = cur_char_nr = 0;
nr_lines_in_buffer = 0;
blinky_box.visible = false;
state = s_done;
Registry.cur_dialogue = "";
change_visibility(false);
} else if (!forced_input && cur_line_nr != lines.length) {
blinky_box.visible = false;
state = s_bumping_up;
} else if (forced_input) {
blinky_box.visible = false;
state = s_writing;
forced_input = false;
}
}
break;
case s_done:
break;
}
dialogue_shadow.x = dialogue.x;
dialogue_shadow.y = dialogue.y + 1;
dialogue_shadow.text = dialogue.text;
super.update();
}
private function get_chunks(dialogue:String):Array {
var lines:Array = new Array();
var line:String = "";
// Split on [\n!?.]
var punc:Array = new Array("\n", ".", "!", "。","…","","", "?");
var punc_chunks:Array = new Array();
// Break dialogue into chunks by punctuation. Lone newlines become whitespace
for (var pos:int = 0; pos < dialogue.length; pos++) {
line += dialogue.charAt(pos);
if (punc.indexOf(dialogue.charAt(pos)) != -1) {
if (dialogue.charAt(pos) == "\n") {
line = line.substring(0, line.length -1);
if (line.length == 0) {
line = " ";
}
} else {
if (dialogue.length - 1 > pos) {
var next_char:String = dialogue.charAt(pos +1);
// Don't push this sentence chunk if the next character is in {.!?} , or
// if the next character is not whittespace.
if (punc.indexOf(next_char) != -1 || next_char != " ") {
continue; //skips the pushing of current sentence
// Double space = line break
} else if (next_char == " ") {
//Skip one of the two whitespaces, and then end up pushing the line anyways
pos++;
}
}
}
punc_chunks.push(line);
line = "";
}
}
if (line != "") {
punc_chunks.push(line);
}
line = "";
var cc:Array = new Array(); // chunk chunks <_>
for each (var chunk:String in punc_chunks) {
// If this chunk fits, just push it into the list.
if (chunk.length <= Max_Line_Size) {
//Remove trailing whitespace if not a single character
var nr_forced_breaks:int = 0;
for (pos = 0; pos < chunk.length; pos++) {
if (chunk.charAt(pos) == "^") {
nr_forced_breaks++;
}
}
// Prevent bitmap font error w/ empty str
if ((chunk.charAt(0) == " " || chunk.charAt(0) == " " )&& (chunk.length - nr_forced_breaks) > 1) {
chunk = chunk.substring(1);
}
lines.push(chunk);
continue;
}
/* Otherwise we gotta break it up */
cc = chunk.split(" ");
var cur_len:int = 0;
for each (var c:String in cc) {
//make a new line if the current word doesnt fit
if (line.length + c.length + 1 > Max_Line_Size) {
if (line.length != 0) {
lines.push(line);
}
if (c.length > Max_Line_Size) {
var intermedIdx:int = 0;
var intermedstring:String = c;
while (intermedstring.length > Max_Line_Size) {
lines.push(c.substr(Max_Line_Size * intermedIdx, Max_Line_Size));
intermedIdx++;
intermedstring = c.substr(Max_Line_Size * intermedIdx);
}
line = intermedstring;
} else {
line = c;
}
} else {
if (line.length == 0) {
line += c;
} else {
line += " " + c;
}
}
}
lines.push(line);
line = "";
}
return lines;
}
/* Return the next character in this line.
* if we reach the end, return a new line and increment
* the number of lines in the buffer, and change state
* if needed. */
private function get_next_char(lines:Array):String {
var line:String = lines[cur_line_nr];
if (line.charAt(cur_char_nr) == "^") {
cur_char_nr++;
state = s_waiting;
forced_input = true;
return "";
// wait for input
}
if (cur_char_nr >= line.length) {
cur_char_nr = 0;
cur_line_nr++;
nr_lines_in_buffer++;
if (!did_initial_read) {
if (nr_lines_in_buffer == Max_Lines_In_Buffer) {
state = s_waiting;
did_initial_read = true;
} else if (cur_line_nr == lines.length) {
state = s_waiting;
blinky_box.visible = true;
blinky_box_timer = blinky_box_timer_max;
}
} else {
lines_since_last_wait++;
if (lines_since_last_wait == max_lines_since_last_wait || cur_line_nr == lines.length) {
lines_since_last_wait = 0;
state = s_waiting;
blinky_box.visible = true;
blinky_box_timer = blinky_box_timer_max;
} else {
state = s_bumping_up;
}
}
// read, read, read, wait
// bump, read, bump, read, bump, read
// wait
// bump, read, bump, read
return "\n";
} else {
return line.charAt(cur_char_nr++);
}
}
private function set_box_position(position:uint):void
{
if (position == FlxObject.DOWN) {
dialogue_box.y = 180 - dialogue_box.height - 2;
} else if (position == FlxObject.UP) {
dialogue_box.y = 22;
}
dialogue_box.x = 2;
dialogue.x = dialogue_box.x + 4;
dialogue.y = dialogue_box.y + 7;
if (DH.isZH()) dialogue.y = dialogue_box.y + 2;
base_y = dialogue.y;
bumped_y = dialogue.y - 5;
blinky_box.x = dialogue_box.x + dialogue_box.width - 10;
blinky_box.y = dialogue_box.y + dialogue_box.height - 10;
}
private function change_visibility(visible:Boolean):void {
dialogue_shadow.visible = dialogue.visible = dialogue_box.visible = blinky_box.visible = visible;
}
override public function push(_parent:FlxState):void
{
dialogue.text = ".";
super.push(_parent);
}
public function reset():void {
state = s_writing;
is_finished = false;
DH.update_current_scene_on_chunk_finish();
}
}
}

View File

@ -0,0 +1,637 @@
package states
{
import entity.enemy.*;
import entity.enemy.bedroom.*;
import entity.enemy.etc.Chaser;
import entity.enemy.etc.Follower_Bro;
import entity.enemy.etc.Red_Walker;
import entity.enemy.etc.Sadbro;
import entity.enemy.etc.Space_Face;
import entity.enemy.redcave.*;
import entity.enemy.crowd.*;
import entity.enemy.apartment.*;
import entity.enemy.hotel.*;
import entity.enemy.circus.*;
import entity.enemy.suburb.Suburb_Killer;
import entity.enemy.suburb.Suburb_Walker;
import entity.gadget.Checkpoint;
import entity.interactive.Fisherman;
import entity.interactive.NPC;
import entity.interactive.npc.Forest_NPC;
import entity.interactive.npc.Mitra;
import entity.interactive.npc.Sage;
import entity.interactive.npc.Shadow_Briar;
import entity.interactive.npc.Space_NPC;
import entity.interactive.npc.Trade_NPC;
import entity.player.Player;
import flash.geom.Point;
import global.Keys;
import global.Registry;
import helper.DH;
import helper.EventScripts;
import org.flixel.FlxG;
import org.flixel.FlxGroup;
import org.flixel.FlxPoint;
import org.flixel.FlxSprite;
import org.flixel.FlxState;
import org.flixel.FlxText;
import org.flixel.plugin.photonstorm.FlxBitmapFont;
public class EndingState extends FlxState
{
public function EndingState () {
}
[Embed(source = "../res/sprites/npcs/easter/dev_npcs.png")] public static const embed_dev_npcs:Class;
private var state:int = 1;
private const S_DONE:int = 2;
private const S_DIALOGUE_DONE:int = 3;
public var text:FlxBitmapFont;
public var text2:FlxBitmapFont;
private var sprites_1:FlxGroup = new FlxGroup(12);
private var sprites_2:FlxGroup = new FlxGroup(12);
private var init_sprites:Array = new Array(30);
private var positions_1:Array = new Array(new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point);
private var positions_2:Array = new Array(new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point, new Point);
public var save_dialog_bg:FlxSprite;
public var save_dialog_text:FlxBitmapFont;
public var save_dialog_selector:FlxSprite;
public var s_ctr:int = 0;
public var ctr:int = 0;
public var timer:Number = 0;
public var timer_text:FlxText = new FlxText(0, 0, 200);
private var filler:String = "\n \n";
private var overlay:FlxSprite = new FlxSprite();
private var bg:FlxSprite = new FlxSprite();
private var stop_text:FlxBitmapFont;
private var dimoverlay:FlxSprite;
private var PG_SPRITES_START:int = 12;
// Array of the dialogue. These should be almsot as screen height, so that when
// They
private var text_ctr:int = 0;
private var dialogue:Array = new Array();
private var bg_ctr:int = 0;
[Embed(source = "../res/sprites/ending/go.png")] public static const embed_go:Class;
[Embed(source = "../res/sprites/ending/screenies.png")] public static const embed_screenies:Class;
override public function destroy():void
{
super.destroy();
save_dialog_bg = save_dialog_selector = save_dialog_text = null;
overlay = null;
timer_text = null;
bg = null;
text = text2 = null;
}
override public function create():void
{
// debug
//ctr = 8;
dialogue = new Array();
for (var i:int = 0; i < 24; i++) {
dialogue.push(DH.lk("ending", i));
}
// REMOVE ABOVE LATER
text = EventScripts.init_bitmap_font(Registry.C_FONT_APPLE_WHITE_STRING, "center", 1, 180, null, "apple_white");
text2 = EventScripts.init_bitmap_font(Registry.C_FONT_APPLE_WHITE_STRING, "center", 1, 360, null, "apple_white");
if (DH.isZH()) {
filler = "\n \n";
}
//text.text = "thanks for playing lol";
text.text = dialogue[ctr] + filler;
ctr++;
text2.text = dialogue[ctr] + filler;
ctr++;
text.velocity.y = text2.velocity.y = -15; // -15 is good
text.drop_shadow = text2.drop_shadow = true;
dimoverlay = new FlxSprite(0, 0);
dimoverlay.makeGraphic(160, 180, 0xff000000);
dimoverlay.alpha = 0.2;
bg.loadGraphic(embed_go, false, false, 160, 480);
bg.x = 0; bg.y = -bg.height + 180;
overlay.makeGraphic(160, 160, 0xff171717);
add(bg);
add(overlay);
add(dimoverlay);
add(text);
add(text2)
//add(timer_text);
poopy_save_stuff();
add(save_dialog_bg);
add(save_dialog_text);
add(save_dialog_selector);
save_dialog_bg.visible = save_dialog_selector.visible = save_dialog_text.visible = false;
for (i=0; i < sprites_1.maxSize; i++) {
var s1:FlxSprite = new FlxSprite;
var s2:FlxSprite = new FlxSprite;
s1.exists = s2.exists = false;
sprites_1.add(s1);
sprites_2.add(s2);
}
add(sprites_1);
add(sprites_2);
for (i = 0; i < 30; i++) {
init_sprites[i] = false;
}
//ctr--;
// REMOVE LATER
//make_sprites(ctr-1, text);
//make_sprites(ctr, text2);
if (Registry.keywatch == null) {
Registry.keywatch = new Keys();
}
add(Registry.keywatch);
Registry.sound_data.stop_current_song();
Registry.sound_data.start_song_from_title("ENDING");
}
private var fade_out:Boolean = false;
private var depth:int = 0;
override public function update():void
{
if (Registry.keywatch.ACTION_1 && depth < 8 && ctr < 24) {
depth++;
update();
depth--;
}
timer += FlxG.elapsed;
timer_text.text = timer.toFixed(2);
if (state == S_DONE) {
if (ctr == 0) {
if (Registry.keywatch.JP_DOWN) {
save_dialog_selector.y += 8;
ctr = 1;
}
if (Registry.keywatch.JP_ACTION_1) {
Registry.GE_States[Registry.GE_Finished_Game] = true;
Save.save();
Registry.sound_data.stop_current_song();
FlxG.switchState(new TitleState());
}
} else {
if (Registry.keywatch.JP_UP) {
ctr = 0;
save_dialog_selector.y -= 8;
}
if (Registry.keywatch.JP_ACTION_1) {
Registry.sound_data.stop_current_song();
FlxG.switchState(new TitleState());
}
}
super.update();
return;
} else if (state == S_DIALOGUE_DONE) {
//stop_text.color = 0xebf600;
if (Registry.keywatch.JP_ACTION_1 || Registry.keywatch.JP_ACTION_2 || Registry.keywatch.JUST_PRESSED_PAUSE) {
fade_out = true;
}
if (fade_out) {
dimoverlay.alpha += 0.02;
stop_text.alpha -= 0.014;
}
if (stop_text.alpha <= 0) {
stop_text.y = 0;
stop_text.alpha = 1;
//stop_text.text = filler + "Now you have\nthe ability\nto explore Young's\nworld with (almost) no\nlimitations, via \nthe swap.\n";
stop_text.text = filler + DH.lk("ending", 25);
state = S_DONE;
ctr = 0;
save_dialog_bg.visible = save_dialog_selector.visible = save_dialog_text.visible = true;
return;
}
}
if (text.y < -165 && ctr < dialogue.length - 1) {
text.y = 180;
ctr++;
text.text = dialogue[ctr] + filler;
if (ctr == dialogue.length - 1) {
stop_text = text;
} else if (ctr >= PG_SPRITES_START) {
make_sprites(ctr, text);
}
} else if (text2.y < -165 && ctr < dialogue.length - 1) {
text2.y = 180;
ctr++;
text2.text = dialogue[ctr] + filler;
if (ctr == dialogue.length - 1) {
stop_text = text2;
} else if (ctr >= PG_SPRITES_START) {
make_sprites(ctr, text2);
}
}
if (stop_text != null) {
if (stop_text.y <= 0) {
stop_text.y = 0;
stop_text.velocity.y = 0;
state = S_DIALOGUE_DONE;
}
}
// woot!
if (ctr >= PG_SPRITES_START) {
for (var i:int = 0; i < sprites_1.maxSize; i++) {
if (sprites_1.members[i] == null) continue;
sprites_1.members[i].x = positions_1[i].x + text.x;
sprites_1.members[i].y = positions_1[i].y + text.y;
}
for (i = 0; i < sprites_2.maxSize; i++) {
if (sprites_2.members[i] == null) continue;
sprites_2.members[i].x = positions_2[i].x + text2.x;
sprites_2.members[i].y = positions_2[i].y + text2.y;
}
}
// set velocity thingies here etc
switch (ctr) {
case 0: case 1: case 2: case 3: case 4: case 5:
overlay.alpha = 0;
bg.alpha = 1;
if (bg.y >= 0){
bg.velocity.y = 0;
bg.y = 0;
} else {
bg.velocity.y = 10;
}
break;
case 6:
text.color = 0x000000;
text2.color = 0x000000;
text.drop_shadow = text2.drop_shadow = false;
bg.x = overlay.x = 0;
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
overlay.loadGraphic(embed_screenies, true, false, 160, 160);
overlay.y = 10;
overlay.alpha = 0;
overlay.frame = 0;
bg.velocity.y = 0;
}
bg.alpha -= fade_rate;
overlay.alpha += fade_rate;
break;
case 7:
text.color = 0xffffff;
text2.color = 0xffffff;
text.drop_shadow = text2.drop_shadow = true;
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
bg.loadGraphic(embed_screenies, true, false, 160, 160);
bg.frame = 1;
bg.y = 10;
}
bg.alpha += fade_rate;
overlay.alpha -= fade_rate;
break;
case 8:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
overlay.frame = 2;
}
overlay.alpha += fade_rate;
bg.alpha -= fade_rate;
break;
case 9:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
bg.frame = 3;
}
bg.alpha += fade_rate;
overlay.alpha -= fade_rate;
break;
case 10:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
overlay.frame = 4;
}
overlay.alpha += fade_rate;
bg.alpha -= fade_rate;
break;
case 11:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
bg.frame = 5;
}
bg.alpha += fade_rate;
overlay.alpha -= fade_rate;
break;
case 12:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
overlay.frame = 6;
}
overlay.alpha += fade_rate;
bg.alpha -= fade_rate;
break;
case 13:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
bg.frame = 7;
}
bg.alpha += fade_rate;
overlay.alpha -= fade_rate;
break;
case 14:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
overlay.frame = 8;
}
overlay.alpha += fade_rate;
bg.alpha -= fade_rate;
break;
case 15:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
bg.frame = 9;
}
bg.alpha += fade_rate;
overlay.alpha -= fade_rate;
break;
case 16:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
overlay.frame = 10;
}
overlay.alpha += fade_rate;
bg.alpha -= fade_rate;
break;
case 17:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
bg.frame = 11;
}
bg.alpha += fade_rate;
overlay.alpha -= fade_rate;
break;
case 18:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
overlay.frame = 12;
}
overlay.alpha += fade_rate;
bg.alpha -= fade_rate;
break;
case 19:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
bg.frame = 13;
}
bg.alpha += fade_rate;
overlay.alpha -= fade_rate;
break;
case 20:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
overlay.frame = 14;
}
overlay.alpha += fade_rate;
bg.alpha -= fade_rate;
break;
case 21:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
bg.frame = 15;
}
bg.alpha += fade_rate;
overlay.alpha -= fade_rate;
break;
case 22:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
overlay.frame = 16;
}
overlay.alpha += fade_rate;
bg.alpha -= fade_rate;
break;
case 23:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
bg.frame = 17;
}
bg.alpha += fade_rate;
overlay.alpha -= fade_rate;
dimoverlay.alpha -= 0.001;
break;
case 24:
if (!init_sprites[ctr-2]) {
init_sprites[ctr - 2] = true;
overlay.frame = 18;
if (stop_text == text2) {
make_sprites(ctr, text2);
} else {
make_sprites(ctr, text);
}
}
init_sprites[ctr - 2] = true;
overlay.alpha += fade_rate;
bg.alpha -= fade_rate;
if (overlay.alpha >= 1) {
stop_text.y = -100;
}
break;
}
super.update();
}
private var fade_rate:Number = 0.009;
private var new_ctr:int = 0;
private var bg_timer:Number = 0;
private static var cur_m:Array;
private static var cur_p:Array;
private static var pos_ctr:int;
private function make_sprites(pg:int, _text:FlxBitmapFont):void {
if (text == _text) {
cur_m = sprites_1.members;
sprites_1.setAll("exists", false);
cur_p = positions_1;
} else {
cur_m = sprites_2.members;
sprites_2.setAll("exists", false);
cur_p= positions_2;
}
pos_ctr = 0;
if (pg == PG_SPRITES_START) {
mk(Slime.Slime_Sprite, 16, 16, [0, 1],5, 4, 20);
mk(Annoyer.S_ANNOYER_SPRITE, 16, 16, [0, 1, 2, 3, 4, 5], 8, 130, 46);
mk( Pew_Laser.PEW_LASER, 16, 16, [0], 2, 5, 66);
mk(Shieldy.SPRITE_SHIELDY, 16, 16, [1, 2, 1, 0, 1, 2, 1, 0, 16, 17, 18], 5, 130, 92);
mk( Pew_Laser.PEW_LASER_BULLET, 16, 8, [0, 1], 8, 5, 84);
mk(Sun_Guy.C_SUN_GUY, 16, 24, [0, 1, 2, 3, 4], 3, 11, 110);
mk(Sun_Guy.C_LIGHT_ORB, 16, 16, [0, 1, 2, 3, 4, 3, 2, 1], 6, 125, 120);
mk( Sun_Guy.C_SUN_GUY_WAVE, 128, 8, [3, 4, 5], 8, 8, 144);
} else if (pg == PG_SPRITES_START + 1) {
mk(Mover.mover_sprite, 16, 16, [0, 1], 4, 35, -4);
mk(On_Off_Laser.on_off_shooter_sprite, 16, 16, [0, 1, 2, 2, 1, 0], 2, 108, 30);
mk(Four_Shooter.four_shooter_sprite, 16, 16, [0, 1, 2, 2, 1, 0], 3, 4, 20);
mk(Slasher.slasher_sprite, 24, 24, [0, 1, 0, 1, 0, 1], 3, 115, 68);
mk(Red_Boss.red_boss_sprite, 32, 32, [0, 0, 1, 0, 0, 2], 3, 12, 110);
mk(Red_Boss.ripple_sprite, 48, 8, [0, 1], 12, 4, 138);
} else if (pg == PG_SPRITES_START + 2) {
mk(Dog.dog_sprite, 16, 16, [2, 3, 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 2, 3], 4, 22, -3);
mk(Frog.frog_sprite, 16, 16, [0, 1, 0, 1, 3, 3], 2, 118, 20);
mk(Rotator.rotator_sprite, 16, 16, [0, 1], 10, 20, 42);
mk(Person.person_sprite, 16, 16, [0, 1, 0, 1, 2, 3, 2, 3, 4, 5, 4, 5, 2, 3, 2, 3], 5, 120, 68);
mk(WallBoss.wall_sprite, 160, 32, [0, 1], 4, -1, 120);
mk(WallBoss.face_sprite, 64, 32, [0, 2, 0, 2,0,2, 1,1, 4,4], 5, -1 + 48, 120);
mk(WallBoss.r_hand_sprite, 32, 32, [0, 1, 2, 3], 1, 8, 150);
mk(WallBoss.l_hand_sprite, 32, 32, [0, 1, 2, 3], 1, 128, 150);
cur_m[7].scale.x = -1;
} else if (pg == PG_SPRITES_START + 3) {
mk(Rat.rat_sprite, 16, 16, [0, 1], 5, 16, 3);
mk(Gasguy.gas_guy_sprite, 16, 24, [0, 1],4, 122, 20);
mk(Gasguy.gas_guy_cloud_sprite, 24, 24, [0, 1], 3, 137, 34);
mk(Silverfish.silverfish_sprite, 16, 16, [4, 5], 6, 5, 46);
mk(Dash_Trap.dash_trap_sprite, 16, 16, [4, 5], 12, 137, 66);
mk(Spike_Roller.Spike_Roller_Sprite_H, 128, 16, [0, 1], 5, 5, 78);
mk(Splitboss.splitboss_sprite, 24, 32, [0, 1, 2, 1], 5, 70, 120);
} else if (pg == PG_SPRITES_START + 4) {
mk(Dustmaid.dustmaid_sprite, 16, 24, [0, 0, 0, 1, 2, 1, 2, 3, 4,3,4], 7, 5, -3);
mk(Burst_Plant.burst_plant_sprite, 16, 16, [0, 0, 1, 0, 1, 3, 3, 3,3,0], 8, 140, 25);
mk(Eye_Boss.eye_boss_water_sprite, 24, 24, [0, 1, 2, 3, 2, 1], 10, 5, 70);
mk(Eye_Boss.eye_boss_water_sprite, 24, 24, [4, 5, 4, 5, 6, 7, 6], 6, 120, 70);
} else if (pg == PG_SPRITES_START + 5) {
mk(Lion.lion_sprite, 32, 32, [10, 11, 10, 11, 10, 11, 12, 12], 4, 10, -5);
mk(Contort.contort_big_sprite, 16, 32, [0, 1, 2, 1], 9, 140, 20);
mk(Contort.contort_small_sprite, 16, 16, [0, 1], 9, 140, 50);
mk(Contort.contort_small_sprite, 16, 16, [2,3], 9, 118, 50);
mk(Contort.contort_small_sprite, 16, 16, [4, 5], 9, 126, 65);
mk(Fire_Pillar.fire_pillar_base_sprite, 16, 16, [0, 1], 8, 5, 54 + 32 - 4 - 12);
mk(Fire_Pillar.fire_pillar_sprite, 16, 32, [0, 0, 0, 0, 1, 2, 3, 4, 3, 4, 5, 6, 0], 9, 5, 54);
mk(Circus_Folks.both_sprite, 16, 32, [0, 1], 8, 65, 94);
} else if (pg == PG_SPRITES_START + 6) {
//follower
mk(Follower_Bro.sprite_follower, 16, 24, [1, 2, 1, 0], 4, 14, -5);
//edward
mk(Sadbro.sadman_sprite, 16, 16, [0, 1], 2, 120, 20);
//fisherman
mk(NPC.embed_beach_npcs, 16, 16, [10,11], 3, 6, 52);
//walker
mk(Red_Walker.sprite_redwalker, 32, 48, [0, 1, 2, 3, 4], 6, 130, 50);
// lobster
mk(NPC.embed_beach_npcs, 16, 16, [0], 2, 6, 80);
//hairs
//bombs
}else if (pg == PG_SPRITES_START + 7) {
// Miao, Icky, Goldman, Shopguy, Rank
mk(Trade_NPC.embed_dame_trade_npc, 16, 16, [0,1], 4,140, 49);
mk(Trade_NPC.embed_dame_trade_npc, 16, 16, [10,11], 4,2, 15);
mk(Trade_NPC.embed_dame_trade_npc, 16, 16, [20,21], 4,124, 91);
mk(Trade_NPC.embed_dame_trade_npc, 16, 16, [50, 51], 4, 2, 45);
mk(Forest_NPC.embed_forest_npcs, 16, 16, [30,31], 4, 129, 15);
mk(Trade_NPC.embed_dame_trade_npc, 32, 32, [15, 15, 15, 15, 15, 15, 15, 15, 16, 17, 17, 18, 18], 18, 2, 80);
}else if (pg == PG_SPRITES_START + 8) {
// James, Thorax, Rabbit, Golem
mk(Forest_NPC.embed_forest_npcs, 16, 16, [0, 1], 4, 4, 0);
mk(Forest_NPC.embed_forest_npcs, 16, 16, [10,10,11,10,10,12], 4, 130, 0);
mk(Forest_NPC.embed_forest_npcs, 16, 16, [20,21,20,22], 4, 4, 20);
mk(Forest_NPC.embed_forest_npcs, 16, 16, [30,31], 4, 130, 20);
mk(NPC.embed_cliff_npcs, 16, 16, [1,3,1,5,1,1,1,0,2,0,4,0,0,1,1], 4, 4, 40); // More ?
//folks
mk(Suburb_Walker.embed_suburb_folk, 16, 16, [0,1],4, 3, 83);
mk(Suburb_Walker.embed_suburb_folk, 16, 16, [9,10],4, 140, 80);
mk(Suburb_Walker.embed_suburb_folk, 16, 16, [18,19],4, 3, 103);
mk(Suburb_Walker.embed_suburb_folk, 16, 16, [27,28],4, 140, 103);
mk(Suburb_Walker.embed_suburb_folk, 16, 16, [36,37],4, 3, 123);
mk(Suburb_Walker.embed_suburb_folk, 16, 16, [45,46],4, 140, 123);
}else if (pg == PG_SPRITES_START + 9) {
mk(Chaser.embed_chaser_sprite, 16, 32, [8,9], 4, 2, 4);
mk(Space_NPC.embed_space_npc, 32, 32, [10,11], 4, 120, 106);
mk(Space_NPC.embed_space_npc, 32, 32, [12,13], 4, 3, 106);
mk(Space_NPC.embed_space_npc, 16,16,[0,1], 4, 20, 40);
mk(Space_NPC.embed_space_npc, 16,16,[20,21], 4, 20, 70);
mk(Space_NPC.embed_space_npc, 16,16,[22,23], 4, 20, 70);
mk(Space_NPC.embed_space_npc, 16,16,[10,11], 4, 120, 40);
//entities
} else if (pg == PG_SPRITES_START + 10) {
mk(Player.Player_Sprite, 16, 16, [1, 0, 1, 0], 6, 39, -5);
mk(Mitra.mitra_sprite, 16, 16, [0, 1, 0, 1], 6, 110, 17);
mk(Sage.sage_sprite, 16, 16, [0, 1], 6, 20, 44);
mk(Shadow_Briar.embed_briar, 16, 16, [0, 1], 6, 125, 67);
} else if (pg == PG_SPRITES_START + 11) {
//us???
mk(embed_dev_npcs, 16, 16, [0], 1, 6, 28);
mk(embed_dev_npcs, 16, 16, [10], 1, 140, 28);
}
}
// Set sprite ref at a[idx] to graphic, with width w, height h.
// Play the anim FRAMES at frame rate FR.
// Set its position relative to its accompanying text to posx,posy.
private function mk(graphic:Class, w:int, h:int, frames:Array, fr:int,posx:int,posy:int):void {
cur_m[pos_ctr].loadGraphic(graphic, true, false, w, h);
cur_m[pos_ctr].scale.x = 1;
cur_m[pos_ctr].addAnimation("anim"+ctr.toString(), frames, fr, true);
cur_m[pos_ctr].play("anim"+ctr.toString());
cur_m[pos_ctr].exists = true;
cur_p[pos_ctr].x = posx;
cur_p[pos_ctr].y = posy;
pos_ctr ++;
}
private function poopy_save_stuff():void {
save_dialog_bg = new FlxSprite;
save_dialog_bg.loadGraphic(Checkpoint.checkpoint_save_box_sprite, true, false, 80, 29);
save_dialog_bg.x = (160 - save_dialog_bg.width) / 2;
save_dialog_bg.y = 20 + (160 - save_dialog_bg.height) / 2;
save_dialog_bg.scrollFactor = new FlxPoint(0, 0);
save_dialog_text = EventScripts.init_bitmap_font(DH.lk("checkpoint",0), "left", save_dialog_bg.x + 5, save_dialog_bg.y + 2, null, "apple_white");
save_dialog_text.drop_shadow = true;
save_dialog_selector = new FlxSprite;
save_dialog_selector.loadGraphic(PauseState.arrows_sprite, true, false, 7, 7);
save_dialog_selector.scrollFactor = new FlxPoint(0, 0);
save_dialog_selector.addAnimation("flash", [0, 1], 8);
save_dialog_selector.play("flash");
save_dialog_selector.scale.x = -1;
save_dialog_selector.x = save_dialog_text.x + 4;
save_dialog_selector.y = save_dialog_text.y + 8;
if (DH.isZH()) save_dialog_selector.y = save_dialog_text.y + 16;
}
}
}

View File

@ -0,0 +1,127 @@
package states {
import entity.decoration.Light;
import global.Keys;
import global.Registry;
import helper.DH;
import helper.EventScripts;
import org.flixel.FlxG;
import org.flixel.FlxSprite;
import org.flixel.FlxState;
import org.flixel.plugin.photonstorm.FlxBitmapFont;
public class IntroScene extends FlxState {
public var darkness:FlxSprite = new FlxSprite(0, 0);
public var dialogue_state:DialogueState = new DialogueState;
public var started_dialogue:Boolean = false;
public var popped_dialogue:Boolean = false;
public var c_sprite:FlxBitmapFont;
public var light_timer:Number = 2;
public function IntroScene() {
}
override public function create():void {
Registry.keywatch = new Keys();
add(Registry.keywatch);
Registry.keywatch.visible = false;
darkness.makeGraphic(160, 180, 0xff000000);
darkness.blend = "multiply";
add(darkness);
//Registry.sound_data.stop_current_song();
Registry.sound_data.start_song_from_title("BLANK");
Registry.ENTRANCE_PLAYER_X = 397 - 320;
Registry.ENTRANCE_PLAYER_Y = 107;
Registry.CURRENT_MAP_NAME = "BLANK";
c_sprite = EventScripts.init_bitmap_font(Registry.controls[Keys.IDX_ACTION_1], "center", 146, 165, null, "apple_white");
c_sprite.color = 0xff2222;
}
private var t_csprite:Number = 0;
private var c_ctr:int = 0;
override public function update():void
{
light_timer -= FlxG.elapsed;
if (!started_dialogue && light_timer < 1) {
started_dialogue = true;
// handle edge case when we restart a new game
// and the gamestate object isn'tnull
if (Registry.GAMESTATE != null) Registry.GAMESTATE.dialogue_latency = -1;
DH.set_scene_to_pos(DH.name_sage, DH.scene_sage_blank_intro, 0);
DH.start_dialogue(DH.name_sage, DH.scene_sage_blank_intro, "BLANK");
//DH.dialogue_popup("Young...^Young...^are you there?^ Wake up!");
dialogue_state.push(this as FlxState);
dialogue_state.blinky_box.exists = false;
add(c_sprite);
} else if (!started_dialogue) {
super.update();
return;
}
t_csprite += FlxG.elapsed;
if (c_sprite.alive) {
if (t_csprite > 0.6) {
t_csprite = 0;
c_sprite.alive = c_sprite.visible = false;
}
} else {
if (t_csprite > 0.6) {
t_csprite = 0;
c_sprite.visible = true;
c_sprite.alive = true;
}
}
if (Registry.keywatch.JP_ACTION_1) {
c_ctr ++;
}
if (c_ctr > 3) {
c_sprite.exists = false;
dialogue_state.blinky_box.exists = true;
}
if (dialogue_state.is_finished) {
DH.update_current_scene_on_chunk_finish();
if (!popped_dialogue) {
popped_dialogue = true;
light_timer = 2;
c_sprite.visible = false;
dialogue_state.pop(this as FlxState);
}
if (light_timer < 0.5) {
Registry.E_Blank_Fade = true;
FlxG.switchState(new PlayState);
}
} else {
if (FlxG.keys.any()) { // havent said to press anything yet
Registry.keywatch.JP_ACTION_1 = true;
}
dialogue_state.update();
}
super.update();
}
override public function draw():void {
darkness.fill(0xff000000);
super.draw();
}
override public function destroy():void
{
remove(Registry.keywatch, true);
dialogue_state.destroy();
dialogue_state = null;
c_sprite = null;
darkness = null;
super.destroy();
}
}
}

View File

@ -0,0 +1,239 @@
package states
{
import data.CSV_Data;
import data.TileData;
import global.Registry;
import org.flixel.FlxG;
import org.flixel.FlxPoint;
import org.flixel.FlxSprite;
import org.flixel.FlxState;
import org.flixel.FlxTilemap;
import org.flixel.system.FlxTile;
/**
* ...
* @author Seagaia
*/
public class MinimapState extends PushableFlxState
{
public var minimap:FlxTilemap;
private var blank_tile_index:int = 9;
/* contants, screen width and height, used for centering the map */
private var sw:int = 160;
private var sh:int = 180;
public static var visited:Object = { STREET: new Array(), BEDROOM: new Array(), REDCAVE: new Array(), CROWD: new Array(), APARTMENT: new Array(), CIRCUS: new Array(), HOTEL: new Array(), FIELDS: new Array(), CLIFF: new Array(), OVERWORLD: new Array(), BEACH: new Array(), REDSEA: new Array(), FOREST: new Array(), SUBURB: new Array(), TRAIN: new Array(), SPACE: new Array() , TERMINAL: new Array()};
public static var minimap_strings:Array = new Array("","","","","","","","","","","","","","","","");
public static var minimap_areas:Array = new Array("STREET", "BEDROOM", "REDCAVE", "CROWD", "APARTMENT", "CIRCUS", "HOTEL","FIELDS","CLIFF","OVERWORLD","BEACH","REDSEA","FOREST","SUBURB","TRAIN","SPACE","TERMINAL");
public var is_finished:Boolean = false;
public var entrance:FlxSprite = new FlxSprite();
public var player_marker:FlxSprite = new FlxSprite();
public var player_marker_blink_timer:Number = 0;
public var player_marker_blink_timer_max:Number = 0.4;
public var has_map:Boolean = false;
public var nr_times_coords_set:int = 0;
public var invalid:Boolean = false;
public function MinimapState()
{
trace("Initializing Minimap");
minimap = new FlxTilemap();
minimap.loadMap("0,2", TileData.Minimap_Tiles, 7, 7);
reset_minimap();
add(minimap);
add(entrance);
add(player_marker);
setAll("scrollFactor", new FlxPoint(0, 0));
}
public static function save_delete_routine():void {
visited["STREET"] = new Array();
visited["BEDROOM"] = new Array();
visited["CROWD"] = new Array();
visited["REDCAVE"] = new Array();
visited["APARTMENT"] = new Array();
visited["CIRCUS"] = new Array();
visited["HOTEL"] = new Array();
visited["FOREST"] = new Array();
visited["CLIFF"] = new Array();
visited["BEACH"] = new Array();
visited["REDSEA"] = new Array();
visited["OVERWORLD"] = new Array();
visited["FIELDS"] = new Array();
visited["SPACE"] = new Array();
visited["TERMINAL"] = new Array();
visited["SUBURB"] = new Array();
visited["TRAIN"] = new Array();
MinimapState.minimap_strings = new Array("","","","","","","","","","","","","","","","","");
}
public function get_minimap():FlxTilemap {
if (has_map) return minimap;
return null;
}
private function reset_minimap():void {
nr_times_coords_set = 0;
is_finished = false;
if (CSV_Data.minimap_csv.hasOwnProperty(Registry.CURRENT_MAP_NAME)) {
player_marker.makeGraphic(3, 3, 0xffff5949);
entrance.makeGraphic(3, 3, 0xff0d52af);
}
var idx:int = minimap_areas.indexOf(Registry.CURRENT_MAP_NAME);
if (idx == -1) {
visible = false;
invalid = true;
has_map = false;
return;
}
visible = true;
minimap.null_buffer(0); // Force a redraw?
minimap.loadMap(new CSV_Data.minimap_csv[Registry.CURRENT_MAP_NAME], TileData.Minimap_Tiles, 7, 7);
set_coords(minimap); // Set alignment of minimap
var tmap:FlxTilemap = new FlxTilemap;
// If we have not yet initialized this according to the serialized
// minimap state, then mark all rooms as not visited
if (minimap_strings[idx] == "" || minimap_strings[idx] == null) {
for (var i:int = 0; i < minimap.totalTiles; i++) {
visited[Registry.CURRENT_MAP_NAME].push(0);
}
// Otherwise use a dirty hack to get the visited data
} else {
tmap.loadMap(minimap_strings[idx], TileData.Minimap_Tiles, 7, 7);
visited[Registry.CURRENT_MAP_NAME] = tmap.getData();
}
minimap.draw(); // Maybe redraw??
update_map(); // Make rooms invisible if not visited yet
set_marker_coords(); // Set entrance/player spot etc
}
override public function update():void
{
player_marker_blink_timer += FlxG.elapsed;
if (player_marker_blink_timer > player_marker_blink_timer_max) {
player_marker.visible = !player_marker.visible;
player_marker_blink_timer = 0;
}
super.update();
}
public function stuff_for_pause_state():void {
if (CSV_Data.minimap_csv.hasOwnProperty(Registry.CURRENT_MAP_NAME)) {
// UPdate a room as visited
update_visited_array(Registry.CURRENT_MAP_NAME, Registry.CURRENT_GRID_X, Registry.CURRENT_GRID_Y);
// Reload the uncovered rooms
minimap.loadMap(new CSV_Data.minimap_csv[Registry.CURRENT_MAP_NAME], TileData.Minimap_Tiles, 7, 7)
// Redraw the map
update_map();
// MOve markers
set_marker_coords();
}
}
override public function push(_parent:FlxState):void
{
if (minimap_areas.indexOf(Registry.CURRENT_MAP_NAME) != -1) {
is_finished = false;
minimap.loadMap(new CSV_Data.minimap_csv[Registry.CURRENT_MAP_NAME], TileData.Minimap_Tiles, 7, 7)
update_visited_array(Registry.CURRENT_MAP_NAME, Registry.CURRENT_GRID_X, Registry.CURRENT_GRID_Y);
update_map();
minimap_strings[minimap_areas.indexOf(Registry.CURRENT_MAP_NAME)] = FlxTilemap.arrayToCSV(visited[Registry.CURRENT_MAP_NAME],minimap.widthInTiles);
set_marker_coords();
}
super.push(_parent);
}
public function init_minimap():void {
if (minimap_areas.indexOf(Registry.CURRENT_MAP_NAME) != -1) {
invalid = false;
is_finished = false;
has_map = true;
minimap.visible = player_marker.visible = entrance.visible = true;
player_marker.exists = true;
reset_minimap();
minimap.loadMap(new CSV_Data.minimap_csv[Registry.CURRENT_MAP_NAME], TileData.Minimap_Tiles,7, 7)
update_visited_array(Registry.CURRENT_MAP_NAME, Registry.CURRENT_GRID_X, Registry.CURRENT_GRID_Y);
minimap_strings[minimap_areas.indexOf(Registry.CURRENT_MAP_NAME)] = FlxTilemap.arrayToCSV(visited[Registry.CURRENT_MAP_NAME],minimap.widthInTiles);
update_map();
set_marker_coords();
} else {
has_map = false;
invalid = true;
minimap.visible = player_marker.visible = entrance.visible = false;
player_marker.exists = false;
}
}
public function set_coords(map:FlxTilemap):void {
minimap.x = 60 + (100 - map.width) / 2;
minimap.y = Registry.HEADER_HEIGHT + (100 - map.height) / 2;
}
override public function destroy():void
{
// Calls the level up, destroys all things added to this state
super.destroy();
}
public function update_visited_array(mapName:String, gx:int, gy:int):void {
if (!invalid) {
if (minimap == null) return;
var idx:int = gy * minimap.widthInTiles + gx;
trace("Updated!", gx, gy);
visited[mapName][idx] = 1;
// Update the serialized map state
minimap_strings[minimap_areas.indexOf(Registry.CURRENT_MAP_NAME)] = FlxTilemap.arrayToCSV(visited[Registry.CURRENT_MAP_NAME], minimap.widthInTiles);
}
}
private function update_map():void
{
for (var i:int = 0; i < minimap.widthInTiles * minimap.heightInTiles; i++) {
if (1 != visited[Registry.CURRENT_MAP_NAME][i]) {
minimap.setTileByIndex(i, blank_tile_index, true);
}
}
}
private function set_marker_coords():void
{
if (nr_times_coords_set < 2) {
nr_times_coords_set++;
entrance.x = minimap.x + 2 + Registry.CURRENT_GRID_X * 7;
entrance.y = minimap.y + 2 + Registry.CURRENT_GRID_Y * 7;
}
player_marker.x = minimap.x + 2 + Registry.CURRENT_GRID_X * 7;
player_marker.y = minimap.y + 2 + Registry.CURRENT_GRID_Y * 7;
}
}
}

View File

@ -0,0 +1,39 @@
package states
{
/**
* update loop for configuring mobile ui
* @author Copyright Melos Han-Tani, Developer of Analgesic Productions LLC, 2013 - ? , www.twitter.com/seagaia2
*/
public class MobileConfig
{
public function MobileConfig()
{
}
public static var did_init:Boolean = false;
public static var in_progress:Boolean = false;
public static var done:Boolean = false;
public static function update():Boolean {
if (!did_init) {
did_init = true;
in_progress = true;
}
if (done) {
done = false;
in_progress = false;
did_init = false;
return true;
}
return false;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,50 @@
package states
{
import org.flixel.FlxGroup;
import org.flixel.FlxState;
/* A totally needless abstraction. oh well */
public class PushableFlxState extends FlxState
{
public var parent:*;
override public function create():void {
}
public function PushableFlxState() {
}
/**
* Pushes all of this state's ADDED OBJETS onto its parents draw group
* @param _parent The FlxState that is being drawn.
*/
public function push(_parent:FlxState):void {
parent = _parent;
for (var i:int = 0; i < members.length; i++) {
if (members[i] != null) {
_parent.add(members[i]);
}
}
}
/**
* Removes this state's ADDED OBJECTS from its parents draw group
* If you allocate memory that isn't added, don't forget to null it!
* @param FlxState The FlxState that is being drawn.
*/
public function pop(parent:FlxState):void {
for (var i:int = 0; i < members.length; i++) {
if (members[i] != null) {
parent.remove(members[i], true);
}
}
}
override public function destroy():void {
super.destroy();
parent = null;
}
}
}

View File

@ -0,0 +1,618 @@
package states
{
import data.CSV_Data;
import data.SoundData;
import data.TileData;
import entity.player.Foot_Overlay;
import entity.player.Player;
import global.*;
import helper.Cutscene;
import helper.DH;
import helper.EventScripts;
import helper.ScreenFade;
import helper.SpriteFactory;
import org.flixel.*;
import org.flixel.plugin.photonstorm.FlxBitmapFont;
public class RoamState extends FlxState
{
private var keywatch:Keys;
private var stateful_mapXML:XML;
private var stateless_mapXML:XML;
public var map:FlxTilemap;
public var map_bg_2:FlxTilemap = new FlxTilemap();
public var map_fg:FlxTilemap = new FlxTilemap();
public var curMapBuf:FlxTilemap; //probably deprecated
public var player:Player;
public var player_group:FlxGroup = new FlxGroup();
public var entities:Array = new Array();
public var anim_tiles_group:FlxGroup = new FlxGroup();
public var statelesses:Array; //deprecated
public var sortables:FlxGroup = new FlxGroup();
public var bg_sprites:FlxGroup = new FlxGroup();
public var fg_sprites:FlxGroup = new FlxGroup(); //stuff from ceiling
public var state:int = 5;
public var S_EXITING:int = -1;
public var SWITCH_MAPS:Boolean = false;
private var cleaned_up_before_exit:Boolean = false;
public var S_NORMAL:int = 0;
public var S_TRANSITION:int = 1;
public var S_PAUSED:int = 2;
public var pause_state:PauseState = new PauseState();
public var pause_timer:Number = 0.2;
public var S_OPEN_TREASURE:int = 3;
public var S_PLAYER_DIED:int = 4;
private var death_fadein:FlxSprite;
private var death_text:FlxBitmapFont;
private var played_death_sound:Boolean = false;
private var start_death_fade_out:Boolean = false;
public var S_JUST_ENTERED_MAP:int = 5;
public var S_DIRECT_CONTROLS:int = 6;
private var S_CUTSCENE:int = 7;
private var cutscene:Cutscene;
public var S_DIALOGUE:int = 8;
public var load_dialogue:Boolean = false;
public var dialogue_state:DialogueState = new DialogueState();
public var dialogue_latency:Number = 0.3;
//header ccrap
[Embed (source = "../res/sprites/menu/autosave_icon.png")] public static var autosave_icon_embed:Class;
public var header_group:FlxGroup = new FlxGroup();
public var header:FlxSprite = new FlxSprite(0, 0);
public var number_of_keys_text:FlxBitmapFont;
public var autosave_icon:FlxSprite;
// graphical overlay stuff
public var darkness:FlxSprite = new FlxSprite(0, 0);
private var downsample_fade:ScreenFade;
private var upsample_fade:ScreenFade;
private var black_overlay:FlxSprite = new FlxSprite(0, 0);
// misc
public var noScrollPt:FlxPoint = new FlxPoint(0, 0);
public function RoamState() {
}
override public function create():void
{
trace("Creating roamstate");
// Add the keywatch
if (Registry.keywatch == null) {
Registry.keywatch = new Keys();
}
keywatch = Registry.keywatch;
Registry.GAMESTATE = this;
// Load the background if needed.
//Determine the proper CSV and tileset to use.
//Load a tilemap and add it.
var csv:String = CSV_Data.getMap(Registry.CURRENT_MAP_NAME);
map = new FlxTilemap();
TileData.setTileset(Registry.CURRENT_MAP_NAME)
map.loadMap(csv, TileData.Tiles, 16, 16);
map.y += Registry.HEADER_HEIGHT;
TileData.set_tile_properties(map);
make_anim_tiles(map, anim_tiles_group);
add(map);
map_bg_2.loadMap(CSV_Data.getMap(Registry.CURRENT_MAP_NAME, 2), TileData.Tiles, 16, 16);
map_bg_2.y += Registry.HEADER_HEIGHT;
TileData.set_tile_properties(map_bg_2);
map_fg.loadMap(CSV_Data.getMap(Registry.CURRENT_MAP_NAME, 3), TileData.Tiles, 16, 16)
map_fg.y += Registry.HEADER_HEIGHT;
// Make darkness
darkness = new FlxSprite(0, Registry.HEADER_HEIGHT);
darkness.scrollFactor = noScrollPt;
set_darkness(darkness);
// Find the entrance and make the player there. Done before
// sprite init because sprites use the player ref.
player = new Player(0, 0, keywatch, darkness, this);
player.foot_overlay = new Foot_Overlay(player);
player.foot_overlay.map = map;
player.x = Registry.ENTRANCE_PLAYER_X;
player.y = Registry.ENTRANCE_PLAYER_Y;
//Grab the relevant chunk of XML.
initXML();
//Instantiate and add all sprites to sortables here.
Registry.reset_subgroups(); //clear from prev state
load_entities(0, 0, true);
add(anim_tiles_group);
add(map_bg_2);
add(bg_sprites);
statelesses = entities;
curMapBuf = map; //for now...
// Draw player on top of everything.
player.init_player_group(player_group, player, map);
sortables.add(player_group);
add(sortables);
add(fg_sprites);
//Add fg
add(map_fg);
// Make the header
header.loadGraphic(PlayState.Header, false, false, 160, 20);
header.scrollFactor = noScrollPt;
number_of_keys_text = EventScripts.init_bitmap_font("x" + Registry.get_nr_keys().toString(), "left", 42,7, null, "apple_white");
autosave_icon = EventScripts.init_autosave_icon(autosave_icon, autosave_icon_embed);
header_group.add(autosave_icon);
header_group.add(header);
header_group.add(number_of_keys_text);
header_group.add(player.health_bar);
add(header_group);
//Death entities
death_fadein = new FlxSprite(0, 0); death_fadein.scrollFactor = noScrollPt;
death_fadein.makeGraphic(Registry.SCREEN_WIDTH_IN_PIXELS, Registry.SCREEN_HEIGHT_IN_PIXELS + Registry.HEADER_HEIGHT, 0xffffffff);
death_fadein.alpha = 0;
death_text = EventScripts.init_bitmap_font("Keep exploring?", "center", 0, 60, null, "apple_black");
death_text.visible = false;
add(death_fadein);
add(death_text);
// Add the darkness
add(darkness);
// add screen fade effects
downsample_fade = new ScreenFade(Registry.SCREEN_WIDTH_IN_PIXELS, Registry.SCREEN_HEIGHT_IN_PIXELS + Registry.HEADER_HEIGHT, this as FlxState, ScreenFade.T_DS);
upsample_fade = new ScreenFade(Registry.SCREEN_WIDTH_IN_PIXELS, Registry.SCREEN_HEIGHT_IN_PIXELS + Registry.HEADER_HEIGHT, this as FlxState, ScreenFade.T_US);
black_overlay.makeGraphic(Registry.SCREEN_WIDTH_IN_PIXELS, Registry.SCREEN_HEIGHT_IN_PIXELS + Registry.HEADER_HEIGHT, 0xff000000);
black_overlay.alpha = 1;
black_overlay.scrollFactor = noScrollPt;
add(black_overlay);
// Add the death overlay objects.
// Play song.
if (Registry.sound_data == null) {
Registry.sound_data = new SoundData();
}
Registry.sound_data.start_song_from_title(Registry.CURRENT_MAP_NAME);
// Make the camera follow the player
FlxG.camera.follow(player);
FlxG.camera.setBounds(0, 0,map.width,map.height + 20, true);
FlxG.camera.deadzone = new FlxRect(50, 80, 160 - 100, 160 - 120);
}
override public function update():void
{
/* First, the bare minimum. */
if (SWITCH_MAPS) state = S_EXITING;
// State if-then.
if (state == S_NORMAL) {
FlxG.collide(curMapBuf, player);
FlxG.collide(map_bg_2, player);
keywatch.update();
state_normal();
} else if (state == S_PAUSED) {
Registry.sound_data.current_song.volume = FlxG.volume * Registry.volume_scale;
keywatch.update();
pause_state.update();
if (pause_state.done) {
pause_state.done = false;
state = S_NORMAL;
remove(pause_state, true);
}
return;
} else if (state == S_DIRECT_CONTROLS) {
pause_state.controls_state.update();
keywatch.update();
if (!pause_state.controls_state.updating && ( Registry.keywatch.JUST_PRESSED_PAUSE || FlxG.keys.justPressed("ESCAPE"))) {
state = S_NORMAL;
pause_state.controls_state.pop(this);
}
} else if (state == S_EXITING) {
state_exiting();
return;
} else if (state == S_JUST_ENTERED_MAP) {
state_just_entered_map();
return;
} else if (state == S_DIALOGUE) {
player.state = player.S_INTERACT;
keywatch.update();
dialogue_state.update();
if (dialogue_state.is_finished) {
player.state = player.S_GROUND;
player.dontMove = false;
dialogue_state.is_finished = false;
state = S_NORMAL;
dialogue_latency = 0.3;
dialogue_state.reset();
Registry.E_Dialogue_Just_Finished = true;
dialogue_state.pop(this as FlxState);
}
} else if (state == S_OPEN_TREASURE) {
state_open_treasure();
return;
} else if (state == S_PLAYER_DIED) {
state_player_died();
} else if (state == S_CUTSCENE) {
}
Registry.sound_data.current_song.volume = FlxG.volume * Registry.volume_scale;
check_events();
// Check entity's distances from player to determine if need to update
// - exists vs. not
// When enemies refactored, will call update.
super.update();
}
private function check_events():void {
if (Registry.EVENT_CHANGE_VOLUME_SCALE) {
if (EventScripts.send_property_to(Registry, "volume_scale", Registry.EVENT_CHANGE_VOLUME_SCALE_TARGET, 0.01))
Registry.EVENT_CHANGE_VOLUME_SCALE = false;
}
if (Registry.E_Load_Cutscene) {
state = S_CUTSCENE;
Registry.E_Load_Cutscene = false;
cutscene = new Cutscene(this);
cutscene.push(this as FlxState);
}
}
private function state_normal():void
{
/* Only pause or enter controls if we're not in the middle of a transition */
if (pause_timer < 0 && (keywatch.JUST_PRESSED_PAUSE || FlxG.keys.justPressed("ESCAPE"))) {
Registry.sound_data.play_sound_group(Registry.sound_data.pause_sound_group);
pause_timer = 0.2;
if (FlxG.keys.justPressed("ESCAPE")) {
state = S_DIRECT_CONTROLS;
pause_state.controls_state.push(this);
} else {
state = S_PAUSED;
add(pause_state);
pause_timer = 0.2;
}
} else {
pause_timer -= FlxG.elapsed;
}
//triggered by an npc or whatever
if (dialogue_latency > 0) {
dialogue_latency -= FlxG.elapsed;
}
if (load_dialogue) {
load_dialogue = false;
if (dialogue_latency < 0) {
state = S_DIALOGUE;
player.dontMove = true;
dialogue_state.push(this as FlxState);
}
}
if (player.health_bar.cur_health <= 0) {
player.play("die");
player.ANIM_STATE = player.ANIM_DEAD;
player.alive = false;
var pt:FlxPoint = player.getScreenXY();
player.scrollFactor = noScrollPt;
player.x = pt.x;
player.y = pt.y;
Registry.sound_data.stop_current_song();
player.velocity.x = player.velocity.y = 0;
remove(player, true);
add(player);
state = S_PLAYER_DIED;
}
}
private function state_exiting():void {
/* Mark all sprites to be cleaned up, reset any events set,
* reset grid state, determine beginning state of the transition */
if (!cleaned_up_before_exit) {
Registry.reset_events();
for (var i:int = 0; i < entities.length; i++) {
entities.pop();
}
cleaned_up_before_exit = true;
player.dontMove = true;
if (Registry.E_Enter_Whirlpool_Down) {
} else {
Registry.EVENT_FADE_BEGUN = true;
}
if (Registry.FUCK_IT_MODE_ON) {
Registry.EVENT_FADE_OVER = true;
Registry.EVENT_FADE_BEGUN = false;
// black_overlay.alpha = 1;
}
}
/* Fade out the song and other sounds playing */
Registry.sound_data.current_song.volume -= 0.03;
if (Registry.sound_data.current_song.playing && Registry.sound_data.current_song.volume < 0.05) {
Registry.sound_data.stop_current_song();
if (Registry.CURRENT_MAP_NAME == "BEACH") {
Registry.sound_data.waves.stop();
}
}
/* Do door-specific stuff here (events, etc) */
if (Registry.CURRENT_MAP_NAME == "BLANK") {
black_overlay.alpha += 0.01;
} else if (Registry.E_Enter_Whirlpool_Down) {
super.update();
player.play('whirl');
if (player.framePixels_y_push != 15) {
player.framePixels_y_push++;
}
if (player.framePixels_y_push >= 15) {
black_overlay.alpha += 0.015;
Registry.EVENT_FADE_BEGUN = true;
}
} else {
black_overlay.alpha += 0.02;
}
/* Actually make the transition when the overlay is completely
* opaque and the downsampling is done */
if (black_overlay.alpha >= 0.99 && !Registry.sound_data.current_song.playing && Registry.EVENT_FADE_OVER) {
Registry.EVENT_FADE_OVER = Registry.EVENT_FADE_BEGUN = false;
DH.reset_scenes_on_map_change();
Registry.CURRENT_MAP_NAME = Registry.NEXT_MAP_NAME;
Registry.set_is_playstate(Registry.CURRENT_MAP_NAME);
if (Registry.is_playstate) {
//FlxG.switchState(Registry.PLAYSTATE);
FlxG.switchState(new PlayState);
} else {
FlxG.switchState(new RoamState);
}
}
}
private function state_just_entered_map():void {
Registry.EVENT_FADE_BEGUN = true;
black_overlay.alpha -= 0.02;
player.dontMove = true;
if (Registry.FUCK_IT_MODE_ON) {
Registry.EVENT_FADE_BEGUN = false;
Registry.EVENT_FADE_OVER = true;
}
if (black_overlay.alpha <= 0 && Registry.EVENT_FADE_OVER) {
state = S_NORMAL; player.dontMove = false;
Registry.EVENT_FADE_BEGUN = Registry.EVENT_FADE_OVER = false;
}
super.update();
}
public function state_player_died():void {
Registry.keywatch.update();
EventScripts.send_property_to(player, "x", 80, 0.5);
EventScripts.send_property_to(player, "y", 100, 0.5);
if (player.frame == player.DEATH_FRAME && !played_death_sound) {
played_death_sound = true;
Registry.sound_data.player_hit_1.play();
Registry.sound_data.GameOver.play();
death_text.visible = true;
death_text.setText("Keep exploring?\n" + "Press " + Registry.controls[Keys.IDX_ACTION_1], true, 0, 0, "center", true);
}
death_fadein.visible = true;
if (death_fadein.alpha < 1) death_fadein.alpha += 0.03;
if (death_fadein.alpha > 0.7) {
death_text.visible = true;
}
if (start_death_fade_out || (played_death_sound && Registry.keywatch.JP_ACTION_1 && death_text.visible )) {
start_death_fade_out = true;
black_overlay.alpha += 0.02;
player.alpha -= 0.02;
death_text.alpha -= 0.02;
if (black_overlay.alpha == 1) {
Registry.sound_data.GameOver.stop();
Registry.sound_data.GameOver = new FlxSound();
Registry.sound_data.GameOver.loadEmbedded(SoundData.GameOver_Song, false);
Registry.ENTRANCE_PLAYER_X = Registry.checkpoint.x;
Registry.ENTRANCE_PLAYER_Y = Registry.checkpoint.y;
Registry.CURRENT_MAP_NAME = Registry.checkpoint.area;
Registry.CUR_HEALTH = Registry.MAX_HEALTH;
player.health_bar.modify_health(Registry.MAX_HEALTH);
Registry.set_is_playstate(Registry.CURRENT_MAP_NAME);
if (Registry.is_playstate) {
//FlxG.switchState(Registry.PLAYSTATE);
FlxG.switchState(new PlayState);
} else {
FlxG.switchState(new RoamState);
}
}
}
}
private function state_open_treasure():void {
Registry.keywatch.update(); // o_O
state = S_NORMAL;
}
private function initXML():void {
var map:XML;
for each (map in Registry.statefulXML.map) {
if (map.@name == Registry.CURRENT_MAP_NAME) {
stateful_mapXML = map; break;
}
}
for each (map in Registry.statelessXML.map) {
if (map.@name == Registry.CURRENT_MAP_NAME) {
stateless_mapXML = map; break;
}
}
}
private function load_entities(gx:int, gy:int, load_all:Boolean = false):void {
if (stateless_mapXML != null) {
add_from_xml(stateless_mapXML.grid,gx,gy,load_all);
}
if (stateful_mapXML != null) {
add_from_xml(stateful_mapXML.grid,gx,gy,load_all);
}
}
private function add_from_xml(xml:XMLList,gx:int,gy:int,load_all:Boolean=false):void
{
var prev_len:int = entities.length;
for each (var grid:XML in xml) {
if (load_all || (parseInt(grid.@grid_x) == gx && parseInt(grid.@grid_y) == gy)) {
for (var i:int = 0; i < grid.child("*").length(); i++) {
SpriteFactory.makeSprite(grid.child("*")[i], i, entities, entities, player, this, darkness);
if (entities.length != prev_len) {
while (prev_len < entities.length) {
if (entities[prev_len].hasOwnProperty("gx")) {
entities[prev_len].gx = parseInt(grid.@grid_x);
entities[prev_len].gy = parseInt(grid.@grid_y);
}
sortables.add(entities[prev_len]);
prev_len++;
}
}
}
}
}
}
/* Check if the tile is an animated tile, change the tilemap tile if needed,
* and then also implicitly add the animated tile to the group. */
private function make_anim_tiles(_map:FlxTilemap, _anim_tiles_group:FlxGroup):void {
for (var i:int = 0; i < _map.totalTiles; i++) {
var tile_type:int = _map.getTileByIndex(i);
TileData.make_anim_tile(_anim_tiles_group, Registry.CURRENT_MAP_NAME, tile_type, 16 * (i % _map.widthInTiles), 20 + 16 * int(i / _map.widthInTiles));
_map.setTileByIndex(i, tile_type, true);
}
}
override public function destroy():void {
remove(keywatch, true);
// Might change this to use recycling.
entities = null;
statelesses = null;
if (downsample_fade != null) downsample_fade.destroy();
downsample_fade = null;
if (upsample_fade != null) upsample_fade.destroy();
upsample_fade = null;
if (pause_state != null) pause_state.destroy();
pause_state = null;
if (dialogue_state != null) dialogue_state.destroy();
dialogue_state = null;
if (cutscene != null) cutscene.destroy();
cutscene = null;
number_of_keys_text = null;
autosave_icon = null;
curMapBuf = map = map_bg_2 = map_fg = null;
noScrollPt = null;
noScrollPt = null
super.destroy();
}
private function set_darkness(_darkness:FlxSprite):void {
if (Registry.CURRENT_MAP_NAME == "BEACH") {
_darkness.makeGraphic(Registry.SCREEN_WIDTH_IN_PIXELS, Registry.SCREEN_HEIGHT_IN_PIXELS, 0xffef8100);
_darkness.blend = "overlay";
_darkness.alpha = 1;
_darkness.visible = false;
} else {
_darkness.makeGraphic(Registry.SCREEN_WIDTH_IN_PIXELS, Registry.SCREEN_HEIGHT_IN_PIXELS, 0x00ef8100);
_darkness.blend = "overlay";
_darkness.alpha = 1;
_darkness.visible = false;
}
}
override public function draw():void
{
if (Registry.CURRENT_MAP_NAME == "BEACH") {
darkness.fill(0xff000000);
}
// effects and wahtnot
sortables.sort("y_bottom", ASCENDING);
super.draw();
if (Registry.EVENT_FADE_BEGUN && state == S_EXITING) {
if (downsample_fade.do_effect() == ScreenFade.DONE) {
Registry.EVENT_FADE_OVER = true;
}
} else if (Registry.EVENT_FADE_BEGUN && state == S_JUST_ENTERED_MAP) {
if (upsample_fade.do_effect() == ScreenFade.DONE) {
Registry.EVENT_FADE_OVER = true;
}
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff