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 - xhunterko

Pages: [1] 2 3 ... 5
1
help / Camera Swap
« on: Wed, Feb 27, 2013 »
Hey there!

I'm not too keen on deciphering documentation docs and I've not seen this posted here yet.

What I'm trying to do is switch a camera's settings when the player walks over a sprite. So, if a player is in a room, the camera scrolls and focuses around that room. If the player switches to another room, the camera scrolls and focuses around that room instead.

Here's what I'm trying to do code-wise:

Code: [Select]
package com
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;
import flash.geom.Rectangle;

public class StationState extends FlxState
{

//Mouse
public var mouseCon:FlxSprite;

public var hbar:HealthBlock;

public var backdrop:FlxGroup;
public var background:FlxSprite;
public var janitorCloset:FlxSprite;

public var _player:PlayerInspector;
public var cam1:FlxCamera;
public var cam2:FlxCamera;

public var wallN:FlxTileblock;
public var wallW:FlxTileblock;
public var wallE:FlxTileblock;
public var wallS:FlxTileblock
public var wallz:FlxGroup;

public var camSettingsA:int;
public var camSettingsB:int;
public var camSettingsC:int;
public var camSettingsD:int;

override public function create():void
{
wallz = new FlxGroup;

FlxG.bgColor = 0xff000000;
background = new FlxSprite(0, 0);
background.makeGraphic(740, 1440, 0xff888888);
add(background);

janitorCloset = new FlxSprite(720, 0);
janitorCloset.makeGraphic(220, 1440, 0xff808080);
add(janitorCloset);

camSettingsA = background.x;
camSettingsB = background.y;
camSettingsC = background.width;
camSettingsD = background.height;


wallE = new FlxTileblock(0, 0, 16, 1440);
wallE.makeGraphic(16, 1440, 0xffD70000);
add(wallE);

wallz.add(wallE);
add(wallz);

_player = new PlayerInspector(120, 62);
add(_player);

//Camera 1
cam1 = new FlxCamera(0, 0, FlxG.width, FlxG.height);
FlxG.resetCameras(cam1);
cam1.follow(_player, FlxCamera.STYLE_TOPDOWN_TIGHT);
FlxG.worldBounds = new FlxRect(camSettingsA,camSettingsB,camSettingsC,camSettingsD);
cam1.bounds = new FlxRect(camSettingsA,camSettingsB,camSettingsC,camSettingsD);

FlxG.camera.follow(_player, FlxCamera.STYLE_TOPDOWN);
add(cam1);





FlxG.mouse.show();
mouseCon = new FlxSprite(0, 0);
mouseCon.makeGraphic(24, 32, 0xff400040);
mouseCon.x = mouseCon.y = 0;
mouseCon.visible = false;
add(mouseCon);


}
//
override public function update():void
{


if (_player.overlaps(background))
{
camSettingsA = background.x;
camSettingsB = background.y;
camSettingsC = background.width;
camSettingsD = background.height;
}

if (_player.overlaps(janitorCloset))
{
camSettingsA = janitorCloset.x;
camSettingsB = janitorCloset.y;
camSettingsC = janitorCloset.width;
camSettingsD = janitorCloset.height;
}

//Debug



super.update();



if (mouseCon.x != FlxG.mouse.x)
{
mouseCon.x = FlxG.mouse.x;
}
if (mouseCon.y != FlxG.mouse.y)
{
mouseCon.y = FlxG.mouse.y;
}

FlxG.collide(_player, wallz);


}




override public function destroy():void
{
// Important! Clear out the plugin, otherwise resources will get messed right up after a while
FlxSpecialFX.clear();

super.destroy();
}



}
}


I don't know why it's not working. But it really seems like it should. Any idea what I'm doing wrong here?

2
releases / Health Bar Variant
« on: Tue, Jan 1, 2013 »
I was working on a project and needed a zelda-like health bar for my game. I tried using the Power tools cause I remember it having a similar funtion. However, I couldn't get it to behave right. So. I remember playing a Ludum Dare game that had a similar mechanic. So I found it and dug through the source til I found what I needed.

The heart meter:
Code: [Select]
package com
{
import org.flixel.*;
//Kuroki

public class HealthBlock extends FlxSprite
{

[Embed(source='../../data/healthBlock.png')] public var ImgHealth:Class;
public var posX:int;

public function  HealthBlock(X:int, Y:int):void
{
super(X, Y);
loadGraphic(ImgHealth, false, false, 16, 16);
//makeGraphic(16, 16, 0xffFF0000, false, "healthBlock");
posX = X;
}



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

override public function draw():void {
//var center:int = FlxG.width ;
                        //Here is where you set the player's health initially
var hearts:int = Registry.health;
                        //The original width of the sprite
var width:int = 16 * hearts + 1;

//y = 229;
frame = 0;
for (var i:uint = 0; i < hearts; i++) {
//x = center - width  + i * 10;
                               //I believe this is the space from the start x, to the next hear's x, if you want spacing between your hearts
x = posX + i *22;
if (Registry.health < i + 1) {
                                        //Er, your guess is as good as mine. 
frame = 1;
}

super.draw();
}
}


}
}



Playstate:
Code: [Select]
//This is how I call it
package com
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;
import org.flixel.plugin.photonstorm.FX.StarfieldFX;
import flash.geom.Rectangle;

public class EarthState2 extends FlxState
{
//Music
//[Embed(source= '../../Music/DeadlierWindmills.mp3')] public var AmbMus1:Class;


public var playNow:FlxAdventureButton;

//Mouse
public var mouseCon:FlxSprite;

//Title
public var t:FlxText;

//Tiled background
public var background:FlxSprite;

public var pickBox:FlxAdventureButton;

private var stars:FlxSprite;
private var starfield:StarfieldFX;

public var _earth:Earth;

//The heart meter and it's text box
public var healthG:FlxText = new FlxText(16,0,400,"Health 2:",false);
public var hbar:HealthBlock;

override public function create():void
{
// If the Plugin isn't already in use, we add it here
if (FlxG.getPlugin(FlxScreenGrab) == null)
{
FlxG.addPlugin(new FlxScreenGrab);
}
if (FlxG.getPlugin(FlxSpecialFX) == null)
{
FlxG.addPlugin(new FlxSpecialFX);
}

starfield = FlxSpecialFX.starfield();
stars = starfield.create(0, 0, 640, 480, 256);
add(stars);


FlxG.bgColor = 0xffFFFFFF;

_earth = new Earth(FlxG.width/2-37, FlxG.height/2-37);
add(_earth);

//Health bar
healthG.size = 18;
add(healthG);

//healthG.x *2 + 34,0
//The heart meter attached to it's text box
hbar = new HealthBlock(healthG.x * 2 + 34, 0);
add(hbar);


mouseCon = new FlxSprite(0, 0);
mouseCon.makeGraphic(16, 16, 0xffFFFFFF);
mouseCon.x = mouseCon.y = 1;
//mouseCon.visible = false;
add(mouseCon);

if (Registry.level == 2)
{



}


}
//
override public function update():void
{
//Any action where the player would lose health
if (FlxG.mouse.justPressed())
{

Registry.health--;

}
if(FlxG.keys.any())
{

FlxG.switchState(new EarthState2());
}

super.update();


if (mouseCon.x != FlxG.mouse.x)
{
mouseCon.x = FlxG.mouse.x;
}
if (mouseCon.y != FlxG.mouse.y)
{
mouseCon.y = FlxG.mouse.y;
}


}



}
}

The registry is just your typical registry file. You could probably do without but I don't reccomend it. You can find out how to set one up here: http://www.photonstorm.com/archives/1136/flash-game-dev-tip-1-creating-a-cross-game-communications-structure

Very handy and very easy to do! So I thought I'd share it here.

Originally written by: @arkeus for Arzea for Ludum Dare 22

Enjoy!

3
help / Weird Bug [solved]
« on: Wed, Oct 10, 2012 »
Okay. So I've been trying to get level loading working and I think I did the other night. So I take a nap, get up, and suddenly everything is broken. In my game, you have to correct a cell patern by switching a cell in the playfield with a cell in the inventory. If the two are compatible, the cell will switch to something else. Once you've corrected the sequence, a next level button will appear and you can go to the next cell sequences. There's a problem.

There are currently 4 levels. I'm using one file to load multiple levels, and a Registry object to hold the level number. When the player hits the next level button, the frame goes back to itself, and then arranges whatever cells in a pattern based on the registry number. The error occurs only after I go from level 1 to level 2. Not from level whatever to level whatever. And I don't know if it's level 1 or 2 that's the problem, cause going from level 2 to 3 (or any other level) is fine.

So, here's the error Flash Develop is throwing at me:

Code: [Select]
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com::GradStudentStage/update()
at org.flixel::FlxGame/update()
at org.flixel::FlxGame/step()
at org.flixel::FlxGame/onEnterFrame()

Which, I don't know why. Cause I have, if Registry is 1, do things to create the level. And I have if Registry is 2, do things to create level. I don't know what's causing that. Here's the code for the, stage:

