/** * Internal function to help with basic pause game functionality. */ internal void unpauseGame() { //if(!FlxG.panel.visible) flash.ui.Mouse.hide(); FlxG.resetInput(); _paused = false; //stage.frameRate = _framerate; }
/// <summary> /// Bind a function Callback(Core:FlxCore,X:uint,Y:uint,Tile:uint) to a range of tiles. /// Temporarily deprecated. /// </summary> /// <param name="Tile">The tile to trigger the callback.</param> /// <param name="Callback">The function to trigger. Parameters should be <code>(Core:FlxCore,X:uint,Y:uint,Tile:uint)</code>.</param> /// <param name="Range">If you want this callback to work for a bunch of different tiles, input the range here. Default value is 1.</param> public void setCallback(int Tile, int Callback, int Range) { FlxG.log("WARNING: FlxTilemap.setCallback()\nhas been temporarily deprecated."); //if(Range <= 0) return; //for(var i:uint = Tile; i < Tile+Range; i++) // _callbacks[i] = Callback; }
/// <summary> /// Allows the FlxConsole to run commands. /// </summary> /// <param name="Cheat">Name of the cheat you want to run.</param> public static void runCheat(string Cheat) { if (Cheat.StartsWith("whatisgame")) { FlxG.log("Four Chambers"); } else if (Cheat.StartsWith("bigmoney")) { FlxG.score += 20000; } else if (Cheat.StartsWith("nobugs")) { FlxG.debug = false; } else if (Cheat == "bounds") { FlxG.showBounds = true; } else if (Cheat == "nobounds") { FlxG.showBounds = false; } else if (Cheat.StartsWith("level")) { FlxG.level = Convert.ToInt32(Cheat.Substring(5).ToString()); } cheatString = Cheat; }
/** * An internal function used to help organize and change the volume of the sound. */ internal void updateTransform() { if (_sound == null) { return; } _sound.Volume = FlxG.getMuteValue() * FlxG.volume * _volume * _volumeAdjust; }
/// <summary> /// Internal function to help with basic pause game functionality. /// </summary> internal void unpauseGame() { Console.WriteLine("Unpausing game from FlxGame"); //if(!FlxG.panel.visible) flash.ui.Mouse.hide(); FlxG.resetInput(); _paused = false; //stage.frameRate = _framerate; }
/// <summary> /// If you don't like to access the data object directly, you can use this to read from it. /// </summary> /// <param name="FieldName">The name of the data field you want to read</param> /// <returns>The value of the data field you are reading (null if it doesn't exist).</returns> public string read(string FieldName) { if (_so == null) { FlxG.log("WARNING: You must call FlxSave.bind()\nbefore calling FlxSave.read()."); return(null); } return(data[FieldName]); }
/** * Useful for finding out how long it takes to execute specific blocks of code. * * @param Start A <code>uint</code> created by <code>FlxU.startProfile()</code>. * @param Name Optional tag (for debug console display). Default value is "Profiler". * @param Log Whether or not to log this elapsed time in the debug console. * * @return A <code>uint</code> to be passed to <code>FlxU.endProfile()</code>. */ static public uint endProfile(uint Start, string Name, bool Log) { uint t = FlxG.getTimer; if (Log) { FlxG.log(Name + ": " + ((t - Start) / 1000) + "s"); } return(t); }
/// <summary> /// If you don't like to access the data object directly, you can use this to write to it. /// </summary> /// <param name="FieldName">The name of the data field you want to create or overwrite.</param> /// <param name="FieldValue">The data you want to store.</param> /// <param name="MinFileSize">If you need X amount of space for your save, specify it here.</param> /// <returns>Whether or not the write and flush were successful.</returns> public bool write(string FieldName, string FieldValue, uint MinFileSize) { if (_so == null) { FlxG.log("WARNING: You must call FlxSave.bind()\nbefore calling FlxSave.write()."); return(false); } data[FieldName] = FieldValue; return(forceSave(MinFileSize)); }
/// <summary> /// Erases everything stored in the local shared object. /// </summary> /// <param name="MinFileSize">If you need X amount of space for your save, specify it here.</param> /// <returns>Whether or not the clear and flush was successful.</returns> public bool erase(uint MinFileSize) { if (_so == null) { FlxG.log("WARNING: You must call FlxSave.bind()\nbefore calling FlxSave.erase()."); return(false); } _savedata = null; forceSave(MinFileSize); _savedata = new FlxSaveData(); return(true); }
/// <summary> /// Automatically creates or reconnects to locally saved data. /// </summary> /// <param name="Name">The name of the object (should be the same each time to access old data).</param> /// <returns>Whether or not you successfully connected to the save data.</returns> public bool bind(string Name) { _so = null; name = Name; try { _savedata = new FlxSaveData(); // Open a storage container. IAsyncResult result = _device.BeginOpenContainer(Name, null, null); // Wait for the WaitHandle to become signaled. result.AsyncWaitHandle.WaitOne(); _so = _device.EndOpenContainer(result); // Close the wait handle. result.AsyncWaitHandle.Close(); // Check to see whether the save exists. if (!_so.FileExists(_savefile)) { // If not, dispose of the container and return new blank data. _so.Dispose(); _savedata = new FlxSaveData(); return(true); } // Open the file. Stream stream = _so.OpenFile(_savefile, FileMode.Open); _savedata.deserialize(stream); // Close the file. stream.Close(); // Dispose the container. _so.Dispose(); } catch { FlxG.log("WARNING: There was a problem binding to\nthe shared object data from FlxSave."); name = null; _so = null; _savedata = null; return(false); } return(true); }
public void start(bool Explode, float Delay, int Quantity) { if (members.Count <= 0) { FlxG.log("WARNING: there are no sprites loaded in your emitter.\nAdd some to FlxEmitter.members or use FlxEmitter.createSprites()."); return; } _explode = Explode; if (!_explode) { _counter = 0; } if (!exists) { _particle = 0; } exists = true; visible = true; active = true; dead = false; on = true; _timer = 0; if (quantity == 0) { quantity = Quantity; } else if (Quantity != 0) { quantity = Quantity; } if (Delay != 0) { delay = Delay; } if (delay < 0) { delay = -delay; } if (delay == 0) { if (Explode) { delay = 3; //default value for particle explosions } else { delay = 0.1f; //default value for particle streams } } }
/// <summary> /// Shows/hides the console /// </summary> public void toggle() { if (_consoleYT == FlxG.spriteBatch.GraphicsDevice.Viewport.Height) { _consoleYT = 0; FlxG.showHud(); FlxG.showBounds = false; } else { _consoleYT = FlxG.spriteBatch.GraphicsDevice.Viewport.Height; visible = true; FlxG.hideHud(); FlxG.showBounds = true; } }
protected override void LoadContent() { //load up graphical content used for the flixel engine targetWidth = (int)(GraphicsDevice.Viewport.Height * ((float)FlxG.width / (float)FlxG.height)); targetLeft = (GraphicsDevice.Viewport.Width - targetWidth) / 2; FlxG.LoadContent(GraphicsDevice); //_sndBeep = FlxG.Content.Load<SoundEffect>("Flixel/beep"); initConsole(); if (_firstScreen != null) { FlxG.state = _firstScreen; _firstScreen = null; } }
/// <summary> /// Switch from one FlxState to another /// </summary> /// <param name="newscreen">The class name of the state you want (e.g. PlayState)</param> public void switchState(FlxState newscreen) { FlxG.unfollow(); FlxG.keys.reset(); FlxG.gamepads.reset(); FlxG.mouse.reset(); FlxG.flash.stop(); FlxG.fade.stop(); FlxG.quake.stop(); if (_state != null) { _state.destroy(); } _state = newscreen; _state.create(); }
//@desc Constructor //@param GameSizeX The width of your game in pixels (e.g. 320) //@param GameSizeY The height of your game in pixels (e.g. 240) //@param InitialState The class name of the state you want to create and switch to first (e.g. MenuState) //@param BGColor The color of the app's background //@param FlixelColor The color of the great big 'f' in the flixel logo public void initGame(int GameSizeX, int GameSizeY, FlxState InitialState, Color BGColor, bool showFlixelLogo, Color logoColor) { FlxG.backColor = BGColor; FlxG.setGameData(this, GameSizeX, GameSizeY); _paused = false; //activate the first screen. if (showFlixelLogo == false) { _firstScreen = InitialState; } else { FlxSplash.setSplashInfo(logoColor, InitialState); _firstScreen = new FlxSplash(); } }
/// <summary> /// Writes the local shared object to disk immediately. /// </summary> /// <param name="MinFileSize">If you need X amount of space for your save, specify it here.</param> /// <returns>Whether or not the flush was successful.</returns> public bool forceSave(uint MinFileSize) { if (_so == null) { FlxG.log("WARNING: You must call FlxSave.bind()\nbefore calling FlxSave.forceSave()."); return(false); } try { // Open a storage container. IAsyncResult result = _device.BeginOpenContainer(name, null, null); // Wait for the WaitHandle to become signaled. result.AsyncWaitHandle.WaitOne(); _so = _device.EndOpenContainer(result); // Close the wait handle. result.AsyncWaitHandle.Close(); // Check to see whether the save exists. if (_so.FileExists(_savefile)) { // Delete it so that we can create one fresh. _so.DeleteFile(_savefile); } // Create the file. Stream stream = _so.CreateFile(_savefile); // Convert the object to XML data and put it in the stream. _savedata.serialize(stream); // Close the file. stream.Close(); // Dispose the container, to commit changes. _so.Dispose(); } catch { FlxG.log("WARNING: There was a problem flushing\nthe shared object data from FlxSave."); return(false); } return(true); }
/// <summary> /// /// </summary> /// <param name="PointsX"></param> /// <param name="PointsY"></param> public void addPointsUsingStrings(string PointsX, string PointsY, int OffsetX, int OffsetY) { string[] splX = PointsX.Split(','); string[] splY = PointsY.Split(','); if (splX.Length != splY.Length) { FlxG.log("Length of both paths does not match"); return; } for (int i = 0; i < splX.Length; i++) { //Console.WriteLine(splX[i]); if (splX[i] != "" || splY[i] != "") { add(float.Parse(splX[i]) + OffsetX, float.Parse(splY[i]) + OffsetY); } } }
/** * Bind a function Callback(Core:FlxCore,X:uint,Y:uint,Tile:uint) to a range of tiles. * * @param Tile The tile to trigger the callback. * @param Callback The function to trigger. Parameters should be <code>(Core:FlxCore,X:uint,Y:uint,Tile:uint)</code>. * @param Range If you want this callback to work for a bunch of different tiles, input the range here. Default value is 1. */ public void setCallback(int Tile, int Callback, int Range) { FlxG.log("WARNING: FlxTilemap.setCallback()\nhas been temporarily deprecated."); }
override public void update() { PlayerIndex pi; updateFramesSinceLeftFloor(); if (FlxG.debug) { if (FlxGlobal.cheatString.StartsWith("slowdown")) { runSpeed = 22; } if (FlxGlobal.cheatString == "control" + GetType().ToString().Split('.')[1]) { control = Controls.player; FlxG.follow(this, 11.0f); } if (FlxGlobal.cheatString == "controlFile" + GetType().ToString().Split('.')[1]) { control = Controls.file; FlxG.follow(this, 11.0f); startPlayingBack(); } } if (control == Controls.player && this.dead != true) { if (FlxG.keys.A || FlxG.keys.LEFT) { leftPressed(); } if (FlxG.gamepads.isButtonDown(Buttons.DPadLeft, ControllingPlayer, out pi)) { leftPressed(); } if (FlxG.gamepads.isButtonDown(Buttons.LeftThumbstickLeft, ControllingPlayer, out pi)) { leftPressed(); } if (FlxG.keys.D || FlxG.keys.RIGHT) { rightPressed(); } if (FlxG.gamepads.isButtonDown(Buttons.DPadRight, ControllingPlayer, out pi)) { rightPressed(); } if (FlxG.gamepads.isButtonDown(Buttons.LeftThumbstickRight, ControllingPlayer, out pi)) { rightPressed(); } if (FlxG.keys.B || FlxG.gamepads.isButtonDown(Buttons.RightTrigger)) { maxVelocity.X = _runningMax * 2; } else { maxVelocity.X = _runningMax; } if (FlxG.keys.W || FlxG.keys.SPACE || FlxG.keys.X || FlxG.gamepads.isButtonDown(Buttons.A, ControllingPlayer, out pi)) { jump(); } else { if (_jumpCounter < numberOfJumps) { _jump = 0.0f; } else { _jump = -1; } } if (FlxG.keys.N || FlxG.gamepads.isButtonDown(Buttons.LeftTrigger)) { action = Actions.talk; } else { action = Actions.idle; } } else if (control == Controls.file) { if (frameCount > _history.Count - 2) { frameCount = 0; return; } frameCount++; int left = 3; int right = 1; if (reverseControls) { left = 1; right = 3; } if (_history[frameCount][left]) { leftPressed(); } if (_history[frameCount][right]) { rightPressed(); } if (_history[frameCount][4]) { jump(); } if (_history[frameCount][10]) { action = Actions.talk; } else { action = Actions.idle; } } updateAnims(); base.update(); }
//@desc This is the main game loop public override void Update(GameTime gameTime) { PlayerIndex pi; //Frame timing FlxG.getTimer = (uint)gameTime.TotalGameTime.TotalMilliseconds; FlxG.elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; if (FlxG.elapsed > FlxG.maxElapsed) { FlxG.elapsed = FlxG.maxElapsed; } FlxG.elapsed *= FlxG.timeScale; //Animate flixel HUD elements _console.update(); if (_soundTrayTimer > 0) { _soundTrayTimer -= FlxG.elapsed; } else if (_soundTrayRect.Y > -_soundTrayRect.Height) { _soundTrayRect.Y -= (int)(FlxG.elapsed * FlxG.height * 2); _soundCaption.y = (_soundTrayRect.Y + 4); for (int i = 0; i < _soundTrayBars.Length; i++) { _soundTrayBars[i].y = (_soundTrayRect.Y + _soundTrayRect.Height - _soundTrayBars[i].height - 2); } if (_soundTrayRect.Y < -_soundTrayRect.Height) { _soundTrayVisible = false; } } //State updating FlxG.keys.update(); FlxG.gamepads.update(); FlxG.mouse.update(); FlxG.updateSounds(); if (FlxG.keys.isNewKeyPress(Keys.D0, null, out pi)) { FlxG.mute = !FlxG.mute; showSoundTray(); } else if (FlxG.keys.isNewKeyPress(Keys.OemMinus, null, out pi)) { FlxG.mute = false; FlxG.volume -= 0.1f; showSoundTray(); } else if (FlxG.keys.isNewKeyPress(Keys.OemPlus, null, out pi)) { FlxG.mute = false; FlxG.volume += 0.1f; showSoundTray(); } else if (FlxG.keys.isNewKeyPress(Keys.D1, null, out pi) || FlxG.keys.isNewKeyPress(Keys.OemTilde, null, out pi)) { _console.toggle(); } else if (FlxG.autoHandlePause && (FlxG.keys.isPauseGame(FlxG.controllingPlayer) || FlxG.gamepads.isPauseGame(FlxG.controllingPlayer))) { FlxG.pause = !FlxG.pause; } if (_paused) { return; } if (FlxG.state != null) { //Update the camera and game state FlxG.camera.doFollow(); FlxG.state.update(); //Update the various special effects if (FlxG.flash.exists) { FlxG.flash.update(); } if (FlxG.fade.exists) { FlxG.fade.update(); } FlxG.quake.update(); _quakeOffset.X = FlxG.quake.x; _quakeOffset.Y = FlxG.quake.y; } }
/// <summary> /// This is the main game loop /// </summary> /// <param name="gameTime">Game Time</param> public override void Update(GameTime gameTime) { PlayerIndex pi; //Frame timing FlxG.getTimer = (uint)gameTime.TotalGameTime.TotalMilliseconds; FlxG.elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; FlxG.elapsedTotal += (float)gameTime.ElapsedGameTime.TotalSeconds; FlxG.elapsedFrames++; FlxG.elapsedAsGameTime = gameTime; if (FlxG.elapsed > FlxG.maxElapsed) { FlxG.elapsed = FlxG.maxElapsed; } FlxG.elapsed *= FlxG.timeScale; //Animate flixel HUD elements _console.update(); hud.update(); if (_soundTrayTimer > 0) { _soundTrayTimer -= FlxG.elapsed; } else if (FlxG.mute || FlxG.volume < 0.05f) { // Volume is mute or 0, so leave it on-screen; } else if (_soundTrayRect.Y > -_soundTrayRect.Height) { _soundTrayRect.Y -= (int)(FlxG.elapsed * FlxG.height * 2); _soundCaption.y = (_soundTrayRect.Y + 4); for (int i = 0; i < _soundTrayBars.Length; i++) { _soundTrayBars[i].y = (_soundTrayRect.Y + _soundTrayRect.Height - _soundTrayBars[i].height - 2); } if (_soundTrayRect.Y < -_soundTrayRect.Height) { _soundTrayVisible = false; } } //State updating FlxG.keys.update(); FlxG.gamepads.update(); FlxG.mouse.update(); //set a helper for last control type used. updateLastUsedControl(); FlxG.updateSounds(); if (FlxG.keys.isNewKeyPress(Keys.OemPipe, null, out pi)) { FlxG.mute = !FlxG.mute; showSoundTray(); } else if (FlxG.keys.isNewKeyPress(Keys.OemOpenBrackets, null, out pi)) { FlxG.mute = false; FlxG.volume -= 0.1f; showSoundTray(); } else if (FlxG.keys.isNewKeyPress(Keys.OemCloseBrackets, null, out pi)) { FlxG.mute = false; FlxG.volume += 0.1f; showSoundTray(); } else if (FlxG.keys.isNewKeyPress(Keys.OemTilde, null, out pi) || FlxG.keys.isNewKeyPress(Keys.D0, null, out pi)) { //FlxG.keys.isNewKeyPress(Keys.D1, null, out pi) || if (FlxG.debug == true) { //Console.WriteLine("TOGGLING THE CONSOLE"); _console.toggle(); } } else if (FlxG.debug && FlxG.gamepads.isButtonDown(Buttons.DPadDown)) { #if ANDROID if (FlxG.debug == true) { _console.toggle(); } #endif } else if (FlxG.autoHandlePause && (FlxG.keys.isPauseGame(FlxG.controllingPlayer) || FlxG.gamepads.isPauseGame(FlxG.controllingPlayer))) { //Previously, causing a double up of pause. //FlxG.pause = !FlxG.pause; _paused = !_paused; if (_paused == true) { FlxG.pauseSounds(); } else if (_paused == false) { FlxG.playSounds(); } } if (_paused) { if (FlxG.gamepads.isNewButtonPress(Buttons.Y)) { _paused = !_paused; FlxG.pauseAction = "Exit"; } else { FlxG.pauseAction = ""; } return; } if (FlxG.state != null) { //Update the camera and game state FlxG.doFollow(); FlxG.state.update(); //Update the various special effects if (FlxG.flash.exists) { FlxG.flash.update(); } if (FlxG.fade.exists) { FlxG.fade.update(); } if (FlxG.transition.exists) { FlxG.transition.update(); } FlxG.quake.update(); _quakeOffset.X = FlxG.quake.x; _quakeOffset.Y = FlxG.quake.y; } FlxGlobal.cheatString = ""; FlxG.pauseAction = ""; }
/// <summary> /// Call this function to lock the automatic camera to the map's edges. /// </summary> /// <param name="Border">Adjusts the camera follow boundary by whatever number of tiles you specify here. Handy for blocking off deadends that are offscreen, etc. Use a negative number to add padding instead of hiding the edges.</param> public void follow(int Border) { FlxG.followBounds((int)x + Border * _tileWidth, (int)y + Border * _tileHeight, (int)width - Border * _tileWidth, (int)height - Border * _tileHeight); }
public override void update() { //if (FlxG.elapsedFrames == 5) // FlxG.transition.startFadeIn(0.08f); if (FlxG.keys.justPressed(Keys.B)) { cheatStorage += "B"; } if (FlxG.keys.justPressed(Keys.U)) { cheatStorage += "U"; } if (FlxG.keys.justPressed(Keys.G)) { cheatStorage += "G"; } if (FlxG.keys.justPressed(Keys.S)) { cheatStorage += "S"; } if (cheatStorage == FlxGlobal.titleScreenDebugMode) { debugMode.visible = true; FlxG.debug = true; } _logoTweener.Update(FlxG.elapsedAsGameTime); //_logo.y = _logoTweener.Position; if (_logoTimer > 1.15f) { //FlxG.bloom.Visible = true; //FlxG.bloom.bloomIntensity += 1.5f; //FlxG.bloom.baseIntensity += 1.0f; //FlxG.bloom.blurAmount += 1.1f; } if (_f == null && _logoTimer > 2.5f) { foreach (FlxLogoSprite item in logoParts.members) { item.play("bugs2", true); //item.velocity.Y = FlxU.randomInt(-200, 200); //item.angularVelocity = FlxU.randomInt(120, 240); float offset = FlxG.height; if (item._row < 1) { offset *= -1.0f; } item.t = new Tweener(item.y, item.y + offset, 0.25f + (item._col / 18.0f), Quadratic.EaseInOut); item.t.Reverse(); item.t.Start(); } //_logo.visible = false; _logoTweener.Reverse(); _logoTweener.Start(); //FlxG.flash.start(FlxG.backColor, 1.0f, null, false); _f = new List <FlxLogoPixel>(); int scale = 10; float pwrscale; int pixelsize = (FlxG.height / scale); int top = (FlxG.height / 2) - (pixelsize * 2); int left = (FlxG.width / 2) - pixelsize; pwrscale = ((float)pixelsize / 24f); //Add logo pixels add(new FlxLogoPixel(left + pixelsize, top, pixelsize, 0, _fc)); add(new FlxLogoPixel(left, top + pixelsize, pixelsize, 1, _fc)); add(new FlxLogoPixel(left, top + (pixelsize * 2), pixelsize, 2, _fc)); add(new FlxLogoPixel(left + pixelsize, top + (pixelsize * 2), pixelsize, 3, _fc)); add(new FlxLogoPixel(left, top + (pixelsize * 3), pixelsize, 4, _fc)); FlxSprite pwr = new FlxSprite((FlxG.width - (int)((float)_poweredBy.Width * pwrscale)) / 2, top + (pixelsize * 4) + 16, _poweredBy); pwr.loadGraphic(_poweredBy, false, false, 64); //pwr.color = _fc; //pwr.scale = pwrscale; add(pwr); _fSound.Play(FlxG.volume, 0f, 0f); } _logoTimer += FlxG.elapsed; base.update(); if (FlxG.keys.ONE) { FlxG.level = 1; } if (FlxG.keys.TWO) { FlxG.level = 2; } if (FlxG.keys.THREE) { FlxG.level = 3; } if (FlxG.keys.FOUR) { FlxG.level = 4; } if (FlxG.keys.FIVE) { FlxG.level = 5; } if (FlxG.keys.SIX) { FlxG.level = 6; } if (FlxG.keys.SEVEN) { FlxG.level = 7; } if (FlxG.keys.EIGHT) { FlxG.level = 8; } if (FlxG.keys.NINE) { FlxG.level = 9; } if (_logoTimer > 5.5f || FlxG.keys.SPACE || FlxG.keys.ENTER || FlxG.gamepads.isButtonDown(Buttons.A)) { FlxG.destroySounds(true); //FlxG.bloom.Visible = false; FlxG.state = _nextScreen; } if (FlxG.keys.F1 || (FlxG.gamepads.isButtonDown(Buttons.RightStick) && FlxG.gamepads.isButtonDown(Buttons.LeftStick))) { //FlxG.bloom.Visible = false; FlxG.destroySounds(true); #if !__ANDROID__ FlxG.state = new org.flixel.examples.TestState(); #endif } if (FlxG.keys.F8) { FlxG.state = new org.flixel.FlxSplash(); return; } }