Home > front end >  Based on simple game problem createjs framework development
Based on simple game problem createjs framework development

Time:10-03

Game is surround nerve type of cat, the original game is a draw vector shapes, and now I want to change to bitmap image types, research day, do not know how, the official written documents feeling is very simple, strives for the big help me solve the ~ ~ ~
Here is the source code:

circle. Js file
The function Circle () {
Createjs. Shape. The call (this);
Enclosing setCircleType=function (a type) {
The console. The log (type);
Enclosing _circleType=type;
The switch (type) {
Case Circle. TYPE_UNSELECTED:
Enclosing setColor (" # CCCCCC ");
break;
Case Circle. TYPE_SELECTED:
Enclosing setColor (" # ff6600 ");
break;
Case Circle. TYPE_CAT:
Enclosing setColor (" # 0000 ff ");
break;
}
}

Enclosing setColor=function (colorString) {
This. Graphics. BeginFill (colorString);
This. Graphics. Methods like drawCircle (0,0,15);
This. Graphics. EndFill ();
}
Enclosing getCircleType=function () {
Return this. _circleType;
}
Enclosing setCircleType (1);
}
Circle. The prototype= new createjs. Shape ();
Circle. TYPE_UNSELECTED=1;
Circle. TYPE_SELECTED=2;
Circle. TYPE_CAT=3;

app. Js file
The function addCircles () {
For (var indexY=0; IndexY<9. IndexY++) {//set the horizontal circle number
For (var indexX=0; IndexX<9. IndexX++) {//vertical circle number
var c=new Circle ();
//the console. The log (c);
GameView. AddChild (c);
CircleArr [indexX] [indexY]=c;
C.i ndexX=indexX;
C.i ndexY=indexY;
C.x=indexY % 2? IndexX * 35 + 18: indexX * 35;//set the spacing between the horizontal circle of
C.y=indexY * 35;//set the gap between the vertical circle

If (indexX==4 & amp; & IndexY==4) {//set to escape the circle initial position
C.s. etCircleType (3);
CurrentCat=c;
} else if (Math. The random () & lt; 0.2) {//to adjust the game difficulty by random number decimal closer to 1, the lower the difficulty of
C.s. etCircleType (Circle. TYPE_SELECTED);
}
C.a. ddEventListener (" click ", circleClicked);
}
}
}
  • Related