Skip to content

Commit 15d8eb4

Browse files
committed
monster speed
1 parent 507f8be commit 15d8eb4

File tree

6 files changed

+64
-11
lines changed

6 files changed

+64
-11
lines changed

bin/data/2.tmx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@
170170
0,0,2684354610,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
171171
55,0,2684354610,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
172172
0,0,2684354610,0,0,0,0,0,0,0,0,0,0,0,0,53,0,0,54,0,0,0,0,0,0,0,0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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
181181
50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,0,60,0,0,0,51,51,51,51,51,51,51,51,51,51,51,51,41,41,41,41,41,41,41,41,41,51,51,51,51,51,51,51,51,51,51,51,51,51,0,0,0,0,0,0,0,0,0,0,0,0,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
182182
51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,0,0,0,0,0,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,0,38,38,38,0,0,0,0,0,0,0,0,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

bin/data/mouse.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"hit": [3]
1313
}
1414
},
15-
"hp": 8
15+
"hp": 16,
16+
"speed": 50.0
1617
}
1718

bin/data/snail.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"right": ["hflip",0,1]
1212
}
1313
},
14-
"hp": 4
14+
"hp": 8,
15+
"speed": 10.0
1516
}
1617

src/Game.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ void Game :: preload()
273273
THING, STATIC,
274274
std::bind(&Thing::cb_to_static, _::_1, _::_2)
275275
);
276+
m_pPartitioner->on_collision(
277+
THING, FATAL,
278+
std::bind(&Thing::cb_to_static, _::_1, _::_2)
279+
);
276280
m_pPartitioner->on_collision(
277281
BULLET, STATIC,
278282
std::bind(&Game::cb_bullet_to_static, this, _::_1, _::_2)
@@ -563,10 +567,11 @@ void Game :: logic(Freq::Time t)
563567
player->position().z
564568
));
565569
//player->stick(shot);
566-
shot->velocity(glm::vec3(
570+
shot->rotate(((std::rand() % 10)-5) / 360.0f, glm::vec3(0.0f, 0.0f, 1.0f));
571+
shot->velocity(shot->orient_to_world(glm::vec3(
567572
(player->check_state("left")?-1.0f:1.0f) * 256.0f,
568573
0.0f, 0.0f
569-
));
574+
)));
570575
auto timer = make_shared<Freq::Alarm>(m_pQor->timer()->timeline());
571576
timer->set(Freq::Time::seconds(1.0f));
572577
auto shotptr = shot.get();
@@ -580,7 +585,7 @@ void Game :: logic(Freq::Time t)
580585
Sound::play(m_pCamera.get(), "shoot.wav", m_pResources);
581586

582587
m_ShootTimer.set(Freq::Time::ms(
583-
m_pChar->config()->at<int>("power",0)>1?100:200
588+
m_pChar->config()->at<int>("power",0)>1?50:100
584589
));
585590

586591
// increase box Z width

src/Thing.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,29 @@ void Thing :: init_thing()
7474
vec3(mask->at<double>(2), mask->at<double>(3), 0.5f)
7575
);
7676

77+
m_pLeft = make_shared<Mesh>();
78+
auto lbox = m_Box;
79+
lbox.min().x -= m_Box.size().x;
80+
lbox.max().x -= m_Box.size().x;
81+
lbox.min().y += m_Box.size().y;
82+
lbox.max().y += m_Box.size().y;
83+
m_pLeft->set_box(lbox);
84+
LOG(box().string());
85+
LOG(m_pLeft->box().string());
86+
add(m_pLeft);
87+
88+
m_pRight = make_shared<Mesh>();
89+
auto rbox = m_Box;
90+
rbox.min().x += m_Box.size().x;
91+
rbox.max().x += m_Box.size().x;
92+
rbox.min().y += m_Box.size().y;
93+
rbox.max().y += m_Box.size().y;
94+
m_pRight->set_box(rbox);
95+
add(m_pRight);
96+
7797
m_HP = m_pConfig->at<int>("hp",5);
98+
m_MaxHP = m_pConfig->at<int>("hp",5);
99+
m_Speed = m_pConfig->at<double>("speed",10.0);
78100
//LOGf("hp: %s", m_HP);
79101
m_pSprite = make_shared<Sprite>(
80102
m_pResources->transform(m_Identity+".json"),
@@ -102,7 +124,7 @@ void Thing :: init_thing()
102124
m_pPartitioner->register_object(m_pSprite->mesh(), Game::THING);
103125
//m_Solid = true;
104126

105-
velocity(vec3(-10.0f, 0.0f, 0.0f));
127+
velocity(vec3(-m_Speed, 0.0f, 0.0f));
106128

107129
//on_lazy_tick.connect([t]{
108130
// move(vec3(10.0f * t.s(), 0.0f, 0.0f));
@@ -342,6 +364,9 @@ void Thing :: cb_to_bullet(Node* thing_node, Node* bullet)
342364
thing->gib(bullet);
343365
bullet->safe_detach();
344366
}
367+
thing->m_pSprite->material()->ambient(kit::mix(
368+
Color::red(), Color::white(), thing->hp_fraction()
369+
));
345370
}
346371
}
347372

@@ -362,6 +387,19 @@ void Thing :: logic_self(Freq::Time t)
362387
clear_snapshots();
363388
snapshot();
364389

390+
//if(is_monster()){
391+
// auto cols = m_pPartitioner->get_collisions_for(m_pLeft.get(), STATIC);
392+
// if(cols.empty()){
393+
// //LOG("left fall");
394+
// velocity(abs(velocity()));
395+
// }
396+
// cols = m_pPartitioner->get_collisions_for(m_pRight.get(), STATIC);
397+
// if(cols.empty()){
398+
// //LOG("right fall");
399+
// velocity(-abs(velocity()));
400+
// }
401+
//}
402+
365403
if(not alive())
366404
detach();
367405
}
@@ -381,7 +419,7 @@ void Thing :: gib(Node* bullet)
381419
gib->move(glm::vec3(std::rand() % 32 - 16.0f, std::rand() % 32 - 16.0f, 2.0f));
382420
gib->velocity(glm::vec3(dir, 0.0f) * 100.0f);
383421
gib->acceleration(glm::vec3(0.0f, 500.0f, 0.0f));
384-
gib->scale(std::rand() % 100 / 100.0 * 2.0f);
422+
gib->scale(std::rand() % 100 / 100.0 * 0.5f);
385423
auto life = make_shared<float>(0.25f * (std::rand() % 4));
386424
auto gibptr = gib.get();
387425
gib->on_tick.connect([gibptr, life](Freq::Time t){

src/Thing.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ class Thing:
9999
virtual void logic_self(Freq::Time t) override;
100100

101101
void gib(Node* bullet);
102+
103+
float hp_fraction() { return m_HP * 1.0f / m_MaxHP; }
102104

103105
private:
104106

105107
int m_HP = 1;
108+
int m_MaxHP = 1;
109+
float m_Speed = 0.0f;
106110
bool m_Dying = false;
107111
bool m_Dead = false;
108112
Cache<Resource, std::string>* m_pResources = nullptr;
@@ -120,6 +124,10 @@ class Thing:
120124
unsigned m_ThingID = 0;
121125

122126
boost::signals2::scoped_connection m_ResetCon;
127+
128+
// ground detection for monsters
129+
std::shared_ptr<Mesh> m_pLeft;
130+
std::shared_ptr<Mesh> m_pRight;
123131
};
124132

125133
#endif

0 commit comments

Comments
 (0)