Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 WindowsGame2
- {
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics; //экран
- SpriteBatch spriteBatch; //Перо для рисования
- Texture2D tex;
- Rectangle rec;
- int speed = 5;
- int PanelW, PanelH;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- protected override void Initialize()
- {
- //Выполняется при старте
- base.Initialize();
- }
- //После старта. Загрузка контента в программу.
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- tex = Content.Load<Texture2D>("187806-earthwormjim");
- rec = new Rectangle(100, 100, 100, 100*tex.Height/tex.Width);
- PanelW = graphics.PreferredBackBufferWidth;
- PanelH = graphics.PreferredBackBufferHeight;
- }
- //Изменение логики игры, до отрисовки.
- int t = 1;
- protected override void Update(GameTime gameTime)
- {
- if (Keyboard.GetState().IsKeyDown(Keys.Right))
- {
- rec.X += speed;
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Down))
- {
- rec.Y += speed;
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Left))
- {
- rec.X -= speed;
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Up))
- {
- rec.Y -= speed;
- }
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.White);
- //Отрисовка игры
- spriteBatch.Begin();
- spriteBatch.Draw(tex, rec, Color.White);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement