├── .gitignore
├── Images
└── creating-a-new-project.png
├── LICENSE
├── README.md
└── Source
├── Complete
├── AlienAttack
│ ├── AlienAttackGame.cs
│ ├── AlienAttackUniversal.csproj
│ ├── AlienAttackUniversal.sln
│ ├── AlienAttackUniversal_TemporaryKey.pfx
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Assets
│ │ ├── LockScreenLogo.scale-200.png
│ │ ├── Logo.scale-200.png
│ │ ├── SmallLogo.scale-200.png
│ │ ├── SplashScreen.scale-200.png
│ │ ├── Square150x150Logo.scale-200.png
│ │ ├── Square310x310Logo.scale-200.png
│ │ ├── Square44x44Logo.scale-200.png
│ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png
│ │ ├── Square71x71Logo.scale-200.png
│ │ ├── StoreLogo.png
│ │ ├── StoreLogo.scale-200.png
│ │ ├── Wide310x150Logo.scale-200.png
│ │ ├── uwp_100x100.png
│ │ ├── uwp_142x142.png
│ │ └── uwp_620x620.png
│ ├── AudioManager.cs
│ ├── Content
│ │ ├── Audiowide-Regular.ttf
│ │ ├── Content.mgcb
│ │ ├── Font.spritefont
│ │ ├── gfx
│ │ │ ├── bgScreen.png
│ │ │ ├── enemy1
│ │ │ │ ├── enemy1_0.png
│ │ │ │ ├── enemy1_1.png
│ │ │ │ ├── enemy1_2.png
│ │ │ │ ├── enemy1_3.png
│ │ │ │ ├── enemy1_4.png
│ │ │ │ ├── enemy1_5.png
│ │ │ │ ├── enemy1_6.png
│ │ │ │ ├── enemy1_7.png
│ │ │ │ ├── enemy1_8.png
│ │ │ │ └── enemy1_9.png
│ │ │ ├── eshot
│ │ │ │ ├── eshot_0.png
│ │ │ │ ├── eshot_1.png
│ │ │ │ └── eshot_2.png
│ │ │ ├── explosion
│ │ │ │ ├── explosion_0.png
│ │ │ │ ├── explosion_1.png
│ │ │ │ ├── explosion_2.png
│ │ │ │ ├── explosion_3.png
│ │ │ │ ├── explosion_4.png
│ │ │ │ ├── explosion_5.png
│ │ │ │ ├── explosion_6.png
│ │ │ │ ├── explosion_7.png
│ │ │ │ └── explosion_8.png
│ │ │ ├── player
│ │ │ │ ├── player.png
│ │ │ │ ├── player_l1.png
│ │ │ │ ├── player_l2.png
│ │ │ │ ├── player_l3.png
│ │ │ │ ├── player_r1.png
│ │ │ │ ├── player_r2.png
│ │ │ │ └── player_r3.png
│ │ │ ├── pshot
│ │ │ │ ├── pshot_0.png
│ │ │ │ ├── pshot_1.png
│ │ │ │ └── pshot_2.png
│ │ │ └── titleScreen.png
│ │ └── sfx
│ │ │ ├── enemyShot.wav
│ │ │ ├── explosion.wav
│ │ │ ├── playerShot.wav
│ │ │ └── theme.wma
│ ├── GamePage.xaml
│ ├── GamePage.xaml.cs
│ ├── InputManager.cs
│ ├── Package.appxmanifest
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ └── Default.rd.xml
│ ├── RenderTargetScaler.cs
│ ├── Screens
│ │ ├── GameScreen.cs
│ │ └── TitleScreen.cs
│ ├── Sprites
│ │ ├── Enemy.cs
│ │ ├── EnemyGroup.cs
│ │ ├── EnemyShot.cs
│ │ ├── Explosion.cs
│ │ ├── Player.cs
│ │ ├── PlayerShot.cs
│ │ └── Sprite.cs
│ └── project.json
└── README.md
├── Ex1
├── Begin
│ ├── AlienAttackGame.cs
│ ├── AlienAttackUniversal.csproj
│ ├── AlienAttackUniversal.sln
│ ├── AlienAttackUniversal_TemporaryKey.pfx
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Assets
│ │ ├── LockScreenLogo.scale-200.png
│ │ ├── Logo.scale-200.png
│ │ ├── SmallLogo.scale-200.png
│ │ ├── SplashScreen.scale-200.png
│ │ ├── Square150x150Logo.scale-200.png
│ │ ├── Square310x310Logo.scale-200.png
│ │ ├── Square44x44Logo.scale-200.png
│ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png
│ │ ├── Square71x71Logo.scale-200.png
│ │ ├── StoreLogo.png
│ │ ├── StoreLogo.scale-200.png
│ │ ├── Wide310x150Logo.scale-200.png
│ │ ├── uwp_100x100.png
│ │ ├── uwp_142x142.png
│ │ └── uwp_620x620.png
│ ├── Content
│ │ ├── Audiowide-Regular.ttf
│ │ ├── Content.mgcb
│ │ ├── Font.spritefont
│ │ ├── gfx
│ │ │ ├── bgScreen.png
│ │ │ ├── enemy1
│ │ │ │ ├── enemy1_0.png
│ │ │ │ ├── enemy1_1.png
│ │ │ │ ├── enemy1_2.png
│ │ │ │ ├── enemy1_3.png
│ │ │ │ ├── enemy1_4.png
│ │ │ │ ├── enemy1_5.png
│ │ │ │ ├── enemy1_6.png
│ │ │ │ ├── enemy1_7.png
│ │ │ │ ├── enemy1_8.png
│ │ │ │ └── enemy1_9.png
│ │ │ ├── eshot
│ │ │ │ ├── eshot_0.png
│ │ │ │ ├── eshot_1.png
│ │ │ │ └── eshot_2.png
│ │ │ ├── explosion
│ │ │ │ ├── explosion_0.png
│ │ │ │ ├── explosion_1.png
│ │ │ │ ├── explosion_2.png
│ │ │ │ ├── explosion_3.png
│ │ │ │ ├── explosion_4.png
│ │ │ │ ├── explosion_5.png
│ │ │ │ ├── explosion_6.png
│ │ │ │ ├── explosion_7.png
│ │ │ │ └── explosion_8.png
│ │ │ ├── player.png
│ │ │ ├── pshot
│ │ │ │ ├── pshot_0.png
│ │ │ │ ├── pshot_1.png
│ │ │ │ └── pshot_2.png
│ │ │ └── titleScreen.png
│ │ └── sfx
│ │ │ ├── enemyShot.wav
│ │ │ ├── explosion.wav
│ │ │ ├── playerShot.wav
│ │ │ └── theme.wma
│ ├── GamePage.xaml
│ ├── GamePage.xaml.cs
│ ├── Package.appxmanifest
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ └── Default.rd.xml
│ ├── RenderTargetScaler.cs
│ ├── Sprites
│ │ ├── Enemy.cs
│ │ ├── EnemyGroup.cs
│ │ ├── EnemyShot.cs
│ │ ├── Explosion.cs
│ │ ├── Player.cs
│ │ ├── PlayerShot.cs
│ │ └── Sprite.cs
│ └── project.json
└── End
│ ├── AlienAttackGame.cs
│ ├── AlienAttackUniversal.csproj
│ ├── AlienAttackUniversal.sln
│ ├── AlienAttackUniversal_TemporaryKey.pfx
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Assets
│ ├── LockScreenLogo.scale-200.png
│ ├── Logo.scale-200.png
│ ├── SmallLogo.scale-200.png
│ ├── SplashScreen.scale-200.png
│ ├── Square150x150Logo.scale-200.png
│ ├── Square310x310Logo.scale-200.png
│ ├── Square44x44Logo.scale-200.png
│ ├── Square44x44Logo.targetsize-24_altform-unplated.png
│ ├── Square71x71Logo.scale-200.png
│ ├── StoreLogo.png
│ ├── StoreLogo.scale-200.png
│ ├── Wide310x150Logo.scale-200.png
│ ├── uwp_100x100.png
│ ├── uwp_142x142.png
│ └── uwp_620x620.png
│ ├── Content
│ ├── Audiowide-Regular.ttf
│ ├── Content.mgcb
│ ├── Font.spritefont
│ ├── gfx
│ │ ├── bgScreen.png
│ │ ├── enemy1
│ │ │ ├── enemy1_0.png
│ │ │ ├── enemy1_1.png
│ │ │ ├── enemy1_2.png
│ │ │ ├── enemy1_3.png
│ │ │ ├── enemy1_4.png
│ │ │ ├── enemy1_5.png
│ │ │ ├── enemy1_6.png
│ │ │ ├── enemy1_7.png
│ │ │ ├── enemy1_8.png
│ │ │ └── enemy1_9.png
│ │ ├── eshot
│ │ │ ├── eshot_0.png
│ │ │ ├── eshot_1.png
│ │ │ └── eshot_2.png
│ │ ├── explosion
│ │ │ ├── explosion_0.png
│ │ │ ├── explosion_1.png
│ │ │ ├── explosion_2.png
│ │ │ ├── explosion_3.png
│ │ │ ├── explosion_4.png
│ │ │ ├── explosion_5.png
│ │ │ ├── explosion_6.png
│ │ │ ├── explosion_7.png
│ │ │ └── explosion_8.png
│ │ ├── player.png
│ │ ├── pshot
│ │ │ ├── pshot_0.png
│ │ │ ├── pshot_1.png
│ │ │ └── pshot_2.png
│ │ └── titleScreen.png
│ └── sfx
│ │ ├── enemyShot.wav
│ │ ├── explosion.wav
│ │ ├── playerShot.wav
│ │ └── theme.wma
│ ├── GamePage.xaml
│ ├── GamePage.xaml.cs
│ ├── Package.appxmanifest
│ ├── Properties
│ ├── AssemblyInfo.cs
│ └── Default.rd.xml
│ ├── RenderTargetScaler.cs
│ ├── Sprites
│ ├── Enemy.cs
│ ├── EnemyGroup.cs
│ ├── EnemyShot.cs
│ ├── Explosion.cs
│ ├── Player.cs
│ ├── PlayerShot.cs
│ └── Sprite.cs
│ └── project.json
├── Setup.cmd
└── Setup
├── Cleanup.cmd
├── Setup.cmd
└── scripts
├── InstallCodeSnippets.cmd
├── installCodeSnippets.ps1
└── snippets
├── IntroMonoGame.vsi
└── IntroMonoGameShort.vsi
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 |
24 | # Visual Studio 2015 cache/options directory
25 | .vs/
26 | # Uncomment if you have tasks that create the project's static files in wwwroot
27 | #wwwroot/
28 |
29 | # MSTest test Results
30 | [Tt]est[Rr]esult*/
31 | [Bb]uild[Ll]og.*
32 |
33 | # NUNIT
34 | *.VisualState.xml
35 | TestResult.xml
36 |
37 | # Build Results of an ATL Project
38 | [Dd]ebugPS/
39 | [Rr]eleasePS/
40 | dlldata.c
41 |
42 | # DNX
43 | project.lock.json
44 | artifacts/
45 |
46 | *_i.c
47 | *_p.c
48 | *_i.h
49 | *.ilk
50 | *.meta
51 | *.obj
52 | *.pch
53 | *.pdb
54 | *.pgc
55 | *.pgd
56 | *.rsp
57 | *.sbr
58 | *.tlb
59 | *.tli
60 | *.tlh
61 | *.tmp
62 | *.tmp_proj
63 | *.log
64 | *.vspscc
65 | *.vssscc
66 | .builds
67 | *.pidb
68 | *.svclog
69 | *.scc
70 |
71 | # Chutzpah Test files
72 | _Chutzpah*
73 |
74 | # Visual C++ cache files
75 | ipch/
76 | *.aps
77 | *.ncb
78 | *.opendb
79 | *.opensdf
80 | *.sdf
81 | *.cachefile
82 |
83 | # Visual Studio profiler
84 | *.psess
85 | *.vsp
86 | *.vspx
87 | *.sap
88 |
89 | # TFS 2012 Local Workspace
90 | $tf/
91 |
92 | # Guidance Automation Toolkit
93 | *.gpState
94 |
95 | # ReSharper is a .NET coding add-in
96 | _ReSharper*/
97 | *.[Rr]e[Ss]harper
98 | *.DotSettings.user
99 |
100 | # JustCode is a .NET coding add-in
101 | .JustCode
102 |
103 | # TeamCity is a build add-in
104 | _TeamCity*
105 |
106 | # DotCover is a Code Coverage Tool
107 | *.dotCover
108 |
109 | # NCrunch
110 | _NCrunch_*
111 | .*crunch*.local.xml
112 | nCrunchTemp_*
113 |
114 | # MightyMoose
115 | *.mm.*
116 | AutoTest.Net/
117 |
118 | # Web workbench (sass)
119 | .sass-cache/
120 |
121 | # Installshield output folder
122 | [Ee]xpress/
123 |
124 | # DocProject is a documentation generator add-in
125 | DocProject/buildhelp/
126 | DocProject/Help/*.HxT
127 | DocProject/Help/*.HxC
128 | DocProject/Help/*.hhc
129 | DocProject/Help/*.hhk
130 | DocProject/Help/*.hhp
131 | DocProject/Help/Html2
132 | DocProject/Help/html
133 |
134 | # Click-Once directory
135 | publish/
136 |
137 | # Publish Web Output
138 | *.[Pp]ublish.xml
139 | *.azurePubxml
140 | # TODO: Comment the next line if you want to checkin your web deploy settings
141 | # but database connection strings (with potential passwords) will be unencrypted
142 | *.pubxml
143 | *.publishproj
144 |
145 | # NuGet Packages
146 | *.nupkg
147 | # The packages folder can be ignored because of Package Restore
148 | **/packages/*
149 | # except build/, which is used as an MSBuild target.
150 | !**/packages/build/
151 | # Uncomment if necessary however generally it will be regenerated when needed
152 | #!**/packages/repositories.config
153 | # NuGet v3's project.json files produces more ignoreable files
154 | *.nuget.props
155 | *.nuget.targets
156 |
157 | # Microsoft Azure Build Output
158 | csx/
159 | *.build.csdef
160 |
161 | # Microsoft Azure Emulator
162 | ecf/
163 | rcf/
164 |
165 | # Microsoft Azure ApplicationInsights config file
166 | ApplicationInsights.config
167 |
168 | # Windows Store app package directory
169 | AppPackages/
170 | BundleArtifacts/
171 |
172 | # Visual Studio cache files
173 | # files ending in .cache can be ignored
174 | *.[Cc]ache
175 | # but keep track of directories ending in .cache
176 | !*.[Cc]ache/
177 |
178 | # Others
179 | ClientBin/
180 | ~$*
181 | *~
182 | *.dbmdl
183 | *.dbproj.schemaview
184 | *.pfx
185 | *.publishsettings
186 | node_modules/
187 | orleans.codegen.cs
188 |
189 | # RIA/Silverlight projects
190 | Generated_Code/
191 |
192 | # Backup & report files from converting an old project file
193 | # to a newer Visual Studio version. Backup files are not needed,
194 | # because we have git ;-)
195 | _UpgradeReport_Files/
196 | Backup*/
197 | UpgradeLog*.XML
198 | UpgradeLog*.htm
199 |
200 | # SQL Server files
201 | *.mdf
202 | *.ldf
203 |
204 | # Business Intelligence projects
205 | *.rdl.data
206 | *.bim.layout
207 | *.bim_*.settings
208 |
209 | # Microsoft Fakes
210 | FakesAssemblies/
211 |
212 | # GhostDoc plugin setting file
213 | *.GhostDoc.xml
214 |
215 | # Node.js Tools for Visual Studio
216 | .ntvs_analysis.dat
217 |
218 | # Visual Studio 6 build log
219 | *.plg
220 |
221 | # Visual Studio 6 workspace options file
222 | *.opt
223 |
224 | # Visual Studio LightSwitch build output
225 | **/*.HTMLClient/GeneratedArtifacts
226 | **/*.DesktopClient/GeneratedArtifacts
227 | **/*.DesktopClient/ModelManifest.xml
228 | **/*.Server/GeneratedArtifacts
229 | **/*.Server/ModelManifest.xml
230 | _Pvt_Extensions
231 |
232 | # Paket dependency manager
233 | .paket/paket.exe
234 |
235 | # FAKE - F# Make
236 | .fake/
237 |
--------------------------------------------------------------------------------
/Images/creating-a-new-project.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Images/creating-a-new-project.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Microsoft
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/AlienAttackGame.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Windows.UI.ViewManagement;
3 | using Microsoft.Xna.Framework;
4 | using AlienAttackUniversal.Screens;
5 |
6 | namespace AlienAttackUniversal
7 | {
8 | public enum GameState
9 | {
10 | TitleScreen,
11 | GameScreen
12 | };
13 |
14 | ///
15 | /// This is the main type for your game
16 | ///
17 | public class AlienAttackGame : Game
18 | {
19 | public static AlienAttackGame Instance;
20 |
21 | private readonly GraphicsDeviceManager _graphics;
22 |
23 | private DrawableGameComponent _screen;
24 | private RenderTargetScaler _scaler;
25 |
26 | public static int ScreenWidth = 1920;
27 | public static int ScreenHeight = 1080;
28 |
29 | public AlienAttackGame()
30 | {
31 | Instance = this;
32 |
33 | _graphics = new GraphicsDeviceManager(this);
34 |
35 | // set our screen size based on the device
36 | _graphics.PreferredBackBufferWidth = ScreenWidth;
37 | _graphics.PreferredBackBufferHeight = ScreenHeight;
38 |
39 | Content.RootDirectory = "Content";
40 | }
41 |
42 | ///
43 | /// Allows the game to perform any initialization it needs to before starting to run.
44 | /// This is where it can query for any required services and load any non-graphic
45 | /// related content. Calling base.Initialize will enumerate through any components
46 | /// and initialize them as well.
47 | ///
48 | protected override void Initialize()
49 | {
50 | _scaler = new RenderTargetScaler(this, _graphics, ScreenWidth, ScreenHeight);
51 |
52 | // create the title screen
53 | SetState(GameState.TitleScreen);
54 |
55 | base.Initialize();
56 | }
57 |
58 | ///
59 | /// LoadContent will be called once per game and is the place to load
60 | /// all of your content.
61 | ///
62 | protected override void LoadContent()
63 | {
64 | }
65 |
66 | ///
67 | /// UnloadContent will be called once per game and is the place to unload
68 | /// all content.
69 | ///
70 | protected override void UnloadContent()
71 | {
72 | }
73 |
74 | ///
75 | /// Allows the game to run logic such as updating the world,
76 | /// checking for collisions, gathering input, and playing audio.
77 | ///
78 | /// Provides a snapshot of timing values.
79 | protected override void Update(GameTime gameTime)
80 | {
81 | // update the user input
82 | InputManager.Update();
83 |
84 | // Allows the game to exit
85 | //if(InputManager.ControlState.Quit)
86 | // this.Exit();
87 |
88 | // update the current screen
89 | _screen.Update(gameTime);
90 |
91 | base.Update(gameTime);
92 | }
93 |
94 | ///
95 | /// This is called when the game should draw itself.
96 | ///
97 | /// Provides a snapshot of timing values.
98 | protected override void Draw(GameTime gameTime)
99 | {
100 | _scaler.SetRenderTarget();
101 | _screen.Draw(gameTime);
102 | _scaler.Draw();
103 | }
104 |
105 | public void SetState(GameState newState)
106 | {
107 | switch(newState)
108 | {
109 | case GameState.TitleScreen:
110 | _screen = new TitleScreen(this);
111 | break;
112 | case GameState.GameScreen:
113 | _screen = new GameScreen(this);
114 | break;
115 | }
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/AlienAttackUniversal.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.24720.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlienAttackUniversal", "AlienAttackUniversal.csproj", "{5EF2882F-8277-4262-A697-F96590277E1B}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|ARM = Debug|ARM
11 | Debug|x64 = Debug|x64
12 | Debug|x86 = Debug|x86
13 | Release|ARM = Release|ARM
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|ARM.ActiveCfg = Debug|ARM
19 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|ARM.Build.0 = Debug|ARM
20 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|ARM.Deploy.0 = Debug|ARM
21 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x64.ActiveCfg = Debug|x64
22 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x64.Build.0 = Debug|x64
23 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x64.Deploy.0 = Debug|x64
24 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x86.ActiveCfg = Debug|x86
25 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x86.Build.0 = Debug|x86
26 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x86.Deploy.0 = Debug|x86
27 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|ARM.ActiveCfg = Release|ARM
28 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|ARM.Build.0 = Release|ARM
29 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|ARM.Deploy.0 = Release|ARM
30 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x64.ActiveCfg = Release|x64
31 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x64.Build.0 = Release|x64
32 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x64.Deploy.0 = Release|x64
33 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x86.ActiveCfg = Release|x86
34 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x86.Build.0 = Release|x86
35 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x86.Deploy.0 = Release|x86
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/AlienAttackUniversal_TemporaryKey.pfx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/AlienAttackUniversal_TemporaryKey.pfx
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Runtime.InteropServices.WindowsRuntime;
6 | using Windows.ApplicationModel;
7 | using Windows.ApplicationModel.Activation;
8 | using Windows.Foundation;
9 | using Windows.Foundation.Collections;
10 | using Windows.UI.Xaml;
11 | using Windows.UI.Xaml.Controls;
12 | using Windows.UI.Xaml.Controls.Primitives;
13 | using Windows.UI.Xaml.Data;
14 | using Windows.UI.Xaml.Input;
15 | using Windows.UI.Xaml.Media;
16 | using Windows.UI.Xaml.Navigation;
17 |
18 | // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=402347&clcid=0x409
19 |
20 | namespace AlienAttackUniversal
21 | {
22 | ///
23 | /// Provides application-specific behavior to supplement the default Application class.
24 | ///
25 | sealed partial class App : Application
26 | {
27 | ///
28 | /// Initializes the singleton application object. This is the first line of authored code
29 | /// executed, and as such is the logical equivalent of main() or WinMain().
30 | ///
31 | public App()
32 | {
33 | this.InitializeComponent();
34 | this.Suspending += OnSuspending;
35 | }
36 |
37 | ///
38 | /// Invoked when the application is launched normally by the end user. Other entry points
39 | /// will be used such as when the application is launched to open a specific file.
40 | ///
41 | /// Details about the launch request and process.
42 | protected override void OnLaunched(LaunchActivatedEventArgs e)
43 | {
44 |
45 | #if DEBUG
46 | if (System.Diagnostics.Debugger.IsAttached)
47 | {
48 | this.DebugSettings.EnableFrameRateCounter = true;
49 | }
50 | #endif
51 |
52 | Frame rootFrame = Window.Current.Content as Frame;
53 |
54 | // Do not repeat app initialization when the Window already has content,
55 | // just ensure that the window is active
56 | if (rootFrame == null)
57 | {
58 | // Create a Frame to act as the navigation context and navigate to the first page
59 | rootFrame = new Frame();
60 |
61 | rootFrame.NavigationFailed += OnNavigationFailed;
62 |
63 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
64 | {
65 | //TODO: Load state from previously suspended application
66 | }
67 |
68 | // Place the frame in the current Window
69 | Window.Current.Content = rootFrame;
70 | }
71 |
72 | if (rootFrame.Content == null)
73 | {
74 | // When the navigation stack isn't restored navigate to the first page,
75 | // configuring the new page by passing required information as a navigation
76 | // parameter
77 | rootFrame.Navigate(typeof(GamePage), e.Arguments);
78 | }
79 | // Ensure the current window is active
80 | Window.Current.Activate();
81 | }
82 |
83 | ///
84 | /// Invoked when Navigation to a certain page fails
85 | ///
86 | /// The Frame which failed navigation
87 | /// Details about the navigation failure
88 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
89 | {
90 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
91 | }
92 |
93 | ///
94 | /// Invoked when application execution is being suspended. Application state is saved
95 | /// without knowing whether the application will be terminated or resumed with the contents
96 | /// of memory still intact.
97 | ///
98 | /// The source of the suspend request.
99 | /// Details about the suspend request.
100 | private void OnSuspending(object sender, SuspendingEventArgs e)
101 | {
102 | var deferral = e.SuspendingOperation.GetDeferral();
103 | //TODO: Save application state and stop any background activity
104 | deferral.Complete();
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/SmallLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/SmallLogo.scale-200.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/Square310x310Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/Square310x310Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/Square71x71Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/Square71x71Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/StoreLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/StoreLogo.scale-200.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/uwp_100x100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/uwp_100x100.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/uwp_142x142.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/uwp_142x142.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Assets/uwp_620x620.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Assets/uwp_620x620.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/AudioManager.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework.Audio;
2 | using Microsoft.Xna.Framework.Media;
3 |
4 | namespace AlienAttackUniversal
5 | {
6 | public static class AudioManager
7 | {
8 | // the different fx that can be played
9 | public enum Cue
10 | {
11 | EnemyShot,
12 | PlayerShot,
13 | Explosion
14 | };
15 |
16 | // instances of the effects
17 | private static readonly Song _theme;
18 | private static readonly SoundEffect _enemyShot;
19 | private static readonly SoundEffect _playerShot;
20 | private static readonly SoundEffect _explosion;
21 |
22 | static AudioManager()
23 | {
24 | // load 'em up
25 | _theme = AlienAttackGame.Instance.Content.Load("sfx\\theme");
26 | _enemyShot = AlienAttackGame.Instance.Content.Load("sfx\\enemyShot");
27 | _playerShot = AlienAttackGame.Instance.Content.Load("sfx\\playerShot");
28 | _explosion = AlienAttackGame.Instance.Content.Load("sfx\\explosion");
29 | }
30 |
31 | public static void PlayCue(Cue cue)
32 | {
33 | // play the effect requested
34 | switch(cue)
35 | {
36 | case Cue.EnemyShot:
37 | _enemyShot.Play();
38 | break;
39 | case Cue.PlayerShot:
40 | _playerShot.Play();
41 | break;
42 | case Cue.Explosion:
43 | _explosion.Play();
44 | break;
45 | }
46 | }
47 |
48 | public static void StartTheme()
49 | {
50 | MediaPlayer.IsRepeating = true;
51 | MediaPlayer.Play(_theme);
52 | }
53 |
54 | public static void StopTheme()
55 | {
56 | MediaPlayer.Stop();
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/Audiowide-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/Audiowide-Regular.ttf
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/Font.spritefont:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
15 | Audiowide-Regular
16 |
17 |
21 | 36
22 |
23 |
27 | 0
28 |
29 |
33 | true
34 |
35 |
39 |
40 |
41 |
48 |
49 |
50 |
51 | ~
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/bgScreen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/bgScreen.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_0.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_1.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_2.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_3.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_4.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_5.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_6.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_7.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_8.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/enemy1/enemy1_9.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/eshot/eshot_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/eshot/eshot_0.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/eshot/eshot_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/eshot/eshot_1.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/eshot/eshot_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/eshot/eshot_2.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_0.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_1.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_2.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_3.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_4.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_5.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_6.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_7.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/explosion/explosion_8.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/player/player.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/player/player.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/player/player_l1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/player/player_l1.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/player/player_l2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/player/player_l2.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/player/player_l3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/player/player_l3.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/player/player_r1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/player/player_r1.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/player/player_r2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/player/player_r2.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/player/player_r3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/player/player_r3.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/pshot/pshot_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/pshot/pshot_0.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/pshot/pshot_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/pshot/pshot_1.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/pshot/pshot_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/pshot/pshot_2.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/gfx/titleScreen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/gfx/titleScreen.png
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/sfx/enemyShot.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/sfx/enemyShot.wav
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/sfx/explosion.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/sfx/explosion.wav
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/sfx/playerShot.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/sfx/playerShot.wav
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Content/sfx/theme.wma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Complete/AlienAttack/Content/sfx/theme.wma
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/GamePage.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/GamePage.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Runtime.InteropServices.WindowsRuntime;
6 | using Windows.Foundation;
7 | using Windows.Foundation.Collections;
8 | using Windows.UI.Xaml;
9 | using Windows.UI.Xaml.Controls;
10 | using Windows.UI.Xaml.Controls.Primitives;
11 | using Windows.UI.Xaml.Data;
12 | using Windows.UI.Xaml.Input;
13 | using Windows.UI.Xaml.Media;
14 | using Windows.UI.Xaml.Navigation;
15 |
16 | // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
17 |
18 | namespace AlienAttackUniversal
19 | {
20 | ///
21 | /// An empty page that can be used on its own or navigated to within a Frame.
22 | ///
23 | public sealed partial class GamePage : Page
24 | {
25 | readonly AlienAttackGame _game;
26 |
27 | public GamePage()
28 | {
29 | this.InitializeComponent();
30 |
31 | // Create the game.
32 | var launchArguments = string.Empty;
33 | _game = MonoGame.Framework.XamlGame.Create(launchArguments, Window.Current.CoreWindow, swapChainPanel);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/InputManager.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Input;
3 | using Microsoft.Xna.Framework.Input.Touch;
4 |
5 | namespace AlienAttackUniversal
6 | {
7 | public struct ControlState
8 | {
9 | public bool Left;
10 | public bool Right;
11 | public bool Start;
12 | public bool Quit;
13 | public bool Fire;
14 | public float FingerPosition;
15 | }
16 |
17 | public static class InputManager
18 | {
19 | private static KeyboardState _keyboardState, _lastKeyboard;
20 | private static GamePadState _gamePadState, _lastGamePad;
21 | private static ControlState _controlState;
22 |
23 | static InputManager()
24 | {
25 | TouchPanel.EnabledGestures = GestureType.Tap | GestureType.HorizontalDrag;
26 | }
27 |
28 | public static void Update()
29 | {
30 | _keyboardState = Keyboard.GetState();
31 | _gamePadState = GamePad.GetState(PlayerIndex.One);
32 |
33 | _controlState.Quit = (_gamePadState.Buttons.Back== ButtonState.Pressed || _keyboardState.IsKeyDown(Keys.Escape));
34 | _controlState.Start = (_gamePadState.Buttons.B == ButtonState.Pressed
35 | || _keyboardState.IsKeyDown(Keys.Enter) || _keyboardState.IsKeyDown(Keys.Space) || _gamePadState.IsButtonDown(Buttons.Start));
36 | _controlState.Left = (_gamePadState.DPad.Left == ButtonState.Pressed || _gamePadState.ThumbSticks.Left.X < -0.1f || _keyboardState.IsKeyDown(Keys.Left));
37 | _controlState.Right = (_gamePadState.DPad.Right == ButtonState.Pressed || _gamePadState.ThumbSticks.Left.X > 0.1f || _keyboardState.IsKeyDown(Keys.Right));
38 | _controlState.Fire = ((_gamePadState.Buttons.B == ButtonState.Pressed && _lastGamePad.Buttons.B == ButtonState.Released)
39 | || (_keyboardState.IsKeyDown(Keys.Space) && !_lastKeyboard.IsKeyDown(Keys.Space)));
40 |
41 | while(TouchPanel.IsGestureAvailable)
42 | {
43 | GestureSample gs = TouchPanel.ReadGesture();
44 | _controlState.Fire |= (gs.GestureType == GestureType.Tap);
45 | _controlState.Start |= (gs.GestureType == GestureType.Tap);
46 | if(gs.GestureType == GestureType.HorizontalDrag)
47 | {
48 | _controlState.Left = (gs.Delta.X < 0);
49 | _controlState.Right = (gs.Delta.X > 0);
50 | _controlState.FingerPosition = gs.Position.X;
51 | }
52 | }
53 |
54 | _lastGamePad = _gamePadState;
55 | _lastKeyboard = _keyboardState;
56 | }
57 |
58 | public static ControlState ControlState
59 | {
60 | get { return _controlState; }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Alien Attack
7 | TED Games Squad
8 | Assets\StoreLogo.png
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("AlienAttackUniversal")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("AlienAttackUniversal")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Version information for an assembly consists of the following four values:
18 | //
19 | // Major Version
20 | // Minor Version
21 | // Build Number
22 | // Revision
23 | //
24 | // You can specify all the values or you can default the Build and Revision Numbers
25 | // by using the '*' as shown below:
26 | // [assembly: AssemblyVersion("1.0.*")]
27 | [assembly: AssemblyVersion("1.0.0.0")]
28 | [assembly: AssemblyFileVersion("1.0.0.0")]
29 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/RenderTargetScaler.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Graphics;
3 |
4 | namespace AlienAttackUniversal
5 | {
6 | class RenderTargetScaler
7 | {
8 | private readonly RenderTarget2D _drawBuffer;
9 | private readonly GraphicsDeviceManager _graphicsDeviceManager;
10 | private readonly int _screenWidth;
11 | private readonly int _screenHeight;
12 | private readonly Game _game;
13 | private readonly SpriteBatch _spriteBatch;
14 |
15 | public RenderTargetScaler(Game game, GraphicsDeviceManager graphicsDeviceManager, int width, int height)
16 | {
17 | _game = game;
18 | _graphicsDeviceManager = graphicsDeviceManager;
19 | _screenWidth = width;
20 | _screenHeight = height;
21 |
22 | _spriteBatch = new SpriteBatch(graphicsDeviceManager.GraphicsDevice);
23 |
24 | // create a surface to draw on which is then scaled to the screen size on the PC
25 | _drawBuffer = new RenderTarget2D(graphicsDeviceManager.GraphicsDevice,
26 | width, height);
27 |
28 | }
29 |
30 | public void SetRenderTarget()
31 | {
32 | _graphicsDeviceManager.GraphicsDevice.SetRenderTarget(_drawBuffer);
33 | }
34 |
35 | public void Draw()
36 | {
37 | float outputAspect = _game.Window.ClientBounds.Width / (float)_game.Window.ClientBounds.Height;
38 | float preferredAspect = _screenWidth / (float)_screenHeight;
39 |
40 | Rectangle dst;
41 |
42 | if (outputAspect <= preferredAspect)
43 | {
44 | // output is taller than it is wider, bars on top/bottom
45 | int presentHeight = (int)((_game.Window.ClientBounds.Width / preferredAspect) + 0.5f);
46 | int barHeight = (_game.Window.ClientBounds.Height - presentHeight) / 2;
47 |
48 | dst = new Rectangle(0, barHeight, _game.Window.ClientBounds.Width, presentHeight);
49 | }
50 | else
51 | {
52 | // output is wider than it is tall, bars left/right
53 | int presentWidth = (int)((_game.Window.ClientBounds.Height * preferredAspect) + 0.5f);
54 | int barWidth = (_game.Window.ClientBounds.Width - presentWidth) / 2;
55 |
56 | dst = new Rectangle(barWidth, 0, presentWidth, _game.Window.ClientBounds.Height);
57 | }
58 |
59 | _graphicsDeviceManager.GraphicsDevice.SetRenderTarget(null);
60 |
61 | // clear to get black bars
62 | _graphicsDeviceManager.GraphicsDevice.Clear(Color.Black);
63 |
64 | // draw a quad to get the draw buffer to the back buffer
65 | _spriteBatch.Begin();
66 | _spriteBatch.Draw(_drawBuffer, dst, Color.White);
67 | _spriteBatch.End();
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Screens/GameScreen.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Microsoft.Xna.Framework;
3 | using Microsoft.Xna.Framework.Graphics;
4 | using AlienAttackUniversal.Sprites;
5 |
6 | namespace AlienAttackUniversal.Screens
7 | {
8 | public class GameScreen : DrawableGameComponent
9 | {
10 | private Player _player;
11 | private readonly List _playerShots;
12 | private double _lastTime;
13 | private readonly SpriteBatch _spriteBatch;
14 | private readonly Player _livesIcon;
15 | private Explosion _playerExplosion;
16 | private readonly Texture2D _bgScreen;
17 | private readonly EnemyGroup _enemyGroup;
18 | private readonly SpriteFont _font;
19 |
20 | private int _score;
21 | private int _lives;
22 | private double _backToMenuTime;
23 | private bool _loseGame;
24 |
25 | public GameScreen(Game game) : base(game)
26 | {
27 | _spriteBatch = new SpriteBatch(game.GraphicsDevice);
28 |
29 | AudioManager.StartTheme();
30 |
31 | _player = new Player();
32 | _player.Position = new Vector2(AlienAttackGame.ScreenWidth / 2 - _player.Width / 2, AlienAttackGame.ScreenHeight - 120);
33 | _playerShots = new List();
34 |
35 | _font = game.Content.Load("font");
36 |
37 | // draw a lives status icon in the lower left
38 | _livesIcon = new Player();
39 |
40 | // cache explosion
41 | new Explosion();
42 |
43 | _bgScreen = game.Content.Load("gfx\\bgScreen");
44 | _livesIcon.Position = new Vector2(20, AlienAttackGame.ScreenHeight-80);
45 | _livesIcon.Scale = new Vector2(0.5f, 0.5f);
46 |
47 | _enemyGroup = new EnemyGroup();
48 |
49 | _lives = 2;
50 | }
51 |
52 | public override void Update(GameTime gameTime)
53 | {
54 | if(_enemyGroup.AllDestroyed() || _loseGame)
55 | {
56 | _backToMenuTime += gameTime.ElapsedGameTime.TotalMilliseconds;
57 | if(_backToMenuTime >= 3000)
58 | {
59 | AudioManager.StopTheme();
60 | AlienAttackGame.Instance.SetState(GameState.TitleScreen);
61 | }
62 |
63 | _enemyGroup.Reset();
64 | _playerShots.Clear();
65 | }
66 | else
67 | {
68 | MovePlayer(gameTime);
69 | UpdatePlayerShots(gameTime);
70 | }
71 |
72 | // as long as we're not in the lose state, update the enemies
73 | if(!_loseGame)
74 | _enemyGroup.Update(gameTime);
75 |
76 | HandleCollisions(gameTime);
77 | }
78 |
79 | private void HandleCollisions(GameTime gameTime)
80 | {
81 | // see if a player shot hit an enemy
82 | for(int i = 0; i < _playerShots.Count; i++)
83 | {
84 | PlayerShot playerShot = _playerShots[i];
85 | // check the shot and see if it it collided with an enemy
86 | if(playerShot != null && _enemyGroup.HandlePlayerShotCollision(_playerShots[i]))
87 | {
88 | // remove the shot, add the score
89 | _playerShots.RemoveAt(i);
90 | _score += 100;
91 | AudioManager.PlayCue(AudioManager.Cue.Explosion);
92 | }
93 | }
94 |
95 | // see if an enemy shot hit the player
96 | if(_player != null && _enemyGroup.HandleEnemyShotCollision(_player))
97 | {
98 | // blow up the player
99 | _playerExplosion = new Explosion();
100 | Vector2 center = _player.Position + (_player.Size/2.0f);
101 | _playerExplosion.Position = center - (_playerExplosion.Size/2.0f);
102 | _player = null;
103 | AudioManager.PlayCue(AudioManager.Cue.Explosion);
104 | }
105 |
106 | // see if an enemy hit the player directly
107 | if(_player != null && _enemyGroup.HandleEnemyPlayerCollision(_player))
108 | {
109 | // blow up the player
110 | _playerExplosion = new Explosion();
111 | Vector2 center = _player.Position + (_player.Size/2.0f);
112 | _playerExplosion.Position = center - (_playerExplosion.Size/2.0f);
113 | _player = null;
114 | AudioManager.PlayCue(AudioManager.Cue.Explosion);
115 | _loseGame = true;
116 | }
117 |
118 | // if the player explosion animation is running, update it
119 | if(_playerExplosion != null)
120 | {
121 | // if this is the last frame
122 | if(_playerExplosion.Update(gameTime) && !_loseGame)
123 | {
124 | // remove it
125 | _playerExplosion = null;
126 |
127 | // we lose if we have no lives left
128 | if(_lives == 0)
129 | _loseGame = true;
130 | else
131 | {
132 | // subract 1 life and reset the board
133 | _lives--;
134 | _enemyGroup.Reset();
135 | _playerShots.Clear();
136 | _player = new Player();
137 | _player.Position = new Vector2(AlienAttackGame.ScreenWidth/2 - _player.Width/2, AlienAttackGame.ScreenHeight - 100);
138 | }
139 | }
140 | }
141 | }
142 |
143 | private void UpdatePlayerShots(GameTime gameTime)
144 | {
145 | // if we are allowed to fire, add a shot to the list
146 | if(_player != null && InputManager.ControlState.Fire && gameTime.TotalGameTime.TotalMilliseconds - _lastTime > 500)
147 | {
148 | // create a new shot over the ship
149 | PlayerShot ps = new PlayerShot();
150 | ps.Position = new Vector2((_player.Position.X + _player.Width/2.0f) - ps.Width/2.0f, _player.Position.Y - ps.Height);
151 | _playerShots.Add(ps);
152 | _lastTime = gameTime.TotalGameTime.TotalMilliseconds;
153 | AudioManager.PlayCue(AudioManager.Cue.PlayerShot);
154 | }
155 |
156 | // enumerate the player shots on the screen
157 | for(int i = 0; i < _playerShots.Count; i++)
158 | {
159 | PlayerShot playerShot = _playerShots[i];
160 |
161 | playerShot.Update(gameTime);
162 |
163 | // if it's off the top of the screen, remove it from the list
164 | if(playerShot.Position.Y + playerShot.Height < 0)
165 | _playerShots.RemoveAt(i);
166 | }
167 | }
168 |
169 | private void MovePlayer(GameTime gameTime)
170 | {
171 | if (_player != null)
172 | {
173 | _player.Velocity = Vector2.Zero;
174 | // move left
175 | if (InputManager.ControlState.Left && _player.Position.X > 0)
176 | _player.Velocity = new Vector2(-400 / 1000.0f, 0);
177 |
178 | // move right
179 | if (InputManager.ControlState.Right && _player.Position.X + _player.Width < AlienAttackGame.ScreenWidth)
180 | _player.Velocity = new Vector2(400 / 1000.0f, 0);
181 | _player.Update(gameTime);
182 | }
183 | }
184 |
185 | public override void Draw(GameTime gameTime)
186 | {
187 | _spriteBatch.Begin();
188 |
189 | _spriteBatch.Draw(_bgScreen, Vector2.Zero, Color.White);
190 |
191 | // draw the enemy board
192 | _enemyGroup.Draw(gameTime, _spriteBatch);
193 |
194 | // draw the player shots
195 | foreach(PlayerShot playerShot in _playerShots)
196 | playerShot.Draw(gameTime, _spriteBatch);
197 |
198 | // draw the player
199 | if (_player != null)
200 | _player.Draw(gameTime, _spriteBatch);
201 |
202 | // draw the explosion
203 | if (_playerExplosion != null)
204 | _playerExplosion.Draw(gameTime, _spriteBatch);
205 |
206 | // draw the score
207 | Vector2 scoreSize = _font.MeasureString("Score: " + _score);
208 | _spriteBatch.DrawString(_font, "Score: " + _score, new Vector2((AlienAttackGame.ScreenWidth - scoreSize.X) / 2, 25), Color.Aqua);
209 |
210 | // draw the lives icon
211 | _livesIcon.Draw(gameTime, _spriteBatch);
212 | _spriteBatch.DrawString(_font, "x" + _lives, new Vector2(_livesIcon.Position.X + (_livesIcon.Width*_livesIcon.Scale.X) + 8, _livesIcon.Position.Y), Color.White);
213 |
214 | // draw the proper text, if required
215 | if(_enemyGroup.AllDestroyed())
216 | {
217 | Vector2 size = _font.MeasureString("You win!");
218 | _spriteBatch.DrawString(_font, "You win!", new Vector2((AlienAttackGame.ScreenWidth - size.X) / 2, (AlienAttackGame.ScreenHeight - size.Y) / 2), Color.Green);
219 | }
220 |
221 | if(_loseGame)
222 | {
223 | Vector2 size = _font.MeasureString("Game Over");
224 | _spriteBatch.DrawString(_font, "Game Over", new Vector2((AlienAttackGame.ScreenWidth - size.X) / 2, (AlienAttackGame.ScreenHeight - size.Y) / 2), Color.Red);
225 | }
226 |
227 | _spriteBatch.End();
228 | }
229 | }
230 | }
231 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Screens/TitleScreen.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Graphics;
3 |
4 | namespace AlienAttackUniversal.Screens
5 | {
6 | public class TitleScreen : DrawableGameComponent
7 | {
8 | private readonly Texture2D _titleScreen;
9 | private readonly SpriteFont _font;
10 | private readonly SpriteBatch _spriteBatch;
11 |
12 | public TitleScreen(Game game) : base(game)
13 | {
14 | _spriteBatch = new SpriteBatch(game.GraphicsDevice);
15 | _titleScreen = game.Content.Load("gfx\\titleScreen");
16 | _font = game.Content.Load("Font");
17 | }
18 |
19 | public override void Update(GameTime gameTime)
20 | {
21 | if(InputManager.ControlState.Start)
22 | AlienAttackGame.Instance.SetState(GameState.GameScreen);
23 | }
24 |
25 | public override void Draw(GameTime gameTime)
26 | {
27 | _spriteBatch.Begin();
28 | _spriteBatch.Draw(_titleScreen, Vector2.Zero, Color.White);
29 | _spriteBatch.DrawString(_font, "Press Enter or Tap to Play", new Vector2(1100, 960), Color.Aqua);
30 | _spriteBatch.End();
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Sprites/Enemy.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class Enemy : Sprite
6 | {
7 | public Enemy()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\enemy1\\enemy1_{0}", 10);
10 | }
11 |
12 | public override void Update(GameTime gameTime)
13 | {
14 | AnimateReverse(gameTime, 60);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Sprites/EnemyGroup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 |
6 | namespace AlienAttackUniversal.Sprites
7 | {
8 | public class EnemyGroup : Sprite
9 | {
10 | // grid of enemies
11 | private readonly Enemy[,] _enemies;
12 |
13 | // all enemy shots
14 | private readonly List _enemyShots;
15 |
16 | // all enemy explosions
17 | private readonly List _explosions;
18 | private readonly Random _random;
19 |
20 | // width of single enemy
21 | private readonly int _enemyWidth;
22 |
23 | private const int EnemyRows = 4; // number of rows in grid
24 | private const int EnemyCols = 8; // number of cols in grid
25 | private readonly Vector2 EnemyVerticalJump = new Vector2(0, 10); // number of pixels to jump vertically after hitting edge
26 | private const int EnemyStartPosition = 10; // vertical position of grid
27 | private const int ScreenEdge = 20; // virtual edge of screen to change direction
28 | private Vector2 EnemySpacing = new Vector2(16, 32); // space between sprites
29 | private readonly Vector2 EnemyVelocity = new Vector2(100 / 1000.0f, 0); // speed at which grid moves per frame
30 |
31 | public EnemyGroup()
32 | {
33 | _random = new Random();
34 |
35 | _enemyShots = new List();
36 | _explosions = new List();
37 |
38 | _enemies = new Enemy[EnemyRows,EnemyCols];
39 |
40 | // create a grid of enemies
41 | for(int y = 0; y < EnemyRows; y++)
42 | {
43 | for(int x = 0; x < EnemyCols; x++)
44 | {
45 | Enemy enemy = new Enemy();
46 | enemy.Position = new Vector2(x * enemy.Width + EnemySpacing.X, y * enemy.Height + EnemySpacing.Y);
47 | _enemies[y,x] = enemy;
48 | }
49 | }
50 |
51 | _enemyWidth = _enemies[0,0].Width;
52 |
53 | // position the grid centered at the vertical position specified above
54 | Position = new Vector2(AlienAttackGame.ScreenWidth/2.0f - ((EnemyCols * (_enemyWidth + EnemySpacing.X)) / 2), EnemyStartPosition);
55 | Velocity = EnemyVelocity;
56 | }
57 |
58 | public override void Update(GameTime gameTime)
59 | {
60 | base.Update(gameTime);
61 |
62 | MoveEnemies(gameTime);
63 | EnemyFire(gameTime);
64 |
65 | for(int i = 0; i < _explosions.Count; i++)
66 | {
67 | // update all explosions, remove those whose animations are over
68 | if(_explosions[i].Update(gameTime))
69 | _explosions.RemoveAt(i);
70 | }
71 | }
72 |
73 | public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
74 | {
75 | // draw all active enemies
76 | foreach(Enemy enemy in _enemies)
77 | {
78 | if(enemy != null)
79 | enemy.Draw(gameTime, spriteBatch);
80 | }
81 |
82 | // draw all enemy shots
83 | foreach(EnemyShot enemyShot in _enemyShots)
84 | enemyShot.Draw(gameTime, spriteBatch);
85 |
86 | // draw all explosions
87 | foreach(Explosion explosion in _explosions)
88 | explosion.Draw(gameTime, spriteBatch);
89 | }
90 |
91 | public void Reset()
92 | {
93 | _enemyShots.Clear();
94 | }
95 |
96 | private Enemy FindRightMostEnemy()
97 | {
98 | // find the enemy in the right-most position in the grid
99 | for(int x = EnemyCols-1; x > -1; x--)
100 | {
101 | for(int y = 0; y < EnemyRows; y++)
102 | {
103 | if(_enemies[y,x] != null)
104 | return _enemies[y,x];
105 | }
106 | }
107 | return null;
108 | }
109 |
110 | private Enemy FindLeftMostEnemy()
111 | {
112 | // find the enemy in the left-most position in the grid
113 | for(int x = 0; x < EnemyCols; x++)
114 | {
115 | for(int y = 0; y < EnemyRows; y++)
116 | {
117 | if(_enemies[y,x] != null)
118 | return _enemies[y,x];
119 | }
120 | }
121 | return null;
122 | }
123 |
124 | public bool AllDestroyed()
125 | {
126 | // we won if we can't find any enemies at all
127 | return (FindLeftMostEnemy() == null);
128 | }
129 |
130 | private void MoveEnemies(GameTime gameTime)
131 | {
132 | Enemy enemy = FindRightMostEnemy();
133 |
134 | // if the right-most enemy hit the screen edge, change directions
135 | if(enemy != null)
136 | {
137 | if(enemy.Position.X + enemy.Width > AlienAttackGame.ScreenWidth - ScreenEdge)
138 | {
139 | Position += EnemyVerticalJump;
140 | Velocity = -EnemyVelocity;
141 | }
142 | }
143 |
144 | enemy = FindLeftMostEnemy();
145 |
146 | // if the left-most enemy hit the screen edge, change direction
147 | if(enemy != null)
148 | {
149 | if(enemy.Position.X < ScreenEdge)
150 | {
151 | Position += EnemyVerticalJump;
152 | Velocity = EnemyVelocity;
153 | }
154 | }
155 |
156 | // update the positions of all enemies
157 | for(int y = 0; y < EnemyRows; y++)
158 | {
159 | for(int x = 0; x < EnemyCols; x++)
160 | {
161 | if(_enemies[y,x] != null)
162 | {
163 | // X = position of the whole grid + (X grid position * width of enemy) + padding
164 | // Y = position of the whole grid + (Y grid position * width of enemy) + padding
165 | _enemies[y,x].Position =
166 | new Vector2((Position.X + (x * (_enemyWidth + EnemySpacing.X))),
167 | (Position.Y + (y * (_enemyWidth + EnemySpacing.Y))));
168 | _enemies[y,x].Update(gameTime);
169 | }
170 | }
171 | }
172 | }
173 |
174 | private void EnemyFire(GameTime gameTime)
175 | {
176 | if (AllDestroyed())
177 | return;
178 |
179 | // at random times, drop an enemy shot
180 | if (_random.NextDouble() > 0.99f)
181 | {
182 | int x, y;
183 |
184 | // find an enemy that hasn't been destroyed
185 | do
186 | {
187 | x = (int)(_random.NextDouble() * EnemyCols);
188 | y = (int)(_random.NextDouble() * EnemyRows);
189 | }
190 | while (_enemies[y, x] == null);
191 |
192 | // create a shot for that enemy and add it to the list
193 | EnemyShot enemyShot = new EnemyShot();
194 | enemyShot.Position = _enemies[y, x].Position;
195 | enemyShot.Position += new Vector2(0, _enemies[y, x].Height);
196 | _enemyShots.Add(enemyShot);
197 |
198 | AudioManager.PlayCue(AudioManager.Cue.EnemyShot);
199 | }
200 |
201 | for (int i = 0; i < _enemyShots.Count; i++)
202 | {
203 | // update all shots
204 | _enemyShots[i].Update(gameTime);
205 |
206 | // remove those that are off the screen
207 | if (_enemyShots[i].Position.Y > AlienAttackGame.ScreenHeight)
208 | _enemyShots.RemoveAt(i);
209 | }
210 | }
211 |
212 | public bool CheckCollision(Sprite s1, Sprite s2)
213 | {
214 | // simple bounding box collision detection
215 | return s1.BoundingBox.Intersects(s2.BoundingBox);
216 | }
217 |
218 | public bool HandlePlayerShotCollision(PlayerShot playerShot)
219 | {
220 | for(int y = 0; y < EnemyRows; y++)
221 | {
222 | for(int x = 0; x < EnemyCols; x++)
223 | {
224 | // if a player shot hit an enemy, destroy the enemy
225 | if(_enemies[y,x] != null && CheckCollision(playerShot, _enemies[y,x]))
226 | {
227 | Explosion explosion = new Explosion();
228 | Vector2 center = _enemies[y,x].Position + (_enemies[y,x].Size/2.0f);
229 | explosion.Position = center - (explosion.Size/2.0f);
230 | _explosions.Add(explosion);
231 | _enemies[y,x] = null;
232 | return true;
233 | }
234 | }
235 | }
236 | return false;
237 | }
238 |
239 | public bool HandleEnemyShotCollision(Player player)
240 | {
241 | for(int i = 0; i < _enemyShots.Count; i++)
242 | {
243 | // if an enemy shot hit the player, destroy the player
244 | if(CheckCollision(_enemyShots[i], player))
245 | {
246 | _enemyShots.RemoveAt(i);
247 | return true;
248 | }
249 | }
250 | return false;
251 | }
252 |
253 | public bool HandleEnemyPlayerCollision(Player player)
254 | {
255 | for(int y = 0; y < EnemyRows; y++)
256 | {
257 | for(int x = 0; x < EnemyCols; x++)
258 | {
259 | // if an enemy hit the player, destroy the enemy
260 | if(_enemies[y,x] != null && CheckCollision(_enemies[y,x], player))
261 | {
262 | Explosion explosion = new Explosion();
263 | Vector2 center = _enemies[y,x].Position + (_enemies[y,x].Size/2.0f);
264 | explosion.Position = center - (explosion.Size/2.0f);
265 | _explosions.Add(explosion);
266 | _enemies[y,x] = null;
267 | return true;
268 | }
269 | }
270 | }
271 | return false;
272 | }
273 | }
274 | }
275 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Sprites/EnemyShot.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class EnemyShot : Sprite
6 | {
7 | public EnemyShot()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\eshot\\eshot_{0}", 3);
10 | Velocity = new Vector2(0, 350 / 1000.0f);
11 | }
12 |
13 | public override void Update(GameTime gameTime)
14 | {
15 | base.Update(gameTime);
16 | AnimateReverse(gameTime, 60);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Sprites/Explosion.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class Explosion : Sprite
6 | {
7 | public Explosion()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\explosion\\explosion_{0}", 9);
10 | }
11 |
12 | public new bool Update(GameTime gameTime)
13 | {
14 | // if it's the final frame, return true to let the other side know we're done
15 | if(FrameIndex == 8)
16 | return true;
17 |
18 | AnimateLoop(gameTime, 60);
19 |
20 | return false;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Sprites/Player.cs:
--------------------------------------------------------------------------------
1 | namespace AlienAttackUniversal.Sprites
2 | {
3 | public class Player : Sprite
4 | {
5 | public Player()
6 | {
7 | // TODO: Animation for left/right!
8 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\player\\player");
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Sprites/PlayerShot.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class PlayerShot : Sprite
6 | {
7 | public PlayerShot()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\pshot\\pshot_{0}", 3);
10 | Velocity = new Vector2(0, -300 / 1000.0f);
11 | }
12 |
13 | public override void Update(GameTime gameTime)
14 | {
15 | base.Update(gameTime);
16 | AnimateReverse(gameTime, 100);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/Sprites/Sprite.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Content;
3 | using Microsoft.Xna.Framework.Graphics;
4 |
5 | namespace AlienAttackUniversal.Sprites
6 | {
7 | public class Sprite
8 | {
9 | // all textures in animation set
10 | protected Texture2D[] Frames { get; set; }
11 |
12 | // current frame to draw
13 | protected int FrameIndex { get; set; }
14 |
15 | // total number of frames
16 | protected int FrameCount { get; set; }
17 |
18 | // size of sprite
19 | public Vector2 Size { get { return new Vector2(Width, Height); } }
20 | public int Width { get; set; }
21 | public int Height { get; set; }
22 |
23 | public Vector2 Position { get; set; }
24 | public Vector2 Velocity { get; set; }
25 | public float Rotation { get; set; }
26 | public Vector2 Scale { get; set; } = Vector2.One;
27 |
28 | // variable to track number of millieconds for animations
29 | private double _time;
30 |
31 | // bounding box of sprite...used for collisions
32 | private Rectangle _boundingBox;
33 | private int _animationDirection = 1;
34 |
35 | public Sprite()
36 | {
37 | Scale = Vector2.One;
38 | }
39 |
40 | public virtual void LoadContent(ContentManager contentManager, string name)
41 | {
42 | // load single frame
43 | Frames = new Texture2D[1];
44 | Frames[0] = contentManager.Load(name);
45 | Width = Frames[0].Width;
46 | Height = Frames[0].Height;
47 | }
48 |
49 | public virtual void LoadContent(ContentManager contentManager, string name, int count)
50 | {
51 | // load multiple frames
52 | Frames = new Texture2D[count];
53 | for(int i = 0; i < count; i++)
54 | Frames[i] = contentManager.Load(string.Format(name, i));
55 | FrameCount = count;
56 | Width = Frames[0].Width;
57 | Height = Frames[0].Height;
58 | }
59 |
60 | public virtual void AnimateLoop(GameTime gameTime, double frameTime)
61 | {
62 | // count number of milliseconds
63 | _time += gameTime.ElapsedGameTime.TotalMilliseconds;
64 |
65 | // if we're over the time for the next frame, move on
66 | if(_time > frameTime)
67 | {
68 | FrameIndex++;
69 | _time -= frameTime;
70 | }
71 |
72 | // if we're past the # of frames, start back at 0
73 | if(FrameIndex > FrameCount-1)
74 | FrameIndex = 0;
75 | }
76 |
77 | public virtual void AnimateReverse(GameTime gameTime, double frameTime)
78 | {
79 | // same as above, but reverse direction instead of starting back at 0
80 | _time += gameTime.ElapsedGameTime.TotalMilliseconds;
81 | if(_time > frameTime)
82 | {
83 | _time -= frameTime;
84 |
85 | if(FrameIndex == 0)
86 | _animationDirection = 1;
87 | else if(FrameIndex == FrameCount-1)
88 | _animationDirection = -1;
89 |
90 | FrameIndex += _animationDirection;
91 | }
92 | }
93 |
94 | public virtual void Update(GameTime gameTime)
95 | {
96 | // move the sprite 1 velocity unit
97 | Position += Velocity * gameTime.ElapsedGameTime.Milliseconds;
98 | }
99 |
100 | public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
101 | {
102 | if(Frames == null)
103 | return;
104 |
105 | spriteBatch.Draw(Frames[FrameIndex], position:Position, color:Color.White, scale:Scale);
106 | }
107 |
108 | public virtual Rectangle BoundingBox
109 | {
110 | get
111 | {
112 | // only need to assign this once
113 | if(_boundingBox == Rectangle.Empty)
114 | {
115 | _boundingBox.Width = Width;
116 | _boundingBox.Height = Height;
117 | }
118 | _boundingBox.X = (int)Position.X;
119 | _boundingBox.Y = (int)Position.Y;
120 |
121 | return _boundingBox;
122 | }
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/Source/Complete/AlienAttack/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
4 | },
5 | "frameworks": {
6 | "uap10.0": {}
7 | },
8 | "runtimes": {
9 | "win10-arm": {},
10 | "win10-arm-aot": {},
11 | "win10-x86": {},
12 | "win10-x86-aot": {},
13 | "win10-x64": {},
14 | "win10-x64-aot": {}
15 | }
16 | }
--------------------------------------------------------------------------------
/Source/Ex1/Begin/AlienAttackGame.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using AlienAttackUniversal.Sprites;
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Audio;
5 | using Microsoft.Xna.Framework.Graphics;
6 | using Microsoft.Xna.Framework.Input;
7 | using Microsoft.Xna.Framework.Input.Touch;
8 | using Microsoft.Xna.Framework.Media;
9 |
10 | namespace AlienAttackUniversal
11 | {
12 | ///
13 | /// This is the main type for your game
14 | ///
15 | public class AlienAttackGame : Game
16 | {
17 | public static int ScreenWidth = 1920;
18 | public static int ScreenHeight = 1080;
19 | private static int ShotTime = 500;
20 | private static readonly Vector2 PlayerVelocity = new Vector2(400 / 1000.0f, 0);
21 | private static readonly Vector2 ScorePosition = new Vector2(ScreenWidth / 2.0f, 30);
22 | private static Vector2 PlayerStartPosition;
23 |
24 | public static AlienAttackGame Instance;
25 | private readonly GraphicsDeviceManager _graphics;
26 | private SpriteBatch _spriteBatch;
27 | private RenderTargetScaler _scaler;
28 | private static KeyboardState _keyboardState, _lastKeyboard;
29 | private Texture2D _bgScreen;
30 | private Player _player;
31 | private List _playerShots;
32 | private double _lastShotTime;
33 | private Explosion _playerExplosion;
34 | private EnemyGroup _enemyGroup;
35 | private SpriteFont _font;
36 | private Song _theme;
37 | private SoundEffect _playerShot;
38 | private SoundEffect _explosion;
39 |
40 | private int _score;
41 |
42 | public AlienAttackGame()
43 | {
44 | Instance = this;
45 |
46 | _graphics = new GraphicsDeviceManager(this);
47 |
48 | // set our screen size based on the device
49 | _graphics.PreferredBackBufferWidth = ScreenWidth;
50 | _graphics.PreferredBackBufferHeight = ScreenHeight;
51 |
52 | Content.RootDirectory = "Content";
53 | }
54 |
55 | ///
56 | /// Allows the game to perform any initialization it needs to before starting to run.
57 | /// This is where it can query for any required services and load any non-graphic
58 | /// related content. Calling base.Initialize will enumerate through any components
59 | /// and initialize them as well.
60 | ///
61 | protected override void Initialize()
62 | {
63 | _scaler = new RenderTargetScaler(this, _graphics, ScreenWidth, ScreenHeight);
64 |
65 | _spriteBatch = new SpriteBatch(GraphicsDevice);
66 |
67 | _player = new Player();
68 | PlayerStartPosition = new Vector2(ScreenWidth / 2 - _player.Width / 2, ScreenHeight - 120);
69 | _player.Position = PlayerStartPosition;
70 |
71 | _enemyGroup = new EnemyGroup();
72 |
73 | _playerShots = new List();
74 |
75 | //
76 | // TODO: Enable TouchPanel gestures
77 | //
78 |
79 | base.Initialize();
80 | }
81 |
82 | ///
83 | /// LoadContent will be called once per game and is the place to load
84 | /// all of your content.
85 | ///
86 | protected override void LoadContent()
87 | {
88 | _bgScreen = Content.Load("gfx\\bgScreen");
89 | _font = Content.Load("font");
90 | _explosion = Content.Load("sfx\\explosion");
91 |
92 | //
93 | // TODO: Load playerShot sound effect
94 | //
95 |
96 | //
97 | // TODO: Load background music
98 | //
99 | }
100 |
101 | ///
102 | /// UnloadContent will be called once per game and is the place to unload
103 | /// all content.
104 | ///
105 | protected override void UnloadContent()
106 | {
107 | }
108 |
109 | ///
110 | /// Allows the game to run logic such as updating the world,
111 | /// checking for collisions, gathering input, and playing audio.
112 | ///
113 | /// Provides a snapshot of timing values.
114 | protected override void Update(GameTime gameTime)
115 | {
116 | bool left = false, right = false, fire = false;
117 |
118 | //
119 | // TODO: Play background music
120 | //
121 |
122 | //
123 | // TODO: Read keyboard
124 | //
125 |
126 | //
127 | // TODO: Read touch input
128 | //
129 |
130 | if (_player != null)
131 | {
132 | if(left && _player.Position.X > 0)
133 | _player.Velocity = -PlayerVelocity;
134 | else if(right && _player.Position.X + _player.Width < ScreenWidth)
135 | _player.Velocity = PlayerVelocity;
136 | else
137 | _player.Velocity = Vector2.Zero;
138 |
139 |
140 | if(fire && gameTime.TotalGameTime.TotalMilliseconds - _lastShotTime > ShotTime)
141 | {
142 | AddPlayerShot();
143 | _lastShotTime = gameTime.TotalGameTime.TotalMilliseconds;
144 | }
145 |
146 | _player.Update(gameTime);
147 | }
148 |
149 | _enemyGroup.Update(gameTime);
150 | UpdatePlayerShots(gameTime);
151 | HandleCollisions(gameTime);
152 |
153 | //
154 | // TODO: Store last keyboard state
155 | //
156 |
157 | base.Update(gameTime);
158 | }
159 |
160 | ///
161 | /// This is called when the game should draw itself.
162 | ///
163 | /// Provides a snapshot of timing values.
164 | protected override void Draw(GameTime gameTime)
165 | {
166 | _scaler.SetRenderTarget();
167 | _spriteBatch.Begin();
168 |
169 | _spriteBatch.Draw(_bgScreen, Vector2.Zero, Color.White);
170 |
171 | // draw the enemy board
172 | _enemyGroup.Draw(gameTime, _spriteBatch);
173 |
174 | // draw the player shots
175 | foreach(PlayerShot playerShot in _playerShots)
176 | playerShot.Draw(gameTime, _spriteBatch);
177 |
178 | // draw the player
179 | if (_player != null)
180 | _player.Draw(gameTime, _spriteBatch);
181 |
182 | // draw the player explosion
183 | if (_playerExplosion != null)
184 | _playerExplosion.Draw(gameTime, _spriteBatch);
185 |
186 | //
187 | // TODO: Draw score
188 | //
189 |
190 | _spriteBatch.End();
191 | _scaler.Draw();
192 | }
193 |
194 | #region Game Logic
195 | private void HandleCollisions(GameTime gameTime)
196 | {
197 | // see if a player shot hit an enemy
198 | for(int i = 0; i < _playerShots.Count; i++)
199 | {
200 | PlayerShot playerShot = _playerShots[i];
201 | // check the shot and see if it it collided with an enemy
202 | if(playerShot != null && _enemyGroup.HandlePlayerShotCollision(_playerShots[i]))
203 | {
204 | // remove the shot, add the score
205 | _playerShots.RemoveAt(i);
206 | _score += 100;
207 | _explosion.Play();
208 | }
209 | }
210 |
211 | // see if an enemy shot hit the player
212 | if(_player != null && _enemyGroup.HandleEnemyShotCollision(_player))
213 | {
214 | // blow up the player
215 | _playerExplosion = new Explosion();
216 | Vector2 center = _player.Position + (_player.Size/2.0f);
217 | _playerExplosion.Position = center - (_playerExplosion.Size/2.0f);
218 | _player = null;
219 | _explosion.Play();
220 | }
221 |
222 | // if the player explosion animation is running, update it
223 | if(_playerExplosion != null)
224 | {
225 | // if this is the last frame
226 | if(_playerExplosion.Update(gameTime))
227 | {
228 | // remove it
229 | _playerExplosion = null;
230 |
231 | // reset the board
232 | _enemyGroup.Reset();
233 | _playerShots.Clear();
234 |
235 | _player = new Player();
236 | _player.Position = PlayerStartPosition;
237 | }
238 | }
239 | }
240 |
241 | private void AddPlayerShot()
242 | {
243 | // create a new shot over the ship
244 | PlayerShot ps = new PlayerShot();
245 | ps.Position = _player.Position + (_player.Size/2) - (ps.Size/2) - new Vector2(0, ps.Height);
246 | _playerShots.Add(ps);
247 | }
248 |
249 | private void UpdatePlayerShots(GameTime gameTime)
250 | {
251 | // enumerate the player shots on the screen
252 | for(int i = 0; i < _playerShots.Count; i++)
253 | {
254 | PlayerShot playerShot = _playerShots[i];
255 |
256 | playerShot.Update(gameTime);
257 |
258 | // if it's off the top of the screen, remove it from the list
259 | if(playerShot.Position.Y + playerShot.Height < 0)
260 | _playerShots.RemoveAt(i);
261 | }
262 | }
263 | #endregion
264 | }
265 | }
266 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/AlienAttackUniversal.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Debug
7 | x86
8 | {5EF2882F-8277-4262-A697-F96590277E1B}
9 | AppContainerExe
10 | Properties
11 | AlienAttackUniversal
12 | AlienAttackUniversal
13 | en-US
14 | UAP
15 | 10.0.10586.0
16 | 10.0.10240.0
17 | 14
18 | true
19 | 512
20 | {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
21 | AlienAttackUniversal_TemporaryKey.pfx
22 | WindowsStoreApp
23 |
24 |
25 | 1B746EAE1B884C3984963143A1445D8BA3095A62
26 | False
27 | False
28 | Always
29 | x86
30 |
31 |
32 | true
33 | bin\WindowsUniversal\ARM\Debug\
34 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UAP
35 | ;2008
36 | full
37 | ARM
38 | false
39 | prompt
40 | true
41 |
42 |
43 | bin\WindowsUniversal\ARM\Release\
44 | TRACE;NETFX_CORE;WINDOWS_UAP
45 | true
46 | ;2008
47 | pdbonly
48 | ARM
49 | false
50 | prompt
51 | true
52 | true
53 |
54 |
55 | true
56 | bin\WindowsUniversal\x64\Debug\
57 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UAP
58 | ;2008
59 | full
60 | x64
61 | false
62 | prompt
63 | true
64 |
65 |
66 | bin\WindowsUniversal\x64\Release\
67 | TRACE;NETFX_CORE;WINDOWS_UAP
68 | true
69 | ;2008
70 | pdbonly
71 | x64
72 | false
73 | prompt
74 | true
75 | true
76 |
77 |
78 | true
79 | bin\WindowsUniversal\x86\Debug\
80 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UAP
81 | ;2008
82 | full
83 | x86
84 | false
85 | prompt
86 | true
87 |
88 |
89 | bin\WindowsUniversal\x86\Release\
90 | TRACE;NETFX_CORE;WINDOWS_UAP
91 | true
92 | ;2008
93 | pdbonly
94 | x86
95 | false
96 | prompt
97 | true
98 | true
99 |
100 |
101 |
102 |
103 | $(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\WindowsUniversal\MonoGame.Framework.dll
104 |
105 |
106 |
107 |
108 |
109 | App.xaml
110 |
111 |
112 | GamePage.xaml
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 | Designer
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 | MSBuild:Compile
152 | Designer
153 |
154 |
155 | MSBuild:Compile
156 | Designer
157 |
158 |
159 |
160 |
161 | 14.0
162 |
163 |
164 |
165 |
172 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/AlienAttackUniversal.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlienAttackUniversal", "AlienAttackUniversal.csproj", "{595C9FD9-6573-4D8F-9E21-69218E0A1FE7}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|ARM = Debug|ARM
11 | Debug|x64 = Debug|x64
12 | Debug|x86 = Debug|x86
13 | Release|ARM = Release|ARM
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Debug|ARM.ActiveCfg = Debug|ARM
19 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Debug|ARM.Build.0 = Debug|ARM
20 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Debug|ARM.Deploy.0 = Debug|ARM
21 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Debug|x64.ActiveCfg = Debug|x64
22 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Debug|x64.Build.0 = Debug|x64
23 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Debug|x64.Deploy.0 = Debug|x64
24 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Debug|x86.ActiveCfg = Debug|x86
25 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Debug|x86.Build.0 = Debug|x86
26 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Debug|x86.Deploy.0 = Debug|x86
27 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Release|ARM.ActiveCfg = Release|ARM
28 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Release|ARM.Build.0 = Release|ARM
29 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Release|ARM.Deploy.0 = Release|ARM
30 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Release|x64.ActiveCfg = Release|x64
31 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Release|x64.Build.0 = Release|x64
32 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Release|x64.Deploy.0 = Release|x64
33 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Release|x86.ActiveCfg = Release|x86
34 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Release|x86.Build.0 = Release|x86
35 | {595C9FD9-6573-4D8F-9E21-69218E0A1FE7}.Release|x86.Deploy.0 = Release|x86
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/AlienAttackUniversal_TemporaryKey.pfx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/AlienAttackUniversal_TemporaryKey.pfx
--------------------------------------------------------------------------------
/Source/Ex1/Begin/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Runtime.InteropServices.WindowsRuntime;
6 | using Windows.ApplicationModel;
7 | using Windows.ApplicationModel.Activation;
8 | using Windows.Foundation;
9 | using Windows.Foundation.Collections;
10 | using Windows.UI.Xaml;
11 | using Windows.UI.Xaml.Controls;
12 | using Windows.UI.Xaml.Controls.Primitives;
13 | using Windows.UI.Xaml.Data;
14 | using Windows.UI.Xaml.Input;
15 | using Windows.UI.Xaml.Media;
16 | using Windows.UI.Xaml.Navigation;
17 |
18 | // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=402347&clcid=0x409
19 |
20 | namespace AlienAttackUniversal
21 | {
22 | ///
23 | /// Provides application-specific behavior to supplement the default Application class.
24 | ///
25 | sealed partial class App : Application
26 | {
27 | ///
28 | /// Initializes the singleton application object. This is the first line of authored code
29 | /// executed, and as such is the logical equivalent of main() or WinMain().
30 | ///
31 | public App()
32 | {
33 | this.InitializeComponent();
34 | this.Suspending += OnSuspending;
35 | }
36 |
37 | ///
38 | /// Invoked when the application is launched normally by the end user. Other entry points
39 | /// will be used such as when the application is launched to open a specific file.
40 | ///
41 | /// Details about the launch request and process.
42 | protected override void OnLaunched(LaunchActivatedEventArgs e)
43 | {
44 |
45 | #if DEBUG
46 | if (System.Diagnostics.Debugger.IsAttached)
47 | {
48 | this.DebugSettings.EnableFrameRateCounter = true;
49 | }
50 | #endif
51 |
52 | Frame rootFrame = Window.Current.Content as Frame;
53 |
54 | // Do not repeat app initialization when the Window already has content,
55 | // just ensure that the window is active
56 | if (rootFrame == null)
57 | {
58 | // Create a Frame to act as the navigation context and navigate to the first page
59 | rootFrame = new Frame();
60 |
61 | rootFrame.NavigationFailed += OnNavigationFailed;
62 |
63 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
64 | {
65 | //TODO: Load state from previously suspended application
66 | }
67 |
68 | // Place the frame in the current Window
69 | Window.Current.Content = rootFrame;
70 | }
71 |
72 | if (rootFrame.Content == null)
73 | {
74 | // When the navigation stack isn't restored navigate to the first page,
75 | // configuring the new page by passing required information as a navigation
76 | // parameter
77 | rootFrame.Navigate(typeof(GamePage), e.Arguments);
78 | }
79 | // Ensure the current window is active
80 | Window.Current.Activate();
81 | }
82 |
83 | ///
84 | /// Invoked when Navigation to a certain page fails
85 | ///
86 | /// The Frame which failed navigation
87 | /// Details about the navigation failure
88 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
89 | {
90 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
91 | }
92 |
93 | ///
94 | /// Invoked when application execution is being suspended. Application state is saved
95 | /// without knowing whether the application will be terminated or resumed with the contents
96 | /// of memory still intact.
97 | ///
98 | /// The source of the suspend request.
99 | /// Details about the suspend request.
100 | private void OnSuspending(object sender, SuspendingEventArgs e)
101 | {
102 | var deferral = e.SuspendingOperation.GetDeferral();
103 | //TODO: Save application state and stop any background activity
104 | deferral.Complete();
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/SmallLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/SmallLogo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/Square310x310Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/Square310x310Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/Square71x71Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/Square71x71Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/StoreLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/StoreLogo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/uwp_100x100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/uwp_100x100.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/uwp_142x142.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/uwp_142x142.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Assets/uwp_620x620.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Assets/uwp_620x620.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/Audiowide-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/Audiowide-Regular.ttf
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/Font.spritefont:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
15 | Audiowide-Regular
16 |
17 |
21 | 36
22 |
23 |
27 | 0
28 |
29 |
33 | true
34 |
35 |
39 |
40 |
41 |
48 |
49 |
50 |
51 | ~
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/bgScreen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/bgScreen.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_0.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_1.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_2.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_3.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_4.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_5.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_6.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_7.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_8.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/enemy1/enemy1_9.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/eshot/eshot_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/eshot/eshot_0.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/eshot/eshot_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/eshot/eshot_1.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/eshot/eshot_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/eshot/eshot_2.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/explosion/explosion_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/explosion/explosion_0.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/explosion/explosion_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/explosion/explosion_1.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/explosion/explosion_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/explosion/explosion_2.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/explosion/explosion_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/explosion/explosion_3.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/explosion/explosion_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/explosion/explosion_4.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/explosion/explosion_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/explosion/explosion_5.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/explosion/explosion_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/explosion/explosion_6.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/explosion/explosion_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/explosion/explosion_7.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/explosion/explosion_8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/explosion/explosion_8.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/player.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/player.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/pshot/pshot_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/pshot/pshot_0.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/pshot/pshot_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/pshot/pshot_1.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/pshot/pshot_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/pshot/pshot_2.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/gfx/titleScreen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/gfx/titleScreen.png
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/sfx/enemyShot.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/sfx/enemyShot.wav
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/sfx/explosion.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/sfx/explosion.wav
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/sfx/playerShot.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/sfx/playerShot.wav
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Content/sfx/theme.wma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/Begin/Content/sfx/theme.wma
--------------------------------------------------------------------------------
/Source/Ex1/Begin/GamePage.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/GamePage.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Runtime.InteropServices.WindowsRuntime;
6 | using Windows.Foundation;
7 | using Windows.Foundation.Collections;
8 | using Windows.UI.Xaml;
9 | using Windows.UI.Xaml.Controls;
10 | using Windows.UI.Xaml.Controls.Primitives;
11 | using Windows.UI.Xaml.Data;
12 | using Windows.UI.Xaml.Input;
13 | using Windows.UI.Xaml.Media;
14 | using Windows.UI.Xaml.Navigation;
15 |
16 | // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
17 |
18 | namespace AlienAttackUniversal
19 | {
20 | ///
21 | /// An empty page that can be used on its own or navigated to within a Frame.
22 | ///
23 | public sealed partial class GamePage : Page
24 | {
25 | readonly AlienAttackGame _game;
26 |
27 | public GamePage()
28 | {
29 | this.InitializeComponent();
30 |
31 | // Create the game.
32 | var launchArguments = string.Empty;
33 | _game = MonoGame.Framework.XamlGame.Create(launchArguments, Window.Current.CoreWindow, swapChainPanel);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Alien Attack
7 | TED Games Squad
8 | Assets\StoreLogo.png
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("AlienAttackUniversal")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("AlienAttackUniversal")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Version information for an assembly consists of the following four values:
18 | //
19 | // Major Version
20 | // Minor Version
21 | // Build Number
22 | // Revision
23 | //
24 | // You can specify all the values or you can default the Build and Revision Numbers
25 | // by using the '*' as shown below:
26 | // [assembly: AssemblyVersion("1.0.*")]
27 | [assembly: AssemblyVersion("1.0.0.0")]
28 | [assembly: AssemblyFileVersion("1.0.0.0")]
29 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/RenderTargetScaler.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Graphics;
3 |
4 | namespace AlienAttackUniversal
5 | {
6 | class RenderTargetScaler
7 | {
8 | private readonly RenderTarget2D _drawBuffer;
9 | private readonly GraphicsDeviceManager _graphicsDeviceManager;
10 | private readonly int _screenWidth;
11 | private readonly int _screenHeight;
12 | private readonly Game _game;
13 | private readonly SpriteBatch _spriteBatch;
14 |
15 | public RenderTargetScaler(Game game, GraphicsDeviceManager graphicsDeviceManager, int width, int height)
16 | {
17 | _game = game;
18 | _graphicsDeviceManager = graphicsDeviceManager;
19 | _screenWidth = width;
20 | _screenHeight = height;
21 |
22 | _spriteBatch = new SpriteBatch(graphicsDeviceManager.GraphicsDevice);
23 |
24 | // create a surface to draw on which is then scaled to the screen size on the PC
25 | _drawBuffer = new RenderTarget2D(graphicsDeviceManager.GraphicsDevice,
26 | width, height);
27 |
28 | }
29 |
30 | public void SetRenderTarget()
31 | {
32 | _graphicsDeviceManager.GraphicsDevice.SetRenderTarget(_drawBuffer);
33 | }
34 |
35 | public void Draw()
36 | {
37 | float outputAspect = _game.Window.ClientBounds.Width / (float)_game.Window.ClientBounds.Height;
38 | float preferredAspect = _screenWidth / (float)_screenHeight;
39 |
40 | Rectangle dst;
41 |
42 | if (outputAspect <= preferredAspect)
43 | {
44 | // output is taller than it is wider, bars on top/bottom
45 | int presentHeight = (int)((_game.Window.ClientBounds.Width / preferredAspect) + 0.5f);
46 | int barHeight = (_game.Window.ClientBounds.Height - presentHeight) / 2;
47 |
48 | dst = new Rectangle(0, barHeight, _game.Window.ClientBounds.Width, presentHeight);
49 | }
50 | else
51 | {
52 | // output is wider than it is tall, bars left/right
53 | int presentWidth = (int)((_game.Window.ClientBounds.Height * preferredAspect) + 0.5f);
54 | int barWidth = (_game.Window.ClientBounds.Width - presentWidth) / 2;
55 |
56 | dst = new Rectangle(barWidth, 0, presentWidth, _game.Window.ClientBounds.Height);
57 | }
58 |
59 | _graphicsDeviceManager.GraphicsDevice.SetRenderTarget(null);
60 |
61 | // clear to get black bars
62 | _graphicsDeviceManager.GraphicsDevice.Clear(Color.Black);
63 |
64 | // draw a quad to get the draw buffer to the back buffer
65 | _spriteBatch.Begin();
66 | _spriteBatch.Draw(_drawBuffer, dst, Color.White);
67 | _spriteBatch.End();
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Sprites/Enemy.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class Enemy : Sprite
6 | {
7 | public Enemy()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\enemy1\\enemy1_{0}", 10);
10 | }
11 |
12 | public override void Update(GameTime gameTime)
13 | {
14 | AnimateReverse(gameTime, 60);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Sprites/EnemyGroup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Audio;
5 | using Microsoft.Xna.Framework.Graphics;
6 |
7 | namespace AlienAttackUniversal.Sprites
8 | {
9 | public class EnemyGroup : Sprite
10 | {
11 | // grid of enemies
12 | private readonly Enemy[,] _enemies;
13 |
14 | // all enemy shots
15 | private readonly List _enemyShots;
16 |
17 | // all enemy explosions
18 | private readonly List _explosions;
19 | private readonly Random _random;
20 |
21 | // width of single enemy
22 | private readonly int _enemyWidth;
23 |
24 | private const int EnemyRows = 4; // number of rows in grid
25 | private const int EnemyCols = 8; // number of cols in grid
26 | private readonly Vector2 EnemyVerticalJump = new Vector2(0, 10); // number of pixels to jump vertically after hitting edge
27 | private const int EnemyStartPosition = 10; // vertical position of grid
28 | private const int ScreenEdge = 20; // virtual edge of screen to change direction
29 | private Vector2 EnemySpacing = new Vector2(16, 32); // space between sprites
30 | private readonly Vector2 EnemyVelocity = new Vector2(100 / 1000.0f, 0); // speed at which grid moves per frame
31 | private readonly SoundEffect _enemyShot;
32 |
33 | public EnemyGroup()
34 | {
35 | _random = new Random();
36 |
37 | _enemyShots = new List();
38 | _explosions = new List();
39 |
40 | _enemies = new Enemy[EnemyRows,EnemyCols];
41 |
42 | _enemyShot = AlienAttackGame.Instance.Content.Load("sfx\\enemyShot");
43 |
44 | // create a grid of enemies
45 | for(int y = 0; y < EnemyRows; y++)
46 | {
47 | for(int x = 0; x < EnemyCols; x++)
48 | {
49 | Enemy enemy = new Enemy();
50 | enemy.Position = new Vector2(x * enemy.Width + EnemySpacing.X, y * enemy.Height + EnemySpacing.Y);
51 | _enemies[y,x] = enemy;
52 | }
53 | }
54 |
55 | _enemyWidth = _enemies[0,0].Width;
56 |
57 | // position the grid centered at the vertical position specified above
58 | Position = new Vector2(AlienAttackGame.ScreenWidth/2.0f - ((EnemyCols * (_enemyWidth + EnemySpacing.X)) / 2), EnemyStartPosition);
59 | Velocity = EnemyVelocity;
60 | }
61 |
62 | public override void Update(GameTime gameTime)
63 | {
64 | base.Update(gameTime);
65 |
66 | MoveEnemies(gameTime);
67 | EnemyFire(gameTime);
68 |
69 | for(int i = 0; i < _explosions.Count; i++)
70 | {
71 | // update all explosions, remove those whose animations are over
72 | if(_explosions[i].Update(gameTime))
73 | _explosions.RemoveAt(i);
74 | }
75 | }
76 |
77 | public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
78 | {
79 | // draw all active enemies
80 | foreach(Enemy enemy in _enemies)
81 | {
82 | if(enemy != null)
83 | enemy.Draw(gameTime, spriteBatch);
84 | }
85 |
86 | // draw all enemy shots
87 | foreach(EnemyShot enemyShot in _enemyShots)
88 | enemyShot.Draw(gameTime, spriteBatch);
89 |
90 | // draw all explosions
91 | foreach(Explosion explosion in _explosions)
92 | explosion.Draw(gameTime, spriteBatch);
93 | }
94 |
95 | public void Reset()
96 | {
97 | _enemyShots.Clear();
98 | }
99 |
100 | private Enemy FindRightMostEnemy()
101 | {
102 | // find the enemy in the right-most position in the grid
103 | for(int x = EnemyCols-1; x > -1; x--)
104 | {
105 | for(int y = 0; y < EnemyRows; y++)
106 | {
107 | if(_enemies[y,x] != null)
108 | return _enemies[y,x];
109 | }
110 | }
111 | return null;
112 | }
113 |
114 | private Enemy FindLeftMostEnemy()
115 | {
116 | // find the enemy in the left-most position in the grid
117 | for(int x = 0; x < EnemyCols; x++)
118 | {
119 | for(int y = 0; y < EnemyRows; y++)
120 | {
121 | if(_enemies[y,x] != null)
122 | return _enemies[y,x];
123 | }
124 | }
125 | return null;
126 | }
127 |
128 | public bool AllDestroyed()
129 | {
130 | // we won if we can't find any enemies at all
131 | return (FindLeftMostEnemy() == null);
132 | }
133 |
134 | private void MoveEnemies(GameTime gameTime)
135 | {
136 | Enemy enemy = FindRightMostEnemy();
137 |
138 | // if the right-most enemy hit the screen edge, change directions
139 | if(enemy != null)
140 | {
141 | if(enemy.Position.X + enemy.Width > AlienAttackGame.ScreenWidth - ScreenEdge)
142 | {
143 | Position += EnemyVerticalJump;
144 | Velocity = -EnemyVelocity;
145 | }
146 | }
147 |
148 | enemy = FindLeftMostEnemy();
149 |
150 | // if the left-most enemy hit the screen edge, change direction
151 | if(enemy != null)
152 | {
153 | if(enemy.Position.X < ScreenEdge)
154 | {
155 | Position += EnemyVerticalJump;
156 | Velocity = EnemyVelocity;
157 | }
158 | }
159 |
160 | // update the positions of all enemies
161 | for(int y = 0; y < EnemyRows; y++)
162 | {
163 | for(int x = 0; x < EnemyCols; x++)
164 | {
165 | if(_enemies[y,x] != null)
166 | {
167 | // X = position of the whole grid + (X grid position * width of enemy) + padding
168 | // Y = position of the whole grid + (Y grid position * width of enemy) + padding
169 | _enemies[y,x].Position =
170 | new Vector2((Position.X + (x * (_enemyWidth + EnemySpacing.X))),
171 | (Position.Y + (y * (_enemyWidth + EnemySpacing.Y))));
172 | _enemies[y,x].Update(gameTime);
173 | }
174 | }
175 | }
176 | }
177 |
178 | private void EnemyFire(GameTime gameTime)
179 | {
180 | if (AllDestroyed())
181 | return;
182 |
183 | // at random times, drop an enemy shot
184 | if (_random.NextDouble() > 0.99f)
185 | {
186 | int x, y;
187 |
188 | // find an enemy that hasn't been destroyed
189 | do
190 | {
191 | x = (int)(_random.NextDouble() * EnemyCols);
192 | y = (int)(_random.NextDouble() * EnemyRows);
193 | }
194 | while (_enemies[y, x] == null);
195 |
196 | // create a shot for that enemy and add it to the list
197 | EnemyShot enemyShot = new EnemyShot();
198 | enemyShot.Position = _enemies[y, x].Position;
199 | enemyShot.Position += new Vector2(0, _enemies[y, x].Height);
200 | _enemyShots.Add(enemyShot);
201 |
202 | _enemyShot.Play();
203 | }
204 |
205 | for (int i = 0; i < _enemyShots.Count; i++)
206 | {
207 | // update all shots
208 | _enemyShots[i].Update(gameTime);
209 |
210 | // remove those that are off the screen
211 | if (_enemyShots[i].Position.Y > AlienAttackGame.ScreenHeight)
212 | _enemyShots.RemoveAt(i);
213 | }
214 | }
215 |
216 | public bool CheckCollision(Sprite s1, Sprite s2)
217 | {
218 | // simple bounding box collision detection
219 | return s1.BoundingBox.Intersects(s2.BoundingBox);
220 | }
221 |
222 | public bool HandlePlayerShotCollision(PlayerShot playerShot)
223 | {
224 | for(int y = 0; y < EnemyRows; y++)
225 | {
226 | for(int x = 0; x < EnemyCols; x++)
227 | {
228 | // if a player shot hit an enemy, destroy the enemy
229 | if(_enemies[y,x] != null && CheckCollision(playerShot, _enemies[y,x]))
230 | {
231 | Explosion explosion = new Explosion();
232 | Vector2 center = _enemies[y,x].Position + (_enemies[y,x].Size/2.0f);
233 | explosion.Position = center - (explosion.Size/2.0f);
234 | _explosions.Add(explosion);
235 | _enemies[y,x] = null;
236 | return true;
237 | }
238 | }
239 | }
240 | return false;
241 | }
242 |
243 | public bool HandleEnemyShotCollision(Player player)
244 | {
245 | for(int i = 0; i < _enemyShots.Count; i++)
246 | {
247 | // if an enemy shot hit the player, destroy the player
248 | if(CheckCollision(_enemyShots[i], player))
249 | {
250 | _enemyShots.RemoveAt(i);
251 | return true;
252 | }
253 | }
254 | return false;
255 | }
256 |
257 | public bool HandleEnemyPlayerCollision(Player player)
258 | {
259 | for(int y = 0; y < EnemyRows; y++)
260 | {
261 | for(int x = 0; x < EnemyCols; x++)
262 | {
263 | // if an enemy hit the player, destroy the enemy
264 | if(_enemies[y,x] != null && CheckCollision(_enemies[y,x], player))
265 | {
266 | Explosion explosion = new Explosion();
267 | Vector2 center = _enemies[y,x].Position + (_enemies[y,x].Size/2.0f);
268 | explosion.Position = center - (explosion.Size/2.0f);
269 | _explosions.Add(explosion);
270 | _enemies[y,x] = null;
271 | return true;
272 | }
273 | }
274 | }
275 | return false;
276 | }
277 | }
278 | }
279 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Sprites/EnemyShot.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class EnemyShot : Sprite
6 | {
7 | public EnemyShot()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\eshot\\eshot_{0}", 3);
10 | Velocity = new Vector2(0, 350 / 1000.0f);
11 | }
12 |
13 | public override void Update(GameTime gameTime)
14 | {
15 | base.Update(gameTime);
16 | AnimateReverse(gameTime, 60);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Sprites/Explosion.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class Explosion : Sprite
6 | {
7 | public Explosion()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\explosion\\explosion_{0}", 9);
10 | }
11 |
12 | public new bool Update(GameTime gameTime)
13 | {
14 | // if it's the final frame, return true to let the other side know we're done
15 | if(FrameIndex == 8)
16 | return true;
17 |
18 | AnimateLoop(gameTime, 60);
19 |
20 | return false;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Sprites/Player.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Graphics;
3 |
4 | namespace AlienAttackUniversal.Sprites
5 | {
6 | public class Player : Sprite
7 | {
8 | public Player()
9 | {
10 | //
11 | // TODO: Load the player sprite
12 | //
13 | }
14 |
15 | public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
16 | {
17 | //
18 | // TODO: Draw the sprite to the screen using the provided spriteBatch
19 | //
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Sprites/PlayerShot.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class PlayerShot : Sprite
6 | {
7 | public PlayerShot()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\pshot\\pshot_{0}", 3);
10 | Velocity = new Vector2(0, -300 / 1000.0f);
11 | }
12 |
13 | public override void Update(GameTime gameTime)
14 | {
15 | base.Update(gameTime);
16 | AnimateReverse(gameTime, 100);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/Sprites/Sprite.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Content;
3 | using Microsoft.Xna.Framework.Graphics;
4 |
5 | namespace AlienAttackUniversal.Sprites
6 | {
7 | public class Sprite
8 | {
9 | // all textures in animation set
10 | protected Texture2D[] Frames { get; set; }
11 |
12 | // current frame to draw
13 | protected int FrameIndex { get; set; }
14 |
15 | // total number of frames
16 | protected int FrameCount { get; set; }
17 |
18 | // size of sprite
19 | public Vector2 Size { get { return new Vector2(Width, Height); } }
20 | public int Width { get; set; }
21 | public int Height { get; set; }
22 |
23 | public Vector2 Position { get; set; }
24 | public Vector2 Velocity { get; set; }
25 | public float Rotation { get; set; }
26 | public Vector2 Scale { get; set; } = Vector2.One;
27 |
28 | // variable to track number of millieconds for animations
29 | private double _time;
30 |
31 | // bounding box of sprite...used for collisions
32 | private Rectangle _boundingBox;
33 | private int _animationDirection = 1;
34 |
35 | public Sprite()
36 | {
37 | Scale = Vector2.One;
38 | }
39 |
40 | public virtual void LoadContent(ContentManager contentManager, string name)
41 | {
42 | // load single frame
43 | Frames = new Texture2D[1];
44 | Frames[0] = contentManager.Load(name);
45 | Width = Frames[0].Width;
46 | Height = Frames[0].Height;
47 | }
48 |
49 | public virtual void LoadContent(ContentManager contentManager, string name, int count)
50 | {
51 | // load multiple frames
52 | Frames = new Texture2D[count];
53 | for(int i = 0; i < count; i++)
54 | Frames[i] = contentManager.Load(string.Format(name, i));
55 | FrameCount = count;
56 | Width = Frames[0].Width;
57 | Height = Frames[0].Height;
58 | }
59 |
60 | public virtual void AnimateLoop(GameTime gameTime, double frameTime)
61 | {
62 | // count number of milliseconds
63 | _time += gameTime.ElapsedGameTime.TotalMilliseconds;
64 |
65 | // if we're over the time for the next frame, move on
66 | if(_time > frameTime)
67 | {
68 | FrameIndex++;
69 | _time -= frameTime;
70 | }
71 |
72 | // if we're past the # of frames, start back at 0
73 | if(FrameIndex > FrameCount-1)
74 | FrameIndex = 0;
75 | }
76 |
77 | public virtual void AnimateReverse(GameTime gameTime, double frameTime)
78 | {
79 | // same as above, but reverse direction instead of starting back at 0
80 | _time += gameTime.ElapsedGameTime.TotalMilliseconds;
81 | if(_time > frameTime)
82 | {
83 | _time -= frameTime;
84 |
85 | if(FrameIndex == 0)
86 | _animationDirection = 1;
87 | else if(FrameIndex == FrameCount-1)
88 | _animationDirection = -1;
89 |
90 | FrameIndex += _animationDirection;
91 | }
92 | }
93 |
94 | public virtual void Update(GameTime gameTime)
95 | {
96 | // move the sprite 1 velocity unit
97 | Position += Velocity * gameTime.ElapsedGameTime.Milliseconds;
98 | }
99 |
100 | public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
101 | {
102 | if(Frames == null)
103 | return;
104 |
105 | spriteBatch.Draw(Frames[FrameIndex], position:Position, color:Color.White, scale:Scale);
106 | }
107 |
108 | public virtual Rectangle BoundingBox
109 | {
110 | get
111 | {
112 | // only need to assign this once
113 | if(_boundingBox == Rectangle.Empty)
114 | {
115 | _boundingBox.Width = Width;
116 | _boundingBox.Height = Height;
117 | }
118 | _boundingBox.X = (int)Position.X;
119 | _boundingBox.Y = (int)Position.Y;
120 |
121 | return _boundingBox;
122 | }
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/Source/Ex1/Begin/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
4 | },
5 | "frameworks": {
6 | "uap10.0": {}
7 | },
8 | "runtimes": {
9 | "win10-arm": {},
10 | "win10-arm-aot": {},
11 | "win10-x86": {},
12 | "win10-x86-aot": {},
13 | "win10-x64": {},
14 | "win10-x64-aot": {}
15 | }
16 | }
--------------------------------------------------------------------------------
/Source/Ex1/End/AlienAttackGame.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using AlienAttackUniversal.Sprites;
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Audio;
5 | using Microsoft.Xna.Framework.Graphics;
6 | using Microsoft.Xna.Framework.Input;
7 | using Microsoft.Xna.Framework.Input.Touch;
8 | using Microsoft.Xna.Framework.Media;
9 |
10 | namespace AlienAttackUniversal
11 | {
12 | ///
13 | /// This is the main type for your game
14 | ///
15 | public class AlienAttackGame : Game
16 | {
17 | public static int ScreenWidth = 1920;
18 | public static int ScreenHeight = 1080;
19 | private static int ShotTime = 500;
20 | private static readonly Vector2 PlayerVelocity = new Vector2(400 / 1000.0f, 0);
21 | private static readonly Vector2 ScorePosition = new Vector2(ScreenWidth / 2.0f, 30);
22 | private static Vector2 PlayerStartPosition;
23 |
24 | public static AlienAttackGame Instance;
25 | private readonly GraphicsDeviceManager _graphics;
26 | private SpriteBatch _spriteBatch;
27 | private RenderTargetScaler _scaler;
28 | private static KeyboardState _keyboardState, _lastKeyboard;
29 | private Texture2D _bgScreen;
30 | private Player _player;
31 | private List _playerShots;
32 | private double _lastShotTime;
33 | private Explosion _playerExplosion;
34 | private EnemyGroup _enemyGroup;
35 | private SpriteFont _font;
36 | private Song _theme;
37 | private SoundEffect _playerShot;
38 | private SoundEffect _explosion;
39 |
40 | private int _score;
41 |
42 | public AlienAttackGame()
43 | {
44 | Instance = this;
45 |
46 | _graphics = new GraphicsDeviceManager(this);
47 |
48 | // set our screen size based on the device
49 | _graphics.PreferredBackBufferWidth = ScreenWidth;
50 | _graphics.PreferredBackBufferHeight = ScreenHeight;
51 |
52 | Content.RootDirectory = "Content";
53 | }
54 |
55 | ///
56 | /// Allows the game to perform any initialization it needs to before starting to run.
57 | /// This is where it can query for any required services and load any non-graphic
58 | /// related content. Calling base.Initialize will enumerate through any components
59 | /// and initialize them as well.
60 | ///
61 | protected override void Initialize()
62 | {
63 | _scaler = new RenderTargetScaler(this, _graphics, ScreenWidth, ScreenHeight);
64 |
65 | _spriteBatch = new SpriteBatch(GraphicsDevice);
66 |
67 | _player = new Player();
68 | PlayerStartPosition = new Vector2(ScreenWidth / 2 - _player.Width / 2, ScreenHeight - 120);
69 | _player.Position = PlayerStartPosition;
70 |
71 | _enemyGroup = new EnemyGroup();
72 |
73 | _playerShots = new List();
74 |
75 | TouchPanel.EnabledGestures = GestureType.Tap | GestureType.HorizontalDrag;
76 |
77 | base.Initialize();
78 | }
79 |
80 | ///
81 | /// LoadContent will be called once per game and is the place to load
82 | /// all of your content.
83 | ///
84 | protected override void LoadContent()
85 | {
86 | _bgScreen = Content.Load("gfx\\bgScreen");
87 | _font = Content.Load("font");
88 | _explosion = Content.Load("sfx\\explosion");
89 | _playerShot = Content.Load("sfx\\playerShot");
90 | _theme = Content.Load("sfx\\theme");
91 | }
92 |
93 | ///
94 | /// UnloadContent will be called once per game and is the place to unload
95 | /// all content.
96 | ///
97 | protected override void UnloadContent()
98 | {
99 | }
100 |
101 | ///
102 | /// Allows the game to run logic such as updating the world,
103 | /// checking for collisions, gathering input, and playing audio.
104 | ///
105 | /// Provides a snapshot of timing values.
106 | protected override void Update(GameTime gameTime)
107 | {
108 | bool left = false, right = false, fire = false;
109 |
110 | if(MediaPlayer.State == MediaState.Stopped)
111 | {
112 | MediaPlayer.IsRepeating = true;
113 | MediaPlayer.Play(_theme);
114 | }
115 |
116 | _keyboardState = Keyboard.GetState();
117 |
118 | if (_keyboardState.IsKeyDown(Keys.Left) && _player.Position.X > 0)
119 | left = true;
120 | else if (_keyboardState.IsKeyDown(Keys.Right) && _player.Position.X + _player.Width < ScreenWidth)
121 | right = true;
122 |
123 | if((_keyboardState.IsKeyDown(Keys.Space) && !_lastKeyboard.IsKeyDown(Keys.Space)))
124 | fire = true;
125 |
126 | while(TouchPanel.IsGestureAvailable)
127 | {
128 | GestureSample gs = TouchPanel.ReadGesture();
129 | if(gs.GestureType == GestureType.HorizontalDrag)
130 | {
131 | if(gs.Delta.X < 0)
132 | left = true;
133 | else if(gs.Delta.X > 0)
134 | right = true;
135 | }
136 | if(gs.GestureType == GestureType.Tap)
137 | fire = true;
138 | }
139 |
140 | if (_player != null)
141 | {
142 | if (left && _player.Position.X > 0)
143 | _player.Velocity = -PlayerVelocity;
144 | else if (right && _player.Position.X + _player.Width < ScreenWidth)
145 | _player.Velocity = PlayerVelocity;
146 | else
147 | _player.Velocity = Vector2.Zero;
148 |
149 | if(fire && gameTime.TotalGameTime.TotalMilliseconds - _lastShotTime > ShotTime)
150 | {
151 | AddPlayerShot();
152 | _playerShot.Play();
153 | _lastShotTime = gameTime.TotalGameTime.TotalMilliseconds;
154 | }
155 |
156 | _player.Update(gameTime);
157 | }
158 |
159 | _enemyGroup.Update(gameTime);
160 | UpdatePlayerShots(gameTime);
161 | HandleCollisions(gameTime);
162 |
163 | _lastKeyboard = _keyboardState;
164 |
165 | base.Update(gameTime);
166 | }
167 |
168 | ///
169 | /// This is called when the game should draw itself.
170 | ///
171 | /// Provides a snapshot of timing values.
172 | protected override void Draw(GameTime gameTime)
173 | {
174 | _scaler.SetRenderTarget();
175 | _spriteBatch.Begin();
176 |
177 | _spriteBatch.Draw(_bgScreen, Vector2.Zero, Color.White);
178 |
179 | // draw the enemy board
180 | _enemyGroup.Draw(gameTime, _spriteBatch);
181 |
182 | // draw the player shots
183 | foreach(PlayerShot playerShot in _playerShots)
184 | playerShot.Draw(gameTime, _spriteBatch);
185 |
186 | // draw the player
187 | if (_player != null)
188 | _player.Draw(gameTime, _spriteBatch);
189 |
190 | // draw the player explosion
191 | if (_playerExplosion != null)
192 | _playerExplosion.Draw(gameTime, _spriteBatch);
193 |
194 | Vector2 scoreSize = _font.MeasureString("Score: " + _score);
195 | _spriteBatch.DrawString(_font, "Score: " + _score, ScorePosition - scoreSize/2.0f, Color.Aqua);
196 |
197 | _spriteBatch.End();
198 | _scaler.Draw();
199 | }
200 |
201 | #region Game Logic
202 | private void HandleCollisions(GameTime gameTime)
203 | {
204 | // see if a player shot hit an enemy
205 | for(int i = 0; i < _playerShots.Count; i++)
206 | {
207 | PlayerShot playerShot = _playerShots[i];
208 | // check the shot and see if it it collided with an enemy
209 | if(playerShot != null && _enemyGroup.HandlePlayerShotCollision(_playerShots[i]))
210 | {
211 | // remove the shot, add the score
212 | _playerShots.RemoveAt(i);
213 | _score += 100;
214 | _explosion.Play();
215 | }
216 | }
217 |
218 | // see if an enemy shot hit the player
219 | if(_player != null && _enemyGroup.HandleEnemyShotCollision(_player))
220 | {
221 | // blow up the player
222 | _playerExplosion = new Explosion();
223 | Vector2 center = _player.Position + (_player.Size/2.0f);
224 | _playerExplosion.Position = center - (_playerExplosion.Size/2.0f);
225 | _player = null;
226 | _explosion.Play();
227 | }
228 |
229 | // if the player explosion animation is running, update it
230 | if(_playerExplosion != null)
231 | {
232 | // if this is the last frame
233 | if(_playerExplosion.Update(gameTime))
234 | {
235 | // remove it
236 | _playerExplosion = null;
237 |
238 | // reset the board
239 | _enemyGroup.Reset();
240 | _playerShots.Clear();
241 |
242 | _player = new Player();
243 | _player.Position = PlayerStartPosition;
244 | }
245 | }
246 | }
247 |
248 | private void AddPlayerShot()
249 | {
250 | // create a new shot over the ship
251 | PlayerShot ps = new PlayerShot();
252 | ps.Position = _player.Position + (_player.Size/2) - (ps.Size/2) - new Vector2(0, ps.Height);
253 | _playerShots.Add(ps);
254 | }
255 |
256 | private void UpdatePlayerShots(GameTime gameTime)
257 | {
258 | // enumerate the player shots on the screen
259 | for(int i = 0; i < _playerShots.Count; i++)
260 | {
261 | PlayerShot playerShot = _playerShots[i];
262 |
263 | playerShot.Update(gameTime);
264 |
265 | // if it's off the top of the screen, remove it from the list
266 | if(playerShot.Position.Y + playerShot.Height < 0)
267 | _playerShots.RemoveAt(i);
268 | }
269 | }
270 | #endregion
271 | }
272 | }
273 |
--------------------------------------------------------------------------------
/Source/Ex1/End/AlienAttackUniversal.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Debug
7 | x86
8 | {5EF2882F-8277-4262-A697-F96590277E1B}
9 | AppContainerExe
10 | Properties
11 | AlienAttackUniversal
12 | AlienAttackUniversal
13 | en-US
14 | UAP
15 | 10.0.10586.0
16 | 10.0.10240.0
17 | 14
18 | true
19 | 512
20 | {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
21 | AlienAttackUniversal_TemporaryKey.pfx
22 | WindowsStoreApp
23 |
24 |
25 | 1B746EAE1B884C3984963143A1445D8BA3095A62
26 | False
27 | False
28 | Always
29 | x86
30 |
31 |
32 | true
33 | bin\WindowsUniversal\ARM\Debug\
34 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UAP
35 | ;2008
36 | full
37 | ARM
38 | false
39 | prompt
40 | true
41 |
42 |
43 | bin\WindowsUniversal\ARM\Release\
44 | TRACE;NETFX_CORE;WINDOWS_UAP
45 | true
46 | ;2008
47 | pdbonly
48 | ARM
49 | false
50 | prompt
51 | true
52 | true
53 |
54 |
55 | true
56 | bin\WindowsUniversal\x64\Debug\
57 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UAP
58 | ;2008
59 | full
60 | x64
61 | false
62 | prompt
63 | true
64 |
65 |
66 | bin\WindowsUniversal\x64\Release\
67 | TRACE;NETFX_CORE;WINDOWS_UAP
68 | true
69 | ;2008
70 | pdbonly
71 | x64
72 | false
73 | prompt
74 | true
75 | true
76 |
77 |
78 | true
79 | bin\WindowsUniversal\x86\Debug\
80 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UAP
81 | ;2008
82 | full
83 | x86
84 | false
85 | prompt
86 | true
87 |
88 |
89 | bin\WindowsUniversal\x86\Release\
90 | TRACE;NETFX_CORE;WINDOWS_UAP
91 | true
92 | ;2008
93 | pdbonly
94 | x86
95 | false
96 | prompt
97 | true
98 | true
99 |
100 |
101 |
102 |
103 | $(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\WindowsUniversal\MonoGame.Framework.dll
104 |
105 |
106 |
107 |
108 |
109 | App.xaml
110 |
111 |
112 | GamePage.xaml
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 | Designer
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 | MSBuild:Compile
152 | Designer
153 |
154 |
155 | MSBuild:Compile
156 | Designer
157 |
158 |
159 |
160 |
161 | 14.0
162 |
163 |
164 |
165 |
172 |
--------------------------------------------------------------------------------
/Source/Ex1/End/AlienAttackUniversal.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.24720.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlienAttackUniversal", "AlienAttackUniversal.csproj", "{5EF2882F-8277-4262-A697-F96590277E1B}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|ARM = Debug|ARM
11 | Debug|x64 = Debug|x64
12 | Debug|x86 = Debug|x86
13 | Release|ARM = Release|ARM
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|ARM.ActiveCfg = Debug|ARM
19 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|ARM.Build.0 = Debug|ARM
20 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|ARM.Deploy.0 = Debug|ARM
21 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x64.ActiveCfg = Debug|x64
22 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x64.Build.0 = Debug|x64
23 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x64.Deploy.0 = Debug|x64
24 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x86.ActiveCfg = Debug|x86
25 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x86.Build.0 = Debug|x86
26 | {5EF2882F-8277-4262-A697-F96590277E1B}.Debug|x86.Deploy.0 = Debug|x86
27 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|ARM.ActiveCfg = Release|ARM
28 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|ARM.Build.0 = Release|ARM
29 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|ARM.Deploy.0 = Release|ARM
30 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x64.ActiveCfg = Release|x64
31 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x64.Build.0 = Release|x64
32 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x64.Deploy.0 = Release|x64
33 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x86.ActiveCfg = Release|x86
34 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x86.Build.0 = Release|x86
35 | {5EF2882F-8277-4262-A697-F96590277E1B}.Release|x86.Deploy.0 = Release|x86
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/Source/Ex1/End/AlienAttackUniversal_TemporaryKey.pfx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/AlienAttackUniversal_TemporaryKey.pfx
--------------------------------------------------------------------------------
/Source/Ex1/End/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Source/Ex1/End/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Runtime.InteropServices.WindowsRuntime;
6 | using Windows.ApplicationModel;
7 | using Windows.ApplicationModel.Activation;
8 | using Windows.Foundation;
9 | using Windows.Foundation.Collections;
10 | using Windows.UI.Xaml;
11 | using Windows.UI.Xaml.Controls;
12 | using Windows.UI.Xaml.Controls.Primitives;
13 | using Windows.UI.Xaml.Data;
14 | using Windows.UI.Xaml.Input;
15 | using Windows.UI.Xaml.Media;
16 | using Windows.UI.Xaml.Navigation;
17 |
18 | // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=402347&clcid=0x409
19 |
20 | namespace AlienAttackUniversal
21 | {
22 | ///
23 | /// Provides application-specific behavior to supplement the default Application class.
24 | ///
25 | sealed partial class App : Application
26 | {
27 | ///
28 | /// Initializes the singleton application object. This is the first line of authored code
29 | /// executed, and as such is the logical equivalent of main() or WinMain().
30 | ///
31 | public App()
32 | {
33 | this.InitializeComponent();
34 | this.Suspending += OnSuspending;
35 | }
36 |
37 | ///
38 | /// Invoked when the application is launched normally by the end user. Other entry points
39 | /// will be used such as when the application is launched to open a specific file.
40 | ///
41 | /// Details about the launch request and process.
42 | protected override void OnLaunched(LaunchActivatedEventArgs e)
43 | {
44 |
45 | #if DEBUG
46 | if (System.Diagnostics.Debugger.IsAttached)
47 | {
48 | this.DebugSettings.EnableFrameRateCounter = true;
49 | }
50 | #endif
51 |
52 | Frame rootFrame = Window.Current.Content as Frame;
53 |
54 | // Do not repeat app initialization when the Window already has content,
55 | // just ensure that the window is active
56 | if (rootFrame == null)
57 | {
58 | // Create a Frame to act as the navigation context and navigate to the first page
59 | rootFrame = new Frame();
60 |
61 | rootFrame.NavigationFailed += OnNavigationFailed;
62 |
63 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
64 | {
65 | //TODO: Load state from previously suspended application
66 | }
67 |
68 | // Place the frame in the current Window
69 | Window.Current.Content = rootFrame;
70 | }
71 |
72 | if (rootFrame.Content == null)
73 | {
74 | // When the navigation stack isn't restored navigate to the first page,
75 | // configuring the new page by passing required information as a navigation
76 | // parameter
77 | rootFrame.Navigate(typeof(GamePage), e.Arguments);
78 | }
79 | // Ensure the current window is active
80 | Window.Current.Activate();
81 | }
82 |
83 | ///
84 | /// Invoked when Navigation to a certain page fails
85 | ///
86 | /// The Frame which failed navigation
87 | /// Details about the navigation failure
88 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
89 | {
90 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
91 | }
92 |
93 | ///
94 | /// Invoked when application execution is being suspended. Application state is saved
95 | /// without knowing whether the application will be terminated or resumed with the contents
96 | /// of memory still intact.
97 | ///
98 | /// The source of the suspend request.
99 | /// Details about the suspend request.
100 | private void OnSuspending(object sender, SuspendingEventArgs e)
101 | {
102 | var deferral = e.SuspendingOperation.GetDeferral();
103 | //TODO: Save application state and stop any background activity
104 | deferral.Complete();
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/SmallLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/SmallLogo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/Square310x310Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/Square310x310Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/Square71x71Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/Square71x71Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/StoreLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/StoreLogo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/uwp_100x100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/uwp_100x100.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/uwp_142x142.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/uwp_142x142.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Assets/uwp_620x620.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Assets/uwp_620x620.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/Audiowide-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/Audiowide-Regular.ttf
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/Font.spritefont:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
15 | Audiowide-Regular
16 |
17 |
21 | 36
22 |
23 |
27 | 0
28 |
29 |
33 | true
34 |
35 |
39 |
40 |
41 |
48 |
49 |
50 |
51 | ~
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/bgScreen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/bgScreen.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/enemy1/enemy1_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/enemy1/enemy1_0.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/enemy1/enemy1_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/enemy1/enemy1_1.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/enemy1/enemy1_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/enemy1/enemy1_2.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/enemy1/enemy1_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/enemy1/enemy1_3.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/enemy1/enemy1_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/enemy1/enemy1_4.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/enemy1/enemy1_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/enemy1/enemy1_5.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/enemy1/enemy1_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/enemy1/enemy1_6.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/enemy1/enemy1_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/enemy1/enemy1_7.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/enemy1/enemy1_8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/enemy1/enemy1_8.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/enemy1/enemy1_9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/enemy1/enemy1_9.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/eshot/eshot_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/eshot/eshot_0.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/eshot/eshot_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/eshot/eshot_1.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/eshot/eshot_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/eshot/eshot_2.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/explosion/explosion_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/explosion/explosion_0.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/explosion/explosion_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/explosion/explosion_1.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/explosion/explosion_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/explosion/explosion_2.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/explosion/explosion_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/explosion/explosion_3.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/explosion/explosion_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/explosion/explosion_4.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/explosion/explosion_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/explosion/explosion_5.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/explosion/explosion_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/explosion/explosion_6.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/explosion/explosion_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/explosion/explosion_7.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/explosion/explosion_8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/explosion/explosion_8.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/player.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/player.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/pshot/pshot_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/pshot/pshot_0.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/pshot/pshot_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/pshot/pshot_1.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/pshot/pshot_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/pshot/pshot_2.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/gfx/titleScreen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/gfx/titleScreen.png
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/sfx/enemyShot.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/sfx/enemyShot.wav
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/sfx/explosion.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/sfx/explosion.wav
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/sfx/playerShot.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/sfx/playerShot.wav
--------------------------------------------------------------------------------
/Source/Ex1/End/Content/sfx/theme.wma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Ex1/End/Content/sfx/theme.wma
--------------------------------------------------------------------------------
/Source/Ex1/End/GamePage.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Source/Ex1/End/GamePage.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Runtime.InteropServices.WindowsRuntime;
6 | using Windows.Foundation;
7 | using Windows.Foundation.Collections;
8 | using Windows.UI.Xaml;
9 | using Windows.UI.Xaml.Controls;
10 | using Windows.UI.Xaml.Controls.Primitives;
11 | using Windows.UI.Xaml.Data;
12 | using Windows.UI.Xaml.Input;
13 | using Windows.UI.Xaml.Media;
14 | using Windows.UI.Xaml.Navigation;
15 |
16 | // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
17 |
18 | namespace AlienAttackUniversal
19 | {
20 | ///
21 | /// An empty page that can be used on its own or navigated to within a Frame.
22 | ///
23 | public sealed partial class GamePage : Page
24 | {
25 | readonly AlienAttackGame _game;
26 |
27 | public GamePage()
28 | {
29 | this.InitializeComponent();
30 |
31 | // Create the game.
32 | var launchArguments = string.Empty;
33 | _game = MonoGame.Framework.XamlGame.Create(launchArguments, Window.Current.CoreWindow, swapChainPanel);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Source/Ex1/End/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Alien Attack
7 | TED Games Squad
8 | Assets\StoreLogo.png
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Source/Ex1/End/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("AlienAttackUniversal")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("AlienAttackUniversal")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Version information for an assembly consists of the following four values:
18 | //
19 | // Major Version
20 | // Minor Version
21 | // Build Number
22 | // Revision
23 | //
24 | // You can specify all the values or you can default the Build and Revision Numbers
25 | // by using the '*' as shown below:
26 | // [assembly: AssemblyVersion("1.0.*")]
27 | [assembly: AssemblyVersion("1.0.0.0")]
28 | [assembly: AssemblyFileVersion("1.0.0.0")]
29 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/Source/Ex1/End/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Source/Ex1/End/RenderTargetScaler.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Graphics;
3 |
4 | namespace AlienAttackUniversal
5 | {
6 | class RenderTargetScaler
7 | {
8 | private readonly RenderTarget2D _drawBuffer;
9 | private readonly GraphicsDeviceManager _graphicsDeviceManager;
10 | private readonly int _screenWidth;
11 | private readonly int _screenHeight;
12 | private readonly Game _game;
13 | private readonly SpriteBatch _spriteBatch;
14 |
15 | public RenderTargetScaler(Game game, GraphicsDeviceManager graphicsDeviceManager, int width, int height)
16 | {
17 | _game = game;
18 | _graphicsDeviceManager = graphicsDeviceManager;
19 | _screenWidth = width;
20 | _screenHeight = height;
21 |
22 | _spriteBatch = new SpriteBatch(graphicsDeviceManager.GraphicsDevice);
23 |
24 | // create a surface to draw on which is then scaled to the screen size on the PC
25 | _drawBuffer = new RenderTarget2D(graphicsDeviceManager.GraphicsDevice,
26 | width, height);
27 |
28 | }
29 |
30 | public void SetRenderTarget()
31 | {
32 | _graphicsDeviceManager.GraphicsDevice.SetRenderTarget(_drawBuffer);
33 | }
34 |
35 | public void Draw()
36 | {
37 | float outputAspect = _game.Window.ClientBounds.Width / (float)_game.Window.ClientBounds.Height;
38 | float preferredAspect = _screenWidth / (float)_screenHeight;
39 |
40 | Rectangle dst;
41 |
42 | if (outputAspect <= preferredAspect)
43 | {
44 | // output is taller than it is wider, bars on top/bottom
45 | int presentHeight = (int)((_game.Window.ClientBounds.Width / preferredAspect) + 0.5f);
46 | int barHeight = (_game.Window.ClientBounds.Height - presentHeight) / 2;
47 |
48 | dst = new Rectangle(0, barHeight, _game.Window.ClientBounds.Width, presentHeight);
49 | }
50 | else
51 | {
52 | // output is wider than it is tall, bars left/right
53 | int presentWidth = (int)((_game.Window.ClientBounds.Height * preferredAspect) + 0.5f);
54 | int barWidth = (_game.Window.ClientBounds.Width - presentWidth) / 2;
55 |
56 | dst = new Rectangle(barWidth, 0, presentWidth, _game.Window.ClientBounds.Height);
57 | }
58 |
59 | _graphicsDeviceManager.GraphicsDevice.SetRenderTarget(null);
60 |
61 | // clear to get black bars
62 | _graphicsDeviceManager.GraphicsDevice.Clear(Color.Black);
63 |
64 | // draw a quad to get the draw buffer to the back buffer
65 | _spriteBatch.Begin();
66 | _spriteBatch.Draw(_drawBuffer, dst, Color.White);
67 | _spriteBatch.End();
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Source/Ex1/End/Sprites/Enemy.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class Enemy : Sprite
6 | {
7 | public Enemy()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\enemy1\\enemy1_{0}", 10);
10 | }
11 |
12 | public override void Update(GameTime gameTime)
13 | {
14 | AnimateReverse(gameTime, 60);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Source/Ex1/End/Sprites/EnemyGroup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Audio;
5 | using Microsoft.Xna.Framework.Graphics;
6 |
7 | namespace AlienAttackUniversal.Sprites
8 | {
9 | public class EnemyGroup : Sprite
10 | {
11 | // grid of enemies
12 | private readonly Enemy[,] _enemies;
13 |
14 | // all enemy shots
15 | private readonly List _enemyShots;
16 |
17 | // all enemy explosions
18 | private readonly List _explosions;
19 | private readonly Random _random;
20 |
21 | // width of single enemy
22 | private readonly int _enemyWidth;
23 |
24 | private const int EnemyRows = 4; // number of rows in grid
25 | private const int EnemyCols = 8; // number of cols in grid
26 | private readonly Vector2 EnemyVerticalJump = new Vector2(0, 10); // number of pixels to jump vertically after hitting edge
27 | private const int EnemyStartPosition = 10; // vertical position of grid
28 | private const int ScreenEdge = 20; // virtual edge of screen to change direction
29 | private Vector2 EnemySpacing = new Vector2(16, 32); // space between sprites
30 | private readonly Vector2 EnemyVelocity = new Vector2(100 / 1000.0f, 0); // speed at which grid moves per frame
31 | private readonly SoundEffect _enemyShot;
32 |
33 | public EnemyGroup()
34 | {
35 | _random = new Random();
36 |
37 | _enemyShots = new List();
38 | _explosions = new List();
39 |
40 | _enemies = new Enemy[EnemyRows,EnemyCols];
41 |
42 | _enemyShot = AlienAttackGame.Instance.Content.Load("sfx\\enemyShot");
43 |
44 | // create a grid of enemies
45 | for(int y = 0; y < EnemyRows; y++)
46 | {
47 | for(int x = 0; x < EnemyCols; x++)
48 | {
49 | Enemy enemy = new Enemy();
50 | enemy.Position = new Vector2(x * enemy.Width + EnemySpacing.X, y * enemy.Height + EnemySpacing.Y);
51 | _enemies[y,x] = enemy;
52 | }
53 | }
54 |
55 | _enemyWidth = _enemies[0,0].Width;
56 |
57 | // position the grid centered at the vertical position specified above
58 | Position = new Vector2(AlienAttackGame.ScreenWidth/2.0f - ((EnemyCols * (_enemyWidth + EnemySpacing.X)) / 2), EnemyStartPosition);
59 | Velocity = EnemyVelocity;
60 | }
61 |
62 | public override void Update(GameTime gameTime)
63 | {
64 | base.Update(gameTime);
65 |
66 | MoveEnemies(gameTime);
67 | EnemyFire(gameTime);
68 |
69 | for(int i = 0; i < _explosions.Count; i++)
70 | {
71 | // update all explosions, remove those whose animations are over
72 | if(_explosions[i].Update(gameTime))
73 | _explosions.RemoveAt(i);
74 | }
75 | }
76 |
77 | public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
78 | {
79 | // draw all active enemies
80 | foreach(Enemy enemy in _enemies)
81 | {
82 | if(enemy != null)
83 | enemy.Draw(gameTime, spriteBatch);
84 | }
85 |
86 | // draw all enemy shots
87 | foreach(EnemyShot enemyShot in _enemyShots)
88 | enemyShot.Draw(gameTime, spriteBatch);
89 |
90 | // draw all explosions
91 | foreach(Explosion explosion in _explosions)
92 | explosion.Draw(gameTime, spriteBatch);
93 | }
94 |
95 | public void Reset()
96 | {
97 | _enemyShots.Clear();
98 | }
99 |
100 | private Enemy FindRightMostEnemy()
101 | {
102 | // find the enemy in the right-most position in the grid
103 | for(int x = EnemyCols-1; x > -1; x--)
104 | {
105 | for(int y = 0; y < EnemyRows; y++)
106 | {
107 | if(_enemies[y,x] != null)
108 | return _enemies[y,x];
109 | }
110 | }
111 | return null;
112 | }
113 |
114 | private Enemy FindLeftMostEnemy()
115 | {
116 | // find the enemy in the left-most position in the grid
117 | for(int x = 0; x < EnemyCols; x++)
118 | {
119 | for(int y = 0; y < EnemyRows; y++)
120 | {
121 | if(_enemies[y,x] != null)
122 | return _enemies[y,x];
123 | }
124 | }
125 | return null;
126 | }
127 |
128 | public bool AllDestroyed()
129 | {
130 | // we won if we can't find any enemies at all
131 | return (FindLeftMostEnemy() == null);
132 | }
133 |
134 | private void MoveEnemies(GameTime gameTime)
135 | {
136 | Enemy enemy = FindRightMostEnemy();
137 |
138 | // if the right-most enemy hit the screen edge, change directions
139 | if(enemy != null)
140 | {
141 | if(enemy.Position.X + enemy.Width > AlienAttackGame.ScreenWidth - ScreenEdge)
142 | {
143 | Position += EnemyVerticalJump;
144 | Velocity = -EnemyVelocity;
145 | }
146 | }
147 |
148 | enemy = FindLeftMostEnemy();
149 |
150 | // if the left-most enemy hit the screen edge, change direction
151 | if(enemy != null)
152 | {
153 | if(enemy.Position.X < ScreenEdge)
154 | {
155 | Position += EnemyVerticalJump;
156 | Velocity = EnemyVelocity;
157 | }
158 | }
159 |
160 | // update the positions of all enemies
161 | for(int y = 0; y < EnemyRows; y++)
162 | {
163 | for(int x = 0; x < EnemyCols; x++)
164 | {
165 | if(_enemies[y,x] != null)
166 | {
167 | // X = position of the whole grid + (X grid position * width of enemy) + padding
168 | // Y = position of the whole grid + (Y grid position * width of enemy) + padding
169 | _enemies[y,x].Position =
170 | new Vector2((Position.X + (x * (_enemyWidth + EnemySpacing.X))),
171 | (Position.Y + (y * (_enemyWidth + EnemySpacing.Y))));
172 | _enemies[y,x].Update(gameTime);
173 | }
174 | }
175 | }
176 | }
177 |
178 | private void EnemyFire(GameTime gameTime)
179 | {
180 | if (AllDestroyed())
181 | return;
182 |
183 | // at random times, drop an enemy shot
184 | if (_random.NextDouble() > 0.99f)
185 | {
186 | int x, y;
187 |
188 | // find an enemy that hasn't been destroyed
189 | do
190 | {
191 | x = (int)(_random.NextDouble() * EnemyCols);
192 | y = (int)(_random.NextDouble() * EnemyRows);
193 | }
194 | while (_enemies[y, x] == null);
195 |
196 | // create a shot for that enemy and add it to the list
197 | EnemyShot enemyShot = new EnemyShot();
198 | enemyShot.Position = _enemies[y, x].Position;
199 | enemyShot.Position += new Vector2(0, _enemies[y, x].Height);
200 | _enemyShots.Add(enemyShot);
201 |
202 | _enemyShot.Play();
203 | }
204 |
205 | for (int i = 0; i < _enemyShots.Count; i++)
206 | {
207 | // update all shots
208 | _enemyShots[i].Update(gameTime);
209 |
210 | // remove those that are off the screen
211 | if (_enemyShots[i].Position.Y > AlienAttackGame.ScreenHeight)
212 | _enemyShots.RemoveAt(i);
213 | }
214 | }
215 |
216 | public bool CheckCollision(Sprite s1, Sprite s2)
217 | {
218 | // simple bounding box collision detection
219 | return s1.BoundingBox.Intersects(s2.BoundingBox);
220 | }
221 |
222 | public bool HandlePlayerShotCollision(PlayerShot playerShot)
223 | {
224 | for(int y = 0; y < EnemyRows; y++)
225 | {
226 | for(int x = 0; x < EnemyCols; x++)
227 | {
228 | // if a player shot hit an enemy, destroy the enemy
229 | if(_enemies[y,x] != null && CheckCollision(playerShot, _enemies[y,x]))
230 | {
231 | Explosion explosion = new Explosion();
232 | Vector2 center = _enemies[y,x].Position + (_enemies[y,x].Size/2.0f);
233 | explosion.Position = center - (explosion.Size/2.0f);
234 | _explosions.Add(explosion);
235 | _enemies[y,x] = null;
236 | return true;
237 | }
238 | }
239 | }
240 | return false;
241 | }
242 |
243 | public bool HandleEnemyShotCollision(Player player)
244 | {
245 | for(int i = 0; i < _enemyShots.Count; i++)
246 | {
247 | // if an enemy shot hit the player, destroy the player
248 | if(CheckCollision(_enemyShots[i], player))
249 | {
250 | _enemyShots.RemoveAt(i);
251 | return true;
252 | }
253 | }
254 | return false;
255 | }
256 |
257 | public bool HandleEnemyPlayerCollision(Player player)
258 | {
259 | for(int y = 0; y < EnemyRows; y++)
260 | {
261 | for(int x = 0; x < EnemyCols; x++)
262 | {
263 | // if an enemy hit the player, destroy the enemy
264 | if(_enemies[y,x] != null && CheckCollision(_enemies[y,x], player))
265 | {
266 | Explosion explosion = new Explosion();
267 | Vector2 center = _enemies[y,x].Position + (_enemies[y,x].Size/2.0f);
268 | explosion.Position = center - (explosion.Size/2.0f);
269 | _explosions.Add(explosion);
270 | _enemies[y,x] = null;
271 | return true;
272 | }
273 | }
274 | }
275 | return false;
276 | }
277 | }
278 | }
279 |
--------------------------------------------------------------------------------
/Source/Ex1/End/Sprites/EnemyShot.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class EnemyShot : Sprite
6 | {
7 | public EnemyShot()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\eshot\\eshot_{0}", 3);
10 | Velocity = new Vector2(0, 350 / 1000.0f);
11 | }
12 |
13 | public override void Update(GameTime gameTime)
14 | {
15 | base.Update(gameTime);
16 | AnimateReverse(gameTime, 60);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/Ex1/End/Sprites/Explosion.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class Explosion : Sprite
6 | {
7 | public Explosion()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\explosion\\explosion_{0}", 9);
10 | }
11 |
12 | public new bool Update(GameTime gameTime)
13 | {
14 | // if it's the final frame, return true to let the other side know we're done
15 | if(FrameIndex == 8)
16 | return true;
17 |
18 | AnimateLoop(gameTime, 60);
19 |
20 | return false;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Source/Ex1/End/Sprites/Player.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Graphics;
3 |
4 | namespace AlienAttackUniversal.Sprites
5 | {
6 | public class Player : Sprite
7 | {
8 | public Player()
9 | {
10 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\player");
11 | }
12 |
13 | public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
14 | {
15 | spriteBatch.Draw(Frames[0], Position);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Source/Ex1/End/Sprites/PlayerShot.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace AlienAttackUniversal.Sprites
4 | {
5 | public class PlayerShot : Sprite
6 | {
7 | public PlayerShot()
8 | {
9 | LoadContent(AlienAttackGame.Instance.Content, "gfx\\pshot\\pshot_{0}", 3);
10 | Velocity = new Vector2(0, -300 / 1000.0f);
11 | }
12 |
13 | public override void Update(GameTime gameTime)
14 | {
15 | base.Update(gameTime);
16 | AnimateReverse(gameTime, 100);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/Ex1/End/Sprites/Sprite.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Content;
3 | using Microsoft.Xna.Framework.Graphics;
4 |
5 | namespace AlienAttackUniversal.Sprites
6 | {
7 | public class Sprite
8 | {
9 | // all textures in animation set
10 | protected Texture2D[] Frames { get; set; }
11 |
12 | // current frame to draw
13 | protected int FrameIndex { get; set; }
14 |
15 | // total number of frames
16 | protected int FrameCount { get; set; }
17 |
18 | // size of sprite
19 | public Vector2 Size { get { return new Vector2(Width, Height); } }
20 | public int Width { get; set; }
21 | public int Height { get; set; }
22 |
23 | public Vector2 Position { get; set; }
24 | public Vector2 Velocity { get; set; }
25 | public float Rotation { get; set; }
26 | public Vector2 Scale { get; set; } = Vector2.One;
27 |
28 | // variable to track number of millieconds for animations
29 | private double _time;
30 |
31 | // bounding box of sprite...used for collisions
32 | private Rectangle _boundingBox;
33 | private int _animationDirection = 1;
34 |
35 | public Sprite()
36 | {
37 | Scale = Vector2.One;
38 | }
39 |
40 | public virtual void LoadContent(ContentManager contentManager, string name)
41 | {
42 | // load single frame
43 | Frames = new Texture2D[1];
44 | Frames[0] = contentManager.Load(name);
45 | Width = Frames[0].Width;
46 | Height = Frames[0].Height;
47 | }
48 |
49 | public virtual void LoadContent(ContentManager contentManager, string name, int count)
50 | {
51 | // load multiple frames
52 | Frames = new Texture2D[count];
53 | for(int i = 0; i < count; i++)
54 | Frames[i] = contentManager.Load(string.Format(name, i));
55 | FrameCount = count;
56 | Width = Frames[0].Width;
57 | Height = Frames[0].Height;
58 | }
59 |
60 | public virtual void AnimateLoop(GameTime gameTime, double frameTime)
61 | {
62 | // count number of milliseconds
63 | _time += gameTime.ElapsedGameTime.TotalMilliseconds;
64 |
65 | // if we're over the time for the next frame, move on
66 | if(_time > frameTime)
67 | {
68 | FrameIndex++;
69 | _time -= frameTime;
70 | }
71 |
72 | // if we're past the # of frames, start back at 0
73 | if(FrameIndex > FrameCount-1)
74 | FrameIndex = 0;
75 | }
76 |
77 | public virtual void AnimateReverse(GameTime gameTime, double frameTime)
78 | {
79 | // same as above, but reverse direction instead of starting back at 0
80 | _time += gameTime.ElapsedGameTime.TotalMilliseconds;
81 | if(_time > frameTime)
82 | {
83 | _time -= frameTime;
84 |
85 | if(FrameIndex == 0)
86 | _animationDirection = 1;
87 | else if(FrameIndex == FrameCount-1)
88 | _animationDirection = -1;
89 |
90 | FrameIndex += _animationDirection;
91 | }
92 | }
93 |
94 | public virtual void Update(GameTime gameTime)
95 | {
96 | // move the sprite 1 velocity unit
97 | Position += Velocity * gameTime.ElapsedGameTime.Milliseconds;
98 | }
99 |
100 | public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
101 | {
102 | if(Frames == null)
103 | return;
104 |
105 | spriteBatch.Draw(Frames[FrameIndex], position:Position, color:Color.White, scale:Scale);
106 | }
107 |
108 | public virtual Rectangle BoundingBox
109 | {
110 | get
111 | {
112 | // only need to assign this once
113 | if(_boundingBox == Rectangle.Empty)
114 | {
115 | _boundingBox.Width = Width;
116 | _boundingBox.Height = Height;
117 | }
118 | _boundingBox.X = (int)Position.X;
119 | _boundingBox.Y = (int)Position.Y;
120 |
121 | return _boundingBox;
122 | }
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/Source/Ex1/End/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
4 | },
5 | "frameworks": {
6 | "uap10.0": {}
7 | },
8 | "runtimes": {
9 | "win10-arm": {},
10 | "win10-arm-aot": {},
11 | "win10-x86": {},
12 | "win10-x86-aot": {},
13 | "win10-x64": {},
14 | "win10-x64-aot": {}
15 | }
16 | }
--------------------------------------------------------------------------------
/Source/Setup.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | setlocal
3 | CD /d "%~dp0"
4 |
5 | ::Test If script has Admin Priviledges/is elevated
6 | REG QUERY "HKU\S-1-5-19"
7 | IF %ERRORLEVEL% NEQ 0 (
8 | ECHO Please run this script as an administrator
9 | pause
10 | EXIT /B 1
11 | )
12 | cls
13 | echo Setup Options
14 | echo =============
15 | echo.
16 | echo 1. Execute setup scripts.
17 | echo WARNING: The setup could fail and the Module might not work properly if you don't have all the prerequisites installed.
18 | echo.
19 | echo 2. Exit.
20 | echo.
21 | choice /c:12 /M "Choose an option: "
22 | if errorlevel 2 goto exit
23 | if errorlevel 1 goto execsetup
24 |
25 |
26 | :execsetup
27 | REM Here executes the Setup.cmd only.
28 | echo Executing setup scripts.
29 | call .\Setup\Setup.cmd
30 | goto exit
31 |
32 | :pause
33 | pause
34 |
35 | :exit
36 |
37 |
38 |
--------------------------------------------------------------------------------
/Source/Setup/Cleanup.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | echo.
3 | echo ======================================================
4 | echo Uninstall Visual Studio Code Snippets for the module
5 | echo ======================================================
6 | echo.
7 |
8 | for /f "tokens=2,*" %%a in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Personal" 2^>NUL ^| findstr Personal') do set MyDocuments=%%b
9 |
10 | DEL "%MyDocuments%\Visual Studio 2015\Code Snippets\Visual C#\My Code Snippets\IntroMonoGame*.snippet" 2>NUL
11 |
12 | echo Module Code Snippets have been removed!
13 | PAUSE
--------------------------------------------------------------------------------
/Source/Setup/Setup.cmd:
--------------------------------------------------------------------------------
1 | @ECHO off
2 | %~d0
3 |
4 | CD "%~dp0"
5 | ECHO Install Visual Studio 2015 Code Snippets for the module:
6 | ECHO -------------------------------------------------------------------------------
7 | CALL .\Scripts\InstallCodeSnippets.cmd
8 | ECHO Done!
9 | ECHO.
10 | ECHO *******************************************************************************
11 | ECHO.
12 |
13 | @PAUSE
14 |
--------------------------------------------------------------------------------
/Source/Setup/scripts/InstallCodeSnippets.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | %~d0
3 | cd "%~dp0"
4 |
5 | echo.
6 | echo ==================================================
7 | echo Install Visual Studio Code Snippets for the module
8 | echo ==================================================
9 | echo.
10 |
11 | IF EXIST %WINDIR%\SysWow64 (
12 | set powerShellDir=%WINDIR%\SysWow64\windowspowershell\v1.0
13 | ) ELSE (
14 | set powerShellDir=%WINDIR%\system32\windowspowershell\v1.0
15 | )
16 |
17 | call %powerShellDir%\powershell.exe -Command Set-ExecutionPolicy unrestricted
18 |
19 | call %powerShellDir%\powershell.exe -Command "&'.\installCodeSnippets.ps1' '%~dp0snippets\IntroMonoGame.vsi'"
20 |
21 | call %powerShellDir%\powershell.exe -Command "&'.\installCodeSnippets.ps1' '%~dp0snippets\IntroMonoGameShort.vsi'"
22 |
23 |
--------------------------------------------------------------------------------
/Source/Setup/scripts/installCodeSnippets.ps1:
--------------------------------------------------------------------------------
1 | ########################
2 | # Zip Helper Functions #
3 | ########################
4 |
5 | # Extract the files form the zip
6 | # Usage: extract-zip c:\myzip.zip c:\destination
7 | function Extract-Zip
8 | {
9 | param([string]$zipfilename, [string] $destination)
10 |
11 | if(test-path($zipfilename))
12 | {
13 | $shellApplication = new-object -com shell.application
14 | $zipPackage = $shellApplication.NameSpace($zipfilename)
15 | $destinationFolder = $shellApplication.NameSpace($destination)
16 | $destinationFolder.CopyHere($zipPackage.Items())
17 | }
18 | }
19 |
20 | # Create a new zip
21 | # Usage: new-zip c:\myzip.zip
22 | function New-Zip
23 | {
24 | param([string]$zipfilename)
25 | set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
26 | (dir $zipfilename).IsReadOnly = $false
27 | }
28 |
29 |
30 | # Add files to a zip via a pipeline
31 | # Usage: dir c:\filesToAdd\*.* -Recurse | add-Zip c:\myzip.zip
32 | function Add-Zip
33 | {
34 | param([string]$zipfilename)
35 |
36 | if(-not (test-path($zipfilename)))
37 | {
38 | set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
39 | (dir $zipfilename).IsReadOnly = $false
40 | }
41 |
42 | $shellApplication = new-object -com shell.application
43 | $zipPackage = $shellApplication.NameSpace($zipfilename)
44 |
45 | foreach($file in $input)
46 | {
47 | $zipPackage.CopyHere($file.FullName)
48 | Start-sleep -milliseconds 500
49 | }
50 | }
51 |
52 | # List the files in a zip
53 | # Usage: Get-Zip c:\myzip.zip
54 | function Get-Zip
55 | {
56 | param([string]$zipfilename)
57 | if(test-path($zipfilename))
58 | {
59 | $shellApplication = new-object -com shell.application
60 | $zipPackage = $shellApplication.NameSpace($zipfilename)
61 | $zipPackage.Items() | Select Path
62 | }
63 | }
64 |
65 | #####################
66 | # END Zip Functions #
67 | #####################
68 |
69 |
70 | #####################
71 | # Main script #
72 | #####################
73 |
74 | [string] $vsiFile = $args[0]
75 |
76 | if ($vsiFile -eq $null -OR $vsiFile -eq "")
77 | {
78 | Write-Error "Missing Argument! The code snippets VSI installer file was expected as a parameter."
79 | return;
80 | }
81 | if (!(Test-Path "$vsiFile"))
82 | {
83 | Write-Error "Cannot find the code snippets VSI installer file at $vsiFile."
84 | return;
85 | }
86 |
87 | Write-Host "Installing code snippets VSI: $vsiFile..."
88 |
89 | [string] $zipFile = "$vsiFile.zip"
90 | [string] $tempFolder = get-item $env:temp
91 | [string] $extractLocation = Join-Path $tempFolder ((Get-Item "$vsiFile").Name.Replace(".vsi", ""))
92 | Copy-Item "$vsiFile" "$zipFile" -force
93 |
94 | if (Test-Path "$extractLocation")
95 | {
96 | Remove-item "$extractLocation" -force -recurse
97 | }
98 | New-Item "$extractLocation" -type directory
99 |
100 |
101 | Write-Host "Extracting vsi content..."
102 | Extract-Zip "$zipFile" "$extractLocation"
103 | Write-Host "Extracting vsi content done!"
104 |
105 | [xml] $vscontent = Get-Content (Join-Path "$extractLocation" "*.vscontent")
106 |
107 | [string] $documentsFolder = [System.Environment]::GetFolderPath( [System.Environment+SpecialFolder]::MyDocuments )
108 | if (-NOT (test-path "$documentsFolder"))
109 | {
110 | $documentsFolder = "$env:UserProfile\Documents";
111 | }
112 |
113 | # ensure code snippets folder exist
114 | New-Item "$documentsFolder\Visual Studio 2015\Code Snippets" -itemtype directory -force
115 |
116 | foreach ($node in $vscontent.VSContent.Content)
117 | {
118 | Write-Host "Installing Code Snippet $($node.FileName)"
119 | $codeSnippetFile = Join-Path "$extractLocation" "$($node.FileName)"
120 | [string] $codeSnippetLocation = ""
121 |
122 | switch (($node.Attributes.Attribute | Where-Object { $_.name -eq "lang" }).value)
123 | {
124 | "XML" { $codeSnippetLocation = "$documentsFolder\Visual Studio 2015\Code Snippets\XML\My Xml Snippets" }
125 | "XAML" { $codeSnippetLocation = "$documentsFolder\Visual Studio 2015\Code Snippets\XAML\My XAML Snippets" }
126 | "HTML" { $codeSnippetLocation = "$documentsFolder\Visual Studio 2015\Code Snippets\Visual Web Developer\My HTML Snippets" }
127 | "CSS" { $codeSnippetLocation = "$documentsFolder\Visual Studio 2015\Code Snippets\Visual Web Developer\My CSS Snippets" }
128 | "JavaScript" { $codeSnippetLocation = "$documentsFolder\Visual Studio 2015\Code Snippets\JavaScript\My Code Snippets" }
129 | "csharp" { $codeSnippetLocation = "$documentsFolder\Visual Studio 2015\Code Snippets\Visual C#\My Code Snippets" }
130 | "vb" { $codeSnippetLocation = "$documentsFolder\Visual Studio 2015\Code Snippets\Visual Basic\My Code Snippets" }
131 | "SQL" { $codeSnippetLocation = "$documentsFolder\Visual Studio 2015\Code Snippets\SQL\My Code Snippets" }
132 |
133 | default { Write-Error "Unexpected code snippet language: $_" }
134 | }
135 |
136 | if (![string]::IsNullOrWhiteSpace($codeSnippetLocation))
137 | {
138 | New-Item -path $codeSnippetLocation -itemtype directory -force
139 | Copy-Item "$codeSnippetFile" -destination $codeSnippetLocation -force
140 | }
141 |
142 | Write-Host "Installing Code Snippet $($node.FileName) done!"
143 | }
144 |
145 | Write-Host "Removing temp files..."
146 | if (Test-Path "$extractLocation")
147 | {
148 | Remove-item "$extractLocation" -force -recurse
149 | }
150 | Remove-item "$zipFile" -force
151 | Write-Host "Removing temp files done!"
152 |
153 | Write-Host "Installing code snippets VSI: $vsiFile done!"
--------------------------------------------------------------------------------
/Source/Setup/scripts/snippets/IntroMonoGame.vsi:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Setup/scripts/snippets/IntroMonoGame.vsi
--------------------------------------------------------------------------------
/Source/Setup/scripts/snippets/IntroMonoGameShort.vsi:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Microsoft-Build-2016/CodeLabs-GameDev-5-MonoGameIntro/1d64c68159decb4daba5798d3428627efaa088de/Source/Setup/scripts/snippets/IntroMonoGameShort.vsi
--------------------------------------------------------------------------------