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 ครั้งที่ 2 Bar_leftโค้ด ตอนเรียน XNA ครั้งที่ 2 Barโค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_right 
SoHandsome (150)
โค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_leftโค้ด ตอนเรียน XNA ครั้งที่ 2 Barโค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_right 
Nut_Cha (145)
โค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_leftโค้ด ตอนเรียน XNA ครั้งที่ 2 Barโค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_right 
AiPokoi (144)
โค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_leftโค้ด ตอนเรียน XNA ครั้งที่ 2 Barโค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_right 
ตกลง (111)
โค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_leftโค้ด ตอนเรียน XNA ครั้งที่ 2 Barโค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_right 
ArDioSis (99)
โค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_leftโค้ด ตอนเรียน XNA ครั้งที่ 2 Barโค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_right 
ชินเบ้ (98)
โค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_leftโค้ด ตอนเรียน XNA ครั้งที่ 2 Barโค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_right 
RaamDynamic (79)
โค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_leftโค้ด ตอนเรียน XNA ครั้งที่ 2 Barโค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_right 
poppuriseed (77)
โค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_leftโค้ด ตอนเรียน XNA ครั้งที่ 2 Barโค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_right 
Parakan (57)
โค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_leftโค้ด ตอนเรียน XNA ครั้งที่ 2 Barโค้ด ตอนเรียน XNA ครั้งที่ 2 Bar_right 

โฆษณา

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

