class SampleScene : public cocos2d::Scene
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
// implement the "static create()" method manually
CREATE_FUNC(SampleScene);
};
#include "SampleScene.h"
#include "SimpleAudioEngine.h"
USING_NS_CC;
Scene* SampleScene::createScene()
{
return SampleScene::create();
}
// Print useful error message instead of segfaulting when files are not there.
static void problemLoading(const char* filename)
{
printf("Error while loading: %s\n", filename);
printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
}
// on "init" you need to initialize your instance
bool SampleScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Scene::init() )
{
return false;
}
auto visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
// add "HelloWorld" splash screen"
auto sprite = Sprite::create("HelloWorld.png");
if (sprite == nullptr)
{
problemLoading("'HelloWorld.png'");
}
else
{
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
}
return true;
}
void SampleScene::menuCloseCallback(Ref* pSender)
{
//Close the cocos2d-x game scene and quit the application
Director::getInstance()->end();
/*To navigate back to native iOS screen(if present) without quitting the application ,do not use Director::getInstance()->end() as given above,instead trigger a custom event created in RootViewController.mm as below*/
//EventCustom customEndEvent("game_scene_close_event");
//_eventDispatcher->dispatchEvent(&customEndEvent);
}
// create a scene. it's an autorelease object
auto scene = SampleScene::createScene();
// run
director->runWithScene(scene);
return true;
}
auto str = String();
str.appendWithFormat("visible (%f %f)", visibleSize.width, visibleSize.height);
auto label = Label::createWithTTF(str.getCString(), "fonts/msgothic.ttc", 24);
if (label == nullptr)
{
problemLoading("'fonts/msgothic.ttc'");
}
else
{
// position the label on the center of the screen
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, 1);
}
auto str2 = String();
str2.appendWithFormat("origin (%f %f)", origin.x, origin.y);
auto label2 = Label::createWithTTF(str2.getCString(), "fonts/msgothic.ttc", 24);
if (label2 == nullptr)
{
problemLoading("'fonts/msgothic.ttc'");
}
else
{
// position the label on the center of the screen
label2->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height * 2));
// add the label as a child to this layer
this->addChild(label2, 2);
}
class HokkaidoWar
{
public HokkaidoWar()
{
}
public void Run()
{
asd.Engine.Initialize("北海道大戦", 1200, 1000, new asd.EngineOption());
// シーンの登録
var scene = new MainScene();
asd.Engine.ChangeScene(scene);
while (asd.Engine.DoEvents())
{
asd.Engine.Update();
}
asd.Engine.Terminate();
}
}
class MainScene : asd.Scene
{
中略
protected override void OnRegistered()
{
var layer = Singleton.GetMainSceneLayer();
AddLayer(layer);
// 下地
var background = new asd.GeometryObject2D();
layer.AddObject(background);
var bgRect = new asd.RectangleShape();
bgRect.DrawingArea = new asd.RectF(0, 0, 1800, 1000);
background.Shape = bgRect;
cities = new List<City>();
var r = new Random();
foreach (var map in mapData.list)
{
City city = new City(map.name, map.point, map.population);
cities.Add(city);
}
_battle = new Battle(cities);
aliveCities = _battle.GetAliveCityList();
}
protected override void OnUpdated()
{
asd.Vector2DF pos = asd.Engine.Mouse.Position;
switch (gameStatus)
{
case GameStatus.SelectCity:
cycleProcessSelectCity(pos);
break;
case GameStatus.ActionEnemy:
cycleProcessActionEnemy(pos);
break;
case GameStatus.ActionPlayer:
cycleProcessActionPlayer(pos);
break;
case GameStatus.ShowResult:
break;
case GameStatus.GameEnd:
cycleProcessGameEnd();
break;
case GameStatus.GameOver:
cycleProcessGameOver(pos);
break;
}
if (asd.Engine.Mouse.LeftButton.ButtonState == asd.ButtonState.Push)
{
switch (gameStatus)
{
case GameStatus.SelectCity:
onClickMouseSelectCity(pos);
break;
case GameStatus.ActionEnemy:
break;
case GameStatus.ActionPlayer:
onClickMouseActionPlayer(pos);
break;
case GameStatus.ShowResult:
onClickMouseShowResult();
break;
case GameStatus.GameEnd:
break;
case GameStatus.GameOver:
break;
}
}
}
後略