Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.*;
- import flash.events.*;
- import flash.ui.Keyboard;
- public class Tridraw extends MovieClip {
- public function Tridraw() {
- stage.addEventListener(MouseEvent.MOUSE_DOWN, clicked);
- stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
- var infoScreen:Info = new Info();
- stage.addChild(infoScreen);
- infoScreen.x=stage.stageWidth/2-infoScreen.width/2;
- infoScreen.y=stage.stageHeight/2-infoScreen.height/2;
- }
- private var points:int=0;
- private var newGame:Boolean=true;
- private var colors:Boolean=false;
- private var p1x:int=0;
- private var p1y:int=0;
- private var p2x:int=0;
- private var p2y:int=0;
- private var p3x:int=0;
- private var p3y:int=0;
- private var shade:int=0;
- private function clicked(e:MouseEvent):void {
- if (newGame) {
- stage.removeChildAt(1);
- newGame=false;
- }
- p3x=p2x;
- p3y=p2y;
- p2x=p1x;
- p2y=p1y;
- p1x=stage.mouseX;
- p1y=stage.mouseY;
- points++;
- if (points>2) {
- var triangleShape:Shape = new Shape();
- stage.addChild(triangleShape);
- if (colors) {
- triangleShape.graphics.beginFill(Math.round(Math.random()*0xFFFFFF));
- } else {
- shade=Math.round(Math.random()*200)+55;
- triangleShape.graphics.beginFill(rgb2hex(shade,shade,shade));
- }
- triangleShape.graphics.moveTo(p3x, p3y);
- triangleShape.graphics.lineTo(p2x, p2y);
- triangleShape.graphics.lineTo(p1x, p1y);
- triangleShape.graphics.endFill();
- }
- }
- private function rgb2hex(r,g,b):Number {
- return (r<<16 | g<<8 | b);
- }
- private function KeyPressed(e:KeyboardEvent):void {
- switch (e.keyCode) {
- case Keyboard.SPACE :
- while (stage.numChildren>1) {
- stage.removeChildAt(1);
- }
- points=0;
- p1x=0;
- p1y=0;
- p2x=0;
- p2y=0;
- p3x=0;
- p3y=0;
- break;
- case Keyboard.UP :
- colors=true;
- break;
- case Keyboard.DOWN :
- colors=false;
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment