Skip to content

Commit

Permalink
Created a new project called Textured Primitives
Browse files Browse the repository at this point in the history
Copied over class files from previous project. Still need to update
namespace. Doesn't compile yet but no biggy. P44
  • Loading branch information
P4r4d0x42 committed Jun 13, 2015
1 parent e38ba19 commit 72f9e80
Show file tree
Hide file tree
Showing 14 changed files with 472 additions and 0 deletions.
Binary file modified GameWindowSize/GameWindowSize.v11.suo
Binary file not shown.
20 changes: 20 additions & 0 deletions Textured Primitives/Textured Primitives.sln
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Textured Primitives", "Textured Primitives\Textured Primitives.csproj", "{7E562CD9-173C-4FA8-8163-AF49F4DF7015}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7E562CD9-173C-4FA8-8163-AF49F4DF7015}.Debug|x86.ActiveCfg = Debug|x86
{7E562CD9-173C-4FA8-8163-AF49F4DF7015}.Debug|x86.Build.0 = Debug|x86
{7E562CD9-173C-4FA8-8163-AF49F4DF7015}.Release|x86.ActiveCfg = Release|x86
{7E562CD9-173C-4FA8-8163-AF49F4DF7015}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added Textured Primitives/Textured Primitives.v11.suo
Binary file not shown.
121 changes: 121 additions & 0 deletions Textured Primitives/Textured Primitives/Game1.cs
@@ -0,0 +1,121 @@
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.GamerServices;
#endregion

namespace GameWindowSize
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

// Prefer window size
const int kWindowWidth = 1000;
const int kWindowHeight = 700;

public Game1()
: base()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";

// Set preferred window size
graphics.PreferredBackBufferWidth = kWindowWidth;
graphics.PreferredBackBufferHeight = kWindowHeight;

}

/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

// TODO: use this.Content to load your game content here
}

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows game to exit. F1 should also work due to mapping in InputWrapper class
if (InputWrapper.Buttons.Back == ButtonState.Pressed)
Exit();

// "A" to toggle to full-screen mode ("k" on keyboard)
if (InputWrapper.Buttons.A == ButtonState.Pressed)
{
if (!graphics.IsFullScreen)
{
graphics.IsFullScreen = true;
graphics.ApplyChanges();
}
}

// "B" toggles back to window mode ("L" on keyboard)
if (InputWrapper.Buttons.B == ButtonState.Pressed)
{
if (graphics.IsFullScreen)
{
graphics.IsFullScreen = false;
graphics.ApplyChanges();
}
}



base.Update(gameTime);
}

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: Add your drawing code here

base.Draw(gameTime);
}
}
}
Binary file added Textured Primitives/Textured Primitives/Icon.ico
Binary file not shown.
194 changes: 194 additions & 0 deletions Textured Primitives/Textured Primitives/InputWrapper.cs
@@ -0,0 +1,194 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

internal struct AllInputButtons
{
private const Keys kA_ButtonKey = Keys.K;
private const Keys kB_ButtonKey = Keys.L;
private const Keys kX_ButtonKey = Keys.J;
private const Keys kY_ButtonKey = Keys.I;
private const Keys kBack_ButtonKey = Keys.F1;
private const Keys kStart_ButtonKey = Keys.F2;


private ButtonState GetState(ButtonState gameButtonState, Keys key)
{
if (Keyboard.GetState().IsKeyDown(key))
return ButtonState.Pressed;

if (GamePad.GetState(PlayerIndex.One).IsConnected)
return gameButtonState;

return ButtonState.Released;

}

// Assessors
public ButtonState A
{
get {return GetState(GamePad.GetState(PlayerIndex.One).Buttons.A, kA_ButtonKey);}
}

public ButtonState B
{
get { return GetState(GamePad.GetState(PlayerIndex.One).Buttons.B, kB_ButtonKey); }
}

public ButtonState Back
{
get { return GetState(GamePad.GetState(PlayerIndex.One).Buttons.Back, kBack_ButtonKey); }
}

public ButtonState Start
{
get { return GetState(GamePad.GetState(PlayerIndex.One).Buttons.Start, kStart_ButtonKey); }
}

public ButtonState X
{
get { return GetState(GamePad.GetState(PlayerIndex.One).Buttons.X, kX_ButtonKey); }
}

public ButtonState Y
{
get { return GetState(GamePad.GetState(PlayerIndex.One).Buttons.Y, kY_ButtonKey); }
}
}

internal struct AllInputTriggers
{
private const Keys KLeftTrigger = Keys.N;
private const Keys KRightTrigger = Keys.M;
const float kKeyTriggerValue = 0.75f;

private float GetTriggerState(float gamePadTrigger, Keys key)
{
if (Keyboard.GetState().IsKeyDown(key)) // checks for keyboard input first and overrides the game pad if found
return kKeyTriggerValue;

if(GamePad.GetState(PlayerIndex.One).IsConnected)
return gamePadTrigger;

return 0f; // If you get here, it's not in use
}


public float Left
{
get { return GetTriggerState(GamePad.GetState(PlayerIndex.One).Triggers.Left, KLeftTrigger);}
}

public float Right
{
get { return GetTriggerState(GamePad.GetState(PlayerIndex.One).Triggers.Right, KRightTrigger); }
}

}

internal struct AllThumbSticks
{
private const Keys kLeftThumbStickUp = Keys.W;
private const Keys kLeftThumbStickDown = Keys.S;
private const Keys kLeftThumbStickLeft = Keys.A;
private const Keys kLeftThumbStickRight = Keys.D;

private const Keys kRightThumbStickUp = Keys.Up;
private const Keys kRightThumbStickDown = Keys.Down;
private const Keys kRightThumbStickLeft = Keys.Left;
private const Keys kRightThumbStickRight = Keys.Right;

private const float kKeyDownValue = 0.75f;

private Vector2 ThumbStickState(Vector2 thumbStickValue,
Keys up, Keys down, Keys left, Keys right)
{
Vector2 r = new Vector2(0f, 0f);
if ((GamePad.GetState(PlayerIndex.One).IsConnected)) // TODO: See why there are two () here instead of the normal single of an if statement. Is it some sort of formatting convention?
{
r = thumbStickValue;
}
if (Keyboard.GetState().IsKeyDown(up)) // checks for keyboard input first and overrides the game pad if found
r.Y += kKeyDownValue;
if (Keyboard.GetState().IsKeyDown(down)) // checks for keyboard input first and overrides the game pad if found
r.Y -= kKeyDownValue;
if (Keyboard.GetState().IsKeyDown(left)) // checks for keyboard input first and overrides the game pad if found
r.X -= kKeyDownValue;
if (Keyboard.GetState().IsKeyDown(right)) // checks for keyboard input first and overrides the game pad if found
r.X += kKeyDownValue;

return r;
}

public Vector2 Left
{
get {
return ThumbStickState(GamePad.GetState(PlayerIndex.One).ThumbSticks.Left,
kLeftThumbStickUp,kLeftThumbStickDown,
kLeftThumbStickLeft,kLeftThumbStickRight);
}
}

public Vector2 Right
{
get
{
return ThumbStickState(GamePad.GetState(PlayerIndex.One).ThumbSticks.Right,
kRightThumbStickUp, kRightThumbStickDown,
kRightThumbStickLeft, kRightThumbStickRight);
}
}
}

internal struct AllInputMouse
{
//private const ButtonState kLeftButton = ButtonState.Pressed;
public Vector2 MousePosition { get; private set; }

private ButtonState GetState(ButtonState gameMouseButtonState)
{

if (gameMouseButtonState == ButtonState.Pressed )
{
MousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); // Update mouse position in this struct only if a button is pressed.
return ButtonState.Pressed;
}


return ButtonState.Released;
}

public ButtonState LeftButton
{
get { return GetState(Mouse.GetState().LeftButton); }
}

public ButtonState RightButton
{
get { return GetState(Mouse.GetState().RightButton); }
}

public ButtonState MiddleButton
{
get { return GetState(Mouse.GetState().MiddleButton); }
}

public ButtonState XButton1
{
get { return GetState(Mouse.GetState().XButton1); }
}

public ButtonState XButton2
{
get { return GetState(Mouse.GetState().XButton2); }
}
}


static class InputWrapper
{
static public AllInputButtons Buttons = new AllInputButtons();
static public AllThumbSticks ThumbSticks = new AllThumbSticks();
static public AllInputTriggers Triggers = new AllInputTriggers();
static public AllInputMouse Mouse = new AllInputMouse();
}

26 changes: 26 additions & 0 deletions Textured Primitives/Textured Primitives/Program.cs
@@ -0,0 +1,26 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
#endregion

namespace Textured_Primitives
{
#if WINDOWS || LINUX
/// <summary>
/// The main class.
/// </summary>
public static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
using (var game = new Game1())
game.Run();
}
}
#endif
}

0 comments on commit 72f9e80

Please sign in to comment.