10 Replies - 4364 Views - Last Post: 26 January 2013 - 07:26 AM

#1 hadisam  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 11
  • Joined: 25-January 13

super mario game in c#

Posted 25 January 2013 - 05:24 AM

it has a problem i don not know what it is ?
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 windowsgame
{

    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        
      
        public rect r0;
        public rect r1;
        public Rectangle position;
        public Texture2D texture;
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        public List<rect> rects = new List<rect>();
        public Game1()
        {


            r0.postion = new Rectangle(20, 20, 30, 40);
            r1.postion = new Rectangle(30, 30, 30, 40);

            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.
            spriteBatch = new SpriteBatch(GraphicsDevice);
             r0.texture = Content.Load<Texture2D>("rect");
            r1.texture = Content.Load<Texture2D>("rect"); 
            rects.Add(r0);
            rects.Add(r1);

            // 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 the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // 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.CornflowerBlue);
            spriteBatch.Begin();
            // TODO: Add your drawing code here
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}


This post has been edited by Skydiver: 25 January 2013 - 05:46 AM
Reason for edit:: Put code into code tags. Please remember to do it yourself in the future.


Is This A Good Question/Topic? 0
  • +

Replies To: super mario game in c#

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3570
  • View blog
  • Posts: 11,099
  • Joined: 05-May 12

Re: super mario game in c#

Posted 25 January 2013 - 05:49 AM

First, Please remember to put your code in code tags. The instructions are right there in the edit box that you put your post in.

Second, tell us what errors you are getting and what you've tried or searched for. Again the instructions are right there is the edit box. Just telling us "it has a problem i don't know what it is?" doesn't help at all.
Was This Post Helpful? 0
  • +
  • -

#3 hadisam  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 11
  • Joined: 25-January 13

Re: super mario game in c#

Posted 25 January 2013 - 06:51 AM

how i can appear the rect in game? please answer with answer clearly

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 windowsgame
{

    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        
      
        public rect r0;
        public rect r1;
        public Rectangle position;
        public Texture2D texture;
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        public List<rect> rects = new List<rect>();
        public Game1()
        {


            r0.postion = new Rectangle(20, 20, 30, 40);
            r1.postion = new Rectangle(30, 30, 30, 40);

            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.
            spriteBatch = new SpriteBatch(GraphicsDevice);
             r0.texture = Content.Load<Texture2D>("rect");
            r1.texture = Content.Load<Texture2D>("rect"); 
            rects.Add(r0);
            rects.Add(r1);

            // 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 the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // 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.CornflowerBlue);
            spriteBatch.Begin();
            // TODO: Add your drawing code here
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}


This post has been edited by Skydiver: 25 January 2013 - 07:03 AM
Reason for edit:: Put code in code tags, again. Please learn how to do so.

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3570
  • View blog
  • Posts: 11,099
  • Joined: 05-May 12

Re: super mario game in c#

Posted 25 January 2013 - 07:07 AM

Ah, this isn't a C# question, but rather an Game Programming / XNA question. Moving to the that forum.

To me, though, it looks like you aren't adding your rectangles to the set of things to be rendered. You are merely adding them to your list of rectangles rect. Of course, they won't be rendered because C# and XNA won't magically read your mind and figure out that you intend them to be rendered. You need to explicitly put them in the render queue.

This post has been edited by Skydiver: 25 January 2013 - 07:09 AM

Was This Post Helpful? 1
  • +
  • -

#5 hadisam  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 11
  • Joined: 25-January 13

Re: super mario game in c#

Posted 25 January 2013 - 07:57 AM

would u help me to write a mario game in c# languge ?
i am not good at c#?
give me advice to write an i will try to write because i have this game for my class....
please help me to write
Was This Post Helpful? 0
  • +
  • -

#6 AdoTheLimey  Icon User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 80
  • Joined: 28-June 10

Re: super mario game in c#

Posted 25 January 2013 - 01:39 PM

protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
            // TODO: Add your drawing code here
            spriteBatch.End();
            base.Draw(gameTime);
        }



Like Skydiver said, your problem is right here. You are not actually drawing anything to the screen.
Start with spriteBatch.Draw and intellisense will tell you what overloads the method is expecting.

Get that resolved and let us know if you still have problems.
Was This Post Helpful? 1
  • +
  • -

#7 NathanMullenax  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 83
  • View blog
  • Posts: 176
  • Joined: 23-September 12

Re: super mario game in c#

Posted 25 January 2013 - 01:49 PM

I wouldn't recommend loading the same texture twice in LoadContent(). For all I know, XNA might optimize it and only load it once, but it might actually unnecessarily duplicate the texture in memory. Unless you need two copies, I would do something like this:
r0.texture = r1.texture = Content.Load<Texture2D>("rect");

Was This Post Helpful? 0
  • +
  • -

#8 hadisam  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 11
  • Joined: 25-January 13

Re: super mario game in c#

Posted 25 January 2013 - 03:03 PM

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 WindowsGame7 
{
          public class Game1 : Microsoft.Xna.Framework.Game
    {
               mario mar=new mario() ;
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        KeyboardState LastKey;
             SpriteBatch spritebarch;
             Texture2D texture;
              Vector2 position;
      
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = 1375;
            graphics.PreferredBackBufferHeight = 800;
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

       
       protected override void LoadContent()
       {
            spriteBatch = new SpriteBatch(GraphicsDevice);          
                    
      spritebatch.Draw(texture, Position, Color.White);<<<<<<<<<<<<<what is the problem here in this line?>>>>>>>>>>

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit();
            if (Keyboard.GetState().IsKeyDown(Keys.N))
            {
               mar.er();
            }
            mar.move();
            // TODO: Add your update logic here
            LastKey = Keyboard.GetState();
            base.Update(gameTime);
        }

   
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            

            mar.draw(spriteBatch);

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}


thank u for helping me.........

i want please the code of background of my game (super mario)how to put it

This post has been edited by Atli: 26 January 2013 - 02:25 AM
Reason for edit:: Use [code] tags when posting code.

Was This Post Helpful? -1
  • +
  • -

#9 NathanMullenax  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 83
  • View blog
  • Posts: 176
  • Joined: 23-September 12

Re: super mario game in c#

Posted 25 January 2013 - 03:05 PM

View Posthadisam, on 25 January 2013 - 03:00 PM, said:

spritebatch.Draw(texture, Position, Color.White);<<<<<<<<<<<<<what is the problem here in this line?>>>>>>>>>>

You can't do this in LoadContent. LoadContent is called only once--when you start the game. You should put all of your drawing in the Draw function (or function called from the Draw function). Even if you could draw from the LoadContent method, you wouldn't be able to see the result because it would only appear for a single frame during the entire execution of the game.
Was This Post Helpful? 1
  • +
  • -

#10 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: super mario game in c#

Posted 26 January 2013 - 02:29 AM

hadisam, use [code] tags when posting code snippets!

:code:


Also, please note that we will not write code for you. We can help you learn what needs to happen, but ultimately it is you who will need to write the code.
Was This Post Helpful? 1
  • +
  • -

#11 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5509
  • View blog
  • Posts: 11,814
  • Joined: 02-June 10

Re: super mario game in c#

Posted 26 January 2013 - 07:26 AM

View Posthadisam, on 25 January 2013 - 08:57 AM, said:

would u help me to write a mario game in c# languge ?
i am not good at c#?
give me advice to write an i will try to write because i have this game for my class....
please help me to write


Go to your teacher. Talk with him/her and admit you are falling behind. If you are honest now you can get some extra tutoring so you don't fall FURTHER behind.

Begging others to do your homework for you does not help you. That is why we refuse to provide code for homework. In the long run it only hurts you.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1