//It's rather long, sorry bout that. I've made a comment in there about where the error occurs.
Code: [Select]
package com
{
import flash.accessibility.ISimpleTextSelection;
import flash.display.InteractiveObject;
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;
import org.flixel.plugin.photonstorm.FX.SineWaveFX;
import flash.geom.Rectangle;
import flash.display.Graphics;

/**
* Evolution!!!vvvv
*/

public class GradStudentStage extends FlxState
{

//Embeds
[Embed(source= '../../data/comoFin.mp3')] public var SndHit:Class;
[Embed(source= '../../data/errorFin.mp3')] public var SndHit2:Class;

//privvate/public vars

//Pause
public var paused:FlxPaused;

//Tutorial Mode
public var tutorialMode:FlxTutorialSession;

//Gui eye group
public var guiGroup:Gui;

//Inventory group
public var inventoryGroup:FlxGroup;


public var hp:FlxHelpBox;

//Cell inventory
public var invCellA:FlxAdventureButton;
public var invCellB:FlxAdventureButton;
public var invCellC:FlxAdventureButton;
public var invCellD:FlxAdventureButton;

//the help
public var click1:FlxAdventureButton;
public var click2:FlxAdventureButton;

//Next screen
public var nextClick:FlxAdventureButton;



//Grid cells
public var gcell1:RandomCell;
public var gcell2:RandomCell;
public var gcell3:RandomCell;
public var gcell4:RandomCell;
public var gcell5:RandomCell;
public var gcell6:RandomCell;

public var gridGroup:FlxGroup;

//Question Block
public var qblock:guiQuestionBlock;

//Hand hacked mouse
public var mouseCon:FlxSprite;

//Backscreen
private var mouseScreen:FlxSprite;
//
//Moves
public var moves:int;
public var moveGui:FlxText;
public var moveGuiNum:FlxText;
//Par
public var par:int;
public var parGui:FlxText;
public var parGuiNum:FlxText;

public var flashfx:FilterSprite;

//Testing board object
//This replaces all the playfield object placing
public var board:BoardState;

//Player's completion for win condition for multiple cells
public var winIt:uint;

override public function create():void
{
//Stage layout
/**
* Steps for a level:
* Set the par for each level.
* Set the hint for each level.
* Set the needed cell changes for each l.-
* Create level by registry number.
* Check to see if win condition met.
* Display next level button.
* Set the registry number when the next level button is clicked.
* Repeat for each level.
*
*/

// If the Plugin isn't already in use, we add it here
if (FlxG.getPlugin(FlxScreenGrab) == null)
{
FlxG.addPlugin(new FlxScreenGrab);
}

// Define our hotkey (string value taken from FlxG.keys) the parameters simply say "save it right away" and "hide the mouse first"
FlxScreenGrab.defineHotKey("F1", true, true);

//FlxG.mouse.show();

if (Registry.level >= 1)
{
board = new BoardState(46, 46);
//board.visible = false;
add(board);
}



//Bullet time effect??
//FlxG.bgColor = 0xff9FB85;
mouseScreen = new FlxSprite(0, 0);
mouseScreen.makeGraphic(640, 416, 0x00000000);
add(mouseScreen);

FlxG.bgColor = 0xffC0C0C0;

guiGroup = new Gui(160,416);
add(guiGroup);



//Help
//Hint Box
qblock = new guiQuestionBlock(608, 0);
add(qblock);

//Cell grid
gridGroup = new FlxGroup();
add(gridGroup);

//Inventory Row
inventoryGroup = new FlxGroup();

invCellA = new FlxAdventureButton(192, 432, 32, 32, "");
invCellA.enabled = false;
invCellA.visible = false;
invCellA._bg.color = 0xffFFFFFF;
add(invCellA);

invCellB = new FlxAdventureButton(invCellA._bg.x + 64, 432, 32, 32, "");
invCellB.enabled = false;
invCellB.visible = false;
add(invCellB);

invCellC = new FlxAdventureButton(invCellB._bg.x + 80, 432, 32, 32, "");
invCellC.enabled = false;
invCellC.visible = false;
add(invCellC);

invCellD = new FlxAdventureButton(invCellC._bg.x+64, 432, 32, 32, "");
invCellD.enabled = false;
invCellD.visible = false;
add(invCellD);

//Adding helper text per stage
var t:FlxText;
t = new FlxText(162, 396,400,"Needed:");
t.size = 16;
t.alignment = "left";
t.color = 0xffFF0000;
add(t);

//Tell the player what they need to fix
//
var miniHelp:MiniCell;
var miniHelpB:MiniCell;
if (Registry.level == 1)
{

miniHelp = new MiniCell(invCellB.px, t.y+8);
miniHelp.distributionp = 1;
add(miniHelp);
}
//
if (Registry.level == 2)
{

miniHelp = new MiniCell(invCellB.px, t.y+8);
miniHelp.distributionp = 1;
add(miniHelp);
}
//
if (Registry.level == 3)
{

miniHelp = new MiniCell(invCellB.px, t.y+8);
miniHelp.distributionp = 0;
add(miniHelp);

miniHelpB = new MiniCell(invCellB.px+32, t.y+8);
miniHelpB.distributionp = 1;
add(miniHelpB);


}
//
if (Registry.level == 4)
{

miniHelp = new MiniCell(invCellB.px, t.y+8);
miniHelp.distributionp = 0;
add(miniHelp);

miniHelpB = new MiniCell(invCellB.px+32, t.y+8);
miniHelpB.distributionp = 0;
add(miniHelpB);


}
//

//Moves
moveGui = new FlxText(0,0,200,"Moves:")
moveGui.size = 16;
moveGui.alignment = "left";
moveGui.color = 0xffFF0000;
add(moveGui);

//Just make them all transparent in one line shall we?
invCellA._bg.alpha = 0.45;
invCellB._bg.alpha = 0.45;
invCellC._bg.alpha = 0.45;
invCellD._bg.alpha = 0.45;



//to next level
nextClick = new FlxAdventureButton(536, 416, 32, 32, "Click to go to Next");
add(nextClick)

//Levels!
if (Registry.level == 1)
{
//Adding the play pieces
//Tutorial pieces are set board.grBx.members[2]
gcell1 = new RandomCell(board.grBx.members[11].x, board.grBx.members[11].y);
gcell1.distributionp = 0;
add(gcell1);

gcell2 = new RandomCell(board.grBx.members[13].x, board.grBx.members[13].y);
gcell2.distributionp = 0;
//gcell2.visible = false;
add(gcell2);

par = 2;
}

if (Registry.level == 2)
{
//Adding the play pieces
gcell1 = new RandomCell(board.grBx.members[11].x, board.grBx.members[11].y);
gcell1.distributionp = 0;
add(gcell1);

gcell2 = new RandomCell(board.grBx.members[2].x, board.grBx.members[2].y);
gcell2.distributionp = 3;
add(gcell2);

gcell3 = new RandomCell(board.grBx.members[8].x, board.grBx.members[8].y);
gcell3.distributionp = 0;
add(gcell3);

par = 3;
}

if (Registry.level == 3)
{
//Adding the play pieces
gcell1 = new RandomCell(board.grBx.members[0].x, board.grBx.members[0].y);
gcell1.distributionp = 3;
add(gcell1);

gcell2 = new RandomCell(board.grBx.members[18].x, board.grBx.members[18].y);
gcell2.distributionp = 0;
add(gcell2);

gcell3 = new RandomCell(board.grBx.members[19].x, board.grBx.members[19].y);
gcell3.distributionp = 3;
add(gcell3);

gcell4 = new RandomCell(board.grBx.members[14].x, board.grBx.members[14].y);
gcell4.distributionp = 0;
add(gcell4);




par = 4;
}

if (Registry.level == 4)
{
//Adding the play pieces
gcell1 = new RandomCell(board.grBx.members[6].x, board.grBx.members[6].y);
gcell1.distributionp = 0;
add(gcell1);

gcell2 = new RandomCell(board.grBx.members[7].x, board.grBx.members[7].y);
gcell2.distributionp = 3;
add(gcell2);

gcell3 = new RandomCell(board.grBx.members[2].x, board.grBx.members[2].y);
gcell3.distributionp = 3;
add(gcell3);

gcell4 = new RandomCell(board.grBx.members[8].x, board.grBx.members[8].y);
gcell4.distributionp = 0;
add(gcell4);

gcell5 = new RandomCell(board.grBx.members[12].x, board.grBx.members[12].y);
gcell5.distributionp = 1;
add(gcell5);



par = 3;
}


//Par
//Unlike moves, par is permanent
parGui = new FlxText(120,0,200,"Par:  02")
parGui.size = 16;
parGui.alignment = "left";
parGui.color = 0xffFF0000;
add(parGui);



//Cell lines
//mouseScreen.drawLine(gcell1.x+4, gcell1.y+32, gcell2.x+32, gcell2.y+32, 0xff000000,2);
//mouseScreen.draw();



gridGroup.add(gcell1);
gridGroup.add(gcell2);
gridGroup.add(gcell3);
gridGroup.add(gcell4);
gridGroup.add(gcell5);
gridGroup.add(gcell6);



//A flash effect for a hint
flashfx = new FilterSprite();
//flashfx.x = gcell2.x;
//flashfx.y = gcell2.y;
flashfx.makeGraphic(64, 64, 0xff8080FF);
flashfx.activateFilter(FilterSprite.FILTER_COLOR);
flashfx.alpha = 0.85;
flashfx.visible = false;
add(flashfx);





//To be on top of almost everything else
paused = new FlxPaused;
//add(paused);



mouseCon = new FlxSprite(0, 0);
mouseCon.makeGraphic(16, 16, 0xff400040);
mouseCon.x = mouseCon.y = 0;
//mouseCon.visible = false;
add(mouseCon);





}
 
override public function update():void
{


//The pause menu is popped up here
if (!paused.showing)
{


if (mouseCon.overlaps(invCellA) && FlxG.mouse.justPressed())
{
invCellA.enabled = true;
invCellA.visible = true;
}

if (mouseCon.overlaps(invCellB) && FlxG.mouse.justPressed())
{
invCellB.enabled = true;
invCellB.visible = true;
}


if (mouseCon.overlaps(invCellC) && FlxG.mouse.justPressed())
{

invCellC.enabled = true;
invCellC.visible = true;
}

if (mouseCon.overlaps(invCellD) && FlxG.mouse.justPressed())
{
invCellD.enabled = true;
invCellD.visible = true;
}

/*
if (mouseCon.overlaps(board.boxes[1]) && FlxG.mouse.justPressed())
{
board.right._bg.flicker(4);

}
*/






//Pieces selected and merging them with other parts
//if a piece is selected and the inventory piece a is picked

//Selectioin cell A
if (invCellA.enabled == true )
{
for each (var oneA:RandomCell in gridGroup.members)
{
//Cell formulaes
//a+a
if (FlxG.overlap(mouseCon, oneA) && oneA.distributionp == 1 && FlxG.mouse.justPressed() )
{
oneA.distributionp = 2;


} else if (!FlxG.overlap(mouseCon, invCellA) && FlxG.mouse.justPressed() )
{
invCellA.visible = false;
invCellA.enabled = false;
}
//
}

}


//Selection Cell B
if (invCellB.enabled == true)
{
for each (var twoA:RandomCell in gridGroup.members)
{
//Cell formulaes

if (FlxG.overlap(mouseCon, twoA) && twoA.distributionp == 2 && FlxG.mouse.justPressed())
{
twoA.distributionp = 3;


} else if (!FlxG.overlap(mouseCon, invCellB) && FlxG.mouse.justPressed())
{
invCellB.visible = false;
invCellB.enabled = false;

}
//
}
}

  //Selection Cell C
if (invCellC.enabled == true)
{
for each (var threeA:RandomCell in gridGroup.members)
{
//Cell formulaes

if (FlxG.overlap(mouseCon, threeA) && threeA.distributionp == 3 && FlxG.mouse.justPressed())
{
threeA.distributionp = 0;


} else if (!FlxG.overlap(mouseCon, invCellC) && FlxG.mouse.justPressed() )
{
invCellC.visible = false;
invCellC.enabled = false;
}
//
}
}

   //Selection Cell D
if (invCellD.enabled == true)
{
for each (var fourA:RandomCell in gridGroup.members)
{
//Cell formulaes

if (FlxG.overlap(mouseCon, fourA) && fourA.distributionp == 0 && FlxG.mouse.justPressed())
{
fourA.distributionp = 1;


} else if (!FlxG.overlap(mouseCon, invCellD) && FlxG.mouse.justPressed() )
{
invCellD.visible = false;
invCellD.enabled = false;
}
//
}
}


//Hint
//LEVEL 1
if (Registry.level == 1)
{
if(FlxG.mouse.justPressed() && mouseCon.overlaps(qblock))
{
flashfx.visible = true;
} else if (FlxG.mouse.justReleased())
{
flashfx.visible = false;
}
}

//Next level
if (Registry.level == 1)
{
if (FlxG.overlap(mouseCon, nextClick) && FlxG.mouse.justPressed())
{

//win condition
if (gcell2.distributionp == 1)
{
//Here is where it throws the error. But it doesn't throw it anywhere else I do this. Why?
Registry.level = 2;
FlxG.switchState(new GradStudentStage());

} else
{

nextClick.visible = false;//
}
}
if (gcell2.distributionp != 1)
{

nextClick.visible = false;//
} else
{

nextClick.visible = true;
}
}
//LEVEL 2 check
if (Registry.level == 2)
{
if (FlxG.overlap(mouseCon, nextClick) && FlxG.mouse.justPressed())
{

//win condition
if (gcell2.distributionp == 1)
{
Registry.level = 3;
FlxG.switchState(new GradStudentStage());

} else
{

nextClick.visible = false;//
}
}
if (gcell3.distributionp != 1)
{

nextClick.visible = false;//
} else
{

nextClick.visible = true;
}
}

//LEVEL 3 check
if (Registry.level == 3)
{
//Different condition for 2 cells
if (gcell3.distributionp == 1 && gcell1.distributionp == 0)
{
winIt = 1;
}

if (winIt == 1)
{

nextClick.visible = true;//
} else
{
nextClick.visible = false;
}


if (FlxG.overlap(mouseCon, nextClick) && FlxG.mouse.justPressed())
{

//win condition
if (winIt == 1)
{
Registry.level = 4;
winIt = 0;
FlxG.switchState(new GradStudentStage());

} else
{

nextClick.visible = false;//
}
}
if (winIt != 1)
{

nextClick.visible = false;//
} else
{

nextClick.visible = true;
}
}



//LEVEL 4 check
if (Registry.level == 4)
{
//Different condition for 2 cells
if (gcell3.distributionp == 0 && gcell5.distributionp == 0)
{
winIt = 1;
}

if (winIt == 1)
{

nextClick.visible = true;//
} else
{
nextClick.visible = false;
}


if (FlxG.overlap(mouseCon, nextClick) && FlxG.mouse.justPressed())
{

//win condition
if (winIt == 1)
{
Registry.level = 1;
FlxG.switchState(new GradStudentStage());

} else
{

nextClick.visible = false;//
}
}
if (winIt != 1)
{

nextClick.visible = false;//
} else
{

nextClick.visible = true;
}
}

//FlxG.log(Registry.level);
//trace("reg" + Registry.level);
super.update();



if (mouseCon.x != FlxG.mouse.x)
{
mouseCon.x = FlxG.mouse.x;
}
if (mouseCon.y != FlxG.mouse.y)
{
mouseCon.y = FlxG.mouse.y;
}

if (FlxG.keys.ONE)
{
Registry.level = 1;
FlxG.switchState(new GradStudentStage());

}
if (FlxG.keys.TWO)
{
Registry.level = 2;
FlxG.switchState(new GradStudentStage());

}
if (FlxG.keys.THREE)
{
Registry.level = 3;
FlxG.switchState(new GradStudentStage());

}
if (FlxG.keys.FOUR)
{
Registry.level = 4;
FlxG.switchState(new GradStudentStage());

}


} else
{

if (mouseCon.x != FlxG.mouse.x)
{
mouseCon.x = FlxG.mouse.x;
}
if (mouseCon.y != FlxG.mouse.y)
{
mouseCon.y = FlxG.mouse.y;
}



paused.update();
}



}


override public function destroy():void
{
// Important! Clear out the plugin, otherwise resources will get messed right up after a while
FlxSpecialFX.clear();
super.destroy();
}

//Example call back function. could be sound, or anything
public function dialogKill():void
{
//_player.kill();
//header.kill();
//headerTxt.kill();
}
//Snap to mouse
//Mouse snapping!
protected function Snap(Sprite1:FlxSprite,Sprite2:FlxSprite):void
{
if (Sprite1.x != Sprite2.x-12)
{
Sprite1.x = Sprite2.x-12;
}
if (Sprite1.y != Sprite2.y-10)
{
Sprite1.y = Sprite2.y - 10;
}

}

}
}


Any ideas? Thanks in advance!

4
help / Behave array!
« on: Wed, Sep 26, 2012 »
Ugh.

I need to get this array to behave. I have one that creates a row of 5 sprites to show off an example of some filters. That single row array looks like this:

Code: [Select]

coins = new Array();

for (var i:int = 0; i < 6; i ++)
{
coins[i] = new FilterCoin();
//coins[i].y = 100;
coins[i].x = 20 + (i * 128);
add(coins[i]);
coins[i].play("spin");


}

Now. What I want to do, is create a 4 height by 5 wide array of objets that are 64x64 each and I want them placed like this: The first one is placed manually, then the next one in the row is 64 pixels away and so on. And the object below it is also 64 pixels. Now I have something from an arcanoid and minesweeper example that places an array of objects in a grid. Here is that one:

Code: [Select]
var bx:int = 10;
var by:int = 30;

var brickColours:Array = [ 0xffd03ad1, 0xfff75352, 0xfffd8014, 0xffff9024, 0xff05b320, 0xff6d65f6 ];

for (var y:int = 0; y < 6; y++)
{
for (var x:int = 0; x < 20; x++)
{
var tempBrick:FlxSprite = new FlxSprite(bx, by);
tempBrick.velocity.y = 2;
tempBrick.makeGraphic(15, 15, brickColours[y]);
tempBrick.immovable = true;
bricks.add(tempBrick);
bx += 15;
}

bx = 10;
by += 15;
}

I'm able to tweak the one above just a little bit. But I don't really understand it. How can I get an array to do what I described?

Thanks in advance!


5
chat / Our own collaboration board, thread, thing?
« on: Tue, Aug 14, 2012 »
So, a couple of sites that I frequent have theirs. Yet I notice that a number of flixel users aren't on there. So I was wondering if we should start our own collaboration board to see if flixel users would want to work together? Especially since this is a pretty mellow site there might be some people wanting to work together on something. What does everybody else think?

6
chat / Trying to save memory with tile maps
« on: Sat, Jun 23, 2012 »
Hey guys!

I'm making a game with fairly large tile maps. From my experience, these take up a lot of memory. I've thought up of several ways to load maps but none of them are going to work I think.

Mostly because in the game, I want you to be able to ask: Can I lift a larg object, throw it from a distance, and it still hit a recycle object to generate cash with? I want to be able to say yes. But with the loading systems I've thought of I've not come up with a good solution.

However, I thought of something the other day.

Can I call collide on a tilemap, but just not draw it?

7
releases / Some Cool Filter Effects (from notsoftgames)
« on: Sun, Jun 17, 2012 »
Hey guys!

In most of my games, I want to be able to help the player figure out what to do by having an item or object that they can interact with glow. Now flash can do this. Flixel doesn't seem to play nicely with flash's filters. However, a conversation was going on on twitter and I noticed another game's screen shot. Now, I don't know if the game was a one shot deal or not, but I assumed that it was and asked the guy if he was going to open source it. He said no at first. But then not only provided the classes, but went the extra mile and provided a working code example in a playstate. How cool is that? He also said it was okay to post these here as well.

A brief explanation is that these classes extend flxsprite and flxtilemap. This also means that you can have them extend photonstorm's FlxExtendedSprite as well. How cool is that? Anyways, here's a playstated example with a registry source file thing going on.

There's only one or two small issues. When he sent me the example swf, it didn't work. When I compiled the code into flash develop, it ran fine. I also noticed that the sprites seemed to be cut off at the top and bottom. There's probably an easy fix for this and I'll or someone smarter will figure it out later. Other then that. Enjoy!

Quick link:
http://t.co/4o6lUxjE

