Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using System;
- namespace gra1.Desktop
- {
- /// <summary>
- /// This is the main type for your game.
- /// </summary>
- public class Game1 : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- //zmienne gry
- private Texture2D tlo;
- private Vector2 pozycja_tlo;
- private Texture2D p1;
- private Vector2 pozycja_p1;
- private Texture2D ob1;
- private Vector2 pozycja_ob1;
- private Vector2 pozycja_ob1n2;
- private Vector2 pozycja_ob1n3;
- private float obrot = 0;
- private float obrot2 = 0;
- private float obrot3 = 0;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- graphics.PreferredBackBufferWidth = 800;
- graphics.PreferredBackBufferHeight = 600;
- 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);
- tlo = this.Content.Load<Texture2D>("lul0");
- p1 = this.Content.Load<Texture2D>("lup0");
- ob1 = this.Content.Load<Texture2D>("luo1");
- pozycja_p1.Y = 500;
- pozycja_p1.X = 500;
- pozycja_ob1.Y = 0;
- pozycja_ob1.X = 200;
- pozycja_ob1n2.Y = 0;
- pozycja_ob1n2.X = 200;
- pozycja_ob1n3.Y = 0;
- pozycja_ob1n3.X = 200;
- // TODO: use this.Content to load your game content here
- }
- /// <summary>
- /// UnloadContent will be called once per game and is the place to unload
- /// game-specific 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)
- {
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
- // TODO: Add your update logic here
- KeyboardState klawisz = Keyboard.GetState();
- if (klawisz.IsKeyDown(Keys.Right))
- {
- pozycja_p1.X += 20;
- p1 = this.Content.Load<Texture2D>("lup1");
- }
- if (klawisz.IsKeyDown(Keys.Left))
- {
- pozycja_p1.X -= 20;
- p1 = this.Content.Load<Texture2D>("lup0");
- }
- if (klawisz.IsKeyDown(Keys.Up))
- {
- pozycja_p1.Y -= 2;
- }
- if (klawisz.IsKeyDown(Keys.Down))
- {
- pozycja_p1.Y += 2;
- }
- //przeskakiwanie przy krawędziach
- if (pozycja_p1.X < 0)
- {
- pozycja_p1.X = 800;
- }
- if (pozycja_p1.X > 800)
- {
- pozycja_p1.X = 0;
- }
- //pozycja banana
- pozycja_ob1.Y = pozycja_ob1.Y + 10;
- if (pozycja_ob1.Y > 600)
- {
- pozycja_ob1.Y = 0;
- Random losuj = new Random();
- pozycja_ob1.X = losuj.Next(0, 700);
- }
- pozycja_ob1n2.Y = pozycja_ob1n2.Y + 20;
- if (pozycja_ob1n2.Y > 600)
- {
- pozycja_ob1n2.Y = 0;
- Random losuj = new Random();
- pozycja_ob1n2.X = losuj.Next(0, 700);
- }
- pozycja_ob1n3.Y = pozycja_ob1n3.Y + 5;
- if (pozycja_ob1n3.Y > 600)
- {
- pozycja_ob1n3.Y = 0;
- Random losuj = new Random();
- pozycja_ob1n3.X = losuj.Next(0, 700);
- }
- //obrot banana
- obrot += 0.01f;
- obrot2 += 0.02f;
- obrot3 += 0.006f;
- 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);
- Vector2 kat = new Vector2(0, 0);
- Rectangle nowy = new Rectangle(0, 0, ob1.Width, ob1.Height);
- spriteBatch.Begin();
- spriteBatch.Draw(tlo, pozycja_tlo, Color.White);
- spriteBatch.Draw(ob1, pozycja_ob1, nowy, Color.White, obrot, kat, 1.0f, SpriteEffects.None, 1);
- spriteBatch.Draw(ob1, pozycja_ob1n2, nowy, Color.White, obrot2, kat, 1.0f, SpriteEffects.None, 1);
- spriteBatch.Draw(ob1, pozycja_ob1n3, nowy, Color.White, obrot3, kat, 1.0f, SpriteEffects.None, 1);
- spriteBatch.End();
- spriteBatch.Begin();
- spriteBatch.Draw(p1, pozycja_p1, Color.White);
- spriteBatch.End();
- // TODO: Add your drawing code here
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment