Added stuff
This commit is contained in:
parent
21c3ba85db
commit
91c4e4a898
37
4/4.cs
37
4/4.cs
@ -173,46 +173,17 @@ namespace LaptopSimulator2015.Levels
|
|||||||
get {
|
get {
|
||||||
for (int i = 0; i < platforms.Count; i++)
|
for (int i = 0; i < platforms.Count; i++)
|
||||||
{
|
{
|
||||||
RectangleF rect = plat2rect(i);
|
Rect rect = new Rect(platforms[i], new Vector2(100, 10), true);
|
||||||
if (player.X < rect.X)
|
if (player.distanceToRectSquared(rect) <= 20 && rect.doOverlap(new Rect(player, new Vector2(10, 10), true)) && platforms[i].Y + 11 > player.Y && player.Y > platforms[i].Y + 9)
|
||||||
{
|
|
||||||
if (player.Y < rect.Y)
|
|
||||||
platforms[i].Tag = (player - new PointF(rect.X, rect.Y)).magnitude;
|
|
||||||
else if (player.Y > rect.Y + rect.Height)
|
|
||||||
platforms[i].Tag = (player - new PointF(rect.X, rect.Y + rect.Height)).magnitude;
|
|
||||||
else
|
|
||||||
platforms[i].Tag = rect.X - player.X;
|
|
||||||
}
|
|
||||||
else if (player.X > rect.X + rect.Width)
|
|
||||||
{
|
|
||||||
if (player.Y < rect.Y)
|
|
||||||
platforms[i].Tag = (player - new PointF(rect.X + rect.Width, rect.Y)).magnitude;
|
|
||||||
else if (player.Y > rect.Y + rect.Height)
|
|
||||||
platforms[i].Tag = (player - new PointF(rect.X + rect.Width, rect.Y + rect.Height)).magnitude;
|
|
||||||
else
|
|
||||||
platforms[i].Tag = player.X - rect.X + rect.Width;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (player.Y < rect.Y)
|
|
||||||
platforms[i].Tag = rect.Y - player.Y;
|
|
||||||
else if (player.Y > rect.Y + rect.Height)
|
|
||||||
platforms[i].Tag = player.Y - (rect.Y + rect.Height);
|
|
||||||
else
|
|
||||||
platforms[i].Tag = 0d;
|
|
||||||
}
|
|
||||||
if (((double)platforms[i].Tag) <= 20 && RectangleF.Intersect(player2rect(), rect) != RectangleF.Empty && player.Y > platforms[i].Y + 8)
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RectangleF plat2rect(int platform) => new RectangleF((platforms[platform] - new Vector2(50, 5)).toPointF(), new SizeF(100, 10));
|
|
||||||
RectangleF player2rect() => new RectangleF((player - new Vector2(5, 5)).toPointF(), new SizeF(10, 10));
|
|
||||||
|
|
||||||
public void draw(GraphicsWrapper g, Panel minigamePanel, Timer minigameTimer, uint minigameTime)
|
public void draw(GraphicsWrapper g, Panel minigamePanel, Timer minigameTimer, uint minigameTime)
|
||||||
{
|
{
|
||||||
g.DrawRectangle(new RectangleF(player.toPointF(), new SizeF(10, 10)), Color.Green);
|
g.DrawRectangle(new Rect(player, new Vector2(10, 10), true), Color.Green);
|
||||||
if (lazorTime >= 0 && lazorTime <= 80)
|
if (lazorTime >= 0 && lazorTime <= 80)
|
||||||
{
|
{
|
||||||
g.DrawRectangle(new RectangleF((float)lazor, minigamePanel.Height / 2, 2, minigamePanel.Height), Color.DarkGray);
|
g.DrawRectangle(new RectangleF((float)lazor, minigamePanel.Height / 2, 2, minigamePanel.Height), Color.DarkGray);
|
||||||
@ -220,7 +191,7 @@ namespace LaptopSimulator2015.Levels
|
|||||||
g.DrawRectangle(new RectangleF((float)lazor, minigamePanel.Height - m / 2, 2, m), Color.Red);
|
g.DrawRectangle(new RectangleF((float)lazor, minigamePanel.Height - m / 2, 2, m), Color.Red);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < platforms.Count; i++)
|
for (int i = 0; i < platforms.Count; i++)
|
||||||
g.DrawRectangle(new RectangleF(platforms[i].toPointF(), new SizeF(100, 10)), Color.White);
|
g.DrawRectangle(new Rect(platforms[i], new Vector2(100, 10), true), Color.White);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
<Compile Include="Minigame.cs" />
|
<Compile Include="Minigame.cs" />
|
||||||
<Compile Include="Misc.cs" />
|
<Compile Include="Misc.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Rect.cs" />
|
||||||
<Compile Include="Vector2.cs" />
|
<Compile Include="Vector2.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
@ -79,6 +79,15 @@ namespace Base
|
|||||||
g.DrawRectangle(new Pen(b, unfilledLineSize), new Rectangle(Misc.f2i(r.X), Misc.f2i(r.Y), Misc.f2i(r.Width), Misc.f2i(r.Height)));
|
g.DrawRectangle(new Pen(b, unfilledLineSize), new Rectangle(Misc.f2i(r.X), Misc.f2i(r.Y), Misc.f2i(r.Width), Misc.f2i(r.Height)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draws a rectangle
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rectangle">The rectangle to be drawn</param>
|
||||||
|
/// <param name="color">The color of the rectangle</param>
|
||||||
|
/// <param name="filled">Whether the rectangle should be filled</param>
|
||||||
|
/// <param name="unfilledLineSize">The size of the lines used when not filling</param>
|
||||||
|
public void DrawRectangle(Rect rectangle, Color color, bool filled = true, int unfilledLineSize = 1) => DrawRectangle(rectangle.toRectangleF(), color, false, true, filled, unfilledLineSize);
|
||||||
|
|
||||||
public void Clear() => g.Clear(backColor);
|
public void Clear() => g.Clear(backColor);
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
116
Base/Rect.cs
Normal file
116
Base/Rect.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace Base
|
||||||
|
{
|
||||||
|
public class Rect
|
||||||
|
{
|
||||||
|
public Vector2 Location;
|
||||||
|
public Vector2 Size;
|
||||||
|
bool centered;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a rect from the provided data
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Location">Bottom-left point</param>
|
||||||
|
/// <param name="Size">Amount to extend top-right</param>
|
||||||
|
public Rect(Vector2 Location, Vector2 Size, bool centered = false)
|
||||||
|
{
|
||||||
|
this.Location = Location ?? throw new ArgumentNullException(nameof(Location));
|
||||||
|
this.Size = Size ?? throw new ArgumentNullException(nameof(Size));
|
||||||
|
this.centered = centered;
|
||||||
|
if (this.centered)
|
||||||
|
this.Location -= this.Size / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a rect from the provided data
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="X">X in world-coordinates</param>
|
||||||
|
/// <param name="Y">Y in world-coordinates</param>
|
||||||
|
/// <param name="Width">Width</param>
|
||||||
|
/// <param name="Height">Height</param>
|
||||||
|
public Rect(double X, double Y, double Width, double Height, bool centered = false)
|
||||||
|
{
|
||||||
|
Location = new Vector2(X, Y);
|
||||||
|
Size = new Vector2(Width, Height);
|
||||||
|
this.centered = centered;
|
||||||
|
if (this.centered)
|
||||||
|
Location -= Size / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Copies the Rect's data
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rect"></param>
|
||||||
|
public Rect(Rect rect)
|
||||||
|
{
|
||||||
|
Location = rect.Location;
|
||||||
|
Size = rect.Size;
|
||||||
|
}
|
||||||
|
public Rect(Rectangle rect)
|
||||||
|
{
|
||||||
|
Location = new Vector2(rect.Location);
|
||||||
|
Size = new Vector2(rect.Size);
|
||||||
|
}
|
||||||
|
public Rect(RectangleF rect)
|
||||||
|
{
|
||||||
|
Location = new Vector2(rect.Location);
|
||||||
|
Size = new Vector2(rect.Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double X
|
||||||
|
{
|
||||||
|
get => Location.X;
|
||||||
|
set => Location.X = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Y
|
||||||
|
{
|
||||||
|
get => Location.Y;
|
||||||
|
set => Location.Y = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Width
|
||||||
|
{
|
||||||
|
get => Size.X;
|
||||||
|
set {
|
||||||
|
if (centered)
|
||||||
|
{
|
||||||
|
double tmp = Size.X - value;
|
||||||
|
Size.X = value;
|
||||||
|
Location.X += tmp / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Size.X = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Height
|
||||||
|
{
|
||||||
|
get => Size.Y;
|
||||||
|
set {
|
||||||
|
if (centered)
|
||||||
|
{
|
||||||
|
double tmp = Size.Y - value;
|
||||||
|
Size.Y = value;
|
||||||
|
Location.Y += tmp / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Size.Y = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Bottom => Location.Y;
|
||||||
|
public double Top => Location.Y + Size.Y;
|
||||||
|
public double Left => Location.X;
|
||||||
|
public double Right => Location.X + Size.X;
|
||||||
|
public Vector2 bottomLeftPoint => new Vector2(Location);
|
||||||
|
public Vector2 bottomRightPoint => new Vector2(Location.X, Location.Y + Size.Y);
|
||||||
|
public Vector2 topLeftPoint => new Vector2(Location.X + Size.X, Location.Y);
|
||||||
|
public Vector2 topRightPoint => Location + Size;
|
||||||
|
public bool doOverlap(Rect other) => (Left <= other.Right && other.Left <= Right) || (Left >= other.Right && other.Left >= Right);
|
||||||
|
public Rectangle toRectangle() => new Rectangle(Misc.d2i(X), Misc.d2i(Y), Misc.d2i(Width), Misc.d2i(Height));
|
||||||
|
public RectangleF toRectangleF() => new RectangleF(Misc.d2f(X), Misc.d2f(Y), Misc.d2f(Width), Misc.d2f(Height));
|
||||||
|
}
|
||||||
|
}
|
@ -128,6 +128,26 @@ namespace Base
|
|||||||
Y = from.Y;
|
Y = from.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new Vector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="from">Size to copy data from</param>
|
||||||
|
public Vector2(Size from)
|
||||||
|
{
|
||||||
|
X = from.Width;
|
||||||
|
Y = from.Height;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new Vector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="from">Size to copy data from</param>
|
||||||
|
public Vector2(SizeF from)
|
||||||
|
{
|
||||||
|
X = from.Width;
|
||||||
|
Y = from.Height;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copy data from the Vector to a new one
|
/// Copy data from the Vector to a new one
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -167,6 +187,37 @@ namespace Base
|
|||||||
/// <param name="other">The other Vector</param>
|
/// <param name="other">The other Vector</param>
|
||||||
/// <returns>Distance</returns>
|
/// <returns>Distance</returns>
|
||||||
public double distanceFrom(Vector2 other) => Math.Sqrt(distanceFromSquared(other));
|
public double distanceFrom(Vector2 other) => Math.Sqrt(distanceFromSquared(other));
|
||||||
|
public double distanceToRectSquared(Rect rect)
|
||||||
|
{
|
||||||
|
if (X < rect.X)
|
||||||
|
{
|
||||||
|
if (Y < rect.Bottom)
|
||||||
|
return distanceFromSquared(rect.bottomLeftPoint);
|
||||||
|
else if (Y > rect.Top)
|
||||||
|
return distanceFromSquared(rect.topLeftPoint);
|
||||||
|
else
|
||||||
|
return Math.Pow(rect.Left - X, 2);
|
||||||
|
}
|
||||||
|
else if (X > rect.X + rect.Width)
|
||||||
|
{
|
||||||
|
if (Y < rect.Bottom)
|
||||||
|
return distanceFromSquared(rect.bottomRightPoint);
|
||||||
|
else if (Y > rect.Top)
|
||||||
|
return distanceFromSquared(rect.topRightPoint);
|
||||||
|
else
|
||||||
|
return Math.Pow(X - rect.Right, 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Y < rect.Bottom)
|
||||||
|
return Math.Pow(rect.Bottom - Y, 2);
|
||||||
|
else if (Y > rect.Top)
|
||||||
|
return Y - rect.Top;
|
||||||
|
else
|
||||||
|
return 0d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public double distanceToRect(Rect rect) => Math.Sqrt(distanceToRectSquared(rect));
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provided for compatibility with some methods for other Vector implementations
|
/// Provided for compatibility with some methods for other Vector implementations
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -229,12 +280,14 @@ namespace Base
|
|||||||
public static Vector2 operator -(Vector2 left, Vector2 right) => new Vector2(left.X - right.X, left.Y - right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
public static Vector2 operator -(Vector2 left, Vector2 right) => new Vector2(left.X - right.X, left.Y - right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
public static Vector2 operator -(Vector2 left, Point right) => new Vector2(left.X - right.X, left.Y - right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
public static Vector2 operator -(Vector2 left, Point right) => new Vector2(left.X - right.X, left.Y - right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
public static Vector2 operator -(Vector2 left, PointF right) => new Vector2(left.X - right.X, left.Y - right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
public static Vector2 operator -(Vector2 left, PointF right) => new Vector2(left.X - right.X, left.Y - right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
|
public static Vector2 operator *(Vector2 left, double right) => new Vector2(left * new Vector2(right, right)).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
public static Vector2 operator *(Vector2 left, Vector2 right) => new Vector2(left.X * right.X, left.Y * right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
public static Vector2 operator *(Vector2 left, Vector2 right) => new Vector2(left.X * right.X, left.Y * right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
public static Vector2 operator *(Vector2 left, Point right) => new Vector2(left.X * right.X, left.Y * right.Y);
|
public static Vector2 operator *(Vector2 left, Point right) => new Vector2(left.X * right.X, left.Y * right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
public static Vector2 operator *(Vector2 left, PointF right) => new Vector2(left.X * right.X, left.Y * right.Y);
|
public static Vector2 operator *(Vector2 left, PointF right) => new Vector2(left.X * right.X, left.Y * right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
public static Vector2 operator /(Vector2 left, Vector2 right) => new Vector2(left.X / right.X, left.Y / right.Y);
|
public static Vector2 operator /(Vector2 left, double right) => new Vector2(left / new Vector2(right, right)).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
public static Vector2 operator /(Vector2 left, Point right) => new Vector2(left.X / right.X, left.Y / right.Y);
|
public static Vector2 operator /(Vector2 left, Vector2 right) => new Vector2(left.X / right.X, left.Y / right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
public static Vector2 operator /(Vector2 left, PointF right) => new Vector2(left.X / right.X, left.Y / right.Y);
|
public static Vector2 operator /(Vector2 left, Point right) => new Vector2(left.X / right.X, left.Y / right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
public static Vector2 operator ^(Vector2 left, double right) => new Vector2(Math.Pow(left.X, right), Math.Pow(left.Y, right));
|
public static Vector2 operator /(Vector2 left, PointF right) => new Vector2(left.X / right.X, left.Y / right.Y).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
|
public static Vector2 operator ^(Vector2 left, double right) => new Vector2(Math.Pow(left.X, right), Math.Pow(left.Y, right)).addData(left.Tag, left.bounds, left.bounds_wrap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user