Advertisement
Remix17

Test biblioteki Camera2DLib

Jul 4th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. using Camera2DLib;
  12.  
  13. namespace TestCam
  14. {
  15.  
  16.     public class Game1 : Microsoft.Xna.Framework.Game
  17.     {
  18.         GraphicsDeviceManager graphics;
  19.         SpriteBatch spriteBatch;
  20.  
  21.         Texture2D[] tex = new Texture2D[2];
  22.  
  23.         CreateObjectCenter center;
  24.         Camera cam;
  25.         Control controlkey;
  26.         Object2D[] array_objects = new Object2D[3];
  27.        
  28.         public Game1()
  29.         {
  30.             graphics = new GraphicsDeviceManager(this);
  31.             Content.RootDirectory = "Content";
  32.         }
  33.  
  34.         protected override void Initialize()
  35.         {
  36.  
  37.             tex[0] = Content.Load<Texture2D>("IMG_0001O");
  38.             tex[1] = Content.Load<Texture2D>("IMG_0006");
  39.  
  40.             center = new CreateObjectCenter(150, 150, 30, 30, tex[0]);
  41.             controlkey = new Control(Keys.Up, Keys.Down, Keys.Left, Keys.Right);
  42.             cam = new Camera(center, controlkey);
  43.  
  44.             Object2D ob1 = new Object2D(tex[1], new Rectangle(2,5,30,30));
  45.             Object2D ob2 = new Object2D(tex[1], new Rectangle(160,0,30,30));
  46.             Object2D ob3 = new Object2D(tex[1], new Rectangle(500,0,30,30));
  47.  
  48.             array_objects[0] = ob1;
  49.             array_objects[1] = ob2;
  50.             array_objects[2] = ob3;
  51.  
  52.             base.Initialize();
  53.         }
  54.  
  55.         protected override void LoadContent()
  56.         {
  57.             spriteBatch = new SpriteBatch(GraphicsDevice);
  58.         }
  59.  
  60.         protected override void UnloadContent()
  61.         {
  62.            
  63.         }
  64.  
  65.         protected override void Update(GameTime gameTime)
  66.         {
  67.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  68.                 this.Exit();
  69.  
  70.             cam.Update(20, array_objects);
  71.  
  72.             if (Keyboard.GetState().IsKeyDown(Keys.F1))
  73.             {
  74.                 cam.Zoom(array_objects, 0, 50);
  75.             }
  76.  
  77.             if (Keyboard.GetState().IsKeyDown(Keys.F2))
  78.             {
  79.                 cam.Zoom(array_objects, 1, 50);
  80.             }
  81.             cam.MoveCamera(array_objects,100,-100);
  82.  
  83.             base.Update(gameTime);
  84.         }
  85.  
  86.         protected override void Draw(GameTime gameTime)
  87.         {
  88.             GraphicsDevice.Clear(Color.CornflowerBlue);
  89.  
  90.             DrawAllObjects draw = new DrawAllObjects(array_objects, spriteBatch);
  91.  
  92.             center.DrawObject(spriteBatch);
  93.  
  94.             base.Draw(gameTime);
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement