Added lighting
This commit is contained in:
parent
76c15e72ca
commit
2189ba267b
5 changed files with 53 additions and 15 deletions
|
|
@ -1,9 +1 @@
|
|||
<Application x:Class="CityGame.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:CityGame"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
|
||||
|
|
@ -29,7 +29,29 @@ namespace CityGame
|
|||
public float Speed { get; set; } = 128;
|
||||
public override OCanvas Render()
|
||||
{
|
||||
return new SourcedImage("Car.png");
|
||||
OCanvas canvas = new OCanvas();
|
||||
Image car = new SourcedImage("Car.png");
|
||||
|
||||
canvas.Children.Add(car);
|
||||
var light = new LightSource { Radius = 64, Intensity = 2, Color = Color.White, Type = LightSourceType.Spotlight, Rotation = -90, RotationOrigin = new Point(MainWindow.TileSize / 2, MainWindow.TileSize / 2) };
|
||||
var light2 = new LightSource { Radius = 64, Intensity = 2, Color = Color.White, Type = LightSourceType.Spotlight, Rotation = -90, RotationOrigin = new Point(MainWindow.TileSize / 2, MainWindow.TileSize / 2) };
|
||||
Canvas.SetLeft(light, 39);
|
||||
Canvas.SetTop(light, 19);
|
||||
Canvas.SetLeft(light2, 46);
|
||||
Canvas.SetTop(light2, 19);
|
||||
canvas.Children.Add(light);
|
||||
canvas.Children.Add(light2);
|
||||
|
||||
var blight = new LightSource { Radius = 24, Intensity = 1, Color = Color.Red, Type = LightSourceType.PointLight, Rotation = 90, RotationOrigin = new Point(MainWindow.TileSize / 2, MainWindow.TileSize / 2) };
|
||||
var blight2 = new LightSource { Radius = 24, Intensity = 1, Color = Color.Red, Type = LightSourceType.PointLight, Rotation = 90, RotationOrigin = new Point(MainWindow.TileSize / 2, MainWindow.TileSize / 2) };
|
||||
Canvas.SetLeft(blight, 39);
|
||||
Canvas.SetTop(blight, 46);
|
||||
Canvas.SetLeft(blight2, 46);
|
||||
Canvas.SetTop(blight2, 46);
|
||||
canvas.Children.Add(blight);
|
||||
canvas.Children.Add(blight2);
|
||||
|
||||
return canvas;
|
||||
}
|
||||
public Car()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using WPFGame;
|
||||
|
||||
namespace CityGame
|
||||
|
|
@ -15,6 +15,7 @@ namespace CityGame
|
|||
int RotorState = 0;
|
||||
public ISelectable Target;
|
||||
bool Move;
|
||||
public LightSource Spotlight;
|
||||
public override OCanvas Render()
|
||||
{
|
||||
OCanvas canvas = new OCanvas();
|
||||
|
|
@ -31,6 +32,12 @@ namespace CityGame
|
|||
canvas.Children.Add(Blades1);
|
||||
canvas.Children.Add(Blades2);
|
||||
|
||||
Spotlight = new LightSource { Type = LightSourceType.Spotlight, Color = Color.White, Intensity = 3, Rotation = -90, Radius = MainWindow.TileSize * 3, RotationOrigin = new Point(MainWindow.TileSize / 2, MainWindow.TileSize / 2) };
|
||||
Canvas.SetTop(Spotlight, 7);
|
||||
Canvas.SetLeft(Spotlight, 32);
|
||||
|
||||
canvas.Children.Add(Spotlight);
|
||||
|
||||
return canvas;
|
||||
}
|
||||
|
||||
|
|
@ -50,14 +57,24 @@ namespace CityGame
|
|||
if (Target is not null)
|
||||
{
|
||||
IntPoint nextTarget = new IntPoint(Target.X(), Target.Y());
|
||||
if(Target is Car car)
|
||||
{
|
||||
var correctionvector = new IntPoint((int)Math.Cos(Microsoft.Xna.Framework.MathHelper.ToRadians(car.Rotation)), (int)Math.Sin(Microsoft.Xna.Framework.MathHelper.ToRadians(car.Rotation)));
|
||||
correctionvector *= MainWindow.TileSize / 4;
|
||||
nextTarget += correctionvector;
|
||||
}
|
||||
Vector2 travel = new Vector2((float)nextTarget.X - X, (float)nextTarget.Y - Y);
|
||||
if (travel.Length() < MainWindow.TileSize * 1) Move = false;
|
||||
if (travel.Length() > MainWindow.TileSize * 3) Move = true;
|
||||
float minDistance = MainWindow.TileSize * 1;
|
||||
if (Target is Tile) minDistance = 0;
|
||||
float minSpeedyDistance = MainWindow.TileSize * 3;
|
||||
Spotlight.Radius = (int)Math.Min(minSpeedyDistance, travel.Length());
|
||||
if (travel.Length() < minDistance) Move = false;
|
||||
if (travel.Length() > minSpeedyDistance) Move = true;
|
||||
Vector2 direction = Vector2.Normalize(travel);
|
||||
float degrees = (float)(Math.Atan2(direction.Y, direction.X) * (180 / Math.PI)) + 90;
|
||||
Rotation = degrees;
|
||||
float Speedmulti = 1;
|
||||
if (travel.Length() < MainWindow.TileSize * 3) Speedmulti = (travel.Length() - MainWindow.TileSize) / (MainWindow.TileSize * 2);
|
||||
if (travel.Length() < minSpeedyDistance) Speedmulti = (travel.Length() - minDistance) / (minSpeedyDistance - minDistance);
|
||||
var possibleDistance = Speed * Speedmulti * deltaTime / 1000;
|
||||
var finalDistance = Math.Min(possibleDistance, travel.Length());
|
||||
Vector2 travelFinal = direction * finalDistance;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@
|
|||
{
|
||||
return new IntPoint(a.X + b.X, a.Y + b.Y);
|
||||
}
|
||||
public static IntPoint operator *(IntPoint a, int b)
|
||||
{
|
||||
return new IntPoint(a.X * b, a.Y * b);
|
||||
}
|
||||
public static bool operator !=(IntPoint a, IntPoint b)
|
||||
{
|
||||
return a.X != b.X || a.Y != b.Y;
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ namespace CityGame
|
|||
Canvas UICanvas = new OCanvas();
|
||||
public MainWindow()
|
||||
{
|
||||
AddPenumbra();
|
||||
|
||||
#region | Texture Conversions |
|
||||
string[] patternCodes = new[] { "0", "1", "2", "2c", "3", "3a", "3ab", "3c", "4", "4m", "4c", "5", "7", "8" };
|
||||
|
||||
|
|
@ -125,6 +127,7 @@ namespace CityGame
|
|||
int minBlockWidth = 3;
|
||||
|
||||
int NPCCount = (int)Math.Ceiling(mapHeight * mapWidth / 100f);
|
||||
//NPCCount = 1;
|
||||
|
||||
random = new Random(seed);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue