1
0
mirror of https://github.com/Memorix101/UnityXNA/ synced 2024-12-30 15:25:35 +01:00
Barnaby Smith 6fe889760d First commit. Proof of concept implementation.
The XNA 4.0 PlatformerGame sample is successfully running inside Unity3D
3.5.
Implemented a basic game loop, game timing, content loading for
Texture2D, SoundEffect and Song. Emulated SpriteBatch drawing for
sprites and strings (note SpriteFont is not yet supported to all strings
are rendered using the default GUI label font). Songs can be played
using an AudioSource attached to the XNATest game object which acts as
an emulator for MediaPlayer. Playing a SoundEffect creates a game object
with an AudioSource attached which is automatically deleted when the
sound finishes. Implemented keyboard input with a limited set of XNA
Keys mapping to Unity3D KeyCodes.
2012-07-07 20:57:54 +01:00

55 lines
1.5 KiB
C#

#region File Description
//-----------------------------------------------------------------------------
// Circle.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
using System;
using Microsoft.Xna.Framework;
namespace Platformer
{
/// <summary>
/// Represents a 2D circle.
/// </summary>
struct Circle
{
/// <summary>
/// Center position of the circle.
/// </summary>
public Vector2 Center;
/// <summary>
/// Radius of the circle.
/// </summary>
public float Radius;
/// <summary>
/// Constructs a new circle.
/// </summary>
public Circle(Vector2 position, float radius)
{
Center = position;
Radius = radius;
}
/// <summary>
/// Determines if a circle intersects a rectangle.
/// </summary>
/// <returns>True if the circle and rectangle overlap. False otherwise.</returns>
public bool Intersects(Rectangle rectangle)
{
Vector2 v = new Vector2(MathHelper.Clamp(Center.X, rectangle.Left, rectangle.Right),
MathHelper.Clamp(Center.Y, rectangle.Top, rectangle.Bottom));
Vector2 direction = Center - v;
float distanceSquared = direction.LengthSquared();
return ((distanceSquared > 0) && (distanceSquared < Radius * Radius));
}
}
}