- server.zip
- Local.testsettings
- packages
- Fleck.0.8.2.1
- Fleck.0.8.2.1.nupkg
- lib
- net40
- Fleck.dll
- HttpClient.0.6.0
- HttpClient.0.6.0.nupkg
- lib
- 40
- JsonValue.0.6.0
- JsonValue.0.6.0.nupkg
- lib
- 40
- Newtonsoft.Json.4.0.5
- repositories.config
- SpaceShooterServer.sln
- SpaceShooterServer.vsmdi
- SpaceShooterServer
- Test
- bin
- Debug
- Release
- Fleck.dll
- Microsoft.Json.dll
- Microsoft.Json.xml
- Microsoft.Server.Common.dll
- SpaceShooterServer.exe
- Test.dll
- Local.testsettings
- obj
- Debug
- TempPE
- Release
- TempPE
- packages.config
- Properties
- SpaceShooterServer.vsmdi
- Test.csproj
- Test.csproj.user
- TraceAndTestImpact.testsettings
- UnitTests.cs
- TraceAndTestImpact.testsettings
- client.zip
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Json;
using SpaceShooterServer.Interfaces;
namespace SpaceShooterServer.Game
{
public class Asteroid : GameObject, IShipCollision, IParticleCollision, IBombCollision, IVelocity, IExplodable
{
const int ASTEROID_LIFE = 10;
int life;
public Asteroid()
{
Life = ASTEROID_LIFE;
Angle = 0;
}
public int Life
{
get { return life; }
set
{
life = value;
if (life < 1)
Dead();
}
}
public double Angle { get; set; }
public double Rotation { get; set; }
public double Vx { get; set; }
public double Vy { get; set; }
public int ExplosionType { get { return 1; } }
public override int Damage
{
get
{
return Size;
}
set
{
}
}
public override void Logic()
{
X += Vx;
Y += Vy;
PeriodicBoundaryConditions();
Angle += Rotation;
}
public override JsonObject ToJson()
{
var json = new JsonObject();
json["size"] = Size;
json["angle"] = Angle;
json["x"] = X;
json["y"] = Y;
json["vx"] = Vx;
json["vy"] = Vy;
json["remove"] = Remove;
return json;
}
public static Asteroid Generate(Match game)
{
var a = new Asteroid();
a.Size = game.Random.Next(0, 51) + 25;
a.Game = game;
a.Rotation = game.Random.NextDouble() * 6 - 3;
var coin = game.Random.NextDouble();
if (coin < 0.5)
{
a.X = 2 * coin * game.Width;
a.Y = coin < 0.25 ? -a.Size / 2 : game.Height + a.Size / 2;
}
else
{
a.X = coin < 0.75 ? -a.Size / 2 : game.Width + a.Size / 2;
a.Y = (coin - 0.5) * game.Height * 2;
}
a.Vx = game.Random.NextDouble() * 6 - 3;
a.Vy = game.Random.NextDouble() * 6 - 3;
return a;
}
public override bool Hit(GameObject source)
{
Life -= source.Damage;
if (Remove)
return true;
InfoText.Add(this, "-" + source.Damage, 50, source);
return false;
}
public void OnCollision(Ship ship)
{
Life = 0;
if (ship.Hit(this))
{
InfoText.Add(this, "Ouch!", 50, ship);
ship.Points--;
}
}
public void OnCollision(Particle particle)
{
particle.OnCollision(this);
}
public void OnCollision(Bomb bomb)
{
bomb.OnCollision(this);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Florian lives in Munich, Germany. He started his programming career with Perl. After programming C/C++ for some years he discovered his favorite programming language C#. He did work at Siemens as a programmer until he decided to study Physics.
During his studies he worked as an IT consultant for various companies. After graduating with a PhD in theoretical particle Physics he is working as a senior technical consultant in the field of home automation and IoT.
Florian has been giving lectures in C#, HTML5 with CSS3 and JavaScript, software design, and other topics. He is regularly giving talks at user groups, conferences, and companies. He is actively contributing to open-source projects. Florian is the maintainer of AngleSharp, a completely managed browser engine.