โฆษณาโดย sarim

    โค้ด ตอนเรียน XNA ครั้งที่ 2

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


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

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

    โค้ด ตอนเรียน XNA ครั้งที่ 2 Empty โค้ด ตอนเรียน XNA ครั้งที่ 2

    ตั้งหัวข้อ by สก๊อยผ่า Sun Jun 28, 2009 3:52 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 pythagorean4
    {
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    SpriteFont font1;
    Vector2 mpos;
    int isshipfired = 0;
    int loop = 0;

    Texture2D ship;
    float shipspeed = 0.5f;
    Vector2 shippos;
    Vector2 targetpos;
    float shipangle;

    Texture2D background;
    Texture2D nebula;
    Texture2D bomb;
    Texture2D enemy1;
    Texture2D enemy2;
    Texture2D fire1;
    Texture2D fire2;

    Vector2 nebularpos;

    Random rnd = new Random(1234);

    //--- enemy
    const int enemy_type_none = 0;
    const int enemy_type1 = 1;
    const int enemy_type2 = 2;

    public struct Tenemy
    {
    public Vector2 pos;
    public float hp;
    public float type;
    }

    const int Maxenemydata = 20;
    Tenemy[] enemydata = new Tenemy[Maxenemydata];

    void clear_enemydata()
    {
    for (int i = 0; i < Maxenemydata; i++)
    {
    enemydata[i].type = enemy_type_none;
    }
    }

    void add_enemydata(Vector2 pos, int type)
    {
    for (int i = 0; i < Maxenemydata; i++)
    {
    if (enemydata[i].type == enemy_type_none)
    {
    enemydata[i].pos = pos;
    enemydata[i].type = type;
    enemydata[i].hp = 100;
    return;
    }
    }
    }
    void draw_enemydata(GameTime gametime)
    {
    float t=gametime.ElapsedGameTime.Milliseconds;
    for (int i = 0; i < Maxenemydata; i++)
    {
    if (enemydata[i].type == enemy_type1)
    {
    spriteBatch.Draw(enemy1, enemydata[i].pos - new Vector2(32, 32), Color.White);
    }
    if (enemydata[i].type == enemy_type2)
    {
    spriteBatch.Draw(enemy2, enemydata[i].pos - new Vector2(32, 32), Color.White);
    }
    if (enemydata[i].type != enemy_type_none)
    {
    if (enemydata[i].type == enemy_type1)
    enemydata[i].pos.Y += 1;

    if (enemydata[i].pos.X < 0) enemydata[i].pos.X = 0;
    if (enemydata[i].pos.Y < 0) enemydata[i].pos.Y = 0;
    if (enemydata[i].pos.X > Window.ClientBounds.Width)
    enemydata[i].pos.X = Window.ClientBounds.Width;
    if (enemydata[i].pos.Y > Window.ClientBounds.Height)
    enemydata[i].pos.Y = Window.ClientBounds.Height;

    if (enemydata[i].type == enemy_type1)
    {
    if (rnd.Next(0, 1000) < 100)
    {
    float a;
    a = calcAngle(shippos, enemydata[i].pos);
    Vector2 v;
    v = Angle2Vector(a, 0.75f);
    add_firedata(enemydata[i].pos, v, fireside_enemy);
    }
    }
    if (enemydata[i].type == enemy_type2)
    {

    float t2 = gametime.TotalGameTime.Ticks;
    float a;
    a = (t2) / 180 * (float)Math.PI;
    Vector2 v;
    v = Angle2Vector(a, 0.75f);
    add_firedata(enemydata[i].pos, v, fireside_enemy);

    }
    }
    }
    }
    //--- fire
    const int fireside_empty = 0;
    const int fireside_player = 1;
    const int fireside_enemy = 2;

    public struct Tfire
    {
    public Vector2 pos;
    public Vector2 velocity;
    public int side;
    }

    const int Maxfiredata = 50;
    Tfire[] firedata = new Tfire[Maxfiredata];

    void clear_firedata()
    {
    for (int i = 0; i < Maxfiredata; i++)
    {
    firedata[i].side = fireside_empty;
    }
    }

    void add_firedata(Vector2 pos, Vector2 vel, int side)
    {
    for (int i = 0; i < Maxfiredata; i++)
    {
    if (firedata[i].side == fireside_empty)
    {
    firedata[i].pos = pos;
    firedata[i].velocity = vel;
    firedata[i].side = side;
    return;
    }
    }
    }

    void draw_firedata(GameTime gameTime)
    {
    float t = gameTime.ElapsedGameTime.Milliseconds;

    for (int i = 0; i < Maxfiredata; i++)
    {
    if (firedata[i].side == fireside_player)
    {
    spriteBatch.Draw(fire1, firedata[i].pos - new Vector2(16, 16), Color.White);
    }
    if (firedata[i].side == fireside_enemy)
    {
    spriteBatch.Draw(fire2, firedata[i].pos - new Vector2(16, 16), Color.White);
    }

    if (firedata[i].side != fireside_empty)
    {
    firedata[i].pos += firedata[i].velocity * t;

    if (firedata[i].pos.X < 0) firedata[i].side = fireside_empty;
    if (firedata[i].pos.Y < 0) firedata[i].side = fireside_empty;
    if (firedata[i].pos.X > Window.ClientBounds.Width) firedata[i].side = fireside_empty;
    if (firedata[i].pos.Y > Window.ClientBounds.Height) firedata[i].side = fireside_empty;
    }
    }
    }
    //-----

    //---------- line -----------------
    Texture2D line;

    void DrawLine(Vector2 a, Vector2 b, Color col)
    {
    Vector2 Origin = new Vector2(0.5f, 0.0f);
    Vector2 diff = b - a;
    Vector2 Scale = new Vector2(0.1f, diff.Length() / line.Height);
    float angle = (float)(Math.Atan2(diff.Y, diff.X) - MathHelper.PiOver2);

    spriteBatch.Draw(line, a, null, col, angle, Origin, Scale, SpriteEffects.None, 1.0f);
    }
    //-------------------------------

    float calcAngle(Vector2 a, Vector2 b)
    {
    Vector2 diff = b - a;
    float angle = (float)(Math.Atan2(diff.Y, diff.X) - MathHelper.PiOver2);
    return angle;
    }

    float calcDistance(Vector2 a, Vector2 b)
    {
    Vector2 diff = b - a;
    float dist = (float)(Math.Sqrt(Math.Pow(diff.X, 2) + Math.Pow(diff.Y, 2)));
    return dist;
    }

    Vector2 Angle2Vector(float angle, float r)
    {
    Vector2 v;
    angle += -MathHelper.PiOver2;
    v.X = (float)Math.Cos(angle) * r;
    v.Y = (float)Math.Sin(angle) * r;
    return v;
    }

    void DrawShip(Vector2 pos, float angle)
    {
    spriteBatch.Draw(ship, pos, null, Color.White,
    angle, new Vector2(64, 64), Vector2.One, SpriteEffects.None, 1.0f);
    }
    //-------------------------------


    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

    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
    line = Content.Load<Texture2D>("line");
    ship = Content.Load<Texture2D>("ship");
    font1 = Content.Load<SpriteFont>("freesiaupc");

    background = Content.Load<Texture2D>("background");
    nebula = Content.Load<Texture2D>("nebula");
    bomb = Content.Load<Texture2D>("bomb");
    enemy1 = Content.Load<Texture2D>("planet1");
    enemy2 = Content.Load<Texture2D>("planet2");
    fire1 = Content.Load<Texture2D>("fire1");
    fire2 = Content.Load<Texture2D>("fire2");

    this.IsMouseVisible = true;
    shippos = new Vector2((Window.ClientBounds.Width) / 2,
    (Window.ClientBounds.Height) / 2);

    clear_firedata();

    clear_enemydata();
    add_enemydata(new Vector2(10, 10), enemy_type1);
    add_enemydata(new Vector2(400, 200), enemy_type2);
    }

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

    UpdateInput(gameTime);

    // TODO: Add your update logic here

    base.Update(gameTime);
    }


    private void UpdateInput(GameTime gameTime)
    {
    float timepass = gameTime.ElapsedGameTime.Milliseconds;

    //---- keyboard
    KeyboardState k = Keyboard.GetState();
    if (k.IsKeyDown(Keys.A)) { shippos.X -= shipspeed * timepass; }
    if (k.IsKeyDown(Keys.D)) { shippos.X += shipspeed * timepass; }
    if (k.IsKeyDown(Keys.W)) { shippos.Y -= shipspeed * timepass; }
    if (k.IsKeyDown(Keys.S)) { shippos.Y += shipspeed * timepass; }

    if (shippos.X < 32) shippos.X = 32;
    if (shippos.Y < 32) shippos.Y = 32;
    if (shippos.X > Window.ClientBounds.Width - 32) shippos.X = Window.ClientBounds.Width - 32;
    if (shippos.Y > Window.ClientBounds.Height - 32) shippos.Y = Window.ClientBounds.Height - 32;

    //---- mouse
    MouseState m = Mouse.GetState();
    // get position
    mpos = new Vector2(m.X, m.Y);
    if (m.LeftButton == ButtonState.Pressed)
    {
    if (isshipfired == 0) isshipfired = 1;
    }
    else
    {
    isshipfired = 0;
    }
    }
    Rectangle getRectangle(int index,
    int width, int height,
    int imagewidth, int imageheight)
    {
    Rectangle rec = new Rectangle();
    rec.X = (index % width) * (imagewidth / width) + 4;
    rec.Y = (index / width) * (imageheight / height) + 4;
    rec.Width = (imagewidth / width) - 8;
    rec.Height = (imageheight / height) - 8;
    return(rec);
    }
    /// <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();
    spriteBatch.Draw(background, Vector2.Zero, Color.White);
    spriteBatch.End();

    spriteBatch.Begin(SpriteBlendMode.Additive);
    nebularpos.Y += +gameTime.ElapsedGameTime.Milliseconds;
    if (nebularpos.Y > Window.ClientBounds.Height) nebularpos.Y = -512;
    spriteBatch.Draw(nebula, nebularpos, Color.White);
    spriteBatch.DrawString(font1, @"Pos " + shippos.X + " " + shippos.Y,
    new Vector2(10, 10), Color.WhiteSmoke);
    spriteBatch.DrawString(font1, @"MPos " + mpos.X + " " + mpos.Y,
    new Vector2(10, 50), Color.WhiteSmoke);
    spriteBatch.DrawString(font1, @"cartesian angle " + ((int)(Math.Abs(shipangle - MathHelper.PiOver2) * 180 / Math.PI)),
    new Vector2(10, 100), Color.WhiteSmoke);
    spriteBatch.DrawString(font1, @"azimuth angle " + ((int)(360 + (shipangle) * 180 / Math.PI) % 360),
    new Vector2(10, 150), Color.WhiteSmoke);
    spriteBatch.DrawString(font1, @"fire " + isshipfired + " ",
    new Vector2(10, 200), Color.WhiteSmoke);
    http://spriteBatch.Draw(ship, shippos, Color.White);
    spriteBatch.End();

    spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
    DrawLine(shippos, mpos, Color.Firebrick);
    spriteBatch.End();

    shipangle = calcAngle(mpos, shippos);
    spriteBatch.Begin();
    DrawShip(shippos, shipangle);

    Vector2 v;
    v = Angle2Vector(shipangle, 0.75f);
    if (isshipfired == 1) { add_firedata(shippos, v, fireside_player); isshipfired = 2; }
    draw_firedata(gameTime);

    int index = (gameTime.ElapsedGameTime.Milliseconds / 20) % 16;
    loop++;if(loop>15){loop=0;}

    spriteBatch.Draw(bomb, new Vector2(10, 10),
    getRectangle(loop, 4, 4, 512, 512),
    Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);


    draw_enemydata(gameTime);


    spriteBatch.End();

    base.Draw(gameTime);
    }
    }
    }

      เวลาขณะนี้ Thu Sep 19, 2024 9:04 am