using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using BlueRoseGames.Helpers.Timers;
using BlueRoseGames.Helpers.Keyboard;
namespace SpaceRocks
{
public partial class Page : UserControl
{
CompositionTargetGameLoop gameLoop;
KeyHandler keyHandler;
double rotationSpeed = 150;
public Page()
{
InitializeComponent();
this.GotFocus += new RoutedEventHandler(Page_GotFocus);
this.LostFocus += new RoutedEventHandler(Page_LostFocus);
this.MouseLeftButtonDown += new MouseButtonEventHandler(Page_MouseLeftButtonDown);
gameLoop = new CompositionTargetGameLoop();
gameLoop.Update += new GameLoop.UpdateHandler(gameLoop_Update);
keyHandler = new KeyHandler(this);
}
void Page_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
clickToStart.Visibility = Visibility.Collapsed;
gameLoop.Start();
}
void Page_LostFocus(object sender, RoutedEventArgs e)
{
clickToStart.Visibility = Visibility.Visible;
gameLoop.Stop();
}
void Page_GotFocus(object sender, RoutedEventArgs e)
{
clickToStart.Visibility = Visibility.Collapsed;
gameLoop.Start();
}
void gameLoop_Update(object sender, TimeSpan elapsed)
{
// do your game loop processing here
if (keyHandler.IsKeyPressed(Key.A) || keyHandler.IsKeyPressed(Key.Left))
{
ship.RotationAngle -= rotationSpeed * elapsed.TotalSeconds;
}
else if (keyHandler.IsKeyPressed(Key.D) || keyHandler.IsKeyPressed(Key.Right))
{
ship.RotationAngle += rotationSpeed * elapsed.TotalSeconds;
}
}
}
}