Browse Source

updated the VectorRumble sample to include the ability to use the touch screen to select menu items
Added the gamepad support. (not working yet)

dellis1972 13 years ago
parent
commit
8e4a5b9379

+ 1 - 2
StarterKits/Android/Cards/Blackjack.Android.csproj

@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -15,7 +15,6 @@
     <AndroidApplication>True</AndroidApplication>
     <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
     <AssemblyName>Blackjack.Android</AssemblyName>
-    <TargetFrameworkVersion>v2.2</TargetFrameworkVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>

+ 0 - 1
StarterKits/Android/Cards/CardsFramework.Android.csproj

@@ -12,7 +12,6 @@
     <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
     <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
     <AssemblyName>CardsFramework.Android</AssemblyName>
-    <TargetFrameworkVersion>v2.2</TargetFrameworkVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>

+ 1 - 2
StarterKits/Android/Marblets/Marblets.csproj

@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -15,7 +15,6 @@
     <AndroidApplication>True</AndroidApplication>
     <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
     <AssemblyName>Marblets</AssemblyName>
-    <TargetFrameworkVersion>v2.2</TargetFrameworkVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>

+ 2 - 1
StarterKits/Android/Platformer/Platformer.csproj

@@ -15,7 +15,7 @@
     <AndroidApplication>True</AndroidApplication>
     <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
     <AssemblyName>Platformer</AssemblyName>
-    <TargetFrameworkVersion>v2.2</TargetFrameworkVersion>
+    <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -266,6 +266,7 @@
     <AndroidAsset Include="..\..\iOS\Platformer\Content\Tiles\Platform.png">
       <Link>Assets\Content\Tiles\Platform.png</Link>
     </AndroidAsset>
+    <None Include="Properties\AndroidManifest.xml" />
   </ItemGroup>
   <ItemGroup>
     <AndroidResource Include="Resources\layout\Main.axml" />

+ 9 - 9
StarterKits/Android/VectorRumble/Resources/Resource.designer.cs

@@ -1,12 +1,12 @@
-// ------------------------------------------------------------------------------
-//  <autogenerated>
-//      This code was generated by a tool.
-//      Mono Runtime Version: 4.0.30319.1
-// 
-//      Changes to this file may cause incorrect behavior and will be lost if 
-//      the code is regenerated.
-//  </autogenerated>
-// ------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.239
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
 
 namespace VectorRumble
 {

+ 3 - 0
StarterKits/Android/VectorRumble/VectorRumble.csproj

@@ -280,5 +280,8 @@
     <AndroidAsset Include="..\..\MacOS\VectorRumble\Content\Textures\title.png">
       <Link>Assets\Content\Textures\title.png</Link>
     </AndroidAsset>
+    <AndroidAsset Include="..\..\MacOS\VectorRumble\Content\Textures\gamepad.png">
+      <Link>Assets\Content\Textures\gamepad.png</Link>
+    </AndroidAsset>
   </ItemGroup>
 </Project>

BIN
StarterKits/MacOS/VectorRumble/Content/Textures/gamepad.png


+ 3 - 3
StarterKits/MacOS/VectorRumble/Game.cs

@@ -42,10 +42,10 @@ namespace VectorRumble
             Content.RootDirectory = "Content";
 			
 #if WINDOWS_PHONE || IOS || ANDROID // WP7, iPad or Tablets only
-            graphics.PreferredBackBufferWidth = 1024;
-            graphics.PreferredBackBufferHeight = 748;
+            graphics.PreferredBackBufferWidth = 800;
+            graphics.PreferredBackBufferHeight = 480;
 			graphics.IsFullScreen = true;
-			//graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
+			graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft;
 #else
 			graphics.PreferredBackBufferWidth = 1280;
             graphics.PreferredBackBufferHeight = 720;

+ 10 - 0
StarterKits/MacOS/VectorRumble/ScreenManager/InputState.cs

@@ -10,6 +10,9 @@
 #region Using Statements
 using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Input;
+#if ANDROID
+using Microsoft.Xna.Framework.Input.Touch;
+#endif
 #endregion
 
 namespace VectorRumble
@@ -32,6 +35,10 @@ namespace VectorRumble
 
         public readonly KeyboardState[] LastKeyboardStates;
         public readonly GamePadState[] LastGamePadStates;
+		
+#if ANDROID
+		public TouchCollection CurrentTouchState;
+#endif		
 
         #endregion
 
@@ -150,6 +157,9 @@ namespace VectorRumble
                 CurrentKeyboardStates[i] = Keyboard.GetState((PlayerIndex)i);
                 CurrentGamePadStates[i] = GamePad.GetState((PlayerIndex)i);
             }
