Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update game-scene.ts #222

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9c2fce1
Update game-scene.ts
quan-nguyen-thuc06 Jun 29, 2022
417db9b
Update game-scene.ts
quan-nguyen-thuc06 Jun 29, 2022
d20167b
Merge branch 'master'
quan-nguyen-thuc06 Jun 29, 2022
36385c7
update candy crush
quan-nguyen-thuc06 Jun 29, 2022
281ff87
update candy crush
quan-nguyen-thuc06 Jun 29, 2022
109f297
update endless-runner and tank
quan-nguyen-thuc06 Jun 30, 2022
2907eba
update game breakout
quan-nguyen-thuc06 Jul 1, 2022
f448f81
update game pack.json
quan-nguyen-thuc06 Jul 1, 2022
f71e872
update game space-invaders
quan-nguyen-thuc06 Jul 1, 2022
c90e32c
update game coin-runner
quan-nguyen-thuc06 Jul 3, 2022
c696121
update game tank menu scene
quan-nguyen-thuc06 Jul 4, 2022
99080dd
update game tank
quan-nguyen-thuc06 Jul 4, 2022
4daf868
update game tank - pauseScene
quan-nguyen-thuc06 Jul 4, 2022
93d7aec
update game tank - enyme
quan-nguyen-thuc06 Jul 5, 2022
3a2339b
update game tank - curosr
quan-nguyen-thuc06 Jul 6, 2022
1a62a45
update game tank - audio
quan-nguyen-thuc06 Jul 6, 2022
c9c8bb6
update game tank - audio shoot and hit
quan-nguyen-thuc06 Jul 7, 2022
dd0829c
update game tank - fix audio menu scene
quan-nguyen-thuc06 Jul 7, 2022
dbc114c
update game candy - create for step update to fix tween
quan-nguyen-thuc06 Jul 7, 2022
290cd13
update candy-crush
quan-nguyen-thuc06 Jul 11, 2022
02ffa61
update candy-crush tween
quan-nguyen-thuc06 Jul 11, 2022
ec40c87
update breakout
quan-nguyen-thuc06 Jul 11, 2022
5195e11
update tank tween trail
quan-nguyen-thuc06 Jul 11, 2022
79049ad
update tank name of file and bullet, interface
quan-nguyen-thuc06 Jul 11, 2022
b261b01
update tank interface button
quan-nguyen-thuc06 Jul 11, 2022
21dc02f
update tank and coin-runner
quan-nguyen-thuc06 Jul 11, 2022
acad6ec
update breakout and coin-runner
quan-nguyen-thuc06 Jul 11, 2022
6a13df0
update name tank
quan-nguyen-thuc06 Jul 12, 2022
d28509b
update name tank create container
quan-nguyen-thuc06 Jul 12, 2022
c73b248
update name tank particale
quan-nguyen-thuc06 Jul 12, 2022
49fc2c6
update tank state
quan-nguyen-thuc06 Jul 12, 2022
7a8c9d6
update name tank - state and input
quan-nguyen-thuc06 Jul 12, 2022
57ec748
update name tank - rename file
quan-nguyen-thuc06 Jul 12, 2022
f8c805c
update tank
quan-nguyen-thuc06 Jul 13, 2022
7899a1e
update tank add Const
quan-nguyen-thuc06 Jul 13, 2022
954f674
update tank
quan-nguyen-thuc06 Jul 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/boilerplates/webpack-boilerplate/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const GameConfig: Phaser.Types.Core.GameConfig = {
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
gravity: { y: 200 },
debug: true,
}
},
scene: [MainScene]
Expand Down
3 changes: 2 additions & 1 deletion src/boilerplates/webpack-boilerplate/src/objects/redhat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export class Redhat extends Phaser.GameObjects.Image {

private initPhysics() {
this.scene.physics.world.enable(this);
this.body.setVelocity(100, 200);
this.body.setVelocity(300, 400);
this.body.setBounce(1, 1);
this.body.setSize(200,200)
this.body.setCollideWorldBounds(true);
}
}
2 changes: 1 addition & 1 deletion src/games/asteroid/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const GameConfig: Phaser.Types.Core.GameConfig = {
physics: {
default: 'arcade',
arcade: {
debug: false
debug: true
}
},
backgroundColor: '#000000',
Expand Down
57 changes: 57 additions & 0 deletions src/games/breakout/assets/images/flares.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{"frames": {

"blue":
{
"frame": {"x":2,"y":2,"w":128,"h":128},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":128},
"sourceSize": {"w":128,"h":128},
"pivot": {"x":0.5,"y":0.5}
},
"green":
{
"frame": {"x":132,"y":2,"w":128,"h":128},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":128},
"sourceSize": {"w":128,"h":128},
"pivot": {"x":0.5,"y":0.5}
},
"red":
{
"frame": {"x":262,"y":2,"w":128,"h":128},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":128},
"sourceSize": {"w":128,"h":128},
"pivot": {"x":0.5,"y":0.5}
},
"white":
{
"frame": {"x":392,"y":2,"w":128,"h":128},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":128},
"sourceSize": {"w":128,"h":128},
"pivot": {"x":0.5,"y":0.5}
},
"yellow":
{
"frame": {"x":522,"y":2,"w":128,"h":128},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":128,"h":128},
"sourceSize": {"w":128,"h":128},
"pivot": {"x":0.5,"y":0.5}
}},
"meta": {
"app": "http://www.codeandweb.com/texturepacker",
"version": "1.0",
"image": "flares.png",
"format": "RGBA8888",
"size": {"w":652,"h":132},
"scale": "1",
"smartupdate": "$TexturePacker:SmartUpdate:f2781d89823d5a67fc31381af364b421:da82646b19b2f0c08684086824b1e581:71625947cf221c10549b852c13ffedc7$"
}
}
Binary file added src/games/breakout/assets/images/flares.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/games/breakout/assets/pack.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"key": "font",
"textureURL": "./assets/font/font.png",
"fontDataURL": "./assets/font/font.fnt"
},
{
"type": "atlas",
"key": "flares",
"textureURL": "./assets/images/flares.png",
"atlasURL": "./assets/images/flares.json"
}
]
}
Expand Down
7 changes: 4 additions & 3 deletions src/games/breakout/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BootScene } from './scenes/boot-scene';
import { GameScene } from './scenes/game-scene';
import { BootScene } from './scenes/bootScene';
import { GameScene } from './scenes/gameScene';

