Skate Park Mod

From X-Moto
Revision as of 09:49, 25 May 2007 by Gaivota (talk | contribs)
Jump to: navigation, search

Català - Español

Skatepark.jpg

This script allows you to convert your level into a skate park. To complete the level, you must collect points by performing tricks.

The more tricks you string together, the higher the points. Try to keep a manual going as long as you can while doing flips.

If you would like to change the values, use the constants defined at the top of the script.

The original Script by Jacky J has been altered a bit, to make it compatible to actual xmoto versions (it won't produce huge replays anymore, but therefore the scoring display had to be changed).

Copy the code directly into your level to add this functionality. Note that if you edit your level in any editor, you'll have to recopy the entities because the editor doesn't retain them correctly.

Level examples: Skate Park mod (old code), Half Pipe (current code)

	<script>
	-- Level Parameters
		SCORE_WIN 			= 6000
		MANUAL_MINTIME 			= 1.0
		MANUAL_MAXTIME 			= 180.0
		MANUAL_UPDATEINTERVAL 		= 3.0
		MANUAL_BASESCORE		= 30
		MANUAL_FLIPDIVISOR		= 4
		AIR_MINDURATION			= 2.0
		AIR_MULTIPLIER			= 3
		AIR_MAXBONUSFLIPCOUNT		= 5		
		FLIP_BASESCORE			= 80
		
		-- States
		ManualAirTime			= 0.0
		InAir 				= false
		AirStart 			= 0.0
		AirFlips			= 0
		WheelTouching 			= {0, 0}
		Manualing				= 0
		ManualingStart 			= 0.0
		
		-- Scores
		FlipCount			= 0
                CurrentStar                     = 0
		FlipScore			= 0
		ManualScore			= 0
		BonusScore			= 0
		LastScore = 0  
		TotalScore 			= 0
		HighTrickScore			= 0
		
		function Tick()
			ManualScore = GetManualScore()
			if ManualScore ~= LastScore then
				PlayerX, PlayerY, PlayerDirection = Game.GetPlayerPosition()
				addStar(PlayerDirection)
				LastScore = ManualScore
			end
			return true
		end 

		function OnLoad()
			Game.SetKeyHook("H", "ShowHelp")
			Game.Message("   Skate Park\nPress H for help")
			return true
		end
		
		function ShowHelp()
			Game.Message("Get points by performing tricks!")
			Game.Message("Get " .. SCORE_WIN .. " points to win.")
			Game.Message("Scripting by Jacky J")
			Game.Message("Level design by Gaivota")
		end
		
		function addStar(direction)
			CurrentStar = CurrentStar + 1
			if CurrentStar <= 7 then
				PlayerX, PlayerY, PlayerDirection = Game.GetPlayerPosition()
				Game.SetDynamicEntityNone("som"..CurrentStar)
				Game.SetEntityPos("som"..CurrentStar, PlayerX, PlayerY)
				if direction == 0 then
					Game.SetDynamicEntityRotation("som"..CurrentStar, 0, 0.5, 100, 0,  0)
				else
					Game.SetDynamicEntityRotation("som"..CurrentStar, 0, 0.5, -100, 0, 0)
				end
			end	
		end 

		function resetStars()
  			for i = 1, CurrentStar do
				if i <= 7 then
					Game.SetDynamicEntityNone("som"..i)
					Game.SetDynamicEntityTranslation("som"..i, 0, 50, 2500, 0, 1250)
				end
			end 

			CurrentStar = 0
		end 

		function OnSomersault(TDirection)
			local AirTime = 0
			local FlipMultiplier = 0
			local FlipDecayCount = 0
			
			-- Get air time
			if InAir == true then
				AirTime = Game.GetTime() - AirStart
			end
			
			-- Get manual time
			local ManualTime = GetManualTime()
			
			-- Increment flip counter
			FlipCount = FlipCount + 1
			AirFlips = AirFlips + 1
			FlipDecayCount = AirFlips
			if FlipDecayCount > AIR_MAXBONUSFLIPCOUNT then
				FlipDecayCount = AIR_MAXBONUSFLIPCOUNT
			end 
			FlipValue = (FLIP_BASESCORE - 5 * FlipDecayCount) * AirFlips
			
			-- Calculate flip score
			FlipScore = FlipScore + math.floor(FlipValue + AIR_MULTIPLIER * AirTime + math.floor(ManualTime / MANUAL_FLIPDIVISOR))

			addStar(TDirection)
		end
		
		function OnWheel1Touchs(TStatus)
			WheelTouching[1] = TStatus
			if TStatus == 1 then
				CancelInAir()
				StartLandManual(1)
			else
				StartLiftManual(1)
				StartInAir(2)
			end
		end
		
		function OnWheel2Touchs(TStatus)
			WheelTouching[2] = TStatus
			if TStatus == 1 then
				
				CancelInAir()
				StartLandManual(2)
			else
				StartLiftManual(2)
				StartInAir(1)
			end
		end
		
		function StartInAir(TWheel)
			if WheelTouching[TWheel] == 0 then
				InAir = true
				AirStart = Game.GetTime()
			end
		end
		
		function CancelInAir()
			if InAir == true then
				AirTime = Game.GetTime() - AirStart
				if AirTime > AIR_MINDURATION then
					--Game.Message("Air Time: " .. AirTime)
				end
				-- Subtract air time from manualing time
				if Manualing ~= 0 and AirTime > 0.5 then
					ManualAirTime = ManualAirTime + AirTime
				end
			end
			
			AirFlips = 0
			InAir = false
		end
		
		-- Called when a wheel touches
		function StartLandManual(TWheel)
			local OtherWheel = 3 - TWheel
			
			-- Check for both wheels touching
			if WheelTouching[OtherWheel] == 1 and Manualing ~= 0 then
				UpdateScore()
				Manualing = 0
				ManualAirTime = 0
				return true
			end
			
			-- Swapping manual wheels without both wheels touching
			if Manualing == OtherWheel then
				Manualing = TWheel
				--DisplayManualTime()
				return true
			end
			
			-- Check for an existing manual
			if Manualing == 0 then
			
				-- Start the manual
				Manualing = TWheel
				ManualingStart = Game.GetTime() + MANUAL_MINTIME
			end
		end
		
		-- Called when a wheel lifts off the ground
		function StartLiftManual(TWheel)
			local OtherWheel = 3 - TWheel
			StartLandManual(OtherWheel)
		end
		
		-- Returns the current manualing time
		function GetManualTime()
		
			-- Check for a manual
			if Manualing == 0 then
				return 0.0
			end
			
			-- Discount current air time
			if InAir == true then
				CurrentAirTime = Game.GetTime() - AirStart
			else
				CurrentAirTime = 0
			end
			
			-- Calculate the time
			ManualTime = Game.GetTime() - ManualingStart - ManualAirTime - CurrentAirTime		 	
			
			-- Cap time
			if ManualTime < 0 then
				ManualTime = 0
			elseif ManualTime > MANUAL_MAXTIME then
				ManualTime = MANUAL_MAXTIME
			end
			
			return ManualTime
		end
					
		-- Calculates the manual score
		function GetManualScore()
			local ManualTime = GetManualTime()
			local Score = math.floor(ManualTime / MANUAL_UPDATEINTERVAL) * MANUAL_BASESCORE;
			
			return Score
		end
		
		-- Awards the player points
		function UpdateScore()
			ManualScore = GetManualScore()
			
			-- Score formulas
			TrickScore = FlipScore + ManualScore + BonusScore
			TotalScore = TotalScore + TrickScore
			
			-- Display score
			if TrickScore > 0 then
				Game.Message("Trick Score: " .. TrickScore)
				Game.Message("Total Score: " .. TotalScore)
			end
			
			if TotalScore >= SCORE_WIN then
				Game.WinPlayer()
			end


			resetStars() 
 

			-- Reset stats
			FlipCount = 0
			FlipScore = 0
			ManualScore = 0
			BonusScore = 0
			TrickScore = 0
		end
  		
	</script>	
        <theme_replacements>
		<sprite_replacement old_name="Strawberry" new_name="Star"/>
		<sprite_replacement old_name="Flower" new_name="Star"/>
		<sprite_replacement old_name="Wrecker" new_name="Star"/>
	</theme_replacements> 

Level code here!

  <entity id="som1" typeid="Sprite">
		<size r="0.400000" width="0.5" height="0.5"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som2" typeid="Sprite">
		<size r="0.400000" width="0.8" height="0.8"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som3" typeid="Sprite">
		<size r="0.400000" width="1.1" height="1.1"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som4" typeid="Sprite">
		<size r="0.400000" width="1.4" height="1.4"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som5" typeid="Sprite">
		<size r="0.400000" width="1.7" height="1.7"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som6" typeid="Sprite">
		<size r="0.400000" width="2.0" height="2.0"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som7" typeid="Sprite">
		<size r="0.400000" width="2.3" height="2.3"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>