Filter Sprite:
Code: [Select]
package
{
import flash.filters.BevelFilter;
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
import flash.filters.GlowFilter;
import flash.geom.Point;
import org.flixel.FlxSprite;

import org.flixel.plugin.photonstorm.*;
/**
* ...
* @author bignobody
*/
public class FilterSprite extends FlxExtendedSprite
{
//Static filters, so we use the same filters for every FilterSprite
public static var FILTERS:Array;
public static var FILTERPOINTS:Array;
// Some named indexes to make this a little more human friendly
public static var FILTER_COLOR:int = 0;
public static var FILTER_GLOW:int = 1;
public static var FILTER_BLUR:int = 2;
public static var FILTER_BEVEL:int = 3;

// the filters currently affecting this sprite.
protected var activeFilters:Array;
protected var activeFilterPoints:Array;


public function FilterSprite()
{
if (FilterSprite.FILTERS == null)
{
// if the filters don't exist yet, make 'em!
FilterSprite.initializeFilters();
}

// initialize the arrays
resetFilters();

super();
}

public static function initializeFilters():void
{
FILTERS = new Array();
FILTERPOINTS = new Array();

// For the colour filter, I'm just turning the brightness down 50%, but you can do lots of crazy cool stuff with this filter.
var bright:Number = 0.5;
var matrix:Array = new Array();
matrix = matrix.concat([bright, 0, 0, 0, 0]); // red
matrix = matrix.concat([0, bright, 0, 0, 0]); // green
matrix = matrix.concat([0, 0, bright, 0, 0]); // blue
matrix = matrix.concat([0, 0, 0, 1, 0]); // alpha

FILTERS[FILTER_COLOR] = new ColorMatrixFilter(matrix);
FILTERPOINTS[FILTER_COLOR] = new Point( 0, 0);

// make the rest of our filters
FILTERS[FILTER_GLOW] = new GlowFilter(0xffffff, 1.0, 16, 16, 2, 1, false, false);
FILTERPOINTS[FILTER_GLOW] = new Point( -8, -8);
FILTERS[FILTER_BLUR] = new BlurFilter(4, 4, 1);
FILTERPOINTS[FILTER_BLUR] = new Point( -2, -2);
FILTERS[FILTER_BEVEL] = new BevelFilter(4, 45, 0xffffff, 1, 0, 0.75, 4, 4, 1, 1, "inner", false);
FILTERPOINTS[FILTER_BEVEL] = new Point( 0, 0);

}

public function resetFilters():void
{
// dump any references to existing filters
activeFilters = new Array();
activeFilterPoints = new Array();
}

public function activateFilter(filterType:int):void
{
if (filterType > -1 && filterType < FilterSprite.FILTERS.length)
{
// add the requested filter to this sprites active filters
activeFilters[activeFilters.length] = FilterSprite.FILTERS[filterType];
activeFilterPoints[activeFilterPoints.length] = FilterSprite.FILTERPOINTS[filterType];
}
}

// here's the Flixel integration!
// framePixels is the Bitmapdata that we can apply flash filters to.
// framePixels gets updated whenever the FlxSprite changes frames, so it seems like the best time to apply our filters
override protected function calcFrame():void
{
super.calcFrame();
if (activeFilters.length > 0)
{
// loop through all filters active on this sprite and apply them to the frame.
for (var i:int = 0; i < activeFilters.length; i ++)
{
if (framePixels != null)
{
// Apparently this is the inefficient way (internal copying), but if you want to add a seperate bitmap and handle it yourself, be my guest :D
framePixels.applyFilter( framePixels, framePixels.generateFilterRect(framePixels.rect, activeFilters[i]), activeFilterPoints[i], activeFilters[i]);
}
}
}
}

}

}

FilterTileMap:
Code: [Select]
package
{
import org.flixel.FlxTilemap;

/**
* ...
* @author bignobody
*/
public class FilterTileMap extends FlxTilemap
{
//Static filters, so we use the same filters for every FilterTileMap
// Alternatively, you could make a static Filters class that held a bunch of filter instances and use them everywhere...
public static var FILTERS:Array;
public static var FILTERPOINTS:Array;
// Some named indexes to make this a little more human friendly
public static var FILTER_COLOR:int = 0;
public static var FILTER_GLOW:int = 1;
public static var FILTER_BLUR:int = 2;
public static var FILTER_BEVEL:int = 3;

// active filters for this tilemap
protected var activeFilters:Array;
protected var activeFilterPoints:Array;

public function FilterTileMap()
{
if (FilterTileMap.FILTERS == null)
{
FilterTileMap.initializeFilters();
}
super();
resetFilters();
}

public static function initializeFilters():void
{
FILTERS = new Array();
FILTERPOINTS = new Array();

// For the colour filter, I'm just turning the brightness down 50%, but you can do lots of crazy cool stuff with this filter.
var bright:Number = 0.5;
var matrix:Array = new Array();
matrix = matrix.concat([bright, 0, 0, 0, 0]); // red
matrix = matrix.concat([0, bright, 0, 0, 0]); // green
matrix = matrix.concat([0, 0, bright, 0, 0]); // blue
matrix = matrix.concat([0, 0, 0, 1, 0]); // alpha

FILTERS[FILTER_COLOR] = new ColorMatrixFilter(matrix);
FILTERPOINTS[FILTER_COLOR] = new Point( 0, 0);

// make the rest of our filters
FILTERS[FILTER_GLOW] = new GlowFilter(0xffffff, 1.0, 16, 16, 2, 1, false, false);
FILTERPOINTS[FILTER_GLOW] = new Point( -8, -8);
FILTERS[FILTER_BLUR] = new BlurFilter(4, 4, 1);
FILTERPOINTS[FILTER_BLUR] = new Point( -2, -2);
FILTERS[FILTER_BEVEL] = new BevelFilter(4, 45, 0xffffff, 1, 0, 0.75, 4, 4, 1, 1, "inner", false);
FILTERPOINTS[FILTER_BEVEL] = new Point( 0, 0);

}

public function resetFilters():void
{
// dump any references to existing filters
activeFilters = new Array();
activeFilterPoints = new Array();
}

public function activateFilter(filterType:int):void
{
if (filterType > -1 && filterType < FilterTileMap.FILTERS.length)
{
// add the requested filter to this sprites active filters
activeFilters[activeFilters.length] = FilterTileMap.FILTERS[filterType];
activeFilterPoints[activeFilterPoints.length] = FilterTileMap.FILTERPOINTS[filterType];
}
}

// Here's the Flixel integration!
// drawTileMap stamps the visible section of the tilemap to the buffer, so we want to apply our filters right after that happens.
override protected function drawTilemap(Buffer:FlxTilemapBuffer, Camera:FlxCamera):void
{

super.drawTilemap(Buffer, Camera);

applyActiveFilters();
}

protected function applyActiveFilters():void
{
// _buffers is an internal array of FlxTilemapBuffer objects, which has the pixels we're filtering
for (var i:int = 0; i < _buffers.length; i ++)
{
if (_buffers[i] != null)
{
for (var f:int = 0; f < activeFilters.length; f ++)
{
_buffers[i].pixels.applyFilter(_buffers[i].pixels, _buffers[i].pixels.generateFilterRect(_buffers[i].pixels.rect, activeFilters[f]), activeFilterPoints[f], activeFilters[f]);
}
}
}
}
}

}

Filter State:
Code: [Select]
package
{
import org.flixel.FlxState;

/**
* ...
* @author bignobody
*/
public class FilterTestState extends FlxState
{

private var coins:Array;

public function FilterTestState()
{
coins = new Array();

for (var i:int = 0; i < 6; i ++)
{
coins[i] = new FilterCoin();
coins[i].y = 100;
coins[i].x = 20 + (i * 128);
add(coins[i]);
coins[i].play("spin");
}

coins[1].activateFilter(FilterSprite.FILTER_GLOW);
coins[2].activateFilter(FilterSprite.FILTER_BEVEL);
coins[3].activateFilter(FilterSprite.FILTER_BLUR);
coins[4].activateFilter(FilterSprite.FILTER_COLOR);
coins[5].activateFilter(FilterSprite.FILTER_BLUR);
coins[5].activateFilter(FilterSprite.FILTER_BEVEL);
coins[5].activateFilter(FilterSprite.FILTER_GLOW);
}

}

}

The resource file, coin file, and it's main file are easily understandable. But there are those in a nutshell. Also be sure and thank notsoftgames when you use them. I'd sure he'd appreciate it. Here's where you can do that:

Notsoftgames site:
http://www.notsoftgames.com/

Notsoftgames twitter:
https://twitter.com/notsoftgames

8
releases / Simple Water Box Effect
« on: Sat, May 12, 2012 »
Hey there!

So I've been hunting around the net for a simple water thing to put in my game, and found a few, but none were compatable with flixel. I had giving up hope of finding anything, but then I remembered that photonstorms power tools had a sine wave effect. I thought it crazy, but I decided to try and hack it any way. I did some poking in the effects code, did some tweaking, and, it worked! It actually worked! Now, it's not real water. It won't drain into little particles or anything, but it has a wave effect going on that says, hey, this blue thing is water! Or it can be a red moving thing for lava. Anyways. To get the effect working, you need to:

Step 1: Get photonstorms power tools if you don't already have them! Seriously, they're great stuff! You can find them here: http://www.photonstorm.com/flixel-power-tools

Step 2: After you've added them to your flixel 2.55 project, if they aren't already in there, using flash develop, open the file sinewaveFx.as.

Step 3: After you've done that, modify the code you see to the one below, or just copy and paste it from here to your file:

Code: [Select]
/**
 * SineWaveFX - Special FX Plugin
 * -- Part of the Flixel Power Tools set
 *
 * v1.0 First release
 *
 * @version 1.0 - May 21st 2011
 * @link http://www.photonstorm.com
 * @author Richard Davey / Photon Storm
*/

