File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ type Health = {
2+ 0 : i32 ;
3+ } ;
4+ const Health : BevyType < Health > = { typeName : "punchy::damage::Health" } ;
5+ type Stats = {
6+ max_health : i32 ;
7+ movement_speed : f32 ;
8+ } ;
9+ const Stats : BevyType < Stats > = { typeName : "punchy::fighter::Stats" } ;
10+
11+ export default {
12+ postUpdate ( ) {
13+ // The `getItemGrabEvents()` method will return all events where a fighter grabbed the item that
14+ // this script is associated with.
15+ const grabEvents = punchy . getItemGrabEvents ( ) ;
16+
17+ const fighterQuery = world . query ( Health , Stats ) ;
18+ for ( const event of grabEvents ) {
19+ const fighter = event . fighter ;
20+
21+ const [ health , stats ] = fighterQuery . get ( fighter ) ;
22+
23+ if ( ( health [ 0 ] + stats . max_health * 0.5 ) > stats . max_health ) {
24+ health [ 0 ] = stats . max_health
25+ }
26+ else {
27+ health [ 0 ] += stats . max_health * 0.5 ;
28+ }
29+ }
30+ } ,
31+ }
Original file line number Diff line number Diff line change 1+ name : Fishfood
2+
3+ image :
4+ image : fishfood.png
5+ image_size : [20, 30]
6+
7+ kind : !Script
8+ script : ./50percent.ts
Original file line number Diff line number Diff line change 1+ type Health = {
2+ 0 : i32 ;
3+ } ;
4+ const Health : BevyType < Health > = { typeName : "punchy::damage::Health" } ;
5+ type Stats = {
6+ max_health : i32 ;
7+ movement_speed : f32 ;
8+ } ;
9+ const Stats : BevyType < Stats > = { typeName : "punchy::fighter::Stats" } ;
10+
11+ export default {
12+ postUpdate ( ) {
13+ // The `getItemGrabEvents()` method will return all events where a fighter grabbed the item that
14+ // this script is associated with.
15+ const grabEvents = punchy . getItemGrabEvents ( ) ;
16+
17+ const fighterQuery = world . query ( Health , Stats ) ;
18+ for ( const event of grabEvents ) {
19+ const fighter = event . fighter ;
20+
21+ const [ health , stats ] = fighterQuery . get ( fighter ) ;
22+
23+ if ( ( health [ 0 ] + stats . max_health * 0.25 ) > stats . max_health ) {
24+ health [ 0 ] = stats . max_health
25+ }
26+ else {
27+ health [ 0 ] += stats . max_health * 0.25 ;
28+ }
29+ }
30+ } ,
31+ }
Original file line number Diff line number Diff line change 1+ name : Pellets
2+
3+ image :
4+ image : pellets.png
5+ image_size : [30, 20]
6+
7+ kind : !Script
8+ script : ./25percent.ts
Original file line number Diff line number Diff line change 1+ name : Poison
2+
3+ image :
4+ image : poison.png
5+ image_size : [22, 20]
6+
7+ kind : !Script
8+ script : ./poison.ts
Original file line number Diff line number Diff line change 1+ type Health = {
2+ 0 : i32 ;
3+ } ;
4+ const Health : BevyType < Health > = { typeName : "punchy::damage::Health" } ;
5+ type Stats = {
6+ max_health : i32 ;
7+ movement_speed : f32 ;
8+ } ;
9+ const Stats : BevyType < Stats > = { typeName : "punchy::fighter::Stats" } ;
10+
11+ export default {
12+ postUpdate ( ) {
13+ // The `getItemGrabEvents()` method will return all events where a fighter grabbed the item that
14+ // this script is associated with.
15+ const grabEvents = punchy . getItemGrabEvents ( ) ;
16+
17+ const fighterQuery = world . query ( Health , Stats ) ;
18+ for ( const event of grabEvents ) {
19+ const fighter = event . fighter ;
20+
21+ const [ health , stats ] = fighterQuery . get ( fighter ) ;
22+
23+ health [ 0 ] -= health [ 0 ] ;
24+ }
25+ } ,
26+ }
Original file line number Diff line number Diff line change @@ -91,6 +91,12 @@ items:
9191 location : [50, -70, 0]
9292 - item : &bottle /items/bottle/bottle.item.yaml
9393 location : [100, -20, 0]
94+ - item : &fishfood /items/fishfood/fishfood.item.yaml
95+ location : [100, -70, 0]
96+ - item : &pellets /items/pellets/pellets.item.yaml
97+ location : [200, -70, 0]
98+ - item : &poison /items/poison/poison.item.yaml
99+ location : [100, -50, 0]
94100 - item : &sword /items/sword/sword.item.yaml
95101 location : [-100, -20, 0]
96102 - item : &box /items/box/box.item.yaml
You can’t perform that action at this time.
0 commit comments