Skip to content

Commit 40c5149

Browse files
bors[bot]loportolodecay
authored
Merge #285
285: New Items Added r=odecay a=loportol Related to [#27](#27) This creates three new items: poison, and two alternative health items, fish food and pellets. Item description: Poison - Interactable Item that drains a player's health to zero Fish food - Intractable item that provides 50 percent of the maximum health back, caps at maximum health Pellets - Intractable item that provides 25 percent of the maximum health back, caps at maximum health All pngs were created by me and are meant to just be sample fill ins. Co-authored-by: loportok <loportok@umich.edu> Co-authored-by: odecay <electricbuck@gmail.com> Co-authored-by: otis <electricbuck@gmail.com>
2 parents 4534eb8 + 1b9eff8 commit 40c5149

10 files changed

Lines changed: 118 additions & 0 deletions

File tree

assets/items/fishfood/50percent.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Fishfood
2+
3+
image:
4+
image: fishfood.png
5+
image_size: [20, 30]
6+
7+
kind: !Script
8+
script: ./50percent.ts

assets/items/fishfood/fishfood.png

1.54 KB
Loading

assets/items/pellets/25percent.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Pellets
2+
3+
image:
4+
image: pellets.png
5+
image_size: [30, 20]
6+
7+
kind: !Script
8+
script: ./25percent.ts

assets/items/pellets/pellets.png

1.88 KB
Loading
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Poison
2+
3+
image:
4+
image: poison.png
5+
image_size: [22, 20]
6+
7+
kind: !Script
8+
script: ./poison.ts

assets/items/poison/poison.png

1.33 KB
Loading

assets/items/poison/poison.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

assets/levels/1_beach/beach.level.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)