+#if ANDROID			
+			CurrentTouchState = TouchPanel.GetState();
+#endif			
         }
 
 

+ 22 - 0
StarterKits/MacOS/VectorRumble/Screens/GameplayScreen.cs

@@ -36,6 +36,7 @@ namespace VectorRumble
         SpriteBatch spriteBatch;
         SpriteFont spriteFont;
         Texture2D starTexture;
+		Texture2D gamePadTexture;
         World world;
         AudioManager audio;
         bool gameOver;
@@ -100,6 +101,23 @@ namespace VectorRumble
             lineBatch.SetProjection(Matrix.CreateOrthographicOffCenter(0.0f,
                 ScreenManager.GraphicsDevice.Viewport.Width, 
                 ScreenManager.GraphicsDevice.Viewport.Height, 0.0f, 0.0f, 1.0f));
+#if ANDROID || IOS
+			gamePadTexture = content.Load<Texture2D>("Textures/gamepad");
+			
+			ThumbStickDefinition thumbStickLeft = new ThumbStickDefinition();
+			thumbStickLeft.Position = new Vector2(10,400);
+			thumbStickLeft.Texture = gamePadTexture;
+			thumbStickLeft.TextureRect = new Rectangle(2,2,68,68);
+			
+			GamePad.LeftThumbStickDefinition = thumbStickLeft;
+			
+			ThumbStickDefinition thumbStickRight = new ThumbStickDefinition();
+			thumbStickRight.Position = new Vector2(240,400);
+			thumbStickRight.Texture = gamePadTexture;
+			thumbStickRight.TextureRect = new Rectangle(2,2,68,68);
+			
+			GamePad.RightThumbStickDefinition = thumbStickRight;
+#endif			
         }
 
 
@@ -239,6 +257,10 @@ namespace VectorRumble
             }
 
             DrawHud(elapsedTime);
+			
+#if ANDROID || IOS || WINDOWS_PHONE			
+			GamePad.Draw(gameTime, spriteBatch);
+#endif			
 
             // If the game is transitioning on or off, fade it out to black.
             if (TransitionPosition > 0)

+ 33 - 1
StarterKits/MacOS/VectorRumble/Screens/MenuScreen.cs

@@ -82,7 +82,39 @@ namespace VectorRumble
         /// or cancelling the menu.
         /// </summary>
         public override void HandleInput(InputState input)
-        {
+        {		
+#if ANDROID
+			var touch = input.CurrentTouchState;
+			if (touch.Count > 0)
+			{
+				Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
+	            Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
+	
+	            Vector2 position = new Vector2(0f, viewportSize.Y * 0.55f);
+				foreach(var t in touch)
+				{
+					// we have a touch event
+					if (t.State == Microsoft.Xna.Framework.Input.Touch.TouchLocationState.Pressed)
+					{
+						var pos = t.Position;
+						for (int i = 0; i < menuEntries.Count; i++)            			
+						{
+							// Draw text, centered on the middle of each line.
+			                Vector2 size = ScreenManager.Font.MeasureString(menuEntries[i].Text);	
+							position.X = viewportSize.X / 2f - size.X / 2f;
+							var rect = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
+							if (rect.Contains(pos))
+							{
+								selectedEntry = i;
+								OnSelectEntry(selectedEntry);
+								break;
+							}
+			                position.Y += ScreenManager.Font.LineSpacing;
+						}
+					}					
+                 }
+			}
+#endif			
             // Move to the previous menu entry?
             if (input.MenuUp)
             {

+ 1 - 1
StarterKits/MonoGame.StarterKits.Android.sln

@@ -55,6 +55,6 @@ Global
 		{9B7D8FCF-5A3B-48D6-B9E7-4C3C0D0632F6} = {ED1C24CA-3D94-4BDF-9B56-1B5866E40BB2}
 	EndGlobalSection
 	GlobalSection(MonoDevelopProperties) = preSolution
-		StartupItem = Android\Platformer\Platformer.csproj
+		StartupItem = Android\VectorRumble\VectorRumble.csproj
 	EndGlobalSection
 EndGlobal