Skip to content

Commit

Permalink
Merge combat, maps, GUI (#7) from feature/combat.
Browse files Browse the repository at this point in the history
  • Loading branch information
c272 authored Mar 15, 2022
2 parents b27aa3a + 15bf10a commit 1f123e8
Show file tree
Hide file tree
Showing 69 changed files with 1,315 additions and 124 deletions.
Binary file added Assets/Example/Fists.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Example/TestModel_Fists_Attacked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Example/TestModel_Fists_Resting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Example/daveSprint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Example/daveSprint_Fists_Attacked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Example/daveSprint_Fists_Resting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Example/daveTank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Example/daveTank_Fists_Attacked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Example/daveTank_Fists_Resting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Example/dave_Fists_Attacked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Example/dave_Fists_Resting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Fonts/MakanHati-vmp94.ttf
Binary file not shown.
Binary file added Assets/LancasterGuy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/LancasterGuy_Fists_Attacked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/LancasterGuy_Fists_Resting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Maps/Alex square shrubs.mdp
Binary file not shown.
Binary file added Assets/Maps/Diagonal squares.mdp
Binary file not shown.
Binary file added Assets/Maps/Diagonal squares.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Maps/Diagonal tile.mdp
Binary file not shown.
Binary file added Assets/Maps/Doors.mdp
Binary file not shown.
Binary file added Assets/Maps/Doors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Maps/Field.mdp
Binary file not shown.
Binary file added Assets/Maps/Field.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Maps/Planter.mdp
Binary file not shown.
Binary file added Assets/Maps/Pool tiles.mdp
Binary file not shown.
Binary file added Assets/Maps/Pool tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Maps/Railing.mdp
Binary file not shown.
Binary file added Assets/Maps/Railing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Maps/Roofing.mdp
Binary file not shown.
Binary file added Assets/Maps/Roofing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Maps/Stone Tile(1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Maps/Stone Tile.mdp
Binary file not shown.
Binary file added Assets/Maps/Window tiles.mdp
Binary file not shown.
Binary file added Assets/Maps/Window tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Maps/gravel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/UclanGuy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/UclanGuy_Fists_Attacked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/UclanGuy_Fists_Resting.png
Binary file added Assets/YorkGuy.png
Binary file added Assets/YorkGuy_Fists_Attacked.png
Binary file added Assets/YorkGuy_Fists_Resting.png
Binary file added Assets/Zombie.png
Binary file added Assets/Zombie_Fists_Attacked.png
Binary file added Assets/Zombie_Fists_Resting.png
Binary file added Assets/click.mp3
Binary file not shown.
Binary file added Assets/enemyDeath.wav
Binary file not shown.
Binary file added Assets/hit.wav
Binary file not shown.
Binary file added Assets/logo.png
Binary file added Assets/playerDeath.wav
Binary file not shown.
Binary file added Assets/waveDone.mp3
Binary file not shown.
Binary file added Assets/waveDone.wav
Binary file not shown.
6 changes: 6 additions & 0 deletions CampusCrawl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@
<ItemGroup>
<Compile Include="Characters\Character.cs" />
<Compile Include="Characters\Enemy.cs" />
<Compile Include="Characters\EnemySprint.cs" />
<Compile Include="Characters\EnemyTank.cs" />
<Compile Include="Characters\Player.cs" />
<Compile Include="Entities\Entity.cs" />
<Compile Include="Entities\Weapon.cs" />
<Compile Include="Entities\Weapons\Fists.cs" />
<Compile Include="Game.cs" />
<Compile Include="Scenes\AlexandraSquare.cs" />
<Compile Include="Scenes\BaseScene.cs" />
<Compile Include="Scenes\LibraryFloorOne.cs" />
<Compile Include="Scenes\LibraryFloorTwo.cs" />
<Compile Include="Scenes\LibraryFloorThree.cs" />
Expand Down
6 changes: 6 additions & 0 deletions CampusCrawl.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
235 changes: 210 additions & 25 deletions Characters/Character.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,235 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using CampusCrawl.Entities;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using tileEngine.SDK;
using tileEngine.SDK.Audio;
using tileEngine.SDK.Components;
using tileEngine.SDK.Diagnostics;
using tileEngine.SDK.Input;
using tileEngine.SDK.Utility;

namespace CampusCrawl.Characters
{
public struct Push
{
public Push(int x, int y)
{
Value = new Vector2(x, y);
Current = Vector2.One;
}
public Vector2 Value { get; set; }
public Vector2 Current { get; set; }
public bool IsPushed => !(Value.X == 0 && Value.Y == 0);

public void Reset()
{
Value = Vector2.Zero;
Current = Vector2.One;
}

public void SetPush(int x, int y)
{
Value = new Vector2(x, y);
if (x < 0)
Current = new Vector2(-1, Current.Y);
if (y < 0)
Current = new Vector2(Current.X, -1);
}

public void DoneXPush() => Current = new Vector2(Current.X + Current.X < 0 ? -1 : 1, Current.Y);
public void DoneYPush() => Current = new Vector2(Current.X, Current.Y + Current.Y < 0 ? -1 : 1);
public void CheckPush()
{
if (Math.Abs(Current.X) == Math.Abs(Value.X))
{
Current = new Vector2(1, Current.Y);
Value = new Vector2(0, Value.Y);
}
if (Math.Abs(Current.Y) == Math.Abs(Value.Y))
{
Current = new Vector2(Current.X, 1);
Value = new Vector2(Value.X, 0); ;
}
}
}
public class Character : GameObject
{
private BoxColliderComponent collider;
private SpriteComponent sprite;
private float speed = 110;
protected bool followingPath = false;
protected BoxColliderComponent collider;
protected SpriteComponent sprite;
protected float speed;
public float health;
public bool attacking;
public Push pushStats = new Push(0, 0);
public float[] attackDirection;
public float damage;
protected SoundReference damageSound;
protected bool isEnemy = false;
protected Weapon weapon;
protected Entity doNotPickUp;
public string playerModelPath;
protected bool soundPlaying = false;
protected Timer soundDone;

public Character()
{
collider = new BoxColliderComponent()
soundDone = new Timer(0.25f);
soundDone.OnTick += SoundCooldown;
soundDone.Loop = false;
}

public void UpdateSprite(SpriteComponent _sprite, BoxColliderComponent boxCollider = null)
{
if (sprite != null)
RemoveComponent(sprite);

if (boxCollider != null)
{
Size = new Vector2(31, 31),
Location = new Vector2(0, 0)
};
AddComponent(collider);
sprite = new SpriteComponent()
if (collider != null)
RemoveComponent(collider);
collider = boxCollider;
AddComponent(boxCollider);
}

sprite = _sprite;
AddComponent(_sprite);
}

public override void Initialize()
{
base.Initialize();
attacking = false;
soundDone.Start();
damageSound = TileEngine.Instance.Sound.LoadSound("Sound/hit.wav");
}

public void CreateAndSetWeapon(Weapon weapon)
{
weapon.SetCharacter(this);
weapon.Spawn(Position);

weapon.PickedUp();
this.weapon = weapon;
}

public void DropCurrentWeapon()
{
doNotPickUp = weapon;
weapon.PutDown();
}

public float[] mouseDirection()
{
var direction = new float[2] { 0, 0 };
var mousePos = InputHandler.GetEvent("MousePosition");
var gridPos = Scene.ToGridLocation(mousePos.Value);
var mouseTile = Scene.GridToTileLocation(gridPos);
var currentTile = Scene.GridToTileLocation(Position);
if (currentTile.X - mouseTile.X > 0)
direction[0] = 1;
if (currentTile.X - mouseTile.X < 0)
direction[0] = -1;
if (currentTile.Y - mouseTile.Y > 0)
direction[1] = 1;
if (currentTile.Y - mouseTile.Y < 0)
direction[1] = -1;
return direction;
}


public void PushSelf(int x, int y)
{
pushStats.SetPush(x, y);
}

public void SoundCooldown()
{
soundPlaying = false;
}

public void OnDamage(float damage, float[] attackDirection, int pushAmt)
{
health -= damage;
PushSelf(-(int)(attackDirection[0] * pushAmt), -(int)(attackDirection[1] * pushAmt));
if (!soundPlaying)
{
Texture = AssetManager.AttemptLoad<Texture2D>(1215427970),
Position = new Vector2(0, 0),
Scale = new Vector2(1, 1)
};
AddComponent(sprite);
TileEngine.Instance.KeyboardInput.AddAxisBinding(Keys.D, Keys.A, Keys.S, Keys.W, "Movement");
SoundInstance soundInstance = TileEngine.Instance.Sound.PlaySound(damageSound);
soundInstance.Volume = 0.3f;
soundInstance.Looping = false;
soundDone.Start();
soundPlaying = true;
}
}


public void ScanAndPickUpEntities()
{
var entities = Scene.GameObjects.Where(x => x is Entity).ToList();
foreach (Entity entity in entities)
{
if (Scene.GridToTileLocation(entity.Position) == Scene.GridToTileLocation(this.Position) && entity != doNotPickUp)
{
// This means, we have an entity that we can pick up.
entity.PickedUp();
entity.Initialise(Scene, Layer);

if (entity is Weapon)
{
weapon = (Weapon)entity;
weapon.SetCharacter(this);
}
}
}
}

public override void Update(GameTime delta)
{
base.Update(delta);
var time = (float)(delta.ElapsedGameTime.TotalSeconds);
var movement = InputHandler.GetEvent("Movement");
Position = new Vector2(Position.X + (movement.Value.X*time*speed), Position.Y + (movement.Value.Y*time*speed));

//...
soundDone.Update(delta);
// Code to pick up entities
if (weapon == null)
ScanAndPickUpEntities();

// Code to move/push
pushStats.CheckPush();
if (pushStats.IsPushed)
{
PushEffect(time);
} else
{
attacking = false;
}
}

public void PushEffect(float time)
{
pushStats.CheckPush();
if (pushStats.IsPushed)
{
float xPushAmt = 0;
float yPushAmt = 0;
if (pushStats.Value.X != 0)
{
xPushAmt = pushStats.Current.X * time * speed;
pushStats.DoneXPush();
}
if (pushStats.Value.Y != 0)
{
yPushAmt = pushStats.Current.Y * time * speed;
pushStats.DoneYPush();
}
if (attacking)
{
if (!weapon.CheckAttack(new Vector2(Position.X + xPushAmt, Position.Y + yPushAmt),!isEnemy))
{
attacking = false;
pushStats.Reset();
}
}
Position = new Vector2(Position.X + xPushAmt, Position.Y + yPushAmt);
}
}
}
}
Loading

0 comments on commit 1f123e8

Please sign in to comment.