User prompt
There will be 3 available shapes: A Circle, A square and A triangle. By every click the player changes the shape to one of those 3.
User prompt
Fix Bug: 'TypeError: shapes[a].containsPoint is not a function' in this line: 'if (shapes[a] && shapes[a].containsPoint(pos)) {' Line Number: 51
User prompt
Fix Bug: 'TypeError: shapes[a] is undefined' in this line: 'if (shapes[a].containsPoint(pos)) {' Line Number: 51
User prompt
Fix Bug: 'TypeError: shapes[a] is undefined' in this line: 'if (shapes[a].matched) {' Line Number: 32
Initial prompt
Shape Match FRVR
var Shape = Container.expand(function () { var self = Container.call(this); var shapeGraphics = self.createAsset('shape', 'Shape Graphics', .5, .5); self.matched = false; self.match = function () { self.matched = true; }; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player Graphics', .5, .5); self.score = 0; self.incrementScore = function () { self.score += 1; }; }); var Game = Container.expand(function () { var self = Container.call(this); var shapes = []; var player = self.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.setText(player.score); scoreTxt.anchor.set(.5, 0); LK.gui.topCenter.addChild(scoreTxt); LK.on('tick', function () { for (var a = shapes.length; a >= 0; a--) { if (shapes[a].matched) { shapes[a].destroy(); shapes.splice(a, 1); player.incrementScore(); scoreTxt.setText(player.score); } } if (LK.ticks % 60 == 0) { var newShape = new Shape(); newShape.x = Math.random() * 2048; newShape.y = Math.random() * 2732; shapes.push(newShape); self.addChild(newShape); } }); stage.on('down', function (obj) { var event = obj.event; var pos = event.getLocalPosition(self); for (var a = shapes.length; a >= 0; a--) { if (shapes[a].containsPoint(pos)) { shapes[a].match(); } } }); });
var Shape = Container.expand(function () {
var self = Container.call(this);
var shapeGraphics = self.createAsset('shape', 'Shape Graphics', .5, .5);
self.matched = false;
self.match = function () {
self.matched = true;
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player Graphics', .5, .5);
self.score = 0;
self.incrementScore = function () {
self.score += 1;
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var shapes = [];
var player = self.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.setText(player.score);
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
LK.on('tick', function () {
for (var a = shapes.length; a >= 0; a--) {
if (shapes[a].matched) {
shapes[a].destroy();
shapes.splice(a, 1);
player.incrementScore();
scoreTxt.setText(player.score);
}
}
if (LK.ticks % 60 == 0) {
var newShape = new Shape();
newShape.x = Math.random() * 2048;
newShape.y = Math.random() * 2732;
shapes.push(newShape);
self.addChild(newShape);
}
});
stage.on('down', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
for (var a = shapes.length; a >= 0; a--) {
if (shapes[a].containsPoint(pos)) {
shapes[a].match();
}
}
});
});