Game Development Reference
In-Depth Information
Changing the Sprite class is a change to the Engine library, which is a change
that shouldn't be taken lightly. In this case, it is a good change that will be ben-
eficial to any future project using the Engine library. With the Sprite method
updated, the Entity class can be created back in the Shooter project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine;
using Tao.OpenGl;
using System.Drawing;
namespace Shooter
{
public class Entity
{
protected Sprite _sprite ¼ new Sprite();
public RectangleF GetBoundingBox()
{
float width ¼ (float)(_sprite.Texture.Width * _sprite.ScaleX);
float height ¼ (float)(_sprite.Texture.Height * _sprite.ScaleY);
return new RectangleF((float)_sprite.GetPosition().X - width / 2,
(float)_sprite.GetPosition().Y - height / 2,
width, height);
}
// Render a bounding box
protected void Render_Debug()
{
Gl.glDisable(Gl.GL_TEXTURE_2D);
RectangleF bounds ¼ GetBoundingBox();
Gl.glBegin(Gl.GL_LINE_LOOP);
{
Gl.glColor3f(1, 0, 0);
Gl.glVertex2f(bounds.Left, bounds.Top);
Gl.glVertex2f(bounds.Right, bounds.Top);
Gl.glVertex2f(bounds.Right, bounds.Bottom);
Gl.glVertex2f(bounds.Left, bounds.Bottom);
}
 
Search WWH ::




Custom Search