Commit 49befe32 authored by Nguyễn Quang Sáng's avatar Nguyễn Quang Sáng

7/8/2023 commit

parent 50258d9c
[
{
"__type__": "cc.Prefab",
"_name": "",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"asyncLoadAssets": false,
"readonly": false
},
{
"__type__": "cc.Node",
"_name": "Bee",
"_objFlags": 0,
"_parent": null,
"_children": [],
"_active": true,
"_components": [
{
"__id__": 2
},
{
"__id__": 3
},
{
"__id__": 4
},
{
"__id__": 5
},
{
"__id__": 6
}
],
"_prefab": {
"__id__": 7
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 50,
"height": 40
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
199.482,
775.451,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "264c6bfd-3067-4b18-a163-8e00eb566c68"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": ""
},
{
"__type__": "81c43rSpUFKXalhcNSxF1Ii",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_id": ""
},
{
"__type__": "cc.Animation",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_defaultClip": {
"__uuid__": "9210cdc7-bcf0-4f0c-bba1-7359ac324c0e"
},
"_clips": [
{
"__uuid__": "9210cdc7-bcf0-4f0c-bba1-7359ac324c0e"
}
],
"playOnLoad": true,
"_id": ""
},
{
"__type__": "cc.RigidBody",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_type": 2,
"_allowSleep": false,
"_gravityScale": 0,
"_linearDamping": 0,
"_angularDamping": 0,
"_linearVelocity": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_angularVelocity": 0,
"_fixedRotation": true,
"enabledContactListener": false,
"bullet": false,
"awakeOnLoad": true,
"_id": ""
},
{
"__type__": "cc.PhysicsPolygonCollider",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"tag": 0,
"_density": 1,
"_sensor": false,
"_friction": 0.2,
"_restitution": 0,
"body": null,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"points": [
{
"__type__": "cc.Vec2",
"x": -25.2,
"y": -6.84
},
{
"__type__": "cc.Vec2",
"x": -18.33,
"y": -8.82
},
{
"__type__": "cc.Vec2",
"x": -14.82,
"y": -15.09
},
{
"__type__": "cc.Vec2",
"x": -8.87,
"y": -18.89
},
{
"__type__": "cc.Vec2",
"x": -4.75,
"y": -19.73
},
{
"__type__": "cc.Vec2",
"x": 0.02,
"y": -19.51
},
{
"__type__": "cc.Vec2",
"x": 5.79,
"y": -19.08
},
{
"__type__": "cc.Vec2",
"x": 14.3,
"y": -16.93
},
{
"__type__": "cc.Vec2",
"x": 17.6,
"y": -14.84
},
{
"__type__": "cc.Vec2",
"x": 20.5,
"y": -10.71
},
{
"__type__": "cc.Vec2",
"x": 21.51,
"y": -8.3
},
{
"__type__": "cc.Vec2",
"x": 21.42,
"y": -6.86
},
{
"__type__": "cc.Vec2",
"x": 23.47,
"y": -4.83
},
{
"__type__": "cc.Vec2",
"x": 25.02,
"y": -2.87
},
{
"__type__": "cc.Vec2",
"x": 23.41,
"y": -1.08
},
{
"__type__": "cc.Vec2",
"x": 21.7,
"y": 1.28
},
{
"__type__": "cc.Vec2",
"x": 18.6,
"y": 1.19
},
{
"__type__": "cc.Vec2",
"x": 17.72,
"y": 2.53
},
{
"__type__": "cc.Vec2",
"x": 18.66,
"y": 3.27
},
{
"__type__": "cc.Vec2",
"x": 19.92,
"y": 3.41
},
{
"__type__": "cc.Vec2",
"x": 21.31,
"y": 3.64
},
{
"__type__": "cc.Vec2",
"x": 22.12,
"y": 3.83
},
{
"__type__": "cc.Vec2",
"x": 22.4,
"y": 5.62
},
{
"__type__": "cc.Vec2",
"x": 20.99,
"y": 7.39
},
{
"__type__": "cc.Vec2",
"x": 19.72,
"y": 7.2
},
{
"__type__": "cc.Vec2",
"x": 18.27,
"y": 5.05
},
{
"__type__": "cc.Vec2",
"x": 15.78,
"y": 3.45
},
{
"__type__": "cc.Vec2",
"x": 14.6,
"y": 4.6
},
{
"__type__": "cc.Vec2",
"x": 15.7,
"y": 5.46
},
{
"__type__": "cc.Vec2",
"x": 17.46,
"y": 5.49
},
{
"__type__": "cc.Vec2",
"x": 17.58,
"y": 7.41
},
{
"__type__": "cc.Vec2",
"x": 16.62,
"y": 9.21
},
{
"__type__": "cc.Vec2",
"x": 15.44,
"y": 9.25
},
{
"__type__": "cc.Vec2",
"x": 14.2,
"y": 8.69
},
{
"__type__": "cc.Vec2",
"x": 13.21,
"y": 5.64
},
{
"__type__": "cc.Vec2",
"x": 11.39,
"y": 5.01
},
{
"__type__": "cc.Vec2",
"x": 10.29,
"y": 6.02
},
{
"__type__": "cc.Vec2",
"x": 11.53,
"y": 8.93
},
{
"__type__": "cc.Vec2",
"x": 12.05,
"y": 11.09
},
{
"__type__": "cc.Vec2",
"x": 11.37,
"y": 13.76
},
{
"__type__": "cc.Vec2",
"x": 10.17,
"y": 16.45
},
{
"__type__": "cc.Vec2",
"x": 8.29,
"y": 18.25
},
{
"__type__": "cc.Vec2",
"x": 5.19,
"y": 19.26
},
{
"__type__": "cc.Vec2",
"x": 0.68,
"y": 19.21
},
{
"__type__": "cc.Vec2",
"x": -3.12,
"y": 17.32
},
{
"__type__": "cc.Vec2",
"x": -7.01,
"y": 19.39
},
{
"__type__": "cc.Vec2",
"x": -10.33,
"y": 18.39
},
{
"__type__": "cc.Vec2",
"x": -12.72,
"y": 15.76
},
{
"__type__": "cc.Vec2",
"x": -13.9,
"y": 13.71
},
{
"__type__": "cc.Vec2",
"x": -13.69,
"y": 10.72
},
{
"__type__": "cc.Vec2",
"x": -12.71,
"y": 7.44
},
{
"__type__": "cc.Vec2",
"x": -11.92,
"y": 5.75
},
{
"__type__": "cc.Vec2",
"x": -16.01,
"y": 1.51
},
{
"__type__": "cc.Vec2",
"x": -17.84,
"y": -2.77
},
{
"__type__": "cc.Vec2",
"x": -18.39,
"y": -3.96
},
{
"__type__": "cc.Vec2",
"x": -24.45,
"y": -5.21
}
],
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "",
"sync": false
}
]
\ No newline at end of file
{
"ver": "1.3.2",
"uuid": "7c6aebf9-b0b0-4ee0-9a19-c3b7e1828a7f",
"importer": "prefab",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"readonly": false,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
...@@ -559,7 +559,7 @@ ...@@ -559,7 +559,7 @@
}, },
"_enabled": true, "_enabled": true,
"_type": 2, "_type": 2,
"_allowSleep": true, "_allowSleep": false,
"_gravityScale": 3, "_gravityScale": 3,
"_linearDamping": 0, "_linearDamping": 0,
"_angularDamping": 0, "_angularDamping": 0,
...@@ -576,7 +576,7 @@ ...@@ -576,7 +576,7 @@
"_id": "0aOtl5uc9D+5f8HUl0n23C" "_id": "0aOtl5uc9D+5f8HUl0n23C"
}, },
{ {
"__type__": "cc.PhysicsChainCollider", "__type__": "cc.PhysicsPolygonCollider",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
...@@ -589,35 +589,34 @@ ...@@ -589,35 +589,34 @@
"_friction": 0.2, "_friction": 0.2,
"_restitution": 0, "_restitution": 0,
"body": null, "body": null,
"loop": false, "_offset": {
"points": [
{
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
"x": -10, "x": 0,
"y": 75 "y": 0
}, },
"points": [
{ {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
"x": -10, "x": -10.3,
"y": -75 "y": -74.6
}, },
{ {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
"x": 9.9, "x": 10.1,
"y": -75 "y": -75.2
}, },
{ {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
"x": 10, "x": 9.9,
"y": 75.3 "y": 74.8
}, },
{ {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
"x": -9.8, "x": -9.5,
"y": 74.7 "y": 74.4
} }
], ],
"_id": "8dIJZn2zJJ1pwh6f63BZgi" "_id": "c4jw7B7cVObaXQvTmhhUtp"
}, },
{ {
"__type__": "7aaccRSHlRDIJdCgIhB/vcq", "__type__": "7aaccRSHlRDIJdCgIhB/vcq",
......
import Dog from "./Dog";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class Bee extends cc.Component { export default class Bee extends cc.Component {
static instance: Bee; static instance: Bee;
flySpeed: number = 100; flySpeed: number = 200;
targetPosition: cc.Vec3 = null; targetPosition: cc.Vec3 = null;
flying = false;
protected onLoad(): void { protected onLoad(): void {
Bee.instance = this; Bee.instance = this;
this.node.setPosition(this.node.parent.position); this.targetPosition = Dog.instance.node.position;
this.node.active = true;
this.targetPosition =
this.node.parent.parent.getChildByName("Dog").position;
} }
onHunting() {}
protected update(dt: number): void {} protected update(dt: number): void {
if (this.targetPosition && this.flying) {
let direction = this.targetPosition.sub(this.node.position);
let distance = direction.mag();
let angle = (Math.atan2(direction.y, direction.x) * 180) / Math.PI;
this.node.angle = angle;
if (distance > 1) {
let step = this.flySpeed * dt;
let newPos = this.node.position.add(direction.normalize().mul(step));
this.node.setPosition(newPos);
}
}
}
fly() {
this.flying = true;
}
} }
...@@ -7,4 +7,5 @@ export default class Dog extends cc.Component { ...@@ -7,4 +7,5 @@ export default class Dog extends cc.Component {
protected onLoad(): void { protected onLoad(): void {
Dog.instance = this; Dog.instance = this;
} }
} }
import Bee from "./Bee"; import Bee from "./Bee";
import Dog from "./Dog"; import Dog from "./Dog";
import Hole from "./Hole";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -10,7 +11,6 @@ export default class GamePlay extends cc.Component { ...@@ -10,7 +11,6 @@ export default class GamePlay extends cc.Component {
@property(cc.Graphics) graphic: cc.Graphics = null; @property(cc.Graphics) graphic: cc.Graphics = null;
isDrawing: boolean = true; isDrawing: boolean = true;
points: any;
draw: cc.Node = null; draw: cc.Node = null;
rb = null; rb = null;
chain = null; chain = null;
...@@ -19,10 +19,9 @@ export default class GamePlay extends cc.Component { ...@@ -19,10 +19,9 @@ export default class GamePlay extends cc.Component {
cc.director.getPhysicsManager().enabled = true; cc.director.getPhysicsManager().enabled = true;
cc.director.getCollisionManager().enabled = true; cc.director.getCollisionManager().enabled = true;
// cc.director.getPhysicsManager().debugDrawFlags = 1; cc.director.getPhysicsManager().debugDrawFlags = 1;
this.loadPrefab(); this.loadPrefab();
this.points = [];
this.gameRegion.on(cc.Node.EventType.TOUCH_START, this.onTouchDown, this); this.gameRegion.on(cc.Node.EventType.TOUCH_START, this.onTouchDown, this);
this.gameRegion.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this); this.gameRegion.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
...@@ -36,33 +35,34 @@ export default class GamePlay extends cc.Component { ...@@ -36,33 +35,34 @@ export default class GamePlay extends cc.Component {
} }
onTouchDown(event) { onTouchDown(event) {
this.points.push(event.getLocation());
this.draw = new cc.Node(); this.draw = new cc.Node();
this.draw.parent = this.node; this.draw.parent = this.node;
this.draw.addComponent(cc.Graphics); this.draw.addComponent(cc.Graphics);
this.rb = this.draw.addComponent(cc.RigidBody); this.rb = this.draw.addComponent(cc.RigidBody);
this.rb.type = cc.RigidBodyType.Static; this.rb.type = cc.RigidBodyType.Static;
this.chain = this.draw.addComponent(cc.PhysicsChainCollider); this.chain = this.draw.addComponent(cc.PhysicsChainCollider);
this.chain.points = []; this.chain.points = [event.getLocation()];
} }
onTouchMove(event) { onTouchMove(event) {
if (this.isDrawing) { if (this.isDrawing) {
this.points.push(event.getLocation());
this.chain.points.push(event.getLocation()); this.chain.points.push(event.getLocation());
this.drawLine(); this.drawLine();
} }
} }
onTouchUp(event) { onTouchUp(event) {
// this.isDrawing = false; // this.isDrawing = false;
this.points = []; // this.rb.type = cc.RigidBodyType.Dynamic;
this.rb.type = cc.RigidBodyType.Dynamic; this.rb.allowSleep = false;
Dog.instance.getComponent(cc.Animation).play("DogScare"); Dog.instance.getComponent(cc.Animation).play("DogScare");
this.chain.apply();
Hole.instance.isSpawnable = true;
} }
drawLine() { drawLine() {
if (this.points.length <= 1) return; if (this.chain.points.length < 3) return;
let lineComponent = this.draw.getComponent(cc.Graphics); let lineComponent = this.draw.getComponent(cc.Graphics);
if (lineComponent == null) if (lineComponent == null)
...@@ -71,15 +71,14 @@ export default class GamePlay extends cc.Component { ...@@ -71,15 +71,14 @@ export default class GamePlay extends cc.Component {
lineComponent.strokeColor = cc.Color.BLACK; lineComponent.strokeColor = cc.Color.BLACK;
lineComponent.lineWidth = 10; lineComponent.lineWidth = 10;
for (let i = 0; i < this.points.length - 1; i++) { for (let i = 0; i < this.chain.points.length - 1; i++) {
let p1 = this.points[i]; let p1 = this.chain.points[i];
let p2 = this.points[i + 1]; let p2 = this.chain.points[i + 1];
let p1InLocal = this.node.convertToNodeSpaceAR(p1); let p1InLocal = this.node.convertToNodeSpaceAR(p1);
let p2InLocal = this.node.convertToNodeSpaceAR(p2); let p2InLocal = this.node.convertToNodeSpaceAR(p2);
lineComponent.moveTo(p1InLocal.x, p1InLocal.y); lineComponent.moveTo(p1InLocal.x, p1InLocal.y);
lineComponent.lineTo(p2InLocal.x, p2InLocal.y); lineComponent.lineTo(p2InLocal.x, p2InLocal.y);
lineComponent.stroke(); lineComponent.stroke();
} }
this.chain.apply();
} }
} }
import Bee from "./Bee";
const { ccclass, property } = cc._decorator;
@ccclass
export default class Hole extends cc.Component {
static instance: Hole;
@property(cc.Prefab) private beePrefab: cc.Prefab = null;
@property(cc.Float) refreshTimer: number = 0.5;
@property(cc.Node) dog: cc.Node = null;
isSpawnable: boolean = false;
timer: number = 0;
beeAmount: number = 10;
currentBeeAmount: number = 0;
spawnBees() {
if (!this.isSpawnable) return;
if (this.timer > 0) return;
if (this.currentBeeAmount >= this.beeAmount) return;
this.timer = this.refreshTimer;
var bee = cc.instantiate(this.beePrefab);
let nodeWorldPosition = this.node.convertToWorldSpaceAR(cc.Vec2.ZERO);
let nodeCanvasPosition =
this.node.parent.parent.convertToNodeSpaceAR(nodeWorldPosition);
bee.parent = this.node.parent.parent;
bee.position = cc.v3(nodeCanvasPosition.x, nodeCanvasPosition.y);
bee.getComponent(Bee).targetPosition = this.dog.position;
bee.getComponent(Bee).fly();
this.currentBeeAmount++;
// bee.getComponent(cc.RigidBody).linearVelocity = velocity
}
protected update(dt: number): void {
this.timer -= dt;
this.spawnBees();
}
protected onLoad(): void {
Hole.instance = this;
}
}
{
"ver": "1.1.0",
"uuid": "916adbe5-3473-4521-95a0-dc7e1cb0c314",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment