You are on page 1of 9

ANEXA NR.1 CLASA PENTRU HARTA package { import flash.display.

MovieClip; public class Tile extends MovieClip { public var index:int; public var type:String; function Tile(i:int):void { this.index = i; setType("normal"); } public function setType(frame:String){ this.type =frame; if(frame == "normal"){ if(this.index %2 == 0){ frame="even"; }else{ frame="odd"; } } this.gotoAndStop(frame); } } CLASA PENTRU INDICATOARE package { import flash.display.MovieClip; import flash.events.MouseEvent; public class Arrow extends MovieClip { public var direction:String; public var index:int = -1; private var spacing:int; private var numColumns:int = 15; function Arrow(direction, xLoc, yLoc):void { this.direction = direction; this.x = xLoc; this.y = yLoc; this.gotoAndStop(direction); this.addEventListener(MouseEvent.MOUSE_DOWN, arrowDrag); this.addEventListener(MouseEvent.MOUSE_UP, arrowDrop); this.spacing = this.width;

Coala

UTM 526.1.783 A
Mod Coala Nr. document Semnt. Data

90

} private function arrowDrag(evt:MouseEvent) { evt.target.startDrag(); } private function arrowDrop(evt:MouseEvent) { evt.target.stopDrag(); var arrowCol:int = Math.floor((evt.target.x+spacing/2)/spacing ); var arrowRow:int = Math.floor((evt.target.y+spacing/2)/spacing); this.x = arrowCol*spacing; this.y = arrowRow*spacing; this.index = arrowRow*numColumns + arrowCol; //trace(this.index); } } } CLASA PERSONAJULUI package { import flash.display.MovieClip; public class Pirate extends MovieClip { function Pirate():void { trace("arg!"); } } } CLASA PENTRU EFECTE VIZUALE package { import flash.events.Event; import flash.display.Graphics; import flash.display.Sprite; public class Drops extends Sprite { private var speed:Number; private var alphaN:Number; private var radius:Number; private var stageWidthIn:Number; private var stageHeightIn:Number; public function Drops(stageWidth, stageHeight) { stageWidthIn = stageWidth; stageHeightIn = stageHeight;

Coala

UTM 526.1.783 A
Mod Coala Nr. document Semnt. Data

91

alphaN = Math.random() * 0.5 + 0.4; radius = Math.random() * 7 + 10; speed = Math.random() * 2 + 4; x = Math.random() * stageWidthIn; y = -30; graphics.beginFill(0xFFFFFF, alphaN); graphics.drawCircle(radius / 2, radius / 2, radius); graphics.endFill(); addEventListener(Event.ENTER_FRAME, enterFrame); } private function enterFrame(e:Event):void { y += speed; if(y > stageHeightIn + 30) { x = Math.random() * stageWidthIn; y = -30; } } } }

LOGICA DE JOC I MISCARILE import flash.display.Sprite; import flash.ui.Mouse; import flash.events.MouseEvent; import fl.motion.MotionEvent; import fl.transitions.Tween; import fl.transitions.easing.None; import fl.transitions.TweenEvent; var aTileData:Array = new Array("normal","normal","normal","normal","normal","normal","normal","normal","wall","norma l","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal" ,"normal","normal","normal","wall","normal","normal","normal","normal","normal","normal","no rmal","normal","normal","normal","normal","normal","normal","normal","wall","normal","treasur e","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal" ,"normal","normal","wall","normal","normal","normal","normal","normal","normal","normal","no rmal","normal","normal","normal","normal","normal","normal","wall","normal","normal","normal ","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal", "normal","wall","wall","gate","wall","wall","wall","wall","normal","normal","normal","normal"," normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","n ormal","normal","normal","normal","normal","key","normal","normal","normal","normal","norma l","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal"

Coala

UTM 526.1.783 A
Mod Coala Nr. document Semnt. Data

92

,"normal","normal","normal","normal","normal","normal","normal","normal","normal","normal"," normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","n ormal","normal","normal","normal","normal");

var mapGrid:Sprite = new Sprite(); mapGrid.x =40; mapGrid.y =40; addChild(mapGrid); var numRows:int =10; var numColumns:int=15; var numTiles:int = numRows*numColumns; var spacing:int =40; var currentColumn:int =0; var currentRow:int =0; var aTileMap:Array=new Array(); var aTypes:Array= new Array("normal","wall","gate","key","treasure"); var hasKey:Boolean=false; function drawTile(){ for(var i:int =0;i<numTiles;i++){ if(currentColumn==numColumns){ currentRow +=1; currentColumn =0; } aTileMap[i]=new Tile(i); aTileMap[i].x =currentColumn*spacing; aTileMap[i].y =currentRow*spacing; aTileMap[i].setType(aTileData[i]); mapGrid.addChild(aTileMap[i]); currentColumn +=1; } } drawTile(); var arrowUp:Arrow=new Arrow("up",620,100); mapGrid.addChild(arrowUp); var arrowDown:Arrow=new Arrow("down",620,150); mapGrid.addChild(arrowDown); var arrowLeft:Arrow=new Arrow("left",620,200); mapGrid.addChild(arrowLeft); var arrowRight:Arrow=new Arrow("right",620,250); mapGrid.addChild(arrowRight); //col 2 row 3 var iconPirate:Pirate = new Pirate(); iconPirate.x=2*spacing; iconPirate.y=3*spacing; mapGrid.addChild(iconPirate);

Coala

UTM 526.1.783 A
Mod Coala Nr. document Semnt. Data

93

function run(evt:MouseEvent):void{ runNext(); } bRun.addEventListener(MouseEvent.CLICK,run); var nextX:int =spacing; var nextY:int =0; function runNext():void{ if(nextX !=0){ var newX=iconPirate.x+nextX; var runX:Tween=new Tween(iconPirate,"x",None.easeNone,iconPirate.x,newX,.3,true); runX.addEventListener(TweenEvent.MOTION_FINISH,checkNextSquare); } if(nextY !=0){ var newY=iconPirate.y+nextY; var runY:Tween=new Tween(iconPirate,"y",None.easeNone,iconPirate.y,newY,.3,true); runY.addEventListener(TweenEvent.MOTION_FINISH,checkNextSquare); } } function checkNextSquare(evt:TweenEvent):void{ var nextCol:int= Math.floor((iconPirate.x +nextX)/spacing); var nextRow:int= Math.floor((iconPirate.y +nextY)/spacing); if(nextRow>=0&&nextRow<numRows&&nextCol>=0&&nextCol<numColumns){ var nextIndex:int= nextRow*numColumns+nextCol; if(aTileMap[nextIndex].type=="normal"){ runNext(); }else if(aTileMap[nextIndex].type=="key"){ hasKey=true; aTileMap[nextIndex].setType("normal"); runNext(); } else if(aTileMap[nextIndex].type=="gate"){ if(hasKey){ runNext(); aTileMap[nextIndex].setType("normal"); } } else if(aTileMap[nextIndex].type=="treasure"){ aTileMap[nextIndex].setType("win"); var topPosition:uint=mapGrid.numChildren -1; mapGrid.setChildIndex(aTileMap[nextIndex],topPosition); gotoAndStop("fine"); } else gotoAndStop("over"); if(arrowUp.index==nextIndex){ nextX=0; nextY=-spacing;

Coala

UTM 526.1.783 A
Mod Coala Nr. document Semnt. Data

94

} if(arrowDown.index==nextIndex){ nextX=0; nextY=spacing; } if(arrowLeft.index==nextIndex){ nextX=-spacing; nextY=0; } if(arrowRight.index==nextIndex){ nextX=spacing; nextY=0; } } }

CREAREA MAPEI SI SALVAREA EI import flash.display.Sprite; import flash.events.MouseEvent; //col 4 row 3 //var aTileData:Array=newArray("normal","normal","normal","normal","normal","normal","normal","n ormal","wall","normal","normal","normal","normal","normal","normal","normal","normal","norm al","normal","normal","normal","normal","normal","wall","normal","normal","normal","normal"," normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","w all","normal","treasure","normal","normal","normal","normal","normal","normal","normal","norm al","normal","normal","normal","normal","wall","normal","normal","normal","normal","normal"," normal","normal","normal","normal","normal","normal","normal","normal","normal","wall","nor mal","normal","normal","normal","normal","normal","normal","normal","normal","normal","norm al","normal","normal","normal","wall","wall","gate","wall","wall","wall","wall","normal","normal ","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal", "normal","normal","normal","normal","normal","normal","normal","key","normal","normal","nor mal","normal","normal","normal","normal","normal","normal","normal","normal","normal","norm al","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal ","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal", "normal","normal","normal","normal","normal","normal","normal"); var mapGrid1:Sprite =new Sprite(); mapGrid1.x =40; mapGrid1.y =40; addChild(mapGrid1); var numRows1:int =10; var numColumns1:int = 15; var numTiles1:int =numRows1*numColumns1; var spacing1:int =40; var currentColumn1:int=0; var currentRow1:int=0;

Coala

UTM 526.1.783 A
Mod Coala Nr. document Semnt. Data

95

var aTypes1:Array = new Array("normal","wall","gate","key","treasure"); var aTileMap1:Array= new Array(); function drawTile1(){ for(var i:int = 0; i< numTiles1;i++){ if (currentColumn1 ==numColumns1){ currentRow1 +=1; currentColumn1 = 0; } aTileMap1[i] = new Tile(i); aTileMap1[i].x =currentColumn1*spacing1; aTileMap1[i].y =currentRow1*spacing1; mapGrid1.addChild(aTileMap1[i]); currentColumn1 += 1; aTileMap1[i].addEventListener(MouseEvent.CLICK,clickTile); } } drawTile1(); function clickTile(evt:MouseEvent):void{ var numTypes:int = aTypes1.length; var currentIndex:int; for(var i:int =0; i<numTypes;i++){ if(evt.target.type==aTypes1[i]){ currentIndex=i; } } var newIndex:int =currentIndex +1; if(newIndex==numTypes){ newIndex=0; } evt.target.setType(aTypes1[newIndex]); } var iconPirate1:Pirate = new Pirate(); iconPirate1.x=-iconPirate1.width/2; iconPirate1.y=-iconPirate1.height/2; mapGrid1.addChild(iconPirate1); function pirateDrag(evt:MouseEvent):void{ iconPirate1.startDrag(); } function pirateDrop(evt:MouseEvent):void{ iconPirate1.stopDrag(); var pirateCol=Math.floor((iconPirate1.x +spacing1/2)/spacing1); var pirateRow=Math.floor((iconPirate1.y +spacing1/2)/spacing1); trace("col "+String(pirateCol)+" row "+String(pirateRow)); }

Coala

UTM 526.1.783 A
Mod Coala Nr. document Semnt. Data

96

iconPirate1.addEventListener(MouseEvent.MOUSE_DOWN,pirateDrag); iconPirate1.addEventListener(MouseEvent.MOUSE_UP,pirateDrop); function clickSave(evt:MouseEvent):void{ var map:String =''; for(var i:int=0;i<numTiles1;i++){ map += '"'+aTileMap1[i].type+'",'; } trace(map); } bSave.addEventListener(MouseEvent.CLICK,clickSave);

Coala

UTM 526.1.783 A
Mod Coala Nr. document Semnt. Data

97

Coala

UTM 526.1.783 A
Mod Coala Nr. document Semnt. Data

22