Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- KLOCEK
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- namespace arkanoid
- {
- class klocek : Microsoft.Xna.Framework.Game
- {
- public double wytrzymalosc;
- public double pozycjax;
- public double pozycjay;
- public Color kolor;
- public klocek(double roz, double pozx, double pozy)
- {
- wytrzymalosc = roz;
- pozycjax = pozx;
- pozycjay = pozy;
- kolor = Color.Black;
- }
- void oberwanie()
- {
- wytrzymalosc--;
- }
- public void zmienkolor()
- {
- wytrzymalosc--;
- if (wytrzymalosc == 2)
- {
- kolor = Color.Black;
- }
- if (wytrzymalosc == 1)
- {
- kolor = Color.White;
- }
- }
- }
- }---------------------------------------------------------------------------
- Kulka
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace arkanoid
- {
- class kula
- {
- public double x;
- public double y;
- public double rozmiar;
- public double kat;
- public double predkosc;
- public kula(double a, double b, double c, double d, double e)
- {
- x = a;
- y = b;
- rozmiar = c;
- kat = d;
- predkosc = e;
- }
- }
- }
- -------------------------------------------------------------------------------
- GRACZ
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace arkanoid
- {
- class Gracz
- {
- public int rozmiar;
- public int pozycjax;
- public int pozycjay;
- public static int ilosczyc;
- public Gracz(int roz, int pozx, int pozy)
- {
- rozmiar = roz;
- pozycjax = pozx;
- pozycjay = pozy;
- ilosczyc = 3;
- }
- }
- }
- -------------------------------------------------------------------------------------
- GAME
- 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 arkanoid
- {
- /// <summary>
- /// This is the main type for your game
- /// </summary>
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- int wynik = 0;
- int a, b;
- SpriteBatch spriteBatch;
- SpriteFont font;
- Gracz player;
- kula bala;
- Texture2D grac, pilka, kloc;
- List<klocek> klocki;
- Rectangle g;
- Rectangle p;
- Rectangle k;
- string cos = "aa";
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- graphics.PreferredBackBufferHeight = 800;
- graphics.PreferredBackBufferWidth = 600;
- graphics.IsFullScreen = true;
- }
- /// <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();
- player = new Gracz(100, (GraphicsDevice.Viewport.Width / 2), (GraphicsDevice.Viewport.Height * 7 / 8));
- bala = new kula((GraphicsDevice.Viewport.Width / 2), (GraphicsDevice.Viewport.Height / 2), 100, 45, 5);
- klocki = new List<klocek>();
- tworzenieklockow();
- }
- /// <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);
- font = Content.Load<SpriteFont>(@"Spritefont1");
- grac = Content.Load<Texture2D>(@"stat");
- pilka = Content.Load<Texture2D>(@"kulka");
- kloc = Content.Load<Texture2D>(@"klocek");
- // TODO: use this.Content to load your game content here
- }
- /// <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();
- if (Keyboard.GetState().IsKeyDown(Keys.Escape) == true) { this.Exit(); }
- if (Keyboard.GetState().IsKeyDown(Keys.Right) == true) { player.pozycjax += 16; }
- if (Keyboard.GetState().IsKeyDown(Keys.Left) == true) { player.pozycjax -= 16; }
- // TODO: Add your update logic here
- bala.y -= 10 * (Math.Cos(bala.kat * MathHelper.Pi / 180));
- bala.x += 10 * (Math.Sin(bala.kat * MathHelper.Pi / 180));
- base.Update(gameTime);
- p = new Rectangle((int)bala.x, (int)bala.y, 30, 30);
- for (int i = 0; i < klocki.Count(); i++)
- {
- k = new Rectangle((int)klocki[i].pozycjax, (int)klocki[i].pozycjay, 100, 30);
- if (p.Intersects(k))
- {
- klocki[i].zmienkolor();
- if (klocki[i].wytrzymalosc == 0)
- {
- klocki.RemoveAt(i);
- }
- bala.kat = 180 - bala.kat;
- wynik++;
- }
- }
- if (bala.y < 0)
- {
- bala.kat = 180 - bala.kat;
- }
- if (bala.x > GraphicsDevice.Viewport.Width - 35)
- {
- bala.kat = 360 - bala.kat;
- }
- if (bala.x < 10)
- {
- bala.kat = 360 - bala.kat;
- }
- g = new Rectangle(player.pozycjax, player.pozycjay, 100, 30);
- if (g.Intersects(p))
- {
- bala.kat = ((int)bala.x - (player.pozycjax + 35));
- }
- }
- /// <summary>
- /// This is called when the game should draw itself.
- /// </summary>6
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin();
- spriteBatch.DrawString(font, ("wynik :" + wynik.ToString()), new Vector2(100, 100), Color.Black);
- spriteBatch.DrawString(font, cos, new Vector2(200, 200), Color.Black);
- spriteBatch.Draw(grac, new Rectangle(player.pozycjax, player.pozycjay, 100, 20), Color.White);
- spriteBatch.Draw(pilka, new Rectangle((int)bala.x, (int)bala.y, 30, 30), Color.White);
- foreach (klocek klo in klocki)
- {
- spriteBatch.Draw(kloc, new Rectangle((int)klo.pozycjax, (int)klo.pozycjay, 100, 30), klo.kolor);
- }
- spriteBatch.End();
- // TODO: Add your drawing code here
- base.Draw(gameTime);
- }
- void tworzenieklockow()
- {
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 4; j++)
- {
- klocek kl = new klocek(2, (GraphicsDevice.Viewport.Width / 11 * i), (GraphicsDevice.Viewport.Height / 15 * j));
- klocki.Add(kl);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement