/BioGameLaunch.as
package {
import flash.text.TextField;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.ProgressEvent;
import flash.events.Event;
public class BioGameLaunch extends MovieClip {
private var mURL:String = './Bio Game.swf';
private var mLoader:Loader;
public function BioGameLaunch():void {
mLoader = new Loader();
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingComplete);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loading);
mLoader.load(new URLRequest('./Bio Game.swf'));
}
private function loading(inProgressEvent:ProgressEvent):void {
var loaded = mLoader.contentLoaderInfo.bytesLoaded;
var total = mLoader.contentLoaderInfo.bytesTotal;
text.text = Math.round((loaded / total) * 100) + '%';
}
private function loadingComplete(inEvent:Event):void {
removeChild(text);
removeChild(tile);
addChild(mLoader);
}
}
}
/BioGame.as
package {
import com.biogame.*;
import flash.text.TextField;
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.ui.Mouse;
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.filters.GlowFilter;
import flash.filters.BitmapFilterQuality;
import flash.media.Sound;
import flash.media.SoundChannel;
import com.exanimo.*;
public class BioGame extends MovieClip {
private var mGameLength:Number = 365;
private var mGameLengthCurrent:Number = mGameLength;
private var mGameTick:Number = 900;
public var mTimer:Timer;
public var mGamePlayer:Game;
public var mGameOpponent:Game;
public var mPaused:Boolean = false;
public var mHighlight:GlowFilter = new GlowFilter();
public var mName:String = '';
private var mFPS:Number = 0;
private var mFPSTimer:Timer;
private var mCount:Number = 0;
public function BioGame():void {
addEventListener(Event.ADDED_TO_STAGE, initialize);
stop();
}
public function initialize(inEvent:Event):void {
Mouse.hide();
Sounds.play(new SndBackground());
stage.scaleMode = StageScaleMode.EXACT_FIT;
launch();
}
public function launch():void {
setupHighlight();
mGameOpponent = new Game(false);
addChild(mGameOpponent);
mGamePlayer = new Game(true);
addChild(mGamePlayer);
mFPSTimer = new Timer(1000, 0);
mFPSTimer.addEventListener(TimerEvent.TIMER, fpsUpdate);
mFPSTimer.start();
stage.addEventListener(Event.ENTER_FRAME, fpsTick);
mTimer = new Timer(mGameTick, mGameLength);
mTimer.addEventListener(TimerEvent.TIMER, tick);
mTimer.addEventListener(TimerEvent.TIMER_COMPLETE, gameDone);
mTimer.start();
stage.addEventListener(MouseEvent.MOUSE_MOVE, mCursor.update);
moveChildToTop(mPopup);
moveChildToTop(mPauser);
moveChildToTop(mCursor);
stage.addEventListener(KeyboardEvent.KEY_UP, handle);
AI.initialize(mGameOpponent);
setupPositions();
//
mGameOpponent.initialize(mTxtOpponentMoney, mTxtOpponentFood, mTxtOpponentCows, mTxtOpponentSlaughter);
mGamePlayer.initialize(mTxtPlayerMoney, mTxtPlayerFood, mTxtPlayerCows, mTxtPlayerSlaughter);
mGamePlayer.setupControls();
//
mPopup.initialize();
mPopup.show(Popup.PERSON, new Array());
}
private function setupHighlight():void {
// mHighlight.color = 0x25325E;
mHighlight.color = 0xFFFFFF;
mHighlight.alpha = 1.0;
mHighlight.blurX = 10;
mHighlight.blurY = 10;
mHighlight.quality = BitmapFilterQuality.MEDIUM;
}
private function setupPositions():void {
var currentIndex:Number = 0;
var removed:Number = 0;
var looping:Boolean = true;
while(looping) {
var child = getChildAt(currentIndex);
if(child is Grass || child is Cow) {
if(child.x < 500) {
mGameOpponent.setupPosition(child, currentIndex + removed);
}else{
mGamePlayer.setupPosition(child, currentIndex + removed);
}
removeChild(child);
removed++;
}else{
currentIndex++;
}
if(currentIndex > (numChildren-1)) {
looping = false;
}
}
}
private function moveChildToTop(inChild:DisplayObject):void {
setChildIndex(inChild, numChildren-1);
}
private function handle(inKeyboardEvent:KeyboardEvent):void {
switch(inKeyboardEvent.keyCode) {
case Keyboard.SPACE:
spaceToggle();
break;
}
}
private function spaceToggle():void {
if(mPaused && !mPopup.mActive) {
resume();
}else{
pause();
}
}
public function pause():void {
if(!mPaused) {
mPaused = true;
//
mPauser.gotoAndPlay('paused');
AI.pause();
mTimer.stop();
mGamePlayer.pause();
mGameOpponent.pause();
}
}
public function resume():void {
if(mPaused) {
mPaused = false;
//
mPauser.gotoAndPlay('resume');
AI.resume();
if(mTimer.currentCount != mGameLength) {
mTimer.start();
}
mGamePlayer.resume();
mGameOpponent.resume();
}
}
private function fpsTick(inEvent:Event):void {
mFPS++;
}
private function fpsUpdate(inTimerEvent:TimerEvent):void {
mTxtFPS.text = String(mFPS) + ' FPS';
mFPS = 0;
}
private function tick(inTimerEvent:TimerEvent):void {
mGameLengthCurrent--;
mTxtTimer.text = String(mGameLengthCurrent);
}
private function gameDone(inTimerEvent:TimerEvent):void {
mPopup.show(Popup.END, new Array());
}
}
}
/com/biogame/AI.as
package com.biogame {
import flash.events.TimerEvent;
import flash.utils.Timer;
public class AI {
private static var mGame:Game;
private static var mTimers:Object = new Object();
private static var mBuyCow:Boolean = false;
public static function initialize(inGame):void {
mGame = inGame;
startTimers();
}
private static function startTimers():void {
mTimers['food'] = new Timer(1500, 0);
mTimers['food'].addEventListener(TimerEvent.TIMER, actionFood);
mTimers['food'].start();
setupDoors(30000, 1);
mTimers['stats'] = new Timer(1000, 0);
mTimers['stats'].addEventListener(TimerEvent.TIMER, actionStats);
mTimers['stats'].start();
}
private static function setupDoors(inDelay:Number, inRepeat:Number):void {
mTimers['doors'] = new Timer(inDelay, inRepeat);
mTimers['doors'].addEventListener(TimerEvent.TIMER, actionDoors);
mTimers['doors'].start();
}
private static function actionDoors(inTimerEvent:TimerEvent):void {
mGame.actionDoors();
if(mGame.mInside) {
mTimers['mow'] = new Timer(2000, 1);
mTimers['mow'].addEventListener(TimerEvent.TIMER, actionMow);
mTimers['mow'].start();
setupDoors(14000, 1);
}else{
setupDoors(30000, 1);
}
}
private static function actionFood(inTimerEvent:TimerEvent):void {
if(!mGame.mInside && mGame.mCows > 0) {
mGame.actionFoodIndividually(pickCow());
}
}
private static function actionMow(inTimerEvent:TimerEvent):void {
mGame.actionMow();
}
private static function actionStats(inTimerEvent:TimerEvent):void {
if(mBuyCow || mGame.mFood > 65) {
mBuyCow = false;
mGame.actionBuyCow();
}else{
mBuyCow = true;
mGame.actionBuyFood();
}
}
public static function pickCow():Cow {
var lowestCow:Cow;
var lowestAmount:Number = 100;
for each(var cow:Cow in mGame.mListCows) {
if(cow.mFood < lowestAmount && !cow.mRemoved) {
lowestAmount = cow.mFood;
lowestCow = cow;
}
}
return lowestCow;
}
public static function pause():void {
for each(var timer in mTimers) {
timer.stop();
}
}
public static function resume():void {
for each(var timer in mTimers) {
timer.start();
}
}
}
}
/com/biogame/BuyCow.as
package com.biogame {
import flash.events.MouseEvent;
import flash.display.MovieClip;
public class BuyCow extends InteractiveElement {
public function BuyCow(inGame:Game):void {
mGame = inGame;
visible = mGame.mIsPlayer;
determineButtonMode();
if(!mGame.mIsPlayer) {
scaleX *= -1;
}
}
public function initialize():void {
mInfo.visible = false;
draw();
}
override function interactionOver(inMouseEvent:MouseEvent):void {
super.interactionOver(inMouseEvent);
if(!mEnabled && !mPaused) {
mInfo.visible = true;
}
}
override function interactionOut(inMouseEvent:MouseEvent):void {
super.interactionOut(inMouseEvent);
mInfo.visible = false;
}
}
}
/com/biogame/BuyFood.as
package com.biogame {
import flash.events.MouseEvent;
import flash.display.MovieClip;
public class BuyFood extends InteractiveElement {
public function BuyFood(inGame:Game):void {
mGame = inGame;
visible = mGame.mIsPlayer;
determineButtonMode();
if(!mGame.mIsPlayer) {
scaleX *= -1;
}
}
public function initialize():void {
mInfo.visible = false;
draw();
}
override function interactionOver(inMouseEvent:MouseEvent):void {
super.interactionOver(inMouseEvent);
if(!mEnabled && !mPaused) {
mInfo.visible = true;
}
}
override function interactionOut(inMouseEvent:MouseEvent):void {
super.interactionOut(inMouseEvent);
mInfo.visible = false;
}
}
}
/com/biogame/Cow.as
package com.biogame {
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import fl.transitions.TweenEvent;
import flash.display.MovieClip;
import flash.geom.Point;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.utils.setTimeout;
import flash.utils.getTimer;
import com.exanimo.transitions.*;
public class Cow extends Element {
public var mSpot:Number;
private var mFoodMax:Number = 15;
private var mFoodChance:Number = 2;
public var mFood:Number = mFoodMax;
private var mLastFed:Number = -10000;
private var mFoodIndicator:FoodIndicator;
private var mInside:Boolean = false;
public var mDead:Boolean = false;
private var mSlaughtered:Boolean = false;
private var mTruck:Truck;
public function Cow():void {
mPerspective = true;
}
public function initialize():void {
mStates.push('calf');
mStates.push('cow');
mStates.push('fatCow');
mStates.push('fattiestCow');
mStates.push('dead');
if(mGame.mIsPlayer) {
mFoodIndicator = new FoodIndicator(scaleX);
addChild(mFoodIndicator);
}
mTimers['food'] = new Timer(1000, 0);
mTimers['food'].addEventListener(TimerEvent.TIMER, foodDecrease);
mTimers['food'].start();
draw();
}
public function drawIndicator():void {
if(mFoodIndicator) {
mFoodIndicator.update(mFood, mFoodMax);
}
}
public function showIndicator(inShow:Boolean):void {
if(mFoodIndicator) {
mFoodIndicator.show(inShow);
}
}
public function foodNeeded():Number {
var foodDifference:Number = mFoodMax - mFood;
return foodDifference;
}
public function feed(inFood:Number):Number {
if(mSlaughtered || mInside || mDead) {
return inFood;
}
if(mGame.mIsPlayer) {
if(getTimer() < (mLastFed + 4000)) {
BioGame(root).mPopup.show(Popup.ILL, new Array());
return inFood;
}
}
if(inFood != 0) {
if(mCurrentState < mStates.length - 2) {
mLastFed = getTimer();
mCurrentState++;
draw();
showIndicator(true);
}else{
slaughterStart();
}
var foodNeeded:Number = foodNeeded();
if(foodNeeded > inFood) {
mFood += inFood;
inFood = 0;
}else{
mFood += foodNeeded;
inFood -= foodNeeded;
}
if(mGame.mIsPlayer) {
Sounds.play(new SndFood());
}
drawIndicator();
return inFood;
}else{
return 0;
}
}
private function slaughterStart():void {
if(mSlaughtered) {
return;
}
showIndicator(false);
mSlaughtered = true;
mTruck = mGame.setupTruck(this);
mTimers['slaughter'] = new Timer(1000, 1);
mTimers['slaughter'].addEventListener(TimerEvent.TIMER_COMPLETE, slaughter);
mTimers['slaughter'].start();
}
private function slaughter(inTimerEvent:TimerEvent):void {
mGame.mSlaughter++;
visible = false;
}
private function foodDecrease(inTimerEvent:TimerEvent):void {
if(mInside || mDead || mSlaughtered) {
return;
}
if(Math.round(Math.random() * mFoodChance) == 0) {
mFood--;
}
if(mFood <= 0) {
dieStart();
}else{
if((mFood == 2 || mFood == 5) && mGame.mIsPlayer) {
if(Math.round(Math.random()) == 0) {
Sounds.play(new SndCow2(), this);
}else{
Sounds.play(new SndCow1(), this);
}
}
drawIndicator();
}
}
private function dieStart():void {
mDead = true;
mCurrentState = 4;
showIndicator(false);
draw();
stop();
mTweens['y'] = new GCSafeTween(this, 'y', Strong.easeIn, y, -200, 2, true);
mTweens['y'].addEventListener(TweenEvent.MOTION_FINISH, dieEnd);
}
private function dieEnd(inTweenEvent:TweenEvent):void {
if(mGame.mIsPlayer) {
BioGame(root).mPopup.show(Popup.DEAD, new Array());
}
remove();
}
override function pause():void {
if(mTruck) {
mTruck.pause();
}
super.pause();
}
override function resume():void {
if(mTruck) {
mTruck.resume();
}
super.resume();
}
override function remove():void {
mGame.removeCow(mSpot);
super.remove();
}
public function walk():void {
if(mDead) {
return;
}
var duration:Number = 2;
if(mInside) {
mTweens['alpha'] = new GCSafeTween(this, 'alpha', Regular.easeInOut, alpha, 1.0, duration, true);
}else{
mTweens['alpha'] = new GCSafeTween(this, 'alpha', Regular.easeInOut, alpha, 0.0, duration, true);
if(mFoodIndicator) {
mFoodIndicator.show(false);
}
}
mInside = !mInside;
mTweens['alpha'].addEventListener(TweenEvent.MOTION_FINISH, walkFinished, false, 0, true);
}
public function walkFinished(inTweenEvent:TweenEvent):void {
if(!mInside) {
showIndicator(true);
}
}
}
}
import flash.display.Sprite;
import flash.events.MouseEvent;
class FoodIndicator extends Sprite {
private var mWidth:Number = 220;
private var mHeight:Number = 30;
private var mRoundness:Number = 30;
private var mAdjustment:Number = 8;
function FoodIndicator(inScale:Number):void {
alpha = 1.0;
if(inScale < 0) {
scaleX *= -1;
x = 70;
}else{
x = -160;
}
y -= 80;
update(1, 1);
}
function show(inShow:Boolean):void {
visible = inShow;
if(inShow) {
parent.setChildIndex(this, parent.numChildren-1);
}
}
function update(inFood:Number, inFoodMax:Number):void {
graphics.clear();
graphics.beginFill(0xF0EED8, 0.8);
graphics.drawRoundRect(0, 0, mWidth, mHeight, mRoundness, mRoundness);
graphics.endFill();
var color:uint = 0x990000;
var percentage:Number = Math.ceil(inFood / inFoodMax * 100);
if(percentage > 60) {
color = 0x00C102;
}else if(percentage <= 60 && percentage > 40) {
color = 0xE1B602;
}
var doubleAdjustment = mAdjustment * 2;
graphics.beginFill(color, 1.0);
graphics.drawRoundRect(mAdjustment, mAdjustment, (percentage / 100 * mWidth) - doubleAdjustment, mHeight - doubleAdjustment, mRoundness - doubleAdjustment, mRoundness - doubleAdjustment);
graphics.endFill();
}
}
/com/biogame/Cursor.as
package com.biogame {
import flash.events.MouseEvent;
public class Cursor extends Element {
private var mAreaTrigger:Boolean = false;
public function Cursor():void {
cacheAsBitmap = true;
mStates.push('normal');
mStates.push('interactive');
mStates.push('disabled');
}
public function update(inMouseEvent:MouseEvent):void {
x = inMouseEvent.stageX + 2;
y = inMouseEvent.stageY + 2;
if(!mAreaTrigger && x < 500 && !BioGame(root).mPaused) {
mCurrentState = 2;
draw();
mAreaTrigger = true;
}else if(mAreaTrigger && x >= 500) {
mCurrentState = 0;
draw();
mAreaTrigger = false;
}
inMouseEvent.updateAfterEvent();
}
}
}
/com/biogame/Doors.as
package com.biogame {
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Doors extends InteractiveElement {
private var mDuration:Number = 2;
public function Doors(inGame:Game):void {
mGame = inGame;
determineButtonMode();
if(!mGame.mIsPlayer) {
visible = false;
}
}
public function initialize():void {
mStates.push('toggle');
}
public function toggle():void {
if(mEnabled && !mPaused) {
disable();
mTimers['toggle'] = new Timer(mDuration * 1000, 1);
mTimers['toggle'].addEventListener(TimerEvent.TIMER_COMPLETE, toggleEnd);
mTimers['toggle'].start();
}
}
public function toggleEnd(inTimerEvent:TimerEvent):void {
if(!mGame.mElementTractor.mMowing) {
enable();
}
}
}
}
/com/biogame/Element.as
package com.biogame {
import flash.display.MovieClip;
import flash.geom.Point;
import flash.events.Event;
public class Element extends MovieClip {
public var mGame:Game;
public var mTimers:Object = new Object();
public var mTweens:Object = new Object();
public var mCurrentState:Number = 0;
public var mStates:Array = new Array();
public var mHighlighted:Boolean = false;
public var mPosition:Point;
public var mRemoved:Boolean = false;
public var mPaused:Boolean = false;
public var mPerspective:Boolean = false;
public var mPerspectiveMin:Number = 0.15;
public function Element():void {
cacheAsBitmap = true;
stop();
}
public function setState(inState:int):void {
mCurrentState = inState;
draw();
}
public function draw():void {
if(mCurrentState in mStates) {
gotoAndStop(mStates[mCurrentState]);
}else if(mStates.length > 0) {
gotoAndStop(mStates[0]);
}
}
public function setIndex(inIndex:Number, inUseParent:Boolean=true):void {
if(parent) {
mGame.setIndex(this, inIndex, inUseParent);
}else{
trace('Incorrect parent relationship for ' + this);
}
}
public function getIndex():Number {
if(parent) {
return parent.getChildIndex(this);
}else{
return -1;
}
}
public function setRandomFlip():void {
if(Math.round(Math.random()) == 0) {
scaleX *= -1;
}
}
public function setPerspectiveInvoke(inEvent:Event):void {
if(mPerspective) {
setPerspective();
}
}
public function setPerspective():void {
if(!mPerspective) {
return;
}
var correctedY = y - 300;
if(correctedY < 1) {
correctedY = 1;
}
var newScale = correctedY / 400;
setScale(newScale);
}
public function setPosition(inX:Number, inY:Number, inMirrored:Boolean=false):void {
if(inMirrored && !mGame.mIsPlayer) {
inX = 500 - inX;
}
x = inX;
y = inY;
mPosition = new Point(x, y);
}
public function setScale(inScale:Number):void {
if(inScale < mPerspectiveMin) {
inScale = mPerspectiveMin;
}
scaleX = (scaleX < 0) ? -1 * inScale : inScale;
scaleY = (scaleY < 0) ? -1 * inScale : inScale;
}
public function highlight(inApply:Boolean):void {
if(inApply && !mRemoved && !mPaused) {
filters = [BioGame(root).mHighlight];
mHighlighted = true;
}else{
filters = new Array();
mHighlighted = false;
}
}
function pause():void {
if(mRemoved) {
return;
}
if(mPaused) {
return;
}
mPaused = true;
for each(var tween in mTweens) {
tween.stop();
}
for each(var timer in mTimers) {
timer.stop();
}
}
function resume():void {
if(mRemoved) {
return;
}
if(!mPaused) {
return;
}
mPaused = false;
for each(var tween in mTweens) {
tween.resume();
}
for each(var timer in mTimers) {
timer.start();
}
}
function remove():void {
mRemoved = true;
for each(var tween in mTweens) {
tween.stop();
tween = null;
}
for each(var timer in mTimers) {
timer.stop();
timer = null;
}
if(parent) {
parent.removeChild(this);
}
}
public function debug():String {
return this.name + ' ' + this + '; Paused: ' + mPaused + '; Removed: ' + mRemoved + '; Tweens: ' + mTweens + '; Timers: ' + mTimers + ';';
}
}
}
/com/biogame/Game.as
package com.biogame {
import flash.display.Sprite;
import flash.geom.Point;
import flash.text.TextField;
import flash.utils.Timer;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.utils.setTimeout;
public class Game extends Sprite {
private var mBioGame:BioGame;
public var mIsPlayer:Boolean = false;
public var mSlaughter:Number = 0;
public var mMoney:Number = 2000;
public var mFood:Number = 50;
public var mCowsMax:Number = 0;
public var mCows:Number = mCowsMax;
public var mPriceFood:Number = 40;
public var mPriceCow:Number = 200;
public var mTxtMoney:TextField;
public var mTxtFood:TextField;
public var mTxtCows:TextField;
public var mTxtSlaughter:TextField;
public var mElementSilo:Silo;
public var mElementDoors:Doors;
public var mElementTractor:Tractor;
public var mElementBuyFood:BuyFood;
public var mElementBuyCow:BuyCow;
public var mFieldCows:Sprite = new Sprite();
public var mFieldGrass:Sprite = new Sprite();
public var mListGrass:Array = new Array();
public var mListCows:Array = new Array();
public var mListSpawns:Array = new Array();
public var mListPositionsCows:Array = new Array();
public var mListPositionsGrass:Array = new Array();
public var mSack:Sack;
public var mInsidePoint:Point;
public var mInsideTimer:Timer;
public var mInside:Boolean = false;
public function Game(inIsPlayer:Boolean=false):void {
mIsPlayer = inIsPlayer;
if(!mIsPlayer) {
setupOpponent();
}
}
public function initialize(inTxtMoney:TextField, inTxtFood:TextField, inTxtCows:TextField, inTxtSlaughter:TextField):void {
mBioGame = BioGame(parent);
mTxtMoney = inTxtMoney;
mTxtFood = inTxtFood;
mTxtCows = inTxtCows;
mTxtSlaughter = inTxtSlaughter;
if(mIsPlayer) {
x = 500;
mInsidePoint = new Point(62, -40);
}else{
x = 0;
mInsidePoint = new Point(238, -40);
}
y = 0;
setupElements();
setupGrass();
setupCows();
addChild(mFieldGrass);
addChild(mFieldCows);
update();
}
public function setupElements():void {
mElementSilo = new Silo(this);
mElementSilo.setPosition(280, 247, true);
addChild(mElementSilo);
mElementSilo.initialize();
mElementTractor = new Tractor(this);
mElementTractor.setPosition(60, 300, true);
addChild(mElementTractor);
mElementTractor.initialize();
mElementDoors = new Doors(this);
mElementDoors.setPosition(416, 242, true);
addChild(mElementDoors);
mElementDoors.initialize();
mElementBuyFood = new BuyFood(this);
mElementBuyFood.setPosition(270, 120, true);
addChild(mElementBuyFood);
mElementBuyFood.initialize();
mElementBuyCow = new BuyCow(this);
mElementBuyCow.setPosition(370, 120, true);
addChild(mElementBuyCow);
mElementBuyCow.initialize();
}
public function setupControls():void {
mElementSilo.addEventListener(MouseEvent.MOUSE_DOWN, actionFoodInvoke);
mElementTractor.addEventListener(MouseEvent.CLICK, actionMowInvoke);
mElementDoors.addEventListener(MouseEvent.CLICK, actionDoorsInvoke);
mElementBuyFood.addEventListener(MouseEvent.CLICK, actionBuyFoodInvoke);
mElementBuyCow.addEventListener(MouseEvent.CLICK, actionBuyCowInvoke);
}
private function moveChildToTop(inChild:DisplayObject):void {
setChildIndex(inChild, numChildren-1);
}
private function moveChildToBack(inChild:DisplayObject):void {
setChildIndex(inChild, 0);
}
public function update():void {
mTxtMoney.text = '€' + String(mMoney);
mTxtFood.text = String(mFood);
mTxtCows.text = String(mCows);
mTxtSlaughter.text = String(mSlaughter);
if(mFood > 0 && !mInside) {
mElementSilo.enable();
}else{
mElementSilo.disable();
}
if(mMoney >= mPriceFood) {
mElementBuyFood.enable();
}else{
mElementBuyFood.disable();
}
if(mCows < mCowsMax && mMoney >= mPriceCow && !mInside) {
mElementBuyCow.enable();
}else{
mElementBuyCow.disable();
}
}
private function actionFoodInvoke(inMouseEvent:MouseEvent):void {
actionFood(inMouseEvent);
}
private function actionMowInvoke(inMouseEvent:MouseEvent):void {
actionMow();
}
private function actionDoorsInvoke(inMouseEvent:MouseEvent):void {
actionDoors();
}
private function actionBuyFoodInvoke(inMouseEvent:MouseEvent):void {
actionBuyFood();
}
private function actionBuyCowInvoke(inMouseEvent:MouseEvent):void {
actionBuyCow();
}
public function actionFood(inMouseEvent:MouseEvent):void {
if(mIsPlayer && mElementSilo.mEnabled && !mElementSilo.mPaused) {
var point:Point = globalToLocal(new Point(inMouseEvent.stageX, inMouseEvent.stageY));
mSack = new Sack(this, point.x, point.y);
mSack.initialize();
addChild(mSack);
}
}
public function actionFoodIndividually(inCow:Cow):void {
mFood = Cow(inCow).feed(mFood);
update();
}
public function actionMow():void {
if(mInside && mElementTractor.mEnabled && !mElementTractor.mPaused) {
moveChildToTop(mElementTractor);
mElementDoors.disable();
mElementTractor.mowStart();
}
}
public function actionMowResult():void {
moveChildToBack(mElementTractor);
mElementTractor.scaleX *= -1;
var mowedAmount:Number = 0;
for each(var grass:Grass in mListGrass) {
mowedAmount += grass.mow();
}
mElementDoors.enable();
if(mIsPlayer) {
mBioGame.mPopup.show(Popup.MOW, new Array());
}else{
mMoney += 400;
}
}
private function actionInsideResult(inTimerEvent:TimerEvent):void {
if(mCows > 0) {
mBioGame.mPopup.show(Popup.INSIDE, new Array());
}
}
public function actionDoors():void {
if(mElementDoors.mEnabled && !mElementDoors.mPaused) {
Sounds.play(new SndDoor3());
mInside = !mInside;
if(mInside) {
if(mIsPlayer) {
mInsideTimer = new Timer(15000, 1);
mInsideTimer.addEventListener(TimerEvent.TIMER_COMPLETE, actionInsideResult);
mInsideTimer.start();
}
mElementSilo.disable();
mElementTractor.enable();
}else{
if(mIsPlayer) {
mInsideTimer.reset();
}
mElementSilo.enable();
mElementTractor.disable();
}
mElementDoors.toggle();
for each(var cow in mListCows) {
cow.walk();
}
update();
}
}
public function actionBuyFood():void {
if(mElementBuyFood.mEnabled && !mElementBuyFood.mPaused && mMoney >= mPriceFood) {
if(mIsPlayer) {
Sounds.play(new SndKaChing());
}
mMoney -= mPriceFood;
mFood += 10;
update();
}
}
public function actionBuyCow():void {
if(mElementBuyCow.mEnabled && !mElementBuyCow.mPaused && mMoney >= mPriceCow) {
if(mIsPlayer) {
Sounds.play(new SndKaChing());
}
mMoney -= mPriceCow;
setupCow();
reorderIndices();
update();
}
}
public function pause():void {
mElementTractor.pause();
mElementDoors.pause();
mElementSilo.pause();
mElementBuyFood.pause();
mElementBuyCow.pause();
if(mIsPlayer && mInsideTimer) {
mInsideTimer.stop();
}
for each(var cow in mListCows) {
cow.pause();
}
for each(var grass in mListGrass) {
grass.pause();
}
}
public function resume():void {
mElementTractor.resume();
mElementDoors.resume();
mElementSilo.resume();
mElementBuyFood.resume();
mElementBuyCow.resume();
if(mIsPlayer && mInside && mInsideTimer && mInsideTimer.currentCount < mInsideTimer.repeatCount) {
mInsideTimer.start();
}
for each(var cow in mListCows) {
cow.resume();
}
for each(var grass in mListGrass) {
grass.resume();
}
}
public function setIndex(inChild:DisplayObject, inIndex:Number, inUseParent:Boolean=true) {
if(inIndex < 0) {
inIndex = 0;
}
if(inUseParent) {
if(inIndex > inChild.parent.numChildren - 1) {
inIndex = inChild.parent.numChildren - 1;
}
inChild.parent.setChildIndex(inChild, inIndex);
}else{
if(inIndex > numChildren - 1) {
inIndex = numChildren - 1;
}
setChildIndex(inChild, inIndex);
}
}
public function reorderIndices():void {
var childArray:Array = new Array();
for(var i=0; i
childArray.push(mFieldCows.getChildAt(i));
}
var sortedArray:Array = childArray.sortOn('y');
for(i=0; i
setIndex(sortedArray[i], i);
}
}
private function setupOpponent():void {
mPriceCow = 100;
mPriceFood = 20;
}
public function removeCow(inSpot:Number):void {
mListSpawns.push(inSpot);
mCows--;
update();
}
private function setupCow():void {
if(mListSpawns.length > 0) {
var position = mListSpawns.shift();
var array = mListPositionsCows[position] as Array;
var cow = new Cow();
cow.mGame = this;
cow.mSpot = position;
cow.setPosition(array[0], array[1]);
cow.setPerspective();
cow.setRandomFlip();
mListCows.push(cow);
mFieldCows.addChild(cow);
cow.setIndex(array[2]);
cow.initialize();
mCows++;
}
}
private function setupCows():void {
mCowsMax = mListPositionsCows.length;
for(var i=0; i
setupCow();
}
}
public function setupTruck(inCow:Cow):Truck {
var truck:Truck = new Truck(this, inCow);
mFieldCows.addChild(truck);
var index:Number = inCow.getIndex();
truck.setIndex(index + 1, true);
return truck;
}
private function setupGrass():void {
for each(var array in mListPositionsGrass) {
var grass = new Grass();
grass.mGame = this;
grass.setPosition(array[0], array[1]);
grass.setPerspective();
grass.setRandomFlip();
mListGrass.push(grass);
mFieldGrass.addChild(grass);
grass.setIndex(array[2]);
grass.initialize();
}
}
public function setupPosition(inChild:Object, inIndex:Number):void {
var inX = inChild.x;
if(mIsPlayer) {
inX -= 500;
}
var inY = inChild.y;
var inArray = new Array(inX, inY, inIndex);
if(inChild is Cow) {
mListSpawns.push(mListPositionsCows.length);
mListPositionsCows.push(inArray);
}else{
mListPositionsGrass.push(inArray);
}
}
}
}
/com/biogame/Grass.as
package com.biogame {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
public class Grass extends Element {
private var mGrowthSpeed:Number = 15000;
public function Grass():void {
cacheAsBitmap = true;
mPerspective = true;
mPerspectiveMin = 0.1;
}
public function initialize():void {
mStates.push('grass0');
mStates.push('grass1');
mStates.push('grass2');
mStates.push('grass3');
mStates.push('grass4');
growTimer();
draw();
}
public function mow():Number {
if(mCurrentState >= 2) {
var returnState:Number = mCurrentState;
shrink();
return returnState;
}else{
return 0;
}
}
private function growTimer():void {
if(mTimers['growth']) {
mTimers['growth'].removeEventListener(TimerEvent.TIMER_COMPLETE, growing);
}
mTimers['growh'] = new Timer(3000 + Math.random() * mGrowthSpeed, 1);
mTimers['growh'].addEventListener(TimerEvent.TIMER_COMPLETE, growing);
mTimers['growh'].start();
}
private function growing(inTimerEvent:TimerEvent):void {
grow();
}
private function grow():void {
if(mCurrentState < mStates.length - 1) {
mCurrentState++;
draw();
}
growTimer();
}
private function shrink():void {
mCurrentState = 0;
draw();
}
}
}
/com/biogame/InteractiveElement.as
package com.biogame {
import flash.events.MouseEvent;
public class InteractiveElement extends Element {
public var mEnabled:Boolean = true;
public function InteractiveElement():void {
mStates.push('enabled');
mStates.push('disabled');
}
public function enableButtonMode():void {
buttonMode = true;
addEventListener(MouseEvent.MOUSE_OVER, interactionOver);
addEventListener(MouseEvent.MOUSE_OUT, interactionOut);
}
public function determineButtonMode():void {
if(mGame.mIsPlayer) {
enableButtonMode();
}else{
buttonMode = false;
}
}
function interactionOver(inMouseEvent:MouseEvent):void {
if(!BioGame(root)) {
return;
}
if(mEnabled && !mPaused) {
BioGame(root).mCursor.setState(1);
highlight(true);
}else{
BioGame(root).mCursor.setState(2);
highlight(false);
}
}
function interactionOut(inMouseEvent:MouseEvent):void {
if(!BioGame(root)) {
return;
}
BioGame(root).mCursor.setState(0);
highlight(false);
}
override function resume():void {
super.resume();
if(mEnabled) {
enable();
}
}
function enable():void {
mEnabled = true;
mCurrentState = 0;
enabled = true;
draw();
}
function disable():void {
mEnabled = false;
mCurrentState = 1;
if(mHighlighted) {
highlight(false);
BioGame(root).mCursor.setState(2);
}
enabled = false;
draw();
}
}
}
/com/biogame/Popup.as
package com.biogame {
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.easing.*;
import com.exanimo.transitions.GCSafeTween;
public class Popup extends Element {
public static const PERSON:Class = PopupPerson;
public static const MISSION:Class = PopupMission;
public static const START:Class = PopupStart;
public static const INTRO:Class = PopupIntro;
public static const INFO:Class = PopupInfo;
public static const DEAD:Class = PopupDead;
public static const MOW:Class = PopupMow;
public static const ILL:Class = PopupIll;
public static const INSIDE:Class = PopupInside;
public static const END:Class = PopupEnd;
public static const MEAT:Class = PopupMeat;
private var mTimer:Timer;
private var mStarted:Boolean = false;
public var mActive:Boolean = false;
private var mOptions:Array;
private var mPopup:MovieClip;
private var mOverlay:Sprite;
private var mOverlayTween:GCSafeTween;
private var mOpponentCows:Number;
private var mOpponentPrice:Number;
private var mOpponentSum:Number;
private var mPlayerCows:Number;
private var mPlayerPrice:Number;
private var mPlayerSum:Number;
public function Popup():void {
visible = false;
}
public function initialize():void {
mOverlay = new Sprite();
mOverlay.graphics.beginFill(0xF0EED8, 1.0);
mOverlay.graphics.drawRect(-0.5 * 1000, -0.5 * 706, 1000, 706);
mOverlay.graphics.endFill();
mOverlay.alpha = 1.0;
addChild(mOverlay);
}
private function fadeIn():void {
mOverlayTween = new GCSafeTween(mOverlay, 'alpha', Regular.easeIn, mOverlay.alpha, 0.6, 1, true);
}
private function fadeOut():void {
// mOverlayTween = new GCSafeTween(mOverlay, 'alpha', Regular.easeIn, mOverlay.alpha, 0.0, 1, true);
}
private function person(inMouseEvent:MouseEvent):void {
BioGame(root).mName = mPopup.mName.text;
show(MISSION, new Array());
}
private function personEmpty(inMouseEvent:MouseEvent):void {
if(mPopup.mName.text == 'Voornaam') {
mPopup.mName.text = '';
}
}
private function fillInName(inString:String):String {
var pattern:RegExp = /###/;
return inString.replace(pattern, BioGame(root).mName);
}
private function mission(inMouseEvent:MouseEvent):void {
show(INTRO, new Array());
}
private function intro(inTimerEvent:TimerEvent):void {
introNext();
}
public function introSkip(inMouseEvent:MouseEvent):void {
introNext();
}
private function introNext():void {
if(!mStarted) {
mStarted = true;
stage.frameRate = 59;
show(START, new Array());
}
}
private function start(inMouseEvent:MouseEvent):void {
hide();
}
private function mowFood(inMouseEvent:MouseEvent):void {
Sounds.play(new SndFood());
BioGame(root).mGamePlayer.mFood += 28;
BioGame(root).mGamePlayer.update();
hide();
}
private function mowMoney(inMouseEvent:MouseEvent):void {
Sounds.play(new SndKaChing());
BioGame(root).mGamePlayer.mMoney += 300;
BioGame(root).mGamePlayer.update();
hide();
}
private function ill(inMouseEvent:MouseEvent):void {
BioGame(root).mGamePlayer.mMoney -= 100;
Sounds.play(new SndKaChing());
if(BioGame(root).mGamePlayer.mMoney < 0) {
BioGame(root).mGamePlayer.mMoney = 0;
}
BioGame(root).mGamePlayer.update();
hide();
}
private function dead(inMouseEvent:MouseEvent):void {
BioGame(root).mGamePlayer.mMoney -= 300;
Sounds.play(new SndKaChing());
if(BioGame(root).mGamePlayer.mMoney < 0) {
BioGame(root).mGamePlayer.mMoney = 0;
}
BioGame(root).mGamePlayer.update();
hide();
}
private function inside(inMouseEvent:MouseEvent):void {
BioGame(root).mGamePlayer.mMoney -= 200;
Sounds.play(new SndKaChing());
if(BioGame(root).mGamePlayer.mMoney < 0) {
BioGame(root).mGamePlayer.mMoney = 0;
}
hide();
}
private function end(inMouseEvent:MouseEvent):void {
if(mPopup.mButton.mEnabled) {
show(MEAT, new Array());
}
}
private function endPriceUp(inMouseEvent:MouseEvent):void {
Sounds.play(new SndKaChing());
mPlayerPrice++;
endPriceUpdate();
}
private function endPriceDown(inMouseEvent:MouseEvent):void {
if(mPlayerPrice > mOpponentPrice) {
Sounds.play(new SndKaChing());
mPlayerPrice--;
}
endPriceUpdate();
}
private function endPriceUpdate():void {
if(mPlayerPrice <= mOpponentPrice) {
mPopup.mDown.disable();
}else{
mPopup.mDown.enable();
}
mPlayerSum = mPlayerPrice * mPlayerCows * 900;
if(mPlayerSum >= mOpponentSum) {
mPopup.mButton.enable();
}else{
mPopup.mButton.disable();
}
mPopup.mPlayerSum.text = '€' + mPlayerSum + ',00';
mPopup.mPlayerPrice.text = '€' + mPlayerPrice + ',00';
}
private function erase():void {
if(mPopup) {
BioGame(root).mCursor.setState(0);
removeChild(mPopup);
mPopup = null;
}
}
public function add(inClass:Class):void {
erase();
mPopup = new inClass();
switch(inClass) {
case PERSON:
mPopup.mName.addEventListener(MouseEvent.CLICK, personEmpty);
mPopup.mButton.set('Verder');
mPopup.mButton.addEventListener(MouseEvent.CLICK, person);
break;
case MISSION:
mPopup.mContent.text = fillInName(mPopup.mContent.text);
mPopup.mButton.set('Verder');
mPopup.mButton.addEventListener(MouseEvent.CLICK, mission);
break;
case INTRO:
mTimer = new Timer(48500, 1);
mTimer.addEventListener(TimerEvent.TIMER_COMPLETE, intro);
mTimer.start();
mPopup.play();
mPopup.mButton.set('Overslaan');
mPopup.mButton.addEventListener(MouseEvent.CLICK, introSkip);
stage.frameRate = 2;
break;
case START:
mPopup.mButton.set('Start');
mPopup.mButton.addEventListener(MouseEvent.CLICK, start);
break;
case DEAD:
mPopup.mButton.set('OK');
mPopup.mButton.addEventListener(MouseEvent.CLICK, dead);
break;
case MOW:
mPopup.mFoodButton.set('Voedsel');
mPopup.mFoodButton.addEventListener(MouseEvent.CLICK, mowFood);
mPopup.mMoneyButton.set('Geld');
mPopup.mMoneyButton.addEventListener(MouseEvent.CLICK, mowMoney);
break;
case ILL:
mPopup.mButton.set('OK');
mPopup.mButton.addEventListener(MouseEvent.CLICK, ill);
break;
case INSIDE:
mPopup.mButton.set('OK');
mPopup.mButton.addEventListener(MouseEvent.CLICK, inside);
break;
case END:
mOpponentCows = BioGame(root).mGameOpponent.mSlaughter;
if(mOpponentCows < 1) {
mOpponentCows = 1;
}
mOpponentPrice = 2;
mOpponentSum = mOpponentCows * 900 * mOpponentPrice;
mPopup.mOpponentCows.text = mOpponentCows;
mPopup.mOpponentMeat.text = mOpponentCows * 900;
mPopup.mOpponentPrice.text = '€' + mOpponentPrice + ',00';
mPopup.mOpponentSum.text = '€' + mOpponentSum + ',00';
mPlayerCows = BioGame(root).mGamePlayer.mSlaughter;
if(mPlayerCows < 1) {
mPlayerCows = 1;
}
mPlayerPrice = 2;
mPopup.mPlayerCows.text = mPlayerCows;
mPopup.mPlayerMeat.text = mPlayerCows * 900;
endPriceUpdate();
mPopup.mName.text = BioGame(root).mName;
mPopup.mUp.addEventListener(MouseEvent.CLICK, endPriceUp);
mPopup.mDown.addEventListener(MouseEvent.CLICK, endPriceDown);
mPopup.mButton.set('Vaststellen');
mPopup.mButton.addEventListener(MouseEvent.CLICK, end);
break;
case MEAT:
mPopup.mPrice.text = '€' + mPlayerPrice + ',00';
break;
}
addChild(mPopup);
}
public function show(inClass:Class, inOptions:Array):void {
visible = true;
fadeIn();
add(inClass);
mOptions = inOptions;
mActive = true;
BioGame(root).pause();
}
public function hide():void {
erase();
visible = false;
mActive = false;
mOverlay.alpha = 0.0;
BioGame(root).resume();
}
}
}
/com/biogame/PopupAdjuster.as
package com.biogame {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.text.TextField;
public class PopupAdjuster extends InteractiveElement {
public function PopupAdjuster():void {
enableButtonMode();
}
}
}
/com/biogame/PopupButton.as
package com.biogame {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.text.TextField;
public class PopupButton extends InteractiveElement {
private var mSprite:Sprite;
public function PopupButton():void {
enableButtonMode();
mSprite = new Sprite();
mSprite.graphics.beginFill(0xFFFFFF, 0.01);
mSprite.graphics.drawRect(-1 * width / 2, -1 * height / 2, width, height);
mSprite.graphics.endFill();
addChild(mSprite);
}
public function set(inText:String):void {
mText.text = inText;
}
}
}
/com/biogame/Sack.as
package com.biogame {
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.events.MouseEvent;
import flash.events.Event;
public class Sack extends InteractiveElement {
private var mMoved:Boolean = false;
public function Sack(inGame:Game, inX:Number, inY:Number):void {
mGame = inGame;
cacheAsBitmap = true;
x = inX;
y = inY;
mPerspectiveMin = 0.2;
mPerspective = true;
setPerspective();
}
public function initialize():void {
startDrag(true, new Rectangle(40, 195, 430, 480));
addEventListener(MouseEvent.MOUSE_MOVE, update);
addEventListener(MouseEvent.MOUSE_UP, drop);
draw();
}
private function removeHighlights():void {
for each(var cow in mGame.mListCows) {
cow.highlight(false);
}
}
private function update(inMouseEvent:MouseEvent):void {
if(mRemoved) {
return;
}
mMoved = true;
var point:Point = mGame.localToGlobal(new Point(x, y));
var skipRest:Boolean = false;
for each(var cow in mGame.mListCows) {
if(!skipRest && !cow.mDead && cow.hitTestPoint(point.x, point.y, true)) {
cow.highlight(true);
skipRest = true;
}else{
cow.highlight(false);
}
}
setPerspective();
}
private function drop(inMouseEvent:MouseEvent):void {
if(!mMoved || mRemoved) {
return;
}
var point:Point = mGame.localToGlobal(new Point(x, y));
for each(var cow in mGame.mListCows) {
if(cow.hitTestPoint(point.x, point.y, true)) {
mGame.actionFoodIndividually(cow);
break;
}
}
mRemoved = true;
removeHighlights();
stopDrag();
if(parent) {
parent.removeChild(this);
}
}
}
}
/com/biogame/Silo.as
package com.biogame {
public class Silo extends InteractiveElement {
public function Silo(inGame:Game):void {
mGame = inGame;
determineButtonMode();
if(!mGame.mIsPlayer) {
visible = false;
}
}
public function initialize():void {
draw();
}
}
}
/com/biogame/Sounds.as
package com.biogame {
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.media.Sound;
import flash.media.SoundChannel;
public class Sounds {
private static var mSoundCounter:Number = 0;
private static var mSounds:Object = new Object();
public static function play(inSound:Sound, inObject:Object=null):void {
var addedIndex:Object;
if(!inObject) {
mSoundCounter++;
addedIndex = mSoundCounter;
}else{
addedIndex = inObject.name;
if(mSounds[addedIndex]) {
stop(addedIndex);
}
}
mSounds[addedIndex] = inSound.play();
}
public static function stop(inObject:Object):void {
if(mSounds[inObject]) {
SoundChannel(mSounds[inObject]).stop();
}
}
}
}
/com/biogame/Tractor.as
package com.biogame {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.events.Event;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import com.exanimo.transitions.GCSafeTween;
public class Tractor extends InteractiveElement {
public var mMowing:Boolean = false;
private var mMowingForward:Boolean = false;
private var mMowingDuration:Number = 1;
private var mMowingLines:Number = 8;
private var mMowingCurrentLine:Number = mMowingLines;
public function Tractor(inGame:Game):void {
mGame = inGame;
determineButtonMode();
mPerspective = true;
setPerspective();
if(mGame.mIsPlayer) {
scaleX *= -1;
}
disable();
}
public function initialize():void {
parent.setChildIndex(this, 0);
draw();
}
public function mowStart():void {
if(!mMowing && mEnabled && !mPaused) {
Sounds.play(new SndTractor());
mEnabled = false;
mMowing = true;
mow();
mAnimation.play();
}
}
private function mow():void {
if(!mMowing) {
return;
}
var positionHedge:Number;
var positionEdge:Number;
if(mGame.mIsPlayer) {
positionHedge = Math.floor(width / 2) * 1.2;
positionEdge = 500 + width;
}else{
positionHedge = 500 - Math.floor(width / 2) * 1.4;
positionEdge = -1 * width;
}
if(mMowingForward) {
mTweens['x'] = new GCSafeTween(this, 'x', None.easeNone, x, positionHedge, mMowingDuration, true);
}else{
mTweens['x'] = new GCSafeTween(this, 'x', None.easeNone, x, positionEdge, mMowingDuration, true);
}
mTweens['x'].addEventListener(TweenEvent.MOTION_FINISH, mowRowFinished);
}
private function mowRowFinished(inTweenEvent:TweenEvent):void {
if(!mMowing) {
return;
}
mMowingForward = !mMowingForward;
if(mMowingCurrentLine > 0) {
mMowingCurrentLine--;
y += (300 / mMowingLines);
setPerspective();
scaleX *= -1;
mow();
}else{
y = mPosition.y;
mMowingCurrentLine = mMowingLines;
mowFinished();
}
}
private function mowFinished():void {
if(mMowing) {
mAnimation.stop();
mMowingForward = !mMowingForward;
scaleX *= -1;
mEnabled = true;
setPerspective();
mTweens['x'] = new GCSafeTween(this, 'x', None.easeNone, x, mPosition.x, 1, true);
mMowing = false;
mGame.actionMowResult();
}
}
}
}
/com/biogame/Tree.as
package com.biogame {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
public class Tree extends Element {
public function Tree():void {
cacheAsBitmap = true;
initialize();
}
public function initialize():void {
mStates.push('spring');
mStates.push('summer');
mStates.push('autumn');
mStates.push('winter');
seasonStart();
draw();
}
private function seasonStart():void {
mTimers['seasonStart'] = new Timer(50000, 1);
mTimers['seasonStart'].addEventListener(TimerEvent.TIMER_COMPLETE, seasonTimer);
mTimers['seasonStart'].start();
}
private function seasonTimer(inTimerEvent:TimerEvent):void {
mTimers['seasonStart'] = null;
mTimers['season'] = new Timer(82000, 3);
mTimers['season'].addEventListener(TimerEvent.TIMER, seasonUpdate);
mTimers['season'].start();
}
private function seasonUpdate(inTimerEvent:TimerEvent):void {
if(mCurrentState < mStates.length - 1) {
mCurrentState++;
draw();
}
}
}
}
/com/biogame/Truck.as
package com.biogame{
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.geom.Point;
import com.exanimo.transitions.*;
public class Truck extends Element {
private var mCow:Cow;
private var mCowPosition:Point;
public function Truck(inGame:Game, inCow:Cow):void {
mGame = inGame;
mCow = inCow;
y = inCow.y;
mPerspective = true;
setPerspective();
var newX;
if (mGame.mIsPlayer) {
newX = 1000 + width;
} else {
newX = 0 - width;
}
var newY = y;
setPosition(newX, newY);
if (mGame.mIsPlayer) {
scaleX *= -1;
mCowPosition = new Point(mCow.x + 30, y);
} else {
mCowPosition = new Point(mCow.x - 20, y);
}
moveToCow();
Sounds.play(new SndTruck());
}
private function moveToCow():void {
mTweens['x'] = new GCSafeTween(this, 'x', Strong.easeOut, x, mCowPosition.x, 1, true);
mTweens['x'].addEventListener(TweenEvent.MOTION_FINISH, moveToButcher);
}
private function moveToButcher(inTweenEvent:TweenEvent):void {
mTweens['x'] = new GCSafeTween(this, 'x', Strong.easeIn, x, mPosition.x, 1, true);
mTweens['x'].addEventListener(TweenEvent.MOTION_FINISH, doneMoving);
}
private function doneMoving(inTweenEvent:TweenEvent):void {
mCow.remove();
remove();
}
}
}