Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- 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 Platformer
- {
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Texture2D tankright;
- Texture2D tankleft;
- Texture2D tankup;
- Texture2D tankdown;
- Texture2D fal;
- Level szint;
- Tank player1;
- Tank player2;
- SpriteFont Verdana;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- graphics.PreferredBackBufferHeight = 640;
- graphics.PreferredBackBufferWidth = 640;
- graphics.ApplyChanges();
- Content.RootDirectory = "Content";
- }
- protected override void Initialize()
- {
- Window.Title = "Tankos játék - By $0undX";
- base.Initialize();
- }
- protected override void LoadContent()
- {
- // Create a new SpriteBatch, which can be used to draw textures.
- spriteBatch = new SpriteBatch(GraphicsDevice);
- tankup = Content.Load<Texture2D>("tankfel");
- tankdown = Content.Load<Texture2D>("tankle");
- tankleft = Content.Load<Texture2D>("tankbalra");
- tankright = Content.Load<Texture2D>("tankjobbra");
- fal = Content.Load<Texture2D>("fal");
- Verdana = Content.Load<SpriteFont>("Verdana");
- player1 = new Tank(true, tankleft, tankright, tankup, tankdown);
- player2 = new Tank(false, tankleft, tankright, tankup, tankdown);
- szint = new Level(new StreamReader("palya.txt"), ref player1, ref player2);
- }
- protected override void UnloadContent()
- {
- }
- protected override void Update(GameTime gameTime)
- {
- // Allows the game to exit
- if (Keyboard.GetState().IsKeyDown(Keys.Escape))
- this.Exit();
- DoKeyBoardActions(Keyboard.GetState());
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin();
- DrawTheGame(szint);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- public void DoKeyBoardActions(KeyboardState bill)
- {
- player1.DoKeyBoardActions(bill);
- player2.DoKeyBoardActions(bill);
- }
- public void DrawBlock(int x, int y)
- {
- spriteBatch.Draw(fal, new Rectangle(x * 64, y * 64, 64, 64), Color.White);
- }
- public void DrawTheGame(Level palya)
- {
- for (int i = 0; i < palya.GetContentX().Length; i++)
- {
- if (i <= 1)
- {
- if(i == 0)
- {
- player1.Draw(spriteBatch);
- }
- if (i == 1)
- {
- player2.Draw(spriteBatch);
- }
- }
- else
- DrawBlock(palya.GetContentX()[i], palya.GetContentY()[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement