Skip to content

Commit

Permalink
Surface Dial support
Browse files Browse the repository at this point in the history
  • Loading branch information
tomverhoeff committed Nov 11, 2016
1 parent af9b499 commit bb0a3ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Space Invaders/Player.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Windows.UI.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
Expand All @@ -11,6 +12,8 @@ class Player
// Variables
private Image playerSprite;
private Image playerBullet;
private RadialController Controller;
private RadialControllerMenuItem MenuItem;

private BitmapImage playerBitmapImage = new BitmapImage(new Uri("ms-appx:///Assets/Sprites/player.png"));
private BitmapImage invaderKilledImage = new BitmapImage(new Uri("ms-appx:///Assets/Sprites/explosion.png"));
Expand Down Expand Up @@ -48,6 +51,24 @@ public Player(Canvas canvas, int playerGameScore)

playerSprite.Source = playerBitmapImage;
canvas.Children.Add(playerSprite);

Controller = RadialController.CreateForCurrentView();
Controller.RotationResolutionInDegrees = 2;
Controller.RotationChanged += Controller_RotationChanged;
Controller.ButtonClicked += Controller_ButtonClicked;

MenuItem = RadialControllerMenuItem.CreateFromKnownIcon("SpaceInvaders", RadialControllerMenuKnownIcon.PenType);
Controller.Menu.Items.Add(MenuItem);
}

private void Controller_ButtonClicked(RadialController sender, RadialControllerButtonClickedEventArgs args)
{
isShooting = true;
}

private void Controller_RotationChanged(RadialController sender, RadialControllerRotationChangedEventArgs args)
{
Canvas.SetLeft(playerSprite, Canvas.GetLeft(playerSprite) + 2 * args.RotationDeltaInDegrees);
}

//Draw and update all object for every game frame
Expand Down
2 changes: 1 addition & 1 deletion Space Invaders/Space Invaders.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AssemblyName>Space Invaders</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
<TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<EnableDotNetNativeCompatibleProfile>true</EnableDotNetNativeCompatibleProfile>
Expand Down

0 comments on commit bb0a3ba

Please sign in to comment.