Permalink
Browse files

cleaning up

  • Loading branch information...
1 parent adc2165 commit 036e44b18fad0508befac9e02834f2dc58813575 @presstube committed Jul 28, 2011
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -1,87 +0,0 @@
-package com.gskinner {
- import flash.display.BitmapData;
- import flash.display.BitmapDataChannel;
- import flash.display.BlendMode;
- import flash.display.DisplayObject;
- import flash.display.DisplayObjectContainer;
- import flash.geom.Matrix;
- import flash.geom.Point;
- import flash.geom.Rectangle;
-
- public class PixelPerfectCollisionDetection {
- /** Get the collision rectangle between two display objects. **/
- public static function getCollisionRect(target1:DisplayObject, target2:DisplayObject, commonParent:DisplayObjectContainer, pixelPrecise:Boolean=false, tolerance:Number=0):Rectangle {
- // get bounding boxes in common parent's coordinate space
- var rect1:Rectangle = target1.getBounds(commonParent);
- var rect2:Rectangle = target2.getBounds(commonParent);
- // find the intersection of the two bounding boxes
- var intersectionRect:Rectangle = rect1.intersection(rect2);
- if (intersectionRect.size.length > 0) {
- if (pixelPrecise) {
- // size of rect needs to integer size for bitmap data
- intersectionRect.width = Math.ceil(intersectionRect.width);
- intersectionRect.height = Math.ceil(intersectionRect.height);
- // get the alpha maps for the display objects
- var alpha1:BitmapData = getAlphaMap(target1, intersectionRect, BitmapDataChannel.RED, commonParent);
- var alpha2:BitmapData = getAlphaMap(target2, intersectionRect, BitmapDataChannel.GREEN, commonParent);
- // combine the alpha maps
- alpha1.draw(alpha2, null, null, BlendMode.LIGHTEN);
- // calculate the search color
- var searchColor:uint;
- if (tolerance <= 0) {
- searchColor = 0x010100;
- } else {
- if (tolerance > 1)
- tolerance = 1;
- var byte:int = Math.round(tolerance * 255);
- searchColor = (byte << 16) | (byte << 8) | 0;
- }
- // find color
- var collisionRect:Rectangle = alpha1.getColorBoundsRect(searchColor, searchColor);
- collisionRect.x += intersectionRect.x;
- collisionRect.y += intersectionRect.y;
- return collisionRect;
- } else {
- return intersectionRect;
- }
- } else {
- // no intersection
- return null;
- }
- }
- /** Gets the alpha map of the display object and places it in the specified channel. **/
- private static function getAlphaMap(target:DisplayObject, rect:Rectangle, channel:uint, commonParent:DisplayObjectContainer):BitmapData {
- // calculate the transform for the display object relative to the common parent
- var parentXformInvert:Matrix = commonParent.transform.concatenatedMatrix.clone();
- parentXformInvert.invert();
- var targetXform:Matrix = target.transform.concatenatedMatrix.clone();
- targetXform.concat(parentXformInvert);
- // translate the target into the rect's space
- targetXform.translate(-rect.x, -rect.y);
- // draw the target and extract its alpha channel into a color channel
- var bitmapData:BitmapData = new BitmapData(rect.width, rect.height, true, 0);
- bitmapData.draw(target, targetXform);
- var alphaChannel:BitmapData = new BitmapData(rect.width, rect.height, false, 0);
- alphaChannel.copyChannel(bitmapData, bitmapData.rect, new Point(0, 0), BitmapDataChannel.ALPHA, channel);
- return alphaChannel;
- }
- /** Get the center of the collision's bounding box. **/
- public static function getCollisionPoint(target1:DisplayObject, target2:DisplayObject, commonParent:DisplayObjectContainer, pixelPrecise:Boolean=false, tolerance:Number=0):Point {
- var collisionRect:Rectangle = getCollisionRect(target1, target2, commonParent, pixelPrecise, tolerance);
- if (collisionRect != null && collisionRect.size.length > 0) {
- var x:Number = (collisionRect.left + collisionRect.right) / 2;
- var y:Number = (collisionRect.top + collisionRect.bottom) / 2;
- return new Point(x, y);
- }
- return null;
- }
- /** Are the two display objects colliding (overlapping)? **/
- public static function isColliding(target1:DisplayObject, target2:DisplayObject, commonParent:DisplayObjectContainer, pixelPrecise:Boolean=false, tolerance:Number=0):Boolean {
- var collisionRect:Rectangle = getCollisionRect(target1, target2, commonParent, pixelPrecise, tolerance);
- if (collisionRect != null && collisionRect.size.length > 0)
- return true;
- else
- return false;
- }
- }
-}
@@ -1,121 +0,0 @@
-package com.presstube.chunkulus {
- import com.gskinner.PixelPerfectCollisionDetection;
- import com.presstube.utils.PTmove;
-
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.BlendMode;
- import flash.display.DisplayObject;
- import flash.display.MovieClip;
- import flash.display.PixelSnapping;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.geom.ColorTransform;
- import flash.geom.Point;
- import flash.utils.getDefinitionByName;
-
- public class ActiveScroller extends Sprite {
-
- private var activeStage:ActiveStage;
- private var items:Array;
- private var radius:Number;
-
- public function ActiveScroller(activeStage:ActiveStage, radius:Number) {
- this.activeStage = activeStage;
- this.radius = radius;
-
- items = [];
-
- addEventListener(Event.ADDED_TO_STAGE, function(e:Event):void {
- makeItems(20);
- addEventListener(Event.ENTER_FRAME, onEnterFrame);
- });
- }
-
- private function makeItems(numItems:int):void {
- for (var i:int = 0; i < numItems; i++) {
- var item:DisplayObject = makeTinyBGChunkle();
- item.x = ((Math.random() * radius) * 2) - ((Math.random() * radius) * 2);
- item.y = ((Math.random() * radius) * 2) - ((Math.random() * radius) * 2);
- item.rotation = Math.random() * 360;
-// item.scaleX = item.scaleY = 5;
-// item.cacheAsBitmap = true;
- addChild(item);
- items.push(item);
- }
- }
-
- private function makeItem():Sprite {
- var item:Sprite = new Sprite;
- item.graphics.lineStyle(1);
- item.graphics.drawCircle(-2, -2, 4);
- return item;
- }
-
- private function makeNothingItem():Sprite {
- var item:Sprite = new Sprite;
- var ran:int = Math.floor(Math.random() * 2) + 1;
- var nothingClass:Class = getDefinitionByName("BG_" + 2) as Class;
- var nothing:Sprite = new nothingClass() as Sprite;
- return nothing
- }
-
- private function makeTinyBGChunkle():MovieClip {
- var itemClass:Class = getDefinitionByName("AssetBG") as Class;
- var item:MovieClip = new itemClass() as MovieClip;
- item.gotoAndStop(Math.floor(Math.random() * item.totalFrames) + 1);
- return item;
- }
-
- private function onEnterFrame(e:Event):void {
- checkForWrap();
- }
-
- private function checkForWrap():void {
- for (var i:int = 0; i < items.length; i++) {
- var item:MovieClip = items[i];
- var itemPosition:Point = new Point(item.x, item.y);
- var centerPosition:Point = new Point(-activeStage.x, -activeStage.y);
- var dist:Number = Point.distance(centerPosition, itemPosition);
- var distAllowed:Number = radius + item.width + item.height;
- if (dist > (distAllowed)) {
- var direction:Number = PTmove.degreesFromPointToPoint(centerPosition, itemPosition);
- item.gotoAndStop(Math.floor(Math.random() * item.totalFrames) + 1);
- var respawnPoint:Point = Point.polar(distAllowed, PTmove.degreesToRads(getOppositeSemiCircleDirection(direction)));
- item.x = respawnPoint.x + centerPosition.x;
- item.y = respawnPoint.y + centerPosition.y;
- item.rotation = Math.random() * 360;
- var ct:ColorTransform = new ColorTransform;
- ct.color = 0x000000;
- item.transform.colorTransform = ct;
- }
- }
- }
-
- private function getOppositeSemiCircleDirection(direction:Number):Number {
- return Math.random() * 180 + (direction + 90);
- }
-
- public function hitTest(objectToTest:DisplayObject):Boolean {
- var isColliding:Boolean;
- for (var i:int = 0; i < items.length; i++) {
- var item:MovieClip = items[i];
- if (PixelPerfectCollisionDetection.isColliding(item, objectToTest, activeStage, true)) {
- isColliding = true;
-// var ct:ColorTransform = new ColorTransform;
-// ct.color = 0xff0000;
-// item.transform.colorTransform = ct;
-// item.scaleX = item.scaleY = 2;
- break;
- } else {
-// var ct:ColorTransform = new ColorTransform;
-// ct.color = 0x000000;
-// item.transform.colorTransform = ct;
-// item.scaleX = item.scaleY = 1;
- }
-
- }
- return isColliding;
- }
- }
-}
@@ -39,9 +39,9 @@ package com.presstube.chunkulus {
velocity.y = forceToAdd.y;
// makeGraphics();
var chunkyAsset:MovieClip = makeChunky();
- chunkyAsset.scaleX = chunkyAsset.scaleY = 0;
+ scaleX = scaleY = 0;
- TweenLite.to(chunkyAsset, 1, {scaleX:.5, scaleY:.5, ease:Expo.easeOut});
+// TweenLite.to(chunkyAsset, 1, {scaleX:.5, scaleY:.5, ease:Expo.easeOut});
addChild(chunkyAsset);
// var ct:ColorTransform = new ColorTransform;
@@ -62,6 +62,8 @@ package com.presstube.chunkulus {
}
private function onEnterFrame(e:Event):void {
+ scaleX += (.5 - scaleX) / 2;
+ scaleY += (.5 - scaleY) / 2;
applyForces();
checkForWrap();
}
@@ -1,19 +1,13 @@
package com.presstube.chunkulus {
- import com.greensock.plugins.VolumePlugin;
import com.presstube.utils.PTmove;
import flash.display.DisplayObject;
import flash.display.MovieClip;
- import flash.display.PixelSnapping;
import flash.display.Sprite;
import flash.events.Event;
- import flash.events.KeyboardEvent;
import flash.geom.Point;
- import flash.ui.Keyboard;
import flash.utils.getDefinitionByName;
- import flashx.textLayout.elements.SpanElement;
-
public class Chunkulus extends Sprite {
private static const OPEN:String = "OPEN";
@@ -40,7 +34,6 @@ package com.presstube.chunkulus {
private var direction:String;
public function Chunkulus(activeStage:ActiveStage, radius:Number) {
-// makeTestGraphics();
this.activeStage = activeStage;
this.radius = radius;
bodyAnimIndex = 2;
@@ -49,6 +42,12 @@ package com.presstube.chunkulus {
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
+ private function onAddedToStage(e:Event):void {
+ removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
+ addEventListener(Event.ENTER_FRAME, onEnterFrame);
+ rotation = 45;
+ }
+
private function makeBody():void {
body = new AssetBody;
exhaustPoint = body.exhaustPoint;
@@ -70,34 +69,6 @@ package com.presstube.chunkulus {
addChild(head);
}
- private function onAddedToStage(e:Event):void {
- removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
- addEventListener(Event.ENTER_FRAME, onEnterFrame);
- rotation = 45;
-// stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
-// stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
- }
-
- private function onKeyDown(e:KeyboardEvent):void {
- if (e.keyCode == Keyboard.UP) {
- upKeyPressed = true;
- } else if (e.keyCode == Keyboard.LEFT) {
- leftKeyPressed = true;
- } else if (e.keyCode == Keyboard.RIGHT) {
- rightKeyPressed = true;
- }
- }
-
- private function onKeyUp(e:KeyboardEvent):void {
- if (e.keyCode == Keyboard.UP) {
- upKeyPressed = false;
- } else if (e.keyCode == Keyboard.LEFT) {
- leftKeyPressed = false;
- } else if (e.keyCode == Keyboard.RIGHT) {
- rightKeyPressed = false;
- }
- }
-
public function onEnterFrame(e:Event):void {
applyForces();
spawnBodyAnims();
@@ -145,18 +116,6 @@ package com.presstube.chunkulus {
}
}
- private function makeTestGraphics():void {
- graphics.beginFill(0x000000);
- graphics.drawRect(-10, -10, 20, 20);
- graphics.endFill();
- graphics.beginFill(0xFF0000);
- graphics.drawCircle(0, -10, 5);
- }
-
- public function get velocity():Point {
- return new Point(_velocity.x, _velocity.y);
- }
-
private function onBodyAnimEnterFrame(e:Event):void {
var bodyAnim:MovieClip = e.target as MovieClip;
if (bodyAnim.currentFrame == bodyAnim.totalFrames) {
@@ -189,15 +148,6 @@ package com.presstube.chunkulus {
}
}
- public function open():void {
- direction = OPEN;
- }
-
- public function close():void {
- direction = CLOSE;
- head.rotation = 0;
- }
-
private function animateHead():void {
if (direction == OPEN) {
head.gotoAndStop(3);
@@ -222,13 +172,22 @@ package com.presstube.chunkulus {
head.rotation = spitRotation - rotation;
}
- public function advanceBodyAnim():void {
- _bodyAnimIndex = (_bodyAnimIndex == 5) ? 1 : _bodyAnimIndex + 1;
+ public function open():void {
+ direction = OPEN;
+ }
+
+ public function close():void {
+ direction = CLOSE;
+ head.rotation = 0;
}
public function set bodyAnimIndex(index:int):void {
_bodyAnimIndex = index;
}
+
+ public function get velocity():Point {
+ return new Point(_velocity.x, _velocity.y);
+ }
}
}
Oops, something went wrong.

0 comments on commit 036e44b

Please sign in to comment.