Implemented movement
AbstractCharacter mainly fleshed out InputManager is done Player movement is done, not ennemy Energy management is done (AbstractCharacter)
This commit is contained in:
parent
99013c5d7a
commit
ea9203ca8a
12 changed files with 304 additions and 26 deletions
155
Assets/Prefabs/Player.prefab
Normal file
155
Assets/Prefabs/Player.prefab
Normal file
|
@ -0,0 +1,155 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &2690590977808455807
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 2690590977808455801}
|
||||
- component: {fileID: 2690590977808455806}
|
||||
- component: {fileID: 2690590977808455800}
|
||||
- component: {fileID: 2690590977808455797}
|
||||
- component: {fileID: 2690590977808455802}
|
||||
- component: {fileID: 2690590977808455803}
|
||||
- component: {fileID: 2690590977808455796}
|
||||
m_Layer: 0
|
||||
m_Name: Player
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &2690590977808455801
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2690590977808455807}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0.051522817, y: -0.05536398, z: -0.18232574}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &2690590977808455806
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2690590977808455807}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 0
|
||||
m_ReceiveShadows: 0
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 0
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_Sprite: {fileID: 21300000, guid: 1fe77f169e8b4289c95cae0cff058bee, type: 3}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_FlipX: 0
|
||||
m_FlipY: 0
|
||||
m_DrawMode: 0
|
||||
m_Size: {x: 0.1, y: 0.1}
|
||||
m_AdaptiveModeThreshold: 0.5
|
||||
m_SpriteTileMode: 0
|
||||
m_WasSpriteAssigned: 1
|
||||
m_MaskInteraction: 0
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!58 &2690590977808455800
|
||||
CircleCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2690590977808455807}
|
||||
m_Enabled: 1
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 0, y: 0}
|
||||
serializedVersion: 2
|
||||
m_Radius: 0.25
|
||||
--- !u!114 &2690590977808455797
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2690590977808455807}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 35183fd85dde156de82c2af47fea6156, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_maxSpeed: 10
|
||||
_maxHealth: 3
|
||||
_maxEnergy: 100
|
||||
_energyRegen: 20
|
||||
--- !u!114 &2690590977808455802
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2690590977808455807}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 8d0d4226322cf15c8b3f89217d9b1c66, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!114 &2690590977808455803
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2690590977808455807}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2a3ed7cf697d2bd43836d1b20c50008e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!114 &2690590977808455796
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2690590977808455807}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 61bf45c54c3d922598ce965db2dc869c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
7
Assets/Prefabs/Player.prefab.meta
Normal file
7
Assets/Prefabs/Player.prefab.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3ae3c84bd570eb26d86ed9ec4e5fcba0
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -2,17 +2,100 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AbstractCharacter : MonoBehaviour
|
||||
public abstract class AbstractCharacter : MonoBehaviour
|
||||
{
|
||||
//
|
||||
// Core components of a character
|
||||
//
|
||||
protected Mover _mover;
|
||||
protected AbstractShooter _shooter;
|
||||
|
||||
//
|
||||
// Characteristics and status of a character
|
||||
//
|
||||
// Speed in m/s
|
||||
[SerializeField] protected float _maxSpeed;
|
||||
public float MaxSpeed
|
||||
{
|
||||
get { return _maxSpeed; }
|
||||
set { _maxSpeed = value; }
|
||||
}
|
||||
|
||||
[SerializeField] protected int _maxHealth;
|
||||
public int MaxHealth => _maxHealth;
|
||||
public int CurrentHealth { get; set; }
|
||||
|
||||
[SerializeField] protected float _maxEnergy;
|
||||
public float MaxEnergy => _maxEnergy;
|
||||
public float CurrentEnergy { get; set; }
|
||||
// Energy gained back per second
|
||||
[SerializeField] private float _energyRegen;
|
||||
public float EnergyRegen
|
||||
{
|
||||
get { return _energyRegen; }
|
||||
set { _energyRegen = value; }
|
||||
}
|
||||
|
||||
protected bool _isShooting;
|
||||
// True if the energy went down to zero
|
||||
protected bool _isDepleted;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
MaxSpeed = 10;
|
||||
_maxHealth = 1;
|
||||
CurrentHealth = MaxHealth;
|
||||
_maxEnergy = 100;
|
||||
CurrentEnergy = MaxEnergy;
|
||||
EnergyRegen = 20;
|
||||
|
||||
_mover = GetComponentInParent<Mover>();
|
||||
_shooter = GetComponentInParent<AbstractShooter>();
|
||||
|
||||
if (_mover == null)
|
||||
{
|
||||
throw new MissingComponentException("No Mover !");
|
||||
}
|
||||
|
||||
if (_shooter == null)
|
||||
{
|
||||
throw new MissingComponentException("No Shooter !");
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
// Manages the energy of the character
|
||||
void Update()
|
||||
{
|
||||
|
||||
if (!_isShooting && CurrentEnergy < MaxEnergy)
|
||||
{
|
||||
var regen = _isDepleted ? EnergyRegen * 0.75f : EnergyRegen;
|
||||
CurrentEnergy += regen * Time.deltaTime;
|
||||
}
|
||||
|
||||
if (CurrentEnergy > MaxEnergy)
|
||||
{
|
||||
CurrentEnergy = MaxEnergy;
|
||||
if (_isDepleted)
|
||||
{
|
||||
_isDepleted = false;
|
||||
}
|
||||
}
|
||||
if (CurrentEnergy < 0)
|
||||
{
|
||||
CurrentEnergy = 0;
|
||||
}
|
||||
|
||||
// The InputManager is executed before and updates it to true if needed
|
||||
_isShooting = false;
|
||||
}
|
||||
|
||||
public abstract void Move(Vector2 movementDirection);
|
||||
public abstract void Shoot();
|
||||
|
||||
// TODO : Manage hurt + OnCollision + Death'n stuff
|
||||
public void Hurt()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ MonoImporter:
|
|||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
executionOrder: -2
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Shooter : MonoBehaviour
|
||||
public class AbstractShooter : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerShooter : MonoBehaviour
|
||||
public class BasicShooter : AbstractShooter
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
|
|
|
@ -4,7 +4,7 @@ MonoImporter:
|
|||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
executionOrder: -3
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
|
|
@ -4,15 +4,32 @@ using UnityEngine;
|
|||
|
||||
public class InputManager : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
|
||||
private AbstractCharacter _character;
|
||||
void Start()
|
||||
{
|
||||
|
||||
_character = GetComponentInParent<AbstractCharacter>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//
|
||||
// Manage movement inputs
|
||||
//
|
||||
var movementDirection = Vector2.zero;
|
||||
|
||||
movementDirection += Input.GetAxis("Horizontal") * Vector2.right;
|
||||
movementDirection += Input.GetAxis("Vertical") * Vector2.up;
|
||||
|
||||
_character.Move(movementDirection);
|
||||
|
||||
//
|
||||
// Manage action inputs
|
||||
//
|
||||
|
||||
if (Input.GetButton("Fire1"))
|
||||
{
|
||||
_character.Shoot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ MonoImporter:
|
|||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
executionOrder: -5
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
|
|
@ -2,17 +2,31 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MovementManager : MonoBehaviour
|
||||
public class Mover : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
private AbstractCharacter _character;
|
||||
private Transform _transform;
|
||||
private Vector2 _direction;
|
||||
private float _maxSpeed;
|
||||
|
||||
public Vector2 Direction
|
||||
{
|
||||
|
||||
get { return _direction; }
|
||||
set { _direction = value; }
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Start()
|
||||
{
|
||||
_transform = GetComponentInParent<Transform>();
|
||||
_character = GetComponentInParent<AbstractCharacter>();
|
||||
_maxSpeed = _character.MaxSpeed;
|
||||
_direction = Vector2.zero;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
_maxSpeed = _character.MaxSpeed;
|
||||
Vector2 currentPosition = _transform.position;
|
||||
_transform.position = currentPosition + _maxSpeed * Time.deltaTime * _direction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,19 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerCharacter : MonoBehaviour
|
||||
public class PlayerCharacter : AbstractCharacter
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
public override void Move(Vector2 movementDirection)
|
||||
{
|
||||
|
||||
// TODO : Implement limits
|
||||
Debug.Log("Direction:");
|
||||
Debug.Log(movementDirection);
|
||||
_mover.Direction = movementDirection;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
public override void Shoot()
|
||||
{
|
||||
|
||||
// TODO : Implement
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ MonoImporter:
|
|||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
executionOrder: -1
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
|
Loading…
Add table
Reference in a new issue