Browse Source

Merge pull request #83 from AtomicGameEngine/JME-ATOMICNET-WORK

Updates for AtomicBlaster on mobile
JoshEngebretson 9 years ago
parent
commit
0942d57912

+ 10 - 10
AtomicNET/AtomicBlaster/Project/AtomicNET/Platforms/Android/Resources/Resource.Designer.cs

@@ -1,15 +1,15 @@
 #pragma warning disable 1591
-//------------------------------------------------------------------------------
-// <auto-generated>
-//     This code was generated by a tool.
-//     Runtime Version:4.0.30319.42000
-//
-//     Changes to this file may cause incorrect behavior and will be lost if
-//     the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------
+//  <autogenerated>
+//      This code was generated by a tool.
+//      Mono Runtime Version: 4.0.30319.42000
+// 
+//      Changes to this file may cause incorrect behavior and will be lost if 
+//      the code is regenerated.
+//  </autogenerated>
+// ------------------------------------------------------------------------------
 
-[assembly: global::Android.Runtime.ResourceDesignerAttribute("Application.Resource", IsApplication=true)]
+[assembly: Android.Runtime.ResourceDesignerAttribute("Application.Resource", IsApplication=true)]
 
 namespace Application
 {

+ 25 - 0
AtomicNET/AtomicBlaster/Project/AtomicNET/Platforms/iOS/AppUIDelegate.cs

@@ -0,0 +1,25 @@
+using Foundation;
+using UIKit;
+using System.Threading.Tasks;
+
+using AtomicEngine;
+using AtomicBlaster;
+
+namespace AtomicPlayer
+{
+	[Register("AppUIDelegate")]
+	public partial class AppUIDelegate : UIApplicationDelegate
+	{
+		public override bool FinishedLaunching(UIApplication app, NSDictionary options)
+		{
+			LaunchGame();
+			return true;
+		}
+
+		async void LaunchGame()
+		{
+			await Task.Yield();
+			Application.Run<GameRoot>(new string[0]);
+		}
+	}
+}

+ 6 - 0
AtomicNET/AtomicBlaster/Project/AtomicNET/Platforms/iOS/Entitlements.plist

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+	<dict>
+	</dict>
+</plist>

+ 38 - 0
AtomicNET/AtomicBlaster/Project/AtomicNET/Platforms/iOS/Info.plist

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleIdentifier</key>
+	<string>com.atomicgameengine.atomicblaster</string>
+	<key>CFBundleShortVersionString</key>
+	<string>1.0</string>
+	<key>CFBundleVersion</key>
+	<string>1.0</string>
+	<key>UIDeviceFamily</key>
+	<array>
+		<integer>1</integer>
+		<integer>2</integer>
+	</array>
+	<key>UISupportedInterfaceOrientations</key>
+	<array>
+		<string>UIInterfaceOrientationLandscapeLeft</string>
+		<string>UIInterfaceOrientationLandscapeRight</string>
+	</array>
+	<key>UISupportedInterfaceOrientations~ipad</key>
+	<array>
+		<string>UIInterfaceOrientationLandscape</string>
+	</array>
+	<key>MinimumOSVersion</key>
+	<string>9.3</string>
+	<key>CFBundleIconFiles</key>
+	<array>
+		<string>Data/Icon</string>
+	</array>
+	<key>UIStatusBarHidden</key>
+	<true/>
+	<key>CFBundleName</key>
+	<string>AtomicBlaster</string>
+	<key>UIRequiresFullScreen</key>
+	<true/>
+</dict>
+</plist>

+ 13 - 0
AtomicNET/AtomicBlaster/Project/AtomicNET/Platforms/iOS/Main.cs

@@ -0,0 +1,13 @@
+using UIKit;
+
+namespace AtomicPlayer
+{
+	public class AtomicApp
+	{
+		// This is the main entry point of the application.
+		static void Main(string[] args)
+		{
+			UIApplication.Main(args, null, "AppUIDelegate");
+		}
+	}
+}

+ 36 - 0
AtomicNET/AtomicBlaster/Project/AtomicNET/Platforms/iOS/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("AtomicBlaster")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("AtomicBlaster")]
+[assembly: AssemblyCopyright("Copyright ©  2015")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components.  If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("3a72e714-15ce-4707-ba90-e389fb7c9b2c")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 9 - 3
AtomicNET/AtomicBlaster/Resources/Scripts/GameRoot.cs

@@ -58,7 +58,10 @@ namespace AtomicBlaster
 
             float amt = (float)Math.Sqrt(ScreenBounds.Width * ScreenBounds.Height / maxGridPoints);
             Vector2 gridSpacing = new Vector2(amt, amt);
-            Grid = new Grid(ScreenBounds, gridSpacing);
+
+            IntRect expandedBounds = ScreenBounds;
+            expandedBounds.Inflate((int)gridSpacing.X, (int)gridSpacing.Y);
+            Grid = new Grid(expandedBounds, gridSpacing);
 
             EntityManager.Add(PlayerShip.Instance);
 
@@ -87,15 +90,18 @@ namespace AtomicBlaster
             
             float time = eventData.GetFloat("timestep");
 
-            deltaTime += time;
+            ElapsedTime += time;
 
-            ElapsedTime += time;// / 2.0f;
+#if !ATOMIC_IOS
+            deltaTime += time;
 
             if (deltaTime < 1.0f / 60.0f)
                 return;
 
             deltaTime = 0.0f;
 
+#endif
+
             ShipInput.Update();
 
             if (!paused)

+ 12 - 11
AtomicNET/AtomicBlaster/Resources/Scripts/PlayerShip.cs

@@ -55,6 +55,18 @@ namespace AtomicBlaster
                 return;
             }
 
