If the mouse is over the shape and the user presses spacebar, i want the colour of the shape to change to a random color. Any help is greatly appreciated as im still learning, cheers.
Program.cs
if (SwinGame.KeyTyped(KeyCode.SpaceKey))
{
myShapes.SelectShapes(SwinGame.MousePosition());
}
Drawing.cs
i believe it is this part of the code that i need to change. Color
is not changing the color of the shape like i hoped but im not sure what else to use, nothing i've tried seems to work.
public void SelectShapes(Point2D pt)
{
foreach (Shape s in _shapes)
{
if (s.At(pt))
{
Color = SwinGame.RandomRGBColor(255);
}
}
}
Shape.cs
using SwinGameSDK;
namespace ShapeGame
{
public class Shape
{
public Color _color;
private float _x, _y;
private int _w, _h;
private bool _selected;
public bool At(Point2D pt)
{
return SwinGame.PointInRect(pt, _x, _y, _w, _h);
}
public Shape()
{
_color = Color.DarkRed;
_x = 0;
_y = 0;
_w = 80;
_h = 80;
}
public Color Color
{
get
{
return _color;
}
set
{
_color = value;
}
}
public float X
{
get
{
return _x;
}
set
{
_x = value;
}
}
public float Y
{
get
{
return _y;
}
set
{
_y = value;
}
}
public int W
{
get
{
return _w;
}
}
public int H
{
get
{
return _h;
}
}
public void Draw()
{
if (_selected)
{
DrawOutline();
}
SwinGame.FillRectangle(_color, _x, _y, _w, _h);
}
Aucun commentaire:
Enregistrer un commentaire