package org.flixel.plugin.photonstorm.FX
{
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;

import org.flixel.*;
import org.flixel.plugin.photonstorm.*;

/**
* Creates a sine-wave effect through an FlxSprite which can be applied vertically or horizontally
*/
public class SineWaveFX extends BaseFX
{
private var waveType:uint;
private var waveVertical:Boolean;
private var waveLength:uint;
private var waveSize:uint;
private var waveFrequency:Number;
private var wavePixelChunk:uint;
private var waveData:Array;
private var waveDataCounter:uint = 0;
private var waveLoopCallback:Function;

public static const WAVETYPE_VERTICAL_SINE:uint = 0;
public static const WAVETYPE_VERTICAL_COSINE:uint = 1;
public static const WAVETYPE_HORIZONTAL_SINE:uint = 2;
public static const WAVETYPE_HORIZONTAL_COSINE:uint = 3;

public function SineWaveFX()
{
}

/**
* Creates a new SineWaveFX Effect from the given FlxSprite. The original sprite remains unmodified.<br>
* The resulting FlxSprite will take on the same width / height and x/y coordinates of the source FlxSprite.<br>
* For really cool effects you can SineWave an FlxSprite that is constantly updating (either through animation or an FX chain).
*
* @param source The FlxSprite providing the image data for this effect. The resulting FlxSprite takes on the source width, height, x/y positions and scrollfactor.
* @param type WAVETYPE_VERTICAL_SINE, WAVETYPE_VERTICAL_COSINE, WAVETYPE_HORIZONTAL_SINE or WAVETYPE_HORIZONTAL_COSINE
* @param size The size in pixels of the sine wave. Either the height of the wave or the width (for vertical or horizontal waves)
* @param length The length of the wave in pixels. You should usually set this to the width or height of the source image, or a multiple of it.
* @param frequency The frequency of the peaks in the wave. MUST BE AN EVEN NUMBER! 2, 4, 6, 8, etc.
* @param pixelsPerChunk How many pixels to use per step. Higher numbers make a more chunky but faster effect. Make sure source.width/height divides by this value evenly.
* @param updateFrame When this effect is created it takes a copy of the source image data and stores it. Set this to true to grab a new copy of the image data every frame.
* @param backgroundColor The background color (0xAARRGGBB format) to draw behind the effect (default 0x0 = transparent)
* @return An FlxSprite with the effect running through it, which should be started with a call to SineWaveFX.start()
*/
public function createFromFlxSprite(source:FlxSprite, type:uint, size:uint, length:uint, frequency:uint = 2, pixelsPerChunk:uint = 1, updateFrame:Boolean = false, backgroundColor:uint = 0x0):FlxSprite
{
var result:FlxSprite = create(source.pixels, source.x, source.y, type, size, length, frequency, pixelsPerChunk, backgroundColor);

updateFromSource = updateFrame;

if (updateFromSource)
{
sourceRef = source;
}

return result;
}

/**
* Creates a new SineWaveFX Effect from the given Class (which must contain a Bitmap).<br>
* If you need to update the source data at run-time then use createFromFlxSprite
*
* @param source The Class providing the bitmapData for this effect, usually from an Embedded bitmap.
* @param x The x coordinate (in game world pixels) that the resulting FlxSprite will be created at.
* @param y The x coordinate (in game world pixels) that the resulting FlxSprite will be created at.
* @param type WAVETYPE_VERTICAL_SINE, WAVETYPE_VERTICAL_COSINE, WAVETYPE_HORIZONTAL_SINE or WAVETYPE_HORIZONTAL_COSINE
* @param size The size in pixels of the sine wave. Either the height of the wave or the width (for vertical or horizontal waves)
* @param length The length of the wave in pixels. You should usually set this to the width or height of the source image, or a multiple of it.
* @param frequency The frequency of the peaks in the wave. MUST BE AN EVEN NUMBER! 2, 4, 6, 8, etc.
* @param pixelsPerChunk How many pixels to use per step. Higher numbers make a more chunky but faster effect. Make sure source.width/height divides by this value evenly.
* @param backgroundColor The background color in 0xAARRGGBB format to draw behind the effect (default 0x0 = transparent)
* @return An FlxSprite with the effect running through it, which should be started with a call to SineWaveFX.start()
*/
public function createFromClass(source:Class, x:int, y:int, type:uint, size:uint, length:uint, frequency:uint = 2, pixelsPerChunk:uint = 1, backgroundColor:uint = 0x0):FlxSprite
{
var result:FlxSprite = create((new source).bitmapData, x, y, type, size, length, frequency, pixelsPerChunk, backgroundColor);

updateFromSource = false;

return result;
}

/**
* Creates a new SineWaveFX Effect from the given bitmapData.<br>
* If you need to update the source data at run-time then use createFromFlxSprite
*
* @param source The bitmapData image to use for this effect.
* @param x The x coordinate (in game world pixels) that the resulting FlxSprite will be created at.
* @param y The x coordinate (in game world pixels) that the resulting FlxSprite will be created at.
* @param type WAVETYPE_VERTICAL_SINE, WAVETYPE_VERTICAL_COSINE, WAVETYPE_HORIZONTAL_SINE or WAVETYPE_HORIZONTAL_COSINE
* @param size The size in pixels of the sine wave. Either the height of the wave or the width (for vertical or horizontal waves)
* @param length The length of the wave in pixels. You should usually set this to the width or height of the source image, or a multiple of it.
* @param frequency The frequency of the peaks in the wave. MUST BE AN EVEN NUMBER! 2, 4, 6, 8, etc.
* @param pixelsPerChunk How many pixels to use per step. Higher numbers make a more chunky but faster effect. Make sure source.width/height divides by this value evenly.
* @param backgroundColor The background color in 0xAARRGGBB format to draw behind the effect (default 0x0 = transparent)
* @return An FlxSprite with the effect running through it, which should be started with a call to SineWaveFX.start()
*/
public function createFromBitmapData(source:BitmapData, x:int, y:int, type:uint, size:uint, length:uint, frequency:uint = 2, pixelsPerChunk:uint = 1, backgroundColor:uint = 0x0):FlxSprite
{
var result:FlxSprite = create(source, x, y, type, size, length, frequency, pixelsPerChunk, backgroundColor);

updateFromSource = false;

return result;
}

/**
* Internal function fed from createFromFlxSprite / createFromClass / createFromBitmapData
*
* @param source The bitmapData image to use for this effect.
* @param x The x coordinate (in game world pixels) that the resulting FlxSprite will be created at.
* @param y The x coordinate (in game world pixels) that the resulting FlxSprite will be created at.
* @param type WAVETYPE_VERTICAL_SINE, WAVETYPE_VERTICAL_COSINE, WAVETYPE_HORIZONTAL_SINE or WAVETYPE_HORIZONTAL_COSINE
* @param size The size in pixels of the sine wave. Either the height of the wave or the width (for vertical or horizontal waves)
* @param length The length of the wave in pixels. You should usually set this to the width or height of the source image, or a multiple of it.
* @param frequency The frequency of the peaks in the wave. MUST BE AN EVEN NUMBER! 2, 4, 6, 8, etc.
* @param pixelsPerChunk How many pixels to use per step. Higher numbers make a more chunky but faster effect. Make sure source.width/height divides by this value evenly.
* @param backgroundColor The background color in 0xAARRGGBB format to draw behind the effect (default 0x0 = transparent)
* @return An FlxSprite with the effect running through it, which should be started with a call to SineWaveFX.start()
*/
private function create(source:BitmapData, x:int, y:int, type:uint, size:uint, length:uint, frequency:uint = 2, pixelsPerChunk:uint = 1, backgroundColor:uint = 0x0):FlxSprite
{
if (type == WAVETYPE_VERTICAL_SINE || type == WAVETYPE_VERTICAL_COSINE)
{
waveVertical = true;

if (pixelsPerChunk >= source.width)
{
throw new Error("SineWaveFX: pixelsPerChunk cannot be >= source.width with WAVETYPE_VERTICAL");
}
}
else if (type == WAVETYPE_HORIZONTAL_SINE || type == WAVETYPE_HORIZONTAL_COSINE)
{
waveVertical = false;

if (pixelsPerChunk >= source.height)
{
throw new Error("SineWaveFX: pixelsPerChunk cannot be >= source.height with WAVETYPE_HORIZONTAL");
}
}

updateWaveData(type, size, length, frequency, pixelsPerChunk);

// The FlxSprite into which the sine-wave effect is drawn

if (waveVertical)
{
sprite = new FlxSprite(x, y).makeGraphic(source.width, source.height/2 + (waveSize * 3), backgroundColor);
}
else
{
sprite = new FlxSprite(x, y).makeGraphic(source.width + (waveSize * 3), source.height/2, backgroundColor);
}

// The scratch bitmapData where we prepare the final sine-waved image
canvas = new BitmapData(sprite.width, sprite.height, true, backgroundColor);

// Our local copy of the sprite image data
image = source.clone();

clsColor = backgroundColor;
clsRect = new Rectangle(0, 0, canvas.width, canvas.height);

copyPoint = new Point(0, 0);

if (waveVertical)
{
copyRect = new Rectangle(0, 0, wavePixelChunk, image.height);
}
else
{
copyRect = new Rectangle(0, 0, image.width, wavePixelChunk);
}

active = true;

return sprite;
}

/**
* Update the SineWave data without modifying the source image being used.<br>
* This call is fast enough that you can modify it in real-time.
*
* @param type WAVETYPE_VERTICAL_SINE, WAVETYPE_VERTICAL_COSINE, WAVETYPE_HORIZONTAL_SINE or WAVETYPE_HORIZONTAL_COSINE
* @param size The size in pixels of the sine wave. Either the height of the wave or the width (for vertical or horizontal waves)
* @param length The length of the wave in pixels. You should usually set this to the width or height of the source image, or a multiple of it.
* @param frequency The frequency of the peaks in the wave. MUST BE AN EVEN NUMBER! 2, 4, 6, 8, etc.
* @param pixelsPerChunk How many pixels to use per step. Higher numbers make a more chunky but faster effect. Make sure source.width/height divides by this value evenly.
*/
public function updateWaveData(type:uint, size:uint, length:uint, frequency:uint = 2, pixelsPerChunk:uint = 1):void
{
if (type > WAVETYPE_HORIZONTAL_COSINE)
{
throw new Error("SineWaveFX: Invalid WAVETYPE");
}

if (FlxMath.isOdd(frequency))
{
throw new Error("SineWaveFX: frequency must be an even number");
}

waveType = type;
waveSize = uint(size * 0.5);
waveLength = uint(length / pixelsPerChunk);
waveFrequency = frequency;
wavePixelChunk = pixelsPerChunk;
waveData = FlxMath.sinCosGenerator(waveLength, waveSize, waveSize, waveFrequency);

if (waveType == WAVETYPE_VERTICAL_COSINE || waveType == WAVETYPE_HORIZONTAL_COSINE)
{
waveData = FlxMath.getCosTable();
}
}

/**
* Use this to set a function to be called every time the wave has completed one full cycle.<br>
* Set to null to remove any previous callback.
*
* @param callback The function to call every time the wave completes a full cycle (duration will vary based on waveLength)
*/
public function setLoopCompleteCallback(callback:Function):void
{
waveLoopCallback = callback;
}

/**
* Called by the FlxSpecialFX plugin. Should not be called directly.
*/
public function draw():void
{
if (ready)
{
if (lastUpdate != updateLimit)
{
lastUpdate++;

return;
}

if (updateFromSource && sourceRef.exists)
{
image = sourceRef.framePixels;
}

canvas.lock();
canvas.fillRect(clsRect, clsColor);

var s:uint = 0;

copyRect.x = 0;
copyRect.y = 0;

if (waveVertical)
{
for (var x:int = 0; x < image.width; x += wavePixelChunk)
{
copyPoint.x = x;
copyPoint.y = waveSize + (waveSize / 2) + waveData[s];

canvas.copyPixels(image, copyRect, copyPoint);

copyRect.x += wavePixelChunk;

s++;
}
}
else
{
for (var y:int = 0; y < image.height; y += wavePixelChunk)
{
copyPoint.x = waveSize + (waveSize / 2) + waveData[s];
copyPoint.y = y;

canvas.copyPixels(image, copyRect, copyPoint);

copyRect.y += wavePixelChunk;

s++;
}
}

// Cycle through the wave data - this is what causes the image to "undulate"
var t:Number = waveData.shift();
waveData.push(t);

waveDataCounter++;

if (waveDataCounter == waveData.length)
{
waveDataCounter = 0;

if (waveLoopCallback is Function)
{
waveLoopCallback.call();
}
}

canvas.unlock();

lastUpdate = 0;

sprite.pixels = canvas;
sprite.dirty = true;
}
}

public function toString():String
{
var output:Array = [ "Type: " + waveType, "Size: " + waveSize, "Length: " + waveLength, "Frequency: " + waveFrequency, "Chunks: " + wavePixelChunk, "clsRect: " + clsRect ];

return output.join(",");
}

}

}



