基础技能完善

This commit is contained in:
2024-08-22 09:04:26 +08:00
parent ee7f1c322b
commit ceee58079d
39 changed files with 1999 additions and 63 deletions

View File

@@ -0,0 +1,29 @@
import { _decorator, color, Component, Material, Node, Sprite } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('FlashSprite')
export class FlashSprite extends Component {
@property(Material)
hitFlashMaterial: Material;
orginalFlashMaterial: Material;
sprite: Sprite;
start() {
this.sprite = this.node.getComponent(Sprite);
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
}
update(deltaTime: number) {
}
public clickFlash() {
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
this.scheduleOnce(() => {
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
}, 0.1);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "df953176-a9fa-4f3e-865e-7956fccc4c52",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -22,7 +22,7 @@ export class MapMonsterComp extends CCComp {
monster_level:number = 1; //怪物池等级
max_monster_level:number = 4; //最高怪物次等级
min_monster_num:number = 2; ///最小每次刷新怪物数量
max_monster_num:number = 2; //最大每次刷新怪物数量
max_monster_num:number = 4; //最大每次刷新怪物数量
refresh_timer: Timer = new Timer(5); // 刷新怪物定时器
refresh_cd: Timer = new Timer(0.5);
mission_up_timer: Timer = new Timer(30); //波次增加
@@ -49,7 +49,7 @@ export class MapMonsterComp extends CCComp {
this.monster_refresh()
}
if (this.refresh_timer.update(dt)) {
this.setp_num = RandomManager.instance.getRandomInt(this.max_monster_num,this.max_monster_level,2)
this.setp_num = RandomManager.instance.getRandomInt(this.min_monster_num,this.max_monster_num,2)
}
if (this.mission_up_timer.update(dt)) {
// 刷新怪物定时器

View File

@@ -73,7 +73,6 @@ export class Hero extends ecs.Entity {
mv.scale = 1;
mv.change_name(smc.heros[uuid].name,1)
this.add(mv);
this.push_monsters_in(uuid,mv.ent.eid)
}
push_monsters_in(uuid:number=1001,eid:number=0){
smc.monsters_in.push({name:smc.heros[uuid].name,eid:eid})

View File

@@ -4,7 +4,7 @@ import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/modu
import { data } from "../data/data";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { smc } from "../common/SingletonModuleComp";
import { CardSet } from "../common/config/CardSet";
import { CardSet, SkillSet } from "../common/config/CardSet";
import { HeroCard } from "./HeroCard";
import { HeroModelComp } from "./HeroModelComp";
import { Hero } from "./Hero";
@@ -105,7 +105,7 @@ export class HeroCardViewComp extends CCComp {
let heros = ecs.query(ecs.allOf(HeroModelComp))
// let heross= ecs.query(ecs.allOf(MonsterViewComp))
// console.log("heross",heross)
if(heros.length >= 4){
if(heros.length >= 4&&this.card_type == 1){
oops.gui.toast("英雄数量达到上限");
this.node.setPosition(this.pos_x,this.pos_y);
return;

View File

@@ -5,7 +5,7 @@
* @LastEditTime: 2022-08-17 12:36:18
*/
import { Vec3, _decorator , v3,Collider2D,Contact2DType,IPhysics2DContact,PhysicsSystem2D,EPhysics2DDrawFlags,Label,Node,Prefab,instantiate,ProgressBar} from "cc";
import { Vec3, _decorator , v3,Collider2D,Contact2DType,IPhysics2DContact,PhysicsSystem2D,EPhysics2DDrawFlags,Label,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite} from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { MonsterSpine } from "./MonsterSpine";
@@ -24,6 +24,12 @@ const { ccclass, property } = _decorator;
@ccclass('MonsterViewComp') // 定义为 Cocos Creator 组件
@ecs.register('MonsterView', false) // 定义为 ECS 组件
export class MonsterViewComp extends CCComp {
@property(Material)
hitFlashMaterial: Material;
orginalFlashMaterial: Material;
sprite: Sprite;
/** 角色动画 */
as: MonsterSpine = null!;
hero_uuid:number = 1001;
@@ -41,7 +47,7 @@ export class MonsterViewComp extends CCComp {
power_max: number = 100; /** 能量最大值 */
power_speed: number = 1; //能量回复速度每0.1秒回复量
skill_name: string = "base"; //技能名称
skill_name: string = "atk"; //技能名称
max_skill_name: string = "base"; //大技能名称
atk: number = 10; /**攻击力 */
@@ -63,6 +69,8 @@ export class MonsterViewComp extends CCComp {
/** 视图层逻辑代码分离演示 */
start () {
this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
// 注册单个碰撞体的回调函数
let collider = this.getComponent(Collider2D);
if (collider) {
@@ -147,7 +155,7 @@ export class MonsterViewComp extends CCComp {
* 如果角色属于正向阵营 (scale == 1) 且 x 轴位置大于等于 0则直接返回。
* 如果角色属于反向阵营 (scale != 1) 且 x 轴位置小于等于 0则直接返回。
*/
if ((this.scale === 1 && this.node.position.x >= 0) || (this.scale !== 1 && this.node.position.x <= -180)) {
if ((this.scale === 1 && this.node.position.x >= 120) || (this.scale !== 1 && this.node.position.x <= -180)) {
return;
}
@@ -226,22 +234,33 @@ export class MonsterViewComp extends CCComp {
}
});
}
load_skill(skill_name){
load_skill(skill_name:string){
// console.log("load_skill");
let skill = ecs.getEntity<Skill>(Skill);
let pos = v3(this.scale*30,30)
let speed =400
let x=30
if(this.scale==1){
x=40
}else{
x=-20
}
let pos = v3(x,50)
let speed =350
let scale = this.scale
let range = 120;
skill.load(pos,speed,range,scale,this.node,skill_name,this.atk);
let dis = 30;
console.log(speed);
skill.load(pos,speed,dis,scale,this.node,skill_name,this.atk);
}
in_atked() {
var path = "game/skills/atked";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
let pos = v3(0,30)
node.setPosition(pos)
node.parent = this.node;
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
this.scheduleOnce(() => {
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
}, 0.1);
// var path = "game/skills/atked";
// var prefab: Prefab = oops.res.get(path, Prefab)!;
// var node = instantiate(prefab);
// let pos = v3(0,30)
// node.setPosition(pos)
// node.parent = this.node;
}
dead(){
var path = "game/skills/dead";
@@ -252,8 +271,7 @@ export class MonsterViewComp extends CCComp {
}
toDestroy(){
this.dead();
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
this.ent.destroy();
}
reset() {

View File

@@ -36,7 +36,7 @@ export class Skill extends ecs.Entity {
node.setScale(scale,1)
//转换pos为世界坐标
node.setPosition(pos)
console.log(speed)
var sv = node.getComponent(SkillCom)!;
sv.speed = speed;
sv.dis = dis;

View File

@@ -44,7 +44,7 @@ export class SkillCom extends CCComp {
tween(this.node).to( 1,{ angle:this.angle,position: this.t_pos},
{
onComplete: (target?: object) => {
// this.check_to_destroy()
this.toDestroy()
},
} ).start();
}else{
@@ -52,7 +52,7 @@ export class SkillCom extends CCComp {
{ position: new Vec3(this.node.position.x+this.scale*this.dis,this.node.position.y) },
{
onComplete: (target?: object) => {
this.check_to_destroy()
this.toDestroy()
},
}
).start();
@@ -66,7 +66,9 @@ export class SkillCom extends CCComp {
switch (otherCollider.group){
case BoxSet.MONSTER:
case BoxSet.DEFAULT:
this.check_to_destroy()
setTimeout(() => {
this.toDestroy()
}, 10);
break
}
break;
@@ -75,7 +77,9 @@ export class SkillCom extends CCComp {
case BoxSet.PLAYER:
case BoxSet.HERO:
case BoxSet.DEFAULT:
this.check_to_destroy()
setTimeout(() => {
this.toDestroy()
}, 10);
break
}
}
@@ -91,7 +95,7 @@ export class SkillCom extends CCComp {
this.move(deltaTime)
// if(Math.abs(this.node.position.x) > this.dis)
// {
// this.check_to_destroy()
// this.toDestroy()
// }
@@ -99,36 +103,17 @@ export class SkillCom extends CCComp {
move(dt: number) {
// this.node.setPosition(v3(this.node.position.x+dt*this.x_speed*this.scale,this.node.position.y+this.y_speed,this.node.position.z))
}
check_to_destroy(){
if(!this.is_destroy){
this.is_destroy = true;
setTimeout(() => {
this.toDestroy();
}, 10);
this.toDestroy();
}
}
/** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) {
// switch (event) {
// case ModuleEvent.Cmd:
// break;
// }
// }
toDestroy() {
// this.node.active = false;
// var scene = smc.map.MapView.scene;
// this.node.parent = scene.entityLayer!.node!;
// console.log("toDestroy");
// console.log("this.node.isValid");
setTimeout(() => {
// console.log("SkillCom.node.destroy",this);
this.ent.destroy()
}, 10);
if(!this.is_destroy){
this.is_destroy = true;
if(this.node.isValid) this.node.destroy()
}
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {