Decided to post a video about one of the greatest games and greatest gaming glitches ever made in the Witcher 3 Wild Hunt.
Also, I'm back!
For now.
Do you like things? Me too. I also like to think about things and have ideas. Come join me and see what I come up with.
public var kLeft:Boolean;//37 public var kRight:Boolean;//39 public var kUp:Boolean;//38 public var kDown:Boolean;//40
stage.addEventListener(KeyboardEvent.KEY_DOWN, keysDown, false, 0, true); stage.addEventListener(KeyboardEvent.KEY_UP, keysUp, false, 0, true);
public function keysDown(ke:KeyboardEvent) : void
{
if(ke.keyCode == 37)
{
kLeft = true;
}
if(ke.keyCode == 39)
{
kRight = true;
}
if(ke.keyCode == 38)
{
kUp = true;
}
if(ke.keyCode == 40)
{
kDown = true;
}
}
public function keysUp(ke:KeyboardEvent) : void
{
if(ke.keyCode == 37)
{
kLeft = false;
}
if(ke.keyCode == 39)
{
kRight = false;
}
if(ke.keyCode == 38)
{
kUp = false;
}
if(ke.keyCode == 40)
{
kDown = false;
}
}
public function keysDown(ke:KeyboardEvent) : void
{
trace(ke.keyCode);
}
package
{
/*
An Amazing Coding Product of Benjamin Floyd
If you got this, even by trickery, feel free to use it.
A tip-o-the-hat would be nice though.
*/
import flash.events.Event;
import flash.display.MovieClip;
public class Hero extends MovieClip
{
public function Hero()
{
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
public function init(e:Event = null) : void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
addEventListener(Event.ENTER_FRAME, update, false, 0, true);
}
public function update(e:Event = null) : void
{
if(Main.instance.kLeft)
{
x -= 1;
}
else if(Main.instance.kRight)
{
x += 1;
}
if(Main.instance.kUp)
{
y -= 1;
}
else if(Main.instance.kDown)
{
y += 1;
}
}
}
}
public var ROOT:Object;
ROOT = Main.instance;
![]() |
| You have to update before you update. Thanks, Windows. |
public class Main extends Sprite
{
public static var instance:Object;
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
public function init(e:Event = null) : void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
instance = this;
}
}
public const SW:int = 512; public const SH:int = 288; public const SWH:int = SW / 2; public const SHH:int = SH / 2; public var TS:int = 16; public var TSH:Number = TS / 2;
stage.stageWidth
![]() |
| http://www.gigs4gags.com/funny-programming/ |
//Main.as
package
{
import flash.display.MovieClip;
public class Main extends MovieClip
{
public function Main()
{
}
}
}
//Main.as internal const SWIDTH:Number = 480; internal const SHEIGHT:Number = 480;
//Main.as
//this will instantiate 80 fire particles and that's it.
//We'll use the "FireParticle.as" (which we haven't created yet)
//to get them to reinitialize themselves.
for (var i:int = 0; i < 80; i++)
{
//creates a new FireParticle at the index above our fire so it's always on top.
addChildAt(new FireParticle(), getChildIndex(fire) + 1);
}
//FireParticle.as
package
{
import flash.display.MovieClip;
public class FireParticle extends MovieClip
{
//MEMBERS
private var ROOT:Object;//our "Main.as" is our root so we need to access it somehow
private var ySpeed:Number;//our particles have to move. What better way than giving them some speed?
//METHODS
public function FireParticle()
{
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
private function init(e:Event = null) : void//we set this to "null" so we can use reinitialize it later
{
}
}
}
//FireParticle.as ROOT = root;//get our root MovieClip alpha = Math.random(); x = ROOT.fire.x;//sets the x in the center of our fire y = ROOT.fire.y;//sets the y in the center or our fire ySpeed = 4;//will be used in our ENTER_FRAME listener addEventListener(Event.ENTER_FRAME, update, false, 0, true);
//FireParticle.as
private function update(e:Event) : void
{
y -= ySpeed;//moves this particle toward the top of the screen
alpha -= 0.01;//lowers this particle's alpha every frame
if (alpha <= 0)//if this particle becomes invisile...
{
init();//...we want to reset it
//this is why we set our "init()" function to a default of "null"
}
}
//FireParticle.as
private function randomRange(minNum:Number, maxNum:Number) : Number
{
return Math.floor((Math.random() * (maxNum - minNum + 1)) + minNum);
}
//EXAMPLE
private function randomRange(minNum:Number, maxNum:Number) : Number
{
return Math.floor((0.2 * (5 - 3 + 1)) + 3);
}
//FireParticle.as ROOT = root;//get our root MovieClip alpha = Math.random(); x = randomRange(ROOT.fire.x - ROOT.fire.width / 2, ROOT.fire.x + ROOT.fire.width / 2);//this makes our particle's x initialize somewhere within the width of our fire object on the stage y = randomRange(ROOT.fire.y - ROOT.fire.height / 2, ROOT.fire.y);//this makes our particle's y initialize somewhere in the top half of our fire object on the stage ySpeed = randomRange(3, 5);//setting a random speed makes it look that much more believable, much as the random alpha value addEventListener(Event.ENTER_FRAME, update, false, 0, true);
//FireParticle.as private var bounce:Boolean = false;//start it off false if you want it to be stationary from the get go, true if you want it to start off bouncing private var xSpeed:Number = 15;//this will be our fire's speed in the x direction private var ySpeed:Number = 15;//this will be our fire's speed in the y direction
//Main.as btnBounce.addEventListener(MouseEvent.CLICK, toggleBounce, false, 0, true);//when we click on the button it will either start or stop the bounce addEventListener(Event.ENTER_FRAME, update, false, 0, true);
//Main.as
private function update(e:Event) : void
{
if (bounce)//if bounce is true...
{
//...we'll make the fire move in both x and y directions
fire.x += xSpeed;
fire.y += ySpeed;
if (fire.x - fire.width / 2 < 0)//if it hits the left side we push it back to the right
{
fire.x = fire.width / 2;//repositions it so it doesn't get stuck. Same for all the other ones
xSpeed *= -1;//this makes the speed the opposite, ie "15" becomes "-15". Same for all the other ones
}
if (fire.x + fire.width / 2 > SWIDTH)//if it hits the right side we push it back to the left
{
fire.x = SWIDTH - fire.width / 2;
xSpeed *= -1;
}
if (fire.y - fire.height / 2 < 0)//if it hits the top we push it back to the bottom
{
fire.y = fire.height / 2;
ySpeed *= -1;
}
if (fire.y + fire.height / 2 > SHEIGHT)//if it hits the bottom we push it back to the top
{
fire.y = SHEIGHT - fire.height / 2;
ySpeed *= -1;
}
}
else//if it's not bouncing then it sits at it's home
{
fire.x = SWIDTH / 2;
fire.y = SHEIGHT * 0.85;
}
}
private function toggleBounce(me:MouseEvent) : void//when clicked...
{
if (!bounce)//..if it's not bouncing yet then we will make it bounce...
{
btnBounce.txtBounce.text = "STOP";//changes the dynamic text box
bounce = true;
}
else//...otherwise we stop it
{
btnBounce.txtBounce.text = "BOUNCE";//changes the dynamic text box
bounce = false;
}
}
Okay, all. I'm tired. Writing tutorials are much more time consuming than I thought. I really hope this helps you out. If it does, hit me up and let me know how you've used the concept or if you have any questions. Peace out!