Tip: So, what did I change? Compare this one to the original. All I did was find out where photonstorm was calculating the math to pull off the effect. Apparently, he's using the height of the flxsprite class to do so. So what to do? Divide it by 2 so only the top half of the sprite gets the sinewave effect applied to it. Couldn't be simpler!

Step 4: To get the effect in your game, just do the following for a simple sprite that doesn't rely on an embedded image:

Code: [Select]
//First off, don't forget to import them!
import org.flixel.plugin.photonstorm.*;
import org.flixel.plugin.photonstorm.FX.*;

//Call the effects private variables
private var sinewave:SineWaveFX;
private var wibbleWobble:FlxSprite;
//Want more then one? Then you have to name it sinewave2,wibbleWobble2, etc.

//Put this in your create structure
// Get a sinewave effect from FlxSpecialFX
sinewave = FlxSpecialFX.sineWave();

var pic:FlxSprite = new FlxSprite(224, 320, null); // AssetsRegistry.overdoseEyePNG);
//if you don't want to use a png, add the next line like I do. It makes a flxSprite instead
pic = new FlxSprite(224, 320 + 8, null).makeGraphic(32, 32, 0xff0000FF);

wibbleWobble = sinewave.createFromFlxSprite(pic, SineWaveFX.WAVETYPE_VERTICAL_SINE, pic.height/4, pic.width);
wibbleWobble.alpha =  0.85;
//You don't have to add alpha if you want. but yes, you do have to add it to the wibbleWobble to get it to work
sinewave.start();
add(wibbleWobble);

//And that's it!

And there you have it! Easy as that! If you want lava, color it red and add the glow effect that I outline, then add some particles coming off it. It's a flxsprite so it should allow for collisions too. I'll test it and let you know. So, there you go, very simple water. It won't break up into particles or anything fancy but it will get the look done.

Enjoy!

9
releases / Lightning class [CAUTION!]
« on: Wed, May 9, 2012 »
So I was looking to post cool effects into my game, and I found an old one that was built for 2.35. The result in the old version, is if you click the mouse, a constrant stream of varied lightning bolts flicker from the center of the screen to the mouse button. It looked really cool, and with the help of wg/funstorm I was able to get it to work. Sort of. The 2.55 version only streams a single lightning bolt fromt he screen center to the mouse, and to get it to stream again you have to click again. It'd be cool if someone would try and tweak it to the original specs, that'd be awesome, but anyways, enough ramble.

Here's the Lightning Class. Put it in your game folder (src, com, whatever your style is):
Code: [Select]
package com
{
import flash.display.BitmapData;
import flash.geom.Matrix;
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;
import flash.display.Shape;
import flash.filters.GlowFilter;


public class Lightning extends FlxSprite
{
private var radius:Number = 1;
private var visibleDuration:Number = .25;
private var visibleTimer:Number;
private var targetX:int;
private var targetY:int;

public function Lightning():void
{
super();
solid = false;
this.kill();
}

public function SetTarget(Target:FlxPoint):void
{
targetX = Target.x;
targetY = Target.y;

}

override public function update():void
{
visibleTimer -= FlxG.elapsed;

if (visibleTimer <= 0)
this.kill();
super.update();
}

override public function draw():void
{
var canvas:Shape = new Shape();
var scrollX:int = FlxG.camera.scroll.x;
var scrollY:int = FlxG.camera.scroll.y;
if (Math.random() < .8)
{
var boltOrigin:FlxPoint = new FlxPoint(FlxG.mouse.screenX, FlxG.mouse.screenY)
var dx:int = boltOrigin.x - (targetX+scrollX);
var dy:int = boltOrigin.y - (targetY+scrollY);
var dist:int = int(Math.sqrt (dx * dx + dy * dy));
var radians:Number = Math.atan2 (dy, dx);
var theAngle:Number = radians * 180 / Math.PI;
//canvas.graphics.clear();
canvas.graphics.lineStyle(2, 0xffffff);
canvas.graphics.moveTo (boltOrigin.x, boltOrigin.y);

var traveled:Number = 0;
var linethickness:Number = 3;
var alpha:Number = 0;
var timer:Number = 20;
while (traveled < dist - 10)
{
var speed:Number = Math.random()*2 + 30;
var tmpAngle:Number = theAngle * Math.PI / 180;
var bx:int = traveled * Math.cos (tmpAngle);
var by:int = traveled * Math.sin (tmpAngle);
traveled += speed;
var theX:Number = (boltOrigin.x - bx) + Math.random () * 25 - 13;
var theY:Number = (boltOrigin.y - by) + Math.random () * 25 - 13;

canvas.graphics.lineStyle (linethickness, 0xFFFFFF, 1);
canvas.graphics.lineTo (theX, theY);
linethickness -= 1;
alpha += .25;
}
canvas.graphics.lineTo (targetX+scrollX, targetY+scrollY);
canvas.graphics.endFill();
var glow:GlowFilter = new GlowFilter;
glow.color = 0x3333FF;
glow.strength = 6;
glow.blurX = 24;
glow.blurY = 24;
canvas.filters = [glow];
        FlxG.camera.buffer.draw(canvas, null, null, "screen");


}

}

public function strike(X:int, Y:int):void
{
this.x = X;
this.y = Y;
this.exists = true;
this.alive = false;
visibleTimer = visibleDuration;
}
}
}

Playstate use example:
Code: [Select]
package com
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;

public class Tribute extends FlxState
{


[Embed(source = '../../data/crosshairs.png')]private var ImgCursor:Class;
public var bolt:Lightning;


override public function create():void
{
FlxG.mouse.show(ImgCursor);

}

override public function update():void
{


//The pause menu is popped up here


super.update();

if (FlxG.mouse.justPressed())
{
bolt = add(new Lightning()) as Lightning;
var target:FlxPoint = new FlxPoint(FlxG.width / 2, FlxG.height / 2);
bolt.SetTarget(target);
bolt.strike(target.x, target.y);

}


}



}
}


That should work straight out of the box. Also, I'm not the original author of the 2.35 version. I just needed help porting it over. So if you are the original author and you do read this then THANK YOU!

All righty.

Enjoy!

10
help / Buffering Lightning?
« on: Tue, May 8, 2012 »
Hey guys!

I was rummaging through my folders and found an example that someone did as to how to have a neat lightning effect in your game. So I thought I'd try and port it over to 2.55 to see if there was anything wrong with it. There was only one or two things that were easy but I came across this line:

Code: [Select]
FlxG.buffer.draw(canvas, null, null, "screen");

Now 2.55 doesn't have that so I was wondering what in 2.55 would allow me to do something like that?

Here's the rest of the class:
Code: [Select]
package com
{
import flash.display.BitmapData;
import flash.geom.Matrix;
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;
import flash.display.Shape;
import flash.filters.GlowFilter;


public class Lightning extends FlxExtendedSprite
{
private var radius:Number = 1;
private var visibleDuration:Number = .25;
private var visibleTimer:Number;
private var targetX:int;
private var targetY:int;

public function Lightning():void
{
super();
solid = false;
this.kill();
}

public function SetTarget(Target:FlxPoint):void
{
targetX = Target.x;
targetY = Target.y;

}

override public function update():void
{
visibleTimer -= FlxG.elapsed;

if (visibleTimer <= 0)
this.kill();
super.update();
}

override public function draw():void
{
var canvas:Shape = new Shape();
var scrollX:int = 0;
var scrollY:int = 0;
if (Math.random() < .8)
{
var boltOrigin:FlxPoint = new FlxPoint(FlxG.mouse.screenX, FlxG.mouse.screenY)
var dx:int = boltOrigin.x - (targetX+scrollX);
var dy:int = boltOrigin.y - (targetY+scrollY);
var dist:int = int(Math.sqrt (dx * dx + dy * dy));
var radians:Number = Math.atan2 (dy, dx);
var theAngle:Number = radians * 180 / Math.PI;
//canvas.graphics.clear();
canvas.graphics.lineStyle(2, 0xffffff);
canvas.graphics.moveTo (boltOrigin.x, boltOrigin.y);

var traveled:Number = 0;
var linethickness:Number = 3;
var alpha:Number = 0;
var timer:Number = 20;
while (traveled < dist - 10)
{
var speed:Number = Math.random()*2 + 30;
var tmpAngle:Number = theAngle * Math.PI / 180;
var bx:int = traveled * Math.cos (tmpAngle);
var by:int = traveled * Math.sin (tmpAngle);
traveled += speed;
var theX:Number = (boltOrigin.x - bx) + Math.random () * 25 - 13;
var theY:Number = (boltOrigin.y - by) + Math.random () * 25 - 13;

canvas.graphics.lineStyle (linethickness, 0xFFFFFF, 1);
canvas.graphics.lineTo (theX, theY);
linethickness -= 1;
alpha += .25;
}
canvas.graphics.lineTo (targetX+scrollX, targetY+scrollY);
canvas.graphics.endFill();
var glow:GlowFilter = new GlowFilter;
glow.color = 0x3333FF;
glow.strength = 6;
glow.blurX = 24;
glow.blurY = 24;
canvas.filters = [glow];
FlxG.buffer.draw(canvas, null, null, "screen");



}

}

public function strike(X:int, Y:int):void
{
this.x = X;
this.y = Y;
this.exists = true;
this.alive = false;
visibleTimer = visibleDuration;
}
}
}

Very little is changed from the original except for the draw function and I'm having it extend FlxExtendedSprite instead. I don't know where else I would find that or what it's been changed too. I just thought this'd be real neat to have in something.

