rherm23

Members
  • Content count

    159
  • Joined

  • Last visited

Community Reputation

147 Neutral

About rherm23

  • Rank
    Member
  1. Sorting Vector containers in C++

    Thanks for the replies. Ill tst them when i get home from work. I appreciate it. +reps to you both.
  2. I have a struct like so .. [source lang="cpp"] struct STUFF { int points; string first_name; string last_name; } [/source] I have a vector <STUFF> stuffs and i wanted to sort the data inside from highest to lowest using the pts value. Is something like that possible? I havent used c++ in a while and i started fleshing out this program and was stumped on this problem. Im going to be displaying the players according to the pts value in each struct so the person with the most points should be at index [0] and the last place person at the last index. Im gonna keep at it but i think that any ideas i might be having might be too complicated and a more elegant solution may exist. Thanks in advance for any help and replies.
  3. Rotating sprite issues

    Thanks a ton! Im at work atm but will try that out when i get home. you are awesome!
  4. XNA sprite rotation

    I posted this in the XNA forums with no response so now im gonna try here. i want to draw a sprite of an arrow pointing up at 200, 200. when A is hit it rotated left , when you hit D it rotates right. [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]// this line draws my arrow in the perfect spot but obviously doesnt account for rotation.[/left][/size][/font][/color] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]//spriteBatch.Draw(image, position, Color.White);[/left][/size][/font][/color] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]// this line draws my arrow half visible in the top left corner of the screen. and it doesnt rotate but pivot.[/left][/size][/font][/color] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]spriteBatch.Draw(image, position, null, Color.White, rotation, origin, 1.0f,SpriteEffects.None, 0); [/left][/size][/font][/color] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]can anyone help me out here? thanks in advance[/left][/size][/font][/color] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][CODE] 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 ArrowRotation { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; SpriteFont font1; KeyboardState k_current_state; Vector2 position; Vector2 origin; float rotation; Texture2D image; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { // TODO: Add your initialization logic here position.X = 200; position.Y = 200; origin.X = position.X + 32; origin.Y = position.Y + 32; rotation = 0.0f; base.Initialize(); } protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); font1 = Content.Load<SpriteFont>("testFont"); image = Content.Load<Texture2D>("up");[/left][/size][/font][/color] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left] } protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } protected override void Update(GameTime gameTime) { k_current_state = Keyboard.GetState(); if (k_current_state.IsKeyDown(Keys.Escape)) { this.Exit(); } if (k_current_state.IsKeyDown(Keys.A)) { rotation -= 0.1f; } if (k_current_state.IsKeyDown(Keys.D)) { rotation += 0.1f; }[/left][/size][/font][/color] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left] base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin();[/left][/size][/font][/color] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left] spriteBatch.DrawString(font1, "rotation = " + rotation.ToString(), new Vector2(0, 0), Color.White); spriteBatch.DrawString(font1, "X position = " + position.X.ToString(), new Vector2(0, 30), Color.White); spriteBatch.DrawString(font1, "Y position = " + position.Y.ToString(), new Vector2(0, 60), Color.White); spriteBatch.DrawString(font1, "X Origin = " + origin.X.ToString(), new Vector2(0, 90), Color.White); spriteBatch.DrawString(font1, "Y Origin = " + origin.Y.ToString(), new Vector2(0, 120), Color.White); //spriteBatch.Draw(image, position, Color.White); spriteBatch.Draw(image, position, null, Color.White, rotation, origin, 1.0f,SpriteEffects.None, 0);[/left][/size][/font][/color] [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left] spriteBatch.End(); base.Draw(gameTime); } } } [/CODE][/left][/size][/font][/color]
  5. Rotating sprite issues

    made another program and ill post code .... my draw code is // this line draws my arrow in the perfect spot //spriteBatch.Draw(image, position, Color.White); // this line draws my arrow half visible in the top left corner of the screen. and it doesnt rotate but pivot. spriteBatch.Draw(image, position, null, Color.White, rotation, origin, 1.0f,SpriteEffects.None, 0); can anyone help me out here? thanks in advance [CODE] 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 ArrowRotation { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; SpriteFont font1; KeyboardState k_current_state; Vector2 position; Vector2 origin; float rotation; Texture2D image; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { // TODO: Add your initialization logic here position.X = 200; position.Y = 200; origin.X = position.X + 32; origin.Y = position.Y + 32; rotation = 0.0f; base.Initialize(); } protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); font1 = Content.Load<SpriteFont>("testFont"); image = Content.Load<Texture2D>("up"); } protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } protected override void Update(GameTime gameTime) { k_current_state = Keyboard.GetState(); if (k_current_state.IsKeyDown(Keys.Escape)) { this.Exit(); } if (k_current_state.IsKeyDown(Keys.A)) { rotation -= 0.1f; } if (k_current_state.IsKeyDown(Keys.D)) { rotation += 0.1f; } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.DrawString(font1, "rotation = " + rotation.ToString(), new Vector2(0, 0), Color.White); spriteBatch.DrawString(font1, "X position = " + position.X.ToString(), new Vector2(0, 30), Color.White); spriteBatch.DrawString(font1, "Y position = " + position.Y.ToString(), new Vector2(0, 60), Color.White); spriteBatch.DrawString(font1, "X Origin = " + origin.X.ToString(), new Vector2(0, 90), Color.White); spriteBatch.DrawString(font1, "Y Origin = " + origin.Y.ToString(), new Vector2(0, 120), Color.White); //spriteBatch.Draw(image, position, Color.White); spriteBatch.Draw(image, position, null, Color.White, rotation, origin, 1.0f,SpriteEffects.None, 0); spriteBatch.End(); base.Draw(gameTime); } } } [/CODE]
  6. I am trying to render a sprite on the screen that will not move but only rotate. I want to make it so when you press the 'A' key it rotates counterclockwise and if you press the 'D' key it rotates clockwise I am very new to XNA so i know my code isnt the best atm i tend to make 1 small program and add to it piece by piece so when i go through these learning programs they tend to not be as clean as they can be. [CODE] class GameObject { public Vector2 position; public Rectangle rect; public Texture2D image; public float rotation; public Vector2 origin; public GameObject() { position = new Vector2(300, 300); rect = new Rectangle(300, 300, 64, 64); rotation = 0.0f; origin.X = position.X + (rect.Width / 2); origin.Y = position.Y + (rect.Height / 2); } public void loadContent(ContentManager manager) { image = manager.Load<Texture2D>("up"); } public void draw(SpriteBatch batch) { batch.Draw(image, position, Color.White); //batch.Draw(image, rect, null, Color.White, rotation, origin, SpriteEffects.None, 0f); } public void update(KeyboardState k_state) { if (k_state.IsKeyDown(Keys.A)) { rotation -= 0.1f; } if (k_state.IsKeyDown(Keys.D)) { rotation += 0.1f; } } } [/CODE] in my draw method when i make the uncommented call it draws my arrow fine ... no rotation but everything is drawn at the correct spots. when i draw using the commented part the arrow is in a completely different position and it pivots more than it rotates. can anyone help me at all? Thanks in advance
  7. Loading an Image in a class

    ill give that a shot and thanks for the replies. Much appreciated.
  8. Loading an Image in a class

    when i type out the code i get .... intellisense or whatever its called doesnt let me add Content to the following image = its like it doesnt exist. if it does come up i cant find the .Load and i get the red squigglies under the line image = Content.Load<Texture2D>("ball"); ill try and post a screenie if need be. I can call it from the load content function in the game1 file but not from inside a class i make.
  9. This is probably an easy question to answer but im new to XNA and this is slowing me down. I want to load an image from a class i created. For instance [code] class Ball { public Texture2D image; public int stuff; public Ball () { } public void loadStuffs () { // i want to be able to load an image here without having to pass it via parameter image = Content.Load<Texture2D>("ball"); // this is whats not working } } [/code] Anyone able to help me out here so i can load textures without having to pass them to my classes.
  10. couple of XNA questions

    this is perfect thanks again. I rated you up again lol since you also helped me in the beginners forum. For #3 thats what i kinda figured i had to do but when i tried i was getting weird results when trying to use a font in a class ... do i need to pass any type of variable in like a content manager or would including / importing be enough to be able to use it in my class (fonts that is)
  11. C# file IO

    thank you for the replies. I am going to look into the XML route. Both were a huge help + to both of you much appreciated.
  12. First question is on mouse clicks. I have a custom GUI_BUTTON and all i want it to do is when i click it .... to increment a variable. I then display that variable to the screen. so basically i have this int count = 0; bool pressed = false; if (mouse is pressed) { pressed = true; if (mouse is inside button bounds AND pressed) { increment count pressed = false; } } this makes the button work when i click inside of it. but when i click outside of it .... well thats diff. It doesnt incrememnt the count ... but when i click outside button then move mouse inside bounds .... it then increments. im not 100% sure how to make that stop. I know at some point i need reset pressed to false .... but ive tried putting that in a few spots and nothing seems to work. ill try and post code for this when i get home. My next question is about fonts in XNA and C#. I want to create a "GUI_LABEL" and have it basically have a series of strings like an array or something and have it display the current index of the array to the label. so like collection of strings called string_list string_list.push_back("this is line 1"); string_list.push_back("this is line 2"); string_list.push_back("this is line 3"); string_list.push_back("this is line 4"); string_list.push_back("this is line 5"); // pardon syntax im like falling asleep as i write this and im sure its horrible /just trying to get the general idea out there and so on. then have a variable like int current_line; string current_string; i want to be able to do something like current_string = string_list[current_line]; again its the syntax thats killing me. im not too good with C# just yet and the difference of containers to C++ seems to throw me off. and lastly ... lol sorry to be a pain in my GUI_LABEL class would i need to pass a Spritefont object to draw text or some sort of SpriteBatch ... or should i just have a method that returns a string and leave all that to the draw method that is given to me when i create an XNA project.
  13. First question is on mouse clicks. I have a custom GUI_BUTTON and all i want it to do is when i click it .... to increment a variable. I then display that variable to the screen. so basically i have this int count = 0; bool pressed = false; if (mouse is pressed) { pressed = true; if (mouse is inside button bounds AND pressed) { increment count pressed = false; } } this makes the button work when i click inside of it. but when i click outside of it .... well thats diff. It doesnt incrememnt the count ... but when i click outside button then move mouse inside bounds .... it then increments. im not 100% sure how to make that stop. I know at some point i need reset pressed to false .... but ive tried putting that in a few spots and nothing seems to work. ill try and post code for this when i get home. My next question is about fonts in XNA and C#. I want to create a "GUI_LABEL" and have it basically have a series of strings like an array or something and have it display the current index of the array to the label. so like collection of strings called string_list string_list.push_back("this is line 1"); string_list.push_back("this is line 2"); string_list.push_back("this is line 3"); string_list.push_back("this is line 4"); string_list.push_back("this is line 5"); // pardon syntax im like falling asleep as i write this and im sure its horrible /just trying to get the general idea out there and so on. then have a variable like int current_line; string current_string; i want to be able to do something like current_string = string_list[current_line]; again its the syntax thats killing me. im not too good with C# just yet and the difference of containers to C++ seems to throw me off. and lastly ... lol sorry to be a pain in my GUI_LABEL class would i need to pass a Spritefont object to draw text or some sort of SpriteBatch ... or should i just have a method that returns a string and leave all that to the draw method that is given to me when i create an XNA project.
  14. C# file IO

    I think i might be burned out from working all night and im pretty sure this is a simple question that im waaay overthinking so help here would save me some grief. I am working on a game ive been mulling over for a bit. Here is the problem .... I want to have a text file say ...... This is a paragraph about monkeys and how much they love to fling poo. I found this concept to be foo foo foo to the foo power and blah blah blah. in my C# i want to read this in. at some point i want to then break up that string into smaller strings. The idea is i want to display the text into a custom GUI_LABEL type object for a text game. for some reason when i sit to code this out i go blank or just really mess this up. In c++ this wasnt really an issue for some reason but in C# its rocking my face.
  15. Beginner troubles

    "I have practically no clue what a Vector is, even though I looked it up on this site" Vector2 gameBoardDisplayOrigin = new Vector2(70, 89); i assume its this line that you are talking about? Vector2 is simply an object that holds 2 numbers. they are usually used as coordinates on a graph (the screen) so this is storing the x and y coordinates for something called gameBoardDisplayOrigin. So when we try to draw the board its going to ask need to know where to draw it ... we are going to draw it at x coordinate 70 and y coordinate 89. This is a simplified explanation there is more to it. If you are struggling with c# i can help i am starting some small c# xna projects myself and wouldnt mind helping you at all. Im no guru but we should be able to make some small stuff to help you understand some of the concepts. Send me a private message if you want to i have AIM (rarely use) Yahoo IM facebook just let me know.