export const GameConfig: Phaser.Types.Core.GameConfig = {
title: 'Breakout',
Expand All @@ -14,7 +14,8 @@ export const GameConfig: Phaser.Types.Core.GameConfig = {
physics: {
default: 'arcade',
arcade: {
gravity: { x: 0, y: 0 }
gravity: { x: 0, y: 0 },
// debug: true,
}
},
scale: {
Expand Down
2 changes: 1 addition & 1 deletion src/games/breakout/src/interfaces/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface IRectangleConstructor {
interface IRectangleConstructor {
scene: Phaser.Scene;
x: number;
y: number;
Expand Down
18 changes: 16 additions & 2 deletions src/games/breakout/src/objects/ball.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IRectangleConstructor } from '../interfaces/interfaces';


export class Ball extends Phaser.GameObjects.Rectangle {
body: Phaser.Physics.Arcade.Body;

emitter!: Phaser.GameObjects.Particles.ParticleEmitter;
constructor(aParams: IRectangleConstructor) {
super(
aParams.scene,
Expand All @@ -16,6 +16,7 @@ export class Ball extends Phaser.GameObjects.Rectangle {

this.initRectangle();
this.initPhysics();
this.initPractices();
this.scene.add.existing(this);
}

Expand All @@ -32,8 +33,21 @@ export class Ball extends Phaser.GameObjects.Rectangle {
this.body.setCollideWorldBounds();
}

private initPractices(): void {
const particles = this.scene.add.particles('flares');
this.emitter = particles.createEmitter({
frame: 'red',
speed: 100,
scale: { start: 0.1, end: 0 },
angle: {min: 60, max:100},
blendMode: 'ADD'
}).stop();
this.emitter.startFollow(this, 5,5);
}

public applyInitVelocity(): void {
this.body.setVelocity(Phaser.Math.RND.between(-200, 200), 200);
this.body.speed = 800;
this.emitter.start()
}
}
45 changes: 41 additions & 4 deletions src/games/breakout/src/objects/brick.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IRectangleConstructor } from '../interfaces/interfaces';
import { settings } from '../settings';

export class Brick extends Phaser.GameObjects.Rectangle {
body: Phaser.Physics.Arcade.Body;

isdestroyed!: boolean;
constructor(aParams: IRectangleConstructor) {
super(
aParams.scene,
Expand All @@ -13,18 +13,55 @@ export class Brick extends Phaser.GameObjects.Rectangle {
aParams.fillColor,
aParams.fillAlpha
);

this.isdestroyed = false;
this.initRectangle();
this.initPhysics();
this.initPhysics();
this.scene.add.existing(this);
}

private initRectangle(): void {
this.setOrigin(0);
this.setScale(0,0);
const x = this.x / (settings.BRICK.WIDTH + settings.BRICK.SPACING);
const y = (this.y - settings.BRICK.MARGIN_TOP) / (settings.BRICK.HEIGHT + settings.BRICK.SPACING);
const WIDTH = settings.LEVELS[settings.currentLevel].WIDTH;
this.scene.tweens.add({
targets: this,
scaleX: 1,
scaleY: 1,
ease: 'Sine.easeInOut',
duration: 300,
delay: this.scene.tweens.stagger(50, {}),
repeat: 0,
yoyo: false,
onComplete: () => {
this.body.setSize(settings.BRICK.WIDTH, settings.BRICK.HEIGHT);
}
});

}

update(): void {
if(this.y > this.scene.scale.height - 100)
this.destroy();
}

private initPhysics(): void {
this.scene.physics.world.enable(this);
this.body.setImmovable(true);
}

public destroyBrick(): void {
this.isdestroyed = true;
this.setOrigin(0.5,0.5);
this.body.setAccelerationY(150);
this.body.checkCollision.none = true;
this.scene.tweens.add({
targets: this,
duration: 1000,
yoyo: false,
angle: 360,
repeat: -1,
});
}
}
1 change: 0 additions & 1 deletion src/games/breakout/src/objects/player.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IRectangleConstructor } from '../interfaces/interfaces';

export class Player extends Phaser.GameObjects.Rectangle {
body: Phaser.Physics.Arcade.Body;
Expand Down
61 changes: 61 additions & 0 deletions src/games/breakout/src/scenes/bootScene.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export class BootScene extends Phaser.Scene {
private loadingBar: Phaser.GameObjects.Graphics;
private progressBar: Phaser.GameObjects.Graphics;

constructor() {
super({
key: 'BootScene'
});
}

preload(): void {
// set the background and create loading bar
// this.cameras.main.setBackgroundColor(0x98d687);
this.createLoadingbar();

// pass value to change the loading bar fill
this.load.on(
'progress',
function (value: number) {
this.progressBar.clear();
this.progressBar.fillStyle(0xfff6d3, 1);
this.progressBar.fillRect(
this.cameras.main.width / 4,
this.cameras.main.height / 2 - 16,
(this.cameras.main.width / 2) * value,
16
);
},
this
);

// delete bar graphics, when loading complete
this.load.on(
'complete',
function () {
this.progressBar.destroy();
this.loadingBar.destroy();
},
this
);

// load out package
this.load.pack('preload', './assets/pack.json', 'preload');
}

update(): void {
this.scene.start('GameScene');
}

private createLoadingbar(): void {
this.loadingBar = this.add.graphics();
this.loadingBar.fillStyle(0x5dae47, 1);
this.loadingBar.fillRect(
this.cameras.main.width / 4 - 2,
this.cameras.main.height / 2 - 18,
this.cameras.main.width / 2 + 4,
20
);
this.progressBar = this.add.graphics();
}
}
Loading