Guest User

Untitled

a guest
Apr 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.85 KB | None | 0 0
  1. //this is how I update and draw my bug in my bug class.
  2.  
  3.  public void Draw()
  4.         {
  5.            
  6.                 GL.glBindTexture(GL.GL_TEXTURE_2D, World.m_TextureIDs[6]);
  7.                 GL.glEnable(GL.GL_BLEND);
  8.                 GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
  9.  
  10.                 GL.glBegin(GL.GL_QUADS);
  11.  
  12.                 GL.glTexCoord2f(0.0f, 0.5f);
  13.                 GL.glVertex2f(m_bugSize + m_Position.X, -m_bugSize + m_Position.Y);
  14.                 GL.glTexCoord2f(1.0f, 0.5f);
  15.                 GL.glVertex2f(-m_bugSize + m_Position.X, -m_bugSize + m_Position.Y);
  16.                 GL.glTexCoord2f(1.0f, 1.0f);
  17.                 GL.glVertex2f(-m_bugSize + m_Position.X, m_bugSize + m_Position.Y);
  18.                 GL.glTexCoord2f(0.0f, 1.0f);
  19.                 GL.glVertex2f(m_bugSize + m_Position.X, m_bugSize + m_Position.Y);
  20.                 GL.glEnd();
  21.  
  22.                 GL.glBindTexture(GL.GL_TEXTURE_2D, World.m_TextureIDs[5]);
  23.                 GL.glBlendFunc(GL.GL_DST_COLOR, GL.GL_ZERO);
  24.  
  25.                 GL.glBegin(GL.GL_QUADS);
  26.  
  27.                 GL.glTexCoord2f(0.0f, 0.5f);
  28.                 GL.glVertex2f(m_bugSize + m_Position.X, -m_bugSize + m_Position.Y);
  29.                 GL.glTexCoord2f(1.0f, 0.5f);
  30.                 GL.glVertex2f(-m_bugSize + m_Position.X, -m_bugSize + m_Position.Y);
  31.                 GL.glTexCoord2f(1.0f, 1.0f);
  32.                 GL.glVertex2f(-m_bugSize + m_Position.X, m_bugSize + m_Position.Y);
  33.                 GL.glTexCoord2f(0.0f, 1.0f);
  34.                 GL.glVertex2f(m_bugSize + m_Position.X, m_bugSize + m_Position.Y);
  35.                 GL.glEnd();                  
  36.  
  37.              
  38.                
  39.         }
  40.  
  41.         public void Update(float pTimeStep)
  42.         {
  43.             m_Position = m_Position.Add(m_Velocity.Multiply(pTimeStep));
  44.         }
  45.  
  46. //this is how I spawn and update my bug in the world method. update is called 60 fps.
  47.  
  48. public void Update()
  49.         {
  50.             float timeStep = m_Timer.Seconds;
  51.  
  52.                 foreach (Bug bug in m_Bugs)
  53.                 {
  54.                     bug.Update(timeStep);
  55.                 }
  56.  
  57.                 m_TimeToNewBug -= timeStep;
  58.  
  59.                 while (m_TimeToNewBug <= 0f)
  60.                 {
  61.                     float velXbl = (float)(randomNumberGenerator.NextDouble());
  62.                     float velYbl = (float)(randomNumberGenerator.NextDouble());
  63.  
  64.                     float velXtr = (float)(randomNumberGenerator.NextDouble() - 1);
  65.                     float velYtr = (float)(randomNumberGenerator.NextDouble() - 1);
  66.  
  67.                     m_Bugs.Add(new Bug(50, new Vector2d(-2f, -2f), new Vector2d(velXbl, velYbl), 0.2f));//bottom left
  68.                     m_Bugs.Add(new Bug(50, new Vector2d(2f, 2f), new Vector2d(velXtr, velYtr), 0.2f)); //top right
  69.  
  70.                     m_TimeToNewBug += 1f / m_BugsPerSecond;
  71.                 }
  72.             }
  73.         }
Add Comment
Please, Sign In to add comment