Interesting things and ways to do them

16 posts

Flag Post

Title ^

Basically this is a thread to post anything cool/interesting that you may have found or discovered. Heres some examples:

- Cryptography, Algorithms, Security
- Procedurally Generated Content
- Pathfinding
- Good Tutorials and/or resources
- Design articles

Really, this thread is for anything you’ve found interesting related to programming and/or games. Resources, tutorials, etc.

 
Flag Post

Only thing that comes to the top of my head atm is this super simple pause code I came up with for Flixel. Not very useful for those not using Flixel, I know, but whatevs. I’ll dump it on the off-chance.

// stick this in your FlxState.update()

if (!FlxG.paused) {
	super.update();
} else {
	pause.update(); // pause FlxGroup (this is the pause menu)
}
			
if (FlxG.keys.justPressed("ESCAPE") || FlxG.keys.justPressed("P")) {
	if(!FlxG.paused){
		FlxG.paused = true;
		pause.revive();
	} else {
		FlxG.paused = false;
		pause.alive = false;
		pause.exists = false;
	}
}
 
Flag Post
Originally posted by MoonlaughMaster:

Only thing that comes to the top of my head atm is this super simple pause code I came up with for Flixel. Not very useful for those not using Flixel, I know, but whatevs. I’ll dump it on the off-chance.

// stick this in your FlxState.update()

if (!FlxG.paused) {
	super.update();
} else {
	pause.update(); // pause FlxGroup (this is the pause menu)
}
			
if (FlxG.keys.justPressed("ESCAPE") || FlxG.keys.justPressed("P")) {
	if(!FlxG.paused){
		FlxG.paused = true;
		pause.revive();
	} else {
		FlxG.paused = false;
		pause.alive = false;
		pause.exists = false;
	}
}

Looks great, even small stuff like this is good.
I’m going to be working on some boids today, If it gets done I’ll post it.

 
Flag Post

I like using this small snippet-full of code for getting an easy keyPress & keyRelease system in place.


public static var self:Main;

private var kNow:Dictionary = new Dictionary();
private var kLast:Dictionary = new Dictionary();

public function Main():void
{
    self=this; addEventListener(Event.ADDED_TO_STAGE,init,false,0,true);
}

public function init(e:Event=null):void
{
    stage.addEventListener(Event.ENTER_FRAME,update,false,0,true);
    stage.addEventListener(KeyboardEvent.KEY_DOWN,onKey,false,0,true);
    stage.addEventListener(KeyboardEvent.UP,onKey,false,0,true);
}

private function update(e:Event):void
{
    //Do all updating of other stuff here first
    //Keyboard update
    for(var i:Object in kNow){
        kLast[i] = kNow[i];
    }
}

private function onKey(e:KeyboardEvent):void
{
    kNow[e.keyCode] = e.type=="keyDown";
}

public static function keyPress(code:int):Boolean
{ return kNow[code] && !kLast[code]; }
public static function keyRelease(code:int):Boolean
{ return !kNow[code] && kLast[code]; }
public static function keyDown(code:int):Boolean { return kNow[code]; }
public static function keyUp(code:int):Boolean { return !kNow[code]; }

Then just use if(Main.keyPress(Keyboard.SPACE)){ trace("SPACE!"); } or whatever anywhere (static function) and it will only return true if the key was pressed that frame.

 
Flag Post

Component based programming for games. It’s the single biggest discovery I made since I started programming.

 
Flag Post

@DPBrad, that looks pretty good. I’ll have to run some speed tests and see if I like it :P

@Drakim, care to elaborate?

 
Flag Post

Quick remark and question for DPBrad: the remark is that, in the init() function, third line, the event should be KEY_UP, not UP. The question is: how do you handle key repeats? A repeat occurs when the player leaves their finger on the key for a length of time that 1) is entirely dependent on their operating system settings and 2) Flash has no control over. It causes the KEY_DOWN event to fire repeatedly at a rate that, once again, you have no control over and is totally user-dependent. Pressing a second key while holding the first one will usually cause the first key to stop firing even though it’s still held down. So, how do you handle all of that, if at all?

I’m asking because I could see the same key being used for two distinct actions (say ‘jump’ and ‘double jump’) and things going pear-shaped pretty quickly if you don’t handle repeats properly.

 
Flag Post
Originally posted by Ace_Blue:

Quick remark and question for DPBrad: the remark is that, in the init() function, third line, the event should be KEY_UP, not UP. The question is: how do you handle key repeats? A repeat occurs when the player leaves their finger on the key for a length of time that 1) is entirely dependent on their operating system settings and 2) Flash has no control over. It causes the KEY_DOWN event to fire repeatedly at a rate that, once again, you have no control over and is totally user-dependent. Pressing a second key while holding the first one will usually cause the first key to stop firing even though it’s still held down. So, how do you handle all of that, if at all?

I’m asking because I could see the same key being used for two distinct actions (say ‘jump’ and ‘double jump’) and things going pear-shaped pretty quickly if you don’t handle repeats properly.

1) Yeah, I didnt directly copy it, I actually just wrote it out for this forum and forgot to put the KEY there.
2) If you run and test the code, you will see that does not occur. If you want to keep firing the function every event, you wouldnt need that in the first place as the direct KeyboardEvent will do that for you.

 
Flag Post

@Drakim, care to elaborate?

I’m planning to make a topic about it in the near future, so you’ll see then :)

 
Flag Post

I’ve made a procedural… thing. Source is with it if any of it looks useful.

http://eyes-squared.co.uk/blog/making-an-endless-animation-that-reacts-to-music/

 
Flag Post
Originally posted by Aaants:

I’ve made a procedural… thing. Source is with it if any of it looks useful.

http://eyes-squared.co.uk/blog/making-an-endless-animation-that-reacts-to-music/

Exactly the type of stuff I’d like to see in this thread.

Aaants… that is absolutely amazing. You are a great programmer XD

E: Alright guys, made Conway’s game of life. Read the desc to learn it. http://www.fastswf.com/DB2lOlo

Check out wikipedia for more info, it’s really cool.

 
Flag Post

Aants that’s incredibly cool! Does the animation react to the rhythm in anyway?
All the things you make are awesomely artistic!

Edit: Can you give a brief explanation of what you did? :) (just the basic idea)

 
Flag Post

Thanks guys. The animation itself doesn’t react to the music but the scaling does. You could edit it to spawn the next animation link when the sound is above a certain volume though I suppose. Give it a go :)

I explain it all in the video Erlend (below the swf)

 
Flag Post

The only thing that bothered me about the animation was that it jittered. Like it would rotate back and forth 5 degrees every frame, for no apparent reason.

 
Flag Post

Not sure I know what you mean; the only rotation code I put in was the big sweeping spin. If you mean the rapid jagged pulsing it does, I think it’s just because the track is so frantic (it’s a bit of a mess in waveform), so the scale fluctuates really quickly. I tried to ease that a bit but I guess it needs more work. I’ll try it on a few other browsers and FP versions to see if I can get a better idea.

Darn you making me break 100 posts btw :)

 
Flag Post

I suppose this qualifies as “interesting things” as well.
Original thread

The interesting bit:

Using an SVG file to control tween motion on an HTML page via the use of getPointAtLength() function.