Skip to content

Commit

Permalink
✨ multiple drop sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
haliphax committed Oct 8, 2021
1 parent fc8f861 commit 490c631
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 15 deletions.
Binary file removed drop-game/static/assets/chute.png
Binary file not shown.
Binary file added drop-game/static/assets/default/chute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drop-game/static/assets/default/drop1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drop-game/static/assets/default/drop2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drop-game/static/assets/default/drop3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drop-game/static/assets/default/drop4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drop-game/static/assets/default/drop5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drop-game/static/assets/default/pad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed drop-game/static/assets/drop.png
Binary file not shown.
Binary file removed drop-game/static/assets/pad.png
Binary file not shown.
3 changes: 2 additions & 1 deletion drop-game/static/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default class Avatar {
stroke: '#000',
strokeThickness: 4,
});
this.sprite = game.physics.add.image(0, 0, 'drop')
this.spriteNumber = Math.ceil(Math.random() * constants.NUM_SPRITES);
this.sprite = game.physics.add.image(0, 0, `drop${this.spriteNumber}`)
.setOrigin(0.5, 0.5)
.setVisible(false);
this.sprite.avatar = this;
Expand Down
4 changes: 2 additions & 2 deletions drop-game/static/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export default {
MAX_RANDOM_VELOCITY: 600,
/** maximum angle of sway */
MAX_SWAY: 25,
/** scale of pad image */
PAD_SCALE: 2,
/** number of sprites */
NUM_SPRITES: 5,
/** height of screen */
SCREEN_HEIGHT: 1080,
/** width of screen */
Expand Down
27 changes: 15 additions & 12 deletions drop-game/static/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ export default class Game extends Phaser.Scene {

preload() {
this.load.addFile(new WebFontFile(this.load, 'Syne Mono'));
this.load.setBaseURL('/assets');
this.load.setBaseURL('/assets/default');
this.load.image('chute', 'chute.png');
this.load.image('drop', 'drop.png');
this.load.image('drop1', 'drop1.png');
this.load.image('drop2', 'drop2.png');
this.load.image('drop3', 'drop3.png');
this.load.image('drop4', 'drop4.png');
this.load.image('drop5', 'drop5.png');
this.load.image('pad', 'pad.png');
}

Expand All @@ -42,10 +46,8 @@ export default class Game extends Phaser.Scene {
this.pad
.setMaxVelocity(0, 0)
.setOrigin(0, 0)
.setScale(constants.PAD_SCALE)
.setVisible(false)
.setPosition(
0, constants.SCREEN_HEIGHT - this.pad.height * constants.PAD_SCALE);
.setPosition(0, constants.SCREEN_HEIGHT - this.pad.height);

setTimeout(this.ready.bind(this), 100);
}
Expand Down Expand Up @@ -77,8 +79,7 @@ export default class Game extends Phaser.Scene {
this.droppers = {};
this.droppersArray = [];
this.winner = null;
this.pad.x = Math.random()
* (constants.SCREEN_WIDTH - (this.pad.width * constants.PAD_SCALE));
this.pad.x = Math.random() * (constants.SCREEN_WIDTH - this.pad.width);
this.pad.setVisible(true);

if (this.queue)
Expand Down Expand Up @@ -117,8 +118,9 @@ export default class Game extends Phaser.Scene {
avatar.active = false;
avatar.chute.visible = false;
avatar.score = ((total - pos) / total * 100).toFixed(2);
avatar.sprite = this.add.image(orig.x, orig.y, 'drop')
.setOrigin(0.5, 0.5);
avatar.sprite =
this.add.image(orig.x, orig.y, `drop${avatar.spriteNumber}`)
.setOrigin(0.5, 0.5);
orig.destroy();

if (this.winner && avatar.score <= this.winner.score)
Expand Down Expand Up @@ -173,9 +175,10 @@ export default class Game extends Phaser.Scene {
avatar.active = false;
avatar.label.destroy();
avatar.label = null;
avatar.sprite = this.add.image(avatar.sprite.x, avatar.sprite.y, 'drop')
.setOrigin(0.5, 0.5)
.setAlpha(0.25);
avatar.sprite = this.add.image(
avatar.sprite.x, avatar.sprite.y, `drop${avatar.spriteNumber}`)
.setOrigin(0.5, 0.5)
.setAlpha(0.25);
avatar.scoreLabel?.destroy();
avatar.scoreLabel = null;
this.dropGroup.remove(avatar.sprite);
Expand Down

0 comments on commit 490c631

Please sign in to comment.