Sunday, July 24, 2011

Flash Game Creating

Начал делать игру на флэше Action Script 2







Ниже код:




// Flash game v 0.28.07.2012


scale = 40; // global scale for zoom


cw=150; // cell width

ch=80; //cell hight


function zoom(scale){ // function Recale cells

_root._xscale=scale;

_root._yscale=scale;

}


//Test map

var map:Array = new Array(

[1,1,1,1,1,1,1,1],

[1,0,1,1,1,1,1,1],

[1,1,1,1,1,0,1,1],

[1,1,1,1,1,1,1,1],

[1,0,1,1,1,1,1,1],

[1,1,1,1,1,0,1,1],

[1,1,1,1,1,1,1,1],

[1,0,1,1,1,1,1,1],

[1,1,1,1,1,0,1,1],

[1,1,1,0,1,1,1,1],

[1,0,1,1,1,1,1,1],

[1,1,1,0,1,0,1,1],

[1,1,1,1,1,1,1,1],

[1,0,1,1,1,1,1,1],

[1,1,1,1,1,0,1,1],

[1,1,1,1,0,1,2,1],

[1,0,1,1,1,1,1,1],

[1,1,1,1,1,0,1,1],

[1,1,1,1,1,0,1,1],

[1,1,1,1,1,1,1,1]



);


function makeMap(map){ //creation map from titles

i=0;j=0;

depth=0;

while(i<map.length){

while(j<map[i].length){

//trace('MAP['+i+','+j+']='+map[i][j]);

k=random(3);

movie='cell'+k;

duplicateMovieClip(movie,'c'+depth,depth);

_root['c'+depth]._y=i*ch/2;

_root['c'+depth]._x=j*cw+cw/2*(i%2);

depth++;

j++;

}

i++;

j=0;

}

}


function placePlayer(){

pd=random(depth);

py=(pd-pd%map[0].length)/map[0].length;

px=pd%map[0].length;

_root['c'+pd].unloadMovie();

movie='player';

duplicateMovieClip(movie,'player1',pd);

_root['player1']._y=py*ch/2;

_root['player1']._x=px*cw+cw/2*(py%2);

}


zoom(scale); //rescale cells for game

makeMap(map); // create map

placePlayer();


onEnterFrame = function(){ // main cycle

//onEnterFrame = function(){} // exit

}


var keys:Object = new Object(); // Add Key Listener

keys.onKeyDown = function(){

if (Key.getCode() == 32) { // space bar

trace("Space Bar was Pressed");

}

if((Key.getCode() == 187)||(Key.getCode() == 107)){ // zoom in

scale +=5;

zoom(scale);

}

if((Key.getCode() == 189)||(Key.getCode() == 109)){ // zoom out

scale -=5;

zoom(scale);

}

//trace(Key.getCode());

};

Key.addListener(keys);


Mouse.hide();


var mouse:Object = new Object(); // Add Mouse Listener

mouse.onMouseMove = function() {

for(i in _root){

if(_root[i].hitTest(_root._xmouse, _root._ymouse)){

pointer._x=_root[i]._x;

pointer._y=_root[i]._y;

}

}

}

mouse.onMouseDown = function() {

pointer.gotoAndStop(2);

//trace('12');

}

mouse.onMouseUp = function() {

pointer.gotoAndStop(1);

}


Mouse.addListener(mouse);


No comments:

Post a Comment