Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mitsuhiko/reddit-game-jam
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Mar 27, 2011
2 parents fdc6718 + ca58397 commit bbb61f1
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/pd/entity.hpp
Expand Up @@ -50,6 +50,8 @@ namespace pd {
bool flipped() const { return m_flipped; }
void flipped(bool val) { m_flipped = val; }
bool airborne() const;
bool colliding_right() const;
bool colliding_left() const;
pd::vec2 linear_velocity() const;

float health() const { return m_health; }
Expand Down
2 changes: 2 additions & 0 deletions include/pd/kinetic_enemy.hpp
Expand Up @@ -19,6 +19,8 @@ namespace pd {
stance_type m_stance;
pd::animation m_walk_anim;
pd::texture *m_dash_texture;
bool m_dashing;
int m_walking_direction;
};
}

Expand Down
Binary file modified resources/maps/testlevel.map
Binary file not shown.
29 changes: 29 additions & 0 deletions src/entity.cpp
Expand Up @@ -72,6 +72,35 @@ bool pd::entity::airborne() const
return true;
}

bool pd::entity::colliding_right() const
{
for (b2ContactEdge* ce = m_body->GetContactList(); ce; ce = ce->next) {
if (!ce->contact->IsTouching())
continue;
b2WorldManifold worldManifold;
ce->contact->GetWorldManifold(&worldManifold);
if (worldManifold.normal.x < 0.0f)
return true;
}
return false;
}


bool pd::entity::colliding_left() const
{
for (b2ContactEdge* ce = m_body->GetContactList(); ce; ce = ce->next) {
if (!ce->contact->IsTouching())
continue;
b2WorldManifold worldManifold;
ce->contact->GetWorldManifold(&worldManifold);
if (worldManifold.normal.x > 0.0f)
return true;
}
return false;

}


pd::vec2 pd::entity::linear_velocity() const
{
return m_body->GetLinearVelocity();
Expand Down
4 changes: 2 additions & 2 deletions src/game_session.cpp
Expand Up @@ -64,8 +64,8 @@ pd::game_session::game_session()
m_map = new pd::map(this, "maps/testlevel.map");

m_player = new pd::player(this, 400.0f, 200.0f);
new pd::thermal_enemy(this, 240.0f, 0.0f);
new pd::kinetic_enemy(this, 100.0f, 0.0f);
//new pd::thermal_enemy(this, 240.0f, 0.0f);
new pd::kinetic_enemy(this, 15.0f, 0.0f);
}

pd::game_session::~game_session()
Expand Down
25 changes: 24 additions & 1 deletion src/kinetic_enemy.cpp
@@ -1,18 +1,41 @@
#include <pd/kinetic_enemy.hpp>
#include <pd/game.hpp>
#include <pd/texture.hpp>

#include <pd/drawtools.hpp>

pd::kinetic_enemy::kinetic_enemy(pd::game_session *session, float x, float y)
: pd::enemy(session, x, y, 50.0f, 90.0f, 0.0f, thermal_stance),
m_walk_anim(pd::get_resource<pd::texture>("textures/enemy_kinetic_walk.png"), 19, 0.035f)
{
m_dash_texture = pd::get_resource<pd::texture>("textures/enemy_kinetic_dash.png");
m_walking_direction = -1;
m_dashing = false;
}

void pd::kinetic_enemy::update(float dt)
{
m_walk_anim.update(dt);

// More clever than Skynet!
if (body()->GetLinearVelocity().x < 0.01f && body()->GetLinearVelocity().x > - 0.01f) {
m_walking_direction *= -1;
m_dashing = 0;
apply_impulse(600.0f * m_walking_direction, 0.0f);
}


/* else {
apply_force(700.0f * m_walking_direction, 0.0f);
if (((x() - player()->x()) * (x() - player()->x()) < (float)(500 ^ 2)) && !m_dashing) {
apply_impulse(3000.0f * m_walking_direction, 0);
printf("Impulse!/n");
m_dashing = 1;
}
}
*/
apply_force(1000.0f * m_walking_direction, 0.0f);

flipped(linear_velocity().x < 0.0f);
}

void pd::kinetic_enemy::local_render(float dt) const
Expand Down

0 comments on commit bbb61f1

Please sign in to comment.