Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126330
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/media/rat.png b/media/rat.png
index 03eca9b..57b88a7 100644
Binary files a/media/rat.png and b/media/rat.png differ
diff --git a/src/GreenRatEntity.cpp b/src/GreenRatEntity.cpp
index 5be9197..76292a6 100644
--- a/src/GreenRatEntity.cpp
+++ b/src/GreenRatEntity.cpp
@@ -1,99 +1,120 @@
#include "GreenRatEntity.h"
#include "BoltEntity.h"
#include "PlayerEntity.h"
#include "sfml_game/SpriteEntity.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SoundManager.h"
#include "Constants.h"
#include "WitchBlastGame.h"
GreenRatEntity::GreenRatEntity(float x, float y)
: EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_RAT), x, y)
{
imagesProLine = 4;
creatureSpeed = GREEN_RAT_SPEED;
velocity = Vector2D(creatureSpeed);
+ computeFacingDirection();
hp = GREEN_RAT_HP;
meleeDamages = GREEN_RAT_DAMAGES;
type = ENTITY_ENNEMY_INVOCATED;
bloodColor = bloodRed;
- shadowFrame = 3;
+ shadowFrame = 6;
timer = (rand() % 50) / 10.0f;
age = -GREEN_RAT_FADE;
frame = 4;
}
void GreenRatEntity::animate(float delay)
{
z = y + boundingBox.top + boundingBox.height;
if (age > 0.0f)
{
sprite.setColor(sf::Color(255,255,255,255));
- frame = 4 + ((int)(age * 5.0f)) % 2;
- timer = timer - delay;
- if (timer <= 0.0f)
- {
- timer = (rand() % 50) / 10.0f;
- float tan = (game().getPlayer()->getX() - x) / (game().getPlayer()->getY() - y);
- float angle = atan(tan);
-
- if (game().getPlayer()->getY() > y)
- setVelocity(Vector2D(sin(angle) * RAT_SPEED,
- cos(angle) * RAT_SPEED));
- else
- setVelocity(Vector2D(-sin(angle) * RAT_SPEED,
- -cos(angle) * RAT_SPEED));
- }
+
+ timer = timer - delay;
+ if (timer <= 0.0f)
+ {
+ timer = (rand() % 50) / 10.0f;
+
+ setVelocity(Vector2D(x, y).vectorTo(game().getPlayerPosition(), GREEN_RAT_SPEED ));
+ computeFacingDirection();
+ }
+
+ frame = 4 + ((int)(age * 5.0f)) % 2;
+ if (facingDirection == 4 || facingDirection == 6) frame += 2;
+ isMirroring = (facingDirection == 4 );
+ if (facingDirection == 8) frame += 0; // TODO
}
else
{
sprite.setColor(sf::Color(255,255,255,255 * (1.0 + age)));
}
EnnemyEntity::animate(delay);
}
void GreenRatEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2 + RAT_BB_LEFT;
boundingBox.width = width - RAT_BB_WIDTH_DIFF;
boundingBox.top = (int)y - height / 2 + RAT_BB_TOP;
boundingBox.height = height - RAT_BB_HEIGHT_DIFF;
}
void GreenRatEntity::collideMapRight()
{
velocity.x = -velocity.x;
+ if (recoil.active) recoil.velocity.x = -recoil.velocity.x;
+ computeFacingDirection();
}
void GreenRatEntity::collideMapLeft()
{
velocity.x = -velocity.x;
+ if (recoil.active) recoil.velocity.x = -recoil.velocity.x;
+ computeFacingDirection();
}
void GreenRatEntity::collideMapTop()
{
velocity.y = -velocity.y;
+ if (recoil.active) recoil.velocity.y = -recoil.velocity.y;
+ computeFacingDirection();
}
void GreenRatEntity::collideMapBottom()
{
velocity.y = -velocity.y;
+ if (recoil.active) recoil.velocity.y = -recoil.velocity.y;
+ computeFacingDirection();
}
+void GreenRatEntity::collideWithEnnemy(GameEntity* collidingEntity)
+{
+ if (recoil.active && recoil.stun) return;
+
+ EnnemyEntity* entity = static_cast<EnnemyEntity*>(collidingEntity);
+ if (entity->getMovingStyle() == movWalking )
+ {
+ Vector2D vel = Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), 100.0f );
+ giveRecoil(false, vel, 0.3f);
+
+ computeFacingDirection();
+ }
+}
void GreenRatEntity::dying()
{
isDying = true;
SpriteEntity* deadRat = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_CORPSES), x, y, 64, 64);
deadRat->setZ(OFFSET_Y);
deadRat->setFrame(FRAME_CORPSE_GREEN_RAT);
deadRat->setType(ENTITY_CORPSE);
for (int i = 0; i < 4; i++) game().generateBlood(x, y, bloodColor);
- //drop();
+
SoundManager::getSoundManager()->playSound(SOUND_ENNEMY_DYING);
}
diff --git a/src/GreenRatEntity.h b/src/GreenRatEntity.h
index 773cd7b..5350bb2 100644
--- a/src/GreenRatEntity.h
+++ b/src/GreenRatEntity.h
@@ -1,24 +1,26 @@
#ifndef GREENRATSPRITE_H
#define GREENRATSPRITE_H
#include "EnnemyEntity.h"
#include "PlayerEntity.h"
class GreenRatEntity : public EnnemyEntity
{
public:
GreenRatEntity(float x, float y);
virtual void animate(float delay);
virtual void calculateBB();
protected:
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
+ virtual void collideWithEnnemy(GameEntity* collidingEntity);
+
virtual void dying();
private:
float timer;
};
#endif // GREENRATSPRITE_H
diff --git a/src/RatEntity.cpp b/src/RatEntity.cpp
index 9596940..61ad16a 100644
--- a/src/RatEntity.cpp
+++ b/src/RatEntity.cpp
@@ -1,75 +1,94 @@
#include "RatEntity.h"
#include "BoltEntity.h"
#include "PlayerEntity.h"
#include "sfml_game/SpriteEntity.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SoundManager.h"
#include "Constants.h"
#include "WitchBlastGame.h"
RatEntity::RatEntity(float x, float y)
: EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_RAT), x, y)
{
creatureSpeed = RAT_SPEED;
velocity = Vector2D(creatureSpeed);
+ computeFacingDirection();
hp = RAT_HP;
meleeDamages = RAT_DAMAGES;
type = ENTITY_ENNEMY;
bloodColor = bloodRed;
- shadowFrame = 3;
+ shadowFrame = 6;
}
void RatEntity::animate(float delay)
{
if (age > 0.0f)
+ {
frame = ((int)(age * 5.0f)) % 2;
+ if (facingDirection == 4 || facingDirection == 6) frame += 2;
+ isMirroring = (facingDirection == 4 );
+ if (facingDirection == 8) frame += 0; // TODO
+ }
EnnemyEntity::animate(delay);
}
void RatEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2 + RAT_BB_LEFT;
boundingBox.width = width - RAT_BB_WIDTH_DIFF;
boundingBox.top = (int)y - height / 2 + RAT_BB_TOP;
boundingBox.height = height - RAT_BB_HEIGHT_DIFF;
}
void RatEntity::collideMapRight()
{
velocity.x = -velocity.x;
if (recoil.active) recoil.velocity.x = -recoil.velocity.x;
+ else computeFacingDirection();
}
void RatEntity::collideMapLeft()
{
velocity.x = -velocity.x;
if (recoil.active) recoil.velocity.x = -recoil.velocity.x;
+ else computeFacingDirection();
}
void RatEntity::collideMapTop()
{
velocity.y = -velocity.y;
if (recoil.active) recoil.velocity.y = -recoil.velocity.y;
+ else computeFacingDirection();
}
void RatEntity::collideMapBottom()
{
velocity.y = -velocity.y;
if (recoil.active) recoil.velocity.y = -recoil.velocity.y;
+ else computeFacingDirection();
}
+void RatEntity::collideWithEnnemy(GameEntity* collidingEntity)
+{
+ EnnemyEntity* entity = static_cast<EnnemyEntity*>(collidingEntity);
+ if (entity->getMovingStyle() == movWalking)
+ {
+ setVelocity(Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), creatureSpeed ));
+ computeFacingDirection();
+ }
+}
void RatEntity::dying()
{
isDying = true;
SpriteEntity* deadRat = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_CORPSES), x, y, 64, 64);
deadRat->setZ(OFFSET_Y);
deadRat->setFrame(FRAME_CORPSE_RAT);
deadRat->setType(ENTITY_CORPSE);
for (int i = 0; i < 4; i++) game().generateBlood(x, y, bloodColor);
drop();
SoundManager::getSoundManager()->playSound(SOUND_ENNEMY_DYING);
}
diff --git a/src/RatEntity.h b/src/RatEntity.h
index 2a316d5..0781fc6 100644
--- a/src/RatEntity.h
+++ b/src/RatEntity.h
@@ -1,23 +1,25 @@
#ifndef RATSPRITE_H
#define RATSPRITE_H
#include "EnnemyEntity.h"
class RatEntity : public EnnemyEntity
{
public:
RatEntity(float x, float y);
virtual void animate(float delay);
virtual void calculateBB();
protected:
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
+ virtual void collideWithEnnemy(GameEntity* collidingEntity);
+
virtual void dying();
private:
};
#endif // RATSPRITE_H
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:18 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68700
Default Alt Text
(8 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline