Commit 54a27744 authored by Friends233's avatar Friends233

坠落、跳跃动效、滑动背景

parent 4fc3d9b8
......@@ -131,6 +131,7 @@ export namespace RES {
* @param name
*/
export function loadGroup(name: string): Promise<void> {
console.log(groupsCompleteHash)
//已经加载完成的直接返回
if (groupsCompleteHash[name]) {//其实直接return就行
return new Promise((resolve) => {
......@@ -328,6 +329,7 @@ export namespace RES {
* @return 已加载好得素材或null
*/
export function getRes(str: string)/*: Texture | VideoEntity*/ {
console.log(textureHash)
if (!str) return null;
var type = str.substring(str.lastIndexOf(".") + 1, str.length);
if (type == "png" || type == "jpg") {
......
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>new_game_template</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<!-- polyfill -->
<script src="//yun.duiba.com.cn/db_games/libs0924/polyfill_220525.js" crossorigin="anonymous"></script>
<!-- 渲染引擎 -->
<script src="//yun.duiba.com.cn/db_games/libs0924/fyge2044.min.js" crossorigin="anonymous"></script>
<!--<script src="libs/fyge.min.js" crossorigin="anonymous"></script>-->
<!-- svga解析库 -->
<script src="//yun.duiba.com.cn/db_games/libs0924/svgaParser.minWeb.js" crossorigin="anonymous"></script>
<!-- 放声音的 -->
<script src="//yun.duiba.com.cn/db_games/libs0924/howler.min.js" crossorigin="anonymous"></script>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: #ffffff;
}
#__loading__ {
position: absolute;
left: 50%;
top: 50%;
margin-left: -45px;
color: #ffffff;
}
#cusEngine {
line-height: 0;
font-size: 0;
position: absolute;
}
#canvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="__loading__">拼命加载中...</div>
<div id="cusEngine">
<canvas id="canvas"></canvas>
</div>
<!-- 帧率检测 -->
<!-- <script src="https://yun.duiba.com.cn/db_games/libs0126/stats.js"></script> -->
<script>
const app = {
checkMember: () => {
return false;
}
};
function getApp() {
return app;
}
// document.oncontextmenu = () => false;
</script>
<script>
var CFG = CFG || {};
CFG.projectId = 'pa525eacc';//线上直接写死
CFG.appID = '76177';//线上直接写死
//TODO我的奖品链接
window["recordUrl"] = "fe071865b.html";
window.addEventListener("load", function () {
//获取canvas
var canvas = document.getElementById("canvas");
canvas.width = document.body.clientWidth * (window.devicePixelRatio || 1)
canvas.height = document.body.clientHeight * (window.devicePixelRatio || 1)
var main = new output.Game(canvas);
main.initWebEvent();
window.stage = main.stage
})
</script>
<!-- 构建的js -->
<script src="//yun.duiba.com.cn/db_games/activity/template/1660209753/output.js" crossorigin="anonymous"></script>
</body>
</html>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -12,6 +12,10 @@
"keys": "reviveBg.png,reviveCancel.png,reviveOk.png",
"name": "RevivePanel"
},
{
"keys": "base.png,pipe_green.png,redbird_downflap.png,redbird_midflap.png,redbird_upflap.png",
"name": "bird"
},
{
"keys": "comCloseBtn.png,com_bg.jpg,toastBg.png,waitingBg.png,waitingRot.png",
"name": "common"
......
......@@ -3,7 +3,7 @@ import { RES } from "../module/RES";
import { changeScene, destroyAllCtrls, showToast } from "../module/ctrls";
import { G_EVENT } from "./common/G_EVENT";
import { IndexScene } from "./scenes/IndexScene";
import MusicBtn from "./scenes/Jump3D/MusicBtn";
import { ResJson } from "./ResJson";
import { SkinJson } from "./SkinJson";
......@@ -106,6 +106,10 @@ export class Game {
await RES.loadGroup("common");
console.log("通用资源加载完成");
//加载通用资源
await RES.loadGroup("bird");
console.log("bird资源加载完成");
// h5环境时,隐藏加载中
if (getEnv() == "web" && document.getElementById("__loading__")) {
document.getElementById("__loading__").style.display = "none";
......
......@@ -12,6 +12,10 @@ export const ResJson = {
"keys": "reviveBg.png,reviveCancel.png,reviveOk.png",
"name": "RevivePanel"
},
{
"keys": "base.png,pipe_green.png,redbird_downflap.png,redbird_midflap.png,redbird_upflap.png",
"name": "bird"
},
{
"keys": "comCloseBtn.png,com_bg.jpg,toastBg.png,waitingBg.png,waitingRot.png",
"name": "common"
......
......@@ -3,7 +3,7 @@ import { Scene } from "../../module/views/Scene";
import { Tools } from "../tools/Tools";
import UI from "../tools/UI";
import { Bird } from "./bird";
import { LoadingScene } from "./LoadingScene";
import { SlideBg } from "./slideBg";
import Button = FYGE.Button;
import Container = FYGE.Container;
import Shape = FYGE.Shape;
......@@ -12,6 +12,7 @@ import TEXT_ALIGN = FYGE.TEXT_ALIGN;
import TextField = FYGE.TextField;
import VERTICAL_ALIGN = FYGE.VERTICAL_ALIGN;
import Texture = FYGE.Texture;
import FrameAni = FYGE.FrameAni
export class IndexScene extends Scene {
......@@ -30,11 +31,15 @@ export class IndexScene extends Scene {
/** 游戏是否开始 */
private isGameStart: boolean = false
/** 滑动背景 */
private slideBg: SlideBg = null
async initUi() {
// UI.Sp(this, Texture.from('com_bg.jpg'))
this.addChild(new Sprite(Texture.from('com_bg.jpg')))
this.slideBg = new SlideBg()
this.addChild(this.slideBg)
const bird = this.bird = new Bird()
bird.x = (this.width - bird.width) * 0.5
bird.x = 100
bird.y = 800
this.addChild(bird)
this._initEvents()
......@@ -47,7 +52,7 @@ export class IndexScene extends Scene {
/** 检查小鸟掉落位置 */
_checkRmove() {
if (this.bird.y >= (this.bird.height + this.height)) {
if (this.bird.y >= (this.bird.height + this.stage.stageHeight)) {
// this.removeChild(this.bird)
this.gameOver()
}
......@@ -56,8 +61,9 @@ export class IndexScene extends Scene {
/** 帧动画 */
_enterFrame() {
if (this.isGameOver || !this.isGameStart) return
console.log(this.bird.y)
this.bird.fail(1)
// console.log(this.bird.y)
this.slideBg.enterFrame()
this.bird.fail(0.6)
this._checkRmove()
}
......
import { RES } from "../../module/RES";
import { Scene } from "../../module/views/Scene";
import { LoadingEffect } from "../lotties/LoadingEffect";
import { changeScene } from "../../module/ctrls";
import UI from "../tools/UI";
import { getBoxConfig, M_loadGLB, typeArr } from "./Jump3D/MT";
import { PlayScene } from "./Jump3D/PlayScene";
import Lottie = FYGE.Lottie;
import Tween = FYGE.Tween;
import Event = FYGE.Event;
export class LoadingScene extends Scene {
get groupNames(): string[] {
return [
'loading',
'LoadingEffect',
]
}
initUi() {
UI.Sp(this, "com_bg.jpg");
UI.Sp(this, "loading_title.png", 115, 356);
const ani = this.addChild(new Lottie(LoadingEffect));
ani.y = 710;
ani.play();
}
async start() {
super.start()
this.addEventListener(Event.PROGRESS, this.progressEvent, this);
const loadPromise = [];
let pro = 0.0;
for (let k of typeArr) {
const config = getBoxConfig(k);
loadPromise.push((async () => {
await M_loadGLB(config.src);
this.dispatchEvent(Event.PROGRESS, pro += 0.8 / typeArr.length);
})());
// await M_loadGLB(config.src);
// this.dispatchEvent(Event.PROGRESS, pro += 0.8 / typeArr.length);
}
await Promise.all(loadPromise);
this.dispatchEvent(Event.PROGRESS, 0.9);
await RES.loadGroup("game");
this.dispatchEvent(Event.PROGRESS, 1);
}
progressEvent(e: Event) {
let pro = e.data;
Tween.get({}, null, null, true)
.to({ value: pro }, 0)
.call(() => {
if (pro >= 1) {
this.removeEventListener(Event.PROGRESS, this.progressEvent, this);
changeScene(PlayScene);
// sendTbNet(TbNetName.openMusic, { isOn: true });
}
});
}
destroy() {
//动效要去掉
// Tween.removeTweens()
super.destroy()
//到时如果内存炸了,考虑销毁用过的贴图缓存,待测试,在RES里写个根据销毁组内贴图的方法
}
}
......@@ -3,6 +3,7 @@ import { Scene } from "../../module/views/Scene";
import { Tools } from "../tools/Tools";
import UI from "../tools/UI";
import { LoadingScene } from "./LoadingScene";
import { RES } from '../../module/RES';
import Button = FYGE.Button;
import Container = FYGE.Container;
import Shape = FYGE.Shape;
......@@ -11,11 +12,12 @@ import TEXT_ALIGN = FYGE.TEXT_ALIGN;
import TextField = FYGE.TextField;
import VERTICAL_ALIGN = FYGE.VERTICAL_ALIGN;
import Texture = FYGE.Texture;
import FrameAni = FYGE.FrameAni;
/** 初始坠落步长 */
const FIAL_STEP = 5
const FIAL_STEP = 4
/** 初始跳跃步长 */
const JUMP_STEP = 30
const JUMP_STEP = 20
export class Bird extends Container {
/** 坠落步长 */
......@@ -24,13 +26,35 @@ export class Bird extends Container {
/** 跳跃步长 */
jumpStep = JUMP_STEP
player: FrameAni = null
constructor() {
super()
this.initUi()
}
async initUi() {
this.addChild(new Sprite(Texture.fromUrl('//yun.duiba.com.cn/aurora/assets/0bcb2c26a85addb1714b4c63f2a873aafe210749.png')))
const birdAni = [
RES.getRes('redbird_upflap.png'),
RES.getRes('redbird_midflap.png'),
RES.getRes('redbird_downflap.png'),
]
this.player = new FrameAni(birdAni)
this.player.play(0)
this.player.scale.x = 3
this.player.scale.y = 3
this.addChild(this.player)
}
/** 旋转小鸟位置 */
birdRotation() {
if (this.failStep > 0) {
this.rotation = Math.min(80, this.failStep * 2)
} else if (this.failStep < 0) {
this.rotation = -25
} else {
this.rotation = 0
}
}
/**
......@@ -41,9 +65,10 @@ export class Bird extends Container {
this.failStep += acceleration
// console.log(this.step.toFixed(2))
this.y = Math.max(this.y + this.failStep, 0)
if(this.y == 0){
if (this.y == 0) {
this.reset()
}
this.birdRotation()
}
/** 小鸟跳跃 */
......@@ -53,7 +78,7 @@ export class Bird extends Container {
}
/** 重置 */
reset(){
reset() {
this.failStep = FIAL_STEP
this.jumpStep = JUMP_STEP
}
......
import { changeScene } from "../../module/ctrls";
import { Scene } from "../../module/views/Scene";
import { Tools } from "../tools/Tools";
import UI from "../tools/UI";
import { LoadingScene } from "./LoadingScene";
import { RES } from '../../module/RES';
import Button = FYGE.Button;
import Container = FYGE.Container;
import Shape = FYGE.Shape;
import Sprite = FYGE.Sprite;
import TEXT_ALIGN = FYGE.TEXT_ALIGN;
import TextField = FYGE.TextField;
import VERTICAL_ALIGN = FYGE.VERTICAL_ALIGN;
import Texture = FYGE.Texture;
import FrameAni = FYGE.FrameAni;
export class SlideBg extends Container {
bg1: Container = null
bg2: Container = null
/** 页面滑动速度 */
speed = 10
slideKey = 1
constructor() {
super()
this.init()
}
init() {
Array(2).fill('').forEach((bg, i) => {
const bg:Container = this[`bg${i+1}`] = new Container()
bg.addChild(new Sprite(RES.getRes('com_bg.jpg')))
const base = new Sprite(RES.getRes('base.png'))
bg.addChild(base)
base.width = 750
base.height = 250
base.y = 1624 - base.height
bg.x = i * 750
this.addChild(bg)
})
}
/** 帧动画 */
enterFrame() {
[this.bg1, this.bg2].forEach((bg, i) => {
bg.x -= this.speed
if(bg.x === -750){
bg.x += 750 * 2
}
})
}
destroy() {
super.destroy();
}
}
\ No newline at end of file
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