https://imamp.colum.edu/mediawiki/api.php?action=feedcontributions&user=Jeff&feedformat=atom IAM MediaWiki - User contributions [en] 2024-03-29T05:27:16Z User contributions MediaWiki 1.28.0 https://imamp.colum.edu/mediawiki/index.php?title=File:ClassDiagramStudentCourses.png&diff=23432 File:ClassDiagramStudentCourses.png 2018-10-15T18:27:35Z <p>Jeff: Jeff uploaded a new version of File:ClassDiagramStudentCourses.png</p> <hr /> <div></div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class1&diff=23386 Game Programming Class1 2018-04-09T14:30:43Z <p>Jeff: </p> <hr /> <div>GitHuib URL https://github.com/dsp56001/GameProgramming<br /> <br /> test<br /> <br /> ==Mono Game==<br /> *http://www.monogame.net/<br /> *MonoGame is a current path to managed games in windows 10 and XboxOne<br /> **http://blogs.msdn.com/b/bobfamiliar/archive/2012/08/01/windows-8-xna-and-monogame-part-1-overview.aspx<br /> *Also a path from XNA to iOS, Android, Sony PS4, XboxOne, Linux, raspberry pi etc..<br /> <br /> ==What is DirectX?==<br /> show c++ examples<br /> <br /> [http://creators.xna.com/en-US/create_detail quick start guide - create]<br /> <br /> * DirectX 8.1 http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> ** Game Sections http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> <br /> * Middleware http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> <br /> watch Accelerating Windows Store Game Development with Middleware http://channel9.msdn.com/Events/Build/2013/3-187<br /> <br /> ==Hello World==<br /> <br /> [[Hello World in Monogame using spritefont]]. We'll revisit the spriteFont when we build the console/debug class<br /> <br /> ==Hello Monogame with texture==<br /> Simple monogame project that draws a pacman sprite<br /> *Start a new Monogame Project (For all the example in this class I will use Monogame Windows)<br /> [[File:NewMonogameProjectWindowGL.PNG]]<br /> <br /> Add two variable declarations at the top of the class<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> <br /> Texture2D PacMan; //Texture2D to hold pacman texture<br /> Vector2 PacManLoc; //Vector location to draw pacman texture<br /> &lt;/syntaxhighlight&gt;<br /> In the &lt;code&gt;LoadContent&lt;/code&gt; Function add the following code to initialize the two variables declared above<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> // TODO: use this.Content to load your game content here<br /> //load PacMan image<br /> PacMan = Content.Load&lt;texture2d&gt;(&quot;pacmanSingle&quot;);<br /> //Center PacMan image<br /> PacManLoc = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> *Add the following code to the Draw Method to Draw the texture<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> protected override void Draw(GameTime gameTime)<br /> {<br /> graphics.GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> // TODO: Add your drawing code here<br /> spriteBatch.Begin();<br /> spriteBatch.Draw(PacMan, PacManLoc, Color.White);<br /> spriteBatch.End();<br /> <br /> base.Draw(gameTime);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> pacman image is availble here: [[Image:PacmanSingle.png]]<br /> <br /> <br /> the full game1.cs file should look like<br /> <br /> TODO ADD URL<br /> <br /> the build of the game will look like<br /> [[Image:IntroSimpleSpriteWindows.png]]<br /> <br /> <br /> &lt;p&gt;Simple 2D texture example with update&lt;/p&gt;<br /> <br /> ==Demos==<br /> <br /> [[Monogame Overview]]<br /> <br /> MonoGameDemos\IntroFonts https://iam.colum.edu:8443/!/#GPMonogame3/view/head/trunk/jeff/IntroFonts zip file!!!</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class2&diff=23344 Game Programming Class2 2017-09-08T02:05:58Z <p>Jeff: /* Texture2D and SpriteBatches */</p> <hr /> <div><br /> ==Objectives==<br /> *Time corrected move bases on elapsed game time Monogame<br /> *Vector2 for direction with and without magnitude<br /> *Single responsibility principal for methods<br /> <br /> ==Skills==<br /> *Get samples from SVN and Git<br /> <br /> ==SVN Checkout==<br /> <br /> All of the examples for this class and the basic game library we wil be building is in our SVN repo this week we'll practice checking out a folder from the repo.<br /> <br /> &lt;!-- https://iam.colum.edu:8443/svn/XNAProg/trunk/Jeff --&gt;<br /> <br /> Tools<br /> * Ahnk SVN for Visual Studio http://visualstudiogallery.msdn.microsoft.com/E721D830-7664-4E02-8D03-933C3F1477F2<br /> * TortoiseSVN http://tortoisesvn.net/<br /> <br /> Repo for Fall 2017<br /> <br /> Trunk : this contains all the old student work as well as my demos so you probably don't want this at least not quite yet<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk<br /> <br /> Just the Jeff folder<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/jeff<br /> <br /> <br /> Demos Projects : this is the link to my demos in SVN<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/jeff<br /> <br /> <br /> tortoisesvn http://tortoisesvn.tigris.org/<br /> <br /> ankhsvn http://ankhsvn.open.collab.net/<br /> <br /> SNV checkout demo.<br /> <br /> In the coming weeks we'll learn how to commit to the SNV. Until then all you need to know is how to checkout.<br /> <br /> ===SVN ingnore git and GIT ignore SVN===<br /> http://stackoverflow.com/questions/21156065/how-to-locally-ignore-git-and-gitignore-in-a-svn-repo<br /> <br /> http://stackoverflow.com/questions/821895/exclude-svn-folders-within-git<br /> <br /> ==Monogame Structures==<br /> Game Class<br /> <br /> The MonogameGame class has two private properties<br /> *GraphicsDeviceManager graphics;<br /> *ContentManager content;<br /> <br /> Graphics for windows and xbox are 60 fps. XBOx supports NTSC resolutions (480i, 480p, 720p, 1080i and 1080p 1080p is only on newer hdmi models).<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> //the game constuctor can be used to set some graphics settings.<br /> graphics.PreferredBackBufferHeight = 768;<br /> graphics.PreferredBackBufferWidth = 1024;<br /> //graphics.PreferredBackBufferHeight = 1080;<br /> //graphics.PreferredBackBufferWidth = 1920;<br /> //graphics.IsFullScreen = true;<br /> &lt;/syntaxhighlight&gt;<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> // Frame rate is 30 fps by default for Windows Phone. <br /> TargetElapsedTime = TimeSpan.FromTicks(333333); <br /> <br /> // Pre-autoscale settings. <br /> graphics.PreferredBackBufferWidth = 480; <br /> graphics.PreferredBackBufferHeight = 800; <br /> &lt;/syntaxhighlight&gt;<br /> <br /> <br /> # Declare SpriteBatch spriteBatch; <br /> # Initialize()<br /> # LoadContent()<br /> # UnloadContent()<br /> # Update(GameTime gameTime)<br /> <br /> ==Texture2D and SpriteBatches==<br /> simple pacmac bouncing back and forth<br /> &lt;syntaxhighlight lang=&quot;csharp&quot; highlight=&quot;17-20,54,56-60,87,91-96,100,103,119-121&quot;&gt;<br /> using System;<br /> using Microsoft.Xna.Framework;<br /> using Microsoft.Xna.Framework.Graphics;<br /> using Microsoft.Xna.Framework.Input;<br /> <br /> <br /> namespace GameUpdate<br /> {<br /> /// &lt;summary&gt;<br /> /// This is the main type for your game.<br /> /// &lt;/summar&gt;<br /> public class Game1 : Microsoft.Xna.Framework.Game<br /> {<br /> GraphicsDeviceManager graphics;<br /> SpriteBatch spriteBatch;<br /> <br /> Texture2D PacMan;<br /> Vector2 PacManLoc; //Pacman location<br /> Vector2 PacManDir; //Pacman direction<br /> float PacManSpeed; //speed for the PacMan Sprite in pixels per frame per second<br /> <br /> public Game1()<br /> {<br /> graphics = new GraphicsDeviceManager(this);<br /> Content.RootDirectory = &quot;Content&quot;;<br /> <br /> //Change the frame fate to 30 Frames per second the default is 60fps<br /> //TargetElapsedTime = TimeSpan.FromTicks(333333); // you may need to add using System; to get the TimeSpan function<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// Allows the game to perform any initialization it needs to before starting to run.<br /> /// This is where it can query for any required services and load any non-graphic<br /> /// related content. Calling base.Initialize will enumerate through any components<br /> /// and initialize them as well.<br /> /// &lt;/summary&gt;<br /> protected override void Initialize()<br /> {<br /> // TODO: Add your initialization logic here<br /> <br /> base.Initialize();<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// LoadContent will be called once per game and is the place to load<br /> /// all of your content.<br /> /// &lt;/summary&gt;<br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> // TODO: use this.Content to load your game content here<br /> PacMan = Content.Load&lt;Texture2D&gt;(&quot;pacmanSingle&quot;);<br /> //Center PacMan<br /> PacManLoc = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2,<br /> graphics.GraphicsDevice.Viewport.Height / 2); //Start with PacManLoc in the center of the screen<br /> PacManDir = new Vector2(1, 0); //start moving left<br /> <br /> PacManSpeed = 20; //initial pacman speed<br /> <br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// UnloadContent will be called once per game and is the place to unload<br /> /// all content.<br /> /// &lt;/summary&gt;<br /> protected override void UnloadContent()<br /> {<br /> // TODO: Unload any non ContentManager content here<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// Allows the game to run logic such as updating the world,<br /> /// checking for collisions, gathering input, and playing audio.<br /> /// &lt;/summary&gt;<br /> /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt;<br /> protected override void Update(GameTime gameTime)<br /> {<br /> // Allows the game to exit<br /> if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)<br /> this.Exit();<br /> <br /> // TODO: Add your update logic here<br /> <br /> //Elapsed time since last update will be used to correct movement speed<br /> float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds;<br /> <br /> <br /> //Turn PacMan Around if it hits the edge of the screen<br /> if ((PacManLoc.X &gt; graphics.GraphicsDevice.Viewport.Width - PacMan.Width)<br /> || (PacManLoc.X &lt; 0)<br /> )<br /> {<br /> PacManDir = Vector2.Negate(PacManDir);<br /> }<br /> <br /> //Move PacMan<br /> //Simple move Moves PacMac by PacManDiv on every update<br /> PacManLoc = PacManLoc + PacManDir * PacManSpeed; //no good not time corrected<br /> <br /> //Time corrected move. MOves PacMan By PacManDiv every Second<br /> //PacManLoc = PacManLoc + ((PacManDir * PacManSpeed) * (time/1000)); //Simple Move PacMan by PacManDir<br /> <br /> <br /> <br /> base.Update(gameTime);<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// This is called when the game should draw itself.<br /> /// &lt;/summary&gt;<br /> /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt;<br /> protected override void Draw(GameTime gameTime)<br /> {<br /> graphics.GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> // TODO: Add your drawing code here<br /> spriteBatch.Begin();<br /> spriteBatch.Draw(PacMan, PacManLoc, Color.White);<br /> spriteBatch.End();<br /> <br /> base.Draw(gameTime);<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==GameTime==<br /> FrameRate and GameTime<br /> * [http://msdn.microsoft.com/en-us/library/bb203873.aspx#ID2EYB Game Loop Timing]<br /> * [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.gametime_members.aspx Game Time Members]<br /> <br /> ===Time and Timespan===<br /> Example of update using GameTime to calculate elapsed time <br /> <br /> Demo<br /> <br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleUpdateMovement SimpleUpdateMovement] : move with Keyboard<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementWGravity SimpleUpdateMovementWGravity]: simple gravity moves sprite down<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleUpdateMovementWState SimpleUpdateMovementWState]: better movement show different types with state selector<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementJump SimpleMovementJump]: Very simple Jump and Gravity<br /> <br /> <br /> Understanding GameTime We'll revisit game time when we talk about performance profiling.<br /> <br /> ==Homework==<br /> *Interesting Movement Monogame : Create a Monogame project the uses keyboard input to move a sprite. The movement should be more interesting than linear up, down, left right. There are several examples of this in the SimpleUpdateMovementWState project. The sprite movement should be time corrected and frame rate independant.<br /> <br /> *Gravity and or Jump with 2 sprites<br /> **Start with SimpleUpdateMovementWGravity or SimpleMovementJump<br /> **How many sprites can you draw?<br /> **Can they have different controls?<br /> **Can you use a class to make the code more organized?<br /> <br /> <br /> Optional Reading<br /> <br /> *Read Chapter 2 in XNA 3.0<br /> *Read Chapter 4 in XNA 3.0 (yes we skipped 3 we'll come back)<br /> <br /> Extra Bonus<br /> <br /> http://advances.realtimerendering.com/s2016/Siggraph2016_idTech6.pdf<br /> <br /> ==Links==<br /> *[http://msdn.microsoft.com/en-us/library/bb194908.aspx How To: Draw a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb203866.aspx How To: Animate a Sprite] <br /> *[http://msdn.microsoft.com/en-us/library/bb203867.aspx How To: Draw a Masked Sprite over a Background]<br /> *[http://msdn.microsoft.com/en-us/library/bb203868.aspx How To: Make a Scrolling Background]<br /> *[http://msdn.microsoft.com/en-us/library/bb203869.aspx How To: Rotate a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb194912.aspx How To: Rotate a Group of Sprites]<br /> *[http://msdn.microsoft.com/en-us/library/bb194913.aspx How To: Scale a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb194914.aspx How To: Tint a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb447674.aspx How To: Scale Sprites Based On Screen Size]</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class2&diff=23343 Game Programming Class2 2017-09-08T02:05:13Z <p>Jeff: /* Monogame Structures */</p> <hr /> <div><br /> ==Objectives==<br /> *Time corrected move bases on elapsed game time Monogame<br /> *Vector2 for direction with and without magnitude<br /> *Single responsibility principal for methods<br /> <br /> ==Skills==<br /> *Get samples from SVN and Git<br /> <br /> ==SVN Checkout==<br /> <br /> All of the examples for this class and the basic game library we wil be building is in our SVN repo this week we'll practice checking out a folder from the repo.<br /> <br /> &lt;!-- https://iam.colum.edu:8443/svn/XNAProg/trunk/Jeff --&gt;<br /> <br /> Tools<br /> * Ahnk SVN for Visual Studio http://visualstudiogallery.msdn.microsoft.com/E721D830-7664-4E02-8D03-933C3F1477F2<br /> * TortoiseSVN http://tortoisesvn.net/<br /> <br /> Repo for Fall 2017<br /> <br /> Trunk : this contains all the old student work as well as my demos so you probably don't want this at least not quite yet<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk<br /> <br /> Just the Jeff folder<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/jeff<br /> <br /> <br /> Demos Projects : this is the link to my demos in SVN<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/jeff<br /> <br /> <br /> tortoisesvn http://tortoisesvn.tigris.org/<br /> <br /> ankhsvn http://ankhsvn.open.collab.net/<br /> <br /> SNV checkout demo.<br /> <br /> In the coming weeks we'll learn how to commit to the SNV. Until then all you need to know is how to checkout.<br /> <br /> ===SVN ingnore git and GIT ignore SVN===<br /> http://stackoverflow.com/questions/21156065/how-to-locally-ignore-git-and-gitignore-in-a-svn-repo<br /> <br /> http://stackoverflow.com/questions/821895/exclude-svn-folders-within-git<br /> <br /> ==Monogame Structures==<br /> Game Class<br /> <br /> The MonogameGame class has two private properties<br /> *GraphicsDeviceManager graphics;<br /> *ContentManager content;<br /> <br /> Graphics for windows and xbox are 60 fps. XBOx supports NTSC resolutions (480i, 480p, 720p, 1080i and 1080p 1080p is only on newer hdmi models).<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> //the game constuctor can be used to set some graphics settings.<br /> graphics.PreferredBackBufferHeight = 768;<br /> graphics.PreferredBackBufferWidth = 1024;<br /> //graphics.PreferredBackBufferHeight = 1080;<br /> //graphics.PreferredBackBufferWidth = 1920;<br /> //graphics.IsFullScreen = true;<br /> &lt;/syntaxhighlight&gt;<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> // Frame rate is 30 fps by default for Windows Phone. <br /> TargetElapsedTime = TimeSpan.FromTicks(333333); <br /> <br /> // Pre-autoscale settings. <br /> graphics.PreferredBackBufferWidth = 480; <br /> graphics.PreferredBackBufferHeight = 800; <br /> &lt;/syntaxhighlight&gt;<br /> <br /> <br /> # Declare SpriteBatch spriteBatch; <br /> # Initialize()<br /> # LoadContent()<br /> # UnloadContent()<br /> # Update(GameTime gameTime)<br /> <br /> ==Texture2D and SpriteBatches==<br /> simple pacmac bouncing back and forth<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;highlight=&quot;17-20,54,56-60,87,91-96,100,103,119-121&quot;&gt;<br /> using System;<br /> using Microsoft.Xna.Framework;<br /> using Microsoft.Xna.Framework.Graphics;<br /> using Microsoft.Xna.Framework.Input;<br /> <br /> <br /> namespace GameUpdate<br /> {<br /> /// &lt;summary&gt;<br /> /// This is the main type for your game.<br /> /// &lt;/summar&gt;<br /> public class Game1 : Microsoft.Xna.Framework.Game<br /> {<br /> GraphicsDeviceManager graphics;<br /> SpriteBatch spriteBatch;<br /> <br /> Texture2D PacMan;<br /> Vector2 PacManLoc; //Pacman location<br /> Vector2 PacManDir; //Pacman direction<br /> float PacManSpeed; //speed for the PacMan Sprite in pixels per frame per second<br /> <br /> public Game1()<br /> {<br /> graphics = new GraphicsDeviceManager(this);<br /> Content.RootDirectory = &quot;Content&quot;;<br /> <br /> //Change the frame fate to 30 Frames per second the default is 60fps<br /> //TargetElapsedTime = TimeSpan.FromTicks(333333); // you may need to add using System; to get the TimeSpan function<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// Allows the game to perform any initialization it needs to before starting to run.<br /> /// This is where it can query for any required services and load any non-graphic<br /> /// related content. Calling base.Initialize will enumerate through any components<br /> /// and initialize them as well.<br /> /// &lt;/summary&gt;<br /> protected override void Initialize()<br /> {<br /> // TODO: Add your initialization logic here<br /> <br /> base.Initialize();<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// LoadContent will be called once per game and is the place to load<br /> /// all of your content.<br /> /// &lt;/summary&gt;<br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> // TODO: use this.Content to load your game content here<br /> PacMan = Content.Load&lt;Texture2D&gt;(&quot;pacmanSingle&quot;);<br /> //Center PacMan<br /> PacManLoc = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2,<br /> graphics.GraphicsDevice.Viewport.Height / 2); //Start with PacManLoc in the center of the screen<br /> PacManDir = new Vector2(1, 0); //start moving left<br /> <br /> PacManSpeed = 20; //initial pacman speed<br /> <br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// UnloadContent will be called once per game and is the place to unload<br /> /// all content.<br /> /// &lt;/summary&gt;<br /> protected override void UnloadContent()<br /> {<br /> // TODO: Unload any non ContentManager content here<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// Allows the game to run logic such as updating the world,<br /> /// checking for collisions, gathering input, and playing audio.<br /> /// &lt;/summary&gt;<br /> /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt;<br /> protected override void Update(GameTime gameTime)<br /> {<br /> // Allows the game to exit<br /> if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)<br /> this.Exit();<br /> <br /> // TODO: Add your update logic here<br /> <br /> //Elapsed time since last update will be used to correct movement speed<br /> float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds;<br /> <br /> <br /> //Turn PacMan Around if it hits the edge of the screen<br /> if ((PacManLoc.X &gt; graphics.GraphicsDevice.Viewport.Width - PacMan.Width)<br /> || (PacManLoc.X &lt; 0)<br /> )<br /> {<br /> PacManDir = Vector2.Negate(PacManDir);<br /> }<br /> <br /> //Move PacMan<br /> //Simple move Moves PacMac by PacManDiv on every update<br /> PacManLoc = PacManLoc + PacManDir * PacManSpeed; //no good not time corrected<br /> <br /> //Time corrected move. MOves PacMan By PacManDiv every Second<br /> //PacManLoc = PacManLoc + ((PacManDir * PacManSpeed) * (time/1000)); //Simple Move PacMan by PacManDir<br /> <br /> <br /> <br /> base.Update(gameTime);<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// This is called when the game should draw itself.<br /> /// &lt;/summary&gt;<br /> /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt;<br /> protected override void Draw(GameTime gameTime)<br /> {<br /> graphics.GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> // TODO: Add your drawing code here<br /> spriteBatch.Begin();<br /> spriteBatch.Draw(PacMan, PacManLoc, Color.White);<br /> spriteBatch.End();<br /> <br /> base.Draw(gameTime);<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> ==GameTime==<br /> FrameRate and GameTime<br /> * [http://msdn.microsoft.com/en-us/library/bb203873.aspx#ID2EYB Game Loop Timing]<br /> * [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.gametime_members.aspx Game Time Members]<br /> <br /> ===Time and Timespan===<br /> Example of update using GameTime to calculate elapsed time <br /> <br /> Demo<br /> <br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleUpdateMovement SimpleUpdateMovement] : move with Keyboard<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementWGravity SimpleUpdateMovementWGravity]: simple gravity moves sprite down<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleUpdateMovementWState SimpleUpdateMovementWState]: better movement show different types with state selector<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementJump SimpleMovementJump]: Very simple Jump and Gravity<br /> <br /> <br /> Understanding GameTime We'll revisit game time when we talk about performance profiling.<br /> <br /> ==Homework==<br /> *Interesting Movement Monogame : Create a Monogame project the uses keyboard input to move a sprite. The movement should be more interesting than linear up, down, left right. There are several examples of this in the SimpleUpdateMovementWState project. The sprite movement should be time corrected and frame rate independant.<br /> <br /> *Gravity and or Jump with 2 sprites<br /> **Start with SimpleUpdateMovementWGravity or SimpleMovementJump<br /> **How many sprites can you draw?<br /> **Can they have different controls?<br /> **Can you use a class to make the code more organized?<br /> <br /> <br /> Optional Reading<br /> <br /> *Read Chapter 2 in XNA 3.0<br /> *Read Chapter 4 in XNA 3.0 (yes we skipped 3 we'll come back)<br /> <br /> Extra Bonus<br /> <br /> http://advances.realtimerendering.com/s2016/Siggraph2016_idTech6.pdf<br /> <br /> ==Links==<br /> *[http://msdn.microsoft.com/en-us/library/bb194908.aspx How To: Draw a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb203866.aspx How To: Animate a Sprite] <br /> *[http://msdn.microsoft.com/en-us/library/bb203867.aspx How To: Draw a Masked Sprite over a Background]<br /> *[http://msdn.microsoft.com/en-us/library/bb203868.aspx How To: Make a Scrolling Background]<br /> *[http://msdn.microsoft.com/en-us/library/bb203869.aspx How To: Rotate a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb194912.aspx How To: Rotate a Group of Sprites]<br /> *[http://msdn.microsoft.com/en-us/library/bb194913.aspx How To: Scale a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb194914.aspx How To: Tint a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb447674.aspx How To: Scale Sprites Based On Screen Size]</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class2&diff=23342 Game Programming Class2 2017-09-08T02:02:19Z <p>Jeff: /* SVN Checkout */</p> <hr /> <div><br /> ==Objectives==<br /> *Time corrected move bases on elapsed game time Monogame<br /> *Vector2 for direction with and without magnitude<br /> *Single responsibility principal for methods<br /> <br /> ==Skills==<br /> *Get samples from SVN and Git<br /> <br /> ==SVN Checkout==<br /> <br /> All of the examples for this class and the basic game library we wil be building is in our SVN repo this week we'll practice checking out a folder from the repo.<br /> <br /> &lt;!-- https://iam.colum.edu:8443/svn/XNAProg/trunk/Jeff --&gt;<br /> <br /> Tools<br /> * Ahnk SVN for Visual Studio http://visualstudiogallery.msdn.microsoft.com/E721D830-7664-4E02-8D03-933C3F1477F2<br /> * TortoiseSVN http://tortoisesvn.net/<br /> <br /> Repo for Fall 2017<br /> <br /> Trunk : this contains all the old student work as well as my demos so you probably don't want this at least not quite yet<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk<br /> <br /> Just the Jeff folder<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/jeff<br /> <br /> <br /> Demos Projects : this is the link to my demos in SVN<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/jeff<br /> <br /> <br /> tortoisesvn http://tortoisesvn.tigris.org/<br /> <br /> ankhsvn http://ankhsvn.open.collab.net/<br /> <br /> SNV checkout demo.<br /> <br /> In the coming weeks we'll learn how to commit to the SNV. Until then all you need to know is how to checkout.<br /> <br /> ===SVN ingnore git and GIT ignore SVN===<br /> http://stackoverflow.com/questions/21156065/how-to-locally-ignore-git-and-gitignore-in-a-svn-repo<br /> <br /> http://stackoverflow.com/questions/821895/exclude-svn-folders-within-git<br /> <br /> ==Monogame Structures==<br /> Game Class<br /> <br /> The MonogameGame class has two private properties<br /> *GraphicsDeviceManager graphics;<br /> *ContentManager content;<br /> <br /> Graphics for windows and xbox are 60 fps. XBOx supports NTSC resolutions (480i, 480p, 720p, 1080i and 1080p 1080p is only on newer hdmi models).<br /> <br /> &lt;pre&gt;<br /> //the game constuctor can be used to set some graphics settings.<br /> graphics.PreferredBackBufferHeight = 768;<br /> graphics.PreferredBackBufferWidth = 1024;<br /> //graphics.PreferredBackBufferHeight = 1080;<br /> //graphics.PreferredBackBufferWidth = 1920;<br /> //graphics.IsFullScreen = true;<br /> &lt;/pre&gt;<br /> <br /> Graphics for Mobile Game is 30 fps and 480 x 800.<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> // Frame rate is 30 fps by default for Windows Phone. <br /> TargetElapsedTime = TimeSpan.FromTicks(333333); <br /> <br /> // Pre-autoscale settings. <br /> graphics.PreferredBackBufferWidth = 480; <br /> graphics.PreferredBackBufferHeight = 800; <br /> &lt;/syntaxhighlight&gt;<br /> <br /> <br /> # Declare SpriteBatch spriteBatch; <br /> # Initialize()<br /> # LoadContent()<br /> # UnloadContent()<br /> # Update(GameTime gameTime)<br /> <br /> ==Texture2D and SpriteBatches==<br /> simple pacmac bouncing back and forth<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;highlight=&quot;17-20,54,56-60,87,91-96,100,103,119-121&quot;&gt;<br /> using System;<br /> using Microsoft.Xna.Framework;<br /> using Microsoft.Xna.Framework.Graphics;<br /> using Microsoft.Xna.Framework.Input;<br /> <br /> <br /> namespace GameUpdate<br /> {<br /> /// &lt;summary&gt;<br /> /// This is the main type for your game.<br /> /// &lt;/summar&gt;<br /> public class Game1 : Microsoft.Xna.Framework.Game<br /> {<br /> GraphicsDeviceManager graphics;<br /> SpriteBatch spriteBatch;<br /> <br /> Texture2D PacMan;<br /> Vector2 PacManLoc; //Pacman location<br /> Vector2 PacManDir; //Pacman direction<br /> float PacManSpeed; //speed for the PacMan Sprite in pixels per frame per second<br /> <br /> public Game1()<br /> {<br /> graphics = new GraphicsDeviceManager(this);<br /> Content.RootDirectory = &quot;Content&quot;;<br /> <br /> //Change the frame fate to 30 Frames per second the default is 60fps<br /> //TargetElapsedTime = TimeSpan.FromTicks(333333); // you may need to add using System; to get the TimeSpan function<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// Allows the game to perform any initialization it needs to before starting to run.<br /> /// This is where it can query for any required services and load any non-graphic<br /> /// related content. Calling base.Initialize will enumerate through any components<br /> /// and initialize them as well.<br /> /// &lt;/summary&gt;<br /> protected override void Initialize()<br /> {<br /> // TODO: Add your initialization logic here<br /> <br /> base.Initialize();<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// LoadContent will be called once per game and is the place to load<br /> /// all of your content.<br /> /// &lt;/summary&gt;<br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> // TODO: use this.Content to load your game content here<br /> PacMan = Content.Load&lt;Texture2D&gt;(&quot;pacmanSingle&quot;);<br /> //Center PacMan<br /> PacManLoc = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2,<br /> graphics.GraphicsDevice.Viewport.Height / 2); //Start with PacManLoc in the center of the screen<br /> PacManDir = new Vector2(1, 0); //start moving left<br /> <br /> PacManSpeed = 20; //initial pacman speed<br /> <br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// UnloadContent will be called once per game and is the place to unload<br /> /// all content.<br /> /// &lt;/summary&gt;<br /> protected override void UnloadContent()<br /> {<br /> // TODO: Unload any non ContentManager content here<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// Allows the game to run logic such as updating the world,<br /> /// checking for collisions, gathering input, and playing audio.<br /> /// &lt;/summary&gt;<br /> /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt;<br /> protected override void Update(GameTime gameTime)<br /> {<br /> // Allows the game to exit<br /> if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)<br /> this.Exit();<br /> <br /> // TODO: Add your update logic here<br /> <br /> //Elapsed time since last update will be used to correct movement speed<br /> float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds;<br /> <br /> <br /> //Turn PacMan Around if it hits the edge of the screen<br /> if ((PacManLoc.X &gt; graphics.GraphicsDevice.Viewport.Width - PacMan.Width)<br /> || (PacManLoc.X &lt; 0)<br /> )<br /> {<br /> PacManDir = Vector2.Negate(PacManDir);<br /> }<br /> <br /> //Move PacMan<br /> //Simple move Moves PacMac by PacManDiv on every update<br /> PacManLoc = PacManLoc + PacManDir * PacManSpeed; //no good not time corrected<br /> <br /> //Time corrected move. MOves PacMan By PacManDiv every Second<br /> //PacManLoc = PacManLoc + ((PacManDir * PacManSpeed) * (time/1000)); //Simple Move PacMan by PacManDir<br /> <br /> <br /> <br /> base.Update(gameTime);<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// This is called when the game should draw itself.<br /> /// &lt;/summary&gt;<br /> /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt;<br /> protected override void Draw(GameTime gameTime)<br /> {<br /> graphics.GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> // TODO: Add your drawing code here<br /> spriteBatch.Begin();<br /> spriteBatch.Draw(PacMan, PacManLoc, Color.White);<br /> spriteBatch.End();<br /> <br /> base.Draw(gameTime);<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> ==GameTime==<br /> FrameRate and GameTime<br /> * [http://msdn.microsoft.com/en-us/library/bb203873.aspx#ID2EYB Game Loop Timing]<br /> * [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.gametime_members.aspx Game Time Members]<br /> <br /> ===Time and Timespan===<br /> Example of update using GameTime to calculate elapsed time <br /> <br /> Demo<br /> <br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleUpdateMovement SimpleUpdateMovement] : move with Keyboard<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementWGravity SimpleUpdateMovementWGravity]: simple gravity moves sprite down<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleUpdateMovementWState SimpleUpdateMovementWState]: better movement show different types with state selector<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementJump SimpleMovementJump]: Very simple Jump and Gravity<br /> <br /> <br /> Understanding GameTime We'll revisit game time when we talk about performance profiling.<br /> <br /> ==Homework==<br /> *Interesting Movement Monogame : Create a Monogame project the uses keyboard input to move a sprite. The movement should be more interesting than linear up, down, left right. There are several examples of this in the SimpleUpdateMovementWState project. The sprite movement should be time corrected and frame rate independant.<br /> <br /> *Gravity and or Jump with 2 sprites<br /> **Start with SimpleUpdateMovementWGravity or SimpleMovementJump<br /> **How many sprites can you draw?<br /> **Can they have different controls?<br /> **Can you use a class to make the code more organized?<br /> <br /> <br /> Optional Reading<br /> <br /> *Read Chapter 2 in XNA 3.0<br /> *Read Chapter 4 in XNA 3.0 (yes we skipped 3 we'll come back)<br /> <br /> Extra Bonus<br /> <br /> http://advances.realtimerendering.com/s2016/Siggraph2016_idTech6.pdf<br /> <br /> ==Links==<br /> *[http://msdn.microsoft.com/en-us/library/bb194908.aspx How To: Draw a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb203866.aspx How To: Animate a Sprite] <br /> *[http://msdn.microsoft.com/en-us/library/bb203867.aspx How To: Draw a Masked Sprite over a Background]<br /> *[http://msdn.microsoft.com/en-us/library/bb203868.aspx How To: Make a Scrolling Background]<br /> *[http://msdn.microsoft.com/en-us/library/bb203869.aspx How To: Rotate a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb194912.aspx How To: Rotate a Group of Sprites]<br /> *[http://msdn.microsoft.com/en-us/library/bb194913.aspx How To: Scale a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb194914.aspx How To: Tint a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb447674.aspx How To: Scale Sprites Based On Screen Size]</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class2&diff=23341 Game Programming Class2 2017-09-08T02:01:45Z <p>Jeff: /* Fonts */</p> <hr /> <div><br /> ==Objectives==<br /> *Time corrected move bases on elapsed game time Monogame<br /> *Vector2 for direction with and without magnitude<br /> *Single responsibility principal for methods<br /> <br /> ==Skills==<br /> *Get samples from SVN and Git<br /> <br /> ==SVN Checkout==<br /> <br /> All of the examples for this class and the basic game library we wil be building is in our SVN repo this week we'll practice checking out a folder from the repo.<br /> <br /> &lt;!-- https://iam.colum.edu:8443/svn/XNAProg/trunk/Jeff --&gt;<br /> <br /> Tools<br /> * Ahnk SVN for Visual Studio http://visualstudiogallery.msdn.microsoft.com/E721D830-7664-4E02-8D03-933C3F1477F2<br /> * TortoiseSVN http://tortoisesvn.net/<br /> <br /> Repo for Fall 2016<br /> <br /> Trunk : this contains all the old student work as well as my demos so you probably don't want this at least not quite yet<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk<br /> <br /> Just the Jeff folder<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/jeff<br /> <br /> <br /> Demos Projects : this is the link to my demos in SVN<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/jeff<br /> <br /> <br /> tortoisesvn http://tortoisesvn.tigris.org/<br /> <br /> ankhsvn http://ankhsvn.open.collab.net/<br /> <br /> SNV checkout demo.<br /> <br /> In the coming weeks we'll learn how to commit to the SNV. Until then all you need to know is how to checkout.<br /> <br /> ===SVN ingnore git and GIT ignore SVN===<br /> http://stackoverflow.com/questions/21156065/how-to-locally-ignore-git-and-gitignore-in-a-svn-repo<br /> <br /> http://stackoverflow.com/questions/821895/exclude-svn-folders-within-git<br /> <br /> ==Monogame Structures==<br /> Game Class<br /> <br /> The MonogameGame class has two private properties<br /> *GraphicsDeviceManager graphics;<br /> *ContentManager content;<br /> <br /> Graphics for windows and xbox are 60 fps. XBOx supports NTSC resolutions (480i, 480p, 720p, 1080i and 1080p 1080p is only on newer hdmi models).<br /> <br /> &lt;pre&gt;<br /> //the game constuctor can be used to set some graphics settings.<br /> graphics.PreferredBackBufferHeight = 768;<br /> graphics.PreferredBackBufferWidth = 1024;<br /> //graphics.PreferredBackBufferHeight = 1080;<br /> //graphics.PreferredBackBufferWidth = 1920;<br /> //graphics.IsFullScreen = true;<br /> &lt;/pre&gt;<br /> <br /> Graphics for Mobile Game is 30 fps and 480 x 800.<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> // Frame rate is 30 fps by default for Windows Phone. <br /> TargetElapsedTime = TimeSpan.FromTicks(333333); <br /> <br /> // Pre-autoscale settings. <br /> graphics.PreferredBackBufferWidth = 480; <br /> graphics.PreferredBackBufferHeight = 800; <br /> &lt;/syntaxhighlight&gt;<br /> <br /> <br /> # Declare SpriteBatch spriteBatch; <br /> # Initialize()<br /> # LoadContent()<br /> # UnloadContent()<br /> # Update(GameTime gameTime)<br /> <br /> ==Texture2D and SpriteBatches==<br /> simple pacmac bouncing back and forth<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;highlight=&quot;17-20,54,56-60,87,91-96,100,103,119-121&quot;&gt;<br /> using System;<br /> using Microsoft.Xna.Framework;<br /> using Microsoft.Xna.Framework.Graphics;<br /> using Microsoft.Xna.Framework.Input;<br /> <br /> <br /> namespace GameUpdate<br /> {<br /> /// &lt;summary&gt;<br /> /// This is the main type for your game.<br /> /// &lt;/summar&gt;<br /> public class Game1 : Microsoft.Xna.Framework.Game<br /> {<br /> GraphicsDeviceManager graphics;<br /> SpriteBatch spriteBatch;<br /> <br /> Texture2D PacMan;<br /> Vector2 PacManLoc; //Pacman location<br /> Vector2 PacManDir; //Pacman direction<br /> float PacManSpeed; //speed for the PacMan Sprite in pixels per frame per second<br /> <br /> public Game1()<br /> {<br /> graphics = new GraphicsDeviceManager(this);<br /> Content.RootDirectory = &quot;Content&quot;;<br /> <br /> //Change the frame fate to 30 Frames per second the default is 60fps<br /> //TargetElapsedTime = TimeSpan.FromTicks(333333); // you may need to add using System; to get the TimeSpan function<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// Allows the game to perform any initialization it needs to before starting to run.<br /> /// This is where it can query for any required services and load any non-graphic<br /> /// related content. Calling base.Initialize will enumerate through any components<br /> /// and initialize them as well.<br /> /// &lt;/summary&gt;<br /> protected override void Initialize()<br /> {<br /> // TODO: Add your initialization logic here<br /> <br /> base.Initialize();<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// LoadContent will be called once per game and is the place to load<br /> /// all of your content.<br /> /// &lt;/summary&gt;<br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> // TODO: use this.Content to load your game content here<br /> PacMan = Content.Load&lt;Texture2D&gt;(&quot;pacmanSingle&quot;);<br /> //Center PacMan<br /> PacManLoc = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2,<br /> graphics.GraphicsDevice.Viewport.Height / 2); //Start with PacManLoc in the center of the screen<br /> PacManDir = new Vector2(1, 0); //start moving left<br /> <br /> PacManSpeed = 20; //initial pacman speed<br /> <br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// UnloadContent will be called once per game and is the place to unload<br /> /// all content.<br /> /// &lt;/summary&gt;<br /> protected override void UnloadContent()<br /> {<br /> // TODO: Unload any non ContentManager content here<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// Allows the game to run logic such as updating the world,<br /> /// checking for collisions, gathering input, and playing audio.<br /> /// &lt;/summary&gt;<br /> /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt;<br /> protected override void Update(GameTime gameTime)<br /> {<br /> // Allows the game to exit<br /> if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)<br /> this.Exit();<br /> <br /> // TODO: Add your update logic here<br /> <br /> //Elapsed time since last update will be used to correct movement speed<br /> float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds;<br /> <br /> <br /> //Turn PacMan Around if it hits the edge of the screen<br /> if ((PacManLoc.X &gt; graphics.GraphicsDevice.Viewport.Width - PacMan.Width)<br /> || (PacManLoc.X &lt; 0)<br /> )<br /> {<br /> PacManDir = Vector2.Negate(PacManDir);<br /> }<br /> <br /> //Move PacMan<br /> //Simple move Moves PacMac by PacManDiv on every update<br /> PacManLoc = PacManLoc + PacManDir * PacManSpeed; //no good not time corrected<br /> <br /> //Time corrected move. MOves PacMan By PacManDiv every Second<br /> //PacManLoc = PacManLoc + ((PacManDir * PacManSpeed) * (time/1000)); //Simple Move PacMan by PacManDir<br /> <br /> <br /> <br /> base.Update(gameTime);<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// This is called when the game should draw itself.<br /> /// &lt;/summary&gt;<br /> /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt;<br /> protected override void Draw(GameTime gameTime)<br /> {<br /> graphics.GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> // TODO: Add your drawing code here<br /> spriteBatch.Begin();<br /> spriteBatch.Draw(PacMan, PacManLoc, Color.White);<br /> spriteBatch.End();<br /> <br /> base.Draw(gameTime);<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> ==GameTime==<br /> FrameRate and GameTime<br /> * [http://msdn.microsoft.com/en-us/library/bb203873.aspx#ID2EYB Game Loop Timing]<br /> * [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.gametime_members.aspx Game Time Members]<br /> <br /> ===Time and Timespan===<br /> Example of update using GameTime to calculate elapsed time <br /> <br /> Demo<br /> <br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleUpdateMovement SimpleUpdateMovement] : move with Keyboard<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementWGravity SimpleUpdateMovementWGravity]: simple gravity moves sprite down<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleUpdateMovementWState SimpleUpdateMovementWState]: better movement show different types with state selector<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementJump SimpleMovementJump]: Very simple Jump and Gravity<br /> <br /> <br /> Understanding GameTime We'll revisit game time when we talk about performance profiling.<br /> <br /> ==Homework==<br /> *Interesting Movement Monogame : Create a Monogame project the uses keyboard input to move a sprite. The movement should be more interesting than linear up, down, left right. There are several examples of this in the SimpleUpdateMovementWState project. The sprite movement should be time corrected and frame rate independant.<br /> <br /> *Gravity and or Jump with 2 sprites<br /> **Start with SimpleUpdateMovementWGravity or SimpleMovementJump<br /> **How many sprites can you draw?<br /> **Can they have different controls?<br /> **Can you use a class to make the code more organized?<br /> <br /> <br /> Optional Reading<br /> <br /> *Read Chapter 2 in XNA 3.0<br /> *Read Chapter 4 in XNA 3.0 (yes we skipped 3 we'll come back)<br /> <br /> Extra Bonus<br /> <br /> http://advances.realtimerendering.com/s2016/Siggraph2016_idTech6.pdf<br /> <br /> ==Links==<br /> *[http://msdn.microsoft.com/en-us/library/bb194908.aspx How To: Draw a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb203866.aspx How To: Animate a Sprite] <br /> *[http://msdn.microsoft.com/en-us/library/bb203867.aspx How To: Draw a Masked Sprite over a Background]<br /> *[http://msdn.microsoft.com/en-us/library/bb203868.aspx How To: Make a Scrolling Background]<br /> *[http://msdn.microsoft.com/en-us/library/bb203869.aspx How To: Rotate a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb194912.aspx How To: Rotate a Group of Sprites]<br /> *[http://msdn.microsoft.com/en-us/library/bb194913.aspx How To: Scale a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb194914.aspx How To: Tint a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb447674.aspx How To: Scale Sprites Based On Screen Size]</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class1&diff=23339 Game Programming Class1 2017-09-05T01:55:13Z <p>Jeff: /* HomeWork */</p> <hr /> <div>GitHuib URL https://github.com/dsp56001/GameProgramming<br /> <br /> ==Mono Game==<br /> *http://www.monogame.net/<br /> *MonoGame is a current path to managed games in windows 10 and XboxOne<br /> **http://blogs.msdn.com/b/bobfamiliar/archive/2012/08/01/windows-8-xna-and-monogame-part-1-overview.aspx<br /> *Also a path from XNA to iOS, Android, Sony PS4, XboxOne, Linux, raspberry pi etc..<br /> <br /> ==What is DirectX?==<br /> show c++ examples<br /> <br /> [http://creators.xna.com/en-US/create_detail quick start guide - create]<br /> <br /> * DirectX 8.1 http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> ** Game Sections http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> <br /> * Middleware http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> <br /> watch Accelerating Windows Store Game Development with Middleware http://channel9.msdn.com/Events/Build/2013/3-187<br /> <br /> ==Hello World==<br /> <br /> [[Hello World in Monogame using spritefont]]. We'll revisit the spriteFont when we build the console/debug class<br /> <br /> ==Hello Monogame with texture==<br /> Simple monogame project that draws a pacman sprite<br /> *Start a new Monogame Project (For all the example in this class I will use Monogame Windows)<br /> [[File:NewMonogameProjectWindowGL.PNG]]<br /> <br /> Add two variable declarations at the top of the class<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> <br /> Texture2D PacMan; //Texture2D to hold pacman texture<br /> Vector2 PacManLoc; //Vector location to draw pacman texture<br /> &lt;/syntaxhighlight&gt;<br /> In the &lt;code&gt;LoadContent&lt;/code&gt; Function add the following code to initialize the two variables declared above<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> // TODO: use this.Content to load your game content here<br /> //load PacMan image<br /> PacMan = Content.Load&lt;texture2d&gt;(&quot;pacmanSingle&quot;);<br /> //Center PacMan image<br /> PacManLoc = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> *Add the following code to the Draw Method to Draw the texture<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> protected override void Draw(GameTime gameTime)<br /> {<br /> graphics.GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> // TODO: Add your drawing code here<br /> spriteBatch.Begin();<br /> spriteBatch.Draw(PacMan, PacManLoc, Color.White);<br /> spriteBatch.End();<br /> <br /> base.Draw(gameTime);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> pacman image is availble here: [[Image:PacmanSingle.png]]<br /> <br /> <br /> the full game1.cs file should look like<br /> <br /> TODO ADD URL<br /> <br /> the build of the game will look like<br /> [[Image:IntroSimpleSpriteWindows.png]]<br /> <br /> <br /> &lt;p&gt;Simple 2D texture example with update&lt;/p&gt;<br /> <br /> ==Demos==<br /> <br /> [[Monogame Overview]]<br /> <br /> MonoGameDemos\IntroFonts https://iam.colum.edu:8443/!/#GPMonogame3/view/head/trunk/jeff/IntroFonts zip file!!!</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class1&diff=23338 Game Programming Class1 2017-09-05T01:54:32Z <p>Jeff: </p> <hr /> <div>GitHuib URL https://github.com/dsp56001/GameProgramming<br /> <br /> ==Mono Game==<br /> *http://www.monogame.net/<br /> *MonoGame is a current path to managed games in windows 10 and XboxOne<br /> **http://blogs.msdn.com/b/bobfamiliar/archive/2012/08/01/windows-8-xna-and-monogame-part-1-overview.aspx<br /> *Also a path from XNA to iOS, Android, Sony PS4, XboxOne, Linux, raspberry pi etc..<br /> <br /> ==What is DirectX?==<br /> show c++ examples<br /> <br /> [http://creators.xna.com/en-US/create_detail quick start guide - create]<br /> <br /> * DirectX 8.1 http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> ** Game Sections http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> <br /> * Middleware http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> <br /> watch Accelerating Windows Store Game Development with Middleware http://channel9.msdn.com/Events/Build/2013/3-187<br /> <br /> ==Hello World==<br /> <br /> [[Hello World in Monogame using spritefont]]. We'll revisit the spriteFont when we build the console/debug class<br /> <br /> ==Hello Monogame with texture==<br /> Simple monogame project that draws a pacman sprite<br /> *Start a new Monogame Project (For all the example in this class I will use Monogame Windows)<br /> [[File:NewMonogameProjectWindowGL.PNG]]<br /> <br /> Add two variable declarations at the top of the class<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> <br /> Texture2D PacMan; //Texture2D to hold pacman texture<br /> Vector2 PacManLoc; //Vector location to draw pacman texture<br /> &lt;/syntaxhighlight&gt;<br /> In the &lt;code&gt;LoadContent&lt;/code&gt; Function add the following code to initialize the two variables declared above<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> // TODO: use this.Content to load your game content here<br /> //load PacMan image<br /> PacMan = Content.Load&lt;texture2d&gt;(&quot;pacmanSingle&quot;);<br /> //Center PacMan image<br /> PacManLoc = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> *Add the following code to the Draw Method to Draw the texture<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> protected override void Draw(GameTime gameTime)<br /> {<br /> graphics.GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> // TODO: Add your drawing code here<br /> spriteBatch.Begin();<br /> spriteBatch.Draw(PacMan, PacManLoc, Color.White);<br /> spriteBatch.End();<br /> <br /> base.Draw(gameTime);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> pacman image is availble here: [[Image:PacmanSingle.png]]<br /> <br /> <br /> the full game1.cs file should look like<br /> <br /> TODO ADD URL<br /> <br /> the build of the game will look like<br /> [[Image:IntroSimpleSpriteWindows.png]]<br /> <br /> <br /> &lt;p&gt;Simple 2D texture example with update&lt;/p&gt;<br /> <br /> ==Demos==<br /> <br /> [[Monogame Overview]]<br /> <br /> MonoGameDemos\IntroFonts https://iam.colum.edu:8443/!/#GPMonogame3/view/head/trunk/jeff/IntroFonts zip file!!!<br /> <br /> ==HomeWork==<br /> <br /> Watch Accelerating Windows Store Game Development with Middleware http://channel9.msdn.com/Events/Build/2013/3-187<br /> <br /> <br /> Install VS2015 get Monogame 3.5 and prerequisites<br /> <br /> Create an Monogame Picture. The picture needs to have at least <br /> *1 SpriteFont<br /> *3 Textures<br /> <br /> Monogame pipeline tool supports different types of images but for this project let's stick with png files. What does the alpha channel in the png files do in monogame? what happens if you use a jpg?<br /> <br /> Also please post a screen shot of your project running in the assignments. Zip and upload source to moodle.<br /> <br /> You can take a screen shot using the snip tool. Start run snip in vista or 7. Or you can just press the Print Screen key on the keyboard.<br /> <br /> *Read Chapter 1 of XNA 3.0</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class1&diff=23337 Game Programming Class1 2017-09-05T01:54:12Z <p>Jeff: </p> <hr /> <div>GitHuib URL https://github.com/dsp56001/GameProgramming<br /> <br /> ==Mono Game==<br /> *http://www.monogame.net/<br /> *MonoGame is a current path to managed games in windows 10 and XboxOne<br /> **http://blogs.msdn.com/b/bobfamiliar/archive/2012/08/01/windows-8-xna-and-monogame-part-1-overview.aspx<br /> *Also a path from XNA to iOS, Android, Sony PS4, XboxOne, Linux, raspberry pi etc..<br /> <br /> [[Installing Monogame]]<br /> <br /> ==What is DirectX?==<br /> show c++ examples<br /> <br /> [http://creators.xna.com/en-US/create_detail quick start guide - create]<br /> <br /> * DirectX 8.1 http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> ** Game Sections http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> <br /> * Middleware http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fbuild%2f2013%2f3-187.pptx<br /> <br /> watch Accelerating Windows Store Game Development with Middleware http://channel9.msdn.com/Events/Build/2013/3-187<br /> <br /> ==Hello World==<br /> <br /> [[Hello World in Monogame using spritefont]]. We'll revisit the spriteFont when we build the console/debug class<br /> <br /> ==Hello Monogame with texture==<br /> Simple monogame project that draws a pacman sprite<br /> *Start a new Monogame Project (For all the example in this class I will use Monogame Windows)<br /> [[File:NewMonogameProjectWindowGL.PNG]]<br /> <br /> Add two variable declarations at the top of the class<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> <br /> Texture2D PacMan; //Texture2D to hold pacman texture<br /> Vector2 PacManLoc; //Vector location to draw pacman texture<br /> &lt;/syntaxhighlight&gt;<br /> In the &lt;code&gt;LoadContent&lt;/code&gt; Function add the following code to initialize the two variables declared above<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> // TODO: use this.Content to load your game content here<br /> //load PacMan image<br /> PacMan = Content.Load&lt;texture2d&gt;(&quot;pacmanSingle&quot;);<br /> //Center PacMan image<br /> PacManLoc = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> *Add the following code to the Draw Method to Draw the texture<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> protected override void Draw(GameTime gameTime)<br /> {<br /> graphics.GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> // TODO: Add your drawing code here<br /> spriteBatch.Begin();<br /> spriteBatch.Draw(PacMan, PacManLoc, Color.White);<br /> spriteBatch.End();<br /> <br /> base.Draw(gameTime);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> pacman image is availble here: [[Image:PacmanSingle.png]]<br /> <br /> <br /> the full game1.cs file should look like<br /> <br /> TODO ADD URL<br /> <br /> the build of the game will look like<br /> [[Image:IntroSimpleSpriteWindows.png]]<br /> <br /> <br /> &lt;p&gt;Simple 2D texture example with update&lt;/p&gt;<br /> <br /> ==Demos==<br /> <br /> [[Monogame Overview]]<br /> <br /> MonoGameDemos\IntroFonts https://iam.colum.edu:8443/!/#GPMonogame3/view/head/trunk/jeff/IntroFonts zip file!!!<br /> <br /> ==HomeWork==<br /> <br /> Watch Accelerating Windows Store Game Development with Middleware http://channel9.msdn.com/Events/Build/2013/3-187<br /> <br /> <br /> Install VS2015 get Monogame 3.5 and prerequisites<br /> <br /> Create an Monogame Picture. The picture needs to have at least <br /> *1 SpriteFont<br /> *3 Textures<br /> <br /> Monogame pipeline tool supports different types of images but for this project let's stick with png files. What does the alpha channel in the png files do in monogame? what happens if you use a jpg?<br /> <br /> Also please post a screen shot of your project running in the assignments. Zip and upload source to moodle.<br /> <br /> You can take a screen shot using the snip tool. Start run snip in vista or 7. Or you can just press the Print Screen key on the keyboard.<br /> <br /> *Read Chapter 1 of XNA 3.0</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Adobe_ETLA_WAH_tutorial&diff=23336 Adobe ETLA WAH tutorial 2017-08-14T14:44:34Z <p>Jeff: </p> <hr /> <div>[[Category:Tutorial]]<br /> [[Category:Adobe]]<br /> [[Category:Software]]<br /> <br /> =Adobe Work at Home (WAH)=<br /> Under our Enterprise Term License Agreement (ETLA) Columbia Staff and Faculty are entitled to Adobe Creative Cloud Complete with 20 Gigs of storage. Previously this program was run by Kivuto. Our ETLA has been renewed and Kivuto will not be supported in the current contract. We are working with Adobe to federate our domain and import our faculty and staff. Until then if your Kivuto account expires please contact<br /> <br /> <br /> [mailto:amlewis@colum.edu;jmeyers@colum.edu?Subject=Adobe%20WAH%20&amp;body=Please%20add%20me%20to%20Adobe%20WAH Amber Lewis amlewis@colum.edu or Jeff Meyers jmeyers@colum.edu]<br /> <br /> <br /> to be manually added to the new program.</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=File:MC-5.jpg&diff=23311 File:MC-5.jpg 2017-07-19T20:12:42Z <p>Jeff: </p> <hr /> <div></div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=File:TotalVDIAfter3YearsCapture.PNG&diff=22875 File:TotalVDIAfter3YearsCapture.PNG 2017-01-27T04:53:36Z <p>Jeff: </p> <hr /> <div></div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=File:CaptureDNS.PNG&diff=22874 File:CaptureDNS.PNG 2017-01-27T04:52:50Z <p>Jeff: </p> <hr /> <div></div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming&diff=22873 Game Programming 2017-01-10T22:36:28Z <p>Jeff: </p> <hr /> <div>[[Category:IAM Classes]]<br /> [[Category:Programming]]<br /> __NOTOC__<br /> =Game Programming=<br /> <br /> [[Monogame Overview]]<br /> <br /> ==Stuff==<br /> <br /> Game Programming Syllabus See moodle https://lms.colum.edu<br /> <br /> http://iam.colum.edu/screenz/SP16/<br /> <br /> <br /> {{XNA Game Programming Classes}}<br /> <br /> <br /> ==Links==</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming&diff=22872 Game Programming 2017-01-10T22:36:11Z <p>Jeff: </p> <hr /> <div>[[Category:IAM Classes]]<br /> [[Category:XNA Programming]]<br /> __NOTOC__<br /> =Game Programming=<br /> <br /> [[Monogame Overview]]<br /> <br /> ==Stuff==<br /> <br /> Game Programming Syllabus See moodle https://lms.colum.edu<br /> <br /> http://iam.colum.edu/screenz/SP16/<br /> <br /> <br /> {{XNA Game Programming Classes}}<br /> <br /> <br /> ==Links==</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming&diff=22871 Game Programming 2017-01-10T22:35:53Z <p>Jeff: </p> <hr /> <div>[[Category:IAM Classes]]<br /> [[Category:XNA Programming]]<br /> __NOTOC__<br /> =Game Programming=<br /> <br /> [[Monogame Overview]]<br /> <br /> ==Stuff==<br /> <br /> Game Programming Syllabus See moodle https://lms.colum.edu<br /> <br /> http://iam.colum.edu/screenz/SP16/<br /> <br /> <br /> {{XNA Game Programming Classes}}<br /> <br /> [[XNA Game Programming Classes]]<br /> <br /> ==Links==</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming&diff=22870 Game Programming 2017-01-10T22:35:08Z <p>Jeff: </p> <hr /> <div>[[Category:IAM Classes]]<br /> [[Category:XNA Programming]]<br /> __NOTOC__<br /> =Game Programming=<br /> <br /> [[Monogame Overview]]<br /> <br /> ==Stuff==<br /> <br /> Game Programming Syllabus See moodle https://lms.colum.edu<br /> <br /> http://iam.colum.edu/screenz/SP16/<br /> <br /> ==Links==</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming&diff=22869 Game Programming 2017-01-10T22:34:51Z <p>Jeff: </p> <hr /> <div>[[Category:IAM Classes]]<br /> [[Category:XNA Programming]]<br /> __NOTOC__<br /> =Game Programming=<br /> <br /> [[Monogame Overview]]<br /> <br /> ==Stuff==<br /> <br /> Game Programming Syllabus See moodle https://lms.colum.edu<br /> <br /> http://iam.colum.edu/screenz/SP16/<br /> <br /> {{XNA Game Programming Classes}}<br /> <br /> [[XNA Game Programming Classes]]<br /> <br /> <br /> ==Links==</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming&diff=22868 Game Programming 2017-01-10T22:34:27Z <p>Jeff: /* Game Programming */</p> <hr /> <div>[[Category:IAM Classes]]<br /> [[Category:XNA Programming]]<br /> __NOTOC__<br /> =Game Programming=<br /> <br /> [[Monogame Overview]]<br /> <br /> ==Stuff==<br /> <br /> Game Programming Syllabus See moodle https://lms.colum.edu<br /> <br /> http://iam.colum.edu/screenz/FA15/<br /> <br /> {{XNA Game Programming Classes}}<br /> <br /> [[XNA Game Programming Classes]]<br /> <br /> Free XNA book<br /> <br /> http://xnagamemaking.com/<br /> http://www.lulu.com/product/download/a-simple-introduction-to-game-programming-with-c%23-and-xna-31/5438606<br /> <br /> ==Links==</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class14&diff=22837 OOP Class14 2016-12-06T20:30:34Z <p>Jeff: /* Parallel */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> <br /> ==Parallel==<br /> http://msdn.microsoft.com/en-us/library/dd460713(v=vs.110).aspx<br /> <br /> samples: http://code.msdn.microsoft.com/windowsdesktop/Samples-for-Parallel-b4b76364<br /> <br /> for<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> int count = 20;<br /> int[] ints = new int[count];<br /> for (int i = 0; i &lt; count; i++)<br /> {<br /> shorts[i] = 1;<br /> }<br /> <br /> //sample Parallel.For<br /> int[] intP = new int[count];<br /> Parallel.For(0, count, i =&gt;<br /> {<br /> intP[i] = 1;<br /> });<br /> &lt;/syntaxhighlight&gt;<br /> <br /> Demo<br /> <br /> http://iam.colum.edu/oop/classsource/class15/AsyncConsoleApplication.zip<br /> <br /> http://iam.colum.edu/oop/classsource/class15/WindowsFormsApplicationAsync.zip<br /> <br /> ==Async==<br /> http://msdn.microsoft.com/en-us/library/hh191443.aspx<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> private void buttonBlock_Click(object sender, EventArgs e)<br /> {<br /> textBox1.Text = DoLongCount();<br /> }<br /> <br /> //Async call to async method<br /> private async void buttonAsync_Click(object sender, EventArgs e)<br /> {<br /> textBox1.Text = await DoLongAsyncCount();<br /> }<br /> <br /> private string DoLongCount()<br /> {<br /> System.Threading.Thread.Sleep(1000);<br /> Count++;<br /> return &quot;count is &quot; + Count;<br /> }<br /> <br /> //Async Task<br /> private async Task&lt;string&gt; DoLongAsyncCount()<br /> {<br /> await Task.Delay(1000);<br /> Count++;<br /> return &quot;count is &quot; + Count;<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> <br /> &lt;!--<br /> ==File IO==<br /> <br /> ===write file===<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt; string fileName = &quot;test.txt&quot;;<br /> string folderPath = &quot;c:\\user\\&quot;; <br /> <br /> FileStream fs;<br /> <br /> //Make sure the the File exists if not create it if so open it<br /> if (!(File.Exists(folderPath + fileName)))<br /> {<br /> fs = File.Create(folderPath + fileName);<br /> }<br /> else<br /> {<br /> fs = new FileStream( folderPath + fileName , FileMode.Open, FileAccess.ReadWrite );<br /> }<br /> <br /> StreamWriter sw = new StreamWriter(fs); //use streamwriter to write to file<br /> <br /> sw.Write(&quot;Hello World!!!&quot;);<br /> sw.Close(); //close writer<br /> fs.Close(); //close file stream&lt;/syntaxhighlight&gt;<br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/hellowrite.cs<br /> <br /> ===read file===<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt; StreamReader sr = new StreamReader(fs);<br /> while( sr.Peek() &gt; -1 )<br /> {<br /> Console.WriteLine(sr.ReadLine());<br /> }<br /> sr.Close();&lt;/syntaxhighlight&gt;<br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/echoFile.cs<br /> <br /> ===File Counter===<br /> <br /> http://iam.colum.edu/oop/classsource/class14/hitCounter.aspx<br /> [[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/hitCounter.aspx - source]]<br /> <br /> ===Send Mail===<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;&lt;% @Page Language=&quot;C#&quot; %&gt;<br /> &lt;% @Import Namespace=&quot;System.Web.Mail&quot; %&gt;<br /> &lt;%<br /> //set up some strings for the email<br /> <br /> string strTo = &quot;only_a_test@fastmail.fm&quot;;<br /> string strFrom = &quot;jeff@interactive.colum.edu&quot;;<br /> string strSubject = &quot;Hi jeff&quot;;<br /> string strBody = &quot;A real nice body text here&quot;;<br /> <br /> //Send email<br /> SmtpMail.SmtpServer = &quot;localhost&quot;;<br /> SmtpMail.Send(strFrom, strTo, strSubject, strBody);<br /> %&gt;&lt;/syntaxhighlight&gt;<br /> http://iam.colum.edu/oop/classsource/class14/mail.aspx<br /> [[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/mail.aspx -source]]<br /> <br /> ===Upload a File===<br /> <br /> http uploader<br /> <br /> Add executionTimeout and maxRequestLength to the web.config so that large uploads will not fail.<br /> <br /> &lt;xml&gt;<br /> &lt;configuration&gt;<br /> &lt;system.web&gt;<br /> &lt;!--<br /> httpRuntime Attributes:<br /> executionTimeout=&quot;[seconds]&quot; - time in seconds before request is automatically timed out<br /> maxRequestLength=&quot;[KBytes]&quot; - KBytes size of maximum request length to accept<br /> useFullyQualifiedRedirectUrl=&quot;[true|false]&quot; - Fully qualifiy the URL for client redirects<br /> minFreeThreads=&quot;[count]&quot; - minimum number of free thread to allow execution of new requests<br /> minLocalRequestFreeThreads=&quot;[count]&quot; - minimum number of free thread to allow execution of new local requests<br /> appRequestQueueLimit=&quot;[count]&quot; - maximum number of requests queued for the application<br /> enableKernelOutputCache=&quot;[true|false]&quot; - enable the http.sys cache on IIS6 and higher - default is true<br /> enableVersionHeader=&quot;[true|false]&quot; - outputs X-AspNet-Version header with each request<br /> --&gt;<br /> &lt;!--<br /> &lt;httpRuntime<br /> executionTimeout=&quot;1200&quot;<br /> maxRequestLength=&quot;65536&quot;<br /> /&gt;<br /> &lt;/system.web&gt;<br /> &lt;/configuration&gt;<br /> &lt;/xml&gt; <br /> <br /> multipart form<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> &lt;form enctype=&quot;multipart/form-data&quot; runat=&quot;server&quot;&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;Select file to upload:&lt;/td&gt;<br /> &lt;td&gt;<br /> &lt;input id=&quot;myfile&quot; type=&quot;file&quot; runat=&quot;server&quot;&gt;&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;<br /> &lt;input type=button id=&quot;btnUploadTheFile&quot; value=&quot;Upload&quot; <br /> OnServerClick=&quot;btnUploadTheFile_Click&quot; runat=&quot;server&quot; /&gt;<br /> &lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;/form&gt;<br /> &lt;/syntaxhighlight&gt;<br /> <br /> Parse the multipart form and save the file msdn library. System.Web.HtmlInputFile.PostedFile Property<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> void btnUploadTheFile_Click(object Source, EventArgs evArgs) <br /> {<br /> //Path to save file<br /> string strBaseLocation = &quot;&quot;;<br /> <br /> if (null != myfile.PostedFile) <br /> {<br /> // Get the HTTP posted file instance (to simplify the code) <br /> HttpPostedFile postedfile = myfile.PostedFile; <br /> <br /> // Get the filename <br /> string filename = new System.IO.FileInfo(postedfile.FileName).Name; <br /> string filesize = postedfile.ContentLength.ToString();<br /> try <br /> {<br /> myfile.PostedFile.SaveAs(strBaseLocation+filename);<br /> txtOutput.InnerHtml = &quot;File &quot; + strBaseLocation + filename + &quot; uploaded successfully&quot;;<br /> }<br /> catch (Exception e) <br /> {<br /> txtOutput.InnerHtml = &quot;Error saving &quot; + strBaseLocation + filename + &quot;<br /> &quot;+ e.ToString();<br /> }<br /> <br /> //Do some other stuff <br /> //maybe like send an email to let admin know file was uploaded<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> http://iam.colum.edu/oop/classsource/class14/up.aspx<br /> [[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/up.aspx up.aspx - source]]<br /> [[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/web.config web.config - source]]<br /> --&gt;<br /> ==Final Review==<br /> <br /> [[OOP Final Review]]<br /> <br /> *Be very familiar with c# syntax<br /> **Basic object types (int, bool, string)<br /> **Conditional and Branching statements<br /> **Arrays and Generics ie List<br /> *Understand Classes and Inheritance.<br /> *Use some advanced class features such as abstract classes and virtual methods that are overridden<br /> <br /> *Understand class relationships<br /> **Is A<br /> **Has A<br /> **Uses A<br /> <br /> *Understand Encapsulation, Abstraction and Polymorphism<br /> **Abstraction <br /> :Each class should abstract its behavior in order to increase usability, reuse, and organization. <br /> **Encapsulation<br /> :Each class should contain all of the properties and methods it needs. It should only expose what is necessary to outside classes.<br /> **Polymorphism<br /> :many forms, same code interface but interchangeable classes<br /> *Be able to read and create UML Diagrams<br /> <br /> *Be able to recognize and use simple design patters<br /> <br /> The final will be consist of two sections the writtens section and the practical section. The practical section will be open everything excpet open mouth (yes open note open book open web). You will not be ablt to use any of theese resources during the written section.</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class13&diff=22836 OOP Class13 2016-11-29T16:22:43Z <p>Jeff: </p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> <br /> Review Strategy Pattern<br /> <br /> Inclass Practice Final<br /> <br /> If there is time we will review observer pattern. <br /> <br /> ==Observer==<br /> <br /> Observer<br /> :Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. <br /> <br /> Observers<br /> <br /> http://www.dofactory.com/Patterns/PatternObserver.aspx<br /> <br /> Observer is a design pattern that is often used to publish (push) or subscribe (pull) changes in the stae of one object to other interested object. It encourages loose coupling of objects.<br /> <br /> The object the get the data often called the subject then notifies the observing objects of the change. The observing object will often respond to the subject.<br /> <br /> <br /> [[Image:Observer.gif]]<br /> <br /> Here is a real example in c#. In this example a stock (the subject) notifies and investor (the observer) of a change in price.<br /> <br /> [[Image:ObserverStocks.png]]<br /> <br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class13/Observer_j.cs<br /> <br /> http://iam.colum.edu/oop/classsource/class13/Observer.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class13/Observer.aspx - source]<br /> <br /> ===Observer App===<br /> <br /> Here's and example of a windows app the uses the observer pattern<br /> <br /> http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class13/Observer<br /> <br /> Here is the start of a web app that does the same<br /> <br /> http://iam.colum.edu/oop/classsource/class13/ColorObserver.aspx<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class13/ColorObserver.aspx - source]<br /> <br /> http://iam.colum.edu/oop/classsource/class13/ColorObserver2.aspx<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class13/ColorObserver2.aspx - source]<br /> <br /> ==Homework==<br /> <br /> Practice final not graded.<br /> <br /> Review next week</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class13&diff=22835 OOP Class13 2016-11-29T16:22:22Z <p>Jeff: </p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> <br /> Review Strategy Pattern<br /> <br /> Inclass Practice Final<br /> <br /> I there is time we will review observer pattern. <br /> <br /> ==Observer==<br /> <br /> Observer<br /> :Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. <br /> <br /> Observers<br /> <br /> http://www.dofactory.com/Patterns/PatternObserver.aspx<br /> <br /> Observer is a design pattern that is often used to publish (push) or subscribe (pull) changes in the stae of one object to other interested object. It encourages loose coupling of objects.<br /> <br /> The object the get the data often called the subject then notifies the observing objects of the change. The observing object will often respond to the subject.<br /> <br /> <br /> [[Image:Observer.gif]]<br /> <br /> Here is a real example in c#. In this example a stock (the subject) notifies and investor (the observer) of a change in price.<br /> <br /> [[Image:ObserverStocks.png]]<br /> <br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class13/Observer_j.cs<br /> <br /> http://iam.colum.edu/oop/classsource/class13/Observer.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class13/Observer.aspx - source]<br /> <br /> ===Observer App===<br /> <br /> Here's and example of a windows app the uses the observer pattern<br /> <br /> http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class13/Observer<br /> <br /> Here is the start of a web app that does the same<br /> <br /> http://iam.colum.edu/oop/classsource/class13/ColorObserver.aspx<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class13/ColorObserver.aspx - source]<br /> <br /> http://iam.colum.edu/oop/classsource/class13/ColorObserver2.aspx<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class13/ColorObserver2.aspx - source]<br /> <br /> ==Homework==<br /> <br /> Practice final not graded.<br /> <br /> Review next week</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=OOP_Final_Review&diff=22834 OOP Final Review 2016-11-29T16:21:39Z <p>Jeff: </p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> {{OOP Review Midterm}}<br /> <br /> *[[OOP Class8]] C Sharp UI and windows forms<br /> **Universal Apps and WPF<br /> **Web Forms<br /> *[[OOP Class9]] Interfaces<br /> **Interfaces<br /> **PolyMorphism<br /> *[[OOP Class10]] Start Patterns Events and Delegation Classes and Objects<br /> *[[OOP Class11]] Interfaces<br /> **Problems with inheritance<br /> **Strategy Pattern<br /> *[[OOP Class12]] IComparable Interfaces<br /> **Collections<br /> **Strategy Pattern <br /> *[[OOP Class13]] Practical Review<br /> *[[OOP Class14]] Files and Mail and Review oh my<br /> **Review<br /> *[[OOP Class15]]<br /> **Take Final</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Template:OOPClasses&diff=22833 Template:OOPClasses 2016-11-29T16:03:50Z <p>Jeff: </p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> <br /> *[[OOP Class1]] Introduction to .NET and C#<br /> *[[OOP Class2]] Review C# fundamentals <br /> *[[OOP Class3]] Review [[CSharp Control Structures]]<br /> *[[OOP Class4]] Classes and Objects / Abstracrtion and Encapsulation<br /> *[[OOP Class5]] Object Relationships Inheritance<br /> *[[OOP Class6]] Object Relation Ships Association Containment / UML<br /> *[[OOP Class7]] Encapsulation Polymorphism / Review MidTerm Review<br /> *[[OOP Class8]] Midterm Exam<br /> *[[OOP Class9]] UI and Interfaces, Separation of Concern<br /> *[[OOP Class10]] [[Basic Android]] More Separation of Concern with call Model and UI<br /> *[[OOP Class11]] Accessors and Interfaces<br /> *[[OOP Class12]] Interfaces and Strategy Pattern IComparable<br /> *[[OOP Class13]] Final Review and Practical Practice<br /> *[[OOP Class14]] Async Parallel and Review oh my<br /> *[[OOP Class15]] Final Exam</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Basic_Android&diff=22821 Basic Android 2016-11-08T19:40:15Z <p>Jeff: /* In Class Demo */</p> <hr /> <div>[[Category:Tech]]<br /> [[Category:Tutorial]]<br /> [[Category:Video Tutorial]]<br /> <br /> =Android Basics=<br /> <br /> <br /> *Install 32 or 64 bit Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html<br /> <br /> *App Inventor Pretty basic web interface an blocks editor to build simple android apps http://appinventor.mit.edu/about/ <br /> **Setup App Inventor http://appinventor.mit.edu/<br /> <br /> *Android SDK<br /> **http://developer.android.com/sdk/index.html<br /> **Download Android Studio<br /> **For SDK path we will use c:\user\Android<br /> <br /> *Android NDK<br /> **we're not covering this http://developer.android.com/sdk/ndk/index.html<br /> <br /> ==Basics==<br /> <br /> <br /> *src folder containing all the source<br /> *res folder containing all the resources<br /> <br /> folder hierarchy explained http://developer.android.com/tools/projects/index.html<br /> <br /> First app demo http://developer.android.com/training/basics/firstapp/running-app.html<br /> <br /> App lifecycle http://developer.android.com/guide/components/activities.html<br /> <br /> http://developer.android.com/images/activity_lifecycle.png<br /> <br /> ==Resources==<br /> <br /> No DPI or PPI Andoid uses dp density independent pixels or sp scale interdependent pixels http://developer.android.com/guide/topics/resources/more-resources.html#Dimension<br /> <br /> also see supporting multiple screens http://developer.android.com/guide/practices/screens_support.html<br /> <br /> ==Activities==<br /> <br /> Activity life cycle http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle<br /> <br /> Get an instance of an object from the R class<br /> <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;/** Called when the activity is first created. */<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main);<br /> <br /> //Get the Button and the TextView from the Resource class<br /> Button btn = (Button)this.findViewById(R.id.button1); //needs import android.widget.Button;<br /> <br /> //Final in java can only be initialized once this is necessary to for use in inner method<br /> final TextView tv = (TextView)this.findViewById(R.id.textView1); //needs import android.widget.TextView;<br /> String s = &quot;hello&quot;;<br /> tv.setText(s);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> notice the cast to the type also notice that the TextView is marked as [http://en.wikipedia.org/wiki/Final_%28Java%29 final] <br /> this is so that we can use it in an inner method<br /> <br /> handle a click event <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> btn.setOnClickListener(new View.OnClickListener() {<br /> <br /> @Override<br /> public void onClick(View v) {<br /> // TODO Auto-generated method stub<br /> tv.setText(d.About());<br /> }<br /> });&lt;/syntaxhighlight&gt;<br /> <br /> We can also do this without the inner method by declaring a click method in the class<br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> public void buttonPressMe_OnCLick(View v)<br /> {<br /> TextView tv = (TextView)this.findViewById(R.id.textView2);<br /> tv.setText(&quot;Hello From Button!!&quot;);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> Then we can set the click handler in the layout xml in out case acivity_main.xml<br /> &lt;syntaxhighlight lang=&quot;xml&quot;&gt;<br /> &lt;Button<br /> android:text=&quot;Press Me&quot;<br /> android:layout_width=&quot;wrap_content&quot;<br /> android:layout_height=&quot;wrap_content&quot;<br /> android:layout_below=&quot;@+id/textView&quot;<br /> android:layout_alignParentLeft=&quot;true&quot;<br /> android:layout_alignParentStart=&quot;true&quot;<br /> android:layout_marginLeft=&quot;13dp&quot;<br /> android:layout_marginStart=&quot;13dp&quot;<br /> android:layout_marginTop=&quot;24dp&quot;<br /> android:id=&quot;@+id/buttonPressMe&quot;<br /> android:onClick=&quot;buttonPressMe_OnCLick (MainActivity)&quot; /&gt;<br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==Events==<br /> <br /> Lots more good reading http://developer.android.com/guide/topics/fundamentals.html<br /> <br /> <br /> ==AVD==<br /> <br /> ==Dog Class in java==<br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> public class Dog {<br /> public String Name; //Java uses capital S String<br /> public int Weight;<br /> public String BarkSound;<br /> <br /> //Constructor<br /> public Dog()<br /> {<br /> this.Name = &quot;fido&quot;;<br /> this.Weight = 1;<br /> this.BarkSound = &quot;woof&quot;;<br /> }<br /> <br /> public void Eat()<br /> {<br /> this.Weight++;<br /> }<br /> public void Poop()<br /> {<br /> this.Weight--;<br /> }<br /> <br /> public String About()<br /> {<br /> //Java string.format is similar to c# but used %s for string substitution<br /> return String.format(&quot;Hello my name is %s. I weigh %s lbs&quot;,<br /> this.Name, this.Weight);<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> =In Class Demo=<br /> *Get and install Android Studio this demo uses 2.2 https://developer.android.com/sdk/installing/studio.html<br /> *Start Android Studio<br /> *Select Configure<br /> [[File:AndroidStudioConfigure.png]]<br /> *Select Android SDK Manager<br /> [[File:AndroidStudioSDKManager.png]]<br /> *Make sure you have a current SDK for this Demo we will use 24<br /> [[File:AndroidSDKManagerCurrentVersion.PNG|Alt]]<br /> *Go back to the main menu and select New Project<br /> [[File:AndroidStudioNewProject.PNG|Alt]]<br /> *Name the Project OOPDog and select Next<br /> [[File:AnroidStudioConfigureNewProject.PNG|Alt]]<br /> *Select a Minimum SDK for this demo we will use API15 : IceCreamSandwich<br /> [[File:AnroidStudioConfigureNewProjectSDK.PNG|Alt]]<br /> *Select Blank Activity for the Project template<br /> [[File:AndroidStudioBlankActivity.PNG|Alt]]<br /> *The defaults are fine for the activity name select next<br /> [[File:AnroidStudioNewProjectAcvtivity.PNG|Alt]]<br /> <br /> *After a minute or so you can open the Project window if it isn't already open Att-1 or View/Tool Windows/Project <br /> [[File:AndroidStudioShowOpenMyActivity.png|Alt]]<br /> *Add Dog class <br /> [[File:AndroidStudioNewClass.png|Alt]]<br /> *Name the class Dog <br /> [[File:AndroidStudioNewClassName.PNG|Alt]]<br /> <br /> *Here is the c# dog class we have been using we need to change it a bit <br /> [[Android Studio CSharpDog Code]]<br /> <br /> [[File:AndroidStudioCSharpDog.PNG|Alt]]<br /> <br /> *In Java [[Android Studio JavaDog]]<br /> [[File:AndroidStudioJavaDog.PNG|Alt]]</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=File:AndroidSDKManagerCurrentVersion.PNG&diff=22820 File:AndroidSDKManagerCurrentVersion.PNG 2016-11-08T19:39:34Z <p>Jeff: Jeff uploaded a new version of File:AndroidSDKManagerCurrentVersion.PNG</p> <hr /> <div></div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=File:AndroidStudioConfigure.png&diff=22819 File:AndroidStudioConfigure.png 2016-11-08T19:36:39Z <p>Jeff: Jeff uploaded a new version of File:AndroidStudioConfigure.png</p> <hr /> <div></div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Basic_Android&diff=22818 Basic Android 2016-11-08T03:47:18Z <p>Jeff: /* Activities */</p> <hr /> <div>[[Category:Tech]]<br /> [[Category:Tutorial]]<br /> [[Category:Video Tutorial]]<br /> <br /> =Android Basics=<br /> <br /> <br /> *Install 32 or 64 bit Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html<br /> <br /> *App Inventor Pretty basic web interface an blocks editor to build simple android apps http://appinventor.mit.edu/about/ <br /> **Setup App Inventor http://appinventor.mit.edu/<br /> <br /> *Android SDK<br /> **http://developer.android.com/sdk/index.html<br /> **Download Android Studio<br /> **For SDK path we will use c:\user\Android<br /> <br /> *Android NDK<br /> **we're not covering this http://developer.android.com/sdk/ndk/index.html<br /> <br /> ==Basics==<br /> <br /> <br /> *src folder containing all the source<br /> *res folder containing all the resources<br /> <br /> folder hierarchy explained http://developer.android.com/tools/projects/index.html<br /> <br /> First app demo http://developer.android.com/training/basics/firstapp/running-app.html<br /> <br /> App lifecycle http://developer.android.com/guide/components/activities.html<br /> <br /> http://developer.android.com/images/activity_lifecycle.png<br /> <br /> ==Resources==<br /> <br /> No DPI or PPI Andoid uses dp density independent pixels or sp scale interdependent pixels http://developer.android.com/guide/topics/resources/more-resources.html#Dimension<br /> <br /> also see supporting multiple screens http://developer.android.com/guide/practices/screens_support.html<br /> <br /> ==Activities==<br /> <br /> Activity life cycle http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle<br /> <br /> Get an instance of an object from the R class<br /> <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;/** Called when the activity is first created. */<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main);<br /> <br /> //Get the Button and the TextView from the Resource class<br /> Button btn = (Button)this.findViewById(R.id.button1); //needs import android.widget.Button;<br /> <br /> //Final in java can only be initialized once this is necessary to for use in inner method<br /> final TextView tv = (TextView)this.findViewById(R.id.textView1); //needs import android.widget.TextView;<br /> String s = &quot;hello&quot;;<br /> tv.setText(s);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> notice the cast to the type also notice that the TextView is marked as [http://en.wikipedia.org/wiki/Final_%28Java%29 final] <br /> this is so that we can use it in an inner method<br /> <br /> handle a click event <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> btn.setOnClickListener(new View.OnClickListener() {<br /> <br /> @Override<br /> public void onClick(View v) {<br /> // TODO Auto-generated method stub<br /> tv.setText(d.About());<br /> }<br /> });&lt;/syntaxhighlight&gt;<br /> <br /> We can also do this without the inner method by declaring a click method in the class<br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> public void buttonPressMe_OnCLick(View v)<br /> {<br /> TextView tv = (TextView)this.findViewById(R.id.textView2);<br /> tv.setText(&quot;Hello From Button!!&quot;);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> Then we can set the click handler in the layout xml in out case acivity_main.xml<br /> &lt;syntaxhighlight lang=&quot;xml&quot;&gt;<br /> &lt;Button<br /> android:text=&quot;Press Me&quot;<br /> android:layout_width=&quot;wrap_content&quot;<br /> android:layout_height=&quot;wrap_content&quot;<br /> android:layout_below=&quot;@+id/textView&quot;<br /> android:layout_alignParentLeft=&quot;true&quot;<br /> android:layout_alignParentStart=&quot;true&quot;<br /> android:layout_marginLeft=&quot;13dp&quot;<br /> android:layout_marginStart=&quot;13dp&quot;<br /> android:layout_marginTop=&quot;24dp&quot;<br /> android:id=&quot;@+id/buttonPressMe&quot;<br /> android:onClick=&quot;buttonPressMe_OnCLick (MainActivity)&quot; /&gt;<br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==Events==<br /> <br /> Lots more good reading http://developer.android.com/guide/topics/fundamentals.html<br /> <br /> <br /> ==AVD==<br /> <br /> ==Dog Class in java==<br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> public class Dog {<br /> public String Name; //Java uses capital S String<br /> public int Weight;<br /> public String BarkSound;<br /> <br /> //Constructor<br /> public Dog()<br /> {<br /> this.Name = &quot;fido&quot;;<br /> this.Weight = 1;<br /> this.BarkSound = &quot;woof&quot;;<br /> }<br /> <br /> public void Eat()<br /> {<br /> this.Weight++;<br /> }<br /> public void Poop()<br /> {<br /> this.Weight--;<br /> }<br /> <br /> public String About()<br /> {<br /> //Java string.format is similar to c# but used %s for string substitution<br /> return String.format(&quot;Hello my name is %s. I weigh %s lbs&quot;,<br /> this.Name, this.Weight);<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> =In Class Demo=<br /> *Get and install Android Studio this demo uses .086 https://developer.android.com/sdk/installing/studio.html<br /> *Start Android Studio<br /> *Select Configure<br /> [[File:AndroidStudioConfigure.png]]<br /> *Select Android SDK Manager<br /> [[File:AndroidStudioSDKManager.png]]<br /> *Make sure you have a current SDK for this Demo we will use 23.05 <br /> [[File:AndroidSDKManagerCurrentVersion.PNG|Alt]]<br /> *Go back to the main menu and select New Project<br /> [[File:AndroidStudioNewProject.PNG|Alt]]<br /> *Name the Project OOPDog and select Next<br /> [[File:AnroidStudioConfigureNewProject.PNG|Alt]]<br /> *Select a Minimum SDK for this demo we will use API15 : IceCreamSandwich<br /> [[File:AnroidStudioConfigureNewProjectSDK.PNG|Alt]]<br /> *Select Blank Activity for the Project template<br /> [[File:AndroidStudioBlankActivity.PNG|Alt]]<br /> *The defaults are fine for the activity name select next<br /> [[File:AnroidStudioNewProjectAcvtivity.PNG|Alt]]<br /> <br /> *After a minute or so you can open the Project window if it isn't already open Att-1 or View/Tool Windows/Project <br /> [[File:AndroidStudioShowOpenMyActivity.png|Alt]]<br /> *Add Dog class <br /> [[File:AndroidStudioNewClass.png|Alt]]<br /> *Name the class Dog <br /> [[File:AndroidStudioNewClassName.PNG|Alt]]<br /> <br /> *Here is the c# dog class we have been using we need to change it a bit <br /> [[Android Studio CSharpDog Code]]<br /> <br /> [[File:AndroidStudioCSharpDog.PNG|Alt]]<br /> <br /> *In Java [[Android Studio JavaDog]]<br /> [[File:AndroidStudioJavaDog.PNG|Alt]]</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Basic_Android&diff=22817 Basic Android 2016-11-08T03:46:49Z <p>Jeff: /* Activities */</p> <hr /> <div>[[Category:Tech]]<br /> [[Category:Tutorial]]<br /> [[Category:Video Tutorial]]<br /> <br /> =Android Basics=<br /> <br /> <br /> *Install 32 or 64 bit Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html<br /> <br /> *App Inventor Pretty basic web interface an blocks editor to build simple android apps http://appinventor.mit.edu/about/ <br /> **Setup App Inventor http://appinventor.mit.edu/<br /> <br /> *Android SDK<br /> **http://developer.android.com/sdk/index.html<br /> **Download Android Studio<br /> **For SDK path we will use c:\user\Android<br /> <br /> *Android NDK<br /> **we're not covering this http://developer.android.com/sdk/ndk/index.html<br /> <br /> ==Basics==<br /> <br /> <br /> *src folder containing all the source<br /> *res folder containing all the resources<br /> <br /> folder hierarchy explained http://developer.android.com/tools/projects/index.html<br /> <br /> First app demo http://developer.android.com/training/basics/firstapp/running-app.html<br /> <br /> App lifecycle http://developer.android.com/guide/components/activities.html<br /> <br /> http://developer.android.com/images/activity_lifecycle.png<br /> <br /> ==Resources==<br /> <br /> No DPI or PPI Andoid uses dp density independent pixels or sp scale interdependent pixels http://developer.android.com/guide/topics/resources/more-resources.html#Dimension<br /> <br /> also see supporting multiple screens http://developer.android.com/guide/practices/screens_support.html<br /> <br /> ==Activities==<br /> <br /> Activity life cycle http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle<br /> <br /> Get an instance of an object from the R class<br /> <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;/** Called when the activity is first created. */<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main);<br /> <br /> //Get the Button and the TextView from the Resource class<br /> Button btn = (Button)this.findViewById(R.id.button1); //needs import android.widget.Button;<br /> <br /> //Final in java can only be initialized once this is necessary to for use in inner method<br /> final TextView tv = (TextView)this.findViewById(R.id.textView1); //needs import android.widget.TextView;<br /> String s = &quot;hello&quot;;<br /> tv.setText(s);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> notice the cast to the type also notice that the TextView is marked as [http://en.wikipedia.org/wiki/Final_%28Java%29 final] <br /> this is so that we can use it in an inner method<br /> <br /> handle a click event <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> btn.setOnClickListener(new View.OnClickListener() {<br /> <br /> @Override<br /> public void onClick(View v) {<br /> // TODO Auto-generated method stub<br /> tv.setText(d.About());<br /> }<br /> });&lt;/syntaxhighlight&gt;<br /> <br /> We can also do this without the inner method by declaring a click method in the class<br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> public void buttonPressMe_OnCLick(View v)<br /> {<br /> TextView tv = (TextView)this.findViewById(R.id.textView2);<br /> tv.setText(&quot;Hello From Button!!&quot;);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> Then we can set the click handler in the layout xml in out case acivity_main.xml<br /> &lt;syntaxhighlight lang=&quot;xml&quot;&gt;<br /> &amp;lt;Button<br /> android:text=&quot;Press Me&quot;<br /> android:layout_width=&quot;wrap_content&quot;<br /> android:layout_height=&quot;wrap_content&quot;<br /> android:layout_below=&quot;@+id/textView&quot;<br /> android:layout_alignParentLeft=&quot;true&quot;<br /> android:layout_alignParentStart=&quot;true&quot;<br /> android:layout_marginLeft=&quot;13dp&quot;<br /> android:layout_marginStart=&quot;13dp&quot;<br /> android:layout_marginTop=&quot;24dp&quot;<br /> android:id=&quot;@+id/buttonPressMe&quot;<br /> android:onClick=&quot;buttonPressMe_OnCLick (MainActivity)&quot; /&amp;gt;<br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==Events==<br /> <br /> Lots more good reading http://developer.android.com/guide/topics/fundamentals.html<br /> <br /> <br /> ==AVD==<br /> <br /> ==Dog Class in java==<br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> public class Dog {<br /> public String Name; //Java uses capital S String<br /> public int Weight;<br /> public String BarkSound;<br /> <br /> //Constructor<br /> public Dog()<br /> {<br /> this.Name = &quot;fido&quot;;<br /> this.Weight = 1;<br /> this.BarkSound = &quot;woof&quot;;<br /> }<br /> <br /> public void Eat()<br /> {<br /> this.Weight++;<br /> }<br /> public void Poop()<br /> {<br /> this.Weight--;<br /> }<br /> <br /> public String About()<br /> {<br /> //Java string.format is similar to c# but used %s for string substitution<br /> return String.format(&quot;Hello my name is %s. I weigh %s lbs&quot;,<br /> this.Name, this.Weight);<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> =In Class Demo=<br /> *Get and install Android Studio this demo uses .086 https://developer.android.com/sdk/installing/studio.html<br /> *Start Android Studio<br /> *Select Configure<br /> [[File:AndroidStudioConfigure.png]]<br /> *Select Android SDK Manager<br /> [[File:AndroidStudioSDKManager.png]]<br /> *Make sure you have a current SDK for this Demo we will use 23.05 <br /> [[File:AndroidSDKManagerCurrentVersion.PNG|Alt]]<br /> *Go back to the main menu and select New Project<br /> [[File:AndroidStudioNewProject.PNG|Alt]]<br /> *Name the Project OOPDog and select Next<br /> [[File:AnroidStudioConfigureNewProject.PNG|Alt]]<br /> *Select a Minimum SDK for this demo we will use API15 : IceCreamSandwich<br /> [[File:AnroidStudioConfigureNewProjectSDK.PNG|Alt]]<br /> *Select Blank Activity for the Project template<br /> [[File:AndroidStudioBlankActivity.PNG|Alt]]<br /> *The defaults are fine for the activity name select next<br /> [[File:AnroidStudioNewProjectAcvtivity.PNG|Alt]]<br /> <br /> *After a minute or so you can open the Project window if it isn't already open Att-1 or View/Tool Windows/Project <br /> [[File:AndroidStudioShowOpenMyActivity.png|Alt]]<br /> *Add Dog class <br /> [[File:AndroidStudioNewClass.png|Alt]]<br /> *Name the class Dog <br /> [[File:AndroidStudioNewClassName.PNG|Alt]]<br /> <br /> *Here is the c# dog class we have been using we need to change it a bit <br /> [[Android Studio CSharpDog Code]]<br /> <br /> [[File:AndroidStudioCSharpDog.PNG|Alt]]<br /> <br /> *In Java [[Android Studio JavaDog]]<br /> [[File:AndroidStudioJavaDog.PNG|Alt]]</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Basic_Android&diff=22816 Basic Android 2016-11-08T03:41:08Z <p>Jeff: /* Activities */</p> <hr /> <div>[[Category:Tech]]<br /> [[Category:Tutorial]]<br /> [[Category:Video Tutorial]]<br /> <br /> =Android Basics=<br /> <br /> <br /> *Install 32 or 64 bit Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html<br /> <br /> *App Inventor Pretty basic web interface an blocks editor to build simple android apps http://appinventor.mit.edu/about/ <br /> **Setup App Inventor http://appinventor.mit.edu/<br /> <br /> *Android SDK<br /> **http://developer.android.com/sdk/index.html<br /> **Download Android Studio<br /> **For SDK path we will use c:\user\Android<br /> <br /> *Android NDK<br /> **we're not covering this http://developer.android.com/sdk/ndk/index.html<br /> <br /> ==Basics==<br /> <br /> <br /> *src folder containing all the source<br /> *res folder containing all the resources<br /> <br /> folder hierarchy explained http://developer.android.com/tools/projects/index.html<br /> <br /> First app demo http://developer.android.com/training/basics/firstapp/running-app.html<br /> <br /> App lifecycle http://developer.android.com/guide/components/activities.html<br /> <br /> http://developer.android.com/images/activity_lifecycle.png<br /> <br /> ==Resources==<br /> <br /> No DPI or PPI Andoid uses dp density independent pixels or sp scale interdependent pixels http://developer.android.com/guide/topics/resources/more-resources.html#Dimension<br /> <br /> also see supporting multiple screens http://developer.android.com/guide/practices/screens_support.html<br /> <br /> ==Activities==<br /> <br /> Activity life cycle http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle<br /> <br /> Get an instance of an object from the R class<br /> <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;/** Called when the activity is first created. */<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main);<br /> <br /> //Get the Button and the TextView from the Resource class<br /> Button btn = (Button)this.findViewById(R.id.button1); //needs import android.widget.Button;<br /> <br /> //Final in java can only be initialized once this is necessary to for use in inner method<br /> final TextView tv = (TextView)this.findViewById(R.id.textView1); //needs import android.widget.TextView;<br /> String s = &quot;hello&quot;;<br /> tv.setText(s);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> notice the cast to the type also notice that the TextView is marked as [http://en.wikipedia.org/wiki/Final_%28Java%29 final] <br /> this is so that we can use it in an inner method<br /> <br /> handle a click event <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> btn.setOnClickListener(new View.OnClickListener() {<br /> <br /> @Override<br /> public void onClick(View v) {<br /> // TODO Auto-generated method stub<br /> tv.setText(d.About());<br /> }<br /> });&lt;/syntaxhighlight&gt;<br /> <br /> ==Events==<br /> <br /> Lots more good reading http://developer.android.com/guide/topics/fundamentals.html<br /> <br /> <br /> ==AVD==<br /> <br /> ==Dog Class in java==<br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> public class Dog {<br /> public String Name; //Java uses capital S String<br /> public int Weight;<br /> public String BarkSound;<br /> <br /> //Constructor<br /> public Dog()<br /> {<br /> this.Name = &quot;fido&quot;;<br /> this.Weight = 1;<br /> this.BarkSound = &quot;woof&quot;;<br /> }<br /> <br /> public void Eat()<br /> {<br /> this.Weight++;<br /> }<br /> public void Poop()<br /> {<br /> this.Weight--;<br /> }<br /> <br /> public String About()<br /> {<br /> //Java string.format is similar to c# but used %s for string substitution<br /> return String.format(&quot;Hello my name is %s. I weigh %s lbs&quot;,<br /> this.Name, this.Weight);<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> =In Class Demo=<br /> *Get and install Android Studio this demo uses .086 https://developer.android.com/sdk/installing/studio.html<br /> *Start Android Studio<br /> *Select Configure<br /> [[File:AndroidStudioConfigure.png]]<br /> *Select Android SDK Manager<br /> [[File:AndroidStudioSDKManager.png]]<br /> *Make sure you have a current SDK for this Demo we will use 23.05 <br /> [[File:AndroidSDKManagerCurrentVersion.PNG|Alt]]<br /> *Go back to the main menu and select New Project<br /> [[File:AndroidStudioNewProject.PNG|Alt]]<br /> *Name the Project OOPDog and select Next<br /> [[File:AnroidStudioConfigureNewProject.PNG|Alt]]<br /> *Select a Minimum SDK for this demo we will use API15 : IceCreamSandwich<br /> [[File:AnroidStudioConfigureNewProjectSDK.PNG|Alt]]<br /> *Select Blank Activity for the Project template<br /> [[File:AndroidStudioBlankActivity.PNG|Alt]]<br /> *The defaults are fine for the activity name select next<br /> [[File:AnroidStudioNewProjectAcvtivity.PNG|Alt]]<br /> <br /> *After a minute or so you can open the Project window if it isn't already open Att-1 or View/Tool Windows/Project <br /> [[File:AndroidStudioShowOpenMyActivity.png|Alt]]<br /> *Add Dog class <br /> [[File:AndroidStudioNewClass.png|Alt]]<br /> *Name the class Dog <br /> [[File:AndroidStudioNewClassName.PNG|Alt]]<br /> <br /> *Here is the c# dog class we have been using we need to change it a bit <br /> [[Android Studio CSharpDog Code]]<br /> <br /> [[File:AndroidStudioCSharpDog.PNG|Alt]]<br /> <br /> *In Java [[Android Studio JavaDog]]<br /> [[File:AndroidStudioJavaDog.PNG|Alt]]</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Basic_Android&diff=22815 Basic Android 2016-11-08T03:38:08Z <p>Jeff: /* Dog Class in java */</p> <hr /> <div>[[Category:Tech]]<br /> [[Category:Tutorial]]<br /> [[Category:Video Tutorial]]<br /> <br /> =Android Basics=<br /> <br /> <br /> *Install 32 or 64 bit Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html<br /> <br /> *App Inventor Pretty basic web interface an blocks editor to build simple android apps http://appinventor.mit.edu/about/ <br /> **Setup App Inventor http://appinventor.mit.edu/<br /> <br /> *Android SDK<br /> **http://developer.android.com/sdk/index.html<br /> **Download Android Studio<br /> **For SDK path we will use c:\user\Android<br /> <br /> *Android NDK<br /> **we're not covering this http://developer.android.com/sdk/ndk/index.html<br /> <br /> ==Basics==<br /> <br /> <br /> *src folder containing all the source<br /> *res folder containing all the resources<br /> <br /> folder hierarchy explained http://developer.android.com/tools/projects/index.html<br /> <br /> First app demo http://developer.android.com/training/basics/firstapp/running-app.html<br /> <br /> App lifecycle http://developer.android.com/guide/components/activities.html<br /> <br /> http://developer.android.com/images/activity_lifecycle.png<br /> <br /> ==Resources==<br /> <br /> No DPI or PPI Andoid uses dp density independent pixels or sp scale interdependent pixels http://developer.android.com/guide/topics/resources/more-resources.html#Dimension<br /> <br /> also see supporting multiple screens http://developer.android.com/guide/practices/screens_support.html<br /> <br /> ==Activities==<br /> <br /> Activity life cycle http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle<br /> <br /> Get an instance of an object from the R class<br /> <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;/** Called when the activity is first created. */<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main);<br /> <br /> //Get the Button and the TextView from the Resource class<br /> Button btn = (Button)this.findViewById(R.id.button1);<br /> final TextView tv = (TextView)this.findViewById(R.id.textView1); <br /> String s = &quot;hello&quot;;<br /> tv.setText(s);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> notice the cast to the type also notice that the TextView is marked as [http://en.wikipedia.org/wiki/Final_%28Java%29 final] <br /> this is so that we can use it in an inner method<br /> <br /> handle a click event <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> btn.setOnClickListener(new View.OnClickListener() {<br /> <br /> @Override<br /> public void onClick(View v) {<br /> // TODO Auto-generated method stub<br /> tv.setText(d.About());<br /> }<br /> });&lt;/syntaxhighlight&gt;<br /> <br /> ==Events==<br /> <br /> Lots more good reading http://developer.android.com/guide/topics/fundamentals.html<br /> <br /> <br /> ==AVD==<br /> <br /> ==Dog Class in java==<br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> public class Dog {<br /> public String Name; //Java uses capital S String<br /> public int Weight;<br /> public String BarkSound;<br /> <br /> //Constructor<br /> public Dog()<br /> {<br /> this.Name = &quot;fido&quot;;<br /> this.Weight = 1;<br /> this.BarkSound = &quot;woof&quot;;<br /> }<br /> <br /> public void Eat()<br /> {<br /> this.Weight++;<br /> }<br /> public void Poop()<br /> {<br /> this.Weight--;<br /> }<br /> <br /> public String About()<br /> {<br /> //Java string.format is similar to c# but used %s for string substitution<br /> return String.format(&quot;Hello my name is %s. I weigh %s lbs&quot;,<br /> this.Name, this.Weight);<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> =In Class Demo=<br /> *Get and install Android Studio this demo uses .086 https://developer.android.com/sdk/installing/studio.html<br /> *Start Android Studio<br /> *Select Configure<br /> [[File:AndroidStudioConfigure.png]]<br /> *Select Android SDK Manager<br /> [[File:AndroidStudioSDKManager.png]]<br /> *Make sure you have a current SDK for this Demo we will use 23.05 <br /> [[File:AndroidSDKManagerCurrentVersion.PNG|Alt]]<br /> *Go back to the main menu and select New Project<br /> [[File:AndroidStudioNewProject.PNG|Alt]]<br /> *Name the Project OOPDog and select Next<br /> [[File:AnroidStudioConfigureNewProject.PNG|Alt]]<br /> *Select a Minimum SDK for this demo we will use API15 : IceCreamSandwich<br /> [[File:AnroidStudioConfigureNewProjectSDK.PNG|Alt]]<br /> *Select Blank Activity for the Project template<br /> [[File:AndroidStudioBlankActivity.PNG|Alt]]<br /> *The defaults are fine for the activity name select next<br /> [[File:AnroidStudioNewProjectAcvtivity.PNG|Alt]]<br /> <br /> *After a minute or so you can open the Project window if it isn't already open Att-1 or View/Tool Windows/Project <br /> [[File:AndroidStudioShowOpenMyActivity.png|Alt]]<br /> *Add Dog class <br /> [[File:AndroidStudioNewClass.png|Alt]]<br /> *Name the class Dog <br /> [[File:AndroidStudioNewClassName.PNG|Alt]]<br /> <br /> *Here is the c# dog class we have been using we need to change it a bit <br /> [[Android Studio CSharpDog Code]]<br /> <br /> [[File:AndroidStudioCSharpDog.PNG|Alt]]<br /> <br /> *In Java [[Android Studio JavaDog]]<br /> [[File:AndroidStudioJavaDog.PNG|Alt]]</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Basic_Android&diff=22814 Basic Android 2016-11-08T03:30:53Z <p>Jeff: /* Basics */</p> <hr /> <div>[[Category:Tech]]<br /> [[Category:Tutorial]]<br /> [[Category:Video Tutorial]]<br /> <br /> =Android Basics=<br /> <br /> <br /> *Install 32 or 64 bit Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html<br /> <br /> *App Inventor Pretty basic web interface an blocks editor to build simple android apps http://appinventor.mit.edu/about/ <br /> **Setup App Inventor http://appinventor.mit.edu/<br /> <br /> *Android SDK<br /> **http://developer.android.com/sdk/index.html<br /> **Download Android Studio<br /> **For SDK path we will use c:\user\Android<br /> <br /> *Android NDK<br /> **we're not covering this http://developer.android.com/sdk/ndk/index.html<br /> <br /> ==Basics==<br /> <br /> <br /> *src folder containing all the source<br /> *res folder containing all the resources<br /> <br /> folder hierarchy explained http://developer.android.com/tools/projects/index.html<br /> <br /> First app demo http://developer.android.com/training/basics/firstapp/running-app.html<br /> <br /> App lifecycle http://developer.android.com/guide/components/activities.html<br /> <br /> http://developer.android.com/images/activity_lifecycle.png<br /> <br /> ==Resources==<br /> <br /> No DPI or PPI Andoid uses dp density independent pixels or sp scale interdependent pixels http://developer.android.com/guide/topics/resources/more-resources.html#Dimension<br /> <br /> also see supporting multiple screens http://developer.android.com/guide/practices/screens_support.html<br /> <br /> ==Activities==<br /> <br /> Activity life cycle http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle<br /> <br /> Get an instance of an object from the R class<br /> <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;/** Called when the activity is first created. */<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.main);<br /> <br /> //Get the Button and the TextView from the Resource class<br /> Button btn = (Button)this.findViewById(R.id.button1);<br /> final TextView tv = (TextView)this.findViewById(R.id.textView1); <br /> String s = &quot;hello&quot;;<br /> tv.setText(s);<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> notice the cast to the type also notice that the TextView is marked as [http://en.wikipedia.org/wiki/Final_%28Java%29 final] <br /> this is so that we can use it in an inner method<br /> <br /> handle a click event <br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> btn.setOnClickListener(new View.OnClickListener() {<br /> <br /> @Override<br /> public void onClick(View v) {<br /> // TODO Auto-generated method stub<br /> tv.setText(d.About());<br /> }<br /> });&lt;/syntaxhighlight&gt;<br /> <br /> ==Events==<br /> <br /> Lots more good reading http://developer.android.com/guide/topics/fundamentals.html<br /> <br /> <br /> ==AVD==<br /> <br /> ==Dog Class in java==<br /> &lt;syntaxhighlight lang=&quot;java&quot;&gt;<br /> public class Dog {<br /> <br /> public String Name;<br /> public int Weight;<br /> public String BarkSound;<br /> <br /> //Constructor<br /> public Dog()<br /> {<br /> this.Name = &quot;fido&quot;;<br /> this.Weight = 1;<br /> this.BarkSound = &quot;woof&quot;;<br /> }<br /> <br /> public void Eat()<br /> {<br /> this.Weight++;<br /> }<br /> public void Poop()<br /> {<br /> this.Weight--;<br /> }<br /> <br /> public String About()<br /> {<br /> return String.format(&quot;Hello my name is %s. I weigh %s lbs&quot;, <br /> this.Name, this.Weight);<br /> }<br /> <br /> <br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> =In Class Demo=<br /> *Get and install Android Studio this demo uses .086 https://developer.android.com/sdk/installing/studio.html<br /> *Start Android Studio<br /> *Select Configure<br /> [[File:AndroidStudioConfigure.png]]<br /> *Select Android SDK Manager<br /> [[File:AndroidStudioSDKManager.png]]<br /> *Make sure you have a current SDK for this Demo we will use 23.05 <br /> [[File:AndroidSDKManagerCurrentVersion.PNG|Alt]]<br /> *Go back to the main menu and select New Project<br /> [[File:AndroidStudioNewProject.PNG|Alt]]<br /> *Name the Project OOPDog and select Next<br /> [[File:AnroidStudioConfigureNewProject.PNG|Alt]]<br /> *Select a Minimum SDK for this demo we will use API15 : IceCreamSandwich<br /> [[File:AnroidStudioConfigureNewProjectSDK.PNG|Alt]]<br /> *Select Blank Activity for the Project template<br /> [[File:AndroidStudioBlankActivity.PNG|Alt]]<br /> *The defaults are fine for the activity name select next<br /> [[File:AnroidStudioNewProjectAcvtivity.PNG|Alt]]<br /> <br /> *After a minute or so you can open the Project window if it isn't already open Att-1 or View/Tool Windows/Project <br /> [[File:AndroidStudioShowOpenMyActivity.png|Alt]]<br /> *Add Dog class <br /> [[File:AndroidStudioNewClass.png|Alt]]<br /> *Name the class Dog <br /> [[File:AndroidStudioNewClassName.PNG|Alt]]<br /> <br /> *Here is the c# dog class we have been using we need to change it a bit <br /> [[Android Studio CSharpDog Code]]<br /> <br /> [[File:AndroidStudioCSharpDog.PNG|Alt]]<br /> <br /> *In Java [[Android Studio JavaDog]]<br /> [[File:AndroidStudioJavaDog.PNG|Alt]]</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=File:Download.jpg&diff=22813 File:Download.jpg 2016-10-25T14:37:01Z <p>Jeff: </p> <hr /> <div></div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming&diff=22812 Game Programming 2016-10-25T14:35:57Z <p>Jeff: </p> <hr /> <div>[[Category:IAM Classes]]<br /> [[Category:XNA Programming]]<br /> __NOTOC__<br /> =Game Programming=<br /> <br /> test<br /> <br /> [[Monogame Overview]]<br /> <br /> ==Stuff==<br /> <br /> Game Programming Syllabus See moodle https://lms.colum.edu<br /> <br /> http://iam.colum.edu/screenz/FA15/<br /> <br /> {{XNA Game Programming Classes}}<br /> <br /> [[XNA Game Programming Classes]]<br /> <br /> Free XNA book<br /> <br /> http://xnagamemaking.com/<br /> http://www.lulu.com/product/download/a-simple-introduction-to-game-programming-with-c%23-and-xna-31/5438606<br /> <br /> ==Links==</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming&diff=22811 Game Programming 2016-10-25T01:58:36Z <p>Jeff: /* Game Programming */</p> <hr /> <div>[[Category:IAM Classes]]<br /> [[Category:XNA Programming]]<br /> __NOTOC__<br /> =Game Programming=<br /> <br /> [[Monogame Overview]]<br /> <br /> ==Stuff==<br /> <br /> Game Programming Syllabus See moodle https://lms.colum.edu<br /> <br /> http://iam.colum.edu/screenz/FA15/<br /> <br /> {{XNA Game Programming Classes}}<br /> <br /> [[XNA Game Programming Classes]]<br /> <br /> Free XNA book<br /> <br /> http://xnagamemaking.com/<br /> http://www.lulu.com/product/download/a-simple-introduction-to-game-programming-with-c%23-and-xna-31/5438606<br /> <br /> ==Links==</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming&diff=22810 Game Programming 2016-10-25T01:56:53Z <p>Jeff: /* Game Programming */</p> <hr /> <div>[[Category:IAM Classes]]<br /> [[Category:XNA Programming]]<br /> __NOTOC__<br /> =Game Programming=<br /> <br /> [[Monogame Overview]]<br /> <br /> test<br /> <br /> ==Stuff==<br /> <br /> Game Programming Syllabus See moodle https://lms.colum.edu<br /> <br /> http://iam.colum.edu/screenz/FA15/<br /> <br /> {{XNA Game Programming Classes}}<br /> <br /> [[XNA Game Programming Classes]]<br /> <br /> Free XNA book<br /> <br /> http://xnagamemaking.com/<br /> http://www.lulu.com/product/download/a-simple-introduction-to-game-programming-with-c%23-and-xna-31/5438606<br /> <br /> ==Links==</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class9&diff=22809 OOP Class9 2016-10-24T16:52:26Z <p>Jeff: /* PolyMorphism */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> <br /> ==PolyMorphism==<br /> <br /> Using the least specific class to increase reuse.<br /> <br /> ==Value vs Reference Types==<br /> <br /> int, float, string and most built in types are value types<br /> <br /> defined classes are Reference types.<br /> <br /> ==Review Coins==<br /> <br /> ?'s<br /> <br /> ==Review MotorVehicle==<br /> <br /> ?'s<br /> <br /> ==Motorvehicle Diagram==<br /> <br /> [[Oop Motorvehicle Diagram]]<br /> <br /> http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class7/MotorvehicleRace<br /> <br /> ==Private instance data members - accessors==<br /> Microsoft has stared calling private variables with accessors Properties<br /> <br /> Private class memebers the use get and set keyword to set and retrieve data. Get and set are known as accessor methods private members are helpful when you want to also do other things when a data member is changed or change the rutern value under certain conditions. C# Programmer's Reference - Accessors http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfaccessorspg.asp. Lastly accessor also make read only and write only variables possible<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;//private string color read/write<br /> private string color;<br /> <br /> public string Color<br /> {<br /> get<br /> {<br /> return color;<br /> }<br /> set<br /> {<br /> color = value;<br /> }<br /> }<br /> <br /> //private string color read only<br /> private string color;<br /> <br /> public string Color<br /> {<br /> get<br /> {<br /> return color;<br /> }<br /> }&lt;/syntaxhighlight&gt;<br /> <br /> <br /> Another property that is a good candidate for a private instance data member is the dogs age<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> private string age;<br /> <br /> public int Age<br /> {<br /> //age can only be accessed with get there is no set accessor<br /> //age must be set with HappyBirthday()<br /> get<br /> {<br /> return age;<br /> }<br /> }<br /> <br /> public int HappyBirthday()<br /> {<br /> age++;<br /> return age;<br /> }<br /> <br /> <br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==Windows forms==<br /> <br /> ===Separation of Concern===<br /> https://en.wikipedia.org/wiki/Separation_of_concerns<br /> <br /> Keep you Moodle Object (logic) classes and your UI Presentation classes separate. This will probably be very different from how you handled login in form in previous classes. We will try to keep all the Model login in the Model classes and UI Logic in the Form class. This will allow us to easily move the Model classes to a different UI like the Web or XAML.<br /> <br /> Events<br /> :events from a windows form or web page are handled by event handlers. Events are raised when a user interacts with interface elements and handled by the event handlers.<br /> <br /> <br /> http://www.csharphelp.com/archives/archive253.html<br /> <br /> ===Examaple of event handlers and classes===<br /> http://iam.colum.edu/oop/MotorvehicleRace.zip<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> private void button1_Click(object sender, EventArgs e)<br /> {<br /> Console.WriteLine(&quot;button1 Clicked&quot;);<br /> MessageBox.Show(&quot;button1 Clicked&quot;); <br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> Create a windows form with a button the uses your class.<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.ComponentModel;<br /> using System.Data;<br /> using System.Drawing;<br /> using System.Text;<br /> using System.Windows.Forms;<br /> <br /> namespace WindowsDog<br /> {<br /> public partial class Form1 : Form<br /> {<br /> Dog fido; //The form 'has a' dog<br /> <br /> public Form1()<br /> {<br /> InitializeComponent();<br /> fido = new Dog();<br /> }<br /> <br /> private void btnBark_Click(object sender, EventArgs e)<br /> {<br /> lblBark.Text = fido.Bark(); //UIEvents are delegated to the model class<br /> }<br /> <br /> <br /> <br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==XAML Example==<br /> <br /> Timer in XAML<br /> https://msdn.microsoft.com/en-us/library/cc189084(v=vs.95).aspx<br /> <br /> <br /> <br /> ==Home Work==<br /> <br /> Create a windows form and port your classes. The form should have UI elements (buttons, dropdown, etc) that demonstrate the use of you classes.<br /> <br /> Get Android Studio Installed<br /> <br /> You wili need<br /> *Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html I'm still using Java 7 Java 8 also should ve fine<br /> *Android Studio http://developer.android.com/sdk/installing/index.html?pkg=studio<br /> <br /> <br /> Watch the Android-Studio-First-Look https://www.lynda.com/Android-tutorials/Welcome/143103/168098-4.html <br /> <br /> You should logon to Oasis http://oasis.colum.edu First then select the training tab. Then search for 'Android-Studio-First-Look'<br /> <br /> *Section 0 Introduction<br /> *Section 1 Getting Started<br /> *Section 2 Exploring the User Interface (fine to watch next week)<br /> *Section 3 Designing and Coding (fine to watch next week)<br /> <br /> <br /> https://www.lynda.com/Android-tutorials/Welcome/143103/168098-4.html</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=File:CatConainmentAssociation.PNG&diff=22808 File:CatConainmentAssociation.PNG 2016-10-12T18:52:57Z <p>Jeff: Jeff uploaded a new version of File:CatConainmentAssociation.PNG</p> <hr /> <div></div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=File:CatConainmentAssociation.PNG&diff=22807 File:CatConainmentAssociation.PNG 2016-10-12T18:52:50Z <p>Jeff: Jeff uploaded a new version of File:CatConainmentAssociation.PNG</p> <hr /> <div></div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class6&diff=22806 OOP Class6 2016-10-12T18:43:00Z <p>Jeff: /* Homework */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> <br /> <br /> ==Review==<br /> ;Accessibility: restrict the visibility of a class and it's members<br /> ;Classes: Abstraction that has properties and methods. properties and the ''nouns'' and methods are the ''verbs''Classes are used to define objects. <br /> ;Objects: Instance of a class<br /> ;Abstraction : Factor out details to work on fewer concepts at a time<br /> ;Encapsulation: Allows us to use objects with out completely understanding how everything inside the object works. Encapsulation also allows the internal state of objects to be changed easily without affecting other objects or interfaces. Real barking dogs...[http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class4/DogBark DogBark] an example of how you don't need to know how all of the classes work just how to use them<br /> ;Polymorphism: many forms that have the same attributes and abilities<br /> ;UML : Unified Modeling Language.<br /> <br /> TODO<br /> ;Virtual Functions: Functions that can be overridden.<br /> ;Static: Members that are associayed with a class not an instance of the class<br /> <br /> ==Shared Members - static members==<br /> aka Shared Properties<br /> <br /> Static - A type of member modifier that indicates that the member applies to the type rather than an instance of the type<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;public class Dog<br /> {<br /> //some code<br /> <br /> static private int dogCount; // total number of dogs<br /> <br /> public Dog()<br /> {<br /> barkSound = &quot;Woof!!!&quot;;<br /> //Add a dog to the total dog count<br /> dogCount++;<br /> }<br /> public Dog(string newName)<br /> {<br /> name = newName;<br /> barkSound = &quot;Woof!!!&quot;;<br /> //Add a dog to the total dog count<br /> dogCount++;<br /> }&lt;/syntaxhighlight&gt;<br /> }<br /> <br /> Static dougCount Example &lt;br /&gt;<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class5/dogStatic.cs dogStatic.cs] - source<br /> <br /> <br /> <br /> <br /> <br /> ==OverLoading==<br /> <br /> You can overload a method to make it more flexible.<br /> <br /> Simple Bark Method<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> <br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog()<br /> {<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> <br /> public string Bark() { <br /> string strBark = this.BarkSound;<br /> barkCount ++;<br /> return strBark;<br /> }<br /> <br /> public void Eat() {<br /> //put eat code here <br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> overloaded method that makes a dog bark more than once.<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> <br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog()<br /> {<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> <br /> public string Bark() { <br /> string strBark = this.BarkSound;<br /> barkCount ++;<br /> return strBark;<br /> }<br /> <br /> public string Bark(int numBarks) { <br /> string strBark = &quot;&quot;;<br /> for(int i =0; i &lt; numBarks; i++) //bark many times<br /> {<br /> strBark += this.BarkSound;<br /> barkCount ++;<br /> }<br /> return strBark;<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> You can overload a method as much as you want as long as each overload has a '''unique argument signature'''<br /> <br /> <br /> ==Overload Constructor==<br /> <br /> Overloading the constructor of you class can make it easier to use.<br /> <br /> here is a simple dog contructor<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> public class Dog<br /> {<br /> <br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog()<br /> {<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> <br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> we can modify this so that we can pass in the sound of the dogs bark when the object is created<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> public class Dog<br /> {<br /> <br /> public string BarkSound; // the sound of the dog's bark<br /> <br /> public Dog(string newBarkSound)<br /> {<br /> this.BarkSound = newBarkSound;<br /> }<br /> <br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> or the name of the dog and the barksound<br /> <br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> public class Dog<br /> {<br /> <br /> public string BarkSound; // the sound of the dog's bark<br /> public string Name;<br /> <br /> public Dog(string newBarkSound, string NewName)<br /> {<br /> this.BarkSound = newBarkSound;<br /> this.Name = newName;<br /> <br /> }<br /> <br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> you can have as many overoads as you want as long as each overload has a unique '''argument signature'''<br /> <br /> &lt;!--<br /> <br /> ==Operator Overloading==<br /> <br /> You can overload operator in c# just like you overload constuctors<br /> <br /> * Operator Overloading In C# - www.csharphelp.com<br /> * Operator Overloading in C# - HowToDoThings.com<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;//Overloading unary operators<br /> public static return_type operator op (Type t)<br /> {<br /> // Statements<br /> }<br /> <br /> //Overloading binary operators<br /> public static ClassType operator + ( object lhs, object rhs )<br /> {<br /> ClassType c<br /> //code to implement class addition<br /> return c;<br /> }&lt;/syntaxhighlight&gt;<br /> <br /> dog addition? extra credit<br /> <br /> How could you overload + operator so that it returns a new dog when two dogs are added together...<br /> <br /> <br /> <br /> <br /> <br /> ===Operator Overloading Fraction Class===<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;public static ClassType operator + ( object lhs, object rhs )<br /> {<br /> ClassType c<br /> //code to implement class addition<br /> return c;<br /> }&lt;/syntaxhighlight&gt;<br /> <br /> Operator also refer to implicit and explicit conversions. Fractions make a good example for opertor overloading.<br /> Fraction class<br /> <br /> * Create fractions from two numbers x/y or from whole numbers<br /> * Convert fractions to whole numbers int<br /> * Convert fractions to float or double<br /> * override ToString() to describe Fraction<br /> <br /> <br /> Fraction Class Example of operator overloading.&lt;br /&gt;<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class5/fractionConv.cs fractionConv.cs] - source&lt;br /&gt;<br /> Fraction class with implicit and explicit conversion&lt;br /&gt;<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class5/fractionConv_NoTest.cs fractionConv_NoTest.cs] - source&lt;br /&gt;<br /> Fraction class with overridden operators&lt;br /&gt;<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class5/fractionConvOver.cs fractionConvOver.cs] - source&lt;br /&gt;<br /> <br /> In class build a test application does thigs with frations.&lt;br /&gt;<br /> Using &lt;br /&gt;<br /> <br /> http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class5/fractionConv_NoTest.cs fractionDone_NoTest.cs] create a test class that...<br /> <br /> * Creates a fraction out of integers (ie cast int into fractions)<br /> * Adds, subtracts, and reduces some fractions<br /> * Creates floting point numbers out of fractions (is cast fraction into double)<br /> * Checks the eqaulity of some fractions<br /> <br /> ==Class Relationships==<br /> Four Class Relation ships<br /> <br /> * Association - 'Uses A'<br /> * Containment - 'Has A'<br /> * Inheritance - 'Is A'<br /> * Interfaces - implements or derives from We'll do this next week in [[OOP Class6]]<br /> <br /> ==Association - 'Uses A'==<br /> <br /> A dog uses a hydrant to relieve them self.<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;//Dog simple class definition<br /> public class Dog<br /> {<br /> //some dog code...<br /> <br /> public void Relieve(Hydrant h)<br /> {<br /> h.Clean = false;<br /> }<br /> } <br /> <br /> public class Hydrant<br /> {<br /> public string Color; //the color of the hydrant<br /> public bool Clean; //if the hydrant is clean or dirty<br /> <br /> public Hydrant()<br /> {<br /> Color = &quot;red&quot;;<br /> Clean = true;<br /> }<br /> <br /> public override string ToString ()<br /> {<br /> if (this.Clean == true)<br /> {<br /> return (&quot;The &quot; + this.Color + &quot; hydrant is clean.&quot;);<br /> }<br /> else<br /> {<br /> return (&quot;The &quot; + this.Color + &quot; hydrant is not clean.&quot;);<br /> }<br /> }<br /> }&lt;/syntaxhighlight&gt;<br /> <br /> Dog Association example<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class5/DogHydrant.cs DogHydrant.cs] - source<br /> <br /> ==Containment - 'Has A'==<br /> A dog has an owner<br /> <br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;Dog fido = new Dog(&quot;fido&quot;);<br /> fido.Owner = new Person(&quot;Sue&quot;);&lt;/syntaxhighlight&gt;<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;//Dog simple class definition<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> public string BarkSound; // the sound of the dog's bark<br /> public Person Owner; // the dogs owner<br /> <br /> public Dog(string dogName)<br /> {<br /> Name = dogName;<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> <br /> public string Bark() { <br /> string s;<br /> s = this.Name + &quot; says &quot; + this.BarkSound;<br /> //Make sure the the dog has an owner<br /> if (!(this.Owner == null))<br /> s += &quot;\n&quot; + Owner.Name + &quot; says be quiet.&quot;;<br /> return s;<br /> }<br /> } <br /> <br /> public class Person<br /> {<br /> public string Name; //the color of the hydrant<br /> <br /> public Person(string newName)<br /> {<br /> Name = newName;<br /> }<br /> }&lt;/syntaxhighlight&gt;<br /> <br /> <br /> Containment example&lt;br&gt;<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class5/DogOwner.cs DogOwner.cs] -source<br /> <br /> <br /> <br /> <br /> and the this keyword<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;//Accessor for private color allow color to be set and return color or 'dirty' + color<br /> public string Color<br /> {<br /> get<br /> {<br /> //if current dog isClean the return dogs color<br /> if (this.isClean == true)<br /> {<br /> return color;<br /> }<br /> //else return 'dirty' and the dogs color<br /> else {<br /> return &quot;dirty &quot; + color;<br /> }<br /> }<br /> set<br /> {<br /> color = value;<br /> }<br /> }&lt;/syntaxhighlight&gt;<br /> <br /> console /infod/jeff/classSource/class4/dogAccessor.cs - source<br /> web /infod/jeff/classSource/class4/dogAccessor.aspx - source<br /> <br /> Dog private members, Overloaded with method class definition<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;//Dog private members, Overloaded with method class definition<br /> public class Dog<br /> {<br /> private string name; // the dog's name<br /> private int age; // the dog's age<br /> private int weight; // the dog's weight<br /> private string barkSound; // the sound of the dog's bark<br /> private int barkCount; // how many times the dog has barked<br /> <br /> public Dog()<br /> {<br /> barkSound = &quot;Woof!!!&quot;;<br /> }<br /> public Dog(string newName)<br /> {<br /> name = newName;<br /> barkSound = &quot;Woof!!!&quot;;<br /> }<br /> public Dog(string newName, string newBarkSound )<br /> {<br /> name = newName;<br /> barkSound = newBarkSound;<br /> }<br /> <br /> public string Name<br /> {<br /> get<br /> {<br /> return name;<br /> }<br /> set<br /> {<br /> name = value;<br /> }<br /> }<br /> public int Age<br /> {<br /> get<br /> {<br /> return age;<br /> }<br /> set<br /> {<br /> age = value;<br /> }<br /> }<br /> public int Weight<br /> {<br /> get<br /> {<br /> return weight;<br /> }<br /> set<br /> {<br /> weight = value;<br /> }<br /> }<br /> public string BarkSound<br /> {<br /> get<br /> {<br /> return barkSound;<br /> }<br /> set<br /> {<br /> barkSound = value;<br /> }<br /> }<br /> public int BarkCount //you can't set bark count<br /> //it only increments from the Bark() method<br /> {<br /> get<br /> {<br /> return barkCount;<br /> }<br /> }<br /> <br /> public string About() <br /> { <br /> //return a string with some information about the dog<br /> string about = &quot;&quot;;<br /> //this refers to current object<br /> about +=(&quot;\nThe dogs name is &quot; + this.name + &quot;.&quot;);<br /> about +=(&quot;\nIt is &quot; + this.age + &quot; years old.&quot;);<br /> about +=(&quot;\nIt weighs &quot; + this.weight + &quot; lb(s).&quot;);<br /> about +=(&quot;\nIts bark sounds like '&quot; + this.barkSound + &quot;'&quot;);<br /> about +=(&quot;\nIt has barked &quot; + this.barkCount + &quot; time(s)&quot; );<br /> about += about.Replace(&quot;\n&quot;,&quot;<br /> &quot;);<br /> return about;<br /> }<br /> <br /> public void Bark() { <br /> //make dog bark<br /> Console.WriteLine (this.Name + &quot; says &quot; + this.barkSound);<br /> //add 1 to the number of times the dog has barked<br /> this.barkCount++ ;<br /> }<br /> public void Eat() {<br /> //put eat code here <br /> }<br /> }&lt;/syntaxhighlight&gt;<br /> <br /> console<br /> <br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class4/dogOverloadMethodScoped.cs dogOverloadMethodScoped.cs]<br /> <br /> ==In class==<br /> <br /> Discuss Dog Diagram<br /> <br /> [[OOP Full Dog Diagram]]<br /> <br /> --&gt;<br /> <br /> <br /> <br /> <br /> <br /> ==Association - 'Uses A'==<br /> <br /> A dog uses a hydrant to relieve them self.<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;//Dog simple class definition<br /> public class Dog<br /> {<br /> //some dog code...<br /> <br /> public void Relieve(Hydrant h)<br /> {<br /> h.Clean = false;<br /> }<br /> } <br /> <br /> public class Hydrant<br /> {<br /> public string Color; //the color of the hydrant<br /> public bool Clean; //if the hydrant is clean or dirty<br /> <br /> public Hydrant()<br /> {<br /> Color = &quot;red&quot;;<br /> Clean = true;<br /> }<br /> <br /> public override string ToString ()<br /> {<br /> if (this.Clean == true)<br /> {<br /> return (&quot;The &quot; + this.Color + &quot; hydrant is clean.&quot;);<br /> }<br /> else<br /> {<br /> return (&quot;The &quot; + this.Color + &quot; hydrant is not clean.&quot;);<br /> }<br /> }<br /> }&lt;/syntaxhighlight&gt;<br /> <br /> Dog Association example<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class5/DogHydrant.cs DogHydrant.cs] - source<br /> <br /> ==Containment - 'Has A'==<br /> A dog has an owner<br /> <br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;Dog fido = new Dog(&quot;fido&quot;);<br /> fido.Owner = new Person(&quot;Sue&quot;);&lt;/syntaxhighlight&gt;<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;//Dog simple class definition<br /> public class Dog<br /> {<br /> public string Name; // the dog's name<br /> public string BarkSound; // the sound of the dog's bark<br /> public Person Owner; // the dogs owner<br /> <br /> public Dog(string dogName)<br /> {<br /> Name = dogName;<br /> BarkSound = &quot;Woof!!!&quot;;<br /> }<br /> <br /> public string Bark() { <br /> string s;<br /> s = this.Name + &quot; says &quot; + this.BarkSound;<br /> //Make sure the the dog has an owner<br /> if (!(this.Owner == null))<br /> s += &quot;\n&quot; + Owner.Name + &quot; says be quiet.&quot;;<br /> return s;<br /> }<br /> } <br /> <br /> public class Person<br /> {<br /> public string Name; //the color of the hydrant<br /> <br /> public Person(string newName)<br /> {<br /> Name = newName;<br /> }<br /> }&lt;/syntaxhighlight&gt;<br /> <br /> <br /> Containment example&lt;br&gt;<br /> [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class5/DogOwner.cs DogOwner.cs] -source<br /> <br /> ==Homework==<br /> <br /> &lt;!--<br /> <br /> use Pair Programming to make tests and classes from the following UML<br /> <br /> [[OOP Students Classes Diagram]]<br /> <br /> If you need to ad any supprting methods or properties that are not on the diagram feel free.<br /> <br /> Create a UML Diagram of your c# classes (not the tv and radio yeah the pong machine and ninja and kungfumonkey and stuff)<br /> --&gt;<br /> <br /> <br /> &lt;!--<br /> Chapter 2 Introduction the UML in The Unified Modeling Language Users Guided (hand out)<br /> <br /> Chapter 4 Classes in The Unified Modeling Language Users Guided (hand out)<br /> --&gt;<br /> <br /> *Create A Cat Containment and Association Project based off of the followong UML<br /> [[Image:CatConainmentAssociation.PNG]]<br /> <br /> The Program should have output similar to <br /> &lt;pre&gt;<br /> Hello I am a CatContainmentAssociation.Cat I'm 10 years old and I weigh 0 My Meo<br /> w sounds like Meow!. punkin doesn't have a toy to play with<br /> Hello I am a CatContainmentAssociation.Cat I'm 10 years old and I weigh 0 My Meo<br /> w sounds like Meow!. punkin plays with SparkleyBall<br /> The Basement LitterBox is clean<br /> The Basement LitterBox is dirty<br /> The Basement LitterBox is clean<br /> &lt;/pre&gt;<br /> <br /> <br /> *Create a fourth class the uses or is used by one of your other classes<br /> **Association<br /> *Create a fifth class the contains or is contained by one of your other classes<br /> **Containment<br /> **Create a UML diagram that show the relationships of your classes post export the diagram as a png (I'll show this in class) post diagram to demo fourth and fifth class</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class4&diff=22805 Game Programming Class4 2016-09-27T02:22:49Z <p>Jeff: /* Sprite class */</p> <hr /> <div><br /> ==Objectives==<br /> *Unified Input Controller Monogame<br /> *Mongame Sprites<br /> *Refactoring classes to common game library<br /> *Separation of Concern where should classes like<br /> ==Skills==<br /> *GameComponents Monogame<br /> *SVN Commit<br /> ==Demo==<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/PacManSprite2Component Monogame\3.5\PacManSprite2Component] : Sprite class <br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/GameComponents Monogame\3.5\GameComponents] : Monogame reusable components that follow game loop<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/FPS Monogame\3.5\FPS] : Game component<br /> <br /> ==Home Work==<br /> *Refactor interesting movement using game component and two players with separate input controls.<br /> <br /> <br /> ==in class==<br /> <br /> Extract sprite from pacman class and build new project<br /> <br /> ===Sprite class===<br /> <br /> [https://github.com/dsp56001/GameProgramming/blob/master/Monogame/3.5/MonoGameLibrary/Sprite2/Sprite2.cs Monogame/3.5/MonoGameLibrary/Sprite2.cs]<br /> [https://github.com/dsp56001/GameProgramming/blob/master/Monogame/3.5/MonoGameLibrary/Sprite2/DrawableSprite2.cs Monogame/3.5/MonoGameLibrary/DrawableSprite2.cs]<br /> <br /> Then the pacman class can inherit from one of these two classes.<br /> <br /> [https://github.com/dsp56001/GameProgramming/blob/master/Monogame/3.5/PacManComponentFromLibrary/PacMan.cs PacMan.cs]<br /> <br /> Due to the desire to limit the number of spritebatches, I've created two classes. The sprite class cannot draw itself without being associated with and external spritebatch.<br /> The DrawableSprite has it's own spritebatch which makes it easier to use but less efficient.<br /> <br /> ==Game Components==<br /> About components [http://msdn.microsoft.com/en-us/library/bb203873.aspx Application Overview]<br /> <br /> Game Components are reusable and easy to add to a game.<br /> <br /> * GameComponent Class<br /> * DrawGameComponent Class<br /> <br /> http://blogs.msdn.com/xna/archive/2006/08/31/734204.aspx<br /> <br /> Common methods<br /> <br /> '''Enabled'''<br /> :Indicates whether GameComponent.Update should be called when Game.Update is called. <br /> <br /> '''UpdateOrder'''<br /> :Indicates the order in which the GameComponent should be updated relative to other GameComponent instances. Lower values are updated first. <br /> <br /> (available if it is a DrawableGameComponent) <br /> <br /> '''Visible'''<br /> :Indicates whether Draw should be called.<br /> <br /> '''DrawOrder'''<br /> :Order in which the component should be drawn, relative to other components that are in the same GameComponentCollection.<br /> <br /> ===Frame Per Second Counter===<br /> &lt;syntaxhighlight lang=&quot;csharp&quot; &gt;<br /> using Microsoft.Xna.Framework;<br /> using Microsoft.Xna.Framework.Graphics;<br /> using Microsoft.Xna.Framework.Input;<br /> using System;<br /> <br /> namespace GameWindowsFPS<br /> {<br /> public class Game1 : Microsoft.Xna.Framework.Game<br /> {<br /> GraphicsDeviceManager graphics;<br /> SpriteBatch spriteBatch;<br /> <br /> float CumulativeFrameTime;<br /> int NumFrames;<br /> int FramesPerSecond;<br /> SpriteFont Font;<br /> <br /> public Game1()<br /> {<br /> graphics = new GraphicsDeviceManager(this);<br /> Content.RootDirectory = &quot;Content&quot;;<br /> <br /> //Set to 30 Frames a Second<br /> //TargetElapsedTime = TimeSpan.FromTicks(333333);<br /> <br /> //Don't set Fix Time<br /> //this.IsFixedTimeStep = false;<br /> //graphics.SynchronizeWithVerticalRetrace = false;<br /> //this.TargetElapsedTime = TimeSpan.FromSeconds(1 / 60f);<br /> }<br /> <br /> <br /> protected override void Initialize()<br /> {<br /> // TODO: Add your initialization logic here<br /> <br /> base.Initialize();<br /> }<br /> <br /> <br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> Font = Content.Load&lt;SpriteFont&gt;(&quot;SpriteFont1&quot;);<br /> }<br /> <br /> <br /> protected override void UnloadContent()<br /> {<br /> <br /> }<br /> <br /> <br /> protected override void Update(GameTime gameTime)<br /> {<br /> // Allows the game to exit<br /> if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)<br /> this.Exit();<br /> <br /> // TODO: Add your update logic here<br /> <br /> base.Update(gameTime);<br /> }<br /> <br /> <br /> protected override void Draw(GameTime gameTime)<br /> {<br /> GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> CumulativeFrameTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000f;<br /> NumFrames++;<br /> if (CumulativeFrameTime &gt;= 1f)<br /> {<br /> FramesPerSecond = NumFrames;<br /> NumFrames = 0;<br /> CumulativeFrameTime -= 1f;<br /> }<br /> spriteBatch.Begin();<br /> spriteBatch.DrawString(Font, &quot;FPS: &quot; + FramesPerSecond.ToString(), new Vector2(0, 0), Color.Black);<br /> spriteBatch.End();<br /> base.Draw(gameTime);<br /> }<br /> }<br /> <br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> TODO in class: Refactor this FPS game into a GameComponent. Does it need to Draw? Then refactor into a library project that can be reused.<br /> <br /> ==Game Service==<br /> A game service is a game component that uses an interface to enforce a singleton pattern and make a single instance of a game component accessible to all other components. It's a nice mechanism to maintain a loose coupling between components.<br /> <br /> A singleton is a class that only allows a single instance of the class to be created. A game service is not a true singleton as it uses a unique interface to identify and expose it at the game level.<br /> <br /> A game service is a built in mechanism that allows a game to create and manage a single instance of a component ans allows other components access to the service.<br /> <br /> Good candidates for a game service are.<br /> *InputHandler<br /> *GameConsole<br /> *Profiling Service<br /> *Scoreboard<br /> <br /> <br /> <br /> ===InputHandler Service===<br /> <br /> In a separate Library Class. We are going to start using this library for reusable components of our games. <br /> <br /> Useful info missing from the XNA input states<br /> <br /> '''WasPressed''' determines is a button was press between the last update and the current update. To do this we need to store that keyboard and controller states from the previous call to update.<br /> <br /> ===Console Class===<br /> Separate IntroGameLibrary Project to help Encapsulate Reusable Code.<br /> * IntroConsole.zip<br /> * IntroGameLibrary.zip<br /> <br /> IntroGameLibrary/GameConsole.cs<br /> To add the Component to the Game we make an declare in the game class. Then we need to add the component to the Game Components Collection.<br /> <br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt; <br /> GameConsole gameConsole;<br /> <br /> public Game1()<br /> {<br /> graphics = new GraphicsDeviceManager(this);<br /> Content.RootDirectory = &quot;Content&quot;;<br /> <br /> gameConsole = new GameConsole(this);<br /> this.Components.Add(gameConsole);<br /> }<br /> <br /> &lt;/syntaxhighlight&gt;<br /> <br /> IntroConsole/Game1.cs<br /> <br /> ==Homework==<br /> *Use the fps component to create a baseline log for you project in Monogame note the number of frames you get when you set <br /> <br /> *Convert Monogame Interesting movement Project to use the inputHandler service and a playerContoller class the uses good separation of concern for input</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class4&diff=22804 Game Programming Class4 2016-09-27T02:19:54Z <p>Jeff: /* Demo */</p> <hr /> <div><br /> ==Objectives==<br /> *Unified Input Controller Monogame<br /> *Mongame Sprites<br /> *Refactoring classes to common game library<br /> *Separation of Concern where should classes like<br /> ==Skills==<br /> *GameComponents Monogame<br /> *SVN Commit<br /> ==Demo==<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/PacManSprite2Component Monogame\3.5\PacManSprite2Component] : Sprite class <br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/GameComponents Monogame\3.5\GameComponents] : Monogame reusable components that follow game loop<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/FPS Monogame\3.5\FPS] : Game component<br /> <br /> ==Home Work==<br /> *Refactor interesting movement using game component and two players with separate input controls.<br /> <br /> <br /> ==in class==<br /> <br /> Extract sprite from pacman class and build new project<br /> <br /> ===Sprite class===<br /> <br /> IntroPacManComponent.zip<br /> <br /> Project that refactors the pacman class into two classes<br /> <br /> Sprite.cs<br /> DrawableSprite.cs<br /> <br /> Then the pacman class can inherit from one of these two classes.<br /> <br /> PacMan.cs<br /> <br /> Due to the desire to limit the number of spritebatches, I've created two classes. The sprite class cannot draw itself without being associated with and external spritebatch.<br /> The DrawableSprite has it's own spritebatch which makes it easier to use but less efficient.<br /> <br /> ==Game Components==<br /> About components [http://msdn.microsoft.com/en-us/library/bb203873.aspx Application Overview]<br /> <br /> Game Components are reusable and easy to add to a game.<br /> <br /> * GameComponent Class<br /> * DrawGameComponent Class<br /> <br /> http://blogs.msdn.com/xna/archive/2006/08/31/734204.aspx<br /> <br /> Common methods<br /> <br /> '''Enabled'''<br /> :Indicates whether GameComponent.Update should be called when Game.Update is called. <br /> <br /> '''UpdateOrder'''<br /> :Indicates the order in which the GameComponent should be updated relative to other GameComponent instances. Lower values are updated first. <br /> <br /> (available if it is a DrawableGameComponent) <br /> <br /> '''Visible'''<br /> :Indicates whether Draw should be called.<br /> <br /> '''DrawOrder'''<br /> :Order in which the component should be drawn, relative to other components that are in the same GameComponentCollection.<br /> <br /> ===Frame Per Second Counter===<br /> &lt;syntaxhighlight lang=&quot;csharp&quot; &gt;<br /> using Microsoft.Xna.Framework;<br /> using Microsoft.Xna.Framework.Graphics;<br /> using Microsoft.Xna.Framework.Input;<br /> using System;<br /> <br /> namespace GameWindowsFPS<br /> {<br /> public class Game1 : Microsoft.Xna.Framework.Game<br /> {<br /> GraphicsDeviceManager graphics;<br /> SpriteBatch spriteBatch;<br /> <br /> float CumulativeFrameTime;<br /> int NumFrames;<br /> int FramesPerSecond;<br /> SpriteFont Font;<br /> <br /> public Game1()<br /> {<br /> graphics = new GraphicsDeviceManager(this);<br /> Content.RootDirectory = &quot;Content&quot;;<br /> <br /> //Set to 30 Frames a Second<br /> //TargetElapsedTime = TimeSpan.FromTicks(333333);<br /> <br /> //Don't set Fix Time<br /> //this.IsFixedTimeStep = false;<br /> //graphics.SynchronizeWithVerticalRetrace = false;<br /> //this.TargetElapsedTime = TimeSpan.FromSeconds(1 / 60f);<br /> }<br /> <br /> <br /> protected override void Initialize()<br /> {<br /> // TODO: Add your initialization logic here<br /> <br /> base.Initialize();<br /> }<br /> <br /> <br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> Font = Content.Load&lt;SpriteFont&gt;(&quot;SpriteFont1&quot;);<br /> }<br /> <br /> <br /> protected override void UnloadContent()<br /> {<br /> <br /> }<br /> <br /> <br /> protected override void Update(GameTime gameTime)<br /> {<br /> // Allows the game to exit<br /> if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)<br /> this.Exit();<br /> <br /> // TODO: Add your update logic here<br /> <br /> base.Update(gameTime);<br /> }<br /> <br /> <br /> protected override void Draw(GameTime gameTime)<br /> {<br /> GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> CumulativeFrameTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000f;<br /> NumFrames++;<br /> if (CumulativeFrameTime &gt;= 1f)<br /> {<br /> FramesPerSecond = NumFrames;<br /> NumFrames = 0;<br /> CumulativeFrameTime -= 1f;<br /> }<br /> spriteBatch.Begin();<br /> spriteBatch.DrawString(Font, &quot;FPS: &quot; + FramesPerSecond.ToString(), new Vector2(0, 0), Color.Black);<br /> spriteBatch.End();<br /> base.Draw(gameTime);<br /> }<br /> }<br /> <br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> TODO in class: Refactor this FPS game into a GameComponent. Does it need to Draw? Then refactor into a library project that can be reused.<br /> <br /> ==Game Service==<br /> A game service is a game component that uses an interface to enforce a singleton pattern and make a single instance of a game component accessible to all other components. It's a nice mechanism to maintain a loose coupling between components.<br /> <br /> A singleton is a class that only allows a single instance of the class to be created. A game service is not a true singleton as it uses a unique interface to identify and expose it at the game level.<br /> <br /> A game service is a built in mechanism that allows a game to create and manage a single instance of a component ans allows other components access to the service.<br /> <br /> Good candidates for a game service are.<br /> *InputHandler<br /> *GameConsole<br /> *Profiling Service<br /> *Scoreboard<br /> <br /> <br /> <br /> ===InputHandler Service===<br /> <br /> In a separate Library Class. We are going to start using this library for reusable components of our games. <br /> <br /> Useful info missing from the XNA input states<br /> <br /> '''WasPressed''' determines is a button was press between the last update and the current update. To do this we need to store that keyboard and controller states from the previous call to update.<br /> <br /> ===Console Class===<br /> Separate IntroGameLibrary Project to help Encapsulate Reusable Code.<br /> * IntroConsole.zip<br /> * IntroGameLibrary.zip<br /> <br /> IntroGameLibrary/GameConsole.cs<br /> To add the Component to the Game we make an declare in the game class. Then we need to add the component to the Game Components Collection.<br /> <br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt; <br /> GameConsole gameConsole;<br /> <br /> public Game1()<br /> {<br /> graphics = new GraphicsDeviceManager(this);<br /> Content.RootDirectory = &quot;Content&quot;;<br /> <br /> gameConsole = new GameConsole(this);<br /> this.Components.Add(gameConsole);<br /> }<br /> <br /> &lt;/syntaxhighlight&gt;<br /> <br /> IntroConsole/Game1.cs<br /> <br /> ==Homework==<br /> *Use the fps component to create a baseline log for you project in Monogame note the number of frames you get when you set <br /> <br /> *Convert Monogame Interesting movement Project to use the inputHandler service and a playerContoller class the uses good separation of concern for input</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class4&diff=22803 Game Programming Class4 2016-09-27T02:14:13Z <p>Jeff: </p> <hr /> <div><br /> ==Objectives==<br /> *Unified Input Controller Monogame<br /> *Mongame Sprites<br /> *Refactoring classes to common game library<br /> *Separation of Concern where should classes like<br /> ==Skills==<br /> *GameComponents Monogame<br /> *SVN Commit<br /> ==Demo==<br /> *Monogame\3.5\PacManSprite2Component : Sprite class <br /> *Monogame\3.5\GameComponents : Monogame reusable components that follow game loop<br /> *Monogame\3.5\FPS : Game component<br /> ==Home Work==<br /> *Refactor interesting movement using game component and two players with separate input controls.<br /> <br /> <br /> ==in class==<br /> <br /> Extract sprite from pacman class and build new project<br /> <br /> ===Sprite class===<br /> <br /> IntroPacManComponent.zip<br /> <br /> Project that refactors the pacman class into two classes<br /> <br /> Sprite.cs<br /> DrawableSprite.cs<br /> <br /> Then the pacman class can inherit from one of these two classes.<br /> <br /> PacMan.cs<br /> <br /> Due to the desire to limit the number of spritebatches, I've created two classes. The sprite class cannot draw itself without being associated with and external spritebatch.<br /> The DrawableSprite has it's own spritebatch which makes it easier to use but less efficient.<br /> <br /> ==Game Components==<br /> About components [http://msdn.microsoft.com/en-us/library/bb203873.aspx Application Overview]<br /> <br /> Game Components are reusable and easy to add to a game.<br /> <br /> * GameComponent Class<br /> * DrawGameComponent Class<br /> <br /> http://blogs.msdn.com/xna/archive/2006/08/31/734204.aspx<br /> <br /> Common methods<br /> <br /> '''Enabled'''<br /> :Indicates whether GameComponent.Update should be called when Game.Update is called. <br /> <br /> '''UpdateOrder'''<br /> :Indicates the order in which the GameComponent should be updated relative to other GameComponent instances. Lower values are updated first. <br /> <br /> (available if it is a DrawableGameComponent) <br /> <br /> '''Visible'''<br /> :Indicates whether Draw should be called.<br /> <br /> '''DrawOrder'''<br /> :Order in which the component should be drawn, relative to other components that are in the same GameComponentCollection.<br /> <br /> ===Frame Per Second Counter===<br /> &lt;syntaxhighlight lang=&quot;csharp&quot; &gt;<br /> using Microsoft.Xna.Framework;<br /> using Microsoft.Xna.Framework.Graphics;<br /> using Microsoft.Xna.Framework.Input;<br /> using System;<br /> <br /> namespace GameWindowsFPS<br /> {<br /> public class Game1 : Microsoft.Xna.Framework.Game<br /> {<br /> GraphicsDeviceManager graphics;<br /> SpriteBatch spriteBatch;<br /> <br /> float CumulativeFrameTime;<br /> int NumFrames;<br /> int FramesPerSecond;<br /> SpriteFont Font;<br /> <br /> public Game1()<br /> {<br /> graphics = new GraphicsDeviceManager(this);<br /> Content.RootDirectory = &quot;Content&quot;;<br /> <br /> //Set to 30 Frames a Second<br /> //TargetElapsedTime = TimeSpan.FromTicks(333333);<br /> <br /> //Don't set Fix Time<br /> //this.IsFixedTimeStep = false;<br /> //graphics.SynchronizeWithVerticalRetrace = false;<br /> //this.TargetElapsedTime = TimeSpan.FromSeconds(1 / 60f);<br /> }<br /> <br /> <br /> protected override void Initialize()<br /> {<br /> // TODO: Add your initialization logic here<br /> <br /> base.Initialize();<br /> }<br /> <br /> <br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> Font = Content.Load&lt;SpriteFont&gt;(&quot;SpriteFont1&quot;);<br /> }<br /> <br /> <br /> protected override void UnloadContent()<br /> {<br /> <br /> }<br /> <br /> <br /> protected override void Update(GameTime gameTime)<br /> {<br /> // Allows the game to exit<br /> if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)<br /> this.Exit();<br /> <br /> // TODO: Add your update logic here<br /> <br /> base.Update(gameTime);<br /> }<br /> <br /> <br /> protected override void Draw(GameTime gameTime)<br /> {<br /> GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> CumulativeFrameTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000f;<br /> NumFrames++;<br /> if (CumulativeFrameTime &gt;= 1f)<br /> {<br /> FramesPerSecond = NumFrames;<br /> NumFrames = 0;<br /> CumulativeFrameTime -= 1f;<br /> }<br /> spriteBatch.Begin();<br /> spriteBatch.DrawString(Font, &quot;FPS: &quot; + FramesPerSecond.ToString(), new Vector2(0, 0), Color.Black);<br /> spriteBatch.End();<br /> base.Draw(gameTime);<br /> }<br /> }<br /> <br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> TODO in class: Refactor this FPS game into a GameComponent. Does it need to Draw? Then refactor into a library project that can be reused.<br /> <br /> ==Game Service==<br /> A game service is a game component that uses an interface to enforce a singleton pattern and make a single instance of a game component accessible to all other components. It's a nice mechanism to maintain a loose coupling between components.<br /> <br /> A singleton is a class that only allows a single instance of the class to be created. A game service is not a true singleton as it uses a unique interface to identify and expose it at the game level.<br /> <br /> A game service is a built in mechanism that allows a game to create and manage a single instance of a component ans allows other components access to the service.<br /> <br /> Good candidates for a game service are.<br /> *InputHandler<br /> *GameConsole<br /> *Profiling Service<br /> *Scoreboard<br /> <br /> <br /> <br /> ===InputHandler Service===<br /> <br /> In a separate Library Class. We are going to start using this library for reusable components of our games. <br /> <br /> Useful info missing from the XNA input states<br /> <br /> '''WasPressed''' determines is a button was press between the last update and the current update. To do this we need to store that keyboard and controller states from the previous call to update.<br /> <br /> ===Console Class===<br /> Separate IntroGameLibrary Project to help Encapsulate Reusable Code.<br /> * IntroConsole.zip<br /> * IntroGameLibrary.zip<br /> <br /> IntroGameLibrary/GameConsole.cs<br /> To add the Component to the Game we make an declare in the game class. Then we need to add the component to the Game Components Collection.<br /> <br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt; <br /> GameConsole gameConsole;<br /> <br /> public Game1()<br /> {<br /> graphics = new GraphicsDeviceManager(this);<br /> Content.RootDirectory = &quot;Content&quot;;<br /> <br /> gameConsole = new GameConsole(this);<br /> this.Components.Add(gameConsole);<br /> }<br /> <br /> &lt;/syntaxhighlight&gt;<br /> <br /> IntroConsole/Game1.cs<br /> <br /> ==Homework==<br /> *Use the fps component to create a baseline log for you project in Monogame note the number of frames you get when you set <br /> <br /> *Convert Monogame Interesting movement Project to use the inputHandler service and a playerContoller class the uses good separation of concern for input</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class3&diff=22802 Game Programming Class3 2016-09-19T03:39:57Z <p>Jeff: /* Unity Basics and Movement */</p> <hr /> <div>=Class 3 Input Handling=<br /> <br /> ==Overview==<br /> <br /> Objectives<br /> *Time corrected move on delta time Unity<br /> *SpriteBatch option in monogame<br /> *Review Input class in monogame<br /> *Movement in Unity<br /> Skills<br /> *SVN Commit<br /> *Unity Package<br /> Demo<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementWRotate Monogame\3.5\SimpleMovementWRotate] :The SimpleMovementWRotate uses the incorrect origin for rotation on purpose. Uncomment second Draw call to fix<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SpriteBatchOptions Monogame\3.5\SpriteBatchOptions] : many many ways to call Spritebatch draw<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Unity/SimpleUpdateMovement/Packages Unity\SimpleUpdateMovement\Packages\SimpleMovement.unitypackage] : Unity basic movement<br /> <br /> ==SpriteBatch Options==<br /> <br /> '''[http://msdn.microsoft.com/en-us/library/bb203919.aspx 2D Graphics Overview]'''<br /> <br /> About textures and Batching<br /> <br /> [http://msdn.microsoft.com/en-us/library/bb203889.aspx Displays, ViewPorts, Client Bounds]<br /> <br /> <br /> ===Alpha channels===<br /> <br /> Demo<br /> * [http://gimp.org Gimp]<br /> * [http://www.getpaint.net/ Paint.NET]<br /> <br /> ===SpriteBatch=== <br /> <br /> demo project<br /> *IntroSimpleSpriteBatchOptionsWindows.zip <br /> <br /> spriteBatch.Begin();<br /> <br /> [[Image:IntroSpriteModesDemo.png]]<br /> <br /> # Options SpriteBlendMode<br /> # Additive Enable additive blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-3.aspx<br /> # AlphaBlend Enable alpha blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-2.aspx<br /> # None No blending specified.<br /> <br /> <br /> <br /> <br /> <br /> ==Inclass Keyboard input demo==<br /> <br /> &lt;code&gt;<br /> KeyboardState keyboardState = Keyboard.GetState();<br /> <br /> Explore Limitations of Built in Keyboard state. <br /> <br /> &lt;/code&gt;<br /> <br /> ==Input==<br /> input from Game Controller and Keyboard<br /> <br /> '''GamePad'''<br /> [[Image:XBoxGamePadWithLabels.png]]<br /> <br /> XNA has built in support for up to 4 game controllers. The default controller is a x-box controller.<br /> X-Box Controller The Controller is accessed through the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad.aspx GamePad] Object and the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate_members.aspx GamePadState] Structure reference types<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> //Get an instance of the gamePadState Structure<br /> GamePadState gamePad1State = GamePad.GetState(PlayerIndex.One); <br /> <br /> /*Since the Keyboard structure is Windows only we <br /> need to use some preprocessor<br /> directives to only compile the KeyBoard <br /> state code if the target is not XBOX360 (I<br /> should also add zune if this is one of our build targets)<br /> */<br /> #if !XBOX360<br /> #region KeyBoard<br /> KeyboardState keyboardState = Keyboard.GetState();<br /> #endif<br /> <br /> &lt;/syntaxhighlight&gt;<br /> <br /> Angle Measured in Radians<br /> <br /> using [http://msdn.microsoft.com/en-us/library/system.math.atan2.aspx atan2] to get the angle from the direction vector<br /> <br /> <br /> IntroSimpleSpriteUpdateRotateWindows Project<br /> <br /> SpriteJump Project<br /> <br /> ==Input Error missing DirectX9==<br /> <br /> Error:An unhandled exception of type 'System.DllNotFoundException' occurred in SharpDX.XInput.dll Additional information: Unable to load DLL 'xinput1_3.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)<br /> <br /> XInput library may be missing if you have a fresh install of win8.1 or 10<br /> <br /> Solution: Install DirectX 9 Runtime http://www.microsoft.com/en-us/download/confirmation.aspx?id=8109 or http://www.microsoft.com/en-us/download/details.aspx?id=35<br /> <br /> ==Unity Basics and Movement==<br /> Demo add Art and setup folders<br /> <br /> ===Unity Input===<br /> Current Unity Input System<br /> <br /> https://docs.unity3d.com/Manual/ConventionalGameInput.html<br /> <br /> Proposal to change Unity input system<br /> <br /> https://blogs.unity3d.com/2016/04/12/developing-the-new-input-system-together-with-you/<br /> https://sites.google.com/a/unity3d.com/unity-input-advisory-board/<br /> <br /> <br /> ===Basic Movement===<br /> Movement script <br /> <br /> parameter<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> public Vector3 Direction = new Vector3(1, 0, 0);<br /> public float Speed = 5;<br /> &lt;/syntaxhighlight&gt;<br /> Update<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> void Update () {<br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> Full Script with wall bouncing<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using UnityEngine;<br /> using System.Collections;<br /> <br /> public class SimpleMove : MonoBehaviour {<br /> <br /> <br /> public Vector3 Direction = new Vector3(1, 0, 0);<br /> public float Speed = 5;<br /> <br /> static Vector3 cameraBottomLeft; //calculate camera left<br /> static Vector3 cameraTopRight; //calculate camera top<br /> static Rect cameraRect; //rectangle for camera<br /> <br /> <br /> // Use this for initialization<br /> void Start () {<br /> <br /> cameraBottomLeft = Camera.main.ScreenToWorldPoint(Vector3.zero);<br /> cameraTopRight = Camera.main.ScreenToWorldPoint(new Vector3(<br /> Camera.main.pixelWidth, Camera.main.pixelHeight));<br /> <br /> cameraRect = new Rect(<br /> cameraBottomLeft.x,<br /> cameraBottomLeft.y,<br /> cameraTopRight.x - cameraBottomLeft.x,<br /> cameraTopRight.y - cameraBottomLeft.y);<br /> <br /> }<br /> <br /> // Update is called once per frame<br /> void Update () {<br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> <br /> if (!cameraRect.Contains(this.transform.position))<br /> {<br /> //keep on screen<br /> if (this.transform.position.x &lt;= cameraRect.xMin)<br /> {<br /> <br /> this.Direction.x *= -1;<br /> }<br /> if (this.transform.position.x &gt;= cameraRect.xMax)<br /> {<br /> <br /> this.Direction.x *= -1;<br /> }<br /> if (this.transform.position.y &gt; cameraRect.yMax)<br /> {<br /> <br /> this.Direction.y *= -1;<br /> }<br /> if (this.transform.position.y &lt; cameraRect.yMin)<br /> {<br /> <br /> this.Direction.y *= -1;<br /> }<br /> <br /> }<br /> <br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> and Input from keyboard<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using UnityEngine;<br /> using System.Collections;<br /> <br /> public class SimpleInput : MonoBehaviour {<br /> <br /> <br /> public Vector3 Direction;<br /> public float Speed;<br /> public Vector3 keyDirection;<br /> <br /> // Use this for initialization<br /> void Start () {<br /> <br /> }<br /> <br /> // Update is called once per frame<br /> void Update () {<br /> //input<br /> //direction.x = direction.y = 0;<br /> keyDirection.x = keyDirection.y = 0;<br /> <br /> //Keyboard<br /> if (Input.GetKey(&quot;right&quot;))<br /> {<br /> keyDirection.x += 1;<br /> }<br /> if (Input.GetKey(&quot;left&quot;))<br /> {<br /> keyDirection.x += -1;<br /> }<br /> <br /> if (Input.GetKey(&quot;up&quot;))<br /> {<br /> keyDirection.y += 1;<br /> }<br /> if (Input.GetKey(&quot;down&quot;))<br /> {<br /> keyDirection.y += -1;<br /> }<br /> <br /> Direction += keyDirection;<br /> Direction.Normalize();<br /> <br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> <br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==Homework==<br /> <br /> Moving Game 2 Interesting movement (Mono Game and Unity)<br /> <br /> Update your moving assigment to make the movement more interesting. Use more than 1 input method ie Keyboard, xbox controller, mouse etc.<br /> <br /> Create a Unity Scene with the same sprite and use a script to create similar movement.<br /> <br /> Commit the mongame project and an export of the Unity Scene as a package to SVN or Moodle.<br /> <br /> Repo URL https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/FA16</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class3&diff=22801 Game Programming Class3 2016-09-19T03:38:52Z <p>Jeff: /* Overview */</p> <hr /> <div>=Class 3 Input Handling=<br /> <br /> ==Overview==<br /> <br /> Objectives<br /> *Time corrected move on delta time Unity<br /> *SpriteBatch option in monogame<br /> *Review Input class in monogame<br /> *Movement in Unity<br /> Skills<br /> *SVN Commit<br /> *Unity Package<br /> Demo<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementWRotate Monogame\3.5\SimpleMovementWRotate] :The SimpleMovementWRotate uses the incorrect origin for rotation on purpose. Uncomment second Draw call to fix<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SpriteBatchOptions Monogame\3.5\SpriteBatchOptions] : many many ways to call Spritebatch draw<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Unity/SimpleUpdateMovement/Packages Unity\SimpleUpdateMovement\Packages\SimpleMovement.unitypackage] : Unity basic movement<br /> <br /> ==SpriteBatch Options==<br /> <br /> '''[http://msdn.microsoft.com/en-us/library/bb203919.aspx 2D Graphics Overview]'''<br /> <br /> About textures and Batching<br /> <br /> [http://msdn.microsoft.com/en-us/library/bb203889.aspx Displays, ViewPorts, Client Bounds]<br /> <br /> <br /> ===Alpha channels===<br /> <br /> Demo<br /> * [http://gimp.org Gimp]<br /> * [http://www.getpaint.net/ Paint.NET]<br /> <br /> ===SpriteBatch=== <br /> <br /> demo project<br /> *IntroSimpleSpriteBatchOptionsWindows.zip <br /> <br /> spriteBatch.Begin();<br /> <br /> [[Image:IntroSpriteModesDemo.png]]<br /> <br /> # Options SpriteBlendMode<br /> # Additive Enable additive blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-3.aspx<br /> # AlphaBlend Enable alpha blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-2.aspx<br /> # None No blending specified.<br /> <br /> <br /> <br /> <br /> <br /> ==Inclass Keyboard input demo==<br /> <br /> &lt;code&gt;<br /> KeyboardState keyboardState = Keyboard.GetState();<br /> <br /> Explore Limitations of Built in Keyboard state. <br /> <br /> &lt;/code&gt;<br /> <br /> ==Input==<br /> input from Game Controller and Keyboard<br /> <br /> '''GamePad'''<br /> [[Image:XBoxGamePadWithLabels.png]]<br /> <br /> XNA has built in support for up to 4 game controllers. The default controller is a x-box controller.<br /> X-Box Controller The Controller is accessed through the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad.aspx GamePad] Object and the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate_members.aspx GamePadState] Structure reference types<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> //Get an instance of the gamePadState Structure<br /> GamePadState gamePad1State = GamePad.GetState(PlayerIndex.One); <br /> <br /> /*Since the Keyboard structure is Windows only we <br /> need to use some preprocessor<br /> directives to only compile the KeyBoard <br /> state code if the target is not XBOX360 (I<br /> should also add zune if this is one of our build targets)<br /> */<br /> #if !XBOX360<br /> #region KeyBoard<br /> KeyboardState keyboardState = Keyboard.GetState();<br /> #endif<br /> <br /> &lt;/syntaxhighlight&gt;<br /> <br /> Angle Measured in Radians<br /> <br /> using [http://msdn.microsoft.com/en-us/library/system.math.atan2.aspx atan2] to get the angle from the direction vector<br /> <br /> <br /> IntroSimpleSpriteUpdateRotateWindows Project<br /> <br /> SpriteJump Project<br /> <br /> ==Input Error missing DirectX9==<br /> <br /> Error:An unhandled exception of type 'System.DllNotFoundException' occurred in SharpDX.XInput.dll Additional information: Unable to load DLL 'xinput1_3.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)<br /> <br /> XInput library may be missing if you have a fresh install of win8.1 or 10<br /> <br /> Solution: Install DirectX 9 Runtime http://www.microsoft.com/en-us/download/confirmation.aspx?id=8109 or http://www.microsoft.com/en-us/download/details.aspx?id=35<br /> <br /> ==Unity Basics and Movement==<br /> Demo add Art and setup folders<br /> <br /> Movement script <br /> <br /> parameter<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> public Vector3 Direction = new Vector3(1, 0, 0);<br /> public float Speed = 5;<br /> &lt;/syntaxhighlight&gt;<br /> Update<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> void Update () {<br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> Full Script with wall bouncing<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using UnityEngine;<br /> using System.Collections;<br /> <br /> public class SimpleMove : MonoBehaviour {<br /> <br /> <br /> public Vector3 Direction = new Vector3(1, 0, 0);<br /> public float Speed = 5;<br /> <br /> static Vector3 cameraBottomLeft; //calculate camera left<br /> static Vector3 cameraTopRight; //calculate camera top<br /> static Rect cameraRect; //rectangle for camera<br /> <br /> <br /> // Use this for initialization<br /> void Start () {<br /> <br /> cameraBottomLeft = Camera.main.ScreenToWorldPoint(Vector3.zero);<br /> cameraTopRight = Camera.main.ScreenToWorldPoint(new Vector3(<br /> Camera.main.pixelWidth, Camera.main.pixelHeight));<br /> <br /> cameraRect = new Rect(<br /> cameraBottomLeft.x,<br /> cameraBottomLeft.y,<br /> cameraTopRight.x - cameraBottomLeft.x,<br /> cameraTopRight.y - cameraBottomLeft.y);<br /> <br /> }<br /> <br /> // Update is called once per frame<br /> void Update () {<br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> <br /> if (!cameraRect.Contains(this.transform.position))<br /> {<br /> //keep on screen<br /> if (this.transform.position.x &lt;= cameraRect.xMin)<br /> {<br /> <br /> this.Direction.x *= -1;<br /> }<br /> if (this.transform.position.x &gt;= cameraRect.xMax)<br /> {<br /> <br /> this.Direction.x *= -1;<br /> }<br /> if (this.transform.position.y &gt; cameraRect.yMax)<br /> {<br /> <br /> this.Direction.y *= -1;<br /> }<br /> if (this.transform.position.y &lt; cameraRect.yMin)<br /> {<br /> <br /> this.Direction.y *= -1;<br /> }<br /> <br /> }<br /> <br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> and Input from keyboard<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using UnityEngine;<br /> using System.Collections;<br /> <br /> public class SimpleInput : MonoBehaviour {<br /> <br /> <br /> public Vector3 Direction;<br /> public float Speed;<br /> public Vector3 keyDirection;<br /> <br /> // Use this for initialization<br /> void Start () {<br /> <br /> }<br /> <br /> // Update is called once per frame<br /> void Update () {<br /> //input<br /> //direction.x = direction.y = 0;<br /> keyDirection.x = keyDirection.y = 0;<br /> <br /> //Keyboard<br /> if (Input.GetKey(&quot;right&quot;))<br /> {<br /> keyDirection.x += 1;<br /> }<br /> if (Input.GetKey(&quot;left&quot;))<br /> {<br /> keyDirection.x += -1;<br /> }<br /> <br /> if (Input.GetKey(&quot;up&quot;))<br /> {<br /> keyDirection.y += 1;<br /> }<br /> if (Input.GetKey(&quot;down&quot;))<br /> {<br /> keyDirection.y += -1;<br /> }<br /> <br /> Direction += keyDirection;<br /> Direction.Normalize();<br /> <br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> <br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==Homework==<br /> <br /> Moving Game 2 Interesting movement (Mono Game and Unity)<br /> <br /> Update your moving assigment to make the movement more interesting. Use more than 1 input method ie Keyboard, xbox controller, mouse etc.<br /> <br /> Create a Unity Scene with the same sprite and use a script to create similar movement.<br /> <br /> Commit the mongame project and an export of the Unity Scene as a package to SVN or Moodle.<br /> <br /> Repo URL https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/FA16</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class3&diff=22800 Game Programming Class3 2016-09-19T03:07:20Z <p>Jeff: /* Overview */</p> <hr /> <div>=Class 3 Input Handling=<br /> <br /> ==Overview==<br /> <br /> Objectives<br /> *Time corrected move on delta time Unity<br /> *SpriteBatch option in monogame<br /> *Review Input class in monogame<br /> *Movement in Unity<br /> Skills<br /> *SVN Commit<br /> *Unity Package<br /> Demo<br /> *Monogame\3.5\SimpleMovementWRotate :The SimpleMovementWRotate uses the incorrect origin for rotation on purpose. Uncomment second Draw call to fix<br /> *Monogame\3.5\SpriteBatchOptions : many many ways to call Spritebatch draw<br /> *Unity\SimpleUpdateMovement\Packages\SimpleMovement.unitypackage : Unity basic movement<br /> <br /> ==SpriteBatch Options==<br /> <br /> '''[http://msdn.microsoft.com/en-us/library/bb203919.aspx 2D Graphics Overview]'''<br /> <br /> About textures and Batching<br /> <br /> [http://msdn.microsoft.com/en-us/library/bb203889.aspx Displays, ViewPorts, Client Bounds]<br /> <br /> <br /> ===Alpha channels===<br /> <br /> Demo<br /> * [http://gimp.org Gimp]<br /> * [http://www.getpaint.net/ Paint.NET]<br /> <br /> ===SpriteBatch=== <br /> <br /> demo project<br /> *IntroSimpleSpriteBatchOptionsWindows.zip <br /> <br /> spriteBatch.Begin();<br /> <br /> [[Image:IntroSpriteModesDemo.png]]<br /> <br /> # Options SpriteBlendMode<br /> # Additive Enable additive blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-3.aspx<br /> # AlphaBlend Enable alpha blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-2.aspx<br /> # None No blending specified.<br /> <br /> <br /> <br /> <br /> <br /> ==Inclass Keyboard input demo==<br /> <br /> &lt;code&gt;<br /> KeyboardState keyboardState = Keyboard.GetState();<br /> <br /> Explore Limitations of Built in Keyboard state. <br /> <br /> &lt;/code&gt;<br /> <br /> ==Input==<br /> input from Game Controller and Keyboard<br /> <br /> '''GamePad'''<br /> [[Image:XBoxGamePadWithLabels.png]]<br /> <br /> XNA has built in support for up to 4 game controllers. The default controller is a x-box controller.<br /> X-Box Controller The Controller is accessed through the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad.aspx GamePad] Object and the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate_members.aspx GamePadState] Structure reference types<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> //Get an instance of the gamePadState Structure<br /> GamePadState gamePad1State = GamePad.GetState(PlayerIndex.One); <br /> <br /> /*Since the Keyboard structure is Windows only we <br /> need to use some preprocessor<br /> directives to only compile the KeyBoard <br /> state code if the target is not XBOX360 (I<br /> should also add zune if this is one of our build targets)<br /> */<br /> #if !XBOX360<br /> #region KeyBoard<br /> KeyboardState keyboardState = Keyboard.GetState();<br /> #endif<br /> <br /> &lt;/syntaxhighlight&gt;<br /> <br /> Angle Measured in Radians<br /> <br /> using [http://msdn.microsoft.com/en-us/library/system.math.atan2.aspx atan2] to get the angle from the direction vector<br /> <br /> <br /> IntroSimpleSpriteUpdateRotateWindows Project<br /> <br /> SpriteJump Project<br /> <br /> ==Input Error missing DirectX9==<br /> <br /> Error:An unhandled exception of type 'System.DllNotFoundException' occurred in SharpDX.XInput.dll Additional information: Unable to load DLL 'xinput1_3.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)<br /> <br /> XInput library may be missing if you have a fresh install of win8.1 or 10<br /> <br /> Solution: Install DirectX 9 Runtime http://www.microsoft.com/en-us/download/confirmation.aspx?id=8109 or http://www.microsoft.com/en-us/download/details.aspx?id=35<br /> <br /> ==Unity Basics and Movement==<br /> Demo add Art and setup folders<br /> <br /> Movement script <br /> <br /> parameter<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> public Vector3 Direction = new Vector3(1, 0, 0);<br /> public float Speed = 5;<br /> &lt;/syntaxhighlight&gt;<br /> Update<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> void Update () {<br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> Full Script with wall bouncing<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using UnityEngine;<br /> using System.Collections;<br /> <br /> public class SimpleMove : MonoBehaviour {<br /> <br /> <br /> public Vector3 Direction = new Vector3(1, 0, 0);<br /> public float Speed = 5;<br /> <br /> static Vector3 cameraBottomLeft; //calculate camera left<br /> static Vector3 cameraTopRight; //calculate camera top<br /> static Rect cameraRect; //rectangle for camera<br /> <br /> <br /> // Use this for initialization<br /> void Start () {<br /> <br /> cameraBottomLeft = Camera.main.ScreenToWorldPoint(Vector3.zero);<br /> cameraTopRight = Camera.main.ScreenToWorldPoint(new Vector3(<br /> Camera.main.pixelWidth, Camera.main.pixelHeight));<br /> <br /> cameraRect = new Rect(<br /> cameraBottomLeft.x,<br /> cameraBottomLeft.y,<br /> cameraTopRight.x - cameraBottomLeft.x,<br /> cameraTopRight.y - cameraBottomLeft.y);<br /> <br /> }<br /> <br /> // Update is called once per frame<br /> void Update () {<br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> <br /> if (!cameraRect.Contains(this.transform.position))<br /> {<br /> //keep on screen<br /> if (this.transform.position.x &lt;= cameraRect.xMin)<br /> {<br /> <br /> this.Direction.x *= -1;<br /> }<br /> if (this.transform.position.x &gt;= cameraRect.xMax)<br /> {<br /> <br /> this.Direction.x *= -1;<br /> }<br /> if (this.transform.position.y &gt; cameraRect.yMax)<br /> {<br /> <br /> this.Direction.y *= -1;<br /> }<br /> if (this.transform.position.y &lt; cameraRect.yMin)<br /> {<br /> <br /> this.Direction.y *= -1;<br /> }<br /> <br /> }<br /> <br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> and Input from keyboard<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using UnityEngine;<br /> using System.Collections;<br /> <br /> public class SimpleInput : MonoBehaviour {<br /> <br /> <br /> public Vector3 Direction;<br /> public float Speed;<br /> public Vector3 keyDirection;<br /> <br /> // Use this for initialization<br /> void Start () {<br /> <br /> }<br /> <br /> // Update is called once per frame<br /> void Update () {<br /> //input<br /> //direction.x = direction.y = 0;<br /> keyDirection.x = keyDirection.y = 0;<br /> <br /> //Keyboard<br /> if (Input.GetKey(&quot;right&quot;))<br /> {<br /> keyDirection.x += 1;<br /> }<br /> if (Input.GetKey(&quot;left&quot;))<br /> {<br /> keyDirection.x += -1;<br /> }<br /> <br /> if (Input.GetKey(&quot;up&quot;))<br /> {<br /> keyDirection.y += 1;<br /> }<br /> if (Input.GetKey(&quot;down&quot;))<br /> {<br /> keyDirection.y += -1;<br /> }<br /> <br /> Direction += keyDirection;<br /> Direction.Normalize();<br /> <br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> <br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==Homework==<br /> <br /> Moving Game 2 Interesting movement (Mono Game and Unity)<br /> <br /> Update your moving assigment to make the movement more interesting. Use more than 1 input method ie Keyboard, xbox controller, mouse etc.<br /> <br /> Create a Unity Scene with the same sprite and use a script to create similar movement.<br /> <br /> Commit the mongame project and an export of the Unity Scene as a package to SVN or Moodle.<br /> <br /> Repo URL https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/FA16</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class3&diff=22799 Game Programming Class3 2016-09-19T03:06:27Z <p>Jeff: /* Class 3 Input Handling */</p> <hr /> <div>=Class 3 Input Handling=<br /> <br /> ==Overview==<br /> <br /> Objectives<br /> • Time corrected move on delta time Unity<br /> • SpriteBatch option in monogame<br /> • Review Input class in monogame<br /> • Movement in Unity<br /> Skills<br /> • SVN Commit<br /> • Unity Package<br /> Demo<br /> • Monogame\3.5\SimpleMovementWRotate :The SimpleMovementWRotate uses the incorrect origin for rotation on purpose. Uncomment second Draw call to fix<br /> • Monogame\3.5\SpriteBatchOptions : many many ways to call Spritebatch draw<br /> Unity\SimpleUpdateMovement\Packages\SimpleMovement.unitypackage : Unity basic movement <br /> <br /> ==SpriteBatch Options==<br /> <br /> '''[http://msdn.microsoft.com/en-us/library/bb203919.aspx 2D Graphics Overview]'''<br /> <br /> About textures and Batching<br /> <br /> [http://msdn.microsoft.com/en-us/library/bb203889.aspx Displays, ViewPorts, Client Bounds]<br /> <br /> <br /> ===Alpha channels===<br /> <br /> Demo<br /> * [http://gimp.org Gimp]<br /> * [http://www.getpaint.net/ Paint.NET]<br /> <br /> ===SpriteBatch=== <br /> <br /> demo project<br /> *IntroSimpleSpriteBatchOptionsWindows.zip <br /> <br /> spriteBatch.Begin();<br /> <br /> [[Image:IntroSpriteModesDemo.png]]<br /> <br /> # Options SpriteBlendMode<br /> # Additive Enable additive blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-3.aspx<br /> # AlphaBlend Enable alpha blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-2.aspx<br /> # None No blending specified.<br /> <br /> <br /> <br /> <br /> <br /> ==Inclass Keyboard input demo==<br /> <br /> &lt;code&gt;<br /> KeyboardState keyboardState = Keyboard.GetState();<br /> <br /> Explore Limitations of Built in Keyboard state. <br /> <br /> &lt;/code&gt;<br /> <br /> ==Input==<br /> input from Game Controller and Keyboard<br /> <br /> '''GamePad'''<br /> [[Image:XBoxGamePadWithLabels.png]]<br /> <br /> XNA has built in support for up to 4 game controllers. The default controller is a x-box controller.<br /> X-Box Controller The Controller is accessed through the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad.aspx GamePad] Object and the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate_members.aspx GamePadState] Structure reference types<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> //Get an instance of the gamePadState Structure<br /> GamePadState gamePad1State = GamePad.GetState(PlayerIndex.One); <br /> <br /> /*Since the Keyboard structure is Windows only we <br /> need to use some preprocessor<br /> directives to only compile the KeyBoard <br /> state code if the target is not XBOX360 (I<br /> should also add zune if this is one of our build targets)<br /> */<br /> #if !XBOX360<br /> #region KeyBoard<br /> KeyboardState keyboardState = Keyboard.GetState();<br /> #endif<br /> <br /> &lt;/syntaxhighlight&gt;<br /> <br /> Angle Measured in Radians<br /> <br /> using [http://msdn.microsoft.com/en-us/library/system.math.atan2.aspx atan2] to get the angle from the direction vector<br /> <br /> <br /> IntroSimpleSpriteUpdateRotateWindows Project<br /> <br /> SpriteJump Project<br /> <br /> ==Input Error missing DirectX9==<br /> <br /> Error:An unhandled exception of type 'System.DllNotFoundException' occurred in SharpDX.XInput.dll Additional information: Unable to load DLL 'xinput1_3.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)<br /> <br /> XInput library may be missing if you have a fresh install of win8.1 or 10<br /> <br /> Solution: Install DirectX 9 Runtime http://www.microsoft.com/en-us/download/confirmation.aspx?id=8109 or http://www.microsoft.com/en-us/download/details.aspx?id=35<br /> <br /> ==Unity Basics and Movement==<br /> Demo add Art and setup folders<br /> <br /> Movement script <br /> <br /> parameter<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> public Vector3 Direction = new Vector3(1, 0, 0);<br /> public float Speed = 5;<br /> &lt;/syntaxhighlight&gt;<br /> Update<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> void Update () {<br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> Full Script with wall bouncing<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using UnityEngine;<br /> using System.Collections;<br /> <br /> public class SimpleMove : MonoBehaviour {<br /> <br /> <br /> public Vector3 Direction = new Vector3(1, 0, 0);<br /> public float Speed = 5;<br /> <br /> static Vector3 cameraBottomLeft; //calculate camera left<br /> static Vector3 cameraTopRight; //calculate camera top<br /> static Rect cameraRect; //rectangle for camera<br /> <br /> <br /> // Use this for initialization<br /> void Start () {<br /> <br /> cameraBottomLeft = Camera.main.ScreenToWorldPoint(Vector3.zero);<br /> cameraTopRight = Camera.main.ScreenToWorldPoint(new Vector3(<br /> Camera.main.pixelWidth, Camera.main.pixelHeight));<br /> <br /> cameraRect = new Rect(<br /> cameraBottomLeft.x,<br /> cameraBottomLeft.y,<br /> cameraTopRight.x - cameraBottomLeft.x,<br /> cameraTopRight.y - cameraBottomLeft.y);<br /> <br /> }<br /> <br /> // Update is called once per frame<br /> void Update () {<br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> <br /> if (!cameraRect.Contains(this.transform.position))<br /> {<br /> //keep on screen<br /> if (this.transform.position.x &lt;= cameraRect.xMin)<br /> {<br /> <br /> this.Direction.x *= -1;<br /> }<br /> if (this.transform.position.x &gt;= cameraRect.xMax)<br /> {<br /> <br /> this.Direction.x *= -1;<br /> }<br /> if (this.transform.position.y &gt; cameraRect.yMax)<br /> {<br /> <br /> this.Direction.y *= -1;<br /> }<br /> if (this.transform.position.y &lt; cameraRect.yMin)<br /> {<br /> <br /> this.Direction.y *= -1;<br /> }<br /> <br /> }<br /> <br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> and Input from keyboard<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using UnityEngine;<br /> using System.Collections;<br /> <br /> public class SimpleInput : MonoBehaviour {<br /> <br /> <br /> public Vector3 Direction;<br /> public float Speed;<br /> public Vector3 keyDirection;<br /> <br /> // Use this for initialization<br /> void Start () {<br /> <br /> }<br /> <br /> // Update is called once per frame<br /> void Update () {<br /> //input<br /> //direction.x = direction.y = 0;<br /> keyDirection.x = keyDirection.y = 0;<br /> <br /> //Keyboard<br /> if (Input.GetKey(&quot;right&quot;))<br /> {<br /> keyDirection.x += 1;<br /> }<br /> if (Input.GetKey(&quot;left&quot;))<br /> {<br /> keyDirection.x += -1;<br /> }<br /> <br /> if (Input.GetKey(&quot;up&quot;))<br /> {<br /> keyDirection.y += 1;<br /> }<br /> if (Input.GetKey(&quot;down&quot;))<br /> {<br /> keyDirection.y += -1;<br /> }<br /> <br /> Direction += keyDirection;<br /> Direction.Normalize();<br /> <br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> <br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==Homework==<br /> <br /> Moving Game 2 Interesting movement (Mono Game and Unity)<br /> <br /> Update your moving assigment to make the movement more interesting. Use more than 1 input method ie Keyboard, xbox controller, mouse etc.<br /> <br /> Create a Unity Scene with the same sprite and use a script to create similar movement.<br /> <br /> Commit the mongame project and an export of the Unity Scene as a package to SVN or Moodle.<br /> <br /> Repo URL https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/FA16</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class3&diff=22798 Game Programming Class3 2016-09-19T03:03:27Z <p>Jeff: /* Class 3 Input Handling */</p> <hr /> <div>=Class 3 Input Handling=<br /> <br /> '''[http://msdn.microsoft.com/en-us/library/bb203919.aspx 2D Graphics Overview]'''<br /> <br /> About textures and Batching<br /> <br /> [http://msdn.microsoft.com/en-us/library/bb203889.aspx Displays, ViewPorts, Client Bounds]<br /> <br /> <br /> ===Alpha channels===<br /> <br /> Demo<br /> * [http://gimp.org Gimp]<br /> * [http://www.getpaint.net/ Paint.NET]<br /> <br /> ===SpriteBatch=== <br /> <br /> demo project<br /> *IntroSimpleSpriteBatchOptionsWindows.zip <br /> <br /> spriteBatch.Begin();<br /> <br /> [[Image:IntroSpriteModesDemo.png]]<br /> <br /> # Options SpriteBlendMode<br /> # Additive Enable additive blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-3.aspx<br /> # AlphaBlend Enable alpha blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-2.aspx<br /> # None No blending specified.<br /> <br /> <br /> <br /> <br /> <br /> ==Inclass Keyboard input demo==<br /> <br /> &lt;code&gt;<br /> KeyboardState keyboardState = Keyboard.GetState();<br /> <br /> Explore Limitations of Built in Keyboard state. <br /> <br /> &lt;/code&gt;<br /> <br /> ==Input==<br /> input from Game Controller and Keyboard<br /> <br /> '''GamePad'''<br /> [[Image:XBoxGamePadWithLabels.png]]<br /> <br /> XNA has built in support for up to 4 game controllers. The default controller is a x-box controller.<br /> X-Box Controller The Controller is accessed through the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad.aspx GamePad] Object and the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate_members.aspx GamePadState] Structure reference types<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> //Get an instance of the gamePadState Structure<br /> GamePadState gamePad1State = GamePad.GetState(PlayerIndex.One); <br /> <br /> /*Since the Keyboard structure is Windows only we <br /> need to use some preprocessor<br /> directives to only compile the KeyBoard <br /> state code if the target is not XBOX360 (I<br /> should also add zune if this is one of our build targets)<br /> */<br /> #if !XBOX360<br /> #region KeyBoard<br /> KeyboardState keyboardState = Keyboard.GetState();<br /> #endif<br /> <br /> &lt;/syntaxhighlight&gt;<br /> <br /> Angle Measured in Radians<br /> <br /> using [http://msdn.microsoft.com/en-us/library/system.math.atan2.aspx atan2] to get the angle from the direction vector<br /> <br /> <br /> IntroSimpleSpriteUpdateRotateWindows Project<br /> <br /> SpriteJump Project<br /> <br /> ==Input Error missing DirectX9==<br /> <br /> Error:An unhandled exception of type 'System.DllNotFoundException' occurred in SharpDX.XInput.dll Additional information: Unable to load DLL 'xinput1_3.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)<br /> <br /> XInput library may be missing if you have a fresh install of win8.1 or 10<br /> <br /> Solution: Install DirectX 9 Runtime http://www.microsoft.com/en-us/download/confirmation.aspx?id=8109 or http://www.microsoft.com/en-us/download/details.aspx?id=35<br /> <br /> ==Unity Basics and Movement==<br /> Demo add Art and setup folders<br /> <br /> Movement script <br /> <br /> parameter<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> public Vector3 Direction = new Vector3(1, 0, 0);<br /> public float Speed = 5;<br /> &lt;/syntaxhighlight&gt;<br /> Update<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> void Update () {<br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> Full Script with wall bouncing<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using UnityEngine;<br /> using System.Collections;<br /> <br /> public class SimpleMove : MonoBehaviour {<br /> <br /> <br /> public Vector3 Direction = new Vector3(1, 0, 0);<br /> public float Speed = 5;<br /> <br /> static Vector3 cameraBottomLeft; //calculate camera left<br /> static Vector3 cameraTopRight; //calculate camera top<br /> static Rect cameraRect; //rectangle for camera<br /> <br /> <br /> // Use this for initialization<br /> void Start () {<br /> <br /> cameraBottomLeft = Camera.main.ScreenToWorldPoint(Vector3.zero);<br /> cameraTopRight = Camera.main.ScreenToWorldPoint(new Vector3(<br /> Camera.main.pixelWidth, Camera.main.pixelHeight));<br /> <br /> cameraRect = new Rect(<br /> cameraBottomLeft.x,<br /> cameraBottomLeft.y,<br /> cameraTopRight.x - cameraBottomLeft.x,<br /> cameraTopRight.y - cameraBottomLeft.y);<br /> <br /> }<br /> <br /> // Update is called once per frame<br /> void Update () {<br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> <br /> if (!cameraRect.Contains(this.transform.position))<br /> {<br /> //keep on screen<br /> if (this.transform.position.x &lt;= cameraRect.xMin)<br /> {<br /> <br /> this.Direction.x *= -1;<br /> }<br /> if (this.transform.position.x &gt;= cameraRect.xMax)<br /> {<br /> <br /> this.Direction.x *= -1;<br /> }<br /> if (this.transform.position.y &gt; cameraRect.yMax)<br /> {<br /> <br /> this.Direction.y *= -1;<br /> }<br /> if (this.transform.position.y &lt; cameraRect.yMin)<br /> {<br /> <br /> this.Direction.y *= -1;<br /> }<br /> <br /> }<br /> <br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> and Input from keyboard<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using UnityEngine;<br /> using System.Collections;<br /> <br /> public class SimpleInput : MonoBehaviour {<br /> <br /> <br /> public Vector3 Direction;<br /> public float Speed;<br /> public Vector3 keyDirection;<br /> <br /> // Use this for initialization<br /> void Start () {<br /> <br /> }<br /> <br /> // Update is called once per frame<br /> void Update () {<br /> //input<br /> //direction.x = direction.y = 0;<br /> keyDirection.x = keyDirection.y = 0;<br /> <br /> //Keyboard<br /> if (Input.GetKey(&quot;right&quot;))<br /> {<br /> keyDirection.x += 1;<br /> }<br /> if (Input.GetKey(&quot;left&quot;))<br /> {<br /> keyDirection.x += -1;<br /> }<br /> <br /> if (Input.GetKey(&quot;up&quot;))<br /> {<br /> keyDirection.y += 1;<br /> }<br /> if (Input.GetKey(&quot;down&quot;))<br /> {<br /> keyDirection.y += -1;<br /> }<br /> <br /> Direction += keyDirection;<br /> Direction.Normalize();<br /> <br /> <br /> //Move Pacman<br /> this.transform.position += this.Direction * this.Speed * Time.deltaTime;<br /> <br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==Homework==<br /> <br /> Moving Game 2 Interesting movement (Mono Game and Unity)<br /> <br /> Update your moving assigment to make the movement more interesting. Use more than 1 input method ie Keyboard, xbox controller, mouse etc.<br /> <br /> Create a Unity Scene with the same sprite and use a script to create similar movement.<br /> <br /> Commit the mongame project and an export of the Unity Scene as a package to SVN or Moodle.<br /> <br /> Repo URL https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/FA16</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=Game_Programming_Class2&diff=22797 Game Programming Class2 2016-09-19T03:03:02Z <p>Jeff: </p> <hr /> <div><br /> ==Objectives==<br /> *Time corrected move bases on elapsed game time Monogame<br /> *Vector2 for direction with and without magnitude<br /> *Single responsibility principal for methods<br /> <br /> ==Skills==<br /> *Get samples from SVN and Git<br /> <br /> ==Fonts==<br /> <br /> free game fonts [http://creators.xna.com/en-us/contentpack/fontpack XNA Redistributable Font Pack]<br /> <br /> [http://geekswithblogs.net/cwilliams/archive/2007/11/03/116573.aspx Fun with Fonts in XNA]<br /> <br /> note this font pack is now included in XNA 4<br /> <br /> ==SVN Checkout==<br /> <br /> All of the examples for this class and the basic game library we wil be building is in our SVN repo this week we'll practice checking out a folder from the repo.<br /> <br /> &lt;!-- https://iam.colum.edu:8443/svn/XNAProg/trunk/Jeff --&gt;<br /> <br /> Tools<br /> * Ahnk SVN for Visual Studio http://visualstudiogallery.msdn.microsoft.com/E721D830-7664-4E02-8D03-933C3F1477F2<br /> * TortoiseSVN http://tortoisesvn.net/<br /> <br /> Repo for Fall 2016<br /> <br /> Trunk : this contains all the old student work as well as my demos so you probably don't want this at least not quite yet<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk<br /> <br /> Just the Jeff folder<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/jeff<br /> <br /> <br /> Demos Projects : this is the link to my demos in SVN<br /> <br /> https://iam.colum.edu:8443/svn/GPMonogame3.5/trunk/jeff<br /> <br /> <br /> tortoisesvn http://tortoisesvn.tigris.org/<br /> <br /> ankhsvn http://ankhsvn.open.collab.net/<br /> <br /> SNV checkout demo.<br /> <br /> In the coming weeks we'll learn how to commit to the SNV. Until then all you need to know is how to checkout.<br /> <br /> ===SVN ingnore git and GIT ignore SVN===<br /> http://stackoverflow.com/questions/21156065/how-to-locally-ignore-git-and-gitignore-in-a-svn-repo<br /> <br /> http://stackoverflow.com/questions/821895/exclude-svn-folders-within-git<br /> <br /> ==Monogame Structures==<br /> Game Class<br /> <br /> The MonogameGame class has two private properties<br /> *GraphicsDeviceManager graphics;<br /> *ContentManager content;<br /> <br /> Graphics for windows and xbox are 60 fps. XBOx supports NTSC resolutions (480i, 480p, 720p, 1080i and 1080p 1080p is only on newer hdmi models).<br /> <br /> &lt;pre&gt;<br /> //the game constuctor can be used to set some graphics settings.<br /> graphics.PreferredBackBufferHeight = 768;<br /> graphics.PreferredBackBufferWidth = 1024;<br /> //graphics.PreferredBackBufferHeight = 1080;<br /> //graphics.PreferredBackBufferWidth = 1920;<br /> //graphics.IsFullScreen = true;<br /> &lt;/pre&gt;<br /> <br /> Graphics for Mobile Game is 30 fps and 480 x 800.<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> // Frame rate is 30 fps by default for Windows Phone. <br /> TargetElapsedTime = TimeSpan.FromTicks(333333); <br /> <br /> // Pre-autoscale settings. <br /> graphics.PreferredBackBufferWidth = 480; <br /> graphics.PreferredBackBufferHeight = 800; <br /> &lt;/syntaxhighlight&gt;<br /> <br /> <br /> # Declare SpriteBatch spriteBatch; <br /> # Initialize()<br /> # LoadContent()<br /> # UnloadContent()<br /> # Update(GameTime gameTime)<br /> <br /> ==Texture2D and SpriteBatches==<br /> simple pacmac bouncing back and forth<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;highlight=&quot;17-20,54,56-60,87,91-96,100,103,119-121&quot;&gt;<br /> using System;<br /> using Microsoft.Xna.Framework;<br /> using Microsoft.Xna.Framework.Graphics;<br /> using Microsoft.Xna.Framework.Input;<br /> <br /> <br /> namespace GameUpdate<br /> {<br /> /// &lt;summary&gt;<br /> /// This is the main type for your game.<br /> /// &lt;/summar&gt;<br /> public class Game1 : Microsoft.Xna.Framework.Game<br /> {<br /> GraphicsDeviceManager graphics;<br /> SpriteBatch spriteBatch;<br /> <br /> Texture2D PacMan;<br /> Vector2 PacManLoc; //Pacman location<br /> Vector2 PacManDir; //Pacman direction<br /> float PacManSpeed; //speed for the PacMan Sprite in pixels per frame per second<br /> <br /> public Game1()<br /> {<br /> graphics = new GraphicsDeviceManager(this);<br /> Content.RootDirectory = &quot;Content&quot;;<br /> <br /> //Change the frame fate to 30 Frames per second the default is 60fps<br /> //TargetElapsedTime = TimeSpan.FromTicks(333333); // you may need to add using System; to get the TimeSpan function<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// Allows the game to perform any initialization it needs to before starting to run.<br /> /// This is where it can query for any required services and load any non-graphic<br /> /// related content. Calling base.Initialize will enumerate through any components<br /> /// and initialize them as well.<br /> /// &lt;/summary&gt;<br /> protected override void Initialize()<br /> {<br /> // TODO: Add your initialization logic here<br /> <br /> base.Initialize();<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// LoadContent will be called once per game and is the place to load<br /> /// all of your content.<br /> /// &lt;/summary&gt;<br /> protected override void LoadContent()<br /> {<br /> // Create a new SpriteBatch, which can be used to draw textures.<br /> spriteBatch = new SpriteBatch(GraphicsDevice);<br /> <br /> // TODO: use this.Content to load your game content here<br /> PacMan = Content.Load&lt;Texture2D&gt;(&quot;pacmanSingle&quot;);<br /> //Center PacMan<br /> PacManLoc = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2,<br /> graphics.GraphicsDevice.Viewport.Height / 2); //Start with PacManLoc in the center of the screen<br /> PacManDir = new Vector2(1, 0); //start moving left<br /> <br /> PacManSpeed = 20; //initial pacman speed<br /> <br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// UnloadContent will be called once per game and is the place to unload<br /> /// all content.<br /> /// &lt;/summary&gt;<br /> protected override void UnloadContent()<br /> {<br /> // TODO: Unload any non ContentManager content here<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// Allows the game to run logic such as updating the world,<br /> /// checking for collisions, gathering input, and playing audio.<br /> /// &lt;/summary&gt;<br /> /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt;<br /> protected override void Update(GameTime gameTime)<br /> {<br /> // Allows the game to exit<br /> if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)<br /> this.Exit();<br /> <br /> // TODO: Add your update logic here<br /> <br /> //Elapsed time since last update will be used to correct movement speed<br /> float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds;<br /> <br /> <br /> //Turn PacMan Around if it hits the edge of the screen<br /> if ((PacManLoc.X &gt; graphics.GraphicsDevice.Viewport.Width - PacMan.Width)<br /> || (PacManLoc.X &lt; 0)<br /> )<br /> {<br /> PacManDir = Vector2.Negate(PacManDir);<br /> }<br /> <br /> //Move PacMan<br /> //Simple move Moves PacMac by PacManDiv on every update<br /> PacManLoc = PacManLoc + PacManDir * PacManSpeed; //no good not time corrected<br /> <br /> //Time corrected move. MOves PacMan By PacManDiv every Second<br /> //PacManLoc = PacManLoc + ((PacManDir * PacManSpeed) * (time/1000)); //Simple Move PacMan by PacManDir<br /> <br /> <br /> <br /> base.Update(gameTime);<br /> }<br /> <br /> /// &lt;summary&gt;<br /> /// This is called when the game should draw itself.<br /> /// &lt;/summary&gt;<br /> /// &lt;param name=&quot;gameTime&quot;&gt;Provides a snapshot of timing values.&lt;/param&gt;<br /> protected override void Draw(GameTime gameTime)<br /> {<br /> graphics.GraphicsDevice.Clear(Color.CornflowerBlue);<br /> <br /> // TODO: Add your drawing code here<br /> spriteBatch.Begin();<br /> spriteBatch.Draw(PacMan, PacManLoc, Color.White);<br /> spriteBatch.End();<br /> <br /> base.Draw(gameTime);<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> ==GameTime==<br /> FrameRate and GameTime<br /> * [http://msdn.microsoft.com/en-us/library/bb203873.aspx#ID2EYB Game Loop Timing]<br /> * [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.gametime_members.aspx Game Time Members]<br /> <br /> ===Time and Timespan===<br /> Example of update using GameTime to calculate elapsed time <br /> <br /> Demo<br /> <br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleUpdateMovement SimpleUpdateMovement] : move with Keyboard<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementWGravity SimpleUpdateMovementWGravity]: simple gravity moves sprite down<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleUpdateMovementWState SimpleUpdateMovementWState]: better movement show different types with state selector<br /> *[https://github.com/dsp56001/GameProgramming/tree/master/Monogame/3.5/SimpleMovementJump SimpleMovementJump]: Very simple Jump and Gravity<br /> <br /> <br /> Understanding GameTime We'll revisit game time when we talk about performance profiling.<br /> <br /> ==Homework==<br /> *Interesting Movement Monogame : Create a Monogame project the uses keyboard input to move a sprite. The movement should be more interesting than linear up, down, left right. There are several examples of this in the SimpleUpdateMovementWState project. The sprite movement should be time corrected and frame rate independant.<br /> <br /> *Gravity and or Jump with 2 sprites<br /> **Start with SimpleUpdateMovementWGravity or SimpleMovementJump<br /> **How many sprites can you draw?<br /> **Can they have different controls?<br /> **Can you use a class to make the code more organized?<br /> <br /> <br /> Optional Reading<br /> <br /> *Read Chapter 2 in XNA 3.0<br /> *Read Chapter 4 in XNA 3.0 (yes we skipped 3 we'll come back)<br /> <br /> Extra Bonus<br /> <br /> http://advances.realtimerendering.com/s2016/Siggraph2016_idTech6.pdf<br /> <br /> ==Links==<br /> *[http://msdn.microsoft.com/en-us/library/bb194908.aspx How To: Draw a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb203866.aspx How To: Animate a Sprite] <br /> *[http://msdn.microsoft.com/en-us/library/bb203867.aspx How To: Draw a Masked Sprite over a Background]<br /> *[http://msdn.microsoft.com/en-us/library/bb203868.aspx How To: Make a Scrolling Background]<br /> *[http://msdn.microsoft.com/en-us/library/bb203869.aspx How To: Rotate a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb194912.aspx How To: Rotate a Group of Sprites]<br /> *[http://msdn.microsoft.com/en-us/library/bb194913.aspx How To: Scale a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb194914.aspx How To: Tint a Sprite]<br /> *[http://msdn.microsoft.com/en-us/library/bb447674.aspx How To: Scale Sprites Based On Screen Size]</div> Jeff https://imamp.colum.edu/mediawiki/index.php?title=OOP_Class2&diff=22796 OOP Class2 2016-09-13T02:06:33Z <p>Jeff: /* Terms */</p> <hr /> <div>[[Category:Object Oriented Programming]]<br /> ==Posting home work and website==<br /> <br /> review Posting homework to moodle<br /> <br /> =C# fundamentals=<br /> <br /> Questions from week 1 reading.<br /> discussion<br /> <br /> Some pages comparing c# to other languages<br /> <br /> A Comparative Overview of C# http://genamics.com/developer/csharp_comparative.htm<br /> <br /> C# and Java: Comparing Programming Languages http://msdn.microsoft.com/en-us/library/ms836794.aspx<br /> <br /> ==Terms==<br /> <br /> CLR<br /> :Common Language Runtime https://en.wikipedia.org/wiki/Common_Language_Runtime<br /> namespace<br /> :organizing classes with hierarchy <br /> keyword<br /> :reserved system word<br /> MSIL<br /> :MicroSoft Intermediary Language<br /> JIT<br /> :Just In Time compilation @ first run https://en.wikipedia.org/wiki/Just-in-time_compilation<br /> <br /> ==Everything is an Object==<br /> In c# everything is an object. And all objects inherit from the object class.<br /> <br /> [http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx See object in the classbrowser]<br /> <br /> Since all objects inherit from the object class they all have some the basic functionality like a method called ToString();<br /> <br /> [https://github.com/mono/mono/blob/mono-2-0/mcs/class/corlib/System/Object.cs See the source for object.cs from mono]<br /> <br /> ==Basic Data Types==<br /> <br /> C# is a strongly typed language. This means every object in C# must be declared to be of a specific type. All of c# basic varible type inherit from [http://msdn2.microsoft.com/en-us/library/system.object.aspx System.Object]<br /> <br /> {{.NET Data Types}}<br /> <br /> Variables must be declared with an identifier and then initialized.<br /> <br /> ===Declaration===<br /> <br /> Declaration sets aside a named section of memory the is the proper size to hold the declared type. At this point the variable contains nothing.<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;// declare a variable<br /> int firstInt; //declares a vaiable of type int<br /> string myString; //declares a vaiable of type string&lt;/syntaxhighlight&gt;<br /> <br /> ===Initialization===<br /> <br /> Initialization actually sets the variables value<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;// initialize the variable<br /> firstInt = 1;<br /> myString = &quot;Hello!&quot;;&lt;/syntaxhighlight&gt;<br /> <br /> Initialization uses the assignment operator to set the value of a variable<br /> <br /> ===Assignment===<br /> The Assignment '''operator''' in c# is the '=' sign. You can assign variables like this...<br /> <br /> ==Assignment==<br /> The Assignment operator in c# is the '=' sign. You can assign variables like this...We'll learn more about operators later.<br /> <br /> other ways to do it<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;// declare some variables<br /> int secondInt, thirdInt, fourthInt;<br /> secondInt = 2;<br /> thirdInt = 3;<br /> fourthInt = 4;<br /> <br /> //declare and initialize variables in one line<br /> int myNegativeInt = -2147483648;&lt;/syntaxhighlight&gt;<br /> <br /> In c# variables cannot be used unil they are initalized.<br /> For example<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;int UsedBeforeInit;<br /> Console.WriteLine(UsedBeforeInit);&lt;/syntaxhighlight&gt;<br /> <br /> will produce<br /> <br /> helloError4.cs(10,31): error CS0165: Use of unassigned local variable 'UsedBeforeInit'<br /> <br /> ==Variable Names==<br /> <br /> Variable should be named with meaningful names.<br /> <br /> for exmaple <br /> :z = x * y;<br /> <br /> does not convey any meaning<br /> <br /> but<br /> :distance = speed * time;<br /> <br /> does convey meaning.<br /> If varibales are named properly it can make your code mush easier to read.<br /> <br /> ==Naming conventions==<br /> Name variables intelligently.<br /> <br /> Name variables with names that have meaning.<br /> <br /> ===Hungarian Notation===<br /> Hungarian notation id a popular notation system used be many C, C++ and VB programmers. It was originally devised in Charles Simonyi's doctoral thesis, &quot;Meta-Programming: A Software Production Method.&quot; Hungarian notation specifies that a prefix be added to each variable that indicated that variables type. It also specifies sometimes adding a suffice to clarify variables meaning. In the early 1980's Microsoft adopted this notation system.<br /> <br /> <br /> ie... intHitCounter, intHitsPerMonthMax <br /> <br /> [http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx Hungarian Notation - Charles Simonyi Microsoft]<br /> <br /> http://msdn.microsoft.com/en-us/library/ms229045.aspx<br /> <br /> '''PascalNotation'''<br /> Capitalize first Letter and then the first letter on each word.<br /> <br /> ie... PascalNotation, IntVarName<br /> <br /> Use on method names method names.<br /> <br /> '''camelNotation'''<br /> Lower case first letter and then capitalize the first letter of each word<br /> <br /> ie... camelNotation, intVarName<br /> <br /> use for variable names<br /> <br /> Other Coding Techniques and practices&lt;br&gt;<br /> *[http://msdn.microsoft.com/en-us/library/ms229002.aspx .NET Framework Developer's Guide Guidelines for Names]<br /> *[http://www-106.ibm.com/developerworks/eserver/articles/hook_duttaC.html?ca=dgr-lnxw06BestC IBM Best Practices for Programming in C]<br /> *[http://www.gnu.org/prep/standards/standards.html GNU Coding Standards]<br /> *[http://www.gnu.org/prep/standards/standards.html#Names GNU Naming conventions]<br /> <br /> More Types<br /> <br /> ==Operators==<br /> <br /> ECMA-334 Operators and punctuators<br /> <br /> C# uses the equals = sign for Assignment<br /> <br /> int myVar = 15; //sets the value of myVar to 15<br /> <br /> ===Mathematical Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |+ ||addition<br /> |-<br /> |- || subtraction<br /> |-<br /> |* || multiplication<br /> |-<br /> |/ || division<br /> |-<br /> |% || modulus remainder Ask Dr.Math What is Modulus?<br /> |}<br /> <br /> ===Increment Decrement Operators===<br /> {|-<br /> |Operator || Description <br /> |-<br /> |++ || increment same as foo = foo + 1<br /> |-<br /> | -- || decrement same as foo = foo - 1<br /> |-<br /> |+= || calculate and reassign addition<br /> |-<br /> | -= || calculate and reassign subtraction<br /> |-<br /> |*= || calculate and reassign multiplication<br /> |-<br /> |/= || calculate and reassign division<br /> |-<br /> |%= || calculate and reassign modulus<br /> |-<br /> |y= x++ || assignment prefix y is assigned to x and then x in incremented<br /> |-<br /> |y= ++x || assignment postfix x is incremented and then assigned to y<br /> |}<br /> <br /> ===Operator Precedence===<br /> Evaluated First<br /> <br /> * ++,--,unary-<br /> * *,/,%<br /> * +,-<br /> <br /> Evaluated Last<br /> <br /> * =,+=,-=,*=,etc<br /> <br /> <br /> {{csharp strings}}<br /> {{csharp string functions}}<br /> <br /> ==Short Assignment==<br /> Short in class Assignment<br /> In class assignment 10-15 mins<br /> Build a c# console app (remember to take a top down aproach start small with something you know maybe start with hello world)<br /> * Declare and initialize two integers<br /> * Display their values using Console.WriteLine<br /> * Declare a third integer and initialize it with the sum of the first two integers<br /> * Output the value of the third integer<br /> <br /> <br /> Top down development with comments [http://iam.colum.edu/oop/classsource/class2/topdown.aspx topdown.aspx]<br /> <br /> Fully implemented Console adding program [http://iam.colum.edu/poop/gbrowser.php?file=/classsource/class2/add.cs add.cs]<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;<br /> using System;<br /> using System.Collections.Generic;<br /> using System.Text;<br /> <br /> namespace Hello<br /> {<br /> class Program<br /> {<br /> static void Main(string[] args)<br /> {<br /> Console.WriteLine(&quot;Super Cool Calculatorizer&quot;);<br /> <br /> //Declare two variables<br /> int intOne;<br /> int intTwo;<br /> int intSum;<br /> <br /> //intialize the two variables<br /> intOne = 47;<br /> intTwo = 2;<br /> <br /> //Lets test the values<br /> Console.Write(&quot;Enter a integer: &quot;);<br /> intOne = int.Parse(Console.ReadLine()); //set the value of intOne <br /> //to what was typed in the console<br /> Console.Write(&quot;Enter another integer: &quot;);<br /> intTwo = int.Parse(Console.ReadLine()); //int.Parse attempts to parse a string<br /> //and convert it to an int<br /> <br /> intSum = intOne + intTwo;<br /> <br /> Console.WriteLine(&quot;intTwo + intTwo = &quot; + intSum);<br /> <br /> Console.ReadKey();<br /> <br /> }<br /> }<br /> }<br /> &lt;/syntaxhighlight&gt;<br /> <br /> ==Constants==<br /> <br /> Constants are datatypes that will be assigned a value that will be constant thought the executing of the code. You cannot change constants once they have been assigned a value.<br /> syntax<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;const type identifier = value;&lt;/syntaxhighlight&gt;<br /> <br /> <br /> example<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;const int freezingPoint = 32;<br /> const int freezingPointMetric = 0;<br /> const float pi = 3.141592&lt;/syntaxhighlight&gt;<br /> <br /> <br /> [[OOP Arrays]]<br /> {{csharp arrays}}<br /> <br /> <br /> ==Simple Branching==<br /> <br /> ===if===<br /> syntax<br /> <br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;if (expression)<br /> // statement<br /> <br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> if (expression) {<br /> // statements<br /> // statements<br /> }<br /> else {<br /> // statements<br /> }&lt;/syntaxhighlight&gt;<br /> <br /> ==HomeWork==<br /> *Learning c#<br /> *Chapter 5, Chapter 6<br /> <br /> Assignments<br /> <br /> 1.Create a simple text game that asks three questions and sets three variables. There should be a fourth variable that counts the number of correct answers. The program should run in the console and use:<br /> <br /> *Console.WriteLine<br /> *Console.ReadLine<br /> *ints, strings and ifs<br /> <br /> Analysis of Homework Project<br /> *On very structured programs like this one analysis is quite easy<br /> ** Start by identifying the steps<br /> ** Add [http://en.wikipedia.org/wiki/Pseudocode Pseudocode] as c# comments for each step<br /> ** Fill in the real syntax for each step and compile each time to make sure nothing breaks (I like to call this baby steps and I like to use this technique whenever I'm trying to implement something that is completely new to me)<br /> <br /> The pseudocode might look something like<br /> &lt;syntaxhighlight lang=&quot;csharp&quot;&gt;using System;<br /> namespace HelloVariables<br /> {<br /> class ThreeQuestions<br /> {<br /> public static void Main()<br /> {<br /> Console.WriteLine(&quot;3 Questions&quot;);<br /> //A simple game that asks three questions and checks the answers. If the question is answered correctly we will award 1 point<br /> <br /> //Declare Variables<br /> <br /> //Ask Question 1<br /> <br /> //Read Answer<br /> <br /> //Check Answer and add 1 to points is correct<br /> <br /> //Repeat with Questions 2 and 3<br /> <br /> //Display Percent Correct<br /> <br /> }<br /> }<br /> }&lt;/syntaxhighlight&gt;<br /> <br /> 2. Broken Toaster Week 2 in Moodle<br /> <br /> 3. Watch http://www.microsoftvirtualacademy.com/training-courses/c-fundamentals-for-absolute-beginners<br /> *05 Quick Overview of the Visual C# Express Edition IDE 30 Mins<br /> *06 Declaring Variables and Assigning Values Duration 28 Mins<br /> *07 Branching with the if Decision Statement and the Conditional Operator 19 Mins<br /> <br /> Download the BrokenToaster project and fix the errors so that it creates the correct output. You may change any source you need to create the output. The program flow inputs and outputs should remain in tact. Points will be awarded modifications made to achieve the correct interaction and output.<br /> <br /> ==Video==<br /> &lt;html&gt;<br /> &lt;script type='text/javascript' src='http://iam.colum.edu/videotutorials/mediaplayer-5.2/swfobject.js'&gt;&lt;/script&gt; <br /> &lt;div id='mediaspace2'&gt;This text will be replaced&lt;/div&gt; <br /> &lt;script type='text/javascript'&gt;<br /> var so = new SWFObject('http://iam.colum.edu/videotutorials/mediaplayer-5.2/player.swf','mpl','800','600','9');so.addParam('allowfullscreen','true')<br /> ;so.addParam('allowscriptaccess','always');<br /> so.addParam('wmode','opaque');<br /> so.addVariable('file','http://iam.colum.edu/screenz/FA13/OOP_MT/OOP_Week_2/OOP_Week_2.mp4');<br /> so.addVariable('autostart','false');<br /> so.write('mediaspace2');<br /> <br /> &lt;/script&gt;<br /> <br /> &lt;/html&gt;</div> Jeff