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 test
- {
- public class Enemy
- {
- public Texture2D enemy_T;
- public Rectangle enemy_Rect;
- public Color enemy_color;
- public int enemy_type;
- public int enemy_hit_white = 0;
- public int enemy_hit_other = 0;
- public void setType(int typ)
- {
- if (typ >= 0 && typ <= 100)
- {
- enemy_type = 0;
- enemy_color = Color.White;
- }
- else if (typ >= 101 && typ <= 200)
- {
- enemy_type = 1;
- enemy_color = Color.Green;
- }
- else
- {
- enemy_type = 2;
- enemy_color = Color.Red;
- }
- }
- public void EnemyHitted()
- {
- if (enemy_type == 0)
- {
- enemy_hit_white++;
- }
- else
- {
- enemy_hit_other++;
- }
- }
- };
- /// <summary>
- /// This is the main type for your game
- /// </summary>
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Texture2D background_T;
- Rectangle background_Rect;
- Random rand = new Random();
- Enemy enemy = new Enemy();
- float Time_step = 1.0f;
- float Current_Time = 0.0f;
- int back_value_ss_x;
- int back_value_ss_y;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- 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
- Window.Title = "Points White:0 || Other:0";
- background_Rect = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
- enemy.enemy_Rect = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth / 12, GraphicsDevice.PresentationParameters.BackBufferHeight / 10);
- enemy.setType(rand.Next(0,300));
- back_value_ss_x = GraphicsDevice.PresentationParameters.BackBufferWidth;
- back_value_ss_y = GraphicsDevice.PresentationParameters.BackBufferHeight;
- 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()
- {
- this.IsMouseVisible = true;
- Window.AllowUserResizing = true;
- // Create a new SpriteBatch, which can be used to draw textures.
- spriteBatch = new SpriteBatch(GraphicsDevice);
- background_T = this.Content.Load<Texture2D>("street");
- enemy.enemy_T = this.Content.Load<Texture2D>("ghost");
- // 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)
- {
- KeyboardState state = Keyboard.GetState();
- MouseState state_mouse = Mouse.GetState();
- // Allows the game to exit
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- this.Exit();
- if (state.IsKeyDown(Keys.Escape)) this.Exit();
- if (back_value_ss_x != GraphicsDevice.PresentationParameters.BackBufferWidth)
- {
- background_Rect = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
- back_value_ss_x = GraphicsDevice.PresentationParameters.BackBufferWidth;
- }
- if (back_value_ss_y != GraphicsDevice.PresentationParameters.BackBufferHeight)
- {
- background_Rect = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
- back_value_ss_y = GraphicsDevice.PresentationParameters.BackBufferHeight;
- }
- if (state_mouse.LeftButton == ButtonState.Pressed)
- {
- Point mouse_pos = new Point(state_mouse.X, state_mouse.Y);
- if (enemy.enemy_Rect.Contains(mouse_pos))
- {
- enemy.EnemyHitted();
- enemy.setType(rand.Next(0, 300));
- 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);
- Current_Time = 0;
- Window.Title = "Points White:" + enemy.enemy_hit_white + " || Other:" + enemy.enemy_hit_other;
- }
- }
- Current_Time += (float)gameTime.ElapsedGameTime.TotalSeconds;
- if (Current_Time > Time_step)
- {
- enemy.setType(rand.Next(0, 300));
- 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);
- Current_Time = 0;
- }
- // TODO: Add your update logic here
- 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);
- // TODO: Add your drawing code here
- spriteBatch.Begin();
- spriteBatch.Draw(background_T, background_Rect, Color.White);
- spriteBatch.Draw(enemy.enemy_T, enemy.enemy_Rect, enemy.enemy_color);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement