Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Make an Asteroid Class</p> <pre><code>public class Asteroid { public Vector2 Velocity; public Vector2 Position; public Asteroid(Vector2 velocity, vector2 position) { Velocity = velocity; Position = position; } } </code></pre> <p>Now change your list to:</p> <pre><code>List&lt;Asteroid&gt; Asteroids = ... </code></pre> <p>And from now on you can do something like this</p> <pre><code>Asteroids[0].Velocity = Whatever </code></pre> <p>This way you can modify each <strong>instance</strong> of an asteroid</p> <p>Now take a look at your draw method,</p> <pre><code>public void DrawAsteroid(float x, float y) { vAsteroid.X -= 5; vAsteroid.Y = y; spriteBatch.Begin(); spriteBatch.Draw(Game1.tAsteroid, vAsteroid, Color.White); spriteBatch.End(); } </code></pre> <p>Your not even using the x and y values, so whats the point? Now everywhere in your code you MUST remove vASteroid and use the instance in the list!</p> <p>Change <code>DrawAsteroid</code> to this:</p> <pre><code> public void DrawAsteroid(Asteroid a) { spriteBatch.Begin(); spriteBatch.Draw(Game1.tAsteroid, a.Position, Color.White); spriteBatch.End(); } </code></pre> <p>And the call to it..</p> <pre><code> foreach (Asteroid a in Asteroids) //Draw each astroid { DrawAsteroid(a); } </code></pre> <p>Now we need to do the same thing in update, don't update your positions in <code>Draw()</code></p> <p>Add this in Update:</p> <pre><code> foreach (Asteroid a in Asteroids) //Update each astroid { UpdateAsteroid(a, elapsed); } </code></pre> <p>And add the new method...</p> <pre><code> public void UpdateAsteroid(Asteroid a, float elapsed) { a.Position += a.Velocity * elapsed; } </code></pre> <p>Now, when you spawn an asteroid, you need to make sure you have velocity added!</p> <pre><code>Asteroids.Add(new Asteroid(new Vector2(0,-10), new Vector2(50,50))); </code></pre> <p>That will spawn an Asteroid with a Y <em>velocity</em> of -10 and a <em>position</em> of 50,50</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload