Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Manabreak

Member Since 16 Nov 2011
Offline Last Active Jan 12 2014 07:11 AM

#4920414 [XNA] Drawing List of Strings

Posted by Manabreak on 08 March 2012 - 07:52 AM

The problem is this:
public void Draw(SpriteBatch spriteBatch)
{
    foreach (string item in items)
        foreach (Vector2 pos in position)
            spriteBatch.DrawString(font, item, pos, Color.White);
}

This draws each string to each of the positions, which isn't the way you want it. Try this:

public void Draw(SpriteBatch spriteBatch)
{
	for(int i = 0; i < items.Count; ++i)
	{
		spriteBatch.DrawString(font, items[i], position[i], Color.White);
	}
}

This should do the trick. Although, I must warn you, there is no quarantee that the items and positions are in the same order. I would suggest creating a new class for each menu object, which would contain the string and the position for the object. Then, you could have a list of these new menu objects and draw them instead. Posted Image


#4916503 OOP Design/help (reworking some code)

Posted by Manabreak on 25 February 2012 - 10:09 AM

I thought about doing that but then my GameObject class would contain every single possible effect that could happen. Is this really a good way of doing it?


Actually, as I said, you can overload the Grow() method in every inherited version, thus making separating the effects for each of the classes.
A bit like this:

public class GameObject
{
     public virtual void Grow() 
     {
          // Do nothing here.
     }
}

public class Player : GameObject
{
     // Place all the player's effect stuff here (For example:)
     private float playerGrowRate = 1.0f;

     public override void Grow()
     {
          // Do the player's grow stuff here (For example like this:)
          playerSize += playerGrowRate; 
     }
}

public class Vehice : GameObject
{
     // Again, place all the vehicle's stuff here <img src='http://public.gamedev.net//public/style_emoticons/default/smile.png' class='bbc_emoticon' alt=':)' />
     private float vehicleGrowRate = 5.4f;

     public override void Grow()
     {
          // Again, do the vehicle's grow code here
     }
}

Hopefully this clears my point. :)


#4916471 Starting from the ground up.

Posted by Manabreak on 25 February 2012 - 06:11 AM

Heya! Making a game is a long and requiring process. If you don't know about programming, you should first learn the basics before trying to do anything serious. The language doesn't really matter (although this is the most debated topic of all time!), but usually people tend to learn either Java, C, C# or Python as their first language. Also, be warned, learning to write code is also time-consuming, a couple of months at least. After you've acquired decent skills in programming, you can start choosing the engine (or API) for your project. Unity3D is quite popular development environment, although it costs if you want to develop anything even remotely nice-looking. For "retro"-sprite-based games, XNA is one of the easiest APIs. It uses C# as the language, which is quite easy to learn. The downside (if you count it as one) is that you can only use XNA to develop for the Microsoft platforms (those being Windows, Windows Phone 7 and Xbox 360).

For sprite creation, you can use just about any program you want. For starters, you can do pixel art with Paint or Gimp. If you fancy 3D modeling, you can produce 2D sprites by making models in 3D, animating them and rendering them as 2D images. Also, ASEPRITE is a simple, free program which helps you to construct sprite sheets and test your animations beforehand.

8-bit music program: I recommend either Sunvox or Psycle. Both offer you nice features, and I must say that Sunvox in particular suits chiptune music making perfectly.

A wing and a prayer: Learn, learn some more and then learn even more stuff. Try everything you want, start with small and build your knowledge and skills up. It takes a lot of time and patience, but it's really rewarding at the end. And the whole Internet is there for you, even though it may be quite hostile sometimes. :D


#4916446 OOP Design/help (reworking some code)

Posted by Manabreak on 25 February 2012 - 01:26 AM

If you want to go with the Grow() method solution, you don't have to 'enum' your gameObjectTypes manually. You can take the enum parameter out from your Grow() method and make it like this:
void Grow(GameObject obj)
{
	 if(obj is Player)
	 {
		  Player playerObj = obj as Player;
		  // Do player-related stuff
	 }
	 if(obj is Vehice)
	 {
		  Vehicle vehicleObj = obj as Vehicle;
		  // Do vehicle-related stuff
	 }
}

... Although, I don't think this is the best approach to your problem. Why not make the Grow() method in the GameObject class? Then you could override it for each of the specialized classes (Player, Vehicle etc.) to do their own Grow() stuff. Posted Image

About removing the statics, I usually make this kind of a structure for my game projects:
- GameController class, which is a DrawableGameComponent (and is added to the Components list)
- ScreenController class, which handles all the drawing (the Draw() method is called from the GameController)
- Player class, which handles all the player-related stuff (Updated from GameController, drawn from ScreenController)

... and so on. I have this structure shown in this video:
http://www.youtube.com/watch?v=4mj4HSNGFnE
It's a bit long, but I think it could help you out while trying to figure out the best structure for your game. Posted Image


#4916189 XNA if statements, confusion!

Posted by Manabreak on 24 February 2012 - 07:40 AM

I think this is because the IsKeyDown() is true for multiple update cycles in a row.
Try to add a boolean variable to "lock" the input only for the current cycle:

// Outside the update loop:
bool isKeyDown = false;
// In the update loop:
if (Card1guessed == true)
{
	 if (Keyboard.GetState().IsKeyDown(Keys.H) && !isKeyDown)
	 {
		 isKeyDown = true;
		 if (ShuffledCards.ElementAt(2).Value > ShuffledCards.ElementAt(1).Value)
			   Card2guessed = true;
	 }
	 else if (Keyboard.GetState().IsKeyDown(Keys.L) && !isKeyDown)
	 {
		 isKeyDown = true;
		 if (ShuffledCards.ElementAt(2).Value < ShuffledCards.ElementAt(1).Value)
			   Card2guessed = true;
	 }

	 if(Keyboard.GetState().IsKeyUp(Keys.H))
	 {
		 isKeyDown = false;
	 }
}



PARTNERS