forked from phaserjs/template-vite-ts
-
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.
- Loading branch information
1 parent
7615628
commit a383996
Showing
14 changed files
with
115 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
minecraft grass texture - https://minecraft.fandom.com/wiki/List_of_block_textures | ||
minecraft grass sprites - https://minecraft.fandom.com/wiki/List_of_block_textures | ||
stickman figures - https://www.deviantart.com/turboignited/art/Stickman-Spritesheet-691692371 | ||
mountain sprite - https://www.deviantart.com/jonata-d/art/Mountain-Sprite-001-706211298 | ||
grass tile set - https://xeleph.itch.io/side-view-grass-tileset | ||
tree textures - https://graphscriptdev.itch.io/plant-trees?download | ||
plant textures - https://www.shutterstock.com/image-vector/trees-bushes-grass-style-pixel-art-2255025673 | ||
tree sprites - https://graphscriptdev.itch.io/plant-trees?download | ||
plant sprites - https://www.shutterstock.com/image-vector/trees-bushes-grass-style-pixel-art-2255025673 | ||
cloud sprite - https://artisan-studio.itch.io/2d-pixel-art-semi-realistic-clouds?download | ||
sun sprite - https://www.shutterstock.com/image-vector/sun-sticker-pixel-art-icon-design-2148275463 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
71 changes: 71 additions & 0 deletions
71
src/scenes/game/world-decoration/cloud-containers/cloud-container.ts
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Physics } from "phaser"; | ||
import { Game as MainGame } from "../../index"; | ||
import { DecorationContainer } from "../decoration-container"; | ||
import { screenSize } from "../../../../constants"; | ||
|
||
export abstract class CloudContainer extends DecorationContainer { | ||
cloudScale = 1; | ||
cloudSpeed = 0.15; | ||
|
||
// static scaleVariation = 3; // deviation from treeScale (subtraction or addition) | ||
static cloudCount = 6; // number of tree textures labeled as "tree{n}" [0, n) | ||
|
||
constructor( | ||
scene: MainGame, | ||
private cloudGroup: Physics.Arcade.StaticGroup | ||
) { | ||
super(scene, cloudGroup); | ||
for (let i = 0; i < CloudContainer.cloudCount; i++) { | ||
this.scene.textures | ||
.get("cloud" + i) | ||
.setFilter(Phaser.Textures.FilterMode.NEAREST); | ||
} | ||
} | ||
|
||
create() { | ||
this.populateClouds(10); | ||
} | ||
|
||
createCloud(x: number) { | ||
const cloud = this.scene.add | ||
.image( | ||
0, | ||
0, | ||
"cloud" + Math.floor(Math.random() * CloudContainer.cloudCount) | ||
) | ||
.setScale( | ||
this.cloudScale //+ | ||
// (Math.random() - 0.5) * TreeContainer.scaleVariation | ||
) | ||
.setOrigin(0, 0); | ||
|
||
const posX = x * cloud.width * this.cloudScale; | ||
cloud.setPosition(posX, cloud.height); | ||
cloud.setData("startingX", x); | ||
this.staticGroup.add(cloud); | ||
} | ||
|
||
populateClouds(width: number) { | ||
const start = Math.random() * 2; | ||
|
||
for (let i = -start; i < width - 1; i += 1) { | ||
this.createCloud(i); | ||
} | ||
} | ||
|
||
update(_: number, delta: number) { | ||
this.cloudGroup.getChildren().forEach((_cloud) => { | ||
const cloud = _cloud as Phaser.Physics.Arcade.Image; | ||
const offset = this.cloudSpeed * delta; | ||
cloud.setPosition(cloud.x - offset, cloud.y); | ||
if (cloud.x < -screenSize.x) { | ||
cloud.setPosition( | ||
screenSize.x + | ||
1000 + | ||
cloud.getData("startingX") * cloud.width * this.cloudScale, | ||
cloud.y | ||
); | ||
} | ||
}); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/scenes/game/world-decoration/cloud-containers/cloud-container1.ts
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Physics } from "phaser"; | ||
import { Game as MainGame } from "../../index"; | ||
import { CloudContainer } from "./cloud-container"; | ||
|
||
export class CloudContainer1 extends CloudContainer { | ||
constructor(scene: MainGame, cloudGroup: Physics.Arcade.StaticGroup) { | ||
super(scene, cloudGroup); | ||
this.cloudScale = 8; | ||
this.create(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./cloud-container1"; |
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