Exemplo n.º 1
0
Arquivo: game.c Projeto: ljg6/MyGame2D
/**
* @brief function that initializes graphics and sets a background color.
*/
void Init_All()
{
	float bgcolor[] = {1,1,1,1};
  Init_Graphics("Game Test",800,600,800,600,bgcolor,0);
  TTF_Init();
  initEntitySystem(100);
  initSpriteSystem(100);
  
}
Exemplo n.º 2
0
bool HelloWorld::init()
{
    if ( !CCLayer::init()){
        return false;
    }

    //init ECS
    initEntitySystem();
    Size size=CCDirector::getInstance()->getVisibleSize();
    LayerColor* colorLayer=LayerColor::create(Color4B(255,255,255,255),size.width,size.height);
    addChild(colorLayer,-1);    
    //船    
	addShip();
	addHelp(Point(_ship->getPositionX()+200,_ship->getPositionY()));
    //addHelp(Point(_ship->getPositionX()-200,_ship->getPositionY()));
    //addHelp(Point(_ship->getPositionX(),_ship->getPositionY()-200));

    
    // 监听鼠标点击
    auto listener=EventListenerTouch::create(Touch::DispatchMode::ONE_BY_ONE);
    listener->setSwallowTouches(true);
    listener->onTouchBegan=CC_CALLBACK_2(HelloWorld::onTouchBegin,this);
    listener->onTouchEnded= CC_CALLBACK_2(HelloWorld::onTouchEnded,this);
    EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, -10);
    
    //监听子弹事件
    auto listener1=EventListenerCustom::create(GunEvent::GUN_EVENT_TYPE, CC_CALLBACK_1(HelloWorld::addbullet,this));
    EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener1, 1);
    
	//显式
	Label* lblTime = Label::createWithTTF("", "fonts/Marker Felt.ttf", 40);
    lblTime->setColor(Color3B::RED);
    addChild(lblTime);
    lblTime->setPosition(Point(size.width-100,size.height-100));
    
    //游戏结束
    Entity* gameOver = _entityManager->createEntity();
    _entityManager->addComponentToEntity(GameOverComponent::create(100,lblTime), gameOver);
    _entityManager->addComponentToEntity(RenderComponent::create(this), gameOver);
    
    scheduleUpdate();
    
    return true;
}