Skip to content

Commit

Permalink
bckp
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric L. Solis committed Nov 24, 2020
1 parent ca5b5b3 commit e453e54
Show file tree
Hide file tree
Showing 5 changed files with 10,020 additions and 14 deletions.
21 changes: 21 additions & 0 deletions ga.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Individual {
constructor(dimentions, min, max) {
const range = max - min;
this.genome = Array.from(Array(dimentions)).map(
() => min + range * Math.random
);
this.fitness = 0;
}
}

class GeneticAlgorithm {
constructor(populationSize, dimentions) {
this.populate(populationSize, dimentions);
}
evolve() {}
populate(populationSize, dimentions) {
this.population = Array.from(Array(populationSize)).map(
() => new Individual(dimentions)
);
}
}
13 changes: 7 additions & 6 deletions src/prefabs/player/InputManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ class InputManager {
* @returns {boolean}
*/
get isJumpKeyPressed() {
const { activePointer } = this.scene.input;
return (
this.cursors.up.isDown ||
this.cursors.space.isDown ||
(activePointer.isDown && activePointer.wasTouch)
);
return Math.round(Math.random());
// const { activePointer } = this.scene.input;
// return (
// this.cursors.up.isDown ||
// this.cursors.space.isDown ||
// (activePointer.isDown && activePointer.wasTouch)
// );
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/prefabs/player/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class Player extends Phaser.Physics.Arcade.Sprite {
/**
* Set player dead | Handle gameover
*/
die() {
die(score) {
// if (!this.isDead) console.log(score);
this.setState(Player.CONFIG.STATES.DEAD);
this.animationManager.update();
this.physicsManager.reset();
Expand Down
33 changes: 26 additions & 7 deletions src/scenes/game/GameScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,23 @@ class GameScene extends Phaser.Scene {
this.ui = new UI(this);
this.intro = new Intro(this.events);

this.player = new Player(this);
this.players = Array.from(Array(10)).map(() => new Player(this));

this.horizon = new Horizon(this);
this.ground = this.horizon.ground;
this.obstacles = this.horizon.obstacles;
this.nightMode = this.horizon.nightMode;

this.physics.add.collider(this.player, this.ground);
this.physics.add.overlap(this.player, this.obstacles, this.onPlayerHitObstacle, null, this);
this.players.forEach((player, i) => {
this.physics.add.collider(player, this.ground);
this.physics.add.overlap(
player,
this.obstacles,
() => this.onPlayerHitObstacle(i),
null,
this,
);
});

this.resizeManager.resize(this.scale.gameSize, this.scale.parentSize);

Expand All @@ -102,14 +110,21 @@ class GameScene extends Phaser.Scene {
}

update() {
const obstacle = this.obstacles.getLast(true) || { x: this.players[0].x, y: this.players[0].y };
this._score = Phaser.Math.Distance.Between(
this.players[0].x,
this.players[0].y,
obstacle.x,
obstacle.y,
);
const { gameSize } = this.scale;
const isMobile = gameSize.width === CONFIG.GAME.WIDTH.PORTRAIT;

this.inputManager.update();
this.ui.update(this.isPlaying, gameSize, this.score);

if (this.isPlaying) {
this.player.update();
this.players.forEach(player => player.update());

if (this.intro.isComplete) {
const { GAME, NIGHTMODE } = GameScene.CONFIG;
Expand Down Expand Up @@ -140,8 +155,11 @@ class GameScene extends Phaser.Scene {
/**
* Handle player collision with obstacle
*/
onPlayerHitObstacle() {
this.events.emit(CONFIG.EVENTS.GAME_OVER, this.score, this.highScore);
onPlayerHitObstacle(id) {
this.players[id].die(this.score);
// this.players.splice(id, 1);
// console.log(id);
// this.events.emit(CONFIG.EVENTS.GAME_OVER, this.score, this.highScore, id);
}

/**
Expand Down Expand Up @@ -241,7 +259,8 @@ class GameScene extends Phaser.Scene {
* @returns {number} - Current score
*/
get score() {
return Math.ceil(this.distance * GameScene.CONFIG.GAME.SCORE.COEFFICIENT);
return this._score;
// return Math.ceil(this.distance * GameScene.CONFIG.GAME.SCORE.COEFFICIENT);
}

/**
Expand Down
Loading

0 comments on commit e453e54

Please sign in to comment.