Skip to content
Browse files

Updated for Windows 8 Release Preview

  • Loading branch information...
0 parents commit 72b38a20263c754964d2d2f8981ddd26be8b38a6 Dave Isbitski committed Jul 12, 2012
22 .gitattributes
@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+*.sln merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
163 .gitignore
@@ -0,0 +1,163 @@
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+[Dd]ebug/
+[Rr]elease/
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.vspscc
+.builds
+*.dotCover
+
+## TODO: If you have NuGet Package Restore enabled, uncomment this
+#packages/
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+
+# Visual Studio profiler
+*.psess
+*.vsp
+
+# ReSharper is a .NET coding add-in
+_ReSharper*
+
+# Installshield output folder
+[Ee]xpress
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish
+
+# Others
+[Bb]in
+[Oo]bj
+sql
+TestResults
+*.Cache
+ClientBin
+stylecop.*
+~$*
+*.dbmdl
+Generated_Code #added for RIA/Silverlight projects
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+
+
+
+############
+## Windows
+############
+
+# Windows image file caches
+Thumbs.db
+
+# Folder config file
+Desktop.ini
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg
+
+# Mac crap
+.DS_Store
28 Readme.txt
@@ -0,0 +1,28 @@
+Metro Game Kit
+
+Author: Dave Isbitski
+Git: http://github.com/disbitski
+Twitter: http://twitter.com/TheDaveDev
+Blog: http://blogs.msdn.com/davedev
+Web: http://about.met/davedev
+
+Summary:
+
+Space Cadet is a Windows 8 Metro Style App developed using HTML5 and JavaScript. The intent of this code is to help HTML5/JavaScript developers with writing their first Metro Style App in a fun, immersive way. The code for the game is intended for demo purposes only and shoul dbe considered a starting kit for future apps you may write. The game includes a functional game loop as well as the following technologies:
+
+HTML5 Canvas
+HTML5 Audio
+CSS3 Styling and Web Fonts
+Implementing a Game Loop with JavaScript
+Third Party Frameworks
+Touch
+Camera Access
+Accelerometer
+WinJS Controls
+
+DISCLAIMER:
+
+The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Both Microsoft and I do not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
+Microsoft and I do not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Microsoft and I disclaim all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
+
+Microsoft and I shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
46 SpaceCadet.sln
@@ -0,0 +1,46 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 11
+Project("{262852C6-CD72-467D-83FE-5EEB1973A190}") = "SpaceCadet", "SpaceCadet\SpaceCadet.jsproj", "{2666F999-F568-44A2-A589-CA5C477D0B33}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|ARM = Debug|ARM
+ Debug|Any CPU = Debug|Any CPU
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|ARM = Release|ARM
+ Release|Any CPU = Release|Any CPU
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|ARM.ActiveCfg = Debug|ARM
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|ARM.Build.0 = Debug|ARM
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|ARM.Deploy.0 = Debug|ARM
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|x64.ActiveCfg = Debug|x64
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|x64.Build.0 = Debug|x64
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|x64.Deploy.0 = Debug|x64
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|x86.ActiveCfg = Debug|x86
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|x86.Build.0 = Debug|x86
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Debug|x86.Deploy.0 = Debug|x86
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|ARM.ActiveCfg = Release|ARM
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|ARM.Build.0 = Release|ARM
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|ARM.Deploy.0 = Release|ARM
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|x64.ActiveCfg = Release|x64
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|x64.Build.0 = Release|x64
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|x64.Deploy.0 = Release|x64
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|x86.ActiveCfg = Release|x86
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|x86.Build.0 = Release|x86
+ {2666F999-F568-44A2-A589-CA5C477D0B33}.Release|x86.Deploy.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
95 SpaceCadet/SpaceCadet.jsproj
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|AnyCPU">
+ <Configuration>Debug</Configuration>
+ <Platform>AnyCPU</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|ARM">
+ <Configuration>Debug</Configuration>
+ <Platform>ARM</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x86">
+ <Configuration>Debug</Configuration>
+ <Platform>x86</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|AnyCPU">
+ <Configuration>Release</Configuration>
+ <Platform>AnyCPU</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|ARM">
+ <Configuration>Release</Configuration>
+ <Platform>ARM</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x86">
+ <Configuration>Release</Configuration>
+ <Platform>x86</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>2666f999-f568-44a2-a589-ca5c477d0b33</ProjectGuid>
+ </PropertyGroup>
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).Default.props" />
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).props" />
+ <PropertyGroup>
+ <TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
+ <TargetPlatformVersion>8.0</TargetPlatformVersion>
+ <DefaultLanguage>en-US</DefaultLanguage>
+ <PackageCertificateKeyFile>SpaceCadet_TemporaryKey.pfx</PackageCertificateKeyFile>
+ </PropertyGroup>
+ <ItemGroup>
+ <AppxManifest Include="package.appxmanifest">
+ <SubType>Designer</SubType>
+ </AppxManifest>
+ <Content Include="css\space.css" />
+ <Content Include="default.html" />
+ <Content Include="fonts\FINALOLD.TTF" />
+ <Content Include="images\accept.png" />
+ <Content Include="images\explosion.png" />
+ <Content Include="images\helmet.png" />
+ <Content Include="images\logo.png" />
+ <Content Include="images\menutitle.png" />
+ <Content Include="images\ship.png" />
+ <Content Include="images\ship1.png" />
+ <Content Include="images\ship2.png" />
+ <Content Include="images\Ship3.png" />
+ <Content Include="images\smalllogo.png" />
+ <Content Include="images\splashscreen.png" />
+ <Content Include="images\starfield.jpg" />
+ <Content Include="images\storelogo.png" />
+ <Content Include="css\default.css" />
+ <Content Include="js\default.js" />
+ <Content Include="js\ship.js" />
+ <Content Include="js\sound.js" />
+ <Content Include="js\starField.js" />
+ <Content Include="page.html" />
+ <Content Include="sounds\hydrogen.mp3" />
+ <Content Include="sounds\laser1.mp3" />
+ <Content Include="sounds\laser2.mp3" />
+ <Content Include="sounds\laser3.mp3" />
+ <Content Include="sounds\newlevel.mp3" />
+ <Content Include="sounds\pulse.mp3" />
+ <Content Include="sounds\redalert.mp3" />
+ <None Include="SpaceCadet_TemporaryKey.pfx" />
+ </ItemGroup>
+ <ItemGroup>
+ <SDKReference Include="Microsoft.WinJS.1.0.RC, Version=1.0" />
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
BIN SpaceCadet/SpaceCadet_TemporaryKey.pfx
Binary file not shown.
60 SpaceCadet/css/default.css
@@ -0,0 +1,60 @@
+html, body {
+ height: 100%;
+ margin: 0;
+ padding: 0;
+}
+
+body {
+ -ms-box-align: middle;
+ -ms-box-orient: vertical;
+ -ms-box-pack: center;
+ display: -ms-box;
+}
+
+.fixedlayout {
+ -ms-grid-columns: 1fr;
+ -ms-grid-rows: 1fr;
+ display: -ms-grid;
+ height: 768px;
+ width: 1024px;
+}
+
+@media screen and (-ms-view-state: fullscreen-landscape) {
+}
+
+@media screen and (-ms-view-state: filled) {
+}
+
+@media screen and (-ms-view-state: snapped) {
+ #imgMenu {
+ -ms-transform: translate(0px, 0px) rotate(0deg) scale(0.50);
+ }
+
+ #btnStart {
+ -ms-transform: translate(0px, 0px) rotate(0deg) scale(0.60);
+ }
+
+ #txtNewLevel {
+ -ms-transform: translate(0px, 0px) rotate(0deg) scale(0.30);
+ }
+
+ #imgPlayer {
+ opacity: 0;
+ }
+
+ #txtLevel {
+ -ms-transform: translate(-120px, 0px) rotate(0deg) scale(0.30);
+ }
+
+ #txtPlayerName {
+ -ms-transform: translate(70px, 0px) rotate(0deg) scale(0.30);
+ }
+
+ #txtScore {
+ -ms-transform: translate(0px, 0px) rotate(0deg) scale(0.30);
+ }
+
+}
+
+@media screen and (-ms-view-state: fullscreen-portrait) {
+}
80 SpaceCadet/css/space.css
@@ -0,0 +1,80 @@
+@font-face {
+ font-family: 'Final Frontier Old Style';
+ src: url( '/fonts/finalold.ttf');
+
+}
+
+#txtScore {
+ font-family: 'Final Frontier Old Style';
+ font-size: 50px;
+ color: #ffd800;
+ text-align: left;
+ margin-left: 10px;
+}
+
+#txtPlayerName {
+ font-family: 'Final Frontier Old Style';
+ font-size: 50px;
+ color: #ffd800;
+ float:left;
+ margin-right:20px;
+
+}
+
+#txtLevel {
+ font-family: 'Final Frontier Old Style';
+ font-size: 50px;
+ color: #ffd800;
+ position:absolute;
+ top: 0;
+}
+
+#divPlayer {
+ position: absolute;
+ top: 0;
+ right: 0;
+ text-align:right;
+}
+
+#imgMenu {
+ position:absolute;
+ max-width: 555px;
+ max-height: 118px;
+ top: 120px;
+}
+
+#imgPlayer {
+ max-width: 100px;
+ max-height: 50px;
+ float:left;
+ margin-right:10px;
+
+}
+
+#txtVersion {
+ position:absolute;
+ bottom:0;
+ right:0;
+ font-family: 'Final Frontier Old Style';
+ font-size: 20px;
+ color: #ffd800;
+}
+
+#btnStart {
+ position:absolute;
+ width: 300px;
+ height: 150px;
+ font-family: 'Final Frontier Old Style';
+ font-size: 30px;
+ z-index: 100;
+}
+
+#txtNewLevel {
+ position:absolute;
+ font-family: 'Final Frontier Old Style';
+ font-size: 100px;
+ visibility: hidden;
+}
+
+
+
66 SpaceCadet/default.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>SpaceCadet</title>
+
+ <!-- WinJS References -->
+ <link href="//Microsoft.WinJS.1.0.RC/css/ui-dark.css" rel="stylesheet" />
+ <script src="//Microsoft.WinJS.1.0.RC/js/base.js"></script>
+ <script src="//Microsoft.WinJS.1.0.RC/js/ui.js"></script>
+
+ <!-- App References -->
+ <link href="/css/default.css" rel="stylesheet">
+ <link href="/css/space.css" rel="stylesheet"/>
+ <script src="/js/default.js"></script>
+ <script src="/js/sound.js"></script>
+ <script src="/js/ship.js"></script>
+ <script src="/js/starField.js"></script>
+
+</head>
+<body style="background-image: url('/images/starfield.jpg');">
+
+<div id="divGame">
+ <div id="txtScore">Score: 0</div>
+ <div id="txtLevel">Level: 0</div>
+ <div id="divPlayer">
+ <div id="txtPlayerName">Player1</div>
+ <img id="imgPlayer" src="/images/helmet.png" />
+ </div>
+<div>
+<div id="divMenu">
+ <img id="imgMenu" src="/images/menutitle.png" />
+
+ <div id="txtVersion"></div>
+ <button id="btnStart">PLAY</button>
+ <div>
+<div id="txtNewLevel"></div>
+
+<div id="divRoot" data-win-control="WinJS.UI.ViewBox">
+ <canvas id="canvas" ></canvas>
+</div>
+
+
+ <div id="AppBar" data-win-control="WinJS.UI.AppBar" data-win-options="">
+ <button id="cmdHome" data-win-control="WinJS.UI.AppBarCommand" data-win-options="{id:'cmdHome',label:'Menu',icon:'home',section:'selection',tooltip:'Menu'}">
+ </button>
+ <button id="cmdCamera" data-win-control ="WinJS.UI.AppBarCommand" data-win-options="{id:'cmdCamera',label:'Cadet Photo',icon:'camera',section:'global',tooltip:'Change Cadet Photo'}">
+ </button>
+ <button id="cmdName" data-win-control ="WinJS.UI.AppBarCommand" data-win-options="{id:'cmdName',label:'Cadet Name',icon:'url(images/accept.png)',section:'global',tooltip:'Change Cadet Name',type:'flyout',flyout:'nameFlyout'}">
+ </button>
+ </div>
+
+ <div id="nameFlyout" data-win-control="WinJS.UI.Flyout">
+ <div>
+ <p>
+ <label>Cadet Name<br />
+ </label>
+ <input type="text" id="cadetName" />
+ </p>
+ </div>
+ <button id="submitButton">Save</button>
+</div>
+
+
+</body>
+</html>
BIN SpaceCadet/fonts/FINALOLD.TTF
Binary file not shown.
BIN SpaceCadet/images/Ship3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/accept.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/explosion.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/helmet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/menutitle.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/ship.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/ship1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/ship2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/smalllogo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/splashscreen.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/starfield.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN SpaceCadet/images/storelogo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
541 SpaceCadet/js/default.js
@@ -0,0 +1,541 @@
+/// <reference path="sound.js" />
+/// <reference path="ship.js" />
+/// <reference path="starField.js" />
+
+// Title: Space Cadet
+// Version 1.0
+// Desc: Fun Space Game to demonstrate Win8 Metro Style App using HTML5 Canvas, CSS3,
+// Accelerometer, Camera, Touch, and Trial APIs
+//
+// Author: David Isbitski
+// Technology Evangelist, Windows 8
+// Microsoft
+//
+// Contact: david.isbitski@microsoft.com, twitter.com/thedavedev, blogs.msdn.com/davedev, github.com/disbitski, slideshare.net/disbitski
+//
+// Last Mod: 6/7/12
+//
+// Special Thanks To:
+// Mark Hindsbo - Developer of starField.js which is used in the Menu Screen
+//
+// Grant Skinner - Developer of SoundJS, whch is used throughout the game for sound effects
+// http://Soundjs.com
+//
+// Bob Familiar - Menu Screen music is called Hydrogen//[h] from Bob's Elements3 Album.
+// http://www.cdbaby.com/cd/BobFamiliar
+
+(function () {
+ "use strict";
+
+ var app = WinJS.Application;
+ var activation = Windows.ApplicationModel.Activation;
+ WinJS.strictProcessing();
+
+ //Version
+ var GAME_VERSION = "1.00";
+
+ //ship and screen constants
+ var POINTS_SHIPHIT = 100;
+ var SNAPPED_VIEW = 320;
+ var SCREEN_WIDTH = 1366;
+ var SCREEN_HEIGHT = 768;
+ var FULLSCREEN_WIDTH = 1366; //To fix current CP bug
+ var SHIP_WIDTH = 190;
+ var SHIP_HEIGHT = 100;
+ var MAX_ACCEL = 17;
+ var MIN_ACCEL = 7;
+ var MAX_X;
+ var MAX_Y;
+ var MAX_SHIPS = 4;
+ var DESTROYED_RENDER_FRAMES = 15;
+ var LEVEL_RENDER_FRAMES = 10;
+ var LEVEL_PTS_REQ = 2000;
+ var LEVEL_SPEED_INCREASE = 0.1;
+ var GRAVITY_WAVE_PTS_REQ = 1500; //1000 for rest, 4000 real gameplay
+
+
+ //initial player score
+ var score = 0;
+ var scoreGravity = 0;
+
+ //canvas and context
+ var canvas;
+ var ctx;
+
+ //camera
+ var capturedPhoto;
+
+ //accelerometer
+ var accelerometer;
+ var intervalId = 0;
+ var getReadingInterval = 0;
+
+ //ships
+ var ships = new Array(MAX_SHIPS);
+
+ //error handler
+ var errorMsg = "";
+
+ //Trial Mode
+ var isLicensed = false;
+
+ //Starfield
+ var stars;
+ var screenHeight;
+ var screenWidth;
+ var thisTime;
+ var deltaTime;
+ var lastTime;
+
+ //Game Mode
+ var menuEnabled = true;
+
+ //Menu Music
+ var musicPlaying = false;
+ var musicMenu = new Audio("/sounds/hydrogen.mp3");
+ //var musicGame = new Audio("/sounds/crazy_comets.wav");
+ var musicGame = new Audio("/sounds/hydrogen.mp3");
+ musicMenu.loop = true;
+
+
+ musicGame.loop = true;
+
+
+ //soundeffects
+ var lasers = new Array();
+ lasers[0] = "laser1";
+ lasers[1] = "laser2";
+ lasers[2] = "laser3";
+
+ //animation handler
+ var anim = null;
+
+ //levels
+ var lvlCurrent = 0;
+ var lvlNextPts = LEVEL_PTS_REQ;
+ var lvlDifficulty = LEVEL_SPEED_INCREASE;
+
+
+ app.onactivated = function (args) {
+ if (args.detail.kind === activation.ActivationKind.launch) {
+ if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
+ // TODO: This application has been newly launched. Initialize
+ // your application here.
+ } else {
+ // TODO: This application has been reactivated from suspension.
+ // Restore application state here.
+ }
+ args.setPromise(WinJS.UI.processAll());
+ }
+ };
+
+ function gravityWave() {
+ //playSound("gravitywave");
+ for (var i = 0; i < MAX_SHIPS; i++) {
+ ships[i] = destroyShip(ships[i]);
+ }
+ }
+
+ //Accelerometer has been shaken and now we need to grant the bonus power
+ function onShakenAccel(event) {
+ //Stop Listening to Accelerometer
+ accelerometer.removeEventListener("shaken", onShakenAccel);
+
+ //Gravity Wave Power - Destory all ships
+ gravityWave();
+
+ }
+
+ //Init Accelerometer
+ function initAccel() {
+ accelerometer = Windows.Devices.Sensors.Accelerometer.getDefault();
+ if (accelerometer) {
+ // Choose a report interval supported by the sensor
+ var minimumReportInterval = accelerometer.minimumReportInterval;
+ var reportInterval = minimumReportInterval > 16 ? minimumReportInterval : 16;
+ accelerometer.reportInterval = reportInterval;
+ getReadingInterval = reportInterval * 2; // double the interval for display (to reduce CPU usage)
+
+ } else {
+ displayError("No accelerometer found");
+ }
+ }
+
+
+ function initLicense() {
+ return true;
+ }
+
+
+ //onLoad Event
+ function initialize() {
+ //Init Canvas
+ canvas = document.getElementById("canvas");
+ ctx = canvas.getContext("2d");
+
+ //CP bug - landscape mode retains snapped width. Backup full width first.
+ FULLSCREEN_WIDTH = window.innerWidth;
+
+ //Set up Coordinates for Screen Size
+ //adjust for different screen sizes
+ canvas.width = window.innerWidth;
+ canvas.height = window.innerHeight;
+ SCREEN_HEIGHT = canvas.height;
+ SCREEN_WIDTH = canvas.width;
+ //Set boundries to be one ship size
+ MAX_X = canvas.width - (SHIP_WIDTH + 20);
+ MAX_Y = canvas.height - (SHIP_HEIGHT + 50);
+
+ //Check Windows Store License
+ isLicensed = initLicense();
+
+ //Set up random location and speeds for all ships
+ initShips();
+
+ //Set up accelerometer for shake events
+ initAccel();
+
+ //Handle View Layout Changes
+ //CP Windows.UI.ViewManagement.ApplicationView.getForCurrentView().addEventListener("viewstatechanged", onViewStateChanged);
+ window.addEventListener("resize", onViewStateChanged);
+
+ //Init starfield
+ lastTime = new Date();
+ lastTime = Number(lastTime.getTime());
+ stars = new StarField(ctx, 500, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, "z", -0.2);
+
+ //Init Sounds
+ SoundJS.addBatch([
+ { name: "redalert", src: "../sounds/redalert.mp3", instances: 1 },
+ { name: "newlevel", src: "../sounds/newlevel.mp3", instances: 1 },
+ { name: "pulse", src: "../sounds/pulse.mp3", instances: 1 },
+ { name: "laser1", src: "../sounds/laser1.mp3", instances: 1 },
+ { name: "laser2", src: "../sounds/laser2.mp3", instances: 1 },
+ { name: "laser3", src: "../sounds/laser3.mp3", instances: 1 }]);
+
+
+ //Handle Touch
+ canvas.addEventListener("MSPointerUp", touchHandler, false);
+ //Save state periodically
+ app.addEventListener("checkpoint", applicationStateCheckpoint, false);
+ //AppBar Commands
+ document.getElementById("cmdCamera").addEventListener("click", capturePhoto, false);
+ document.getElementById("cmdName").addEventListener("click", showCadetNameUpdate, false);
+ document.getElementById("cmdHome").addEventListener("click", showMenu, false);
+ document.getElementById("submitButton").addEventListener("click", updateCadetName, false);
+ //Menu Commands
+ document.getElementById("btnStart").addEventListener("click", startGame, false);
+
+ //Game Menu
+ showMenu();
+
+ //Game Loop - update, draw
+ update();
+
+ app.start();
+
+ }
+
+ //Set Up Menu Screen UI Elements
+ function showMenu(event) {
+ menuEnabled = true;
+
+ txtPlayerName.style.visibility = "hidden";
+ txtScore.style.visibility = "hidden";
+ imgPlayer.style.visibility = "hidden";
+ imgMenu.style.visibility = "visible";
+ btnStart.style.visibility = "visible";
+ txtVersion.innerHTML = GAME_VERSION;
+ txtVersion.style.visibility = "visible";
+ txtLevel.style.visibility = "hidden";
+
+ //Detect View State
+ if (event === 'snapped') {
+ canvas.width = SNAPPED_VIEW;
+ }
+ else if (event === 'filled') {
+ canvas.width = FULLSCREEN_WIDTH - SNAPPED_VIEW;
+ }
+ else {
+ canvas.width = FULLSCREEN_WIDTH;
+ }
+ //Readjust canvas for Snapped/Filled modes
+ canvas.height = window.innerHeight;
+ SCREEN_HEIGHT = canvas.height;
+ SCREEN_WIDTH = canvas.width;
+
+ //Set boundries to be one ship size
+ MAX_X = canvas.width - (SHIP_WIDTH + 20);
+ MAX_Y = canvas.height - (SHIP_HEIGHT + 50);
+
+
+ var menuX, btnX, btnY;
+ menuX = (SCREEN_WIDTH - imgMenu.width) / 2;
+ btnX = (SCREEN_WIDTH - btnStart.clientWidth) / 2;
+ btnY = (SCREEN_HEIGHT - btnStart.clientHeight) / 2;
+
+ imgMenu.style.posLeft = menuX;
+ btnStart.style.posLeft = btnX;
+ btnStart.style.posTop = btnY;
+
+ //clear screen
+ ctx.clearRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+
+ musicGame.pause();
+ musicMenu.play();
+
+ }
+
+ //Set up Game Screen UI Elements
+ function startGame(event) {
+ txtPlayerName.style.visibility="visible";
+ txtScore.style.visibility="visible";
+ imgPlayer.style.visibility = "visible";
+ imgMenu.style.visibility = "hidden";
+ btnStart.style.visibility = "hidden";
+ txtVersion.style.visibility = "hidden";
+ txtLevel.style.visibility = "visible";
+
+ var lvlX = (SCREEN_WIDTH - txtLevel.clientWidth) / 2;
+ txtLevel.style.posLeft = lvlX;
+
+ musicMenu.pause();
+ musicGame.play();
+
+ menuEnabled = false;
+
+ }
+
+ //AppBar Camera Icon Event Handler
+ function clickedPhoto(event) {
+ capturePhoto();
+ }
+
+ //Change Cadet Name from Player1 to custom
+ function updateCadetName(event) {
+ txtPlayerName.innerHTML = document.getElementById("cadetName").value;
+ document.getElementById("nameFlyout").winControl.hide();
+ }
+
+ function showCadetNameUpdate(event) {
+ var cmdNameButton = document.getElementById("cmdName");
+ document.getElementById("nameFlyout").winControl.show(cmdNameButton);
+ }
+
+ //Random acceleration speed
+ function randomAccel(a, b) {
+ return (Math.floor(Math.random() * (1 + b - a))) + a;
+ }
+
+ //Generate ship collection
+ function initShips() {
+ var ship;
+
+ for (var i = 0; i < MAX_SHIPS; i++) {
+ ship = new Ship(MAX_X, MAX_Y, MIN_ACCEL, MAX_ACCEL, lvlDifficulty);
+ ship.img.onload = function () {
+ ctx.drawImage(ship.img, ship.x, ship.y);
+ }
+ ships[i] = ship;
+ }
+ }
+
+ //Save state of current x position
+ function applicationStateCheckpoint() {
+ //TODO: Save State
+ }
+
+ //Verify if point was within the bounds of an actual ship
+ function touchHandler(event) {
+ for (var i = 0; i < MAX_SHIPS; i++) {
+ var ship = ships[i];
+ if (shipHit(ship.x, ship.y, event.x, event.y)) {
+ ships[i] = destroyShip(ship);
+ }
+ }
+ }
+
+ function destroyShip(ship) {
+
+ var r = randomAccel(0, 2);
+ var laserSound = lasers[r];
+ SoundJS.play(laserSound, SoundJS.INTERRUPT_ANY);
+
+ //TODO: Animation Explosion and better sound
+ var explosion = new Image();
+ explosion.onload = function () {
+ ctx.drawImage(explosion, ship.x, ship.y);
+ }
+ explosion.src = "/images/explosion.png";
+ ship.img = explosion;
+ ship.destroyed = true;
+
+ updateScore(POINTS_SHIPHIT);
+
+ return ship;
+ }
+
+ function blowUpAnimation(ship) {
+ if (ship.destroyRendered > DESTROYED_RENDER_FRAMES) {
+ ship = new Ship(MAX_X, MAX_Y, MIN_ACCEL, MAX_ACCEL, lvlDifficulty);
+ }
+ else {
+ ship.destroyRendered += 1;
+ }
+ return ship;
+ }
+
+ //Verify pixels clicked by pointer are within bounds of a ship's drawn pixels
+ function shipHit(shipX, shipY, x, y) {
+ var maxX = shipX + SHIP_WIDTH;
+ var maxY = shipY + SHIP_HEIGHT;
+ if (x >= shipX && x <= maxX && shipX >= 0 && y >= shipY && y <= maxY) {
+ return true;
+ }
+ else {
+ return false;
+ }
+
+ }
+
+ //update player score
+ function updateScore(points) {
+
+ score += points;
+ scoreGravity += points;
+ txtScore.innerHTML = " Score: " + score;
+
+ if (scoreGravity === GRAVITY_WAVE_PTS_REQ) {
+ accelerometer.addEventListener("shaken", onShakenAccel);
+ txtScore.innerHTML = " > SHAKE THAT SCREEN <";
+ scoreGravity = 0;
+ SoundJS.play("pulse", SoundJS.INTERRUPT_ANY);
+ }
+
+ //new level
+ lvlNextPts = (lvlCurrent + 1) * LEVEL_PTS_REQ;
+ if (score >= lvlNextPts) {
+ lvlCurrent++;
+ txtLevel.innerHTML = "Level: " + lvlCurrent;
+ lvlDifficulty = LEVEL_SPEED_INCREASE * lvlCurrent;
+
+ SoundJS.play("newlevel",SoundJS.INTERUPT_ANY);
+
+ }
+
+
+ }
+
+
+ //Game Loop to update x position of ship
+ function update() {
+
+ //RequestAnimationFrame faster pef than setInterval
+ anim = window.msRequestAnimationFrame(update);
+
+ if (menuEnabled) {
+ drawStars();
+ }
+ else {
+ //Game Loop
+ updateShips();
+ drawShips();
+ }
+ }
+
+ //Render starfield to canvas
+ function drawStars() {
+ thisTime = new Date();
+ thisTime = Number(thisTime.getTime());
+ deltaTime = thisTime - lastTime;
+ lastTime = thisTime;
+
+ ctx.clearRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+ stars.update(deltaTime);
+ stars.draw(deltaTime);
+ }
+
+ //Render shipts to canvas
+ function drawShips() {
+ var ship;
+
+ //clear each frame
+ ctx.clearRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+
+ //Render ships to canvas
+ for (var i = 0; i < MAX_SHIPS; i++) {
+ ship = ships[i];
+ ctx.drawImage(ship.img, ship.x, ship.y);
+ if (ship.destroyed) {
+ ships[i] = blowUpAnimation(ship);
+ }
+
+ }
+ }
+
+ //Play Sound Effect
+ function playSound(sound) {
+ setTimeout(function () {
+ SoundJS.play(sound, SoundJS.INTERUPT_NONE, 1, false);
+ }, 100);
+ }
+
+ //Move ship across screen based on that ships acceleration.
+ //If ship has moved one ship length passed beginning of screen move it to beginning
+ function updateShips() {
+ var ship;
+ for (var i = 0; i < MAX_SHIPS; i++) {
+ ship = ships[i];
+ if (ship.x <= -SHIP_WIDTH) {
+ ship.x = SCREEN_WIDTH;
+ ship.y = Math.random() * MAX_Y;
+ ship[i] = ship;
+ }
+ ship.x += -ship.accel;
+ }
+ }
+
+ //WinRT Camera API
+ function capturePhoto() {
+ try {
+ var dialog = new Windows.Media.Capture.CameraCaptureUI();
+ var aspectRatio = { width: 16, height: 9 };
+ dialog.photoSettings.croppedAspectRatio = aspectRatio;
+ dialog.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).then(function (file) {
+ if (file) {
+ imgPlayer.src = URL.createObjectURL(file);
+
+ } else {
+ //No Photo captured
+ }
+ }, function (err) {
+ displayError(err);
+ });
+ } catch (err) {
+ displayError(err);
+ }
+ }
+
+ function displayError(err) {
+ errorMsg = err;
+ }
+
+ function onViewStateChanged(eventArgs) {
+ var viewStates = Windows.UI.ViewManagement.ApplicationViewState, msg;
+ var newViewState = Windows.UI.ViewManagement.ApplicationView.value;
+ if (newViewState === viewStates.snapped) {
+ showMenu('snapped');
+ } else if (newViewState === viewStates.filled) {
+ showMenu('filled');
+ } else if (newViewState === viewStates.fullScreenLandscape) {
+ showMenu('landscape');
+ } else if (newViewState === viewStates.fullScreenPortrait) {
+ //Currently not supported
+ }
+
+ }
+
+ //If Document fully loaded than begin processing
+ document.addEventListener("DOMContentLoaded", initialize, false);
+
+})();
35 SpaceCadet/js/ship.js
@@ -0,0 +1,35 @@
+
+
+ function Ship(MAX_X, MAX_Y, MIN_ACCEL, MAX_ACCEL, LVL_MULTIPLY) {
+
+ this.x = Math.random() * MAX_X;
+ this.y = Math.random() * MAX_Y;
+
+ var speed = randomRanged(MIN_ACCEL, MAX_ACCEL);
+ var extra = speed * LVL_MULTIPLY;
+
+ this.accel = speed + extra;
+ this.img = new Image();
+ this.img.src = randomImg();
+ this.destroyed = false;
+ this.destroyRendered = 0;
+ };
+
+ function randomRanged(a, b) {
+ return (Math.floor(Math.random() * (1 + b - a))) + a;
+ }
+
+ function randomImg() {
+ var images = Array(3);
+
+ //TODO: new ship artwork
+ images[0] = "/images/ship.png";
+ images[1] = "/images/ship1.png";
+ images[2] = "/images/ship2.png";
+ images[3] = "/images/ship3.png";
+
+ var ran = randomRanged(0, 3);
+
+ return images[ran];
+ }
+
43 SpaceCadet/js/sound.js
@@ -0,0 +1,43 @@
+/**
+* EaselJS
+* Visit http://easeljs.com/ for documentation, updates and examples.
+*
+* Copyright (c) 2011 Grant Skinner
+*
+* Permission is hereby granted, free of charge, to any person
+* obtaining a copy of this software and associated documentation
+* files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use,
+* copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following
+* conditions:
+*
+* The above copyright notice and this permission notice shall be
+* included in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+**/
+(function(m){function a(){throw"SoundJS cannot be instantiated";}function n(a,d){this.instances=[];this.name=a;this.src=d;this.loaded=this.canPlay=false;this.length=0}a.AUDIO_TIMEOUT=8E3;a.INTERRUPT_ANY=1;a.INTERRUPT_EARLY=2;a.INTERRUPT_LATE=3;a.INTERRUPT_NONE=4;a.onProgress=null;a.onSoundTimeout=null;a.onSoundLoadError=null;a.onSoundLoadComplete=null;a.onLoadQueueComplete=null;a.onSoundComplete=null;a.soundHash=[];a.loadQueue=[];a.itemsToLoad=0;a.instanceCount=0;a.INST_MAX=35;a.FT=0.0010;a.AUDIO_ERROR=
+"error";a.AUDIO_PROGRESS="progress";a.AUDIO_COMPLETE="canplaythrough";a.AUDIO_ENDED="ended";a.AUDIO_STALLED="stalled";a._master=1;a._currentLoad=0;a.add=function(b,d,c){a.loadQueue.push({name:b,src:d,instances:c});a.loadQueue.length==1?(a.itemsToLoad=1,a.loadNext()):a.itemsToLoad++};a.addBatch=function(b){for(var d=b.length;b.length;)a.loadQueue.push(b.shift());a.loadQueue.length==d?(a.loadNext(),a.itemsToLoad=d):a.itemsToLoad++};a.play=function(b,d,c,e,f){if(b==null||a.soundHash[b]==null||a.soundHash[b].length==
+0||d!=a.INTERRUPT_ANY&&d!=a.INTERRUPT_EARLY&&d!=a.INTERRUPT_LATE&&d!=a.INTERRUPT_NONE&&d!=null)return NaN;if(d==null)d=a.INTERRUPT_NONE;e==null&&(e=false);f||(f=0);c==null||c>1?c=1:c<0&&(c=0);if(f>0)setTimeout(function(){a.beginPlaying(b,d,c,e)},f);else return a.beginPlaying(b,d,c,e);return-1};a.getMasterVolume=function(){return a._master};a.setMasterVolume=function(b){if(Number(b)!=null){b<0?b=0:b>1&&(b=1);var d,c,e;d=a._master;a._master=b;if(a._master!=d)for(e in a.soundHash){c=a.soundHash[e];d=
+c.length;for(b=0;b<d;b++)c[b].volume=c[b].storedVolume*a._master}}};a.remove=function(b,d){var c,e,f;if(b==null)for(c in a.soundHash){f=a.soundHash[c];e=f.length;do a.stop(c,e-1),f[e-1].currentSrc="",document.body.removeChild(f[e-1]),f.pop(),e=f.length,a.instanceCount--;while(e)}else{f=a.soundHash[b];if(f==null)return false;e=f.length;if(d==null){do a.stop(b,e-1),f[e-1].currentSrc="",document.body.removeChild(f[e-1]),f.pop(),e=f.length,a.instanceCount--;while(e)}else{if(d<=0||e<=0)return false;e--;
+for(c=0;c<=e&&c<d;c++)a.stop(b,e-c),f[e-c].currentSrc="",document.body.removeChild(f[e-c]),f.pop(),a.instanceCount--}}return true};a.setVolume=function(b,d,c){var e,f;if(b==null)return false;b*=a._master;if(d==null)for(f in a.soundHash){e=a.soundHash[f];d=e.length;for(c=0;c<d;c++)e[c].storedVolume=b,e[c].volume=b}else{e=a.soundHash[d];if(e==null)return false;d=e.length;if(c==null)for(c=0;c<d;c++)e[c].storedVolume=b,e[c].volume=b;else{if(d<=c)return false;e[c].storedVolume=b;e[c].volume=b}}return true};
+a.getVolume=function(b,d){var c=a.soundHash[b];return c==null||c.length==0?-1:d==null?c[1].storedVolume:c.length<d?-1:c[d].storedVolume};a.setMute=function(b,d,c){var e,f;if(b==null)return false;if(d==null)for(f in a.soundHash){e=a.soundHash[f];d=e.length;for(c=0;c<d;c++)e[c].muted=b}else{e=a.soundHash[d];if(e==null)return false;d=e.length;if(c==null)for(c=0;c<d;c++)e[c].muted=b;else{if(d<=c)return false;e[c].muted=b}}return true};a.pause=function(b,d){var c,e,f,g;if(b==null)for(g in a.soundHash){f=
+a.soundHash[g];e=f.length;for(c=0;c<e;c++)f[c].pause()}else{f=a.soundHash[b];if(f==null)return false;e=f.length;if(d==null)for(c=0;c<e;c++)f[c].pause();else{if(e<=d)return false;f[d].pause()}}return true};a.resume=function(b,d){var c,e,f,g;if(b==null)for(g in a.soundHash){e=a.soundHash[g].length;for(c=0;c<e;c++)f=a.soundHash[g][c],(f.loop||f.currentTime!=f.duration&&f.currentTime!=0)&&f.play()}else{if(a.soundHash[b]==null)return false;e=a.soundHash[b].length;if(d==null)for(c=0;c<e;c++)f=a.soundHash[b][c],
+(f.loop||f.currentTime!=f.duration&&f.currentTime!=0)&&f.play();else{if(e<=d)return false;f=a.soundHash[b][d];(f.loop||f.currentTime!=f.duration&&f.currentTime!=0)&&f.play()}}return true};a.stop=function(b,d){var c,e,f,g;if(b==null)for(g in a.soundHash){e=a.soundHash[g].length;for(c=0;c<e;c++){f=a.soundHash[g][c];try{f.currentTime=0}catch(h){}f.pause()}}else{if(a.soundHash[b]==null)return false;e=a.soundHash[b].length;if(d==null)for(c=0;c<e;c++)f=a.soundHash[b][c],f.currentTime=0,f.pause();else{if(e<=
+d)return false;f=a.soundHash[b][d];f.currentTime=0;f.pause()}}return true};a.isLoaded=function(b){var d=true,c;if(b==null)for(c in a.soundHash){if(d=d&&a.soundHash[c]&&a.soundHash[c][0]&&a.soundHash[c][0].loaded,!d)break}else return a.soundHash[b]&&a.soundHash[b][0]&&a.soundHash[b][0].loaded;return d};a.getNumInstances=function(b){return b==null?instanceCount:a.soundHash[b]?a.soundHash[b].length:-1};a.getMaxInstances=function(){return a.INST_MAX};a.getCurrentLoadProgress=function(){return(a.itemsToLoad-
+a.loadQueue.length-(1-a._currentLoad))/a.itemsToLoad};a.getInstance=function(b,d){return b==null||d<0||!a.soundHash[b]||!a.soundHash[b][d]?null:a.soundHash[b][d]};a.beginPlaying=function(b,d,c,e){var f,g,h,i=false,j=a.soundHash[b];if(!j[0].loaded)throw Error("Audio is not loaded. The source(s) are either not found, or the correct audio formats are not provided.");for(var k=j.length,b=0;b<k;b++){h=j[b];g==null&&d!=a.INTERRUPT_ANY&&d!=a.INTERRUPT_NONE&&(g=h,f=b);if(h.currentTime>=h.duration-a.FT&&!h.loop||
+h.currentTime==0&&h.paused)i=true,k=b;else if(d==a.INTERRUPT_EARLY&&h.currentTime<g.currentTime||d==a.INTERRUPT_LATE&&h.currentTime>g.currentTime)i=true;i&&(g=h,f=b)}d==a.INTERRUPT_ANY&&!g&&(g=j[0],f=0);return g?(g.loop=e,g.storedVolume=c,g.volume=c*a._master,g.currentTime=0,g.paused&&g.play(),f):-1};a.loadNext=function(){if(a.loadQueue.length<=0){if(a.onLoadQueueComplete)a.onLoadQueueComplete()}else{var b=a.loadQueue.shift(),d=b.instances||1,c=b.name,b=b.src,e=a.soundHash[c];if(e==null)e=a.soundHash[c]=
+[];else if(e.length)b=e[0].src;for(var f=e=e.length,d=e+d;f<d;f++){var g=document.createElement("audio");if(f==e)g.timeoutId=setTimeout(function(){a.handleAudioTimeout(g)},a.AUDIO_TIMEOUT),g.addEventListener(a.AUDIO_COMPLETE,a.handleAudioComplete,false),g.addEventListener(a.AUDIO_PROGRESS,a.handleProgress,false),g.addEventListener(a.AUDIO_STALLED,a.handleAudioStall,false),g.addEventListener(a.AUDIO_ERROR,a.handleAudioError,false),g.loaded=false;g.addEventListener(a.AUDIO_ENDED,a.handleEnded,false);
+g.setAttribute("id",c+"_"+f);g.setAttribute("preload","auto");var h;if(b instanceof Array)for(var i=0,j=b.length;i<j;i++){var k=g.appendChild(document.createElement("source"));h=a.getType(b[i]);k.setAttribute("type",h);k.setAttribute("src",b[i])}else h=a.getType(b),g.setAttribute("type",h),g.setAttribute("src",b);g.load();document.body.appendChild(g);a.soundHash[c].push(g);a.instanceCount++}}};a.getType=function(a){switch(a.slice(a.lastIndexOf(".")+1)){case "mp3":return"audio/mpeg";case "ogg":return"audio/ogg";
+case "wav":return"audio/wav";default:throw"'"+a+"' is not a recognized audio file";}};a.handleEnded=function(){if(a.onSoundEnded){var b=this.id.split("_");a.onSoundEnded(this,b[0],b[1])}};a.handleAudioTimeout=function(b){if(a.onSoundTimeout){var d=b.id.split("_");a.onSoundTimeout(b,d[0],d[1])}a.loadNext()};a.handleProgress=function(){try{this.buffered.end()}catch(b){return}a._currentLoad=this.buffered.end()/this.duration;if(a.onProgress)a.onProgress(a.getCurrentLoadProgress())};a.handleAudioError=
+function(){clearTimeout(this.timeoutId);if(a.onSoundLoadError){var b=this.id.split("_");a.onSoundLoadError(this,b[0],b[1])}a.loadNext()};a.handleAudioComplete=function(){var b=this.id.split("_");this.removeEventListener(a.AUDIO_COMPLETE,a.handleAudioComplete,false);clearTimeout(this.timeoutId);this.loaded=true;if(a.onSoundLoadComplete)a.onSoundLoadComplete(this,b[0],b[1]);a.loadNext()};a.handleAudioStall=function(a){setTimeout(function(){testAudioStall(a)},0)};a.testAudioStall=function(){var b=this.id.split("_");
+if(!a.soundHash[b[0]][b[1]].loaded){if(a.onStall)a.onStall(this,b[0],b[1]);a.loadNext()}};m.SoundJS=a;var l=n.prototype;l.add=function(a){this.instances.push(a);this.length=this.instances.length;this.instances.length==1&&a.addEventListener("canplaythrough",function(){a.canplaythrough()})};l.remove=function(a){this.instances.splice(a,1);this.length=this.instances.length};l.canplaythrough=function(){this.loaded=true};m.SoundJSElement=n})(window);
165 SpaceCadet/js/starField.js
@@ -0,0 +1,165 @@
+// --------------------------------
+// Starfield (C) Mark Hindsbo, 2011
+// --------------------------------
+
+// Creates a starfield with numberStars of stars
+// (startX, startY) is the upper left cornor of the canvas where starrfield starts and it is (width, height) in size
+// chose (0,0) and (canvas width, canvas height) for starfield to fill the entire canvas
+// direction = "x"/"y"/"z" indicating which axis stars are moving along. Velocity is in % of width/height/depth per second
+function StarField(context, numberStars, startX, startY, width, height, direction, velocity) {
+ this.context = context; // Context of Canvas on which stars are drawn
+ this.startX = startX;
+ this.startY = startY;
+ this.startZ = 0;
+ this.width = width;
+ this.height = height;
+ this.depth = 1000;
+ this.sx = this.startX + (this.width / 2); // X translation from star coordinates to canvas coordinates
+ this.sy = this.startY + (this.height / 2); // Y translation from star coordinates to canvas coordinates
+ this.direction = direction;
+ this.velocity = velocity;
+
+ this.numStars = numberStars;
+ this.stars = new Array(this.numStars);
+
+ StarField.prototype.createStars = function () {
+ switch (direction) { // Determine what speed is in absolute pixels, depending on dirtection
+ case "x":
+ this.velocity *= this.width / 1000;
+ break;
+ case "y":
+ this.velocity *= this.width / 1000;
+ break;
+ default:
+ this.velocity *= this.depth / 1000;
+ break;
+ }
+
+ for (var i = 0; i < this.numStars; i++) {
+ var star = new Array(3);
+ star[0] = (Math.random() - 0.5) * 2 * this.width; // X coordinate of star goes from -width to width
+ star[1] = (Math.random() - 0.5) * 2 * this.height; // Y coordinate of star goes from -height to height
+ star[2] = Math.random() * this.depth; // Z coordinate of star 0 to depth
+ star[3] = false; // Active. If false then star is not drawn
+ this.stars[i] = star; // add star to array
+ }
+ }
+
+ StarField.prototype.draw = function (dt) {
+ for (var i = 0; i < this.numStars; i++) {
+ var color, radius;
+ var p = this.pz(this.stars[i][2]); // Determine projection factor based on z-value
+ var x = this.stars[i][0] / p + this.sx; // Projected and translated x-value
+ var y = this.stars[i][1] / p + this.sy; // projected and translated y-value
+
+
+ if (this.visible(x,y) && this.stars[i][3]) { // Check if star is within visible field and active
+ if (p < 1.25) { // Determine size and color of star depending on distance
+ radius = 5;
+ color = "rgba(255,255,255,1.0)"
+ }
+ else if (p < 1.5) {
+ radius = 4;
+ color = "rgba(192,192,192,1.0)"
+ }
+ else if (p < 1.75) {
+ radius = 3;
+ color = "rgba(128,128,128,1.0)"
+ }
+ else {
+ radius = 2;
+ color = "rgba(64,64,64,1.0)"
+ }
+
+ var gradient = this.context.createRadialGradient(x, y, 1, x, y, radius);
+ gradient.addColorStop(0, color);
+ gradient.addColorStop(1, "rgba(0,0,0,0.0)");
+ this.context.fillStyle = gradient;
+ this.context.fillRect(x - 5, y - 5, 11, 11);
+ }
+ }
+ }
+
+ StarField.prototype.update = function (dt) {
+ var axis, limit1, limit2, boundaryCheck; // Sets to the index of the direction stars are moving in. 0 = x, 1 = y, 2 = z;
+
+ switch (this.direction) { // Determine the index of the axis the stars are moving along, the boundary values and to check for > or <
+ case "x":
+ axis = 0;
+ if (this.velocity >= 0) {
+ limit1 = this.width;
+ limit2 = -limit1;
+ boundaryCheck = this.boundaryCheck1;
+ }
+ else {
+ limit1 = -this.width;
+ limit2 = -limit1;
+ boundaryCheck = this.boundaryCheck2;
+ }
+ break;
+ case "y":
+ axis = 1
+ if (this.velocity >= 0) {
+ limit1 = this.height;
+ limit2 = -limit1;
+ boundaryCheck = this.boundaryCheck1;
+ }
+ else {
+ limit1 = -this.height;
+ limit2 = -limit1;
+ boundaryCheck = this.boundaryCheck2;
+ }
+ break;
+ default:
+ axis = 2;
+ if (this.velocity >= 0) {
+ limit1 = this.depth;
+ limit2 = 0;
+ boundaryCheck = this.boundaryCheck1;
+ }
+ else {
+ limit1 = 0;
+ limit2 = this.depth;
+ boundaryCheck = this.boundaryCheck2;
+ }
+ break;
+ }
+
+ for (var i = 0; i < this.numStars; i++) {
+ this.stars[i][axis] += this.velocity * dt;
+
+ if (boundaryCheck(this.stars[i][axis], limit1)) { // If star is out of box then move to other side so it can come in again
+ this.addBoundaryStar(i, axis, limit2);
+ }
+ }
+ }
+
+ StarField.prototype.boundaryCheck1 = function (value, limit) { // Function checks if value > limit. assigned dynamically when stars are moving with positive velocity
+ if (value > limit) return true;
+ else return false;
+ }
+
+ StarField.prototype.boundaryCheck2 = function (value, limit) { // Function checks if value < limit. assigned dynamically when stars are moving with negative velocity
+ if (value < limit) return true;
+ else return false;
+ }
+
+ StarField.prototype.addBoundaryStar = function (i, axis, limit) { // Adds a new star to the boundary at which they need to enter
+ this.stars[i][axis] = limit;
+ this.stars[i][3] = true;
+ }
+
+ StarField.prototype.pz = function (z) { // Projection factor. pz(startZ) = 1, pz(startZ + depth) = 2.
+ return ((z / this.depth) + 1);
+ }
+
+ StarField.prototype.visible = function (x, y) {
+ if (x < this.StartX) return false;
+ if (x >= this.startX + this.width) return false;
+ if (y < this.StartY) return false;
+ if (y >= this.startY + this.height) return false;
+ return true;
+ }
+
+ this.createStars();
+}
32 SpaceCadet/package.appxmanifest
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
+ <Identity Name="2666f999-f568-44a2-a589-ca5c477d0b33" Version="1.0.0.0" Publisher="CN=David" />
+ <Properties>
+ <DisplayName>SpaceCadet</DisplayName>
+ <PublisherDisplayName>David</PublisherDisplayName>
+ <Logo>images\storelogo.png</Logo>
+ </Properties>
+ <Prerequisites>
+ <OSMinVersion>6.2.0</OSMinVersion>
+ <OSMaxVersionTested>6.2.0</OSMaxVersionTested>
+ </Prerequisites>
+ <Resources>
+ <Resource Language="x-generate" />
+ </Resources>
+ <Applications>
+ <Application Id="App" StartPage="default.html">
+ <VisualElements DisplayName="SpaceCadet" Logo="images\logo.png" SmallLogo="images\smalllogo.png" Description="SpaceCadet" ForegroundText="light" BackgroundColor="black">
+ <DefaultTile ShowName="allLogos" />
+ <SplashScreen Image="images\splashscreen.png" BackgroundColor="black" />
+ <InitialRotationPreference>
+ <Rotation Preference="landscape" />
+ <Rotation Preference="landscapeFlipped" />
+ </InitialRotationPreference>
+ </VisualElements>
+ </Application>
+ </Applications>
+ <Capabilities>
+ <Capability Name="internetClient" />
+ <DeviceCapability Name="webcam" />
+ </Capabilities>
+</Package>
8 SpaceCadet/page.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title></title>
+ </head>
+ <body>
+ </body>
+</html>
BIN SpaceCadet/sounds/hydrogen.mp3
Binary file not shown.
BIN SpaceCadet/sounds/laser1.mp3
Binary file not shown.
BIN SpaceCadet/sounds/laser2.mp3
Binary file not shown.
BIN SpaceCadet/sounds/laser3.mp3
Binary file not shown.
BIN SpaceCadet/sounds/newlevel.mp3
Binary file not shown.
BIN SpaceCadet/sounds/pulse.mp3
Binary file not shown.
BIN SpaceCadet/sounds/redalert.mp3
Binary file not shown.

0 comments on commit 72b38a2

Please sign in to comment.
Something went wrong with that request. Please try again.