Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 17 Mar 2006
Offline Last Active Jul 17 2013 09:35 AM

Topics I've Started

Language Advice

21 May 2013 - 08:55 PM


First and foremost, I'm very very sorry for creating another thread about this same topic. I've been searching the internet for opinions regarding this, but there's quite the diversity in responses it appears. Basically, I'm in a pickle between learning C++ and C# at this point. I'd like to elaborate for those who are interested in helping me.


I've been programming for many years, on and off, originally learning C++ and then migrating to C# when I realized how much easier it was. I absolutely love to program, but when I start to need to learn the "intermediate" or "advanced" topics of a language, I start to get discouraged and stop programming for months. I want to dedicate an hour or two of my time each day for the next year or so to just learn a language from the absolute basics to the more advanced topics. I don't just want to develop games, I want to become a programmer. I know for a fact that I'll have to learn C++ at one point in my life, but when I think about pointers, linked lists, algorithms, etc., I just want to immediately say "nope" and go back to C# where it's nice and cozy and I have someone holding my hand.


Basically, I'm relatively comfortable with both; with C++ I stopped using it when pointers were involved, and with C#, I stopped when I realized I had no idea what dictionaries do, how to do exception handling, or how to handle events. I want to become a programmer but I always get intimidated when it comes to more complicated topics and discourage myself from programming the next day. Not only that, but I can't ever find any good resources that appeal and grab my attention, and when I search on the forums, it usually has outdated recommendations that don't really work for me.


Anyways, I hope that covered where I'm at. If you have any recommendations, please feel free to throw them my way. Thanks so much!


TLDR: Stopped learning C++, went to C#, getting stuck at the "harder" subjects for both languages, and now I'm having trouble deciding if I should continue down C# or start to learn C++ now to make myself a better programmer. 

Sprite Facing Mouse

13 November 2012 - 01:44 PM

Hey all,

So I'm trying to have a sprite face my mouse cursor, but with my current code, the sprite is -close-, but it's not fully rotating to face my cursor. I've pasted my Player.cs class below. Right now, I initialize the direction and rotation variables within my Update(GameTime gameTime) class. I've already set the origin to be in the center of the sprite, so I don't think that's causing the issue. Thanks!

