Compare commits
No commits in common. "0f5f7b84f7533a2518f51b661dcc06225767ed5b" and "7faf1ecd9763c78f375c8ee046e8c527937537cb" have entirely different histories.
0f5f7b84f7
...
7faf1ecd97
@ -41,10 +41,6 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
// Everything below this point is boilerplate delegation to the underlying list.
|
// Everything below this point is boilerplate delegation to the underlying list.
|
||||||
|
|
||||||
public void AddRange(IEnumerable<T> collection) {
|
|
||||||
items.AddRange(collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear() {
|
public void Clear() {
|
||||||
items.Clear();
|
items.Clear();
|
||||||
}
|
}
|
||||||
|
@ -10,32 +10,8 @@ namespace SemiColinGames {
|
|||||||
// Center of player sprite.
|
// Center of player sprite.
|
||||||
public Vector2 Position = new Vector2(48, 1080 / 8);
|
public Vector2 Position = new Vector2(48, 1080 / 8);
|
||||||
public Vector2 HalfSize = new Vector2(16, 10);
|
public Vector2 HalfSize = new Vector2(16, 10);
|
||||||
|
public float Speed = 150f;
|
||||||
private float speed = 150f;
|
public float ShotCooldown = 0f;
|
||||||
private float shotCooldown = 0f;
|
|
||||||
private ProfilingList<Shot> shots = new ProfilingList<Shot>(10, "playerShots");
|
|
||||||
|
|
||||||
public ProfilingList<Shot> Update(
|
|
||||||
float modelTime, History<Input> input, Rectangle worldBounds) {
|
|
||||||
// Movement update.
|
|
||||||
Vector2 motion = Vector2.Multiply(input[0].Motion, modelTime * speed);
|
|
||||||
Position = Vector2.Add(Position, motion);
|
|
||||||
Position.X = Math.Max(Position.X, HalfSize.X);
|
|
||||||
Position.X = Math.Min(Position.X, worldBounds.Size.X - HalfSize.X);
|
|
||||||
Position.Y = Math.Max(Position.Y, HalfSize.Y);
|
|
||||||
Position.Y = Math.Min(Position.Y, worldBounds.Size.Y - HalfSize.Y);
|
|
||||||
|
|
||||||
// Check whether we need to add new shots.
|
|
||||||
shotCooldown -= modelTime;
|
|
||||||
shots.Clear();
|
|
||||||
if (input[0].Attack && shotCooldown <= 0) {
|
|
||||||
shotCooldown = 0.2f;
|
|
||||||
Vector2 shotOffset = new Vector2(12, 2);
|
|
||||||
Vector2 shotPosition = Vector2.Add(Position, shotOffset);
|
|
||||||
shots.Add(new Shot(shotPosition, new Vector2(300, 0)));
|
|
||||||
}
|
|
||||||
return shots;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Shot {
|
public class Shot {
|
||||||
@ -89,14 +65,26 @@ namespace SemiColinGames {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Update(float modelTime, History<Input> input) {
|
public void Update(float modelTime, History<Input> input) {
|
||||||
ProfilingList<Shot> newPlayerShots = Player.Update(modelTime, input, Bounds);
|
Vector2 motion = Vector2.Multiply(input[0].Motion, modelTime * Player.Speed);
|
||||||
|
Player.Position = Vector2.Add(Player.Position, motion);
|
||||||
|
Player.Position.X = Math.Max(Player.Position.X, Player.HalfSize.X);
|
||||||
|
Player.Position.X = Math.Min(Player.Position.X, Bounds.Size.X - Player.HalfSize.X);
|
||||||
|
Player.Position.Y = Math.Max(Player.Position.Y, Player.HalfSize.Y);
|
||||||
|
Player.Position.Y = Math.Min(Player.Position.Y, Bounds.Size.Y - Player.HalfSize.Y);
|
||||||
|
Player.ShotCooldown -= modelTime;
|
||||||
|
|
||||||
foreach (Shot shot in Shots) {
|
foreach (Shot shot in Shots) {
|
||||||
shot.Update(modelTime);
|
shot.Update(modelTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
Shots.AddRange(newPlayerShots);
|
// TODO: move this all into Player.Update().
|
||||||
// TODO: inflate bounds rectangle
|
if (input[0].Attack && Player.ShotCooldown <= 0) {
|
||||||
|
Player.ShotCooldown = 0.2f;
|
||||||
|
Vector2 shotOffset = new Vector2(12, 2);
|
||||||
|
Vector2 shotPosition = Vector2.Add(Player.Position, shotOffset);
|
||||||
|
Shots.Add(new Shot(shotPosition, new Vector2(300, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
Shots.RemoveAll(shot => !Bounds.Intersects(shot.Bounds));
|
Shots.RemoveAll(shot => !Bounds.Intersects(shot.Bounds));
|
||||||
|
|
||||||
Debug.AddToast("shots: " + Shots.Count);
|
Debug.AddToast("shots: " + Shots.Count);
|
||||||
|
@ -54,7 +54,7 @@ def lint_csharp(filename):
|
|||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
this_dir = os.path.dirname(os.path.realpath(__file__))
|
this_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
sneak_root = os.path.join(this_dir, '..', '..')
|
sneak_root = os.path.join(this_dir, '..', '..', '..')
|
||||||
os.chdir(sneak_root)
|
os.chdir(sneak_root)
|
||||||
|
|
||||||
csharp_files = sorted(glob.glob('**/*.cs', recursive=True))
|
csharp_files = sorted(glob.glob('**/*.cs', recursive=True))
|
||||||
|
Loading…
Reference in New Issue
Block a user