Thanks in advance!

(i didn't write the original and i forgot where it came from, it's originally for 2.35)

11
releases / Custom FlxPause
« on: Wed, May 2, 2012 »
So this has popped up on the forums here and there and I needed one for my current game I'm doing. So I decided to write a quick pause class. Place it in your org folder where the rest of flixel is and add it to the playstate like this:

Class:
Code: [Select]
package org.flixel
{

import org.flixel.*;


public class FlxPaused extends FlxGroup
{


/**
* Background rect for the text
*/
private var _bg:FlxSprite;

/**
* The text field used to display the text
*/
private var _field:FlxText;

/**
* Use this to tell if dialog is showing on the screen or not.
*/
public var showing:Boolean;

internal var _displaying:Boolean;

/**
 * Called when dialog is finished (optional)
 */
private var _finishCallback:Function;


public function FlxPaused()
{


_bg = new FlxSprite(88,56).makeGraphic(420, 72, 0xff808080);
_bg.scrollFactor.x = _bg.scrollFactor.y = 0;
add(_bg);

_field = new FlxText(_bg.x,_bg.y+16, 410, "Paused");
_field.setFormat(null, 12, 0xff00FFFF, "center");
_field.scrollFactor.x = _field.scrollFactor.y = 0;
add(_field);

}

/**
* Call this from your code to display some dialog
*/
public function showPaused():void
{
_displaying = true;
showing = true;
}

/**
* The meat of the class. Used to display text over time as well
* as control which page is 'active'
*/
override public function update():void
{
if (_displaying)
{
{
_field.text = "Paused";
}
if(FlxG.keys.SPACE)
{
this.kill();
this.exists = false;
showing = false;
_displaying = false;
if (_finishCallback != null) _finishCallback();

}
else
{

showing = true;
_displaying = true;

}

super.update();
}
}

/**
* Called when the dialog is completely finished
*/
public function set finishCallback(val:Function):void
{
_finishCallback = val;
}

}
}

Playstate with callback example:
Code: [Select]
package com
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;
import com.*;


//DAME FILE ALLOCATION

public class Tribute extends FlxState
{

[Embed(source = '../pics/RedRacer.png')] public static var RedRacer:Class;
[Embed(source = '../../data/ball.png')] private var ImgBall:Class;

public var _player:player;

//DAME
private var coinsGroup:FlxGroup = null;
private var level:BaseLevel;
private var camera:FlxCamera;
public static var elapsedTime:Number = 0;
private static var lastTime:uint = 0;

//Player UI
//Status Bars
public var fuelBar:FlxSprite;
public var powerBar:FlxSprite;
public  var powerLimit:int = 0;

//Pause Test
public var paused:FlxPaused;

//DAME INPUT
//Box2d objects should follow the same structure if they are to be placed in
//a DAME project.
protected function onSpriteAddedCallback(sprite:FlxSprite, group:FlxGroup):void
{
if (sprite is Coin)
{
coinsGroup = group;
}
}

override public function create():void
{
FlxG.bgColor = 0xff0000FF;

//DAME INPUT
level = new Level_dummy(true, onSpriteAddedCallback);
camera = new FlxCamera(0, 0, FlxG.width, FlxG.height);
FlxG.resetCameras(camera);
camera.follow(_player, FlxCamera.STYLE_PLATFORMER);
FlxG.worldBounds = new FlxRect(level.mainLayer.x, level.mainLayer.y, level.mainLayer.width, level.mainLayer.height);

FlxG.camera.follow(_player, FlxCamera.STYLE_PLATFORMER);

_player = new player(120, 120);
add(_player);


//Player GUI to be created above everything else to be visible
//the weapon cool down bar
powerBar = new FlxSprite(32,38);
powerBar.makeGraphic(1,4,0xff4DFDFC); //The yellow bar itself
powerBar.scrollFactor.x = powerBar.scrollFactor.y = 0;
powerBar.origin.x = powerBar.origin.y = 0; //Zero out the origin
powerBar.scale.x = 20;
add(powerBar);


//To be on top of everything else
paused = new FlxPaused;
//add(paused);
}

override public function update():void
{
//The pause menu is popped up here
if (!paused.showing)
{


super.update();



//DAME MAP COLLISIONS
FlxG.collide(level.mainLayer, _player);
FlxG.collide(level.mainLayer, coinsGroup);


FlxG.camera.follow(_player);
FlxG.worldBounds = new FlxRect(0, 0, 640, 480);
FlxG.camera.bounds = new FlxRect(0, 0, 640, 480);
//FlxG.camera.bounds(0, 0, level.boundsMaxX, level.boundsMaxY);


FlxG.debug = true;
FlxG.visualDebug = true;

//Something to pause with
if (FlxG.keys.P)
{
//paused.showPaused();
paused = new FlxPaused;
paused.showPaused();
paused.finishCallback = dialogKill;
add(paused);
}


} else
{
paused.update();

}

}
//Example call back function. could be sound, or anything
public function dialogKill():void
{
_player.kill();
//header.kill();
//headerTxt.kill();
}




}
}

Enjoy!

12
help / Custom FlxPause[SOLVED]
« on: Wed, May 2, 2012 »
Hey guys!

I've been trying to write a pause class for the game.  I am able to get the pause to show, pause the game, and then unpause the game. The problem lies in the pause message itself. It's supposed to go away but it's not doing that. If I call kill on the group, then it goes away once, but doesn't show up again. It's based on the FlxDialog class that I posted earlier to help someone else that Paala worked on a bit. The playstate is pretty simple so I'll add it too. Any ideas on what I'm not doing?

Playstate
Code: [Select]
package com
{
import org.flixel.*;
import org.flixel.plugin.photonstorm.*;
import com.*;
import flash.utils.getTimer;

//DAME FILE ALLOCATION
/**
* When reimporting, use the following file structure in Level_dummy:
* [Embed(source="../../data/mapCSV_Game_Map2.csv", mimeType="application/octet-stream")] public var CSV_GameMap2:Class;
* Say yes to a file has been modified externally
* Change ball class to coin class
*
* The coin class mentioned in the level dummy mirrors the coin class
* in the com folder. So any coin placed in the dame stage will behave
* exactly like the coin in the com folder.
*
* DONE: Unable to add box2d
* DONE: Add level bounds
*
* TODO: NOTE: If I want Mike to pick up anything, it must be made outside of DAME
*/
public class Tribute extends FlxState
{

[Embed(source = '../pics/RedRacer.png')] public static var RedRacer:Class;
[Embed(source = '../../data/ball.png')] private var ImgBall:Class;

public var _player:player;

//DAME
private var coinsGroup:FlxGroup = null;
private var level:BaseLevel;
private var camera:FlxCamera;
public static var elapsedTime:Number = 0;
private static var lastTime:uint = 0;

//Player UI
//Status Bars
public var fuelBar:FlxSprite;
public var powerBar:FlxSprite;
public  var powerLimit:int = 0;

//Pause Test
public var paused:FlxPaused;

//DAME INPUT
//Box2d objects should follow the same structure if they are to be placed in
//a DAME project.
protected function onSpriteAddedCallback(sprite:FlxSprite, group:FlxGroup):void
{
if (sprite is Coin)
{
coinsGroup = group;
}
}

override public function create():void
{
FlxG.bgColor = 0xff0000FF;

//DAME INPUT
level = new Level_dummy(true, onSpriteAddedCallback);
camera = new FlxCamera(0, 0, FlxG.width, FlxG.height);
FlxG.resetCameras(camera);
camera.follow(_player, FlxCamera.STYLE_PLATFORMER);
FlxG.worldBounds = new FlxRect(level.mainLayer.x, level.mainLayer.y, level.mainLayer.width, level.mainLayer.height);

FlxG.camera.follow(_player, FlxCamera.STYLE_PLATFORMER);

_player = new player(120, 120);
add(_player);


//Player GUI to be created above everything else to be visible
//the weapon cool down bar
powerBar = new FlxSprite(32,38);
powerBar.makeGraphic(1,4,0xff4DFDFC); //The yellow bar itself
powerBar.scrollFactor.x = powerBar.scrollFactor.y = 0;
powerBar.origin.x = powerBar.origin.y = 0; //Zero out the origin
powerBar.scale.x = 20;
add(powerBar);


//To be on top of everything else
paused = new FlxPaused;
//add(paused);
}

override public function update():void
{
//The pause menu is popped up here
if (!paused.showing)
{


super.update();



//DAME MAP COLLISIONS
FlxG.collide(level.mainLayer, _player);
FlxG.collide(level.mainLayer, coinsGroup);


FlxG.camera.follow(_player);
FlxG.worldBounds = new FlxRect(0, 0, 640, 480);
FlxG.camera.bounds = new FlxRect(0, 0, 640, 480);
//FlxG.camera.bounds(0, 0, level.boundsMaxX, level.boundsMaxY);


FlxG.debug = true;
FlxG.visualDebug = true;

//Something to pause with
if (FlxG.keys.P)
{
//paused.showPaused();
//paused = new FlxPaused;
paused.showPaused();
add(paused);
}


} else
{
paused.update();

}

}
//Example call back function. could be sound, or anything
public function dialogKill():void
{

//header.kill();
//headerTxt.kill();
}




}
}


FlxPaused
Code: [Select]
package org.flixel
{

import org.flixel.*;


public class FlxPaused extends FlxGroup
{


/**
* Background rect for the text
*/
private var _bg:FlxSprite;

/**
* The text field used to display the text
*/
private var _field:FlxText;

/**
* Use this to tell if dialog is showing on the screen or not.
*/
public var showing:Boolean;

internal var _displaying:Boolean;




public function FlxPaused()
{


_bg = new FlxSprite(88,56).makeGraphic(420, 72, 0xff808080);
_bg.scrollFactor.x = _bg.scrollFactor.y = 0;
add(_bg);

_field = new FlxText(_bg.x,_bg.y+16, 410, "Paused");
_field.setFormat(null, 12, 0xff00FFFF, "center");
_field.scrollFactor.x = _field.scrollFactor.y = 0;
add(_field);

}

/**
* Call this from your code to display some dialog
*/
public function showPaused():void
{
_displaying = true;
showing = true;
}

/**
* The meat of the class. Used to display text over time as well
* as control which page is 'active'
*/
override public function update():void
{
if (_displaying)
{
{
_field.text = "Paused";
}
if(FlxG.keys.SPACE)
{
this.kill();
showing = false;
_displaying = false;
}
else
{

showing = true;
_displaying = true;

}


super.update();
}
}

}
}

