feat: endless level

main
tiendat3699 2024-03-01 18:08:57 +07:00
parent 21d132f9db
commit 9e8f73b417
11 changed files with 19805 additions and 32 deletions

View File

@ -252,7 +252,7 @@
{ {
"__type__": "cc.CurveRange", "__type__": "cc.CurveRange",
"mode": 0, "mode": 0,
"constant": 30, "constant": 35,
"multiplier": 1 "multiplier": 1
}, },
{ {
@ -674,7 +674,7 @@
"lifeTime": { "lifeTime": {
"__id__": 51 "__id__": 51
}, },
"_minParticleDistance": 0.05, "_minParticleDistance": 0.01,
"existWithParticles": true, "existWithParticles": true,
"textureMode": 0, "textureMode": 0,
"widthFromParticle": true, "widthFromParticle": true,
@ -711,8 +711,7 @@
"__type__": "cc.RealCurve", "__type__": "cc.RealCurve",
"_times": [ "_times": [
0, 0,
0.07179487179487179, 0.11
0.25
], ],
"_values": [ "_values": [
{ {
@ -720,25 +719,13 @@
"interpolationMode": 2, "interpolationMode": 2,
"tangentWeightMode": 0, "tangentWeightMode": 0,
"value": 1, "value": 1,
"rightTangent": 0, "rightTangent": -15.269841269841269,
"rightTangentWeight": 1, "rightTangentWeight": 1,
"leftTangent": 0, "leftTangent": -15.269841269841269,
"leftTangentWeight": 1, "leftTangentWeight": 1,
"easingMethod": 0, "easingMethod": 0,
"__editorExtras__": null "__editorExtras__": null
}, },
{
"__type__": "cc.RealKeyframeValue",
"interpolationMode": 2,
"tangentWeightMode": 0,
"value": 0.5444444444444444,
"rightTangent": -5.59722222222222,
"rightTangentWeight": 0,
"leftTangent": -5.59722222222222,
"leftTangentWeight": 0,
"easingMethod": 0,
"__editorExtras__": null
},
{ {
"__type__": "cc.RealKeyframeValue", "__type__": "cc.RealKeyframeValue",
"interpolationMode": 2, "interpolationMode": 2,
@ -783,7 +770,7 @@
{ {
"__type__": "cc.AlphaKey", "__type__": "cc.AlphaKey",
"alpha": 0, "alpha": 0,
"time": 0.15 "time": 0.1
}, },
{ {
"__type__": "cc.GradientRange", "__type__": "cc.GradientRange",
@ -913,7 +900,7 @@
"__id__": 66 "__id__": 66
}, },
"tag": 0, "tag": 0,
"_group": 1, "_group": 4,
"_density": 1, "_density": 1,
"_sensor": false, "_sensor": false,
"_friction": 2, "_friction": 2,
@ -945,7 +932,7 @@
"enabledContactListener": true, "enabledContactListener": true,
"bullet": true, "bullet": true,
"awakeOnLoad": true, "awakeOnLoad": true,
"_group": 1, "_group": 4,
"_type": 2, "_type": 2,
"_allowSleep": true, "_allowSleep": true,
"_gravityScale": 2, "_gravityScale": 2,
@ -976,7 +963,7 @@
"__prefab": { "__prefab": {
"__id__": 70 "__id__": 70
}, },
"maxSpeed": 50, "maxSpeed": 100,
"rigidbody": { "rigidbody": {
"__id__": 67 "__id__": 67
}, },

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
{"ver":"1.1.43","importer":"scene","imported":true,"uuid":"82e6ef2e-3f9c-4d4e-ab02-dc963e925b88","files":[".json"],"subMetas":{},"userData":{}}

View File

@ -10,6 +10,7 @@ import {
EventTarget, EventTarget,
IPhysics2DContact, IPhysics2DContact,
ParticleSystem, ParticleSystem,
randomRangeInt,
RigidBody2D, RigidBody2D,
Vec2, Vec2,
} from 'cc'; } from 'cc';
@ -28,6 +29,7 @@ export class Ball extends Component {
@property(ParticleSystem) @property(ParticleSystem)
private trail: ParticleSystem; private trail: ParticleSystem;
public isActive: boolean; public isActive: boolean;
private hitted = false;
public eventHitObstacle = new EventTarget(); public eventHitObstacle = new EventTarget();
public eventGoal = new EventTarget(); public eventGoal = new EventTarget();
@ -41,6 +43,16 @@ export class Ball extends Component {
director.on(Director.EVENT_AFTER_PHYSICS, this.setMaxVelocity, this); director.on(Director.EVENT_AFTER_PHYSICS, this.setMaxVelocity, this);
} }
protected onEnable(): void {
let dir = randomRangeInt(-1, 2);
while (dir == 0) {
dir = randomRangeInt(-1, 2);
}
const force = new Vec2(dir, 1);
this.rigidbody.applyLinearImpulse(force.multiply2f(5, 50), Vec2.ZERO, true);
SoundManager.Instance().PlayOneShot(SoundManager.Instance().whistle);
}
private onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { private onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// Hit boundary // Hit boundary
if (otherCollider.tag == 1) { if (otherCollider.tag == 1) {
@ -70,9 +82,11 @@ export class Ball extends Component {
return; return;
} }
if (this.rigidbody.linearVelocity.length() >= 2) { if (!this.hitted && this.rigidbody.linearVelocity.length() >= 2) {
SoundManager.Instance().PlayOneShot(SoundManager.Instance().hitPlayer); SoundManager.Instance().PlayOneShot(SoundManager.Instance().hitPlayer);
} }
this.hitted = true;
} }
private setMaxVelocity() { private setMaxVelocity() {
@ -83,6 +97,7 @@ export class Ball extends Component {
private onEndContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { private onEndContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// console.log(otherCollider.tag, otherCollider.node.name); // console.log(otherCollider.tag, otherCollider.node.name);
this.hitted = false;
} }
public resetTrail() { public resetTrail() {

View File

@ -18,6 +18,10 @@ export class FlipperController extends Component {
public lFlipper: Flipper; public lFlipper: Flipper;
@property(Flipper) @property(Flipper)
public rFlipper: Flipper; public rFlipper: Flipper;
@property(Flipper)
public lFlipper2: Flipper;
@property(Flipper)
public rFlipper2: Flipper;
protected onLoad(): void { protected onLoad(): void {
// Mouse input // Mouse input
@ -34,25 +38,36 @@ export class FlipperController extends Component {
} }
//#region Handle mouse/touch input //#region Handle mouse/touch input
private HandleFlipperActive(params: EventMouse): void { private HandleFlipperActive(params: EventMouse): void {
if (params.getLocationX() > screen.width / 2) this.rFlipper.ActiveFlipper(); if (params.getLocationX() > screen.width / 2) {
else this.lFlipper.ActiveFlipper(); this.rFlipper.ActiveFlipper();
this.rFlipper2.ActiveFlipper();
} else {
this.lFlipper.ActiveFlipper();
this.lFlipper2.ActiveFlipper();
}
} }
private HandleFlipperDeActive(params: EventMouse): void { private HandleFlipperDeActive(params: EventMouse): void {
this.rFlipper.DeActiveFlipper(); this.rFlipper.DeActiveFlipper();
this.lFlipper.DeActiveFlipper(); this.lFlipper.DeActiveFlipper();
this.rFlipper2.DeActiveFlipper();
this.lFlipper2.DeActiveFlipper();
} }
private HandleFlipperActiveTouch(params: EventTouch): void { private HandleFlipperActiveTouch(params: EventTouch): void {
if (params.getLocationX() > Screen.windowSize.x / 2) { if (params.getLocationX() > Screen.windowSize.x / 2) {
console.log('right'); console.log('right');
this.rFlipper.ActiveFlipper(); this.rFlipper.ActiveFlipper();
this.rFlipper2.ActiveFlipper();
} else { } else {
console.log('left'); console.log('left');
this.lFlipper.ActiveFlipper(); this.lFlipper.ActiveFlipper();
this.lFlipper2.ActiveFlipper();
} }
} }
private HandleFlipperDeActiveTouch(params: EventTouch): void { private HandleFlipperDeActiveTouch(params: EventTouch): void {
this.rFlipper.DeActiveFlipper(); this.rFlipper.DeActiveFlipper();
this.lFlipper.DeActiveFlipper(); this.lFlipper.DeActiveFlipper();
this.rFlipper2.DeActiveFlipper();
this.lFlipper2.DeActiveFlipper();
} }
//#endregion //#endregion
@ -61,10 +76,12 @@ export class FlipperController extends Component {
case KeyCode.ARROW_LEFT: case KeyCode.ARROW_LEFT:
case KeyCode.KEY_A: case KeyCode.KEY_A:
this.lFlipper.ActiveFlipper(); this.lFlipper.ActiveFlipper();
this.lFlipper2.ActiveFlipper();
break; break;
case KeyCode.ARROW_RIGHT: case KeyCode.ARROW_RIGHT:
case KeyCode.KEY_D: case KeyCode.KEY_D:
this.rFlipper.ActiveFlipper(); this.rFlipper.ActiveFlipper();
this.rFlipper2.ActiveFlipper();
break; break;
} }
} }
@ -73,10 +90,12 @@ export class FlipperController extends Component {
case KeyCode.ARROW_LEFT: case KeyCode.ARROW_LEFT:
case KeyCode.KEY_A: case KeyCode.KEY_A:
this.lFlipper.DeActiveFlipper(); this.lFlipper.DeActiveFlipper();
this.lFlipper2.DeActiveFlipper();
break; break;
case KeyCode.ARROW_RIGHT: case KeyCode.ARROW_RIGHT:
case KeyCode.KEY_D: case KeyCode.KEY_D:
this.rFlipper.DeActiveFlipper(); this.rFlipper.DeActiveFlipper();
this.rFlipper2.DeActiveFlipper();
break; break;
} }
} }

View File

@ -7,7 +7,6 @@ import {
instantiate, instantiate,
Node, Node,
ParticleSystem, ParticleSystem,
ParticleSystem2D,
Prefab, Prefab,
randomRangeInt, randomRangeInt,
RigidBody2D, RigidBody2D,
@ -86,8 +85,14 @@ export class GameplayController extends Component {
@property(CCInteger) @property(CCInteger)
public startGameCountDown: number = 3; public startGameCountDown: number = 3;
@property([Node])
private randomEnemies: Node[] = [];
@property(CCInteger)
private maxRandomEnemies = 0;
//#endregion //#endregion
private _currentRandomEnemies = 0;
public eventMenuGame = new EventTarget(); public eventMenuGame = new EventTarget();
public eventStartGame = new EventTarget(); public eventStartGame = new EventTarget();
@ -104,6 +109,7 @@ export class GameplayController extends Component {
protected start(): void { protected start(): void {
BEConnector.instance.authenticate(); BEConnector.instance.authenticate();
this.ChangeGameState(GameState.MainMenu); this.ChangeGameState(GameState.MainMenu);
this.randomEnemies.forEach((enemy) => (enemy.active = false));
} }
private SpawnBall(): void { private SpawnBall(): void {
@ -131,11 +137,11 @@ export class GameplayController extends Component {
this.controllingBall.active = true; this.controllingBall.active = true;
this.controllingBall.getComponent(Ball).resetTrail(); this.controllingBall.getComponent(Ball).resetTrail();
} }
SoundManager.Instance().PlayOneShot(SoundManager.Instance().whistle);
} }
public SpawnBallInTime(time: number): void { public SpawnBallInTime(time: number): void {
if (this.ball <= 0) return; if (this.ball <= 0) return;
if (this.currentGameState == GameState.EndGame) return; if (this.currentGameState == GameState.EndGame) return;
this.spawnEnemies();
//this.unscheduleAllCallbacks(); //this.unscheduleAllCallbacks();
console.log(this.currentGameState.toString()); console.log(this.currentGameState.toString());
@ -144,6 +150,17 @@ export class GameplayController extends Component {
}, time); }, time);
this.SetupObstacle(); this.SetupObstacle();
} }
private spawnEnemies() {
this._currentRandomEnemies = 0;
this.randomEnemies.forEach((enemy) => {
if (this._currentRandomEnemies >= this.maxRandomEnemies) return;
const chance = randomRangeInt(0, 100) <= 50;
enemy.active = chance;
if (chance) this._currentRandomEnemies++;
});
}
//#region Events //#region Events
public AddScore(score: number): void { public AddScore(score: number): void {
this.score += score; this.score += score;
@ -192,7 +209,7 @@ export class GameplayController extends Component {
case GameState.StartGame: case GameState.StartGame:
this.eventStartGame.emit(EventType.StartGame); this.eventStartGame.emit(EventType.StartGame);
this.SpawnBallInTime(this.startGameCountDown); this.SpawnBallInTime(this.startGameCountDown);
this.levelController.LevelUp(); this.levelController?.LevelUp();
BEConnector.instance.ticketMinus('auth'); BEConnector.instance.ticketMinus('auth');
break; break;

36
assets/Scripts/Spring.ts Normal file
View File

@ -0,0 +1,36 @@
import { _decorator, Collider2D, Component, Contact2DType, Node, RigidBody2D, Vec2 } from 'cc';
import Utilities from './Utilities/Utilities';
const { ccclass, property } = _decorator;
@ccclass('Spring')
export class Spring extends Component {
@property(Collider2D)
private collider: Collider2D;
@property(Node)
private gate: Node;
@property(Node)
private lid: Node;
protected onLoad(): void {
this.collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
this.gate.active = false;
}
private async onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D) {
otherCollider.node.setWorldPosition(this.node.worldPosition);
const rigi = otherCollider.getComponent(RigidBody2D);
rigi.linearVelocity = Vec2.ZERO.clone();
rigi.angularVelocity = 0;
const gravity = rigi.gravityScale;
rigi.gravityScale = 0;
this.lid.active = false;
await Utilities.delay(1000);
rigi.gravityScale = gravity;
rigi.applyLinearImpulse(new Vec2(0, 100), Vec2.ZERO, true);
await Utilities.delay(500);
this.lid.active = true;
if (this.gate) {
this.gate.active = true;
}
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "6b2f78b4-ee6c-4dff-9719-76165c277e71",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -0,0 +1,47 @@
import { _decorator, Component, Node, Tween, tween, TweenSystem } from 'cc';
const { ccclass, property, float } = _decorator;
@ccclass('TweenPath')
export class TweenPath extends Component {
@property(Node)
private target: Node;
@property([Node])
private waypoints: Node[] = [];
@property(Node)
private startPoint: Node;
@float
private duration = 2;
private tweenPath: Tween<Node>;
protected onEnable(): void {
this.startFollow(1);
}
protected onDisable(): void {
this.stopFollow();
}
private followPath(duration: number) {
this.tweenPath = tween(this.target);
for (let i = 0; i < this.waypoints.length; i++) {
this.tweenPath.to(duration, {
position: this.waypoints[i].getPosition(),
});
}
// repeatForever method bug: not repeat on completed tween, use repeat(Number.MAX_SAFE_INTEGER, this.tweenPath) instead repeatForever to make infinite loop
this.tweenPath.repeat(Number.MAX_SAFE_INTEGER, this.tweenPath);
this.tweenPath.start();
}
public stopFollow() {
this.tweenPath?.stop();
}
public startFollow(speed: number = 1) {
if (this.waypoints.length > 0) {
this.target.setPosition(this.startPoint?.position || this.waypoints[this.waypoints.length - 1].position);
this.followPath(this.duration / speed);
}
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c9d88ffb-aa44-4460-91cf-8993b0e4313e",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -2,16 +2,32 @@
"__version__": "1.0.4", "__version__": "1.0.4",
"general": { "general": {
"designResolution": { "designResolution": {
"width": 1440, "width": 1080,
"height": 1080, "height": 2340,
"fitHeight": true "fitHeight": true,
"fitWidth": true
} }
}, },
"physics": { "physics": {
"gravity": { "gravity": {
"y": -9.81 "y": -9.81
}, },
"fixedTimeStep": 0.016667 "fixedTimeStep": 0.016667,
"collisionGroups": [
{
"index": 1,
"name": "TRIGGER"
},
{
"index": 2,
"name": "BALL"
}
],
"collisionMatrix": {
"0": 5,
"1": 4,
"2": 7
}
}, },
"custom_joint_texture_layouts": [] "custom_joint_texture_layouts": []
} }