BLUE ERA

Would you like to react to this message? Create an account in a few clicks or log in to continue.
BLUE ERA

เว็บสังคมของคนไม่เต็มเต็ง

SMS ประจำวันเดือนปีนี้>>>
[ ผมเทพมากครับ...คอนเฟม!!! -อีหมอกิด ]
[ บอร์ดบลูอีร่าหนาวมาก - สก๊อยผ่า ]
[ ที่นี่ร้างกว่าบ้านผีสิงอีกนะครับ - พี่ป๋อง]
[ สวยลดหุ่นไม่อ้วนปลอดภัย 1% ติดต่อ 02-11xxxxx]
[ หอยทอดเจ้แมงดา 10 บาทเอง - แมงดาจ๊ะ ]

Top posters

Admin (240)
โค้ดXNA ครั้งที่1 Bar_leftโค้ดXNA ครั้งที่1 Barโค้ดXNA ครั้งที่1 Bar_right 
SoHandsome (150)
โค้ดXNA ครั้งที่1 Bar_leftโค้ดXNA ครั้งที่1 Barโค้ดXNA ครั้งที่1 Bar_right 
Nut_Cha (145)
โค้ดXNA ครั้งที่1 Bar_leftโค้ดXNA ครั้งที่1 Barโค้ดXNA ครั้งที่1 Bar_right 
AiPokoi (144)
โค้ดXNA ครั้งที่1 Bar_leftโค้ดXNA ครั้งที่1 Barโค้ดXNA ครั้งที่1 Bar_right 
ตกลง (111)
โค้ดXNA ครั้งที่1 Bar_leftโค้ดXNA ครั้งที่1 Barโค้ดXNA ครั้งที่1 Bar_right 
ArDioSis (99)
โค้ดXNA ครั้งที่1 Bar_leftโค้ดXNA ครั้งที่1 Barโค้ดXNA ครั้งที่1 Bar_right 
ชินเบ้ (98)
โค้ดXNA ครั้งที่1 Bar_leftโค้ดXNA ครั้งที่1 Barโค้ดXNA ครั้งที่1 Bar_right 
RaamDynamic (79)
โค้ดXNA ครั้งที่1 Bar_leftโค้ดXNA ครั้งที่1 Barโค้ดXNA ครั้งที่1 Bar_right 
poppuriseed (77)
โค้ดXNA ครั้งที่1 Bar_leftโค้ดXNA ครั้งที่1 Barโค้ดXNA ครั้งที่1 Bar_right 
Parakan (57)
โค้ดXNA ครั้งที่1 Bar_leftโค้ดXNA ครั้งที่1 Barโค้ดXNA ครั้งที่1 Bar_right 

โฆษณา

ติดต่อโฆษณาได้ที่ADMIN
ขนาดรูป 150px × 250px

โฆษณาโดย sarim

