Skip to content

Update game-scene.ts #222

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

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update game coin-runner
  • Loading branch information
quan-nguyen-thuc06 committed Jul 3, 2022
commit c90e32c3d2fced6c23e36f4e4a72770cdef4a4e9
57 changes: 57 additions & 0 deletions src/games/coin-runner/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/coin-runner/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.
27 changes: 27 additions & 0 deletions src/games/coin-runner/assets/pack.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"preload": {
"files": [
{
"type": "image",
"key": "coin",
"url": "./assets/images/coin.png"
},
{
"type": "image",
"key": "player",
"url": "./assets/images/player.png"
},
{
"type": "image",
"key": "background",
"url": "./assets/images/background.png"
},
{
"type": "atlas",
"key": "flares",
"textureURL": "./assets/images/flares.png",
"atlasURL": "./assets/images/flares.json"
}
]
}
}
3 changes: 2 additions & 1 deletion src/games/coin-runner/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BootScene } from './scenes/boot-scene';
import { GameScene } from './scenes/game-scene';

export const GameConfig: Phaser.Types.Core.GameConfig = {
Expand All @@ -8,7 +9,7 @@ export const GameConfig: Phaser.Types.Core.GameConfig = {
height: 576,
type: Phaser.AUTO,
parent: 'game',
scene: [GameScene],
scene: [BootScene, GameScene],
input: {
keyboard: true
},
Expand Down
46 changes: 46 additions & 0 deletions src/games/coin-runner/src/objects/coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ export class Coin extends Phaser.GameObjects.Image {

private initImage(): void {
this.setOrigin(0.5, 0.5);
this.setScale(0.01,1);
this.scene.tweens.add({
targets: this,
scaleX: 1,
flipX: true,
ease: 'Sine.easeInOut',
duration: 1000,
yoyo: true,
repeat: -1
});
}

private initEvents(): void {
Expand Down Expand Up @@ -64,4 +74,40 @@ export class Coin extends Phaser.GameObjects.Image {
this.lastPosition = 'right';
}
}

public playerHitCoin(){
// emitter
var particles = this.scene.add.particles('flares');
var emitter = particles.createEmitter({
frame: 'yellow',
x: this.x,
y: this.y,
lifespan: 2000,
speed: { min: 400, max: 600 },
scale: { start: 0.4, end: 0 },
quantity: 1,
blendMode: 'ADD'
});
this.scene.time.delayedCall(50, ()=>{
emitter.stop();
}, [], this);

// tweens
this.scene.tweens.add({
targets: this,
scaleX: 0.5,
scaleY: 0.5,
x: this.scene.sys.canvas.width / 2,
y: this.scene.sys.canvas.height - 50,
angle: 0,
ease: 'Sine.easeInOut',
duration: 500,
repeat: 0,
yoyo: false,
onComplete:()=>{
this.setScale(0.01,1)
this.changePosition();
}
});
}
}
61 changes: 61 additions & 0 deletions src/games/coin-runner/src/scenes/boot-scene.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();
}
}
22 changes: 12 additions & 10 deletions src/games/coin-runner/src/scenes/game-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ export class GameScene extends Phaser.Scene {
private coinsCollectedText: Phaser.GameObjects.Text;
private collectedCoins: number;
private player: Player;
private checkAddCoin!: boolean;

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

preload(): void {
this.load.image('background', './assets/images/background.png');
this.load.image('player', './assets/images/player.png');
this.load.image('coin', './assets/images/coin.png');
}

init(): void {
this.collectedCoins = 0;
this.checkAddCoin = false;
}

create(): void {
Expand Down Expand Up @@ -71,13 +67,19 @@ export class GameScene extends Phaser.Scene {
this.coin.getBounds()
)
) {
this.updateCoinStatus();
if(!this.checkAddCoin){
this.updateCoinStatus();
this.checkAddCoin = true;
}
}
}

private updateCoinStatus(): void {
this.collectedCoins++;
this.coinsCollectedText.setText(this.collectedCoins + '');
this.coin.changePosition();
this.coin.playerHitCoin();
this.time.delayedCall(500, ()=>{
this.collectedCoins++;
this.coinsCollectedText.setText(this.collectedCoins + '');
this.checkAddCoin =false
}, [], this);
}
}
Binary file added src/games/tank/assets/sprites/btn-music.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 src/games/tank/assets/sprites/btn-sound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.