[source lang="csharp"]using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Input;using Microsoft.Xna.Framework.Content;using Microsoft.Xna.Framework.Graphics;namespace MyTerribleGame{ class Player { #region Data Fields private Texture2D texture; private Rectangle position; private int health; private int armor; private int lives; private int velocity; private Vector2 direction; private float rotation; #endregion #region Properties public Texture2D Texture { get { return texture; } set { texture = value; } } public Rectangle Position { get { return position; } set { position = value; } } public int Health { get { return health; } set { health = value; } } public int Armor { get { return armor; } set { armor = value; } } public int Lives { get { return lives; } set { lives = value; } } public int Velocity { get { return velocity; } set { velocity = value; } } #endregion #region Constructors // Default Constructor. Will be removed when there's more implementation. public Player() { health = 100; armor = 100; lives = 100; velocity = 10; } // Overloaded Constructor. Possibly will become the new default. public Player(Rectangle position, int health, int armor, int lives, int velocity) { this.position = position; this.health = health; this.armor = armor; this.lives = lives; this.velocity = velocity; } #endregion #region Methods // Load the content of the player class. public void LoadContent(ContentManager Content) { texture = Content.Load<Texture2D>("Player/playerRed"); } // Update the player, such as input, collision detection, etc. public void Update(GameTime gameTime) { direction.X = Input.MousePos.X - position.X; direction.Y = Input.MousePos.Y - position.Y; direction.Normalize(); if (Input.IsKeyDown(Keys.W)) { position.Y -= velocity; } if (Input.IsKeyDown(Keys.S)) { position.Y += velocity; } if (Input.IsKeyDown(Keys.D)) { position.X += velocity; } if (Input.IsKeyDown(Keys.A)) { position.X -= velocity; } rotation = (float)Math.Atan2(direction.Y, direction.X); } // Draw the player to the screen. public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(texture, position, null, Color.White, rotation, new Vector2(position.Width / 2, position.Height / 2), SpriteEffects.None, 0); } // This version of CheckCollision is used to check for collision between the screen and the player. public void CheckCollision(GraphicsDeviceManager graphics) { if (position.X <= 0) position.X += velocity; if (this.position.Y <= 0) position.Y += velocity; if (this.position.X + this.position.Width >= graphics.PreferredBackBufferWidth) position.X -= velocity; if (this.position.Y + this.position.Height >= graphics.PreferredBackBufferHeight) position.Y -= velocity; } // 2D Bounding Box collision b/w the player and an object. public void CheckCollision(Rectangle obj) { // Player -> Object // Right -> Left if (position.Right > obj.Left &amp;amp;&amp;amp; position.Left < obj.Left &amp;amp;&amp;amp; position.Bottom > obj.Top &amp;amp;&amp;amp; position.Top < obj.Bottom) { position.X -= velocity; } // Left -> Right if (position.Left < obj.Right &amp;amp;&amp;amp; position.Right > obj.Right &amp;amp;&amp;amp; position.Bottom > obj.Top &amp;amp;&amp;amp; position.Top < obj.Bottom) { position.X += velocity; } // Top -> Bottom if (position.Top < obj.Bottom &amp;amp;&amp;amp; position.Bottom > obj.Bottom &amp;amp;&amp;amp; position.Right > obj.Left &amp;amp;&amp;amp; position.Left < obj.Right) { position.Y += velocity; } // Bottom -> Top if (position.Bottom > obj.Top &amp;amp;&amp;amp; position.Top < obj.Top &amp;amp;&amp;amp; position.Right > obj.Left &amp;amp;&amp;amp; position.Left < obj.Right) { position.Y -= velocity; } } #endregion }}[/source]

Menu Fading

05 June 2012 - 07:31 PM

Hey everybody!

So I'm working on my own Snake clone using C# and XNA, and I created a very simple state manager to cycle through the menu and game states. I know, I know, "why re-invent the wheel? why not use the GameStateManagement sample?". Honestly, I'm having trouble understanding their code, and need more time to digest it. I don't need a fancy menu or state manager, just the very basics so that I can create a game.

Moving on! I'm trying to add a fade effect to my splash screen. Essentially, I want the screen to slowly become black, and then after five game seconds, switch to the Main Menu state. Unfortunately, when I try to increase the transparency so that it goes from white to black, it just leaves fills in the entire background with a black screen (almost like the new Color(255, 255, 255, fadeValue) argument isn't being called). Here's the source code:

[source lang="csharp"]using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Input;using Microsoft.Xna.Framework.Content;using Microsoft.Xna.Framework.Graphics;namespace Snake{ static class Splash { #region FIELDS // These are the splash screen's data fields. private static Texture2D texture; private static Rectangle position; private static Texture2D spacer; private static int fadeValue = 1; #endregion #region METHODS /// <summary> /// The LoadContent(Content) method will load the default content into memory. /// </summary> /// <param name="Content"></param> public static void LoadContent(ContentManager Content) { // Load the texture for later use. texture = Content.Load<Texture2D>("Screens/Splash"); spacer = Content.Load<Texture2D>("Spacer"); // Create a default position for the splash screen. position = new Rectangle(0, 0, 800, 600); } /// <summary> /// The Update(gameTime) method will be called each frame and handles all game logic. /// </summary> /// <param name="gameTime"></param> public static void Update(GameTime gameTime) { // If the total GameTime (since the program started) has gone over a second, or a key is pressed, change the game state. if (gameTime.TotalGameTime.TotalSeconds >= 5 || InputManager.AnyKeyPressed()) { ScreenManager.State = MenuState.MainMenu; } if(fadeValue < 255) fadeValue += 1; } /// <summary> /// The Draw(spriteBatch) method will be called each frame and handles the drawing logic. /// </summary> /// <param name="spriteBatch"></param> public static void Draw(SpriteBatch spriteBatch) { // Create a new SpriteBatch to avoid overwriting layers. spriteBatch.Begin(); // Draw the splash screen to our buffer. spriteBatch.Draw(spacer, new Rectangle(0, 0, 800, 600), new Color(255, 255, 255, 200)); spriteBatch.Draw(texture, position, new Color(255, 255, 255, fadeValue)); // End the SpriteBatch object. spriteBatch.End(); } #endregion }}[/source]

Loading a tiled map

02 May 2012 - 10:05 PM


I'm currently working on a top-down shooter, and have reached a "hmm, I'm doing something terribly wrong" point. Basically, here's what I'm trying to accomplish:
  • I'd like to allow the programmer to hard-code in the map (I don't understand how to make a tile editor yet, need to familiarze myself with WPF prior to beginning that project) so that it can be loaded into application for later use. This has been accomplished.
  • After the map has been created, I alter the code so that I can load the map and draw the contents of it. Essentially, if there's a 0 in the text file, draw the grass tile. If there's a 1, draw the dirt tile, etc.
  • I'd like to have mulitple worlds so that if the player goes to a certain location (for instance, they step over the left side of the screen), then the world will change entirely. Think of the old Zelda games.

The problem is that when I load the text file and draw the world to the screen, I receive extremely bad framerate lag. I've tried altering the source a bit, but now the world doesn't even draw. I've attached a zip that contains the project's code and assets. I'm looking for any type of suggestions with creating and loading tiled maps using C# and XNA. In case you don't wish to download the project, I went ahead and included three source code files which are likely the cause of the issue to this post.





Getting Started with Networking

09 April 2012 - 03:34 AM

Hey everybody!

So, I've been learning C# for the past few months, and finally migrated towards learning some XNA to remake a Pong clone. I've made Pong in the past, but using C++ and SDL, so this was another learning experience. However, this time, I've added extra "features" to the game, and what I mean by that, is I've actually incorporated a menu system, winning and losing, beatable A.I., and sound effects which I've never done before.

I found the process incredibly fun and the motivation for game development came back to me. Now, I know this may be a bit overambitious, but I'm very interested in adding networking into the game. I don't plan on doing development for Xbox 360 or Windows Phone, so my networking options aren't available within the XNA framework itself.

I'm thinking of adding a P2P connection so that players can host/join lobbies and compete against each other. I could also implement a high scoring system to show who has the most amount of points currently, just to encourage some friendly competition among my friends. So, I did some research and found out about Lidgren, but it appears that the library is currently only for a client/server network, and it appears to be extremely complicated with not too many resources available (although I could be searching in the wrong area).

I noticed there was the System.Net.PeerTopeer namespace that I could use, but again, I didn't find many examples of using that either. Would anybody happen to have suggestions for dabbling into networking for the first time, or should I just worry about finishing up my game and start working on another clone such as Breakout or Tetris?

I appreciate the help guys and gals!