feat: pad controller
parent
aa6dcfad2c
commit
86b3b434ec
Binary file not shown.
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"ver": "1.0.1",
|
||||
"importer": "ttf-font",
|
||||
"imported": true,
|
||||
"uuid": "b1f7797d-3e59-499d-821f-1fffde502106",
|
||||
"files": [
|
||||
".json",
|
||||
"Nunito-ExtraBold.ttf"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,59 @@
|
|||
import {
|
||||
_decorator,
|
||||
Camera,
|
||||
CCFloat,
|
||||
clamp,
|
||||
Component,
|
||||
EventMouse,
|
||||
Input,
|
||||
input,
|
||||
IVec2Like,
|
||||
Node,
|
||||
Vec2,
|
||||
Vec3,
|
||||
} from 'cc';
|
||||
import P4PSDK, { EventType } from '../P4PSDK';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('Bar')
|
||||
export default class Bar extends Component {
|
||||
@property(CCFloat)
|
||||
private yOffset: number = 350;
|
||||
@property(CCFloat)
|
||||
private minX: number = 0;
|
||||
@property(CCFloat)
|
||||
private maxX: number = 100;
|
||||
@property(Camera)
|
||||
private camera: Camera;
|
||||
|
||||
private _screenPoint: Vec2 = new Vec2();
|
||||
private _worldPoint: Vec3 = new Vec3();
|
||||
|
||||
protected onLoad(): void {
|
||||
input.on(Input.EventType.MOUSE_MOVE, this.onMouseMove, this);
|
||||
P4PSDK.broadCast.on(EventType.OnMouse, this.onMouse, this);
|
||||
}
|
||||
|
||||
private onMouseMove(event: EventMouse): void {
|
||||
event.getLocation(this._screenPoint);
|
||||
this.updateWorldPoint();
|
||||
}
|
||||
|
||||
private onMouse(position: IVec2Like): void {
|
||||
this._screenPoint = new Vec2(position.x, position.y);
|
||||
this.updateWorldPoint();
|
||||
}
|
||||
|
||||
private updateWorldPoint(): Vec3 {
|
||||
this.camera.screenToWorld(this._screenPoint.toVec3(), this._worldPoint);
|
||||
this._worldPoint.x = clamp(this._worldPoint.x, this.minX, this.maxX);
|
||||
this._worldPoint.y = this.yOffset;
|
||||
this._worldPoint.z = 0;
|
||||
return this._worldPoint;
|
||||
}
|
||||
|
||||
protected update(dt: number): void {
|
||||
this.node.setWorldPosition(this.node.getWorldPosition().lerp(this._worldPoint, 30 * dt));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "3eb45051-a94a-4100-b478-7137efd07fa9",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
|
@ -97,7 +97,6 @@ export class GameManager extends Singleton<GameManager>() {
|
|||
}
|
||||
|
||||
protected async start(): Promise<void> {
|
||||
P4PSDK.isUseApi = false;
|
||||
await P4PSDK.init();
|
||||
if (P4PSDK.gameTime) {
|
||||
this._timePlay = P4PSDK.gameTime;
|
||||
|
|
|
@ -37,9 +37,9 @@ export interface IDataModule {
|
|||
}
|
||||
|
||||
export interface IBroadCast {
|
||||
emit(eventType: EventType, data?: any): void;
|
||||
on<K extends keyof EventMap>(eventType: K, listener: EventMap[K], thisArg?: any): void;
|
||||
off<K extends keyof EventMap>(eventType: K, listener: EventMap[K], thisArg?: any): void;
|
||||
emit(eventType: EventType | string, data?: any): void;
|
||||
on<K extends keyof EventMap>(eventType: K | string, listener: EventMap[K], thisArg?: any): void;
|
||||
off<K extends keyof EventMap>(eventType: K | string, listener: EventMap[K], thisArg?: any): void;
|
||||
}
|
||||
|
||||
export enum EventType {
|
||||
|
@ -59,7 +59,8 @@ export interface EventMap {
|
|||
[EventType.OnMouseDown]: (button: number) => void;
|
||||
[EventType.OnMouseUp]: (button: number) => void;
|
||||
[EventType.OnGameStart]: () => void;
|
||||
[EventType.OnGameEnd]: () => void;
|
||||
[EventType.OnGameEnd]: (score: number) => void;
|
||||
[event: string]: (data: any) => void;
|
||||
}
|
||||
|
||||
interface IVector2 {
|
||||
|
@ -149,8 +150,7 @@ class _P4PSDK implements SDK {
|
|||
return new Promise((resolve, reject) => {
|
||||
const tag = document.createElement('script');
|
||||
tag.type = 'module';
|
||||
tag.src =
|
||||
'https://firebasestorage.googleapis.com/v0/b/play-now-1aef8.appspot.com/o/SDKTEST%2Fsdk.js?alt=media';
|
||||
tag.src = 'https://storage.googleapis.com/play-now-1aef8.appspot.com/SDKTEST/sdk.js';
|
||||
tag.async = true;
|
||||
tag.onload = async () => {
|
||||
this._sdk = (globalThis as any).P4P.SDK;
|
||||
|
|
|
@ -53,7 +53,7 @@ export class GameOverPanel extends Component {
|
|||
const currentScore = P4PSDK.previousScore;
|
||||
const gameScore = P4PSDK.currentScore;
|
||||
const top = await P4PSDK.getLeaderBoard(0, 1);
|
||||
this.topScore.string = top.length > 0 ? top[0].totalScore.toString() : '0';
|
||||
// this.topScore.string = top.length > 0 ? top[0].totalScore.toString() : '0';
|
||||
this.yourScore.string = currentScore.toString();
|
||||
this.playCollectEffect(gameScore, currentScore);
|
||||
this.scheduleOnce(this.endGame, 60);
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import { _decorator, Component, Label, Node } from 'cc';
|
||||
import P4PSDK from '../P4PSDK';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('LeaderBoard')
|
||||
export default class LeaderBoard extends Component {
|
||||
@property(Node)
|
||||
private items: Node[] = [];
|
||||
|
||||
protected async onLoad(): Promise<void> {
|
||||
const LeaderBoard = await P4PSDK.getLeaderBoard(0, 5);
|
||||
LeaderBoard.forEach((info, i) => {
|
||||
this.items[i].getChildByName('Score').getComponent(Label).setString(info.totalScore);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9bedefa1-9567-4550-8128-fd27c9a8091d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
_decorator,
|
||||
CCBoolean,
|
||||
Component,
|
||||
EventKeyboard,
|
||||
EventTouch,
|
||||
|
@ -32,6 +33,10 @@ export class TutorialController extends Component {
|
|||
private _tapLEffect: ParticleSystem;
|
||||
@property({ type: ParticleSystem, visible: true })
|
||||
private _tapREffect: ParticleSystem;
|
||||
@property(CCBoolean)
|
||||
private playOnStart: boolean;
|
||||
@property(CCBoolean)
|
||||
private enableTutorial: boolean = true;
|
||||
|
||||
private _timer = 0;
|
||||
private _showed = false;
|
||||
|
@ -44,6 +49,9 @@ export class TutorialController extends Component {
|
|||
P4PSDK.broadCast.on(EventType.OnKeyDown, this.onSDKKeyInputStart, this);
|
||||
EventManger.instance.on(GameEvent.GameStateChange, this.onGameStateChange, this);
|
||||
this.playTutorial();
|
||||
if (this.playOnStart) {
|
||||
this.startGame();
|
||||
}
|
||||
}
|
||||
|
||||
protected update(dt: number): void {
|
||||
|
@ -73,6 +81,7 @@ export class TutorialController extends Component {
|
|||
}
|
||||
|
||||
private async playTutorial() {
|
||||
if (!this.enableTutorial) return;
|
||||
if (this._canShow) {
|
||||
this._tapL.setActive(true);
|
||||
this._tapR.setActive(true);
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
|
@ -0,0 +1,134 @@
|
|||
{
|
||||
"ver": "1.0.26",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "220aee0b-1bec-404e-89c3-a309ef059864",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "220aee0b-1bec-404e-89c3-a309ef059864@6c48a",
|
||||
"displayName": "thanh pad",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "220aee0b-1bec-404e-89c3-a309ef059864",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "220aee0b-1bec-404e-89c3-a309ef059864@f9941",
|
||||
"displayName": "thanh pad",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 438,
|
||||
"height": 68,
|
||||
"rawWidth": 438,
|
||||
"rawHeight": 68,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-219,
|
||||
-34,
|
||||
0,
|
||||
219,
|
||||
-34,
|
||||
0,
|
||||
-219,
|
||||
34,
|
||||
0,
|
||||
219,
|
||||
34,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
68,
|
||||
438,
|
||||
68,
|
||||
0,
|
||||
0,
|
||||
438,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-219,
|
||||
-34,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
219,
|
||||
34,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "220aee0b-1bec-404e-89c3-a309ef059864@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "220aee0b-1bec-404e-89c3-a309ef059864@f9941"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue