我对monogame很新,而且我遇到了另一个我无法理解的问题。经过一些其他问题(这些问题已由你们解决了!)我已经遇到了另一个问题!
我似乎无法弄清楚为什么我的小怪会产生,其他一切产生并按原样运作,但敌人不会产卵。我对此比较陌生,所以我没有尝试过任何东西,只是在网上查看教程,看看我是否正确完成了但是我看不出我做错了什么。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Content;
namespace Roid_shoooota
{
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
//player and BG stuff
PlayerShip Player = new PlayerShip();
Background bG = new Background();
//asteroid stuff
List<Roids> asteroidList = new List<Roids>();
Random random = new Random();
//mob stuff
public int enemyBulletDamage;
List<Mobs> mobsList = new List<Mobs>();
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.IsFullScreen = false;
graphics.PreferredBackBufferWidth = 800;
graphics.PreferredBackBufferHeight = 950;
this.Window.Title = "Roid Shoota";
enemyBulletDamage = 10;
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
Player.LoadContent(Content);
bG.LoadContent(Content);
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
//updating mobs and checking for collisions
foreach (Mobs M in mobsList)
{
if (M.hitBox.Intersects(Player.boundingBox))
{
Player.health -= 40;
M.isVisible = false;
}
//enemy bullet collision with player
for (int i = 0; i < M.bulletList.Count; i++)
{
if (Player.boundingBox.Intersects(M.bulletList[i].hitBox))
{
Player.health -= enemyBulletDamage;
M.bulletList[i].isVisible = false;
}
}
for (int i = 0; i < Player.bulletList.Count; i++)
{
if (Player.bulletList[i].hitBox.Intersects(M.hitBox))
{
Player.bulletList[i].isVisible = false;
M.isVisible = false;
}
}
M.update(gameTime);
}
//updating the asteroid list, check for collisions
foreach (Roids R in asteroidList)
{
//if a roid hits the player get oot me game
if (R.hitBox.Intersects(Player.boundingBox))
{
Player.health -= 20;
R.isVisible = false;
}
for (int i = 0; i < Player.bulletList.Count; i++)
{
if (R.hitBox.Intersects(Player.bulletList[i].hitBox))
{
R.isVisible = false;
Player.bulletList.ElementAt(i).isVisible = false;
}
}
R.update(gameTime);
}
Player.update(gameTime);
bG.update(gameTime);
loadAsteroids();
loadMobs();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
bG.Draw(spriteBatch);
Player.draw(spriteBatch);
foreach (Roids R in asteroidList)
{
R.Draw(spriteBatch);
}
foreach (Mobs M in mobsList)
{
M.Draw(spriteBatch);
}
spriteBatch.End();
base.Draw(gameTime);
}
//random roid spawns
public void loadAsteroids()
{
int randY = random.Next(-600, -50);
int randX = random.Next(0, 750);
//create more if less than 5
if(asteroidList.Count() < 40)
{
asteroidList.Add(new Roids(Content.Load<Texture2D>("asteroid"), new Vector2(randX, randY)));
}
//if destoryed or off screen remove it from da list
for (int i = 0; i < asteroidList.Count; i++)
{
if (!asteroidList[i].isVisible)
{
asteroidList.RemoveAt(i);
i--;
}
}
}
//load mobs
public void loadMobs()
{
int randY = random.Next(-600, -50);
int randX = random.Next(0, 750);
//create more if less than 3
if (mobsList.Count() < 3)
{
mobsList.Add(new Mobs(Content.Load<Texture2D>("enemyship"), new Vector2(randX, randY), Content.Load<Texture2D>("EnemyBullet")));
}
//if destoryed or off screen remove it from da list
for (int i = 0; i < mobsList.Count; i++)
{
if (!mobsList[i].isVisible)
{
mobsList.RemoveAt(i);
i--;
}
}
}
}
}