Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: hero.distanceTo is not a function' in this line: 'if (hero.intersects(obstacles[i]) && hero.distanceTo(obstacles[i]) < 50) {' Line Number: 164
User prompt
Reduce collision threshold to 10 pixels
User prompt
Fix Bug: 'TypeError: hero.distanceTo is not a function' in this line: 'if (hero.intersects(obstacles[i]) && hero.distanceTo(obstacles[i]) < 50) {' Line Number: 164
User prompt
Add 50 pixels collisio threshold between hero and obstavles
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'width')' in this line: 'var enemyGraphics = self.createAsset(selectedAssetId, 'Enemy', enemyGraphics.width / 2, enemyGraphics.height / 2);' Line Number: 81
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'width')' in this line: 'var obstacleGraphics = self.createAsset('obstacle', 'Obstacle', obstacleGraphics.width / 2, obstacleGraphics.height / 2);' Line Number: 30
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'width')' in this line: 'var heroGraphics = self.createAsset('hero', 'Hero character', heroGraphics.width / 2, heroGraphics.height / 2);' Line Number: 48
User prompt
Update anchor points of hero and obstacles to correclty detct collision. Anchor points should be defined by the asset graphic not the shape
User prompt
Add collision detection on the cemter of the assets
User prompt
Fix Bug: 'TypeError: hero.distanceTo is not a function' in this line: 'if (hero.intersects(obstacles[i]) && hero.distanceTo(obstacles[i]) < 20) {' Line Number: 164
User prompt
Hero and obstacle can collide for 20 pixels and its not game over
User prompt
Fix Bug: 'TypeError: hero.getBounds(...).intersects is not a function' in this line: 'if (hero.getBounds().intersects(obstacles[i].getBounds())) {' Line Number: 164
User prompt
Veryfy that hero and obstacles actually colide and not juat the area of the asset
User prompt
Add 20 pixels collision threshold berween hero and obstavles
User prompt
Add a 10 pixels collision threshold betweem hero and obstacles
User prompt
Fix Bug: 'TypeError: this.getPixel is not a function' in this line: 'var pixel = this.getPixel(x, y);' Line Number: 127
User prompt
Fix Bug: 'ReferenceError: pixel is not defined' in this line: 'if (pixel.alpha > 0) {' Line Number: 127
User prompt
Fix Bug: 'TypeError: this.getPixel is not a function' in this line: 'var pixel = this.getPixel(x, y);' Line Number: 127
User prompt
Fix Bug: 'ReferenceError: pixel is not defined' in this line: 'if (pixel.alpha > 0) {' Line Number: 127
User prompt
Fix Bug: 'TypeError: this.getPixel is not a function' in this line: 'var pixel = this.getPixel(x, y);' Line Number: 127
User prompt
Fix Bug: 'ReferenceError: pixel is not defined' in this line: 'if (pixel.alpha > 0) {' Line Number: 127
User prompt
Fix Bug: 'TypeError: this.getPixel is not a function' in this line: 'var pixel = this.getPixel(x, y);' Line Number: 127
User prompt
Fix Bug: 'ReferenceError: pixel is not defined' in this line: 'if (pixel.alpha > 0) {' Line Number: 127
User prompt
Fix Bug: 'TypeError: this.getPixel is not a function' in this line: 'var pixel = this.getPixel(x, y);' Line Number: 127
===================================================================
--- original.js
+++ change.js
@@ -44,20 +44,8 @@
};
});
var Hero = Container.expand(function () {
var self = Container.call(this);
- self.pixelIntersects = function (obstacle) {
- var heroPixels = heroGraphics.getPixels();
- var obstaclePixels = obstacle.getPixels();
- for (var i = 0; i < heroPixels.length; i++) {
- for (var j = 0; j < obstaclePixels.length; j++) {
- if (heroPixels[i].x === obstaclePixels[j].x && heroPixels[i].y === obstaclePixels[j].y) {
- return true;
- }
- }
- }
- return false;
- };
var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
var wingGraphics = self.createAsset('wing', 'Hero Wing', .7, .8);
wingGraphics.direction = 1;
self.speed = 0;
@@ -119,22 +107,8 @@
if (bg1.x <= -2048) bg1.x = bg2.x + 2048;
if (bg2.x <= -2048) bg2.x = bg1.x + 2048;
};
});
-Container.prototype.getPixels = function () {
- var pixels = [];
- for (var y = 0; y < this.height; y++) {
- for (var x = 0; x < this.width; x++) {
- if (pixel.alpha > 0) {
- pixels.push({
- x: x + this.x,
- y: y + this.y
- });
- }
- }
- }
- return pixels;
-};
var Game = Container.expand(function () {
var self = Container.call(this);
var secondBackground = self.addChild(new SecondBackground());
var clouds = [];
@@ -186,12 +160,10 @@
obstacles[i].destroy();
obstacles.splice(i, 1);
scoreTxt.setText(score);
}
- if (hero.intersects(obstacles[i])) {
- if (hero.pixelIntersects(obstacles[i])) {
- isGameOver = true;
- }
+ if (hero.intersects(obstacles[i], 10)) {
+ isGameOver = true;
} else {
for (var j = hero.bullets.length - 1; j >= 0; j--) {
if (hero.bullets[j].intersects(obstacles[i])) {
if (obstacles[i] instanceof Enemy) {