feat: endless level
parent
21d132f9db
commit
9e8f73b417
|
@ -252,7 +252,7 @@
|
|||
{
|
||||
"__type__": "cc.CurveRange",
|
||||
"mode": 0,
|
||||
"constant": 30,
|
||||
"constant": 35,
|
||||
"multiplier": 1
|
||||
},
|
||||
{
|
||||
|
@ -674,7 +674,7 @@
|
|||
"lifeTime": {
|
||||
"__id__": 51
|
||||
},
|
||||
"_minParticleDistance": 0.05,
|
||||
"_minParticleDistance": 0.01,
|
||||
"existWithParticles": true,
|
||||
"textureMode": 0,
|
||||
"widthFromParticle": true,
|
||||
|
@ -711,8 +711,7 @@
|
|||
"__type__": "cc.RealCurve",
|
||||
"_times": [
|
||||
0,
|
||||
0.07179487179487179,
|
||||
0.25
|
||||
0.11
|
||||
],
|
||||
"_values": [
|
||||
{
|
||||
|
@ -720,25 +719,13 @@
|
|||
"interpolationMode": 2,
|
||||
"tangentWeightMode": 0,
|
||||
"value": 1,
|
||||
"rightTangent": 0,
|
||||
"rightTangent": -15.269841269841269,
|
||||
"rightTangentWeight": 1,
|
||||
"leftTangent": 0,
|
||||
"leftTangent": -15.269841269841269,
|
||||
"leftTangentWeight": 1,
|
||||
"easingMethod": 0,
|
||||
"__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",
|
||||
"interpolationMode": 2,
|
||||
|
@ -783,7 +770,7 @@
|
|||
{
|
||||
"__type__": "cc.AlphaKey",
|
||||
"alpha": 0,
|
||||
"time": 0.15
|
||||
"time": 0.1
|
||||
},
|
||||
{
|
||||
"__type__": "cc.GradientRange",
|
||||
|
@ -913,7 +900,7 @@
|
|||
"__id__": 66
|
||||
},
|
||||
"tag": 0,
|
||||
"_group": 1,
|
||||
"_group": 4,
|
||||
"_density": 1,
|
||||
"_sensor": false,
|
||||
"_friction": 2,
|
||||
|
@ -945,7 +932,7 @@
|
|||
"enabledContactListener": true,
|
||||
"bullet": true,
|
||||
"awakeOnLoad": true,
|
||||
"_group": 1,
|
||||
"_group": 4,
|
||||
"_type": 2,
|
||||
"_allowSleep": true,
|
||||
"_gravityScale": 2,
|
||||
|
@ -976,7 +963,7 @@
|
|||
"__prefab": {
|
||||
"__id__": 70
|
||||
},
|
||||
"maxSpeed": 50,
|
||||
"maxSpeed": 100,
|
||||
"rigidbody": {
|
||||
"__id__": 67
|
||||
},
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1 @@
|
|||
{"ver":"1.1.43","importer":"scene","imported":true,"uuid":"82e6ef2e-3f9c-4d4e-ab02-dc963e925b88","files":[".json"],"subMetas":{},"userData":{}}
|
|
@ -10,6 +10,7 @@ import {
|
|||
EventTarget,
|
||||
IPhysics2DContact,
|
||||
ParticleSystem,
|
||||
randomRangeInt,
|
||||
RigidBody2D,
|
||||
Vec2,
|
||||
} from 'cc';
|
||||
|
@ -28,6 +29,7 @@ export class Ball extends Component {
|
|||
@property(ParticleSystem)
|
||||
private trail: ParticleSystem;
|
||||
public isActive: boolean;
|
||||
private hitted = false;
|
||||
|
||||
public eventHitObstacle = new EventTarget();
|
||||
public eventGoal = new EventTarget();
|
||||
|
@ -41,6 +43,16 @@ export class Ball extends Component {
|
|||
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) {
|
||||
// Hit boundary
|
||||
if (otherCollider.tag == 1) {
|
||||
|
@ -70,9 +82,11 @@ export class Ball extends Component {
|
|||
return;
|
||||
}
|
||||
|
||||
if (this.rigidbody.linearVelocity.length() >= 2) {
|
||||
if (!this.hitted && this.rigidbody.linearVelocity.length() >= 2) {
|
||||
SoundManager.Instance().PlayOneShot(SoundManager.Instance().hitPlayer);
|
||||
}
|
||||
|
||||
this.hitted = true;
|
||||
}
|
||||
|
||||
private setMaxVelocity() {
|
||||
|
@ -83,6 +97,7 @@ export class Ball extends Component {
|
|||
|
||||
private onEndContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
// console.log(otherCollider.tag, otherCollider.node.name);
|
||||
this.hitted = false;
|
||||
}
|
||||
|
||||
public resetTrail() {
|
||||
|
|
|
@ -18,6 +18,10 @@ export class FlipperController extends Component {
|
|||
public lFlipper: Flipper;
|
||||
@property(Flipper)
|
||||
public rFlipper: Flipper;
|
||||
@property(Flipper)
|
||||
public lFlipper2: Flipper;
|
||||
@property(Flipper)
|
||||
public rFlipper2: Flipper;
|
||||
|
||||
protected onLoad(): void {
|
||||
// Mouse input
|
||||
|
@ -34,25 +38,36 @@ export class FlipperController extends Component {
|
|||
}
|
||||
//#region Handle mouse/touch input
|
||||
private HandleFlipperActive(params: EventMouse): void {
|
||||
if (params.getLocationX() > screen.width / 2) this.rFlipper.ActiveFlipper();
|
||||
else this.lFlipper.ActiveFlipper();
|
||||
if (params.getLocationX() > screen.width / 2) {
|
||||
this.rFlipper.ActiveFlipper();
|
||||
this.rFlipper2.ActiveFlipper();
|
||||
} else {
|
||||
this.lFlipper.ActiveFlipper();
|
||||
this.lFlipper2.ActiveFlipper();
|
||||
}
|
||||
}
|
||||
private HandleFlipperDeActive(params: EventMouse): void {
|
||||
this.rFlipper.DeActiveFlipper();
|
||||
this.lFlipper.DeActiveFlipper();
|
||||
this.rFlipper2.DeActiveFlipper();
|
||||
this.lFlipper2.DeActiveFlipper();
|
||||
}
|
||||
private HandleFlipperActiveTouch(params: EventTouch): void {
|
||||
if (params.getLocationX() > Screen.windowSize.x / 2) {
|
||||
console.log('right');
|
||||
this.rFlipper.ActiveFlipper();
|
||||
this.rFlipper2.ActiveFlipper();
|
||||
} else {
|
||||
console.log('left');
|
||||
this.lFlipper.ActiveFlipper();
|
||||
this.lFlipper2.ActiveFlipper();
|
||||
}
|
||||
}
|
||||
private HandleFlipperDeActiveTouch(params: EventTouch): void {
|
||||
this.rFlipper.DeActiveFlipper();
|
||||
this.lFlipper.DeActiveFlipper();
|
||||
this.rFlipper2.DeActiveFlipper();
|
||||
this.lFlipper2.DeActiveFlipper();
|
||||
}
|
||||
//#endregion
|
||||
|
||||
|
@ -61,10 +76,12 @@ export class FlipperController extends Component {
|
|||
case KeyCode.ARROW_LEFT:
|
||||
case KeyCode.KEY_A:
|
||||
this.lFlipper.ActiveFlipper();
|
||||
this.lFlipper2.ActiveFlipper();
|
||||
break;
|
||||
case KeyCode.ARROW_RIGHT:
|
||||
case KeyCode.KEY_D:
|
||||
this.rFlipper.ActiveFlipper();
|
||||
this.rFlipper2.ActiveFlipper();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -73,10 +90,12 @@ export class FlipperController extends Component {
|
|||
case KeyCode.ARROW_LEFT:
|
||||
case KeyCode.KEY_A:
|
||||
this.lFlipper.DeActiveFlipper();
|
||||
this.lFlipper2.DeActiveFlipper();
|
||||
break;
|
||||
case KeyCode.ARROW_RIGHT:
|
||||
case KeyCode.KEY_D:
|
||||
this.rFlipper.DeActiveFlipper();
|
||||
this.rFlipper2.DeActiveFlipper();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import {
|
|||
instantiate,
|
||||
Node,
|
||||
ParticleSystem,
|
||||
ParticleSystem2D,
|
||||
Prefab,
|
||||
randomRangeInt,
|
||||
RigidBody2D,
|
||||
|
@ -86,8 +85,14 @@ export class GameplayController extends Component {
|
|||
|
||||
@property(CCInteger)
|
||||
public startGameCountDown: number = 3;
|
||||
@property([Node])
|
||||
private randomEnemies: Node[] = [];
|
||||
@property(CCInteger)
|
||||
private maxRandomEnemies = 0;
|
||||
//#endregion
|
||||
|
||||
private _currentRandomEnemies = 0;
|
||||
|
||||
public eventMenuGame = new EventTarget();
|
||||
|
||||
public eventStartGame = new EventTarget();
|
||||
|
@ -104,6 +109,7 @@ export class GameplayController extends Component {
|
|||
protected start(): void {
|
||||
BEConnector.instance.authenticate();
|
||||
this.ChangeGameState(GameState.MainMenu);
|
||||
this.randomEnemies.forEach((enemy) => (enemy.active = false));
|
||||
}
|
||||
|
||||
private SpawnBall(): void {
|
||||
|
@ -131,11 +137,11 @@ export class GameplayController extends Component {
|
|||
this.controllingBall.active = true;
|
||||
this.controllingBall.getComponent(Ball).resetTrail();
|
||||
}
|
||||
SoundManager.Instance().PlayOneShot(SoundManager.Instance().whistle);
|
||||
}
|
||||
public SpawnBallInTime(time: number): void {
|
||||
if (this.ball <= 0) return;
|
||||
if (this.currentGameState == GameState.EndGame) return;
|
||||
this.spawnEnemies();
|
||||
//this.unscheduleAllCallbacks();
|
||||
console.log(this.currentGameState.toString());
|
||||
|
||||
|
@ -144,6 +150,17 @@ export class GameplayController extends Component {
|
|||
}, time);
|
||||
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
|
||||
public AddScore(score: number): void {
|
||||
this.score += score;
|
||||
|
@ -192,7 +209,7 @@ export class GameplayController extends Component {
|
|||
case GameState.StartGame:
|
||||
this.eventStartGame.emit(EventType.StartGame);
|
||||
this.SpawnBallInTime(this.startGameCountDown);
|
||||
this.levelController.LevelUp();
|
||||
this.levelController?.LevelUp();
|
||||
BEConnector.instance.ticketMinus('auth');
|
||||
|
||||
break;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6b2f78b4-ee6c-4dff-9719-76165c277e71",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c9d88ffb-aa44-4460-91cf-8993b0e4313e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
|
@ -2,16 +2,32 @@
|
|||
"__version__": "1.0.4",
|
||||
"general": {
|
||||
"designResolution": {
|
||||
"width": 1440,
|
||||
"height": 1080,
|
||||
"fitHeight": true
|
||||
"width": 1080,
|
||||
"height": 2340,
|
||||
"fitHeight": true,
|
||||
"fitWidth": true
|
||||
}
|
||||
},
|
||||
"physics": {
|
||||
"gravity": {
|
||||
"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": []
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue