Commit bf202af7 authored by 谌继荃's avatar 谌继荃

初始化bird

parent 986c1c4e
This diff is collapsed.
{
"scripts": {
"start": "webpack serve --open",
"build": "webpack"
},
"devDependencies": {
"ts-loader": "^9.2.6",
"typescript": "^4.4.4",
"webpack": "^5.61.0",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.4.0"
}
}
{
"scripts": {
"start": "webpack serve --open",
"build": "webpack"
},
"devDependencies": {
"ts-loader": "^9.2.6",
"typescript": "^4.4.4",
"webpack": "^5.61.0",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.4.0"
}
}
This diff is collapsed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="http://yun.duiba.com.cn/db_games/libs0924/fyge2018.minSpine.js" crossorigin="anonymous"></script>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: #faf4f4;
/* background: linear-gradient(#93dbb7,#ff0,#b5d89a); */
/* background: linear-gradient(#93dbb7,#b5d89a); */
/* 背景图片,解决加载太慢,白屏问题,加了这个下面的__loading__可以删掉了 */
/* background-size: 100%;
background-position: center;
background-image: url("https://yun.duiba.com.cn/db_games/activity/game/1550472986/resource/assets/playscene/playscenebg.jpg"); */
}
</style>
</head>
<body>
<div id="cusEngine" style="line-height:0;font-size:0">
<canvas id="canvas" style="width: 100%;height: 100%"></canvas>
</div>
<script src="bundle.js"></script>
</body>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="http://yun.duiba.com.cn/db_games/libs0924/fyge2018.minSpine.js" crossorigin="anonymous"></script>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: #faf4f4;
/* background: linear-gradient(#93dbb7,#ff0,#b5d89a); */
/* background: linear-gradient(#93dbb7,#b5d89a); */
/* 背景图片,解决加载太慢,白屏问题,加了这个下面的__loading__可以删掉了 */
/* background-size: 100%;
background-position: center;
background-image: url("https://yun.duiba.com.cn/db_games/activity/game/1550472986/resource/assets/playscene/playscenebg.jpg"); */
}
</style>
</head>
<body>
<div id="cusEngine" style="line-height:0;font-size:0">
<canvas id="canvas" style="width: 100%;height: 100%"></canvas>
</div>
<script src="bundle.js"></script>
</body>
</html>
\ No newline at end of file
import Movable from "./Movable";
export default class Bullet extends Movable {
constructor() {
super();
this.texture = FYGE.Texture.fromUrl('//yun.duiba.com.cn/aurora/assets/0bcb2c26a85addb1714b4c63f2a873aafe210749.png')
}
}
\ No newline at end of file
import Bird from "./Bird";
import MovableManager from "./MovableManager";
import Vector2 from "./Vector2";
export function addGame(stage: FYGE.Stage) {
const movableManager = new MovableManager(stage);//创建管理器
const bird = stage.addChild(new Bird());//有加速度
bird.position.set(300, 200);
bird.velocity = new Vector2(0, 0);
bird.acceleration=new Vector2(0, 1);
movableManager.add(bird);
stage.addEventListener(FYGE.MouseEvent.CLICK,onclick);
function onclick() {
bird.velocity.y = -20;
}
}
\ No newline at end of file
import Movable from "../lib/Movable";
import MovableManager from "../lib/MovableManager";
import Vector2 from "../lib/Vector2";
class BackgroundItem extends Movable {
constructor() {
super();
this.texture = FYGE.Texture.fromUrl(
"//yun.duiba.com.cn/aurora/assets/bd7b3b10169265123e52d02acf8739db5ff59b3d.png"
);
this.velocity = new Vector2(1, 0);
}
getCanRemove() {
return false;
}
}
const width = 375;
export default class Background {
constructor(stage: FYGE.Stage, movableManager: MovableManager) {
var bg = new BackgroundItem();
var bg2 = new BackgroundItem();
movableManager.add(bg);
movableManager.add(bg2);
stage.addChild(bg);
stage.addChild(bg2);
bg.y = 0;
bg2.x = width;
stage.addEventListener(FYGE.Event.ENTER_FRAME, () => {
console.log("bg.x", bg.x);
console.log("bg2.x", bg2.x);
if (bg.x > width) {
bg.x = bg2.x - width;
}
if (bg2.x > width) {
bg2.x = bg.x - width;
}
});
}
}
import Movable from "../lib/Movable";
export default class Bullet extends Movable {
constructor() {
super();
this.texture = FYGE.Texture.fromUrl(
"//yun.duiba.com.cn/aurora/assets/0bcb2c26a85addb1714b4c63f2a873aafe210749.png"
);
}
}
import Bird from "./Bird";
import MovableManager from "../lib/MovableManager";
import Vector2 from "../lib/Vector2";
import Background from "./Background";
export function addGame(stage: FYGE.Stage) {
const movableManager = new MovableManager(stage); //创建管理器
const background = new Background(stage, movableManager);
const bird = stage.addChild(new Bird()); //有加速度
bird.position.set(300, 200);
bird.velocity = new Vector2(0, 0);
bird.acceleration = new Vector2(0, 1);
movableManager.add(bird);
stage.addEventListener(FYGE.MouseEvent.CLICK, onclick);
function onclick() {
bird.velocity.y = -20;
}
}
import Vector2 from "./Vector2";
export default class Movable extends FYGE.Sprite {
private _velocity: Vector2;
set velocity(val: Vector2) { this._velocity = val }
get velocity() { return this._velocity }
private _acceleration: Vector2;
set acceleration(val: Vector2) { this._acceleration = val }
step() {
this._acceleration = this._acceleration || new Vector2(0, 0);
this._velocity.x += this._acceleration.x;
this._velocity.y += this._acceleration.y;
this.y += this._velocity.y;
this.x += this._velocity.x;
}
import Vector2 from "./Vector2";
export default class Movable extends FYGE.Sprite {
private _velocity: Vector2;
set velocity(val: Vector2) { this._velocity = val }
get velocity() { return this._velocity }
private _acceleration: Vector2;
set acceleration(val: Vector2) { this._acceleration = val }
step() {
this._acceleration = this._acceleration || new Vector2(0, 0);
this._velocity.x += this._acceleration.x;
this._velocity.y += this._acceleration.y;
this.y += this._velocity.y;
this.x += this._velocity.x;
}
}
\ No newline at end of file
import Movable from "./Movable";
export default class MovableManager {
private _stage: FYGE.Stage;
private _movableList: Movable[] = [];
constructor(stage: FYGE.Stage) {
this._stage = stage;
this._stage.addEventListener(FYGE.Event.ENTER_FRAME, this.onEnterFrame);
}
onEnterFrame = () => {
this.step();
this.checkRemove();
console.log('移动对象的数量:',this._movableList.length)
}
private calcCanRemove(item: FYGE.DisplayObject) {
if (item.y > 1624) return true;
if (item.y < -item.height) return true;
if (item.x > 750) return true;
if (item.x < -item.width) return true;
return false;
}
private checkRemove() {
for (let index = 0; index < this._movableList.length; index++) {
const item = this._movableList[index];
if (this.calcCanRemove(item)) {
this._movableList.splice(index, 1);
index--;
}
}
}
private step() {
this._movableList.forEach(item => item.step());
}
add(item: Movable) {
this._movableList.push(item);
}
remove(item: Movable) {
const index = this._movableList.indexOf(item);
this._movableList.splice(index, 1);
}
import Movable from "./Movable";
export default class MovableManager {
private _stage: FYGE.Stage;
private _movableList: Movable[] = [];
constructor(stage: FYGE.Stage) {
this._stage = stage;
this._stage.addEventListener(FYGE.Event.ENTER_FRAME, this.onEnterFrame);
}
onEnterFrame = () => {
this.step();
this.checkRemove();
console.log('移动对象的数量:',this._movableList.length)
}
private calcCanRemove(item: FYGE.DisplayObject) {
if (item.y > 1624) return true;
if (item.y < -item.height) return true;
if (item.x > 750) return true;
if (item.x < -item.width) return true;
return false;
}
private checkRemove() {
for (let index = 0; index < this._movableList.length; index++) {
const item = this._movableList[index];
if (this.calcCanRemove(item)) {
this._movableList.splice(index, 1);
index--;
}
}
}
private step() {
this._movableList.forEach(item => item.step());
}
add(item: Movable) {
this._movableList.push(item);
}
remove(item: Movable) {
const index = this._movableList.indexOf(item);
this._movableList.splice(index, 1);
}
}
\ No newline at end of file
export default class Vector2 {
x:number;
y:number;
constructor(x:number,y:number){
this.x=x;
this.y=y;
}
export default class Vector2 {
x:number;
y:number;
constructor(x:number,y:number){
this.x=x;
this.y=y;
}
}
\ No newline at end of file
import { addGame } from "./addGame";
var canvas: any = document.getElementById("canvas")
canvas.width = document.body.clientWidth * 1
canvas.height = document.body.clientHeight * 1
var stage = new FYGE.Stage(
canvas,
750,
1624,
canvas.width,
canvas.height,
FYGE.RENDERER_TYPE.CANVAS,
false,
false
)
var mouseEvent = stage.onMouseEvent.bind(stage);
canvas.addEventListener("touchstart", mouseEvent, false);
canvas.addEventListener('touchmove', mouseEvent, false);
canvas.addEventListener('touchend', mouseEvent, false);
stage.addEventListener(FYGE.Event.INIT_STAGE, onInitStage, this);
function onInitStage() {
new addGame(stage)
}
(function loop() {
FYGE.Tween.flush()
stage.flush();
requestAnimationFrame(loop);
})();
\ No newline at end of file
import { addGame } from "./bird/addGame";
var canvas: any = document.getElementById("canvas");
canvas.width = document.body.clientWidth * 1;
canvas.height = document.body.clientHeight * 1;
var stage = new FYGE.Stage(
canvas,
750,
1624,
canvas.width,
canvas.height,
FYGE.RENDERER_TYPE.CANVAS,
false,
false
);
var mouseEvent = stage.onMouseEvent.bind(stage);
canvas.addEventListener("touchstart", mouseEvent, false);
canvas.addEventListener("touchmove", mouseEvent, false);
canvas.addEventListener("touchend", mouseEvent, false);
stage.addEventListener(FYGE.Event.INIT_STAGE, onInitStage, this);
function onInitStage() {
new addGame(stage);
}
(function loop() {
FYGE.Tween.flush();
stage.flush();
requestAnimationFrame(loop);
})();
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": false,
"module": "es6",
"target": "es5",
"jsx": "react",
"allowJs": true
}
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": false,
"module": "es6",
"target": "es5",
"jsx": "react",
"allowJs": true
}
}
\ No newline at end of file
const path = require('path');
module.exports = {
mode: 'development',
devtool: 'eval',
entry: './src/main.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
},
};
const path = require('path');
module.exports = {
mode: 'development',
devtool: 'eval',
entry: './src/main.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
},
};
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment