碰撞
This commit is contained in:
@@ -41,10 +41,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__id__": 36
|
"__id__": 36
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 38
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 40
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"_prefab": {
|
"_prefab": {
|
||||||
"__id__": 38
|
"__id__": 42
|
||||||
},
|
},
|
||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
@@ -250,8 +256,8 @@
|
|||||||
},
|
},
|
||||||
"_lscale": {
|
"_lscale": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 0.25,
|
"x": 0.2,
|
||||||
"y": 0.25,
|
"y": 0.2,
|
||||||
"z": 1
|
"z": 1
|
||||||
},
|
},
|
||||||
"_mobility": 0,
|
"_mobility": 0,
|
||||||
@@ -790,6 +796,74 @@
|
|||||||
"__type__": "cc.CompPrefabInfo",
|
"__type__": "cc.CompPrefabInfo",
|
||||||
"fileId": "37VIdk5BVNxqSq7DlGbRu2"
|
"fileId": "37VIdk5BVNxqSq7DlGbRu2"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.RigidBody2D",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": {
|
||||||
|
"__id__": 39
|
||||||
|
},
|
||||||
|
"enabledContactListener": true,
|
||||||
|
"bullet": true,
|
||||||
|
"awakeOnLoad": true,
|
||||||
|
"_group": 4,
|
||||||
|
"_type": 2,
|
||||||
|
"_allowSleep": false,
|
||||||
|
"_gravityScale": 0,
|
||||||
|
"_linearDamping": 0,
|
||||||
|
"_angularDamping": 0,
|
||||||
|
"_linearVelocity": {
|
||||||
|
"__type__": "cc.Vec2",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"_angularVelocity": 0,
|
||||||
|
"_fixedRotation": false,
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.CompPrefabInfo",
|
||||||
|
"fileId": "capWEt+gNO1olaQ3b/bJvS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.BoxCollider2D",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": {
|
||||||
|
"__id__": 41
|
||||||
|
},
|
||||||
|
"tag": 0,
|
||||||
|
"_group": 4,
|
||||||
|
"_density": 1,
|
||||||
|
"_sensor": true,
|
||||||
|
"_friction": 0.2,
|
||||||
|
"_restitution": 0,
|
||||||
|
"_offset": {
|
||||||
|
"__type__": "cc.Vec2",
|
||||||
|
"x": -1.5,
|
||||||
|
"y": -2.5
|
||||||
|
},
|
||||||
|
"_size": {
|
||||||
|
"__type__": "cc.Size",
|
||||||
|
"width": 49,
|
||||||
|
"height": 55
|
||||||
|
},
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.CompPrefabInfo",
|
||||||
|
"fileId": "79jbcosJ9D6oZt2TJpZIO2"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.PrefabInfo",
|
"__type__": "cc.PrefabInfo",
|
||||||
"root": {
|
"root": {
|
||||||
|
|||||||
@@ -41,10 +41,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__id__": 36
|
"__id__": 36
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 38
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 40
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"_prefab": {
|
"_prefab": {
|
||||||
"__id__": 38
|
"__id__": 42
|
||||||
},
|
},
|
||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
@@ -250,8 +256,8 @@
|
|||||||
},
|
},
|
||||||
"_lscale": {
|
"_lscale": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 0.25,
|
"x": 0.2,
|
||||||
"y": 0.25,
|
"y": 0.2,
|
||||||
"z": 1
|
"z": 1
|
||||||
},
|
},
|
||||||
"_mobility": 0,
|
"_mobility": 0,
|
||||||
@@ -689,7 +695,7 @@
|
|||||||
"node": {
|
"node": {
|
||||||
"__id__": 1
|
"__id__": 1
|
||||||
},
|
},
|
||||||
"_enabled": true,
|
"_enabled": false,
|
||||||
"__prefab": {
|
"__prefab": {
|
||||||
"__id__": 31
|
"__id__": 31
|
||||||
},
|
},
|
||||||
@@ -790,6 +796,74 @@
|
|||||||
"__type__": "cc.CompPrefabInfo",
|
"__type__": "cc.CompPrefabInfo",
|
||||||
"fileId": "37VIdk5BVNxqSq7DlGbRu2"
|
"fileId": "37VIdk5BVNxqSq7DlGbRu2"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.RigidBody2D",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": {
|
||||||
|
"__id__": 39
|
||||||
|
},
|
||||||
|
"enabledContactListener": true,
|
||||||
|
"bullet": true,
|
||||||
|
"awakeOnLoad": true,
|
||||||
|
"_group": 4,
|
||||||
|
"_type": 2,
|
||||||
|
"_allowSleep": false,
|
||||||
|
"_gravityScale": 0,
|
||||||
|
"_linearDamping": 0,
|
||||||
|
"_angularDamping": 0,
|
||||||
|
"_linearVelocity": {
|
||||||
|
"__type__": "cc.Vec2",
|
||||||
|
"x": 0,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"_angularVelocity": 0,
|
||||||
|
"_fixedRotation": false,
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.CompPrefabInfo",
|
||||||
|
"fileId": "13SqotxrBONYCFGINKqG8F"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.BoxCollider2D",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": {
|
||||||
|
"__id__": 41
|
||||||
|
},
|
||||||
|
"tag": 0,
|
||||||
|
"_group": 4,
|
||||||
|
"_density": 1,
|
||||||
|
"_sensor": true,
|
||||||
|
"_friction": 0.2,
|
||||||
|
"_restitution": 0,
|
||||||
|
"_offset": {
|
||||||
|
"__type__": "cc.Vec2",
|
||||||
|
"x": -2.5,
|
||||||
|
"y": -2
|
||||||
|
},
|
||||||
|
"_size": {
|
||||||
|
"__type__": "cc.Size",
|
||||||
|
"width": 57,
|
||||||
|
"height": 52
|
||||||
|
},
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.CompPrefabInfo",
|
||||||
|
"fileId": "9dz9ACoHpDcJCuJCyRkKh+"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.PrefabInfo",
|
"__type__": "cc.PrefabInfo",
|
||||||
"root": {
|
"root": {
|
||||||
|
|||||||
@@ -256,8 +256,8 @@
|
|||||||
},
|
},
|
||||||
"_lscale": {
|
"_lscale": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": 0.25,
|
"x": 0.2,
|
||||||
"y": 0.25,
|
"y": 0.2,
|
||||||
"z": 1
|
"z": 1
|
||||||
},
|
},
|
||||||
"_mobility": 0,
|
"_mobility": 0,
|
||||||
@@ -695,7 +695,7 @@
|
|||||||
"node": {
|
"node": {
|
||||||
"__id__": 1
|
"__id__": 1
|
||||||
},
|
},
|
||||||
"_enabled": true,
|
"_enabled": false,
|
||||||
"__prefab": {
|
"__prefab": {
|
||||||
"__id__": 31
|
"__id__": 31
|
||||||
},
|
},
|
||||||
@@ -816,13 +816,13 @@
|
|||||||
"_restitution": 0,
|
"_restitution": 0,
|
||||||
"_offset": {
|
"_offset": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
"x": -2.7,
|
"x": -2.4,
|
||||||
"y": -2.5
|
"y": -0.9
|
||||||
},
|
},
|
||||||
"_size": {
|
"_size": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 87.4,
|
"width": 56.4,
|
||||||
"height": 77.5
|
"height": 53
|
||||||
},
|
},
|
||||||
"_id": ""
|
"_id": ""
|
||||||
},
|
},
|
||||||
@@ -843,11 +843,11 @@
|
|||||||
"__id__": 41
|
"__id__": 41
|
||||||
},
|
},
|
||||||
"enabledContactListener": true,
|
"enabledContactListener": true,
|
||||||
"bullet": true,
|
"bullet": false,
|
||||||
"awakeOnLoad": true,
|
"awakeOnLoad": true,
|
||||||
"_group": 4,
|
"_group": 4,
|
||||||
"_type": 2,
|
"_type": 2,
|
||||||
"_allowSleep": true,
|
"_allowSleep": false,
|
||||||
"_gravityScale": 0,
|
"_gravityScale": 0,
|
||||||
"_linearDamping": 0,
|
"_linearDamping": 0,
|
||||||
"_angularDamping": 0,
|
"_angularDamping": 0,
|
||||||
|
|||||||
@@ -256,8 +256,8 @@
|
|||||||
},
|
},
|
||||||
"_lscale": {
|
"_lscale": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
"x": -0.25,
|
"x": -0.2,
|
||||||
"y": 0.25,
|
"y": 0.2,
|
||||||
"z": 1
|
"z": 1
|
||||||
},
|
},
|
||||||
"_mobility": 0,
|
"_mobility": 0,
|
||||||
@@ -695,7 +695,7 @@
|
|||||||
"node": {
|
"node": {
|
||||||
"__id__": 1
|
"__id__": 1
|
||||||
},
|
},
|
||||||
"_enabled": true,
|
"_enabled": false,
|
||||||
"__prefab": {
|
"__prefab": {
|
||||||
"__id__": 31
|
"__id__": 31
|
||||||
},
|
},
|
||||||
@@ -816,13 +816,13 @@
|
|||||||
"_restitution": 0,
|
"_restitution": 0,
|
||||||
"_offset": {
|
"_offset": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
"x": 3.6,
|
"x": 1.6,
|
||||||
"y": -2.5
|
"y": -3
|
||||||
},
|
},
|
||||||
"_size": {
|
"_size": {
|
||||||
"__type__": "cc.Size",
|
"__type__": "cc.Size",
|
||||||
"width": 75.1,
|
"width": 59.1,
|
||||||
"height": 70
|
"height": 55
|
||||||
},
|
},
|
||||||
"_id": ""
|
"_id": ""
|
||||||
},
|
},
|
||||||
@@ -843,11 +843,11 @@
|
|||||||
"__id__": 41
|
"__id__": 41
|
||||||
},
|
},
|
||||||
"enabledContactListener": true,
|
"enabledContactListener": true,
|
||||||
"bullet": true,
|
"bullet": false,
|
||||||
"awakeOnLoad": true,
|
"awakeOnLoad": true,
|
||||||
"_group": 2,
|
"_group": 2,
|
||||||
"_type": 2,
|
"_type": 2,
|
||||||
"_allowSleep": true,
|
"_allowSleep": false,
|
||||||
"_gravityScale": 0,
|
"_gravityScale": 0,
|
||||||
"_linearDamping": 0,
|
"_linearDamping": 0,
|
||||||
"_angularDamping": 0,
|
"_angularDamping": 0,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* @LastEditors: dgflash
|
* @LastEditors: dgflash
|
||||||
* @LastEditTime: 2022-08-17 13:43:02
|
* @LastEditTime: 2022-08-17 13:43:02
|
||||||
*/
|
*/
|
||||||
import { profiler, _decorator } from 'cc';
|
import { profiler, _decorator ,PhysicsSystem2D} from 'cc';
|
||||||
import { DEBUG } from 'cc/env';
|
import { DEBUG } from 'cc/env';
|
||||||
import { oops } from '../../extensions/oops-plugin-framework/assets/core/Oops';
|
import { oops } from '../../extensions/oops-plugin-framework/assets/core/Oops';
|
||||||
import { Root } from '../../extensions/oops-plugin-framework/assets/core/Root';
|
import { Root } from '../../extensions/oops-plugin-framework/assets/core/Root';
|
||||||
@@ -24,16 +24,16 @@ export class Main extends Root {
|
|||||||
protected async run() {
|
protected async run() {
|
||||||
smc.initialize = ecs.getEntity<Initialize>(Initialize);
|
smc.initialize = ecs.getEntity<Initialize>(Initialize);
|
||||||
smc.monsters = [
|
smc.monsters = [
|
||||||
{profession:'m1',speed:60},
|
{profession:'m1',speed:50},
|
||||||
{profession:'m2',speed:600},
|
{profession:'m2',speed:50},
|
||||||
{profession:'m3',speed:200},
|
{profession:'m3',speed:50},
|
||||||
{profession:'m4',speed:100},
|
{profession:'m4',speed:50},
|
||||||
]
|
]
|
||||||
smc.heros = [
|
smc.heros = [
|
||||||
{profession:'war',speed:60},
|
{profession:'war',speed:50},
|
||||||
{profession:'magic',speed:60},
|
{profession:'magic',speed:50},
|
||||||
{profession:'heath',speed:60},
|
{profession:'heath',speed:50},
|
||||||
{profession:'war',speed:60},
|
{profession:'war',speed:50},
|
||||||
]
|
]
|
||||||
console.log("Game start");
|
console.log("Game start");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ export class SingletonModuleComp extends ecs.Comp {
|
|||||||
monsters = []
|
monsters = []
|
||||||
/**heros 数据 */
|
/**heros 数据 */
|
||||||
heros = [];
|
heros = [];
|
||||||
|
monsters_in=[]
|
||||||
|
heros_in = []
|
||||||
|
monsters_dead = []
|
||||||
|
heros_dead = []
|
||||||
|
|
||||||
reset() { }
|
reset() { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,13 +46,9 @@ export class Hero extends ecs.Entity {
|
|||||||
node.setPosition(pos)
|
node.setPosition(pos)
|
||||||
node.setScale(1, 1, 1);
|
node.setScale(1, 1, 1);
|
||||||
var mv = node.getComponent(HeroViewComp)!;
|
var mv = node.getComponent(HeroViewComp)!;
|
||||||
|
mv.speed=smc.heros[0].speed;
|
||||||
this.add(mv);
|
this.add(mv);
|
||||||
let speed = smc.heros[0].speed;
|
|
||||||
tween(node).to(speed/60, { position: new Vec3(0, -60, 0) }, {
|
|
||||||
onComplete: () => {
|
|
||||||
// this.as.walk();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
//移除全局列表
|
//移除全局列表
|
||||||
smc.heros.splice(0,1)
|
smc.heros.splice(0,1)
|
||||||
// console.log(ecs.query(ecs.allOf(HeroViewComp)))
|
// console.log(ecs.query(ecs.allOf(HeroViewComp)))
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
|||||||
@disallowMultiple
|
@disallowMultiple
|
||||||
@requireComponent(sp.Skeleton)
|
@requireComponent(sp.Skeleton)
|
||||||
export default class HeroSpineAnimator extends Component {
|
export default class HeroSpineAnimator extends Component {
|
||||||
private animName: string = "idle";
|
private animName: string = "move";
|
||||||
private loop: boolean = true;
|
private loop: boolean = true;
|
||||||
private spine!: sp.Skeleton;
|
private spine!: sp.Skeleton;
|
||||||
start() {
|
start() {
|
||||||
|
|||||||
@@ -5,11 +5,12 @@
|
|||||||
* @LastEditTime: 2022-08-17 12:36:18
|
* @LastEditTime: 2022-08-17 12:36:18
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Vec3, _decorator ,Collider2D,Contact2DType,PhysicsSystem2D,IPhysics2DContact} from "cc";
|
import { Vec3, v3,_decorator ,Collider2D,Contact2DType,PhysicsSystem2D,IPhysics2DContact,EPhysics2DDrawFlags} from "cc";
|
||||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||||
import { HeroSpine } from "./HeroSpine";
|
import { HeroSpine } from "./HeroSpine";
|
||||||
import {BoxSet} from "../common/config/BoxSet"
|
import {BoxSet} from "../common/config/BoxSet"
|
||||||
|
import { smc } from "../common/SingletonModuleComp";
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
/** 角色显示组件 */
|
/** 角色显示组件 */
|
||||||
@@ -19,14 +20,15 @@ export class HeroViewComp extends CCComp {
|
|||||||
/** 角色动画 */
|
/** 角色动画 */
|
||||||
as: HeroSpine = null!;
|
as: HeroSpine = null!;
|
||||||
/** 角色控制器 */
|
/** 角色控制器 */
|
||||||
|
speed: number = 100;
|
||||||
|
Tpos: Vec3 = v3(0,-60,0);
|
||||||
|
|
||||||
start () {
|
start () {
|
||||||
// 注册单个碰撞体的回调函数
|
// 注册单个碰撞体的回调函数
|
||||||
// console.log('MonsterViewComp start');
|
// console.log('MonsterViewComp start');
|
||||||
let collider = this.getComponent(Collider2D);
|
let collider = this.getComponent(Collider2D);
|
||||||
// console.log('hero collider',collider);
|
|
||||||
if (collider) {
|
if (collider) {
|
||||||
|
// console.log('hero collider',collider);
|
||||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +60,29 @@ export class HeroViewComp extends CCComp {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update(dt: number){
|
||||||
|
if(this.node.position.x < 360){
|
||||||
|
this.move(dt);
|
||||||
|
|
||||||
|
}
|
||||||
|
if(this.node.position.x > 360){
|
||||||
|
smc.heros_in = smc.heros_in.filter(element => element.eid !== this.ent.eid);
|
||||||
|
this.node.destroy();
|
||||||
|
}
|
||||||
|
this.update_pos();
|
||||||
|
|
||||||
|
}
|
||||||
|
move(dt: number){
|
||||||
|
this.node.setPosition(this.node.position.x+dt*this.speed, this.node.position.y, this.node.position.z);
|
||||||
|
}
|
||||||
|
update_pos(){
|
||||||
|
smc.heros_in.forEach(element => {
|
||||||
|
if(element.eid == this.ent.eid){
|
||||||
|
element.pos_x = this.node.position.x;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// console.log('smc.heros_in',smc.heros_in);
|
||||||
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.node.destroy();
|
this.node.destroy();
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export class MapViewComp extends CCComp {
|
|||||||
/** 转场 */
|
/** 转场 */
|
||||||
protected update(dt: number): void {
|
protected update(dt: number): void {
|
||||||
if (this.timer.update(dt)) {
|
if (this.timer.update(dt)) {
|
||||||
console.log('每2秒触发一次');
|
// console.log('每2秒触发一次');
|
||||||
this.addHero();
|
this.addHero();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,11 +47,10 @@ export class Monster extends ecs.Entity {
|
|||||||
|
|
||||||
var mv = node.getComponent(MonsterViewComp)!;
|
var mv = node.getComponent(MonsterViewComp)!;
|
||||||
mv.speed = speed;
|
mv.speed = speed;
|
||||||
// console.log("speed:"+mv.speed)
|
|
||||||
mv.Tpos = v3(0,0,0);
|
mv.Tpos = v3(0,0,0);
|
||||||
this.add(mv);
|
this.add(mv);
|
||||||
|
smc.monsters_in.push({name:mv.ent.name,eid:mv.ent.eid,pos_x:0}),
|
||||||
// node.setScale(-1, 1, 1);
|
// node.setScale(-1, 1, 1);
|
||||||
|
|
||||||
oops.message.dispatchEvent("monster_load",this)
|
oops.message.dispatchEvent("monster_load",this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
|||||||
@disallowMultiple
|
@disallowMultiple
|
||||||
@requireComponent(sp.Skeleton)
|
@requireComponent(sp.Skeleton)
|
||||||
export default class MonsterSpineAnimator extends Component {
|
export default class MonsterSpineAnimator extends Component {
|
||||||
private animName: string = "idle";
|
private animName: string = "move";
|
||||||
private loop: boolean = true;
|
private loop: boolean = true;
|
||||||
private spine!: sp.Skeleton;
|
private spine!: sp.Skeleton;
|
||||||
start() {
|
start() {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { MonsterSpine } from "./MonsterSpine";
|
|||||||
import { Monster } from "./Monster";
|
import { Monster } from "./Monster";
|
||||||
import { MonsterModelComp } from "./MonsterModelComp";
|
import { MonsterModelComp } from "./MonsterModelComp";
|
||||||
import { BoxSet } from "../common/config/BoxSet";
|
import { BoxSet } from "../common/config/BoxSet";
|
||||||
|
import { smc } from "../common/SingletonModuleComp";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ export class MonsterViewComp extends CCComp {
|
|||||||
}
|
}
|
||||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||||
// 只在两个碰撞体开始接触时被调用一次
|
// 只在两个碰撞体开始接触时被调用一次
|
||||||
// console.log('monster Contact,selfCollider',selfCollider);
|
// console.log('monster Contact,otherCollider',otherCollider);
|
||||||
|
|
||||||
switch (otherCollider.group) {
|
switch (otherCollider.group) {
|
||||||
case BoxSet.HERO:
|
case BoxSet.HERO:
|
||||||
@@ -57,12 +58,32 @@ export class MonsterViewComp extends CCComp {
|
|||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.as = this.getComponent(MonsterSpine);
|
this.as = this.getComponent(MonsterSpine);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update(dt: number){
|
update(dt: number){
|
||||||
|
if(this.node.position.x > -360){
|
||||||
|
this.move(dt);
|
||||||
|
}
|
||||||
|
if(this.node.position.x < -360){
|
||||||
|
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||||
|
this.node.destroy();
|
||||||
|
}
|
||||||
|
this.update_pos();
|
||||||
|
|
||||||
|
}
|
||||||
|
move(dt: number){
|
||||||
this.node.setPosition(this.node.position.x-dt*this.speed, this.node.position.y, this.node.position.z);
|
this.node.setPosition(this.node.position.x-dt*this.speed, this.node.position.y, this.node.position.z);
|
||||||
}
|
}
|
||||||
|
update_pos(){
|
||||||
|
smc.monsters_in.forEach(element => {
|
||||||
|
if(element.eid == this.ent.eid){
|
||||||
|
element.pos_x = this.node.position.x;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// console.log('smc.monsters_in',smc.monsters_in);
|
||||||
|
}
|
||||||
reset() {
|
reset() {
|
||||||
this.node.destroy();
|
this.node.destroy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"collisionMatrix": {
|
"collisionMatrix": {
|
||||||
"0": 0,
|
"0": 1,
|
||||||
"1": 20,
|
"1": 20,
|
||||||
"2": 10,
|
"2": 10,
|
||||||
"3": 4,
|
"3": 4,
|
||||||
|
|||||||
Reference in New Issue
Block a user