Permalink
Browse files

it's cool

  • Loading branch information...
Bilkokuya committed Apr 27, 2012
1 parent e827a14 commit de61d9eef550e7bef2567cfe0785e35fdd0201ce
View
Binary file not shown.
@@ -69,7 +69,7 @@ package mutation.entity
food = new Resource(100, -0.1, 100);
money = new Resource(Math.random()*50, 1, 100);
- love = new Resource(Math.random()*50, 0, 100);
+ love = new Resource(Math.random()*50, 0.01, 100);
super();
if (stage) onInit();
@@ -83,6 +83,7 @@ package mutation.entity
addEventListener(MouseEvent.ROLL_OVER, onRollOver);
addEventListener(MouseEvent.ROLL_OUT, onRollOut);
+ moveAround(true);
}
// Updates the logic of this each frame, needs to be called by it's container
@@ -100,7 +101,7 @@ package mutation.entity
}
if (flagIsHungry) {
- draw(0x00FF66);
+ draw(0x006611);
}else {
draw(0x0066FF);
}
@@ -127,7 +128,7 @@ package mutation.entity
if (food.amount < 1) kill();
- popOut.update(food.amount ,money.amount ,level.experience);
+ popOut.update(nameString ,money.amount ,love.amount);
// Update position
if (canMove){
@@ -145,7 +146,6 @@ package mutation.entity
parent.setChildIndex(this, parent.numChildren - 1);
addChild(popOut);
canMove = false;
- Main.isPaused = true;
}
// Hide the stats display
@@ -156,7 +156,6 @@ package mutation.entity
scaleY = 1;
removeChild(popOut);
canMove = true;
- Main.isPaused = false;
}
// Feeds the bacteria, limiting to 100
@@ -199,9 +198,9 @@ package mutation.entity
}
// Moving around when there is no target
- private function moveAround():void
+ private function moveAround(forced:Boolean = false):void
{
- if (Math.random() < (DIRECTION_RATE)) {
+ if ((Math.random() < (DIRECTION_RATE)) || (forced)) {
var radians:Number = ((Math.random() - 0.5) * 2 * Math.PI);
moveAt(radians);
}
@@ -30,7 +30,7 @@ package mutation.entity
xSpeed = 0;
ySpeed = 0;
life = 4 * 30;
- radius = 6;
+ radius = 4 * (amount/100);
money = amount;
draw();
@@ -18,6 +18,8 @@ package mutation.entity
import mutation.events.FoodEvent;
import mutation.Main;
import mutation.ui.BacteriaDisplay;
+ import mutation.ui.NameBacteriaDisplay;
+ import mutation.ui.PopupDisplay;
import mutation.util.Keys;
import mutation.util.Util;
@@ -35,6 +37,7 @@ package mutation.entity
private var radius:int; // Radius of movement for the testtube
private var flagIsClicked:Boolean = false;
+ private var popup:NameBacteriaDisplay;
// Constructor: default
public function TestTube(x:Number = 200, y:Number = 200, radius:int = 50) {
@@ -45,14 +48,10 @@ package mutation.entity
bacterias = new Array();
foods = new Array();
items = new Array();
+ popup = new NameBacteriaDisplay(-3*radius/4, 0);
+
+ addChild(popup);
- // Temporay set up the bacteria to test
- for (var i:int = 0; i < 5; i++) {
- var x:Number = (Math.random() - 0.5) * 5;
- var y:Number = (Math.random() - 0.5) * 5;
- spawnBacteria(x, y);
- }
-
draw();
super();
@@ -72,6 +71,11 @@ package mutation.entity
addEventListener(ItemEvent.DEATH, onItemDeath);
addEventListener(ItemEvent.PRODUCE, onBacteriaProduce);
addEventListener(BacteriaEvent.BREED, onBacteriaBreed);
+ popup.addEventListener(BacteriaEvent.COMPLETE, onBacteriaNamed);
+
+ popup.display(new Bacteria(0,0,5));
+ Main.isPaused = true;
+ removeEventListener(MouseEvent.CLICK, onClick);
}
@@ -154,6 +158,14 @@ package mutation.entity
}
}
+ private function onBacteriaNamed(e:BacteriaEvent):void
+ {
+ popup.hide();
+ Main.isPaused = false;
+ addEventListener(MouseEvent.CLICK, onClick);
+ spawnBacteria(e.bacteria);
+ }
+
// Called when a bacteria produces something
private function onBacteriaProduce(e:ItemEvent):void
{
@@ -164,22 +176,24 @@ package mutation.entity
// Bacteria created/ mutated function
private function onBacteriaBreed(e:BacteriaEvent):void
{
- spawnBacteria(e.bacteria.x, e.bacteria.y);
+ addChildAt(popup, numChildren - 1);
+ popup.display(new Bacteria(e.bacteria.x, e.bacteria.y,e.bacteria.radius));
+ Main.isPaused = true;
+ removeEventListener(MouseEvent.CLICK, onClick);
}
- private function spawnBacteria(x:Number, y:Number):void
+ private function spawnBacteria(bacteria:Bacteria):void
{
if (bacteriaCount > MAX_BACTERIA) return;
bacteriaCount++;
- var bacteria:Bacteria = new Bacteria(x, y);
bacterias.push(bacteria);
addChild(bacteria);
}
// Feeds the bacteria when the testTube is clicked on
- private function onClick(e:MouseEvent):void {
-
+ private function onClick(e:MouseEvent):void
+ {
flagIsClicked = true;
}
@@ -8,6 +8,7 @@ package mutation.events
public static const DEATH:String = "BACTERIA_DEATH";
public static const PRODUCE:String = "BACTERIA_PRODUCE";
public static const BREED:String = "BACTERIA_BREED";
+ public static const COMPLETE:String = "BACTERIA_COMPLETE";
public var bacteria:Bacteria;
@@ -6,31 +6,29 @@ package mutation.ui
import flash.text.TextFormat;
import mutation.entity.Bacteria;
- public class BacteriaDisplay extends Sprite
+ public class BacteriaDisplay extends PopupDisplay
{
private var nameField:TextField;
private var foodField:TextField;
private var productionField:TextField;
- private var boxWidth_:int;
- private var boxHeight_:int;
- private var arrowWidth_:int;
- private var arrowHeight_:int;
-
- public function BacteriaDisplay(x:int, y:int, width:int, height:int, length:int = 10, thickness:int = 20)
- {
- this.x = x;
- this.y = y;
- boxWidth_ = width;
- boxHeight_ = height;
- arrowWidth_ = length;
- arrowHeight_ = thickness;
-
- visible = false;
-
+ public function BacteriaDisplay(x:Number, y:Number, width:Number, height:Number, length:Number = 10, thickness:Number = 20)
+ {
nameField = new TextField();
foodField = new TextField();
productionField = new TextField();
+
+
+ super(x, y, width, height, length, thickness);
+ if (stage) onInit();
+ else addEventListener(Event.ADDED_TO_STAGE, onInit)
+ }
+
+ private function onInit(e:Event = null):void
+ {
+ addChild(nameField);
+ addChild(foodField);
+ addChild(productionField);
var format:TextFormat = new TextFormat();
format.size = 12;
@@ -49,63 +47,15 @@ package mutation.ui
productionField.x = arrowWidth_;
productionField.y = (-boxHeight_/2) + 32;
- super();
- if (stage) onInit();
- else addEventListener(Event.ADDED_TO_STAGE, onInit)
- }
-
- private function onInit(e:Event = null):void
- {
- addChild(nameField);
- addChild(foodField);
- addChild(productionField);
-
- draw();
-
removeEventListener(Event.ADDED_TO_STAGE, onInit);
}
- public function show():void
- {
- this.visible = true;
- }
- public function hide():void
- {
- this.visible = false;
- }
-
- public function update(names:Number, food:Number, production:Number):void
+ public function update(names:String, food:Number, production:Number):void
{
- nameField.text = "DNA: " + names.toFixed(0);
- foodField.text = "Gen: " + food.toFixed(0);
- productionField.text = "PAPS: " + production.toFixed(0);
- }
-
- private function draw():void
- {
- // orange surround
- graphics.beginFill(0xFF6600, 0.7);
- graphics.drawRoundRect( arrowWidth_ - 2, (-boxHeight_/2) - 2, boxWidth_ + 4, boxHeight_ + 4, 11);
- graphics.endFill();
-
- //orange triangle to bacteria
- graphics.lineStyle();
- graphics.beginFill(0xFF6600, 0.7);
- graphics.moveTo(0, 0);
- graphics.lineTo((arrowWidth_) - 2, -arrowHeight_/2);
- graphics.lineTo((arrowWidth_) - 2, arrowHeight_/2);
- graphics.lineTo(0, 0);
- graphics.endFill();
-
-
- // white background to make text obvious
- graphics.beginFill(0xFFFFFF, 0.7);
- graphics.drawRoundRect(arrowWidth_, -boxHeight_/2, boxWidth_, boxHeight_, 10);
- graphics.endFill();
-
-
+ nameField.text = "Name: " + names;
+ foodField.text = "Money: " + food.toFixed(0);
+ productionField.text = "Love: " + production.toFixed(0);
}
-
}
}
@@ -0,0 +1,89 @@
+package mutation.ui
+{
+ import flash.display.Sprite;
+ import flash.events.Event;
+ import flash.events.KeyboardEvent;
+ import flash.text.TextField;
+ import flash.text.TextFieldType;
+ import flash.text.TextFieldAutoSize;
+ import flash.events.FocusEvent;
+ import flash.ui.Keyboard;
+ import mutation.entity.Bacteria;
+ import mutation.events.BacteriaEvent;
+
+ public class NameBacteriaDisplay extends PopupDisplay
+ {
+ public var infoOut:TextField;
+ public var nameInput:TextField;
+ public var submitOut:TextField;
+ public var submitButton:Sprite;
+ private var bacteria:Bacteria = new Bacteria(0,0,5);
+
+ public function NameBacteriaDisplay(x:Number = 0, y:Number = 0)
+ {
+ infoOut = new TextField();
+ nameInput = new TextField();
+ submitOut = new TextField();
+ submitButton = new Sprite();
+
+ infoOut.text = "Congratulations! \n" +
+ "A new Bacteria has been born! \n" +
+ "Let's give it a name.";
+ infoOut.y = -50;
+ infoOut.width = boxWidth_;
+ infoOut.multiline = true;
+ infoOut.autoSize = TextFieldAutoSize.LEFT;
+
+ nameInput.type = TextFieldType.INPUT;
+ nameInput.text = "Name...";
+ nameInput.border = true;
+ nameInput.y = 10;
+ nameInput.x = 25;
+ nameInput.multiline = false;
+ nameInput.background = true;
+ nameInput.backgroundColor = 0xDDDDDD;
+ nameInput.width = 100;
+ nameInput.height = 20;
+ nameInput.restrict = "a-zA-Z .";
+
+
+ super(x, y, 150, 100, 0, 0);
+ if (stage) onInit();
+ else addEventListener(Event.ADDED_TO_STAGE, onInit);
+ }
+
+ public function onInit(e:Event = null):void
+ {
+ addChild(infoOut);
+ addChild(nameInput);
+ addChild(submitOut);
+ addChild(submitButton);
+
+ removeEventListener(Event.ADDED_TO_STAGE, onInit);
+ nameInput.addEventListener(FocusEvent.FOCUS_IN, onFocus);
+ nameInput.addEventListener(KeyboardEvent.KEY_UP, onEnter);
+ }
+
+ private function onFocus(e:FocusEvent):void
+ {
+ nameInput.text = "";
+ }
+
+ private function onEnter(e:KeyboardEvent):void
+ {
+ if (e.keyCode == Keyboard.ENTER) {
+ bacteria.nameString = nameInput.text;
+ dispatchEvent(new BacteriaEvent(BacteriaEvent.COMPLETE, bacteria, true));
+ }
+ }
+
+ public function display(bacteria:Bacteria):void
+ {
+ visible = true;
+ nameInput.text = "Name...";
+ this.bacteria = bacteria;
+
+ }
+ }
+
+}
Oops, something went wrong.

0 comments on commit de61d9e

Please sign in to comment.