2 posters

    โค้ดXNA ครั้งที่1

    สก๊อยผ่า
    สก๊อยผ่า
    คนธรรมดา
    คนธรรมดา


    จำนวนข้อความ : 40
    Join date : 01/12/2008

    Character sheet
    พลังชีวิต:
    โค้ดXNA ครั้งที่1 Left_bar_bleue9999/9999โค้ดXNA ครั้งที่1 Empty_bar_bleue  (9999/9999)
    เกรียนอบิลิตี้: สก๊อยผ่านศึก

    โค้ดXNA ครั้งที่1 Empty โค้ดXNA ครั้งที่1

    ตั้งหัวข้อ by สก๊อยผ่า Sun Jun 14, 2009 12:56 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;
    using Microsoft.Xna.Framework.Net;
    using Microsoft.Xna.Framework.Storage;

    namespace WindowsGame1
    {
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    Texture2D ball;
    Texture2D ball2;
    Texture2D ball3;
    Texture2D background;
    SpriteFont font1;
    Vector2 ballpos;
    Vector2 ballspeed;
    int currentcolor;

    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

    //3บรรทัดล่างนี้ ปรับขนาดจอให้เป็น 640x480
    // graphics.PreferredBackBufferWidth = 640;
    // graphics.PreferredBackBufferHeight = 480;
    // graphics.ApplyChanges();

    ballpos.X = 20;
    ballpos.Y = 10;
    ballspeed.X = 10;
    ballspeed.Y = 10;

    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);

    // TODO: use this.Content to load your game content here
    ball = Content.Load<Texture2D>("ball-red");
    ball2 = Content.Load<Texture2D>("ball-blue");
    ball3 = Content.Load<Texture2D>("ball-green");
    currentcolor = 1;

    background = Content.Load<Texture2D>("background1");
    font1 = Content.Load<SpriteFont>("freesiaupc");
    }

    /// <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
    if ((ballpos.X < 0) || (ballpos.X > Window.ClientBounds.Width - 64))
    {
    ballspeed.X *= -1;
    currentcolor++;
    }
    if ((ballpos.Y < 0) || (ballpos.Y > Window.ClientBounds.Height - 64))
    {
    ballspeed.Y *= -1;
    currentcolor++;
    }
    if (currentcolor > 3) currentcolor = 1;
    ballpos.X += ballspeed.X;
    ballpos.Y += ballspeed.Y;

    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);

    // TODO: Add your drawing code here
    spriteBatch.Begin();
    http://spriteBatch.Draw(background, Vector2.Zero, Color.White);
    //บรรทัดล่างนี้สร้างbackground ให้ติดขอบจอ
    spriteBatch.Draw(background, new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height), Color.White);
    http://spriteBatch.Draw(ball, Vector2.Zero, Color.White);
    if (currentcolor == 1) spriteBatch.Draw(ball, ballpos, Color.White);
    if (currentcolor == 2) spriteBatch.Draw(ball2, ballpos, Color.White);
    if (currentcolor == 3) spriteBatch.Draw(ball3, ballpos, Color.White);

    spriteBatch.DrawString(font1, @"Goldenpig มาแล้วนะเด็กน้อย", new Vector2(10, 10), Color.YellowGreen);
    spriteBatch.End();

    base.Draw(gameTime);
    }
    }
    }

    สก๊อยผ่า
    สก๊อยผ่า
    คนธรรมดา
    คนธรรมดา


    จำนวนข้อความ : 40
    Join date : 01/12/2008

    Character sheet
    พลังชีวิต:
    โค้ดXNA ครั้งที่1 Left_bar_bleue9999/9999โค้ดXNA ครั้งที่1 Empty_bar_bleue  (9999/9999)
    เกรียนอบิลิตี้: สก๊อยผ่านศึก

    โค้ดXNA ครั้งที่1 Empty Re: โค้ดXNA ครั้งที่1

    ตั้งหัวข้อ by สก๊อยผ่า Sun Jun 14, 2009 3:57 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;
    using Microsoft.Xna.Framework.Net;
    using Microsoft.Xna.Framework.Storage;

    namespace WindowsGame1
    {
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    Texture2D ball;
    Texture2D ball2;
    Texture2D ball3;

    Texture2D background;

    Texture2D bar;
    Texture2D brick1;
    Texture2D brick2;
    Texture2D brick3;

    SpriteFont font1;
    Vector2 ballpos;
    Vector2 ballspeed;

    Vector2 barpos;

    int currentcolor;

    int[,] block;//สร้างArray2มิติชื่อblock
    const int noblock = 0;
    const int block1 = 1;
    const int block2 = 2;
    const int block3 = 3;


    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

    //3บรรทัดล่างนี้ ปรับขนาดจอให้เป็น 640x480
    // graphics.PreferredBackBufferWidth = 640;
    // graphics.PreferredBackBufferHeight = 480;
    // graphics.ApplyChanges();

    block = new int[6,3];
    block[0, 0] = block3;
    block[1, 0] = block1;
    block[2, 0] = block2;
    block[3, 0] = block2;
    block[4, 0] = block1;
    block[5, 0] = block3;
    for (int i = 0; i <= 5; i++)
    {
    block[i, 1] = block2;
    block[i, 2] = block3;
    }

    ballpos.X = 20;
    ballpos.Y = 300;
    ballspeed.X = 5;
    ballspeed.Y = 5;

    barpos.X = 300;
    barpos.Y = 550;


    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);

    // TODO: use this.Content to load your game content here
    ball = Content.Load<Texture2D>("ball-red");
    ball2 = Content.Load<Texture2D>("ball-blue");
    ball3 = Content.Load<Texture2D>("ball-green");

    bar = Content.Load<Texture2D>("bar");
    brick1 = Content.Load<Texture2D>("brick1");
    brick2 = Content.Load<Texture2D>("brick2");
    brick3 = Content.Load<Texture2D>("brick3");

    currentcolor = 1;

    background = Content.Load<Texture2D>("background1");
    font1 = Content.Load<SpriteFont>("freesiaupc");
    }

    /// <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
    if ((ballpos.X < 0) || (ballpos.X > Window.ClientBounds.Width - 64))
    {
    ballspeed.X *= -1;
    currentcolor++;
    }
    if ((ballpos.Y < 0) || (ballpos.Y > Window.ClientBounds.Height - 64))
    {
    ballspeed.Y *= -1;
    currentcolor++;
    }
    if (currentcolor > 3) currentcolor = 1;
    ballpos.X += ballspeed.X;
    ballpos.Y += ballspeed.Y;

    UpdateInput();//เกี่ยวกับปุ่ม


    base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>

    private void UpdateInput()
    {
    KeyboardState newState = Keyboard.GetState();

    // Is the Arrow key down?
    if (newState.IsKeyDown(Keys.Left))
    {
    barpos.X -= 7; if(barpos.X<0) barpos.X=0;
    }
    if (newState.IsKeyDown(Keys.Right))
    {
    barpos.X += 7;
    if(barpos.X > Window.ClientBounds.Width - 128)barpos.X = Window.ClientBounds.Width - 128;
    }

    }

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

    // TODO: Add your drawing code here
    spriteBatch.Begin();
    http://spriteBatch.Draw(background, Vector2.Zero, Color.White);
    //บรรทัดล่างนี้สร้างbackground ให้ติดขอบจอ
    spriteBatch.Draw(background, new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height), Color.White);
    //สร้างbarตามตำแหน่งที่กำหนดไว้
    spriteBatch.Draw(bar, barpos, Color.White);

    //draw brick
    for (int e=0; e<=2;e++)
    for (int i = 0; i <= 5; i++)
    {
    switch (block[i, e])
    {
    case noblock: break;
    case block1: spriteBatch.Draw(brick1,
    new Vector2(i * 128, e * 64), Color.White);
    break;
    case block2: spriteBatch.Draw(brick2,
    new Vector2(i * 128, e * 64), Color.White);
    break;
    case block3: spriteBatch.Draw(brick3,
    new Vector2(i * 128, e * 64), Color.White);
    break;
    }
    }

    http://spriteBatch.Draw(ball, Vector2.Zero, Color.White);
    if (currentcolor == 1) spriteBatch.Draw(ball, ballpos, Color.White);
    if (currentcolor == 2) spriteBatch.Draw(ball2, ballpos, Color.White);
    if (currentcolor == 3) spriteBatch.Draw(ball3, ballpos, Color.White);

    spriteBatch.DrawString(font1, @"Goldenpig มาแล้วนะเด็กน้อย", new Vector2(10, 10), Color.YellowGreen);
    spriteBatch.DrawString(font1, @"X="+(int)(ballpos.X/128)+" Y="+(int)(ballpos.Y/64),new Vector2(10, 50), Color.White);
    //เช็คตำแหน่งการชนระหว่าง ball กับ block
    Vector2 ballblock;
    ballblock.X = (int)(ballpos.X / 128);
    ballblock.Y = (int)(ballpos.Y / 64);

    if ((ballblock.X >=0) && (ballblock.X <=5) &&
    (ballblock.Y >=0) && (ballblock.Y <=2))
    {
    if (block[(int)ballblock.X, (int)ballblock.Y] != noblock)
    {
    block[(int)ballblock.X, (int)ballblock.Y] = noblock;
    ballspeed.Y *= -1;
    }
    }
    if ((barpos.X - 64 < ballpos.X) && (ballpos.X < barpos.X + 128))
    {
    if (ballpos.Y > barpos.Y - 64)
    {
    ballspeed.Y *= -1;
    }
    }

    spriteBatch.End();

    base.Draw(gameTime);
    }
    }
    }

    avatar
    titr
    คนดี
    คนดี


    จำนวนข้อความ : 1
    Join date : 10/05/2010

    โค้ดXNA ครั้งที่1 Empty Re: โค้ดXNA ครั้งที่1

    ตั้งหัวข้อ by titr Mon May 10, 2010 2:45 am

    ผมได้เอาไป รัน ดูแล้วงับ แต่ไม่มีเสียง ออกมา ตอนนี้ผมลองเขียนแบบค่าพลังชีวิต ลด เพืม ค่า โจมตี แต่ไม่รู้จะเริ้มต้นอย่างไรดีผมขอคำปรึกษาได้ใมงับ
    ขอบคุณมากครับ

      เวลาขณะนี้ Tue Sep 17, 2024 2:37 am