Untitled
unknown
plain_text
2 years ago
4.8 kB
7
Indexable
stage {
backdrop White("gallery:General/White")
let cols = 5;
let rows = 5;
let matrix = [ ];
let db = 0;
let point = 0;
let hidelist = [ ];
let item2;
actor Robot {
default costume Idle("gallery:Figures/Robot Idle")
costume Winner("gallery:Text/Winner Blue")
function createMatrix(row, col) {
matrix = [ ];
for(let i = 0; i < row; i++) {
let list = [ ];
for(let j = 0; j < col; j++) {
list.push(0);
}
matrix.push(list);
}
}
function showMatrix(row, col) {
let y = 130;
for(let i = 0; i < row; i++) {
let x = -280;
for(let j = 0; j < col; j++) {
let item = matrix[i][j];
item.setPosition(x, y);
item.setCostume(Math.randomBetween(1, 3));
item.show();
x += 50;
}
y -= 50;
}
}
function createClones(n) {
for(let i = 0; i < n; i++) {
createClone(Button);
}
}
function remove(i, j) {
let item = matrix[i][j];
if(item) {
let color = item.costumeId;
item.setCostume(4);
if(i > 0) {
let up = matrix[i - 1][j];
if(up && up.costumeId == color) {
this.remove(i - 1, j);
}
}
if(i < rows - 1) {
let down = matrix[i + 1][j];
if(down && down.costumeId == color) {
this.remove(i + 1, j);
}
}
if(j > 0) {
let left = matrix[i][j - 1];
if(left && left.costumeId == color) {
this.remove(i, j - 1);
}
}
if(j < cols - 1) {
let right = matrix[i][j + 1];
if(right && right.costumeId == color) {
this.remove(i, j + 1);
}
}
hidelist.push(item);
}
}
function hideAndFall() {
for(let item of hidelist) {
let i = item.i;
let j = item.j;
item.hide();
matrix[i][j] = 0;
while(i > 0) {
item2 = matrix[i - 1][j];
if(item2) {
item2.i += 1;
item2.y -= 50;
matrix[i][j] = item2;
matrix[i - 1][j] = 0;
}
i--;
}
}
let k = hidelist.length;
point += k * k;
Ring.sayPoint();
db += k;
if(db == rows * cols) {
this.show();
this.setPosition(0, 0);
this.setCostume(this.Winner);
}
}
when stage.started {
this.createMatrix(rows, cols);
this.createClones(rows * cols);
this.setPosition(-200, 50);
this.show();
this.say("Welcome to the game! You have to blow up button by clicking on them. Of coursem the neighbours with the same color will also be destroyed.");
this.wait(2);
this.say("");
this.hide();
this.showMatrix(rows, cols);
}
}
actor Button {
default costume Blue("gallery:Objects/Button Blue")
costume Red("gallery:Objects/Button Purple")
costume Green("gallery:Objects/Button Green")
costume Bomb("gallery:Objects/Bomb Explode")
let i = 0;
let j = 0;
when clicked {
hidelist = [ ];
Robot.remove(i, j);
Robot.hideAndFall();
}
when cloned {
let id = this.cloneId - 1;
this.j = id % cols;
this.i = (id - this.j) / cols;
matrix[this.i][this.j] = this;
}
when stage.started {
this.hide();
this.size = 100;
}
}
actor Ring {
costume Red("gallery:Objects/Ring Red")
when stage.started{
this.setPosition(300, 150);
point = 0;
db = 0;
sayPoint();
}
function sayPoint(){
this.say("Point: "+ point);
}
}
}Editor is loading...
Leave a Comment