Skip to content

Commit

Permalink
v2.6.3 更改部分游戏内效果表现
Browse files Browse the repository at this point in the history
  • Loading branch information
yu0107an committed Nov 14, 2024
1 parent fbae399 commit 21fa4aa
Show file tree
Hide file tree
Showing 8 changed files with 1,350 additions and 1,097 deletions.
2,379 changes: 1,324 additions & 1,055 deletions assets/Scene/MainScene.scene

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions assets/Script/Frame/EventManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { _decorator, director, find, Node, v3, Vec3 } from 'cc';
import { Game } from '../MainScene/Game';
import { GameMgr } from '../MainScene/GameMgr';
import { EffectLayer } from '../MainScene/EffectLayer';
import { UI1 } from '../MainScene/UI1';
import { Map } from '../MainScene/Map';
Expand All @@ -11,6 +11,7 @@ import { EnemyLayer } from '../MainScene/EnemyLayer';
import { ObstacleLayer } from '../MainScene/ObstacleLayer';
import { AudioManager } from './AudioManager';
import { GameInfo } from './GameInfo';
import { struct } from './AStar';
const { ccclass, property } = _decorator;

export enum IObserverType
Expand All @@ -23,7 +24,7 @@ export enum IObserverType
export class EventManager {

private static instance: EventManager;
private gameTs: Game;
private gameTs: GameMgr;
private mapTs: Map;
private UI1Ts: UI1;
private UI2Ts: UIControl;
Expand Down Expand Up @@ -53,7 +54,7 @@ export class EventManager {

init()
{
this.gameTs = find('Canvas/Game').getComponent(Game);
this.gameTs = find('Canvas/Game').getComponent(GameMgr);
this.mapTs = find('Canvas/Map').getComponent(Map);
this.UI1Ts = find('Canvas/UI1').getComponent(UI1);
this.UI2Ts = find('Canvas/UI2').getComponent(UIControl);
Expand Down Expand Up @@ -145,15 +146,15 @@ export class EventManager {
}

//初始化关卡数据(关卡开始时使用)
initLevelData(weaponDt: any, monsterDt: any, waveDt: any)
initLevelData(weaponDt: any, monsterDt: any, waveDt: any): struct[]
{
let enemyPath = this.mapTs.getEnemyPath();
find('Canvas/UI2/ChoiceCard').getComponent(ChoiceCard).initAllCard(weaponDt);
this.enemyLayerTs.init(monsterDt, waveDt, enemyPath);
this.bulletLayerTs.initBulletPool(weaponDt, weaponDt.length);
this.obstacleLayerTs.init(this.mapTs.getObstacleInfo());
this.UI2Ts.init(v3(enemyPath[enemyPath.length - 1].x, enemyPath[enemyPath.length - 1].y));
this.UI1Ts.init(v3(enemyPath[0].x, enemyPath[0].y), v3(enemyPath[1].x, enemyPath[1].y));
this.UI2Ts.init();
return enemyPath;
}

//创建effect
Expand Down Expand Up @@ -276,7 +277,7 @@ export class EventManager {
//Carrot扣血
reduceHp_Carrot(count: number)
{
this.UI2Ts.reduceHp_Carrot(count);
this.gameTs.reduceHp_Carrot(count);
}

//障碍物扣血
Expand Down
7 changes: 2 additions & 5 deletions assets/Script/MainScene/Carrot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@ export class Carrot extends Component {
animation: Animation;
sch: any;

init()
init(pos: Vec3)
{
this.node.setPosition(pos.x - 480, pos.y - 320);
this.animation = this.getComponent(Animation);
this.sch = this.schedule(() => {
if (!this.animation.getState('CarrotClick').isPlaying && this.curHp === 10)
{
this.animation.play('CarrotIdle');
}
}, 5, macro.REPEAT_FOREVER, 7);
}

enableClick()
{
this.node.on(Node.EventType.TOUCH_START, this.click, this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { _decorator, Component, director, JsonAsset, Node } from 'cc';
import { _decorator, Component, director, JsonAsset, Node, v3 } from 'cc';
import { GameInfo } from '../Frame/GameInfo';
import { EventManager } from '../Frame/EventManager';
import { StartNode } from './StartNode';
import { Carrot } from './Carrot';
const { ccclass, property } = _decorator;

@ccclass('Game')
export class Game extends Component {
@ccclass('GameMgr')
export class GameMgr extends Component {

@property(JsonAsset)
levelDt: JsonAsset;//关卡数据
Expand Down Expand Up @@ -39,7 +41,9 @@ export class Game extends Component {
let monsterDt = this.levelDt.json[GameInfo.Instance.curTheme - 1].monsterid[GameInfo.Instance.curLevel - 1];
let waveDt = this.levelDt.json[GameInfo.Instance.curTheme - 1].wavemonstercount[GameInfo.Instance.curLevel - 1];
this.gameCoinChanged(this.levelDt.json[GameInfo.Instance.curTheme - 1].initgold[GameInfo.Instance.curLevel - 1]);
EventManager.Instance.initLevelData(weaponDt, monsterDt, waveDt);
const enemyPath = EventManager.Instance.initLevelData(weaponDt, monsterDt, waveDt);
this.node.getChildByName('Start').getComponent(StartNode).init(v3(enemyPath[0].x, enemyPath[0].y), v3(enemyPath[1].x, enemyPath[1].y));
this.node.getChildByName('Carrot').getComponent(Carrot).init(v3(enemyPath[enemyPath.length - 1].x, enemyPath[enemyPath.length - 1].y));
EventManager.Instance.closeLoading();
}, 0.5);
}
Expand All @@ -65,6 +69,11 @@ export class Game extends Component {
this.gameSpeed = speed;
}

reduceHp_Carrot(count: number)
{
this.node.getChildByName('Carrot').getComponent(Carrot).reduceHp(count);
}

restartGame()
{
EventManager.Instance.clearAllObserver();
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions assets/Script/MainScene/TowerLayer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { _decorator, Component, instantiate, JsonAsset, Node, Prefab, v3, Vec3 } from 'cc';
import { Tower } from './Tower';
import { Game } from './Game';
import { GameMgr } from './GameMgr';
import { EventManager, IObserverType } from '../Frame/EventManager';
const { ccclass, property } = _decorator;

Expand All @@ -25,7 +25,7 @@ export class TowerLayer extends Component implements IObserver {
let tower = instantiate(this.TowerPrefab[id - 1001]);
let data = this.weaponDt.json[id - 1001];
tower.name = data.icon.split('.', 1)[0];
let isPaused = this.node.parent.getComponent(Game).isPaused;
let isPaused = this.node.parent.getComponent(GameMgr).isPaused;
this.node.addChild(tower);
tower.setPosition(v3(pos.x - 480, pos.y - 320));
tower.getComponent(Tower).init(data, isPaused, EventManager.Instance.getAttackPoint());
Expand Down
9 changes: 0 additions & 9 deletions assets/Script/MainScene/UI1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export class UI1 extends Component {
atlas: SpriteAtlas;
@property(Prefab)
selectPrefab: Prefab;
@property(Prefab)
startPrefab: Prefab;
selectNode: Node;
drawTool: Graphics;

Expand All @@ -19,13 +17,6 @@ export class UI1 extends Component {
this.drawTool = this.node.getComponent(Graphics);
}

init(startPos: Vec3, nextPos: Vec3)
{
let startNode = instantiate(this.startPrefab);
this.node.addChild(startNode);
startNode.getComponent(StartNode).init(startPos, nextPos);
}

drawTowerRange(radius: number, pos: Vec3)
{
this.drawTool.fillColor = new Color(86, 142, 226, 123);
Expand Down
16 changes: 1 addition & 15 deletions assets/Script/MainScene/UIControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { AttackPoint } from './AttackPoint';
import { GameInfo } from '../Frame/GameInfo';
import { CountDown } from './CountDown';
import { AudioManager } from '../Frame/AudioManager';
import { Carrot } from './Carrot';
const { ccclass, property } = _decorator;

@ccclass('UIControl')
Expand All @@ -15,8 +14,6 @@ export class UIControl extends Component implements IObserver {
atlas: SpriteAtlas;
@property(Prefab)
attackPointPrefab: Prefab;
@property(Prefab)
carrotPrefab: Prefab;
attackPoint: Node;
choiceCard: Node;
isMenuOpen: boolean = false;
Expand All @@ -31,18 +28,13 @@ export class UIControl extends Component implements IObserver {
this.coin = this.node.getChildByPath('UP/Coin');
}

init(carrotPos: Vec3)
init()
{
this.node.getChildByPath('UP/WaveCount/AllWave').getComponent(Label).string = GameInfo.Instance.maxWave.toString();
this.choiceCard = this.node.getChildByName('ChoiceCard');
this.disableUpButton();

this.node.getChildByName('CountDown').getComponent(CountDown).init();

let carrot = instantiate(this.carrotPrefab);
this.node.addChild(carrot);
carrot.setPosition(carrotPos.x - 480, carrotPos.y - 320);
this.node.getChildByName('Carrot').getComponent(Carrot).init();
}

showLoading()
Expand All @@ -67,12 +59,6 @@ export class UIControl extends Component implements IObserver {
this.node.getChildByName('UP').getComponentsInChildren(Button).forEach((value) => {
value.interactable = true;
})
this.node.getChildByName('Carrot').getComponent(Carrot).enableClick();
}

reduceHp_Carrot(count: number)
{
this.node.getChildByName('Carrot').getComponent(Carrot).reduceHp(count);
}

showGameOver()
Expand Down

0 comments on commit 21fa4aa

Please sign in to comment.