Aside from that, I got some code in that makes the controller vibrate every 2 seconds, it's rather fun...although if you don't change the vibration back to 0, 0, it'll keep vibrating. o.o Only way to fix that is unplug it.
Other than that, I found more about the variables used for the controller, like how the analog sticks use a normalized vector (basically max of 1 in either x or y) for its direction, which is very logical and useful. The triggers also use a float to determine how far pressed they are. I notice some FPS games basically use a hair trigger for shooting, and it drives me nuts that you can basically tap the right trigger or left trigger, and it'll fire. It seems like something that could easily be customized by the user, how far they have to press before firing. I suppose there's hardware out there that's for it, kind of like the resistors on the Onza sticks.
Anyway, as for the last thing in my title, I set up a system in my game for making cheat codes using a string...>.> So basically what it does is use a timer, whenever you click a button, the timer is reset to 0, once it hits 60 (1 second at 60 FPS), it resets the combo text. So basically if you can type in a combo within 1 second of each press, you can create a cheat code...I decided to use the epically amazing Konami Code as my example, so the combo text is basically "upupdowndownleftrightleftrightba", although this can easily be shortened if you really wanted to...Once the konami code is inputted, it displays a lovely little text of "SHAZAM BITCHES!" under all the other mumbo jumbo in my test.
So that's basically the display of the program. I created a TextObject class, which basically draws a single string to the screen with a black background. This is the basic class for the object:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace InputTesting360
{
public class TextObject : DrawableGameComponent
{
public string text;
public Vector2 pos;
public SpriteFont font;
protected Game1 parent;
protected bool vibrate;
protected int timer;
protected const int maxTimer = 60;
protected string combo;
protected GamePadState prevState;
protected string output;
public TextObject(Game1 game, SpriteFont font) : base(game)
{
this.parent = game;
this.font = font;
vibrate = false;
timer = 0;
output = "";
}
public override void Update(GameTime gameTime)
{
//Might make the text follow the mouse around, or maybe the controller.
GamePadState gps = GamePad.GetState(PlayerIndex.One);
bool a, b, x, y, dup, ddn, dlf, drt;
a = gps.IsButtonDown(Buttons.A) && prevState.IsButtonUp(Buttons.A);
b = gps.IsButtonDown(Buttons.B) && prevState.IsButtonUp(Buttons.B);
x = gps.IsButtonDown(Buttons.X) && prevState.IsButtonUp(Buttons.X);
y = gps.IsButtonDown(Buttons.Y) && prevState.IsButtonUp(Buttons.Y);
dup = gps.IsButtonDown(Buttons.DPadUp) && prevState.IsButtonUp(Buttons.DPadUp);
ddn = gps.IsButtonDown(Buttons.DPadDown) && prevState.IsButtonUp(Buttons.DPadDown);
dlf = gps.IsButtonDown(Buttons.DPadLeft) && prevState.IsButtonUp(Buttons.DPadLeft);
drt = gps.IsButtonDown(Buttons.DPadRight) && prevState.IsButtonUp(Buttons.DPadRight);
text = "Packet#: " + gps.PacketNumber;
text += "\nController 1 is connected? " + gps.IsConnected.ToString();
text += "\nLeftStick Vector: " + gps.ThumbSticks.Left.ToString();
text += "\nRightStick Vector: " + gps.ThumbSticks.Right.ToString();
text += "\nLeft Trigger: " + gps.Triggers.Left;
text += "\nRight Trigger: " + gps.Triggers.Right;
text += "\n" + output;
if (a)
{
combo += "a";
timer = 0;
}
if (b)
{
combo += "b";
timer = 0;
}
if (dup)
{
combo += "up";
timer = 0;
}
if (ddn)
{
combo += "down";
timer = 0;
}
if (dlf)
{
combo += "left";
timer = 0;
}
if (drt)
{
combo += "right";
timer = 0;
}
if (combo == "upupdowndownleftrightleftrightba")
{
output = "SHAZAM BITCHES!";
}
timer++;
if (timer >= maxTimer)
{
timer = 0;
combo = "";
//output = "";
}
prevState = gps;
}
public override void Draw(GameTime gameTime)
{
parent.batch.Begin();
parent.batch.DrawString(font, text, pos, Color.White);
parent.batch.End();
}
}
}
Unfortunately I don't know how to add in code snippets, if I did, I would totally do it. -_- But yeah, this, added onto the following Game1 class would give you everything you need to load the game, excluding the TNR14 variable. That's just a TimesNewRoman size 14 font I use...
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace InputTesting360
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
public SpriteBatch batch;
TextObject text;
SpriteFont font;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <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.
batch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("TNR14");
text = new TextObject(this, font);
Components.Add(text);
// 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)
{
// TODO: Add your update logic here
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.Black);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
No comments:
Post a Comment