Ejemplo n.º 1
0
int main(int argc, char **argv)
{	
	sound = new SoundEngine();

    // Check if input file was given, if not use default
    if(argc > 1){
        fileIO->processFile(argv[1]);
        // Make sure that file was correctly read and parsed
        if(fileIO->getNumHoles() <= 0){
            cout << "Error reading file. Using default instead." << endl;
			fileIO->processFile(DEFAULT_COURSE);
        }
    }
    else{
        cout << "No input file was provided." << endl;
        // Create default level since no file was specified
        fileIO->processFile(DEFAULT_COURSE);
    }

	// Load level
	levelController->loadFirstLevel(fileIO);

	// Add Player
	addNewPlayer(0);

    // Move arrow to ball's starting position
    arrow->translate(levelController->getCurrentLevel()->getBall()->getPhysics()->getPosition());
    arrow->translate(glm::vec3(0.0, BALL_OFFSET, 0.0));

    // Add shapes to game level
    shapes.clear();
    shapes = levelController->getCurrentLevel()->getLevelShapes();
    reloadAllShapes(&verts, &color, &norms, shapes);

	initializeGraphics(argc, argv, "MiniGolf", 1280, 720);  

    glutMainLoop();

	// Clean-up -- NEED TO ADD THE REST OF THIS
    if(shader) delete shader;
    if(levelController) delete levelController;
    if(fileIO) delete fileIO;
    if(arrow) delete arrow;
	if(sound) delete sound;

	return 0;
}
Ejemplo n.º 2
0
void TiledMap::loadEntityLayer(const Tmx::ObjectGroup *objectGroup)
{
	for(int i = 0; i < objectGroup->GetNumObjects(); ++i)
	{
		const Tmx::Object* object = objectGroup->GetObject(i);
		if(object->GetType() == "Enemy")
		{
			new Enemy(object->GetName(), osg::Vec3(object->GetX() / tileWidth, - object->GetY() / tileHeight, 0));
		}
		else if(object->GetType() == "Player")
		{
			addNewPlayer(object->GetName(), osg::Vec3(object->GetX() / tileWidth, - object->GetY() / tileHeight, 0));
			setActivePlayer(object->GetName());
		}
		else
		{
			std::ostringstream stream;
			stream << "Unable to determine function of object type \"" << object->GetType() << "\" in entity layer.";
			logWarning(stream.str());
		}
	}
}
Ejemplo n.º 3
0
void GameServer::update()
{
	m_gsThread->lock();
	//std::cout << "Update!" <<std::endl;
	// process new connections
	for( auto connected = m_newConnections.begin(); connected != m_newConnections.end();  )
	{
		(*connected)->m_lastRecv -= 1;
		if((*connected)->m_lastRecv <= 0)
		{
			Packet ninjaInfo;
			new (ninjaInfo.m_buffer) NinjaInfoCardMessage((*connected)->m_netID);
			ninjaInfo.m_length = sizeof(NinjaInfoCardMessage);
			for(int i = 0; i < m_PRIs.size(); ++i)
			{
				if(m_PRIs[i].m_netid == (*connected)->m_netID)
				{
					m_PRIs[i] = m_PRIs[m_PRIs.size()-1];
					m_PRIs.pop_back();
				}
			}
			//printf("Kill this connection\n");
			connected = m_newConnections.erase(connected);

			for( auto client = m_newConnections.begin(); client != m_newConnections.end(); ++client)
				if( client != connected )
					(*client)->send(ninjaInfo);
			continue;
		}

		Packet received;
		if( !(*connected)->pop_receivePacket(received) )
		{
			++connected;
			continue;
		}

		(*connected)->m_lastRecv = 500;
		BaseNetMessage * msg = reinterpret_cast<BaseNetMessage*>(received.m_buffer);

		if( msg->type() == PLAYER_REPLICATION_INFO )
		{
			int i = WSAGetLastError();
			auto pri = msg->as<PlayerReplicationInfoNetMessage>()->playerInfo();
			if( !updatePlayerReplicationInfo(pri) )
			{
				(*connected)->m_netID = m_nextNetID;
				i = WSAGetLastError();
				addNewPlayer(*connected, pri);
			}
										
			// new players update the player count
			m_info.currentPlayers = m_PRIs.size();
		}

		else if( msg->type() == OBJECT )
		{
			m_objectMsgs.push_back(*msg->as<ObjectNetMessage>());
			for( auto client = m_newConnections.begin(); client != m_newConnections.end(); ++client)
				if( client != connected )
					(*client)->send(received);
		}
		else if( msg->type() == NINJA_INFO )
		{
			m_ninjaMsgs.push_back(*msg->as<NinjaInfoCardMessage>());
			for( auto client = m_newConnections.begin(); client != m_newConnections.end(); ++client)
				if( client != connected )
					(*client)->send(received);
		}

		++connected;
	}


	m_gsThread->unlock();
}
Ejemplo n.º 4
0
bool GameScene::init(){
	if (!Layer::init())
	{
		return false;
	}


	//游戏数据初始化
	card_num = 0;
	debt_num = 0;



	//先添加桌面背景,在最下面
	auto * table = Sprite::create("table.png");
	this->addChild(table);
	auto screenSize = Director::getInstance()->getWinSize();//获取屏幕尺寸  
	table->setPosition(screenSize.width/2,screenSize.height/2-30);
	table->setScale(1.1);//设置缩放级别
	
	//add buttons
	//按钮上的文字后期用ps来制作

	auto giveUpMenuItem = MenuItemImage::create(
		"button01.png",
		"button02.png", CC_CALLBACK_1(GameScene::button_giveUp, this));
	giveUpMenuItem->setPosition(Point(60, 40));

	auto genZhuMenuItem = MenuItemImage::create(
		"button01.png",
		"button02.png", CC_CALLBACK_1(GameScene::button_xiaZhu, this));
	genZhuMenuItem->setPosition(Point(190, 40));

	auto yiLvMenuItem = MenuItemImage::create(
		"button01.png",
		"button02.png", CC_CALLBACK_1(GameScene::button_jiaZhu, this));
	yiLvMenuItem->setPosition(Point(320, 40));

	auto starMenu = Menu::create(giveUpMenuItem, genZhuMenuItem,yiLvMenuItem,NULL);
	starMenu->setPosition(Point::ZERO);
	
	this->addChild(starMenu, 1);

	//按钮上添加文字(暂时的功能,后期完善可以删掉)
	auto button_label01 = Label::createWithSystemFont("giveUp", "Arial", 17);
	button_label01->setPosition(Point(60, 40));
	this->addChild(button_label01,2);
	//按钮上添加文字(暂时的功能,后期完善可以删掉)
	auto button_label02 = Label::createWithSystemFont("xiaZhu", "Arial", 17);
	button_label02->setPosition(Point(190, 40));
	this->addChild(button_label02,2);
	//按钮上添加文字(暂时的功能,后期完善可以删掉)
	auto button_label03 = Label::createWithSystemFont("jiaZhu", "Arial", 17);
	button_label03->setPosition(Point(320, 40));
	this->addChild(button_label03,2);




	// your codes here 
	
	/*

	char str[] = "poker_pic/13.png";
	auto test_card = Sprite::create(str);
	this->addChild(test_card);
	test_card->setPosition(screenSize.width / 2, screenSize.height -400);
	test_card->setScale(0.6);

	auto my_testCard = Card::create("roomgirl.png");  // auto == Card
	my_testCard->setPosition(screenSize.width / 2, screenSize.height - 200);
	my_testCard->setScale(0.6);
	my_testCard->setCardID(23);
	this->addChild(my_testCard);
	CCLOG("my_testCard->ID = %d .", my_testCard->getCardID());//会得到log:my_testCard->ID = 23 .

	*/

	//test_end

	//显示玩家头像,玩家筹码等信息,荷官的片,
	auto roomgirl = Sprite::create("roomgirl.png");
	this->addChild(roomgirl);
	roomgirl->setPosition(screenSize.width/2, screenSize.height-70);
	roomgirl->setScale(1);

	
	player_num = 2;//设置为2名玩家

	//添加游戏玩家(other players)
	auto player01 = addNewPlayer("player01", 50000);

	int my_total = 50000;
	char *my_name = "player_me";
	//添加自己的游戏数据========
	player_me = Player::create("default_player.png");//创建纹理,并且显示在屏幕的正下方
	player_me->setPhoto("default_player.png");
	player_me->setPosition(screenSize.width/2,170);
	player_me->setDebt(0); //set to 0
	player_me->setTotal(my_total);
	player_me->setOnTable(true);
	this->addChild(player_me);
	player01->setPlayerName(my_name);
	player01->setTotal(my_total);

	//show player name
	auto player_me_name = Label::createWithSystemFont(my_name, "Arial", 17);
	player_me_name->setPosition(screenSize.width/2, 215);
	this->addChild(player_me_name);

	//show player total money
	char tmp[9];
	sprintf(tmp, "%d",my_total);
	auto player_me_total = Label::createWithSystemFont(tmp, "Arial", 17);
	player_me_total->setPosition(screenSize.width/2,120);
	this->addChild(player_me_total);


	

	//下底注(后期可以用ps来制作一张图来支持中文)
	//show tips
	auto tips = Sprite::create("show_tips.png");
	tips->setScale(0.3);
	tips->setPosition(screenSize.width / 2, screenSize.height / 2);
	tips->setOpacity(200);
	this->addChild(tips, 0, 100);// set tag 100
	auto tips_label = Label::createWithSystemFont("XiaDiZhu", "SimSun", 30);
	tips_label->setPosition(screenSize.width / 2, screenSize.height / 2);
	tips_label->setColor(ccc3(0, 0, 0));//color black
	this->addChild(tips_label, 0, 101);// set tag 101
	this->scheduleOnce(schedule_selector(GameScene::showTips), 1);//调用回调函数来删掉刚刚创建的tips 
	
	
	player01->addDebt(DIZHU);
	player_me->addDebt(DIZHU);

	debt_num = DIZHU * 2;
	//CCLOG为调试信息
	CCLOG("player01.debt = %d ,total = %d", player01->getDebt(), player01->getTotal());
	CCLOG("player_me.debt = %d ,total = %d", player_me->getDebt(), player_me->getTotal());


	//发底牌(2张底牌)保证不相同
	srand((unsigned)time(NULL)); //初始化随机数种子

	int t1 = getOneNumber();//两名玩家共4张底牌
	int t2 = getOneNumber();
	int t3 = getOneNumber();
	int t4 = getOneNumber();
	CCLOG("DIPAI  == %d %d %d %d",t1,t2,t3,t4);
	player01->setCards(t1,t2);
	player_me->setCards(t3,t4);

	//CCLOG("PLAYER01 c1 = %d, c2 = %d ,PLAYER_ME  c3 = %d, c4 =%d ", player01->getCard01(), player01->getCard02(), player_me->getCard01(), player_me->getCard02());


	//显示玩家得到的底牌(可以添加动画效果)
	char poker_file_name[20]="poker_pic/";
	char temp[9];
	sprintf(temp, "%d", player_me->getCard01());
	strcat(poker_file_name,temp);
	strcat(poker_file_name, ".png");
	//CCLOG("poker_file_name 1 = %s", poker_file_name);
	auto dipai01 = Card::create(poker_file_name);
	dipai01->setRotation(-13);//旋转角度 
	dipai01->setScale(0.5);
	dipai01->setPosition(320, 165);
	this->addChild(dipai01);

	//重新创建一个变量
	char poker_file_name2[20] = "poker_pic/";
	sprintf(temp, "%d", player_me->getCard02());
	strcat(poker_file_name2, temp);
	strcat(poker_file_name2, ".png");
	//CCLOG("poker_file_name 2 = %s", poker_file_name2);
	auto dipai02 = Card::create(poker_file_name2);
	dipai02->setRotation(9);//旋转角度 
	dipai02->setScale(0.5);
	dipai02->setPosition(340, 165);
	this->addChild(dipai02);

	//添加背面的牌:
	auto hand_card_R = Sprite::create("hand_card_back.png");
	hand_card_R->setScale(0.6);
	hand_card_R->setPosition(22, 470);
	this->addChild(hand_card_R);

	//刚发过底牌,设置一个标签,来定义玩到了什么进度
	game_round = 1;//刚发过底牌,设置为1
	
	//若不弃牌,则下注,下注之后可选加注


	//庄家下注,玩家跟注?加注?

	//发第一张公共牌

	//发第二张公共牌

	//...

	//...直到发最后一张公共牌,是否加注?判断游戏输赢
	
	//以上内容写在了按钮中,通过读取变量值来知道是第几个回合

	return true;//init函数执行成功,返回真
}