+            const float speed = 8;
+
+            Velocity += speed * ShipInput.GetMovementDirection();
+
+            Position += Velocity;
+            Position = Vector2.Clamp(Position, Size / 2, GameRoot.ScreenSize - Size / 2);
+
+            if (Velocity.LengthSquared > 0)
+                Orientation = Velocity.ToAngle();
+
+            MakeExhaustFire();
+
             var aim = ShipInput.GetAimDirection();
 
             if (aim.LengthSquared > 0 && cooldowmRemaining <= 0)
@@ -78,17 +90,6 @@ namespace AtomicBlaster
             if (cooldowmRemaining > 0)
                 cooldowmRemaining--;
 
-            const float speed = 8;
-
-            Velocity += speed * ShipInput.GetMovementDirection();
-
-            Position += Velocity;
-            Position = Vector2.Clamp(Position, Size / 2, GameRoot.ScreenSize - Size / 2);
-
-            if (Velocity.LengthSquared > 0)
-                Orientation = Velocity.ToAngle();
-
-            MakeExhaustFire();
             Velocity = Vector2.Zero;
         }
 

+ 55 - 1
AtomicNET/AtomicBlaster/Resources/Scripts/ShipInput.cs

@@ -13,6 +13,7 @@ namespace AtomicBlaster
     static class ShipInput
     {
         private static bool isAimingWithMouse = false;
+        static IntVector2 lastTouchPos = IntVector2.Zero;
 
         public static void Update()
         {
@@ -26,6 +27,7 @@ namespace AtomicBlaster
 
             Vector2 direction = new Vector2(0, 0);
 
+#if ATOMIC_DESKTOP
             if (input.GetKeyDown((int) SDL.SDL_Keycode.SDLK_a))
                 direction.X -= 1;
             if (input.GetKeyDown((int)SDL.SDL_Keycode.SDLK_d))
@@ -34,9 +36,43 @@ namespace AtomicBlaster
                 direction.Y -= 1;
             if (input.GetKeyDown((int)SDL.SDL_Keycode.SDLK_w))
                 direction.Y += 1;
+#endif      
 
+#if ATOMIC_MOBILE
 
+            var touchPos = lastTouchPos;
+
+            if (input.NumTouches == 1)
+            {
+                touchPos = input.GetTouchPosition(0);
+                lastTouchPos = touchPos;
+
+            }
+
+            if (touchPos != IntVector2.Zero)
+            {
+                direction = new Vector2((float)touchPos.X, (float)touchPos.Y);
+            }
+
+
+            Vector2 shipPos = PlayerShip.Instance.Position;
+
+            shipPos.Y = GameRoot.ScreenBounds.Height - shipPos.Y;
+
+            direction -= shipPos;
+
+            direction.Y = -direction.Y;
+
+            if (touchPos == IntVector2.Zero || direction.Length < 4.0f)
+                direction = Vector2.Zero;
+
+#endif
+
+#if ATOMIC_IOS
+            uint numJoySticks = 0;
+#else
             uint numJoySticks = input.GetNumJoysticks();
+#endif
 
             if (numJoySticks > 0)
             {
@@ -73,7 +109,18 @@ namespace AtomicBlaster
         {
             var input = AtomicNET.GetSubsystem<Input>();
 
+            Vector2 direction = new Vector2();
+
+#if ATOMIC_DESKTOP
+            direction = new Vector2((float)input.GetMousePosition().X, (float)input.GetMousePosition().Y);            
+
+#endif
+
+#if ATOMIC_IOS
+            uint numJoySticks = 0;
+#else
             uint numJoySticks = input.GetNumJoysticks();
+#endif
 
             if (numJoySticks > 0)
             {
@@ -102,7 +149,14 @@ namespace AtomicBlaster
 
             }
 
-            Vector2 direction = new Vector2((float)input.GetMousePosition().X, (float)input.GetMousePosition().Y);            
+#if !ATOMIC_MOBILE
+                direction = new Vector2((float)input.GetMousePosition().X, (float)input.GetMousePosition().Y);
+#else
+            {
+                direction = PlayerShip.Instance.Velocity;
+                return Vector2.Normalize(direction);
+            }
+#endif
 
             Vector2 shipPos = PlayerShip.Instance.Position;