-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added stone splashes when an asteroid is destroyed
- Loading branch information
Aleksey Filatev
committed
Jan 22, 2021
1 parent
3322b4e
commit 4a00179
Showing
6 changed files
with
74 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,53 @@ | ||
import Block from "./Block"; | ||
|
||
export default class Flash extends Block { | ||
constructor(canvasWidth, canvasHeight) { | ||
class Splash extends Block { | ||
constructor(canvasWidth, canvasHeight, lifetime) { | ||
super(canvasWidth, canvasHeight, 2); | ||
this.lifetime = lifetime; | ||
this.createTime = null; | ||
this.transparency = 0.3; | ||
} | ||
onUpdate(time) { | ||
if (this.stateTime == null) { | ||
return; | ||
} | ||
if (this.stateTime + 5000 < time) { | ||
if (this.createTime == null) { | ||
this.createTime = this.stateTime; | ||
} | ||
if (this.createTime + this.lifetime < time) { | ||
this.isDestroyed = true; | ||
} else { | ||
this.transparency *= (this.lifetime - (time - this.createTime)) / this.lifetime; | ||
} | ||
} | ||
onOutOfScreen() { | ||
this.isDestroyed = true; | ||
} | ||
} | ||
|
||
export class FireSplash extends Splash { | ||
onDraw(context) { | ||
context.save(); | ||
context.translate(this.position.x, this.position.y); | ||
context.rotate(this.direction); | ||
context.beginPath(); | ||
context.moveTo(0, 1); | ||
context.lineTo(0, -1); | ||
context.strokeStyle = 'rgb(255, 150, 150, 0.3)'; | ||
context.strokeStyle = 'rgb(255, 150, 150, ' + this.transparency + ')'; | ||
context.stroke(); | ||
context.restore(); | ||
} | ||
onOutOfScreen() { | ||
this.isDestroyed = true; | ||
} | ||
|
||
export class StoneSplash extends Splash { | ||
onDraw(context) { | ||
context.save(); | ||
context.translate(this.position.x, this.position.y); | ||
context.rotate(this.direction); | ||
context.beginPath(); | ||
context.arc(0, 0, 2, 0, Math.PI * 2, true); | ||
context.fillStyle = 'rgb(110, 110, 110, ' + this.transparency + ')'; | ||
context.fill(); | ||
context.restore(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
import BlockFactory from "./BlockFactory"; | ||
import Asteroid from "../block/Asteroid"; | ||
|
||
export class AsteroidFactory extends BlockFactory { | ||
constructor(canvasWidth, canvasHeight, collection, asteroidFactory) { | ||
class AsteroidFactory extends BlockFactory { | ||
constructor(canvasWidth, canvasHeight, collection, splashFactory, asteroidFactory) { | ||
super(canvasWidth, canvasHeight, collection); | ||
this.splashFactory = splashFactory; | ||
this.asteroidFactory = asteroidFactory; | ||
} | ||
} | ||
|
||
export class BigAsteroidFactory extends AsteroidFactory { | ||
doCreate(radius, positionX, positionY, direction, speed) { | ||
return new Asteroid(this.canvasWidth, this.canvasHeight, 3, this.asteroidFactory); | ||
return new Asteroid(this.canvasWidth, this.canvasHeight, 3, this.splashFactory, this.asteroidFactory); | ||
} | ||
} | ||
export class MediumAsteroidFactory extends AsteroidFactory { | ||
doCreate(radius, positionX, positionY, direction, speed) { | ||
return new Asteroid(this.canvasWidth, this.canvasHeight, 2, this.asteroidFactory); | ||
return new Asteroid(this.canvasWidth, this.canvasHeight, 2, this.splashFactory, this.asteroidFactory); | ||
} | ||
} | ||
export class SmallAsteroidFactory extends AsteroidFactory { | ||
doCreate(radius, positionX, positionY, direction, speed) { | ||
return new Asteroid(this.canvasWidth, this.canvasHeight, 1, this.asteroidFactory); | ||
return new Asteroid(this.canvasWidth, this.canvasHeight, 1, this.splashFactory, this.asteroidFactory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import Splash from "../block/Flash"; | ||
import BlockFactory from "./BlockFactory"; | ||
import {FireSplash, StoneSplash} from "../block/Splash"; | ||
|
||
export default class FlashFactory extends BlockFactory { | ||
class SplashFactory extends BlockFactory { | ||
} | ||
|
||
export class FireSplashFactory extends SplashFactory { | ||
doCreate() { | ||
return new FireSplash(this.canvasWidth, this.canvasHeight, 2000); | ||
} | ||
} | ||
|
||
export class StoneSplashFactory extends SplashFactory { | ||
doCreate() { | ||
return new Splash(this.canvasWidth, this.canvasHeight); | ||
return new StoneSplash(this.canvasWidth, this.canvasHeight, 1500); | ||
} | ||
} |