Skip to content

Commit 64ee7c8

Browse files
Flying KatsuFlying Katsu
Flying Katsu
authored and
Flying Katsu
committedApr 9, 2017
adjusted sword attack animation; initial attack collision behavior
1 parent 00c76a9 commit 64ee7c8

File tree

7 files changed

+175
-16
lines changed

7 files changed

+175
-16
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class HitBehavior extends Sup.Behavior {
2+
3+
defense = 1;
4+
5+
awake() {
6+
7+
}
8+
9+
update() {
10+
11+
}
12+
13+
// Update health accordingly
14+
processHit() {
15+
16+
}
17+
18+
}
19+
Sup.registerBehavior(HitBehavior);

‎assets/Entities (134)/Actors (27)/Player (21)/PlayerBehavior (24)/script.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class PlayerBehavior extends Sup.Behavior {
290290
}
291291

292292
private processUseItem() {
293-
if ( this.controls.pressed.use ) Sup.log("Used item!");
293+
//if ( this.controls.pressed.use ) Sup.log("Used item!");
294294

295295
// Check item actions
296296

‎assets/Entities (134)/Items (12)/ItemBehavior (183)/script.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ItemBehavior extends Sup.Behavior {
1818
private isEquipped: boolean;
1919
private isFlipped: boolean;
2020

21-
private owner: Sup.Actor;
21+
owner: Sup.Actor;
2222

2323
awake() {
2424
this.label = this.actor.getChild("Label");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
class WeaponBehavior extends Sup.Behavior {
2+
itemtype: number;
3+
4+
private timer = 0;
5+
private isAttacking = false;
6+
7+
private localPos;
8+
private initialRot;
9+
10+
private deltaX = 0;
11+
private deltaY = 0;
12+
13+
awake() {
14+
this.localPos = this.actor.getLocalPosition();
15+
this.initialRot = this.actor.getLocalEulerAngles();
16+
}
17+
18+
update() {
19+
if (this.isAttacking && this.timer > -1) {
20+
21+
// Process collisions with actors
22+
let maybeHitActors: Sup.Actor[] = [];
23+
if ( this.actor.getBehavior(ItemBehavior).owner.getName() == "Player" ) {
24+
for ( let actor:Sup.Actor of Sup.getActor("Heroes").getChildren() ) {
25+
maybeHitActors.push(actor);
26+
}
27+
} else {
28+
maybeHitActors.push(Sup.getActor("Player"));
29+
}
30+
for ( let dragon:Sup.Actor of Sup.getActor("Dragons").getChildren() ) {
31+
for (let actor:Sup.Actor of dragon.getChild("Hitbox").getChildren()) {
32+
maybeHitActors.push(actor);
33+
}
34+
}
35+
36+
for ( let actor:Sup.Actor in maybeHitActors ) {
37+
if ( Sup.ArcadePhysics2D.intersects(actor.arcadeBody2D, this.actor.getChild("Sprite").arcadeBody2D) ) {
38+
actor.getBehavior(HitBehavior).processHit();
39+
}
40+
}
41+
42+
43+
// Animate weapon movement
44+
let flip = this.actor.getChild("Sprite").spriteRenderer.getHorizontalFlip() ? -1 : 1;
45+
let fliprot = this.actor.getChild("Sprite").spriteRenderer.getHorizontalFlip() ? 180 : 0;
46+
switch(this.timer) {
47+
case 0:
48+
default:
49+
this.actor.getChild("Sprite").moveLocalX( -this.deltaX );
50+
this.actor.getChild("Sprite").moveLocalY( -this.deltaY );
51+
this.deltaX = 0; this.deltaY = 0;
52+
this.actor.getChild("Sprite").setLocalEulerZ(Sup.Math.toRadians(45 * flip));
53+
break;
54+
55+
case 1:
56+
break;
57+
58+
case 2:
59+
this.actor.getChild("Sprite").moveLocalX( -0.5 * flip );
60+
this.actor.getChild("Sprite").moveLocalY( -0.5 );
61+
this.deltaX += -0.5 * flip; this.deltaY += -0.5;
62+
this.actor.getChild("Sprite").setLocalEulerZ(Sup.Math.toRadians(-30 * flip));
63+
break;
64+
65+
case 3:
66+
this.actor.getChild("Sprite").moveLocalX( 0.5 * flip );
67+
this.actor.getChild("Sprite").moveLocalY( -0.5 );
68+
this.deltaX += 0.5 * flip; this.deltaY += -0.5;
69+
this.actor.getChild("Sprite").setLocalEulerZ(Sup.Math.toRadians(0 * flip));
70+
break;
71+
72+
case 4:
73+
this.actor.getChild("Sprite").moveLocalX( 1 * flip );
74+
this.actor.getChild("Sprite").moveLocalY( 0.5 );
75+
this.deltaX += 1 * flip; this.deltaY += 0.5;
76+
this.actor.getChild("Sprite").setLocalEulerZ(Sup.Math.toRadians(30 * flip));
77+
break;
78+
79+
case 5:
80+
break;
81+
}
82+
this.timer--;
83+
}
84+
}
85+
86+
attack() {
87+
this.isAttacking = true;
88+
this.timer = 5;
89+
}
90+
}
91+
Sup.registerBehavior(WeaponBehavior);

‎assets/Entities (134)/Items (12)/Weapons (13)/WeaponBehavior (184)/script.ts

+46-13
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,64 @@ class WeaponBehavior extends Sup.Behavior {
1717

1818
update() {
1919
if (this.isAttacking && this.timer > -1) {
20+
21+
// Process collisions with actors
22+
let maybeHitActors = [];
23+
if ( this.actor.getBehavior(ItemBehavior).owner.getName() == "Player" ) {
24+
for ( let actor of Sup.getActor("Heroes").getChildren() ) {
25+
maybeHitActors.push(actor);
26+
}
27+
} else {
28+
maybeHitActors.push(Sup.getActor("Player"));
29+
}
30+
for ( let dragon of Sup.getActor("Dragons").getChildren() ) {
31+
for (let actor of dragon.getChild("Hitbox").getChildren()) {
32+
maybeHitActors.push(actor);
33+
}
34+
}
35+
36+
for ( let actor in maybeHitActors ) {
37+
38+
}
39+
40+
41+
// Animate weapon movement
2042
let flip = this.actor.getChild("Sprite").spriteRenderer.getHorizontalFlip() ? -1 : 1;
43+
let fliprot = this.actor.getChild("Sprite").spriteRenderer.getHorizontalFlip() ? 180 : 0;
2144
switch(this.timer) {
2245
case 0:
2346
default:
24-
//this.actor.getChild("Sprite").rotateEulerZ(this.initialRot);
25-
//this.actor.getChild("Sprite").setLocalPosition(this.localPos);
26-
//this.actor.getChild("Sprite").rotateLocalEulerZ(5);
2747
this.actor.getChild("Sprite").moveLocalX( -this.deltaX );
2848
this.actor.getChild("Sprite").moveLocalY( -this.deltaY );
29-
//this.actor.getChild("Sprite").rotateEulerZ(35);
3049
this.deltaX = 0; this.deltaY = 0;
50+
this.actor.getChild("Sprite").setLocalEulerZ(Sup.Math.toRadians(45 * flip));
3151
break;
52+
3253
case 1:
33-
//this.actor.getChild("Sprite").rotateLocalEulerZ(-5);
34-
this.actor.getChild("Sprite").moveLocalX( 0.5 * flip );
35-
this.actor.getChild("Sprite").moveLocalY( 0.25 * flip );
36-
this.deltaX += 0.5 * flip; this.deltaY += 0.25 * flip;
3754
break;
55+
3856
case 2:
39-
this.actor.getChild("Sprite").moveLocalX( 0.5 * flip);
40-
this.actor.getChild("Sprite").moveLocalY( 0.25 * flip);
41-
this.deltaX += 0.5 * flip; this.deltaY += 0.25 * flip;
57+
this.actor.getChild("Sprite").moveLocalX( -0.5 * flip );
58+
this.actor.getChild("Sprite").moveLocalY( -0.5 );
59+
this.deltaX += -0.5 * flip; this.deltaY += -0.5;
60+
this.actor.getChild("Sprite").setLocalEulerZ(Sup.Math.toRadians(-30 * flip));
4261
break;
62+
4363
case 3:
44-
//this.actor.getChild("Sprite").rotateLocalEulerZ(-35);
64+
this.actor.getChild("Sprite").moveLocalX( 0.5 * flip );
65+
this.actor.getChild("Sprite").moveLocalY( -0.5 );
66+
this.deltaX += 0.5 * flip; this.deltaY += -0.5;
67+
this.actor.getChild("Sprite").setLocalEulerZ(Sup.Math.toRadians(0 * flip));
68+
break;
69+
70+
case 4:
71+
this.actor.getChild("Sprite").moveLocalX( 1 * flip );
72+
this.actor.getChild("Sprite").moveLocalY( 0.5 );
73+
this.deltaX += 1 * flip; this.deltaY += 0.5;
74+
this.actor.getChild("Sprite").setLocalEulerZ(Sup.Math.toRadians(30 * flip));
75+
break;
76+
77+
case 5:
4578
break;
4679
}
4780
this.timer--;
@@ -50,7 +83,7 @@ class WeaponBehavior extends Sup.Behavior {
5083

5184
attack() {
5285
this.isAttacking = true;
53-
this.timer = 3;
86+
this.timer = 5;
5487
}
5588
}
5689
Sup.registerBehavior(WeaponBehavior);

‎entries.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"nextEntryId": 200,
2+
"nextEntryId": 201,
33
"nodes": [
44
{
55
"id": "178",
@@ -340,6 +340,11 @@
340340
"type": "sprite"
341341
}
342342
]
343+
},
344+
{
345+
"id": "200",
346+
"name": "HitBehavior",
347+
"type": "script"
343348
}
344349
]
345350
},

‎resources/behaviorProperties/resource.json

+11
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@
187187
"type": "string"
188188
}
189189
]
190+
},
191+
"HitBehavior": {
192+
"scriptId": "200",
193+
"line": 0,
194+
"parentBehavior": null,
195+
"properties": [
196+
{
197+
"name": "defense",
198+
"type": "number"
199+
}
200+
]
190201
}
191202
}
192203
}

0 commit comments

Comments
 (0)
Please sign in to comment.