Skip to content

Commit

Permalink
爆弾投擲研究会を設立
Browse files Browse the repository at this point in the history
  • Loading branch information
jnc-explosion committed Jan 29, 2024
1 parent 568828d commit a34559e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
Binary file added assets/gather.mp3
Binary file not shown.
1 change: 0 additions & 1 deletion src/engine/components/RigidBody.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class RigidBody: Component {
layer["Hero"]["Enemy"] = true;
layer["Enemy"]["Enemy"] = true;
layer["Enemy"]["Bomb"] = true;
layer["Hero"]["Bomb"] = true;
layer["Bomb"]["Bomb"] = true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/game/GameManager.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ struct Status{
bool isDamaged = false;
bool willDead = false;
bool dead = false;

GameObject[] haveObj;
}

struct Persist {
Expand Down
39 changes: 31 additions & 8 deletions src/game/entities/Bomb.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@ import game;
import engine;

class Bomb : GameObject {
enum Affi {
Enemy,
Hero,
}

SpriteRenderer rend;
Transform tform;
RigidBody rigid;
string imgdir() => "bomb.png";
AudioSource se;
Affi af;

bool isExplosion = false;

this() {
this(Affi af = Affi.Enemy) {
auto bokan = new AudioAsset("dogaan.mp3");
se = register(new AudioSource(bokan));
se.volume(20);
se.volume(60);
addTag("Bomb");
// 僕はHikakin 死亡
tform = register(new Transform(tform.Org.Spawn));
tform.scale = Vec2(0.2, 0.2);
this.af = af;
}

override void setup() {
Expand All @@ -37,13 +44,19 @@ class Bomb : GameObject {
}

override void collide(GameObject go) {
if(go.getTag("Missile")) explosion;
if(go.getTag("Missile") || af == Affi.Hero) explosion(go);
else if(go.getTag("Hero")) {
auto aa = new AudioAsset("gather.mp3");
se.set(aa);
se.volume(100);
se.play(0);
gm.heroStatus.haveObj ~= new Bomb(Affi.Hero);
bye;
}
}

void explosion() {
void explosion(GameObject go) {
if(!isExplosion) {
//se.play(1);
register(new Explosion);
component!BoxCollider.isTrigger = true;

// damage function
Expand All @@ -52,11 +65,21 @@ class Bomb : GameObject {
auto ptf = gm.hero.component!Transform;
Vec2 r = ptf.pos - tform.pos;
real len = r.size;
Status* pstat = gm.heroStatus();
if(!pstat.star)pstat.life -= cast(int)dmgf(len);
Status* stat;
if(af == Affi.Enemy) {
stat = gm.heroStatus();
} else {
if(go.getTag("Hero")) return;
auto keys = go in gm.status;
if(keys !is null) stat = gm.status[go];
else return;
}
if(!stat.star) stat.life -= cast(int)dmgf(len);
rigid.addForce(r * dmgf(len));
dbg("damaged! :", dmgf(len));

se.play(1);
register(new Explosion);
isExplosion = true;
}
} // 爆発は芸術なのかもしれませんね
Expand Down
10 changes: 9 additions & 1 deletion src/game/entities/Hero.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Hero: GameObject {

Timer rndtmr;
Timer dashtmr;
Timer bombdtmr;
bool isDash;
Kalashnikov ak;

Expand Down Expand Up @@ -57,6 +58,7 @@ class Hero: GameObject {

rndtmr = new Timer;
dashtmr = new Timer;
bombdtmr = new Timer;
}

override void loop() {
Expand Down Expand Up @@ -88,7 +90,13 @@ class Hero: GameObject {
dust.component!Transform.initPos = Vec2(0, rend.size.x);
dashtmr.reset;
}
}else{
} else if(im.key('t') && gm.heroStatus.haveObj !is null && gm.heroStatus.haveObj.length != 0 && bombdtmr.cur >= 2_000) {
auto bm = register(gm.heroStatus.haveObj[$-1]);
gm.heroStatus.haveObj.popBack;
bm.component!RigidBody.addForce(Vec2(300, 450) * dir);
bm.component!Transform.initPos = Vec2(80, 0) * dir;
bombdtmr.reset;
} else {
rb.v.x = 0;
rb.v.x = 0;
isDash = false;
Expand Down

0 comments on commit a34559e

Please sign in to comment.