Thanks in advance!

13
help / Using Tiled Map Editor
« on: Sat, Apr 28, 2012 »
I've been looking at using Tiled for my next game because it seems pretty stable. Anyways, I found a tutorial on lithander's blog detailing how to do so here:

http://pixelpracht.wordpress.com/2010/03/31/flash-tmx-parser/

However, when I run the project and hit enter, I'm given an Stream error on the tmx. Has anyone else gotten this to work properly and if so what did you do?

Thanks in advance!

14
help / Getting pc to slowly clear a board
« on: Sat, Apr 14, 2012 »
Hey guys!

So I've been trying to add ai to a minesweeper code. I've had some successes with it, and I'm getting it to clear an entire board, but I don't want that. Sure I want the flood fill for empty spaces to work, but it shouldn't work for the whole thing.

Here's what I mean:

http://www.swfcabin.com/open/1334444127

First, the text box that has numbers on it, click it to give it focus, then hit Enter, then hit space to be taken to the playfield.

It's minesweeper, and the player is supposed to go back and forth with the cpu to see who clceared their board first or who hit three mines first. Right now, only the player can play like their supposed to. If you play right now, the cpu will clear it's board in one go. I don't want that.

Here's what I use currently for the pc:
Code: [Select]
var pcsTurn:Boolean;
pcsTurn = true;
/**
* Player checking way method
*/
if (pcsTurn == true)
{
for each (var uzone:Zone in boardGroup2.members)
{if (boardGroup2.getRandom()) {
if (!uzone.liveMine) {
if(uzone.hidden){
if (uzone.mineNum == 0) {
fillFlood2(uzone);
boardSpaces2--;

}else {
uzone.updateText();
boardSpaces2--;

}
}
}else {

uzone.graphic.color = 0xffFF0000;

//FlxG.switchState(new EndState(false));
}
}
}
}


Any ideas on how I can get this to pick one piece at a time and clear the board naturally like a player would?

Thanks in advance!

15
So I'm using the FlxInputText as found here:

http://forums.flixel.org/index.php/topic,272.0.html

I know there are some fixes around here but I don't know if they'll fix my problem. Notice the input box here:

http://www.majhost.com/gallery/rob/Friends/deminedscn1.png

Is in the same position on the next frame here:

http://www.majhost.com/gallery/rob/Friends/deminedscn2.png

I am calling kill and destroy on the previous frame. But it still floats around.

How do make sure the input box is cleared after a state change?

(if your wondering about the grid, you can follow it here: http://forums.tigsource.com/index.php?topic=25333.0 )

I'll look around the forums here some, but I don't know if the fixes are going to help my specific problem.

Thanks in advance!

16
help / Need help with some Mumbo Jumbo code
« on: Sat, Mar 31, 2012 »
Hey all. I'm picking through a Minesweeper code here on the forums and have come across something that I'm trying to interpet. Basically I'm trying to figure out why he does this:

Code: [Select]
//his way

for (var y:int = 1; y <= boardSize; y++) { // y positions
for (var x:int = 1; x <= boardSize; x++) { // x positions
var zone:Zone = new Zone(((x-1) * 13) + 2, ((y - 1) * 13) + 2); // create zone
zone.place[0] = x; // set board x location
zone.place[1] = y; // set board y location

boardGroup.add(zone); // add zone to the board

}
}


And not something like this:

Code: [Select]
//My Test
for (var y2:int = 1; y2 <= boardSize2; y2++) { // y positions
for (var x2:int = 1; x2 <= boardSize2; x2++) { // x positions
var zone2:Zone = new Zone(216, 2); // create zone
zone2.place[0] = x2; // set board x location
zone2.place[1] = y2; // set board y location

boardGroup2.add(zone2); // add zone to the board

}
}


What that does, is create  a 10x10 array of boxes that create a board. In my test, I don't use some long, convuluted equation to set down the zone. However, this has the problem of creating only one graphic. What I want to know is why he does that and, isn't 1(x) -1 = 0? What's going on here?

Thanks in advance!

17
chat / Flixel rope?
« on: Wed, Feb 29, 2012 »
I've been looking around for a while and I've found a few examples. The MouseSpring in Photonstorms powertools seems ideal to tweak but I don't know how I'd go about doing it. Has anyone done any ropes in their games? Any suggestions? Ideas?

18
help / Count down to 0 problem {SOLVED(?)}
« on: Sun, Feb 26, 2012 »
Hi there! Since I used this set of objects a lot in my projects, I figured I'd just go ahead and make them a class on their own, so I did:

Code: [Select]
package
{

import org.flixel.*;

public class FlxCounter extends FlxGroup
{
public var tickerType1:Boolean;
public var tickerType2:Boolean;

//The ticker slots
public var min1:Number=0;
public var min2:Number=0;
public var sec1:Number=0;
public var sec2:Number=0;
public var minsec:Number=0;
public var font:Number=0;

//The ticker text
public var min1Txt:FlxText;
public var min2Txt:FlxText;
public var colon:FlxText;
public var secA:FlxText;
public var secB:FlxText;

public var countDirection:Boolean

/**
* A basic digital clock class
* @param X
* @param Y
* @param 0
* @param 0
* @param 0
* @param 0
*/

public function FlxCounter(MainX:int, MainY:int,min1:Number,min2:Number,sec1:Number,sec2:Number,font:Number)
{
//Minutes slot 1
min1Txt = new FlxText(MainX,  MainY, 46, min1.toString());
min1Txt.setFormat(null, font, 0xffFB00FB, "left");
//add(min1Txt);

//Minutes slot 2
min2Txt = new FlxText(MainX+8,  MainY, 46, min2.toString());
min2Txt.setFormat(null, font, 0xffFB00FB, "left");
add(min2Txt);

//colon
colon = new FlxText(MainX+22, MainY, 32, ":");
colon.setFormat(null, font, 0xffFB00FB, "left");
add(colon);

//Seconds1
secA = new FlxText(MainX+26, MainY, 46, sec1.toString());
secA.setFormat(null, font, 0xffFB00FB, "left");
add(secA);

    //Seconds2
secB = new FlxText(MainX+38, MainY, 46, sec2.toString());
secB.setFormat(null,font, 0xffFB00FB, "left");
add(secB);

}

override public function update():void
{
//Count up
if (countDirection == true)
{
//Tweak the number multiplied for testing
minsec += FlxG.elapsed*2;
//game length
//Timer
//Seconds slot 1
if (minsec >= 1)
{
minsec = 0;
sec2 += 1;
secB.text = sec2.toString();
}
//Seconds slot 2
if (sec2 >= 10)
{
sec2 = 0;
sec1 += 1;
secB.text = sec2.toString();
secA.text = sec1.toString();
}
//Minute slot 1
if (sec1 == 5 && sec2 == 9)
{
sec2 = 0;
sec1 = 0;

min1 += 1;

secB.text = sec2.toString();
secA.text = sec1.toString();
min2Txt.text = min1.toString();
}
}

if (countDirection == false)
{
//count down
minsec += FlxG.elapsed*2;
//game length
//Timer
//Seconds slot 1
if (minsec >= 1)
{
minsec = 0;
sec2 -=1;
secB.text = sec2.toString();
}
//Seconds slot 2
if (sec2 >= 10)
{
sec2 = 0;
sec1 += 1;
secB.text = sec2.toString();
secA.text = sec1.toString();
}
//Minute slot 1
if (sec1 == 5 && sec2 == 9)
{
sec2 = 0;
sec1 = 0;

min1 += 1;

secB.text = sec2.toString();
secA.text = sec1.toString();
min2Txt.text = min1.toString();
}
}

super.update();
}

}
}

So the problem arises in the count down boolean. The result is insteaed of the numbers going 9,8,7,6 etc, like, I'd expect them to. It goes -1,-2,-3,-4 etc instead.

What can I do to make them properly subtract? Is there something I'm missing?

Thanks in advance!

19
help / Different project old problem
« on: Mon, Jan 23, 2012 »
So, I've come to the point where I want to add a couple sounds to the game to let the player know they have selected something. I've got a fake underlying sprite set up as a select spot, a mouse icon, and a visual selecting cursor that show over the fake sprite as well. Now, I want the sound to play just once when the mouse is overlapping the select spot. So here I go and code this:

Code: [Select]
if (FlxG.overlap(ph1, mouseCon))
{
selector.x = ph1.x;
selector.y = ph1.y;
FlxG.play(SndSlide, 0.55, false);
}

The problem? The sound just doesn't play once. It continuosly plays. One way I solved this was by implementing FlashPunk into a project. But I'm sure that's not the best solution. Any ideas for this one?

Thanks in advance!

20
help / Need some help with a gem slide mechanic
« on: Sun, Jan 15, 2012 »
Hey there!

Over the past week or two I've been trying to port an old click game I made to Flixel. It's been very successful. But the reason I wanted to port it was so that I could possibly add a gem slide mechanic that you see in most match-3 games. I've got mostly everything set up, except the sliding part. However, I have managed to come up with something:

Code: [Select]
if (!p1.overlaps(p5) && !p5.alive)
{
p1.IsAbused = true;
} else
{
p1.IsAbused = false;
}

Now. What this does, is that when the gem below the first gem (p5) is killed by the player, the gem above (p1) falls downard (whitch is what the IsAbused boolean tells a function in the gem class what to do). Now. This works for a one to one basis. But what if I have 30 or more gems to check? So naturally I checked to see if the first gem did not collide with any of the other gem members that were not alive (i think that's how to say it). I did that by doing this:
Code: [Select]
if (!p1.overlaps(gems.countLiving()))
{
p1.IsAbused = true;
} else
{
p1.IsAbused = false;
}

This of course throws an error. What I'm basically trying to do, is something like this:

How do I check to see if a gem has empty spaces on it's sides?

How do I properly use the CIELING, FLOOR, WALLS, etc for overlap detection?

Any help or ideas?
Thanks in advance!

ps: if you do suggest some flood fill method, please do as best you can to describe what the heck is going on. Cause I've looked it up and have a foggy understanding at best. Thanks.

Pages: [1] 2 3 ... 5