Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
tiendat3699 | 93f788d5be | |
tiendat3699 | 5e8ffdf31e |
Binary file not shown.
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"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
File diff suppressed because it is too large
Load Diff
|
@ -1,59 +0,0 @@
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"ver": "4.0.23",
|
|
||||||
"importer": "typescript",
|
|
||||||
"imported": true,
|
|
||||||
"uuid": "3eb45051-a94a-4100-b478-7137efd07fa9",
|
|
||||||
"files": [],
|
|
||||||
"subMetas": {},
|
|
||||||
"userData": {}
|
|
||||||
}
|
|
|
@ -12,12 +12,10 @@ import {
|
||||||
Vec3,
|
Vec3,
|
||||||
} from 'cc';
|
} from 'cc';
|
||||||
import ControllerSide from '../Enum/ControllerSide';
|
import ControllerSide from '../Enum/ControllerSide';
|
||||||
import GameState from '../Enum/GameState';
|
|
||||||
import TimeConfig from '../Enum/TimeConfig';
|
import TimeConfig from '../Enum/TimeConfig';
|
||||||
import GameEvent from '../Events/GameEvent';
|
import GameEvent from '../Events/GameEvent';
|
||||||
import AudioManager from '../Manager/AudioManager';
|
import AudioManager from '../Manager/AudioManager';
|
||||||
import { EventManger } from '../Manager/EventManger';
|
import { EventManger } from '../Manager/EventManger';
|
||||||
import P4PSDK, { EventType } from '../P4PSDK';
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@ccclass('Flipper')
|
@ccclass('Flipper')
|
||||||
|
@ -40,14 +38,13 @@ export class Flipper extends Component {
|
||||||
private _isAnimationPlaying;
|
private _isAnimationPlaying;
|
||||||
|
|
||||||
protected onLoad(): void {
|
protected onLoad(): void {
|
||||||
|
input.on(Input.EventType.KEY_DOWN, this.onKeyInputDown, this);
|
||||||
|
input.on(Input.EventType.KEY_UP, this.onKeyInputUp, this);
|
||||||
EventManger.instance.on(GameEvent.ControlTouchStart, this.onTouchStart, this);
|
EventManger.instance.on(GameEvent.ControlTouchStart, this.onTouchStart, this);
|
||||||
EventManger.instance.on(GameEvent.ControlTouchEnd, this.onTouchEnd, this);
|
EventManger.instance.on(GameEvent.ControlTouchEnd, this.onTouchEnd, this);
|
||||||
EventManger.instance.on(GameEvent.GameStateChange, this.gameStateChange, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected start(): void {
|
protected start(): void {
|
||||||
input.on(Input.EventType.KEY_DOWN, this.onKeyInputDown, this);
|
|
||||||
input.on(Input.EventType.KEY_UP, this.onKeyInputUp, this);
|
|
||||||
this._animation.play();
|
this._animation.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,53 +56,8 @@ export class Flipper extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private gameStateChange(state: GameState) {
|
|
||||||
if (state == GameState.Init) {
|
|
||||||
P4PSDK.broadCast.on(EventType.OnKeyDown, this.onSDKKeyDown, this);
|
|
||||||
P4PSDK.broadCast.on(EventType.OnKeyUp, this.onSDKKeyUp, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//#region Input Handler
|
//#region Input Handler
|
||||||
|
|
||||||
private onSDKKeyDown(key: number) {
|
|
||||||
switch (key) {
|
|
||||||
case KeyCode.KEY_A:
|
|
||||||
case KeyCode.ARROW_LEFT:
|
|
||||||
if (this.side == ControllerSide.Left) this.activeFlipper();
|
|
||||||
this._timer = 0;
|
|
||||||
if (this._animation.getState(this._animation.defaultClip.name).isPlaying) {
|
|
||||||
this._animation.stop();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case KeyCode.KEY_D:
|
|
||||||
case KeyCode.ARROW_RIGHT:
|
|
||||||
if (this.side == ControllerSide.Right) this.activeFlipper();
|
|
||||||
this._timer = 0;
|
|
||||||
if (this._isAnimationPlaying) {
|
|
||||||
this._animation.stop();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private onSDKKeyUp(key: number) {
|
|
||||||
switch (key) {
|
|
||||||
case KeyCode.KEY_A:
|
|
||||||
case KeyCode.ARROW_LEFT:
|
|
||||||
if (this.side == ControllerSide.Left) this.deActiveFlipper();
|
|
||||||
break;
|
|
||||||
case KeyCode.KEY_D:
|
|
||||||
case KeyCode.ARROW_RIGHT:
|
|
||||||
if (this.side == ControllerSide.Right) this.deActiveFlipper();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private onKeyInputDown(event: EventKeyboard) {
|
private onKeyInputDown(event: EventKeyboard) {
|
||||||
switch (event.keyCode) {
|
switch (event.keyCode) {
|
||||||
case KeyCode.KEY_A:
|
case KeyCode.KEY_A:
|
||||||
|
@ -164,7 +116,7 @@ export class Flipper extends Component {
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
private activeFlipper(): void {
|
private activeFlipper(): void {
|
||||||
// AudioManager.playSfx(this._activeSound, { volume: 0.5 });
|
AudioManager.playSfx(this._activeSound, { volume: 0.5 });
|
||||||
this._hingeJoint.motorSpeed = this._motorSpeedActive;
|
this._hingeJoint.motorSpeed = this._motorSpeedActive;
|
||||||
}
|
}
|
||||||
private deActiveFlipper(): void {
|
private deActiveFlipper(): void {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
Vec2,
|
Vec2,
|
||||||
Vec3,
|
Vec3,
|
||||||
} from 'cc';
|
} from 'cc';
|
||||||
|
import { EDITOR, PREVIEW } from 'cc/env';
|
||||||
import Timer, { TimerType } from '../Base/Timer';
|
import Timer, { TimerType } from '../Base/Timer';
|
||||||
import { BoosterBase } from '../Booster/BoosterBase';
|
import { BoosterBase } from '../Booster/BoosterBase';
|
||||||
import BoosterType from '../Enum/BoosterType';
|
import BoosterType from '../Enum/BoosterType';
|
||||||
|
@ -97,12 +98,13 @@ export class GameManager extends Singleton<GameManager>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async start(): Promise<void> {
|
protected async start(): Promise<void> {
|
||||||
await P4PSDK.init();
|
await P4PSDK.init(this.onBoughtTicket, this);
|
||||||
if (P4PSDK.gameTime) {
|
if (P4PSDK.getGameTime()) {
|
||||||
this._timePlay = P4PSDK.gameTime;
|
this._timePlay = P4PSDK.getGameTime();
|
||||||
}
|
}
|
||||||
|
P4PSDK.setCallAPI(this._callAPI);
|
||||||
|
await P4PSDK.authenticate();
|
||||||
this.changeGameState(GameState.Init);
|
this.changeGameState(GameState.Init);
|
||||||
this.Ready();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected update(dt: number): void {
|
protected update(dt: number): void {
|
||||||
|
@ -112,8 +114,8 @@ export class GameManager extends Singleton<GameManager>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private onBoughtTicket() {
|
private onBoughtTicket() {
|
||||||
// this.gameRelive();
|
this.gameRelive();
|
||||||
// EventManger.instance.emit(GameEvent.TicketUpdate, P4PSDK.getUserTicket());
|
EventManger.instance.emit(GameEvent.TicketUpdate, P4PSDK.getUserTicket());
|
||||||
}
|
}
|
||||||
|
|
||||||
private async changeGameState(state: GameState) {
|
private async changeGameState(state: GameState) {
|
||||||
|
@ -304,29 +306,27 @@ export class GameManager extends Singleton<GameManager>() {
|
||||||
private _minusTicketLoading = false;
|
private _minusTicketLoading = false;
|
||||||
|
|
||||||
public async replay(): Promise<void> {
|
public async replay(): Promise<void> {
|
||||||
// if (this._minusTicketLoading) return;
|
if (this._minusTicketLoading) return;
|
||||||
// this._minusTicketLoading = true;
|
this._minusTicketLoading = true;
|
||||||
// if (!PREVIEW && !EDITOR) {
|
if (!PREVIEW && !EDITOR) {
|
||||||
// const checkGameScoreTicket = await P4PSDK.checkGameScoreTicket();
|
const checkGameScoreTicket = await P4PSDK.checkGameScoreTicket();
|
||||||
// if (checkGameScoreTicket) {
|
if (checkGameScoreTicket) {
|
||||||
// const success = await P4PSDK.minusTicket('revive');
|
const success = await P4PSDK.minusTicket('revive');
|
||||||
// if (success) {
|
if (success) {
|
||||||
// this.gameRelive();
|
this.gameRelive();
|
||||||
// } else {
|
} else {
|
||||||
// P4PSDK.callPayPalModal();
|
P4PSDK.callPayPalModal();
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// this.gameOver();
|
this.gameOver();
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// this.gameRelive();
|
this.gameRelive();
|
||||||
// }
|
}
|
||||||
// this._minusTicketLoading = false;
|
this._minusTicketLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async play() {
|
public async play() {
|
||||||
await P4PSDK.startGame();
|
|
||||||
const coin = await P4PSDK.getUserCoin();
|
|
||||||
this._timer.time = this._timePlay;
|
this._timer.time = this._timePlay;
|
||||||
this._score = 0;
|
this._score = 0;
|
||||||
this._currentBallInGame = 0;
|
this._currentBallInGame = 0;
|
||||||
|
@ -335,7 +335,8 @@ export class GameManager extends Singleton<GameManager>() {
|
||||||
await Utils.delay(TimeConfig.DelayPLay);
|
await Utils.delay(TimeConfig.DelayPLay);
|
||||||
this._timer.startCount();
|
this._timer.startCount();
|
||||||
this.spawnBall(true);
|
this.spawnBall(true);
|
||||||
EventManger.instance.emit(GameEvent.TicketUpdate, coin);
|
await P4PSDK.minusTicket('auth');
|
||||||
|
EventManger.instance.emit(GameEvent.TicketUpdate, P4PSDK.getUserTicket());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async gameRelive() {
|
public async gameRelive() {
|
||||||
|
|
|
@ -1,92 +1,48 @@
|
||||||
export interface IObject {
|
export type postMessageType = 'paypal_modal' | 'game_tournament';
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IUserInfo {
|
export type minusTicketType = 'auth' | 'revive';
|
||||||
id: string;
|
|
||||||
displayName: string;
|
|
||||||
promoCode: string;
|
|
||||||
isSubscriber: boolean;
|
|
||||||
avatarLink: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IParticipationInfo {
|
|
||||||
id: string;
|
|
||||||
totalScore: number;
|
|
||||||
myRank: number;
|
|
||||||
gameStates: IObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ILogger {
|
|
||||||
log(...data: (number | string | boolean | undefined | null)[]): void;
|
|
||||||
info(...data: (number | string | boolean | undefined | null)[]): void;
|
|
||||||
warn(...data: (number | string | boolean | undefined | null)[]): void;
|
|
||||||
error(...data: (number | string | boolean | undefined | null)[]): void;
|
|
||||||
addBadge(badge: string, style?: { color?: string; backgroundColor?: string }): ILogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IAnalyticsModule {
|
|
||||||
logger: ILogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IDataModule {
|
|
||||||
getItem<T>(key: string): T | null;
|
|
||||||
setItem(key: string, value: any): void;
|
|
||||||
removeItem(key: string): void;
|
|
||||||
clear(): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IBroadCast {
|
|
||||||
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 {
|
|
||||||
OnKeyDown = 'OnKeyDown',
|
|
||||||
OnKeyUp = 'OnKeyUp',
|
|
||||||
OnMouse = 'OnMouse',
|
|
||||||
OnMouseDown = 'OnMouseDown',
|
|
||||||
OnMouseUp = 'OnMouseUp',
|
|
||||||
OnGameStart = 'OnGameStart',
|
|
||||||
OnGameEnd = 'OnGameEnd',
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EventMap {
|
|
||||||
[EventType.OnKeyDown]: (key: number) => void;
|
|
||||||
[EventType.OnKeyUp]: (key: number) => void;
|
|
||||||
[EventType.OnMouse]: (position: IVector2) => void;
|
|
||||||
[EventType.OnMouseDown]: (button: number) => void;
|
|
||||||
[EventType.OnMouseUp]: (button: number) => void;
|
|
||||||
[EventType.OnGameStart]: () => void;
|
|
||||||
[EventType.OnGameEnd]: (score: number) => void;
|
|
||||||
[event: string]: (data: any) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IVector2 {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SDK {
|
export interface SDK {
|
||||||
previousScore: number;
|
setCallAPI(value: boolean): void;
|
||||||
currentScore: number;
|
getEnv(): string;
|
||||||
totalScore: number;
|
getUserTicket(): number;
|
||||||
userRank: number;
|
getTopScore(): number;
|
||||||
isUseApi: boolean;
|
getLatestScore(): number;
|
||||||
tournamentData: IDataModule;
|
getGameScore(): number;
|
||||||
userData: IDataModule;
|
getUserId(): string;
|
||||||
gameData: IDataModule;
|
getGameTime(): number | null;
|
||||||
analytics: IAnalyticsModule;
|
getTicketNeedToContinue(): number;
|
||||||
broadCast: IBroadCast;
|
init(buyTicketCallBack: () => any, thisArg?: any): void;
|
||||||
gameTime: number;
|
|
||||||
updateScore(score: number): void;
|
updateScore(score: number): void;
|
||||||
init(): Promise<void>;
|
authenticate(): Promise<boolean>;
|
||||||
getUserInfo(): Promise<IUserInfo>;
|
checkGameScoreTicket(): Promise<boolean>;
|
||||||
getLeaderBoard(start: number, count: number): Promise<IParticipationInfo[]>;
|
buyMoreTicket(): void;
|
||||||
startGame(): Promise<boolean>;
|
postScoreToServer(): void;
|
||||||
endGame(): Promise<boolean>;
|
minusTicket(type: minusTicketType): Promise<boolean>;
|
||||||
getUserCoin(): Promise<number>;
|
callPayPalModal(): void;
|
||||||
|
canRelive(): boolean;
|
||||||
|
spinGacha(id: string): Promise<Reward>;
|
||||||
|
getLeaderBoard(): Promise<PlayerInfo[]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum Env {
|
||||||
|
development,
|
||||||
|
staging,
|
||||||
|
production,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlayerInfo {
|
||||||
|
userId: string;
|
||||||
|
displayName: string;
|
||||||
|
score: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Reward {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
quantity: number;
|
||||||
|
thumbnailLink: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum InitState {
|
enum InitState {
|
||||||
|
@ -94,72 +50,54 @@ enum InitState {
|
||||||
Initialized,
|
Initialized,
|
||||||
}
|
}
|
||||||
|
|
||||||
(window as any).P4P = {
|
export default class P4PSDK {
|
||||||
isUseApi: true,
|
private static _initState: InitState = InitState.UnInitialized;
|
||||||
};
|
private static _sdk: SDK;
|
||||||
|
|
||||||
class _P4PSDK implements SDK {
|
//#region PUBLIC METHOD
|
||||||
private _initState: InitState = InitState.UnInitialized;
|
|
||||||
private _sdk: SDK;
|
|
||||||
|
|
||||||
private get sdk() {
|
public static getEnv(): Env {
|
||||||
if (this._initState !== InitState.Initialized || !this._sdk) {
|
return Env[this._sdk?.getEnv() as keyof typeof Env];
|
||||||
throw new Error('P4P SDK is not initialized yet. Please call P4PSDK.init() first.');
|
|
||||||
}
|
|
||||||
return this._sdk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get tournamentData(): IDataModule {
|
public static getUserTicket(): number {
|
||||||
return this.sdk.tournamentData;
|
return this._sdk?.getUserTicket();
|
||||||
}
|
|
||||||
public get userData(): IDataModule {
|
|
||||||
return this.sdk.userData;
|
|
||||||
}
|
|
||||||
public get gameData(): IDataModule {
|
|
||||||
return this.sdk.gameData;
|
|
||||||
}
|
|
||||||
public get analytics(): IAnalyticsModule {
|
|
||||||
return this.sdk.analytics;
|
|
||||||
}
|
|
||||||
public get broadCast(): IBroadCast {
|
|
||||||
return this.sdk.broadCast;
|
|
||||||
}
|
|
||||||
public get previousScore(): number {
|
|
||||||
return this.sdk.previousScore;
|
|
||||||
}
|
|
||||||
public get currentScore(): number {
|
|
||||||
return this.sdk.currentScore;
|
|
||||||
}
|
|
||||||
public get totalScore(): number {
|
|
||||||
return this.sdk.totalScore;
|
|
||||||
}
|
|
||||||
public get userRank(): number {
|
|
||||||
return this.sdk.userRank;
|
|
||||||
}
|
|
||||||
public get isUseApi(): boolean {
|
|
||||||
return this.sdk.isUseApi;
|
|
||||||
}
|
|
||||||
public set isUseApi(value: boolean) {
|
|
||||||
(window as any).P4P.isUseApi = value;
|
|
||||||
}
|
|
||||||
public get gameTime(): number {
|
|
||||||
return this.sdk.gameTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async loadSDK(): Promise<void> {
|
public static getTopScore(): number {
|
||||||
|
return this._sdk?.getTopScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getLatestScore(): number {
|
||||||
|
return this._sdk?.getLatestScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getGameScore(): number {
|
||||||
|
return this._sdk?.getGameScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getUserId(): string {
|
||||||
|
return this._sdk.getUserId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getGameTime(): number | null {
|
||||||
|
return this._sdk.getGameTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getTicketNeedToContinue(): number {
|
||||||
|
return this._sdk?.getTicketNeedToContinue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async loadSDK(): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const tag = document.createElement('script');
|
const tag = document.createElement('script');
|
||||||
tag.type = 'module';
|
tag.type = 'module';
|
||||||
tag.src = 'https://storage.googleapis.com/play-now-1aef8.appspot.com/SDKTEST/sdk.js';
|
tag.src = 'https://firebasestorage.googleapis.com/v0/b/play-now-1aef8.appspot.com/o/SDK%2Fsdk.js?alt=media';
|
||||||
tag.async = true;
|
tag.async = true;
|
||||||
tag.onload = async () => {
|
tag.onload = async () => {
|
||||||
this._sdk = (globalThis as any).P4P.SDK;
|
console.log('P4P SDK loaded');
|
||||||
if (this._sdk) {
|
this._sdk = (window as any).P4P.SDK;
|
||||||
await this._sdk.init();
|
resolve();
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
reject('P4P SDK is undefined');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
tag.onerror = (e) => {
|
tag.onerror = (e) => {
|
||||||
console.error('Failed to load P4PSDK JS. Please check your internet connection.');
|
console.error('Failed to load P4PSDK JS. Please check your internet connection.');
|
||||||
|
@ -169,39 +107,55 @@ class _P4PSDK implements SDK {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init(): Promise<void> {
|
public static setCallAPI(value: boolean) {
|
||||||
|
this._sdk?.setCallAPI(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async init(buyTicketCallBack: () => any, thisArg?: any): Promise<void> {
|
||||||
if (this._initState == InitState.Initialized) return;
|
if (this._initState == InitState.Initialized) return;
|
||||||
await this.loadSDK();
|
await this.loadSDK();
|
||||||
|
this._sdk.init(buyTicketCallBack, thisArg);
|
||||||
this._initState = InitState.Initialized;
|
this._initState = InitState.Initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setIsUseApi(value: boolean) {
|
public static updateScore(score: number) {
|
||||||
(window as any).P4P.isUseApi = value;
|
this._sdk?.updateScore(score);
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateScore(score: number): void {
|
public static async authenticate(): Promise<boolean> {
|
||||||
this.sdk.updateScore(score);
|
return this._sdk?.authenticate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUserInfo(): Promise<IUserInfo> {
|
public static async checkGameScoreTicket(): Promise<boolean> {
|
||||||
return this.sdk.getUserInfo();
|
return this._sdk?.checkGameScoreTicket();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getLeaderBoard(start: number, count: number) {
|
public static buyMoreTicket() {
|
||||||
return this.sdk.getLeaderBoard(start, count);
|
this._sdk?.buyMoreTicket();
|
||||||
}
|
}
|
||||||
|
|
||||||
public startGame(): Promise<boolean> {
|
public static async postScoreToServer() {
|
||||||
return this.sdk.startGame();
|
this._sdk?.postScoreToServer();
|
||||||
}
|
}
|
||||||
public endGame(): Promise<boolean> {
|
|
||||||
return this.sdk.endGame();
|
public static async minusTicket(type: minusTicketType): Promise<boolean> {
|
||||||
|
return this._sdk?.minusTicket(type);
|
||||||
}
|
}
|
||||||
public getUserCoin(): Promise<number> {
|
|
||||||
return this.sdk.getUserCoin();
|
public static callPayPalModal() {
|
||||||
|
this._sdk?.callPayPalModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static canRelive(): boolean {
|
||||||
|
return this._sdk?.canRelive();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async spinGacha(id: string): Promise<Reward> {
|
||||||
|
return this._sdk?.spinGacha(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async getLeaderBoard(): Promise<PlayerInfo[]> {
|
||||||
|
return this._sdk?.getLeaderBoard();
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
const P4PSDK: SDK = new _P4PSDK();
|
|
||||||
|
|
||||||
export default P4PSDK;
|
|
||||||
|
|
|
@ -48,12 +48,11 @@ export class GameOverPanel extends Component {
|
||||||
EventManger.instance.on(GameEvent.GameStateChange, this.onGameStateChange, this);
|
EventManger.instance.on(GameEvent.GameStateChange, this.onGameStateChange, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async show(end: boolean): Promise<void> {
|
public show(end: boolean): void {
|
||||||
// this._ticketMinus.string = P4PSDK.getTicketNeedToContinue().toString();
|
this._ticketMinus.string = P4PSDK.getTicketNeedToContinue().toString();
|
||||||
const currentScore = P4PSDK.previousScore;
|
const currentScore = P4PSDK.getLatestScore();
|
||||||
const gameScore = P4PSDK.currentScore;
|
const gameScore = P4PSDK.getGameScore();
|
||||||
const top = await P4PSDK.getLeaderBoard(0, 1);
|
this.topScore.string = P4PSDK.getTopScore().toString();
|
||||||
// this.topScore.string = top.length > 0 ? top[0].totalScore.toString() : '0';
|
|
||||||
this.yourScore.string = currentScore.toString();
|
this.yourScore.string = currentScore.toString();
|
||||||
this.playCollectEffect(gameScore, currentScore);
|
this.playCollectEffect(gameScore, currentScore);
|
||||||
this.scheduleOnce(this.endGame, 60);
|
this.scheduleOnce(this.endGame, 60);
|
||||||
|
@ -80,7 +79,7 @@ export class GameOverPanel extends Component {
|
||||||
this._quitBtn.active = false;
|
this._quitBtn.active = false;
|
||||||
if (this._active) {
|
if (this._active) {
|
||||||
await Utils.delay(1);
|
await Utils.delay(1);
|
||||||
P4PSDK.endGame();
|
P4PSDK.postScoreToServer();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GameState.Relive:
|
case GameState.Relive:
|
||||||
|
@ -162,7 +161,7 @@ export class GameOverPanel extends Component {
|
||||||
.start();
|
.start();
|
||||||
if (!this._end) return;
|
if (!this._end) return;
|
||||||
await Utils.delay(1);
|
await Utils.delay(1);
|
||||||
P4PSDK.endGame();
|
P4PSDK.postScoreToServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"ver": "4.0.23",
|
|
||||||
"importer": "typescript",
|
|
||||||
"imported": true,
|
|
||||||
"uuid": "9bedefa1-9567-4550-8128-fd27c9a8091d",
|
|
||||||
"files": [],
|
|
||||||
"subMetas": {},
|
|
||||||
"userData": {}
|
|
||||||
}
|
|
|
@ -1,6 +1,5 @@
|
||||||
import {
|
import {
|
||||||
_decorator,
|
_decorator,
|
||||||
CCBoolean,
|
|
||||||
Component,
|
Component,
|
||||||
EventKeyboard,
|
EventKeyboard,
|
||||||
EventTouch,
|
EventTouch,
|
||||||
|
@ -18,7 +17,6 @@ import TimeConfig from '../Enum/TimeConfig';
|
||||||
import GameEvent from '../Events/GameEvent';
|
import GameEvent from '../Events/GameEvent';
|
||||||
import { EventManger } from '../Manager/EventManger';
|
import { EventManger } from '../Manager/EventManger';
|
||||||
import { GameManager } from '../Manager/GameManager';
|
import { GameManager } from '../Manager/GameManager';
|
||||||
import P4PSDK, { EventType } from '../P4PSDK';
|
|
||||||
import Utils from '../Utilities';
|
import Utils from '../Utilities';
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
@ -33,25 +31,20 @@ export class TutorialController extends Component {
|
||||||
private _tapLEffect: ParticleSystem;
|
private _tapLEffect: ParticleSystem;
|
||||||
@property({ type: ParticleSystem, visible: true })
|
@property({ type: ParticleSystem, visible: true })
|
||||||
private _tapREffect: ParticleSystem;
|
private _tapREffect: ParticleSystem;
|
||||||
@property(CCBoolean)
|
|
||||||
private playOnStart: boolean;
|
|
||||||
@property(CCBoolean)
|
|
||||||
private enableTutorial: boolean = true;
|
|
||||||
|
|
||||||
private _timer = 0;
|
private _timer = 0;
|
||||||
private _showed = false;
|
private _showed = false;
|
||||||
private _canShow = true;
|
private _canShow = true;
|
||||||
private _playing = false;
|
private _playing = false;
|
||||||
|
|
||||||
protected onLoad() {
|
protected onLoad(): void {
|
||||||
this.node.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
|
this.node.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
|
||||||
input.on(Input.EventType.KEY_UP, this.onKeyInputUpStart, this);
|
input.on(Input.EventType.KEY_UP, this.onKeyInputUpStart, this);
|
||||||
P4PSDK.broadCast.on(EventType.OnKeyDown, this.onSDKKeyInputStart, this);
|
|
||||||
EventManger.instance.on(GameEvent.GameStateChange, this.onGameStateChange, this);
|
EventManger.instance.on(GameEvent.GameStateChange, this.onGameStateChange, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected start() {
|
||||||
this.playTutorial();
|
this.playTutorial();
|
||||||
if (this.playOnStart) {
|
|
||||||
this.startGame();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected update(dt: number): void {
|
protected update(dt: number): void {
|
||||||
|
@ -81,7 +74,6 @@ export class TutorialController extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async playTutorial() {
|
private async playTutorial() {
|
||||||
if (!this.enableTutorial) return;
|
|
||||||
if (this._canShow) {
|
if (this._canShow) {
|
||||||
this._tapL.setActive(true);
|
this._tapL.setActive(true);
|
||||||
this._tapR.setActive(true);
|
this._tapR.setActive(true);
|
||||||
|
@ -123,11 +115,9 @@ export class TutorialController extends Component {
|
||||||
this.stopTutorial();
|
this.stopTutorial();
|
||||||
this.node.off(Input.EventType.TOUCH_START, this.onTouchStart, this);
|
this.node.off(Input.EventType.TOUCH_START, this.onTouchStart, this);
|
||||||
input.off(Input.EventType.KEY_UP, this.onKeyInputUpStart, this);
|
input.off(Input.EventType.KEY_UP, this.onKeyInputUpStart, this);
|
||||||
P4PSDK.broadCast.off(EventType.OnKeyDown, this.onSDKKeyInputStart, this);
|
|
||||||
|
|
||||||
this.node.on(Input.EventType.TOUCH_START, this.onTouch, this);
|
this.node.on(Input.EventType.TOUCH_START, this.onTouch, this);
|
||||||
input.on(Input.EventType.KEY_UP, this.onKeyInputUp, this);
|
input.on(Input.EventType.KEY_UP, this.onKeyInputUp, this);
|
||||||
P4PSDK.broadCast.on(EventType.OnKeyDown, this.onSDKKeyInput, this);
|
|
||||||
|
|
||||||
GameManager.instance.play();
|
GameManager.instance.play();
|
||||||
}
|
}
|
||||||
|
@ -140,19 +130,6 @@ export class TutorialController extends Component {
|
||||||
this.startGame();
|
this.startGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
private onSDKKeyInputStart(key: number) {
|
|
||||||
switch (key) {
|
|
||||||
case KeyCode.KEY_A:
|
|
||||||
case KeyCode.ARROW_LEFT:
|
|
||||||
case KeyCode.KEY_D:
|
|
||||||
case KeyCode.ARROW_RIGHT:
|
|
||||||
this.startGame();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private onKeyInputUpStart(event: EventKeyboard) {
|
private onKeyInputUpStart(event: EventKeyboard) {
|
||||||
switch (event.keyCode) {
|
switch (event.keyCode) {
|
||||||
case KeyCode.KEY_A:
|
case KeyCode.KEY_A:
|
||||||
|
@ -178,17 +155,4 @@ export class TutorialController extends Component {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private onSDKKeyInput(key: number) {
|
|
||||||
switch (key) {
|
|
||||||
case KeyCode.KEY_A:
|
|
||||||
case KeyCode.ARROW_LEFT:
|
|
||||||
case KeyCode.KEY_D:
|
|
||||||
case KeyCode.ARROW_RIGHT:
|
|
||||||
this.stopTutorial();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,10 +65,9 @@ export class UIController extends Component {
|
||||||
private async onGameStateChange(state: GameState) {
|
private async onGameStateChange(state: GameState) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case GameState.Init:
|
case GameState.Init:
|
||||||
const coin = await P4PSDK.getUserCoin();
|
|
||||||
this.playButton.interactable = true;
|
this.playButton.interactable = true;
|
||||||
this.loadingScreen.active = false;
|
this.loadingScreen.active = false;
|
||||||
this._ticketLabel.string = coin.toString();
|
this._ticketLabel.string = P4PSDK.getUserTicket().toString();
|
||||||
this._scoreLabel.string = '0';
|
this._scoreLabel.string = '0';
|
||||||
break;
|
break;
|
||||||
case GameState.Ready:
|
case GameState.Ready:
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 10 KiB |
|
@ -1,134 +0,0 @@
|
||||||
{
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "PinBallTCC",
|
"name": "PinBallTCC",
|
||||||
|
"version": "1.0.0",
|
||||||
"uuid": "1dc6dfe4-8871-44d8-881e-f7fee9494679",
|
"uuid": "1dc6dfe4-8871-44d8-881e-f7fee9494679",
|
||||||
"creator": {
|
"creator": {
|
||||||
"version": "3.8.2"
|
"version": "3.8.2"
|
||||||
|
|
Loading…
Reference in New Issue