SHARE
TWEET

Untitled

a guest Oct 16th, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  12.  
  13.  
  14. namespace test
  15. {
  16.     public class Enemy
  17.     {
  18.         public Texture2D enemy_T;
  19.         public Rectangle enemy_Rect;
  20.         public Color enemy_color;
  21.         public int enemy_type;
  22.  
  23.         public int enemy_hit_white = 0;
  24.         public int enemy_hit_other = 0;
  25.  
  26.         public void setType(int typ)
  27.         {
  28.             if (typ >= 0 && typ <= 100)
  29.             {
  30.                 enemy_type = 0;
  31.                 enemy_color = Color.White;
  32.             }
  33.             else if (typ >= 101 && typ <= 200)
  34.             {
  35.                 enemy_type = 1;
  36.                 enemy_color = Color.Green;
  37.             }
  38.             else
  39.             {
  40.                 enemy_type = 2;
  41.                 enemy_color = Color.Red;
  42.             }
  43.         }
  44.         public void EnemyHitted()
  45.         {
  46.             if (enemy_type == 0)
  47.             {
  48.                 enemy_hit_white++;
  49.             }
  50.             else
  51.             {
  52.                 enemy_hit_other++;
  53.             }
  54.         }
  55.     };
  56.  
  57.     /// <summary>
  58.     /// This is the main type for your game
  59.     /// </summary>
  60.     public class Game1 : Microsoft.Xna.Framework.Game
  61.     {
  62.         GraphicsDeviceManager graphics;
  63.         SpriteBatch spriteBatch;
  64.  
  65.         Texture2D   background_T;
  66.         Rectangle   background_Rect;
  67.  
  68.         Random rand = new Random();
  69.        
  70.         Enemy enemy = new Enemy();
  71.         float Time_step = 1.0f;
  72.         float Current_Time = 0.0f;
  73.  
  74.         int back_value_ss_x;
  75.         int back_value_ss_y;
  76.        
  77.         public Game1()
  78.         {
  79.             graphics = new GraphicsDeviceManager(this);
  80.             Content.RootDirectory = "Content";
  81.         }
  82.  
  83.         /// <summary>
  84.         /// Allows the game to perform any initialization it needs to before starting to run.
  85.         /// This is where it can query for any required services and load any non-graphic
  86.         /// related content.  Calling base.Initialize will enumerate through any components
  87.         /// and initialize them as well.
  88.         /// </summary>
  89.         protected override void Initialize()
  90.         {
  91.             // TODO: Add your initialization logic here
  92.            Window.Title = "Points White:0 || Other:0";
  93.  
  94.            background_Rect = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
  95.            
  96.            enemy.enemy_Rect = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth / 12, GraphicsDevice.PresentationParameters.BackBufferHeight / 10);
  97.            enemy.setType(rand.Next(0,300));
  98.  
  99.  
  100.            back_value_ss_x = GraphicsDevice.PresentationParameters.BackBufferWidth;
  101.            back_value_ss_y = GraphicsDevice.PresentationParameters.BackBufferHeight;
  102.            base.Initialize();
  103.         }
  104.  
  105.         /// <summary>
  106.         /// LoadContent will be called once per game and is the place to load
  107.         /// all of your content.
  108.         /// </summary>
  109.         protected override void LoadContent()
  110.         {
  111.             this.IsMouseVisible = true;
  112.             Window.AllowUserResizing = true;
  113.             // Create a new SpriteBatch, which can be used to draw textures.
  114.             spriteBatch = new SpriteBatch(GraphicsDevice);
  115.             background_T = this.Content.Load<Texture2D>("street");
  116.             enemy.enemy_T = this.Content.Load<Texture2D>("ghost");
  117.             // TODO: use this.Content to load your game content here
  118.         }
  119.  
  120.         /// <summary>
  121.         /// UnloadContent will be called once per game and is the place to unload
  122.         /// all content.
  123.         /// </summary>
  124.         protected override void UnloadContent()
  125.         {
  126.             // TODO: Unload any non ContentManager content here
  127.         }
  128.  
  129.         /// <summary>
  130.         /// Allows the game to run logic such as updating the world,
  131.         /// checking for collisions, gathering input, and playing audio.
  132.         /// </summary>
  133.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  134.         protected override void Update(GameTime gameTime)
  135.         {
  136.             KeyboardState   state = Keyboard.GetState();
  137.             MouseState      state_mouse = Mouse.GetState();
  138.             // Allows the game to exit
  139.  
  140.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  141.                 this.Exit();
  142.  
  143.             if (state.IsKeyDown(Keys.Escape)) this.Exit();
  144.  
  145.             if (back_value_ss_x != GraphicsDevice.PresentationParameters.BackBufferWidth)
  146.             {
  147.                background_Rect = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
  148.                back_value_ss_x = GraphicsDevice.PresentationParameters.BackBufferWidth;
  149.             }
  150.  
  151.             if (back_value_ss_y != GraphicsDevice.PresentationParameters.BackBufferHeight)
  152.             {
  153.                 background_Rect = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
  154.                 back_value_ss_y = GraphicsDevice.PresentationParameters.BackBufferHeight;
  155.             }
  156.  
  157.             if (state_mouse.LeftButton == ButtonState.Pressed)
  158.             {
  159.                 Point mouse_pos = new Point(state_mouse.X, state_mouse.Y);
  160.                 if (enemy.enemy_Rect.Contains(mouse_pos))
  161.                 {
  162.                     enemy.EnemyHitted();
  163.                     enemy.setType(rand.Next(0, 300));
  164.                     enemy.enemy_Rect = new Rectangle(rand.Next(0, GraphicsDevice.PresentationParameters.BackBufferWidth - enemy.enemy_Rect.Width), rand.Next(0, GraphicsDevice.PresentationParameters.BackBufferHeight - enemy.enemy_Rect.Height), GraphicsDevice.PresentationParameters.BackBufferWidth / 12, GraphicsDevice.PresentationParameters.BackBufferHeight / 10);
  165.                     Current_Time = 0;
  166.                     Window.Title = "Points White:" + enemy.enemy_hit_white + " || Other:" + enemy.enemy_hit_other;
  167.                 }
  168.             }
  169.  
  170.             Current_Time += (float)gameTime.ElapsedGameTime.TotalSeconds;
  171.  
  172.             if (Current_Time > Time_step)
  173.             {
  174.                 enemy.setType(rand.Next(0, 300));
  175.                 enemy.enemy_Rect = new Rectangle(rand.Next(0, GraphicsDevice.PresentationParameters.BackBufferWidth - enemy.enemy_Rect.Width), rand.Next(0, GraphicsDevice.PresentationParameters.BackBufferHeight - enemy.enemy_Rect.Height), GraphicsDevice.PresentationParameters.BackBufferWidth / 12, GraphicsDevice.PresentationParameters.BackBufferHeight / 10);
  176.                 Current_Time = 0;
  177.             }
  178.  
  179.             // TODO: Add your update logic here
  180.  
  181.             base.Update(gameTime);
  182.         }
  183.  
  184.         /// <summary>
  185.         /// This is called when the game should draw itself.
  186.         /// </summary>
  187.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  188.         protected override void Draw(GameTime gameTime)
  189.         {
  190.             GraphicsDevice.Clear(Color.CornflowerBlue);
  191.  
  192.             // TODO: Add your drawing code here
  193.             spriteBatch.Begin();
  194.  
  195.                 spriteBatch.Draw(background_T, background_Rect, Color.White);
  196.                 spriteBatch.Draw(enemy.enemy_T, enemy.enemy_Rect, enemy.enemy_color);
  197.  
  198.             spriteBatch.End();
  199.  
  200.             base.Draw(gameTime);
  201.         }
  202.     }
  203. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top