Skip to content

Commit

Permalink
Merge pull request #125 from Keallar/controllingNanim
Browse files Browse the repository at this point in the history
Added step sound
  • Loading branch information
Keallar committed Dec 19, 2021
2 parents 66dafa9 + 9721068 commit 0a00a6c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
1 change: 0 additions & 1 deletion Classes/MainScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "imgui.h"
#include "IdleBehaviour.h"
#include "Enemy.h"
#include "NoticeBox.h"

USING_NS_CC;

Expand Down
4 changes: 2 additions & 2 deletions Classes/enemies/AgressiveBehaviour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void AgressiveBehaviour::perform(IEnemy* enemy, Vec2 targetPos, float dt) {
if (enemy->getName().substr(0, 5) == "Aboba") {
if (_moveCooldown <= 0) {
_moveCooldown = MOVE_COOLDOWN;
if (enemy->getShootTarget().x > enemy->getPositionX()) {
if (enemy->getShootTarget().x > enemy->getPositionX() && enemy->getScaleX() > 0) {
auto scale = enemy->getScaleX();
enemy->setScaleX(-scale);
}
Expand All @@ -63,7 +63,7 @@ void AgressiveBehaviour::perform(IEnemy* enemy, Vec2 targetPos, float dt) {
enemy->runAction(spawn);
}
_moveCooldown -= dt;
//enemy->hit();
enemy->hit();
}
if (enemy->getName().substr(0, 4) == "Wolf") {
if (_moveCooldown <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/enemies/Enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool Enemy::init(std::string type) {
setShootingPattern(shootingPatternInfo);
}
}
a if (ent.HasMember("components")) {
if (ent.HasMember("components")) {
const rapidjson::Value& compEnt = ent["components"];
if (compEnt.HasMember("textureFile")) {
const rapidjson::Value& fileName = compEnt["textureFile"];
Expand Down
8 changes: 7 additions & 1 deletion Classes/enemies/IEnemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ void IEnemy::createHpLabel() {

void IEnemy::updateHpLabel() {
_hpLabel->setString(std::to_string(_hp));
if (getScaleX() > 0 && _hpLabel->getScaleX() > 0) {
auto hpLabelScaleX = _hpLabel->getScaleX();
_hpLabel->setScaleX(-hpLabelScaleX);
}
}

const cocos2d::Vector<SpriteFrame*> IEnemy::getIdleFrames() const {
Expand All @@ -226,7 +230,9 @@ const cocos2d::Vector<SpriteFrame*> IEnemy::getMoveFrames() const {
}

void IEnemy::setBehaviour(IEnemyBehaviour* behaviour) {
delete _behaviour;
if (!_behaviour) {
delete _behaviour;
}
_behaviour = behaviour;
}

Expand Down
25 changes: 13 additions & 12 deletions Classes/player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ bool Player::init() {
const rapidjson::Value& valueEnt = playerEnt["specifications"];
if (valueEnt.HasMember("hp") && valueEnt.HasMember("mana") && valueEnt.HasMember("speed") && valueEnt.HasMember("jumpSpeed")) {
const rapidjson::Value& hp = valueEnt["hp"];
_hp = hp.GetInt(); // int value obtained
_hp = hp.GetInt();

const rapidjson::Value& mana = valueEnt["mana"];
_mana = mana.GetInt(); // int value obtained
_mana = mana.GetInt();

const rapidjson::Value& speed = valueEnt["speed"];
_speed = speed.GetDouble(); // int value obtained
_speed = speed.GetDouble();

const rapidjson::Value& maxSpeed = valueEnt["maxSpeed"];
_maxSpeed = maxSpeed.GetDouble(); // int value obtained
_maxSpeed = maxSpeed.GetDouble();

const rapidjson::Value& jumpSpeed = valueEnt["jumpSpeed"];
_jumpSpeed = jumpSpeed.GetInt(); // int value obtained
_jumpSpeed = jumpSpeed.GetInt();

const rapidjson::Value& jumpHeight = valueEnt["jumpHeight"];
_jumpHeight = jumpHeight.GetInt(); // int value obtained
_jumpHeight = jumpHeight.GetInt();

}
}
Expand Down Expand Up @@ -118,6 +118,9 @@ bool Player::init() {
//shoot
_bulletCreator = new IdleBulletCreator(playerPhysMask());

//Sound effects
CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("sounds/Step.mp3");

//Animation
//Idle animation
_idleAnimFrames.reserve(8);
Expand Down Expand Up @@ -212,16 +215,14 @@ void Player::restart() {
const rapidjson::Value& valueEnt = playerEnt["specifications"];
if (valueEnt.HasMember("hp") && valueEnt.HasMember("mana")) {
const rapidjson::Value& hp = valueEnt["hp"];
_hp = hp.GetInt(); // int value obtained
_hp = hp.GetInt();

const rapidjson::Value& mana = valueEnt["mana"];
_mana = mana.GetInt(); // int value obtained
_mana = mana.GetInt();
}
}
}
}


}

void Player::meleeInit() {
Expand Down Expand Up @@ -267,7 +268,7 @@ void Player::keyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event*
scaleX *= -1;
setScaleX(scaleX);
}
//_stepSound = CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("sounds/Step.mp3", true);
_stepSound = CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("sounds/Step.mp3");
break;
}
case EventKeyboard::KeyCode::KEY_A:
Expand All @@ -279,7 +280,7 @@ void Player::keyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event*
scaleX *= -1;
setScaleX(scaleX);
}
//_stepSound = CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("sounds/Step.mp3", true);
_stepSound = CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("sounds/Step.mp3");
break;
}
case EventKeyboard::KeyCode::KEY_SPACE:
Expand Down

0 comments on commit 0a00a6c

Please sign in to comment.