Mudanca de projeto para Phazer

This commit is contained in:
2026-03-30 22:03:59 -03:00
parent 570b4e1fa2
commit 91e7b1c681
35 changed files with 3756 additions and 1875 deletions
+12
View File
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
+21
View File
@@ -0,0 +1,21 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Phaser Studio Inc
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+230 -41
View File
@@ -1,54 +1,243 @@
# React + TypeScript + Vite
# Phaser React Template
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
This is a Phaser 3 project template that uses the React framework and Vite for bundling. It includes a bridge for React to Phaser game communication, hot-reloading for quick development workflow and scripts to generate production-ready builds.
Currently, two official plugins are available:
**[This Template is also available as a TypeScript version.](https://github.com/phaserjs/template-react-ts)**
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
### Versions
## Expanding the ESLint configuration
This template has been updated for:
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
- [Phaser 3.90.0](https://github.com/phaserjs/phaser)
- [React 19.0.0](https://github.com/facebook/react)
- [Vite 6.3.1](https://github.com/vitejs/vite)
![screenshot](screenshot.png)
## Requirements
[Node.js](https://nodejs.org) is required to install dependencies and run scripts via `npm`.
## Available Commands
| Command | Description |
|---------|-------------|
| `npm install` | Install project dependencies |
| `npm run dev` | Launch a development web server |
| `npm run build` | Create a production build in the `dist` folder |
| `npm run dev-nolog` | Launch a development web server without sending anonymous data (see "About log.js" below) |
| `npm run build-nolog` | Create a production build in the `dist` folder without sending anonymous data (see "About log.js" below) |
## Writing Code
After cloning the repo, run `npm install` from your project directory. Then, you can start the local development server by running `npm run dev`.
The local development server runs on `http://localhost:8080` by default. Please see the Vite documentation if you wish to change this, or add SSL support.
Once the server is running you can edit any of the files in the `src` folder. Vite will automatically recompile your code and then reload the browser.
## Template Project Structure
We have provided a default project structure to get you started. This is as follows:
| Path | Description |
|-------------------------------|-----------------------------------------------------------------------------|
| `index.html` | A basic HTML page to contain the game. |
| `src` | Contains the React client source code. |
| `src/main.jsx` | The main **React** entry point. This bootstraps the React application. |
| `src/App.jsx` | The main React component. |
| `src/PhaserGame.jsx` | The React component that initializes the Phaser Game and serves as a bridge between React and Phaser. |
| `src/game/EventBus.js` | A simple event bus to communicate between React and Phaser. |
| `src/game` | Contains the game source code. |
| `src/game/main.jsx` | The main **game** entry point. This contains the game configuration and starts the game. |
| `src/game/scenes/` | The Phaser Scenes are in this folder. |
| `public/style.css` | Some simple CSS rules to help with page layout. |
| `public/assets` | Contains the static assets used by the game. |
## React Bridge
The `PhaserGame.jsx` component is the bridge between React and Phaser. It initializes the Phaser game and passes events between the two.
To communicate between React and Phaser, you can use the **EventBus.js** file. This is a simple event bus that allows you to emit and listen for events from both React and Phaser.
```js
export default tseslint.config({
extends: [
// Remove ...tseslint.configs.recommended and replace with this
...tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
...tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
// In React
import { EventBus } from './EventBus';
// Emit an event
EventBus.emit('event-name', data);
// In Phaser
// Listen for an event
EventBus.on('event-name', (data) => {
// Do something with the data
});
```
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
In addition to this, the `PhaserGame` component exposes the Phaser game instance along with the most recently active Phaser Scene using React forwardRef.
Once exposed, you can access them like any regular react reference.
## Phaser Scene Handling
In Phaser, the Scene is the lifeblood of your game. It is where you sprites, game logic and all of the Phaser systems live. You can also have multiple scenes running at the same time. This template provides a way to obtain the current active scene from React.
You can get the current Phaser Scene from the component event `"current-active-scene"`. In order to do this, you need to emit the event `"current-scene-ready"` from the Phaser Scene class. This event should be emitted when the scene is ready to be used. You can see this done in all of the Scenes in our template.
**Important**: When you add a new Scene to your game, make sure you expose to React by emitting the `"current-scene-ready"` event via the `EventBus`, like this:
```js
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'
class MyScene extends Phaser.Scene
{
constructor ()
{
super('MyScene');
}
export default tseslint.config({
plugins: {
// Add the react-x and react-dom plugins
'react-x': reactX,
'react-dom': reactDom,
},
rules: {
// other rules...
// Enable its recommended typescript rules
...reactX.configs['recommended-typescript'].rules,
...reactDom.configs.recommended.rules,
},
})
create ()
{
// Your Game Objects and logic here
// At the end of create method:
EventBus.emit('current-scene-ready', this);
}
}
```
You don't have to emit this event if you don't need to access the specific scene from React. Also, you don't have to emit it at the end of `create`, you can emit it at any point. For example, should your Scene be waiting for a network request or API call to complete, it could emit the event once that data is ready.
### React Component Example
Here's an example of how to access Phaser data for use in a React Component:
```js
import { useRef } from 'react';
// In a parent component
const ReactComponent = () => {
const phaserRef = useRef(); // you can access to this ref from phaserRef.current
const onCurrentActiveScene = (scene) => {
// This is invoked
}
return (
...
<PhaserGame ref={phaserRef} currentActiveScene={onCurrentActiveScene} />
...
);
}
```
In the code above, you can get a reference to the current Phaser Game instance and the current Scene by creating a reference with `useRef()` and assign to PhaserGame component.
From this state reference, the game instance is available via `phaserRef.current.game` and the most recently active Scene via `phaserRef.current.scene`.
The `onCurrentActiveScene` callback will also be invoked whenever the the Phaser Scene changes, as long as you emit the event via the EventBus, as outlined above.
## Handling Assets
Vite supports loading assets via JavaScript module `import` statements.
This template provides support for both embedding assets and also loading them from a static folder. To embed an asset, you can import it at the top of the JavaScript file you are using it in:
```js
import logoImg from './assets/logo.png'
```
To load static files such as audio files, videos, etc place them into the `public/assets` folder. Then you can use this path in the Loader calls within Phaser:
```js
preload ()
{
// This is an example of an imported bundled image.
// Remember to import it at the top of this file
this.load.image('logo', logoImg);
// This is an example of loading a static image
// from the public/assets folder:
this.load.image('background', 'assets/bg.png');
}
```
When you issue the `npm run build` command, all static assets are automatically copied to the `dist/assets` folder.
## Deploying to Production
After you run the `npm run build` command, your code will be built into a single bundle and saved to the `dist` folder, along with any other assets your project imported, or stored in the public assets folder.
In order to deploy your game, you will need to upload *all* of the contents of the `dist` folder to a public facing web server.
## Customizing the Template
### Vite
If you want to customize your build, such as adding plugin (i.e. for loading CSS or fonts), you can modify the `vite/config.*.mjs` file for cross-project changes, or you can modify and/or create new configuration files and target them in specific npm tasks inside of `package.json`. Please see the [Vite documentation](https://vitejs.dev/) for more information.
## About log.js
If you inspect our node scripts you will see there is a file called `log.js`. This file makes a single silent API call to a domain called `gryzor.co`. This domain is owned by Phaser Studio Inc. The domain name is a homage to one of our favorite retro games.
We send the following 3 pieces of data to this API: The name of the template being used (vue, react, etc). If the build was 'dev' or 'prod' and finally the version of Phaser being used.
At no point is any personal data collected or sent. We don't know about your project files, device, browser or anything else. Feel free to inspect the `log.js` file to confirm this.
Why do we do this? Because being open source means we have no visible metrics about which of our templates are being used. We work hard to maintain a large and diverse set of templates for Phaser developers and this is our small anonymous way to determine if that work is actually paying off, or not. In short, it helps us ensure we're building the tools for you.
However, if you don't want to send any data, you can use these commands instead:
Dev:
```bash
npm run dev-nolog
```
Build:
```bash
npm run build-nolog
```
Or, to disable the log entirely, simply delete the file `log.js` and remove the call to it in the `scripts` section of `package.json`:
Before:
```json
"scripts": {
"dev": "node log.js dev & dev-template-script",
"build": "node log.js build & build-template-script"
},
```
After:
```json
"scripts": {
"dev": "dev-template-script",
"build": "build-template-script"
},
```
Either of these will stop `log.js` from running. If you do decide to do this, please could you at least join our Discord and tell us which template you're using! Or send us a quick email. Either will be super-helpful, thank you.
## Join the Phaser Community!
We love to see what developers like you create with Phaser! It really motivates us to keep improving. So please join our community and show-off your work 😄
**Visit:** The [Phaser website](https://phaser.io) and follow on [Phaser Twitter](https://twitter.com/phaser_)<br />
**Play:** Some of the amazing games [#madewithphaser](https://twitter.com/search?q=%23madewithphaser&src=typed_query&f=live)<br />
**Learn:** [API Docs](https://newdocs.phaser.io), [Support Forum](https://phaser.discourse.group/) and [StackOverflow](https://stackoverflow.com/questions/tagged/phaser-framework)<br />
**Discord:** Join us on [Discord](https://discord.gg/phaser)<br />
**Code:** 2000+ [Examples](https://labs.phaser.io)<br />
**Read:** The [Phaser World](https://phaser.io/community/newsletter) Newsletter<br />
Created by [Phaser Studio](mailto:support@phaser.io). Powered by coffee, anime, pixels and love.
The Phaser logo and characters are &copy; 2011 - 2025 Phaser Studio Inc.
All rights reserved.
-28
View File
@@ -1,28 +0,0 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
+9 -7
View File
@@ -1,13 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/png" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<link rel="stylesheet" href="/style.css">
<title>Phaser React Template</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
+36
View File
@@ -0,0 +1,36 @@
import * as fs from 'fs';
import * as https from 'https';
export const main = async () => {
const args = process.argv.slice(2);
const packageData = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const event = args[0] || 'unknown';
const phaserVersion = packageData.dependencies.phaser;
const options = {
hostname: 'gryzor.co',
port: 443,
path: `/v/${event}/${phaserVersion}/${packageData.name}`,
method: 'GET'
};
try {
const req = https.request(options, (res) => {
res.on('data', () => {});
res.on('end', () => {
process.exit(0);
});
});
req.on('error', (error) => {
process.exit(1);
});
req.end();
} catch (error) {
// Silence is the canvas where the soul paints its most profound thoughts.
process.exit(1);
}
}
main();
+2864
View File
File diff suppressed because it is too large Load Diff
+44 -29
View File
@@ -1,31 +1,46 @@
{
"name": "vite-project",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@pixi/react": "^8.0.2",
"pixi.js": "^8.10.1",
"react": "^19.1.0",
"react-dom": "^19.1.0"
},
"devDependencies": {
"@eslint/js": "^9.25.0",
"@types/react": "^19.1.2",
"@types/react-dom": "^19.1.2",
"@vitejs/plugin-react": "^4.4.1",
"eslint": "^9.25.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"typescript": "~5.8.3",
"typescript-eslint": "^8.30.1",
"vite": "^6.3.5"
}
"name": "template-react",
"description": "A Phaser 3 project template that demonstrates React communication and uses Vite for bundling.",
"version": "1.2.0",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/phaserjs/template-react.git"
},
"author": "Phaser Studio <support@phaser.io> (https://phaser.io/)",
"license": "MIT",
"licenseUrl": "http://www.opensource.org/licenses/mit-license.php",
"bugs": {
"url": "https://github.com/phaserjs/template-react/issues"
},
"homepage": "https://github.com/phaserjs/template-react#readme",
"keywords": [
"phaser",
"phaser3",
"react",
"vite"
],
"scripts": {
"dev": "node log.js dev & vite --config vite/config.dev.mjs",
"build": "node log.js build & vite build --config vite/config.prod.mjs",
"dev-nolog": "vite --config vite/config.dev.mjs",
"build-nolog": "vite build --config vite/config.prod.mjs"
},
"dependencies": {
"phaser": "^3.90.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@eslint/js": "^9.22.0",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@vitejs/plugin-react": "^4.3.4",
"eslint": "^9.22.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"vite": "^6.3.1",
"terser": "5.39.0"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 296 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B

+48
View File
@@ -0,0 +1,48 @@
body {
margin: 0;
padding: 0;
color: rgba(255, 255, 255, 0.87);
background-color: #000000;
font-family: Arial, Helvetica, sans-serif;
}
#app {
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
}
.spritePosition {
margin: 10px 0 0 10px;
font-size: 0.8em;
}
.button {
width: 140px;
margin: 10px;
padding: 10px;
background-color: #000000;
color: rgba(255, 255, 255, 0.87);
border: 1px solid rgba(255, 255, 255, 0.87);
cursor: pointer;
transition: all 0.3s;
&:hover {
border: 1px solid #0ec3c9;
color: #0ec3c9;
}
&:active {
background-color: #0ec3c9;
}
/* Disabled styles */
&:disabled {
cursor: not-allowed;
border: 1px solid rgba(255, 255, 255, 0.3);
color: rgba(255, 255, 255, 0.3);
}
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 589 KiB

+94
View File
@@ -0,0 +1,94 @@
import { useRef, useState } from 'react';
import Phaser from 'phaser';
import { PhaserGame } from './PhaserGame';
function App ()
{
// The sprite can only be moved in the MainMenu Scene
const [canMoveSprite, setCanMoveSprite] = useState(true);
// References to the PhaserGame component (game and scene are exposed)
const phaserRef = useRef();
const [spritePosition, setSpritePosition] = useState({ x: 0, y: 0 });
const changeScene = () => {
const scene = phaserRef.current.scene;
if (scene)
{
scene.changeScene();
}
}
const moveSprite = () => {
const scene = phaserRef.current.scene;
if (scene && scene.scene.key === 'MainMenu')
{
// Get the update logo position
scene.moveLogo(({ x, y }) => {
setSpritePosition({ x, y });
});
}
}
const addSprite = () => {
const scene = phaserRef.current.scene;
if (scene)
{
// Add more stars
const x = Phaser.Math.Between(64, scene.scale.width - 64);
const y = Phaser.Math.Between(64, scene.scale.height - 64);
// `add.sprite` is a Phaser GameObjectFactory method and it returns a Sprite Game Object instance
const star = scene.add.sprite(x, y, 'star');
// ... which you can then act upon. Here we create a Phaser Tween to fade the star sprite in and out.
// You could, of course, do this from within the Phaser Scene code, but this is just an example
// showing that Phaser objects and systems can be acted upon from outside of Phaser itself.
scene.add.tween({
targets: star,
duration: 500 + Math.random() * 1000,
alpha: 0,
yoyo: true,
repeat: -1
});
}
}
// Event emitted from the PhaserGame component
const currentScene = (scene) => {
setCanMoveSprite(scene.scene.key !== 'MainMenu');
}
return (
<div id="app">
<PhaserGame ref={phaserRef} currentActiveScene={currentScene} />
<div>
<div>
<button className="button" onClick={changeScene}>Change Scene</button>
</div>
<div>
<button disabled={canMoveSprite} className="button" onClick={moveSprite}>Toggle Movement</button>
</div>
<div className="spritePosition">Sprite Position:
<pre>{`{\n x: ${spritePosition.x}\n y: ${spritePosition.y}\n}`}</pre>
</div>
<div>
<button className="button" onClick={addSprite}>Add New Sprite</button>
</div>
</div>
</div>
)
}
export default App
-9
View File
@@ -1,9 +0,0 @@
function App() {
return (
<>
<h1>UMA COISA MUITO FODA OMEGA</h1>
</>
)
}
export default App
+57
View File
@@ -0,0 +1,57 @@
import { forwardRef, useEffect, useLayoutEffect, useRef } from 'react';
import StartGame from './game/main';
import { EventBus } from './game/EventBus';
export const PhaserGame = forwardRef(function PhaserGame ({ currentActiveScene }, ref)
{
const game = useRef();
// Create the game inside a useLayoutEffect hook to avoid the game being created outside the DOM
useLayoutEffect(() => {
if (game.current === undefined)
{
game.current = StartGame("game-container");
if (ref !== null)
{
ref.current = { game: game.current, scene: null };
}
}
return () => {
if (game.current)
{
game.current.destroy(true);
game.current = undefined;
}
}
}, [ref]);
useEffect(() => {
EventBus.on('current-scene-ready', (currentScene) => {
if (currentActiveScene instanceof Function)
{
currentActiveScene(currentScene);
}
ref.current.scene = currentScene;
});
return () => {
EventBus.removeListener('current-scene-ready');
}
}, [currentActiveScene, ref])
return (
<div id="game-container"></div>
);
});
+4
View File
@@ -0,0 +1,4 @@
import Phaser from 'phaser';
// Used to emit events between components, HTML and Phaser scenes
export const EventBus = new Phaser.Events.EventEmitter();
+31
View File
@@ -0,0 +1,31 @@
import { Boot } from './scenes/Boot';
import { Game } from './scenes/Game';
import { GameOver } from './scenes/GameOver';
import { MainMenu } from './scenes/MainMenu';
import Phaser from 'phaser';
import { Preloader } from './scenes/Preloader';
// Find out more information about the Game Config at:
// https://docs.phaser.io/api-documentation/typedef/types-core#gameconfig
const config = {
type: Phaser.AUTO,
width: 1024,
height: 768,
parent: 'game-container',
backgroundColor: '#028af8',
scene: [
Boot,
Preloader,
MainMenu,
Game,
GameOver
]
};
const StartGame = (parent) => {
return new Phaser.Game({ ...config, parent });
}
export default StartGame;
+22
View File
@@ -0,0 +1,22 @@
import { Scene } from 'phaser';
export class Boot extends Scene
{
constructor ()
{
super('Boot');
}
preload ()
{
// The Boot Scene is typically used to load in any assets you require for your Preloader, such as a game logo or background.
// The smaller the file size of the assets, the better, as the Boot Scene itself has no preloader.
this.load.image('background', 'assets/bg.png');
}
create ()
{
this.scene.start('Preloader');
}
}
+30
View File
@@ -0,0 +1,30 @@
import { EventBus } from '../EventBus';
import { Scene } from 'phaser';
export class Game extends Scene
{
constructor ()
{
super('Game');
}
create ()
{
this.cameras.main.setBackgroundColor(0x00ff00);
this.add.image(512, 384, 'background').setAlpha(0.5);
this.add.text(512, 384, 'Make something fun!\nand share it with us:\nsupport@phaser.io', {
fontFamily: 'Arial Black', fontSize: 38, color: '#ffffff',
stroke: '#000000', strokeThickness: 8,
align: 'center'
}).setOrigin(0.5).setDepth(100);
EventBus.emit('current-scene-ready', this);
}
changeScene ()
{
this.scene.start('GameOver');
}
}
+30
View File
@@ -0,0 +1,30 @@
import { EventBus } from '../EventBus';
import { Scene } from 'phaser';
export class GameOver extends Scene
{
constructor ()
{
super('GameOver');
}
create ()
{
this.cameras.main.setBackgroundColor(0xff0000);
this.add.image(512, 384, 'background').setAlpha(0.5);
this.add.text(512, 384, 'Game Over', {
fontFamily: 'Arial Black', fontSize: 64, color: '#ffffff',
stroke: '#000000', strokeThickness: 8,
align: 'center'
}).setOrigin(0.5).setDepth(100);
EventBus.emit('current-scene-ready', this);
}
changeScene ()
{
this.scene.start('MainMenu');
}
}
+72
View File
@@ -0,0 +1,72 @@
import { EventBus } from '../EventBus';
import { Scene } from 'phaser';
export class MainMenu extends Scene
{
logoTween;
constructor ()
{
super('MainMenu');
}
create ()
{
this.add.image(512, 384, 'background');
this.logo = this.add.image(512, 300, 'logo').setDepth(100);
this.add.text(512, 460, 'Main Menu', {
fontFamily: 'Arial Black', fontSize: 38, color: '#ffffff',
stroke: '#000000', strokeThickness: 8,
align: 'center'
}).setDepth(100).setOrigin(0.5);
EventBus.emit('current-scene-ready', this);
}
changeScene ()
{
if (this.logoTween)
{
this.logoTween.stop();
this.logoTween = null;
}
this.scene.start('Game');
}
moveLogo (reactCallback)
{
if (this.logoTween)
{
if (this.logoTween.isPlaying())
{
this.logoTween.pause();
}
else
{
this.logoTween.play();
}
}
else
{
this.logoTween = this.tweens.add({
targets: this.logo,
x: { value: 750, duration: 3000, ease: 'Back.easeInOut' },
y: { value: 80, duration: 1500, ease: 'Sine.easeOut' },
yoyo: true,
repeat: -1,
onUpdate: () => {
if (reactCallback)
{
reactCallback({
x: Math.floor(this.logo.x),
y: Math.floor(this.logo.y)
});
}
}
});
}
}
}
+47
View File
@@ -0,0 +1,47 @@
import { Scene } from 'phaser';
export class Preloader extends Scene
{
constructor ()
{
super('Preloader');
}
init ()
{
// We loaded this image in our Boot Scene, so we can display it here
this.add.image(512, 384, 'background');
// A simple progress bar. This is the outline of the bar.
this.add.rectangle(512, 384, 468, 32).setStrokeStyle(1, 0xffffff);
// This is the progress bar itself. It will increase in size from the left based on the % of progress.
const bar = this.add.rectangle(512-230, 384, 4, 28, 0xffffff);
// Use the 'progress' event emitted by the LoaderPlugin to update the loading bar
this.load.on('progress', (progress) => {
// Update the progress bar (our bar is 464px wide, so 100% = 464px)
bar.width = 4 + (460 * progress);
});
}
preload ()
{
// Load the assets for the game - Replace with your own assets
this.load.setPath('assets');
this.load.image('logo', 'logo.png');
this.load.image('star', 'star.png');
}
create ()
{
// When all the assets have loaded, it's often worth creating global objects here that the rest of the game can use.
// For example, you can define global animations here, so we can use them in other scenes.
// Move to the MainMenu. You could also swap this for a Scene Transition, such as a camera fade.
this.scene.start('MainMenu');
}
}
+9
View File
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App.jsx';
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
-9
View File
@@ -1,9 +0,0 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import App from './App.tsx'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
-1
View File
@@ -1 +0,0 @@
/// <reference types="vite/client" />
-27
View File
@@ -1,27 +0,0 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}
-7
View File
@@ -1,7 +0,0 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}
-25
View File
@@ -1,25 +0,0 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}
-7
View File
@@ -1,7 +0,0 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
})
+13
View File
@@ -0,0 +1,13 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
base: './',
plugins: [
react(),
],
server: {
port: 8080
}
})
+48
View File
@@ -0,0 +1,48 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
const phasermsg = () => {
return {
name: 'phasermsg',
buildStart() {
process.stdout.write(`Building for production...\n`);
},
buildEnd() {
const line = "---------------------------------------------------------";
const msg = `❤️❤️❤️ Tell us about your game! - games@phaser.io ❤️❤️❤️`;
process.stdout.write(`${line}\n${msg}\n${line}\n`);
process.stdout.write(`✨ Done ✨\n`);
}
}
}
export default defineConfig({
base: './',
plugins: [
react(),
phasermsg()
],
logLevel: 'warning',
build: {
rollupOptions: {
output: {
manualChunks: {
phaser: ['phaser']
}
}
},
minify: 'terser',
terserOptions: {
compress: {
passes: 2
},
mangle: true,
format: {
comments: false
}
},
outDir: "../Sites/GameProd",
emptyOutDir: true,
}
});
-1671
View File
File diff suppressed because it is too large Load Diff