Esempio n. 1
0
void LevelEditor::CheckForMaterialAssign()
{
	GameObject * object = mTerrainEditing ? mSelectedLineStrip : mSelectedObject;

	if (!object)
	{
		return;
	}

	if (GetAsyncKeyState('5') < 0)
	{
		Material * material = MaterialManager::Instance()->GetMaterial("grassground");
		GAME_ASSERT(material);

		if (material)
		{
			object->SetMaterial(material);
		}
	}
	else if (GetAsyncKeyState('6') < 0)
	{
		Material * material = MaterialManager::Instance()->GetMaterial("softwood");
		GAME_ASSERT(material);

		if (material)
		{
			object->SetMaterial(material);
		}
	}
	else if (GetAsyncKeyState('7') < 0)
	{
		Material * material = MaterialManager::Instance()->GetMaterial("caverock");
		GAME_ASSERT(material);

		if (material)
		{
			object->SetMaterial(material);
		}
	}
	else if (GetAsyncKeyState('8') < 0)
	{
		Material * material = MaterialManager::Instance()->GetMaterial("metal");
		GAME_ASSERT(material);

		if (material)
		{
			object->SetMaterial(material);
		}
	}
	else if (GetAsyncKeyState('9') < 0)
	{
		Material * material = MaterialManager::Instance()->GetMaterial("ethereal_walkway");
		GAME_ASSERT(material);

		if (material)
		{
			object->SetMaterial(material);
		}
	}
}
Esempio n. 2
0
void LevelEditor::CheckForSolidLineSetDropDown()
{
	GAME_ASSERT(mTerrainEditing);

	if (!mTerrainEditing)
	{
		return;
	}

	if (!mSelectedLineStrip)
	{
		return;
	}

	static bool pressingDown = false;

	if (!pressingDown && GetAsyncKeyState(VK_DOWN) < 0)
	{
		pressingDown = true;

		if (mSelectedLineStrip->GetCanDropDown())
		{
			mSelectedLineStrip->SetCanDropDown(false);
		}
		else
		{
			mSelectedLineStrip->SetCanDropDown(true);
		}
	}

	if (GetAsyncKeyState(VK_DOWN) >= 0)
	{
		pressingDown = false;
	}
}
Esempio n. 3
0
void LevelEditor::CheckForTerrainNewPoint()
{
	static bool pressingNewPoint = false;

	if (mSelectedLineStrip && mSelectedLinePointIndex > -1)
	{
		if (!pressingNewPoint && GetAsyncKeyState('P') < 0)
		{
			pressingNewPoint = true;

			SolidLineStrip::SolidLinePoint newPoint;

			std::vector<SolidLineStrip::SolidLinePoint> points = mSelectedLineStrip->GetLinePoints();

			GAME_ASSERT(points.size() > 0 && mSelectedLinePointIndex < points.size());

			newPoint.WorldPosition = Vector2(points[mSelectedLinePointIndex].WorldPosition.X, points[mSelectedLinePointIndex].WorldPosition.Y + 150.0f);
			newPoint.LocalPosition = Vector2(points[mSelectedLinePointIndex].LocalPosition.X, points[mSelectedLinePointIndex].LocalPosition.Y + 150.0f);

			points.insert(points.begin() + (mSelectedLinePointIndex + 1), newPoint);
			++mSelectedLinePointIndex;

			mSelectedLineStrip->RecalculateLines(points);
		}
	}

	if (GetAsyncKeyState('P') >= 0)
	{
		pressingNewPoint = false;
	}
}
Esempio n. 4
0
void LevelEditor::Draw()
{
	if (mTerrainEditing)
	{
		Graphics::GetInstance()->DrawDebugText("Terrain Edit Mode", 100, 100);

		if (mSelectedLineStrip && mSelectedLinePointIndex > -1)
		{
			std::vector<SolidLineStrip::SolidLinePoint> points = mSelectedLineStrip->GetLinePoints();

			GAME_ASSERT(points.size() > 0 && mSelectedLinePointIndex < points.size());

			DrawUtilities::DrawTexture(Vector3(points[mSelectedLinePointIndex].WorldPosition.X, points[mSelectedLinePointIndex].WorldPosition.Y, 3),
										Vector2(50, 50),
										"Media\\editor\\circle_selected.png");

			std::string materialName;
			if (mSelectedLineStrip->GetMaterial())
			{
				materialName = mSelectedLineStrip->GetMaterial()->GetMaterialName();
			}

			const int bufferSize = 100;
			char array[bufferSize];
			memset(array, 0, bufferSize);
			sprintf(array, "Selected Line Material: %s", materialName.empty() ? "none" : materialName.c_str());

			Graphics::GetInstance()->DrawDebugText(array, 100, 200);
		}
	}

	Vector2 mousePos = GetMouseWorldPos();

	Graphics::GetInstance()->DrawDebugText(Utilities::getFormattedString("Mouse X,Y: %f %f", mousePos.X, mousePos.Y).c_str(), 100, 150);
}
void AnimationSkeleton::PopulateFrameData(unsigned int frame, list<AnimationSkeletonFramePiece> framePieces)
{
	mSkeletonLines[frame].clear();
	mSkeletonLines[frame].reserve(framePieces.size());

	for (auto & piece : framePieces)
	{
		AnimationSkeletonFramePiece internalPiece;
		internalPiece.mStartPos = piece.mStartPos;
		internalPiece.mEndPos = piece.mEndPos;

		Vector2 lineDirection = piece.mEndPos - piece.mStartPos;
		internalPiece.mLength = lineDirection.Length();

		if (internalPiece.mLength <= 0)
		{
			GAME_ASSERT(false);
			continue;
		}

		internalPiece.mLineDirection.X = lineDirection.X / internalPiece.mLength;
		internalPiece.mLineDirection.Y = lineDirection.Y / internalPiece.mLength;

		internalPiece.mNormal.X = -internalPiece.mLineDirection.Y;
		internalPiece.mNormal.Y = internalPiece.mLineDirection.X;

		mSkeletonLines[frame].push_back(internalPiece);
	}
}
bool AIStateGroundAnimalWander::CanAccelerateX(float direction)
{
	GAME_ASSERT(std::abs(direction) == 1.0f);

	auto cam = Camera2D::GetInstance();

	if (cam->IsObjectInView(m_npc))
	{
		// should be able to accelerate if in view
		return true;
	}

	if (direction < 0.0f)
	{
		if (m_npc->m_position.X - 10.0f < cam->GetLeftLevelBounds())
		{
			return false;
		}
	}
	else
	{
		if (m_npc->m_position.X + 10.0f > cam->GetRightLevelBounds())
		{
			return false;
		}
	}

	return true;
}
Esempio n. 7
0
void Explosion::ApplyForceToApplicable()
{
	list<GameObject *> objects;
	GameObjectManager::Instance()->GetTypesOnScreen<DrawableObject>(objects);

	for (auto obj : objects)
	{
		if (!obj)
		{
			GAME_ASSERT(obj);
			continue;
		}

		if (obj->IsDebris() ||
			obj->IsProjectile())
		{
			MovingSprite * moveable = static_cast<MovingSprite *>(obj); // has to be a movingsprite if it's one of the above

			Vector3 direction =  obj->Position() - m_position;

			float distSquared = direction.LengthSquared();

			if (distSquared < (mRadius * mRadius))
			{
				direction.Normalise();

				moveable->SetVelocityXYZ(moveable->GetVelocity().X + (direction.X * 10), moveable->GetVelocity().Y + (direction.Y * 15), 0);
			}
		}
	}
}
Esempio n. 8
0
void LevelEditor::CheckForSolidLineStripEdgeAssign()
{
	GAME_ASSERT(mTerrainEditing);

	if (!mTerrainEditing)
	{
		return;
	}

	if (!mSelectedLineStrip)
	{
		return;
	}

	static bool pressingLeft = false;

	if (!pressingLeft && GetAsyncKeyState(VK_LEFT) < 0)
	{
		pressingLeft = true;

		if (mSelectedLineStrip->GetHasHardLeftEdge())
		{
			mSelectedLineStrip->SetHasHardLeftEdge(false);
			mSelectedLineStrip->SetHardLeftEdgeOffsetX(0.0f);
		}
		else
		{
			mSelectedLineStrip->SetHasHardLeftEdge(true);
			mSelectedLineStrip->SetHardLeftEdgeOffsetX(20.0f);
		}
	}

	if (GetAsyncKeyState(VK_LEFT) >= 0)
	{
		pressingLeft = false;
	}

	static bool pressingRight = false;

	if (!pressingRight && GetAsyncKeyState(VK_RIGHT) < 0)
	{
		pressingRight = true;

		if (mSelectedLineStrip->GetHasHardRightEdge())
		{
			mSelectedLineStrip->SetHasHardRightEdge(false);
			mSelectedLineStrip->SetHardRightEdgeOffsetX(0.0f);
		}
		else
		{
			mSelectedLineStrip->SetHasHardRightEdge(true);
			mSelectedLineStrip->SetHardRightEdgeOffsetX(20.0f);
		}
	}

	if (GetAsyncKeyState(VK_RIGHT) >= 0)
	{
		pressingRight = false;
	}
}
Esempio n. 9
0
void SpriteResource::loadInMainThread(const std::string &fileName, CL_SharedPtr<Resource> &firstResource)
{
	FrameMap::iterator it = mFrames.find(fileName);
	GAME_ASSERT(it != mFrames.end());

	// convert previously loaded pixel buffer to the texture (only for the first resource)
	if (this == firstResource.get())
	{
		if (it->second.texture.is_null())
		{
			GAME_ASSERT(!it->second.pixelBuffer.is_null());
			it->second.texture = CL_Texture(Graphics::getSingleton().getWindow().get_gc(), it->second.pixelBuffer.get_size(), cl_rgba);
			it->second.texture.set_subimage(0, 0, it->second.pixelBuffer, CL_Rect(it->second.pixelBuffer.get_size()), 0);
			it->second.pixelBuffer = CL_PixelBuffer();
			CL_SharedGCData::add_texture(it->second.texture, it->second.fileName, mResource.get_manager().get_directory(mResource));
		}
	}
}
Esempio n. 10
0
void Log::deleteFileLog(const char* filePath)
{
    if (remove(filePath) == 0)
    {
        //success
    }
    else
    {
        GAME_ASSERT(0);
    }
}
Esempio n. 11
0
AnimationSkeleton * Animation::GetSkeletonForCurrentSequence(const char * bodyPart)
{
	AnimationSequence * currentSequence = m_animationParts[bodyPart]->CurrentSequence();
	GAME_ASSERT(currentSequence);

	if (!currentSequence)
	{
		return nullptr;
	}

	return currentSequence->GetSkeleton();
}
Esempio n. 12
0
void SpriteResource::loadInBackgroundThread(const std::string &fileName, CL_SharedPtr<Resource> &firstResource)
{
	FrameMap::iterator it = mFrames.find(fileName);
	GAME_ASSERT(it != mFrames.end());

	// load image into the pixel buffer (only for the first resource)
	if (this == firstResource.get())
	{
		if (it->second.pixelBuffer.is_null())
			it->second.pixelBuffer = CL_PixelBuffer(it->second.fileName, mResource.get_manager().get_directory(mResource));
	}
}
Esempio n. 13
0
void UIManager::DisplayObjectEditor(GameObject * gameObject)
{
	mObjectEditorDisplaying = true;

	UIObjectEditScreen * screen = dynamic_cast<UIObjectEditScreen*>(PushUI("object_editor"));

	GAME_ASSERT(screen != 0);

	if (screen)
	{
		screen->SetObjectToEdit(gameObject);
	}
}
Esempio n. 14
0
void Log::fileLog(const char * format, va_list args)
{
    /*
    char buffer[MAX_FILE_LOG_BUFFER_SIZE];
    std::string nowTime = TimeDefault::getInstance()->getNowTime();
    nowTime += " ";
    auto timeLen = nowTime.length();
    strcpy(buffer, nowTime.c_str());
    vsnprintf(buffer+timeLen, MAX_FILE_LOG_BUFFER_SIZE-timeLen-3, format, args);
    strcat(buffer, "\n");
    
    writeFileLog(getFileLogPath(), strlen(buffer), (unsigned char*)buffer);
     */
    GAME_ASSERT(0);
}
Esempio n. 15
0
void Log::writeFileLog(const char* filePath, ssize_t len, const unsigned char* data)
{
    //auto startTime = GlobalFunc::getCurMicroSecond();
    FILE* file = fopen(filePath, "ab");
    if (file == NULL)
    {
        GAME_ASSERT(0);
    }
    else
    {
        fwrite(data, sizeof(unsigned char), len, file);
        fflush(file);
        fclose(file);
    }
}
Esempio n. 16
0
SpriteResource::SpriteResource(CL_Resource &resource)
: mResource(resource)
{
	GAME_ASSERT(mResource.get_type() == "sprite");

	std::string basePath = mResource.get_manager().get_directory(mResource).get_file_system().get_path();
	for (CL_DomElement element = mResource.get_element().get_first_child_element(); !element.is_null(); element = element.get_next_sibling_element())
		if (element.get_tag_name() == "image")
		{
			std::string fileName = element.get_attribute("file");
			if (fileName.empty())
				throw Exception("Sprite '" + mResource.get_name() + "' has empty or missing 'file' attribute");
			mFrames.insert(std::make_pair(basePath + fileName, Frame(fileName)));
		}

	if (mFrames.empty())
		throw Exception("Sprite '" + mResource.get_name() + "' has no frames");
}
Esempio n. 17
0
const char* Log::getFileLogPath()
{
    if (s_logFilePath.length() > 0)
        return s_logFilePath.c_str();
    else
    {
        /*
        s_logFilePath = GlobalFunc::getStoragePath();
        if (s_logFilePath.back() != '/')
        {
            s_logFilePath += "/";
        }
        s_logFilePath += RESOURCE_DIR;
        s_logFilePath += "/";
        s_logFilePath += FILE_LOG_NAME;
        return s_logFilePath.c_str();
         */
        GAME_ASSERT(0);
    }
}
Esempio n. 18
0
void LevelEditor::CheckForPixelMovement()
{
	GAME_ASSERT(!mTerrainEditing);

	if (mTerrainEditing)
	{
		return;
	}

	if (!mSelectedObject)
	{
		return;
	}

	if (GetAsyncKeyState(VK_UP))
	{
		mSelectedObject->SetY(mSelectedObject->Y() + 0.1f);
		mSelectedObject->Update(0);
	}

	if (GetAsyncKeyState(VK_LEFT))
	{
		mSelectedObject->SetX(mSelectedObject->X() - 0.1f);
		mSelectedObject->Update(0);
	}

	if (GetAsyncKeyState(VK_DOWN))
	{
		mSelectedObject->SetY(mSelectedObject->Y() - 0.1f);
		mSelectedObject->Update(0);
	}

	if (GetAsyncKeyState(VK_RIGHT))
	{
		mSelectedObject->SetX(mSelectedObject->X() + 0.1f);
		mSelectedObject->Update(0);
	}
}
Esempio n. 19
0
void LevelEditor::CheckForTerrainPointMove()
{
	if (mSelectedLineStrip && mSelectedLinePointIndex > -1)
	{
		if (GetAsyncKeyState(VK_LBUTTON) >= 0)
		{
			return;
		}

		Vector2 mousePos = GetMouseWorldPos();

		std::vector<SolidLineStrip::SolidLinePoint> points = mSelectedLineStrip->GetLinePoints();

		GAME_ASSERT(points.size() > 0 && mSelectedLinePointIndex < points.size());

		points[mSelectedLinePointIndex].WorldPosition = mousePos;

		Vector2 LocalPos = Vector2(mousePos.X - mSelectedLineStrip->Position().X, mousePos.Y - mSelectedLineStrip->Position().Y);

		points[mSelectedLinePointIndex].LocalPosition = LocalPos;

		mSelectedLineStrip->RecalculateLines(points);
	}
}
Esempio n. 20
0
Application::Application(const std::vector<CL_String> &args, lua_State *luaState)
    : mUpdated(false), mCompanyName(""), mApplicationName("bmgui"), mApplicationVersion(""), mQuit(false)
{
    GAME_ASSERT(!args.empty());

#ifdef WIN32
    // bind main thread to the first core for correct timings on some multicore systems
    SetThreadAffinityMask(GetCurrentThread(), 0x01);
#endif

    // parse the command line arguments
    std::vector<char *> argv;
    for (std::vector<CL_String>::const_iterator it = args.begin(); it != args.end(); ++it)
        argv.push_back(const_cast<char *>(it->c_str()));

    CL_CommandLine commandLine;
    commandLine.set_help_indent(40);
    commandLine.add_doc("Graphical interface for Sibek balance machines");
    commandLine.add_usage("[OPTION...]\n");

    commandLine.add_option('g', "gateway", "ADDR", "Default gateway address");
    commandLine.add_option('a', "local_addr", "ADDR", "Local address");
    commandLine.add_option('m', "netmask", "ADDR", "Subnet mask");
    commandLine.add_option('d', "dns", "ADDR", "DNS server address");
    commandLine.add_option('i', "input_dev", "TYPE", "Input device type");
    commandLine.add_option('s', "server_status", "FLAG", "Server status");
    commandLine.add_option('u', "available_update_version", "VERSION", "Available update version");
    commandLine.add_option('U', "updated", "FLAG", "Software update flag");
    commandLine.add_option('W', "updatedfw", "FLAG", "Firmware update flag");
    commandLine.add_option('D', "datadir", "PATH", "Path to the data directory");
    commandLine.add_option('h', "help", "", "Show this help");
    commandLine.parse_args(argv.size(), &argv[0]);

#if defined(WIN32) || defined(__APPLE__)
    mDataDirectory = CL_Directory::get_resourcedata("bmgui", "data");
#else
    mDataDirectory = CL_PathHelp::add_trailing_slash(GAME_DATA_DIR);
#endif
    while (commandLine.next())
    {
        switch (commandLine.get_key())
        {
        case 'g':
            mGateway = commandLine.get_argument();
            break;
        case 'a':
            mLocalAddr = commandLine.get_argument();
            break;
        case 'm':
            mNetmask = commandLine.get_argument();
            break;
        case 'd':
            mDNS = commandLine.get_argument();
            break;
        case 'i':
            mInputDev = commandLine.get_argument();
            break;
        case 's':
            mServerStatus = commandLine.get_argument();
            break;
        case 'u':
            mAvailableUpdateVersion = commandLine.get_argument();
            break;
        case 'U':
            mUpdated = CL_StringHelp::text_to_bool(commandLine.get_argument());
            break;
        case 'W':
            mFirmwareUpdated = commandLine.get_argument();
            break;
        case 'D':
            mDataDirectory = CL_PathHelp::add_trailing_slash(commandLine.get_argument());
            break;
        case 'h':
            commandLine.print_help();
            quit();
            return;
        }
    }

    /*CL_Console::write_line(cl_format("mGateway = %1", mGateway));
    CL_Console::write_line(cl_format("mLocalAddr = %1", mLocalAddr));
    CL_Console::write_line(cl_format("mNetmask = %1", mNetmask));
    CL_Console::write_line(cl_format("mDNS = %1", mDNS));
    CL_Console::write_line(cl_format("mInputDev = %1", mInputDev));
    CL_Console::write_line(cl_format("mServerStatus = %1", mServerStatus));
    CL_Console::write_line(cl_format("mAvailableUpdateVersion = %1", mAvailableUpdateVersion));
    CL_Console::write_line(cl_format("mDataDirectory = %1", mDataDirectory));*/

    // load the system profile
    Profile profile("");

    CL_Console::write_line(cl_format("gateway = %1", profile.getString("gateway")));
    CL_Console::write_line(cl_format("local_addr = %1", profile.getString("local_addr")));
    CL_Console::write_line(cl_format("netmask = %1", profile.getString("netmask")));
    CL_Console::write_line(cl_format("dns = %1", profile.getString("dns")));
    CL_Console::write_line(cl_format("input_dev = %1", profile.getInt("input_dev")));
    CL_Console::write_line(cl_format("server_status = %1", profile.getBool("server_status")));
    CL_Console::write_line(cl_format("available_update_version = %1", profile.getString("available_update_version")));
    CL_Console::write_line(cl_format("server_addr = %1", profile.getString("server_addr")));
    CL_Console::write_line(cl_format("remote_control = %1", profile.getBool("remote_control")));
    CL_Console::write_line(cl_format("ignored_update_version = %1", profile.getString("ignored_update_version")));
    CL_Console::write_line(cl_format("cal_command = %1", profile.getString("cal_command")));
    CL_Console::write_line(cl_format("language = %1", profile.getInt("language")));
    CL_Console::write_line(cl_format("fullscreen = %1", profile.getBool("fullscreen")));
    CL_Console::write_line(cl_format("width = %1", profile.getInt("width")));
    CL_Console::write_line(cl_format("height = %1", profile.getInt("height")));
    CL_Console::write_line(cl_format("sound_level = %1", profile.getInt("sound_level")));

    // initialize all game subsystems
    mBalance = CL_SharedPtr<Balance>(new Balance(profile));
    mDatabase = CL_SharedPtr<Database>(new Database(getConfigDirectory() + getApplicationName() + ".db"));
    mResourceManager = CL_SharedPtr<ResourceManager>(new ResourceManager());
    mResourceQueue = CL_SharedPtr<ResourceQueue>(new ResourceQueue());
    mGraphics = CL_SharedPtr<Graphics>(new Graphics(profile));
    mKeyboard = CL_SharedPtr<Keyboard>(new Keyboard());
    mMouse = CL_SharedPtr<Mouse>(new Mouse());
    mSoundOutput = CL_SoundOutput(44100);
    mLuaScript = CL_SharedPtr<LuaScript>(new LuaScript("main.lua", luaState));
}
Esempio n. 21
0
void Camera2D::FollowTargetObjectWithLag(bool forceUpdate, float overrideLagX, float overrideLagY)
{
	GAME_ASSERT(mTargetObject);

	if (!mTargetObject)
	{
		return;
	}

	if ((mFollowX && UpdateBoundsX(mTargetObject)) || forceUpdate)
	{
		// get the x and y distance between the camera and the object
		float distanceX = 0.0f;

		if (mIsOverrideDirection)
		{
			if (mOverrideDirection.X > 0)
			{
				distanceX = m_position.X - (mTargetObject->X() + mTargetOffset.X * mZoomInPercent);
			}
			else
			{
				distanceX = m_position.X - (mTargetObject->X() - mTargetOffset.X * mZoomInPercent);
			}
		}
		else
		{
			if (mTargetObject->DirectionX() > 0)
			{
				distanceX = m_position.X - (mTargetObject->X() + mTargetOffset.X * mZoomInPercent);
			}
			else
			{
				distanceX = m_position.X - (mTargetObject->X() - mTargetOffset.X * mZoomInPercent);
			}
		}

		float xLag = mTargetLag.X * mZoomInPercent;

		if (overrideLagX != 0.0f)
		{
			xLag = overrideLagX;
		}

		if (xLag < 1.0f)
		{
			xLag = 1.0f;
		}
		m_position.X -= distanceX / xLag;
	}

	if ((mFollowY && UpdateBoundsY(mTargetObject)) || forceUpdate)
	{
		float yLag = mTargetLag.Y;

		if (overrideLagY != 0.0f)
		{
			yLag = overrideLagY;
		}

		if (yLag < 1.0f)
		{
			yLag = 1.0f;
		}

		float distanceY = m_position.Y - (mTargetObject->Y() + mTargetOffset.Y * mZoomInPercent);

		m_position.Y -= distanceY / yLag;
	}
}
Esempio n. 22
0
void Camera2D::Update()
{
	D3DXMatrixTranslation(&m_view, (int)-m_position.X, (int)-m_position.Y, m_position.Z);

	if (mCurrentlyShaking)
	{
		float currentTime = Timing::Instance()->GetTotalTimeSeconds();

		float timeDiff = (mShakeStartTime + mCurrentShakeDuration) - currentTime;

		if (timeDiff <= 0.0f)
		{
			mCurrentlyShaking = false;
		}
		else
		{
			float shakePercentTime = timeDiff / mCurrentShakeDuration;

			bool minusX = (rand() % 2) == 1;
			bool minusY = (rand() % 2) == 1;

			GAME_ASSERT(mTargetObject);
			if (UpdateBoundsX(mTargetObject))
			{
				if (minusX)
				{
					m_position.X += mCurrentShakeIntensity * shakePercentTime * Timing::Instance()->GetTimeModifier();
				}
				else
				{
					m_position.X -= mCurrentShakeIntensity * shakePercentTime * Timing::Instance()->GetTimeModifier();
				}
			}
			
			if (UpdateBoundsY(mTargetObject))
			{
				if (minusY)
				{
					m_position.Y += mCurrentShakeIntensity * shakePercentTime * Timing::Instance()->GetTimeModifier();
				}
				else
				{
					m_position.Y -= mCurrentShakeIntensity * shakePercentTime  * Timing::Instance()->GetTimeModifier();
				}
			}
		}
	}

#if _DEBUG
	if (!UIManager::Instance()->IsObjectEditorDisplaying())
	{
		int movespeed = 40;
		// test
		if (GetAsyncKeyState('D') < 0)
		{
			m_position.X += movespeed;

			if (Game::GetInstance()->GetIsLevelEditMode())
			{
				list<shared_ptr<GameObject> > & gameObjects = GameObjectManager::Instance()->GetGameObjectList();
				for (auto & obj : gameObjects)
				{
					if (obj->GetParallaxMultiplierX() != 1.0f ||
						obj->GetParallaxMultiplierY() != 1.0f)
					{
						obj->Update(1.0f);
					}
				}
			}
		}
		else if (GetAsyncKeyState('A') < 0)
		{
			m_position.X -= movespeed;
			if (Game::GetInstance()->GetIsLevelEditMode())
			{
				list<shared_ptr<GameObject> > & gameObjects = GameObjectManager::Instance()->GetGameObjectList();
				for (auto & obj : gameObjects)
				{
					if (obj->GetParallaxMultiplierX() != 1.0f ||
						obj->GetParallaxMultiplierY() != 1.0f)
					{
						obj->Update(1.0f);
					}
				}
			}
		}

		if (GetAsyncKeyState('W') < 0)
		{
			m_position.Y += movespeed;
			if (Game::GetInstance()->GetIsLevelEditMode())
			{
				list<shared_ptr<GameObject> > & gameObjects = GameObjectManager::Instance()->GetGameObjectList();
				for (auto & obj : gameObjects)
				{
					if (obj->GetParallaxMultiplierX() != 1.0f ||
						obj->GetParallaxMultiplierY() != 1.0f)
					{
						obj->Update(1.0f);
					}
				}
			}
		}
		else if (GetAsyncKeyState('S') < 0 && GetAsyncKeyState(VK_CONTROL) >= 0)
		{
			m_position.Y -= movespeed;
			if (Game::GetInstance()->GetIsLevelEditMode())
			{
				list<shared_ptr<GameObject> > & gameObjects = GameObjectManager::Instance()->GetGameObjectList();
				for (auto & obj : gameObjects)
				{
					if (obj->GetParallaxMultiplierX() != 1.0f ||
						obj->GetParallaxMultiplierY() != 1.0f)
					{
						obj->Update(1.0f);
					}
				}
			}
		}
	}
#endif
}
Esempio n. 23
0
void MovingSprite::Update(float delta)
{	
	// update our base class 
	Sprite::Update(delta);

	if (Game::GetInstance()->GetIsLevelEditMode())
	{
		return;
	}

	if (GetIsInWater() &&
			(std::abs(m_velocity.X) > 0.1f || (std::abs(m_velocity.Y) > 1.0f &&
			!(IsCharacter() && static_cast<Character *>(this)->IsOnSolidSurface() ))))
	{
		DoWaterAccelerationBubbles();
	}

	float velocityMod = mIsInWater ? (GetWaterIsDeep() ? 0.35f : 0.6f) : 1.0f;
	Vector3 nextVelocity = m_velocity + (m_acceleration * m_direction) * velocityMod;

	if (nextVelocity.X > m_maxVelocity.X * velocityMod && mMaxVelocityXLimitEnabled)
	{
		nextVelocity.X = m_maxVelocity.X * velocityMod;
	}
	else if (nextVelocity.X < -m_maxVelocity.X * velocityMod && mMaxVelocityXLimitEnabled)
	{
		nextVelocity.X = -m_maxVelocity.X * velocityMod;
	}

	if (nextVelocity.Y > m_maxVelocity.Y * velocityMod)
	{
		nextVelocity.Y = m_maxVelocity.Y * velocityMod;
	}
	else if (nextVelocity.Y < -m_maxVelocity.Y * velocityMod)
	{
		nextVelocity.Y = -m_maxVelocity.Y * velocityMod;
	}

	mHittingSolidLineEdge = false;

	if (IsCharacter())
	{
		Character * character = static_cast<Character *>(this);
		if (character->IsOnSolidLine())
		{
			SolidLineStrip * solidLineStrip = character->GetCurrentSolidLineStrip();
			GAME_ASSERT(solidLineStrip);

			if (solidLineStrip)
			{
				Vector2 rightMostPoint = solidLineStrip->GetRightMostPoint();
				Vector2 leftMostPoint = solidLineStrip->GetLeftMostPoint();

				float nextPositionX = m_position.X + nextVelocity.X;

				if ((solidLineStrip->GetHasHardRightEdge() && 
					nextVelocity.X > 0 &&
					nextPositionX > rightMostPoint.X - solidLineStrip->GetHardRightEdgeOffsetX()) ||
					(solidLineStrip->GetHasHardLeftEdge() && 
					nextVelocity.X < 0 &&
					nextPositionX < leftMostPoint.X + solidLineStrip->GetHardLeftEdgeOffsetX()))
				{
					nextVelocity.X = 0.0f;
					StopXAccelerating();
					mHittingSolidLineEdge = true;
				}
			}
		}
	}

	// increase velocity
	m_velocity = nextVelocity;

	float targetDelta =  Timing::Instance()->GetTargetDelta();
	float percentDelta = delta / targetDelta;

	if (mObjectMovingWith)
	{
		m_position += m_velocity * percentDelta;
		m_position.X += mObjectMovingWith->VelocityX() * percentDelta;
	}
	else
	{
		m_position += m_velocity * percentDelta; // update our position by velocity
	}

	// apply gravity?
	float fakeGravity = 1.0f; // must be greater than 1
	if (m_applyGravity) // TODO: only apply if not on solid surface
	{
		if (!mIsInWater)
		{
			AccelerateY(-1, (fakeGravity/mCurrentYResistance) * percentDelta);
		}
		else
		{
			if (m_velocity.Y > 0.0f)
			{
				AccelerateY(-1, 0.055f * percentDelta);
			}
			else
			{
				AccelerateY(-1, 0.004f * percentDelta);
			}
		}
	}

	// apply friction values
	m_velocity.X = m_velocity.X * mCurrentXResistance;

	// stop us if we get too slow
	if(m_velocity.X < 0.1 && m_velocity.X > -0.1)
	{
		// then stop
		m_velocity.X = 0;
	}

	if (mIsInWater == false)
	{
		mWasInWaterLastFrame = false;
	}

	mIsInWater = false;// let the collision manager handle this again

	if (mTimeUntilCanSpawnWaterBubbles > 0.0f)
	{
		mTimeUntilCanSpawnWaterBubbles -= delta;
	}
}
void AIStateRangeAttack::Update(float delta)
{
	if (m_npc->m_player)
	{
		if (!CanAccelerateX(1.0f))
		{
			m_npc->Teleport(m_npc->m_player->Position().X - 300, m_npc->m_player->Position().Y + 300, true);
			mLastTimeRanAway = 0.0f;
			return; // skip this update
		}
		else if (!CanAccelerateX(-1.0f))
		{
			m_npc->Teleport(m_npc->m_player->Position().X + 300, m_npc->m_player->Position().Y + 300, true);
			mLastTimeRanAway = 0.0f;
			return; // skip this update
		}

		Vector3 distanceSquaredVector = m_npc->m_player->Position() - m_npc->Position();

		if (std::abs(distanceSquaredVector.X > 3000) ||
			(std::abs(distanceSquaredVector.Y > 1000) && m_npc->m_player->IsOnSolidSurface() && m_npc->m_player->GetTimeOnSolidSurface() > 1.0f))
		{
			if (mTimeUntilCanTeleport <= 0.0f)
			{
				m_npc->Teleport(m_npc->m_player->Position().X + 5, m_npc->m_player->Position().Y + 500, true);
				mLastTimeRanAway = 0.0f;
				mTimeUntilCanTeleport = kTeleportDelayMin + (rand() % (int)((kTeleportDelayMax - kTeleportDelayMin) * 100.0f)) * 0.01f;
				m_npc->FireProjectileAtObject(m_npc->m_player);
			}
		}

		float currentTime = Timing::Instance()->GetTotalTimeSeconds();
		if (currentTime > mLastTimeRanAway + kRunAwayDelay)
		{
			// get the distance to the player
			float distanceSquared = distanceSquaredVector.LengthSquared();

			if (distanceSquared < (mDesiredRange + mRandOffset) * (mDesiredRange + mRandOffset))
			{
				// run away from player
				distanceSquaredVector.Normalise();

				m_npc->AccelerateX(-distanceSquaredVector.X);
			}
			else if (distanceSquared > (mFollowRange + mRandOffset) * (mFollowRange + mRandOffset))
			{
				distanceSquaredVector.Normalise();

				m_npc->AccelerateX(distanceSquaredVector.X);
			}
			else
			{
				m_npc->StopXAccelerating();
				GAME_ASSERT(GameObjectManager::Instance()->GetPlayer());
				m_npc->FireProjectileAtObject(GameObjectManager::Instance()->GetPlayer());

				mLastTimeRanAway = currentTime;
			}
		}
		else
		{
			m_npc->StopXAccelerating();
			GAME_ASSERT(GameObjectManager::Instance()->GetPlayer());
			m_npc->FireProjectileAtObject(GameObjectManager::Instance()->GetPlayer());
		}

		if (mTimeUntilRandomlyJump > 0.0f)
		{
			mTimeUntilRandomlyJump -= delta;
		}

		// let's just randomly jump
		if (m_npc->IsOnSolidSurface())
		{
			if (mTimeUntilRandomlyJump <= 0.0f)
			{
				if (m_npc->Jump(100.0f))
				{
					m_npc->SetVelocityY(0.5f);
					mTimeUntilRandomlyJump = kJumpRandomDelayMin + (rand() % (int)((kJumpRandomDelayMax - kJumpRandomDelayMin) * 100.0f)) * 0.01f;
				}
			}
		}

		m_npc->SetIsStrafing(true);
		if (distanceSquaredVector.X > 0)
		{
			m_npc->SetStrafeDirectionX(1.0f);
		}
		else
		{
			m_npc->SetStrafeDirectionX(-1.0f);
		}
	}

	if (mTimeUntilCanTeleport > 0.0f)
	{
		mTimeUntilCanTeleport -= delta;
	}
}