Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Kytin

Pages: [1]
1
games / DragonFlight (prototype)
« on: Fri, Dec 9, 2011 »
Thought I would share what I have so far for my 2d platformer. It's still at the prototype stage so it is still missing some significant features (such as sound and music).

DragonFlight
Arrow keys move. 'Z' attacks.
'UP' flaps your wings. Press and hold 'UP' to glide while moving through the air.
Eating dead enemies restores health.
Eating white bats increases maximum stamina (the yellow bar).
'DOWN' interacts with environmental objects (doors and save points).
'ESC' will return you to the main menu.





Major features still needed:
Breath weapons
Sounds
Music
Scripted/cinematic events
Additional enemy types
Complete series of levels

2
help / FlxSave only works locally [Fixed!]
« on: Sun, Dec 4, 2011 »
I recently got my game prototype to the stage where I'm happy to start showing it around. Unfortunately, after I upload it to a hosting site, I find that it no longer saves and loads the way it does when I run the swf from my computer. I'm using FlxSave, and as far as I can tell, I have done everything correctly.

I figure I'm probably just overlooking some simple thing, but I really haven't been able to determine what. It's quite frustrating as I can't use the debugger to see what all my code is doing.


Anyway, here's the relevant code:
Code: [Select]
package 
{
/**
* ...
* @author Stephen Ashby
*/
import org.flixel.*;
import flash.utils.*;
 
public class PlayState extends FlxState
{
public var level:BaseLevel;
//public var player:Player;

private static var _save:FlxSave; //The FlxSave instance
private static var canUseSave:Boolean = false; //Did bind() work? Do we have a valid SharedObject?

public static function initSaves():void
{
_save = new FlxSave();
canUseSave = _save.bind("savegame");

Registry.initializeEventFlags();

//if the save file has never been used before, create the eventFlags array
if (_save.data.eventFlags == null)
{
_save.data.eventFlags = new Array();
for each(var f:Boolean in Registry.eventFlags)
{
(_save.data.boxPositions as Array).push(f);
}
}
}

override public function create():void
{
if ( canUseSave == false)
trace("Failed to initialize savestate! Your game cannot be saved!");

if (Registry.level == null && Registry.nextLevel == null)
Registry.setLevel(DemoLevel1);

if (Registry.player == null)
Registry.player = new Player(34.000, 448.000);


FlxG.worldBounds = new FlxRect(0, 0, 80 * 16, 30 * 16);
}

public function PlayState():void
{
super();
initSaves();
}

override public function update():void
{
super.update();

if (FlxG.keys.justPressed("S"))
{
Registry.saveTheGame = true;
}

if (FlxG.keys.justPressed("L"))
{
loadGame();
}

if (FlxG.keys.justPressed("D"))
{
//do debug stuff
level.alive = true;
}


if (Registry.saveTheGame)
{
Registry.saveTheGame = false;
saveGame();
}
//if Registry.setLevel() has been called, but not acted on
//change the level to the new one
if (Registry.nextLevel != null)
{
levelChange();
}

if (FlxG.keys.justPressed("ESCAPE"))
{
Registry.gotoMainMenu = true;
}

if (Registry.gotoMainMenu)
{
  Registry.gotoMainMenu = false;


clearPlayer();
clearLevel();
FlxG.switchState(new MenuState());
}
}

//clears the currently loaded player character
public function clearPlayer():void
{
//destroy current player character, if there is one
if (Registry.player != null)
{
Registry.player.destroy();
Registry.player = null;
}
}

//clears the currently loaded level
public function clearLevel():void
{
//destroy current level, if there is one
if (level != null)
{ level.destroy(); }
remove(level);
Registry.level = null;

}

private function levelChange():void
{
//clear the current level
clearLevel();

//load new level
level = new Registry.nextLevel();
level.addPlayer();
add(level);
Registry.level = level;

Registry.currentLevel = Registry.nextLevel;
Registry.nextLevel = null;
}

private function saveGame():void
{

if (canUseSave)
{
_save.data.player.x = Registry.player.x;
_save.data.player.y = Registry.player.y;
_save.data.player.maxHealth = Registry.player.maxHealth;
_save.data.player.maxStamina = Registry.player.maxStamina;
var levelName:String = flash.utils.getQualifiedClassName( Registry.currentLevel );
_save.data.level = levelName;

var counter:uint = 0;
for each(var f:Boolean in Registry.eventFlags)
{
_save.data.eventFlags[counter] = f;
counter++;
}
}
else
{
trace("Savestate was not initialized. Your game cannot save.");
}
}

public function loadGame():void
{
clearPlayer();
clearLevel();

if (canUseSave && _save.data.player == null)
{
//if there is no saved game, start a new game
Registry.player = new Player(304.000, 202.000);
Registry.setLevel(Level2);
}
else if(canUseSave && _save.data.player != null)
{
//load the game properly
Registry.player = new Player(_save.data.player.x, _save.data.player.y, _save.data.player.maxHealth, _save.data.player.maxStamina);
Registry.setLevel(flash.utils.getDefinitionByName( _save.data.level ) as Class);


for (var i:uint; i < Registry.eventFlags.length; i++ )
{
Registry.eventFlags[i] = _save.data.eventFlags[i];

}
}
else
{
//if the save file does not load (corrupted?)...
trace("Savestate was not initialized. Your game cannot load.");
//... start a new game
Registry.player = new Player(304.000, 202.000);
Registry.setLevel(Level2);
}
}
}

}

EDIT: fixed a bug that was unrelated.
Also, a link to the swf: http://megaswf.com/serve/1385343/



After looking at things a bit closer, it appears that the FlxSave is failing to bind. Would this be due to my local flash setting, and if so, what do I need to change?





Pages: [1]