GithubHelp home page GithubHelp logo

thewindshan / cocos2dx_sanguo_heroes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wagulu/cocos2dx_sanguo_heroes

0.0 1.0 0.0 249.16 MB

cocos2dx suanguo SLG game, ECS systems are used in battle.

Shell 0.02% C++ 33.69% C 21.31% Objective-C 0.19% Java 4.94% Lua 38.11% Objective-C++ 0.93% Makefile 0.05% PureBasic 0.76%

cocos2dx_sanguo_heroes's Introduction

Ccocos2dx c++ & lua

Game Video

Play Game Video YouTobe

Battle images

[Promo]

[Promo]

[Promo]

[Promo]

Client

version:cocos2dx 3.6 (c++&lua)

gameplay:c++

ui logic:lua

c/s protcol: protobuf(pbc lua)

design pattern ECS entityx

How to Use

run with mac

install |CocosFramework-v3.6.pkg|click download|

open SanguoClient/frameworks⁩/⁨runtime-src⁩/proj.ios_mac⁩/sanguoGame.xcodeproj by Xcode

Code Path

Example code

cpp

#include "SkillSystem.h"
#include "BattleWorld.h"
#include "AudioManager.h"
#include "AICommonHelper.h"

SkillSystem::~SkillSystem()
{
}

void SkillSystem::configure(entityx::EventManager& events)
{
    events.subscribe<BattleEvent::FireSkill>(*this);
    events.subscribe<BattleEvent::FireNegativeSkill>(*this);
    events.subscribe<BattleEvent::CancelSkill>(*this);
    events.subscribe<BattleEvent::TriggerSkillAction>(*this);
    events.subscribe<BattleEvent::BattlePause>(*this);
    events.subscribe<BattleEvent::BattleResume>(*this);
}

void SkillSystem::receive(const BattleEvent::BattlePause& e)
{
    m_isPausing = true;
}

void SkillSystem::receive(const BattleEvent::BattleResume& e)
{
    m_isPausing = false;
}

void SkillSystem::receive(const BattleEvent::FireSkill& e)
{
    auto entity = _ENTITY_MANAGER.create();
    auto* skillObj = SkillManager::getInstance()->createSkill(e.pSkillData, e.fromId, entity.id());
    entity.assign<BattleComponent::Skill>(skillObj, e.fromId);
    
    _CAMERA_MANAGER.setCameraCauseID(entity.id().id());
}

void SkillSystem::receive(const BattleEvent::FireNegativeSkill& e)
{
    auto entity = _ENTITY_MANAGER.create();
    auto* skillObj = SkillManager::getInstance()->createSkill(e.pSkillData, e.fromId, entity.id());
    entity.assign<BattleComponent::Skill>(skillObj, e.fromId);
}

void SkillSystem::receive(const BattleEvent::CancelSkill& e)
{
    auto identify = e.entity.component<BattleComponent::Identify>();
    
    BattleComponent::Skill::Handle skill;
    for (entityx::Entity entity : _ENTITY_MANAGER.entities_with_components(skill))
    {
        if (LEFT_HERO == identify->id)
        {
            _CAMERA_MANAGER.setCameraUserControlLocked(false);
        }
        
        bool breakSucceed = false;
        if (skill->fromId == identify->id)
        {
            auto* pSkillData = skill->skill->getSkillData();
            if (e.forceCancel)
            {
                breakSucceed = true;
            }
            else if (pSkillData->pConfig->type != BattleConfig::SkillType::NEGATIVE)
            {
                if (pSkillData->canBreak || isDead(e.entity))
                {
                    breakSucceed = true;
                }
            }
        }
        
        if (breakSucceed)
        {
            CCLOG("skill cancelled of hero:%d name:%s", identify->id, skill->skill->getSkillData()->name.c_str());
         
            for (int soundId : skill->m_playingSoundPool)
            {
                AudioManager::getInstance()->stopEffect(soundId);
            }
            skill->m_playingSoundPool.clear();
            
            BattleComponent::Effect::Handle effect;
            for (entityx::Entity entity : _ENTITY_MANAGER.entities_with_components(effect))
            {
                if (effect->fromId == identify->id)
                {
                    entity.destroy();
                }
            }
            
            BattleComponent::Attack::Handle attack;
            for (entityx::Entity entity : _ENTITY_MANAGER.entities_with_components(attack))
            {
                if (attack->attackData.fromId == identify->id)
                {
                    entity.destroy();
                }
            }
            
            entity.destroy();
        }
    }
}

void SkillSystem::receive(const BattleEvent::TriggerSkillAction& e)
{
    if(_ENTITY_MANAGER.valid(e.id))
    {
        auto entity = _ENTITY_MANAGER.get(e.id);
        BattleComponent::Skill::Handle skill = entity.component<BattleComponent::Skill>();
        skill->skill->triggerAction(e.trigger);
    }
}

void SkillSystem::update(entityx::EntityManager &es, entityx::EventManager &events, double dt)
{
    BattleComponent::Skill::Handle skill;

    for (entityx::Entity entity : es.entities_with_components(skill))
    {
        if((!m_isPausing) || entity.has_component<BattleComponent::ActiveEntity>())
        {
            if(skill->skill->shouldRemove())
            {
                entity.destroy();
            }
            else
            {
                skill->elapse += dt;
                skill->skill->update(es, skill->elapse, dt);
            }
        }
    }
}

lua

_REQUIRE("SanGuoLib")

local BattleScene = class("BattleScene", cc.load("mvc").ViewBase)

local model_game = _REQUIRE("model/model_game.lua")
local helper_battle_data = _REQUIRE("model.helper.helper_battle_data")

function BattleScene:onCreate()

    SanGuoAnimationLib.freeAllAdvancedAnimation();
    SanGuoAnimationLib.freeAllAdvancedAnimationAsset();

    local fight = helper_battle_data:prepareJSON()
    local autoQuickBattle = model_game:getAutoQuickBattle();
    local battleLayer = SanGuoLib.createBattle(fight, autoQuickBattle);
    self:addChild(battleLayer)
--    
--    if model_game:getAutoQuickBattle() then
--        battleLayer:setVisible(false)
--    end
--    Timer:runOnce(function()
--        if model_game:getAutoQuickBattle() then
--            self:showDlg("arena/RapidBattleWaiting")
--        end
--    end,0.01)
    
end

function BattleScene:btnBackCallback(sender, eventType)
    if eventType == 2 then
        SWITSCENE("MainScene")
        --        local test = my.MyClass:create()
        --        release_print("lua bind: " .. test:foo(99))
    end
end

function BattleScene:onExit()
    release_print("dddddd")
    --self:removeTexture()
end

return BattleScene

cocos2dx_sanguo_heroes's People

Contributors

fchsg avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.