Skip to content

Commit

Permalink
PlayerMove and PlayerShot
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDX committed Nov 23, 2015
1 parent e6248fc commit 910d82c
Show file tree
Hide file tree
Showing 20 changed files with 251 additions and 0 deletions.
Binary file added .vs/Playground2015_Project2/v14/.suo
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Materials.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Materials/New Material.mat
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Materials/New Material.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/Resources.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/Resources/Prefabs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Resources/Prefabs/PrefabBullet.prefab
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Resources/Prefabs/PrefabBullet.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/Scenes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Scenes/mainScene.unity
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Scenes/mainScene.unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions Assets/Scripts/BulletBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using UnityEngine;
using System.Collections;

public class BulletBehavior : MonoBehaviour
{
#region Properties
public float m_Speed = 3.0f;
Rigidbody2D m_RigidB2D;
#endregion


#region Main methods
void Start ()
{
m_RigidB2D = GetComponent<Rigidbody2D>();
m_RigidB2D.velocity = Vector2.right * m_Speed;
}

void FixedUpdate()
{
// Bullet destruction default period (if never colliding)
Destroy(gameObject, 1);
}
#endregion


#region Utils

// TODO : destroy bullet after few seconds (in case of never collision entering)


void OnTriggerEnter2D(Collider2D other)
{
// If collision on a target, destroy it too
if (other.gameObject.CompareTag("Target"))
{
Destroy(gameObject);
Destroy(other.gameObject);
}
}

void OnCollisionEnter2D(Collision2D other)
{
// Destroy the bullet if entering with "Ground"-tagged gameObject
if (other.gameObject.CompareTag("Ground"))
{
Destroy(gameObject);
}
}

#endregion


}
12 changes: 12 additions & 0 deletions Assets/Scripts/BulletBehavior.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions Assets/Scripts/PlayerBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using UnityEngine;
using System.Collections;

public class PlayerBehavior : MonoBehaviour
{

#region Public properties
public string m_Axis;
public float m_MoveSpeed = 10.0f;
public float m_JumpSpeed = 10.0f;
#endregion


#region Main methods
void Start ()
{
m_RigidB2D = GetComponent<Rigidbody2D>();
}

void Update()
{

}

void FixedUpdate ()
{
m_CurrentPosition = transform.position;

InstantiateBullet();
Move();
Jump();
}
#endregion


#region Utils
// TODO : input DIRECTION ! (= player direction; left or right)
void InstantiateBullet()
{
if (Input.GetKeyDown(KeyCode.Return))
{
GameObject BulletPrefab = (GameObject)Instantiate(Resources.Load("prefabs/PrefabBullet"));
BulletPrefab.transform.position = m_CurrentPosition;
}
}

void Move()
{
float Axis = Input.GetAxisRaw(m_Axis);
m_RigidB2D.velocity = new Vector2(Axis, 0) * m_MoveSpeed;
}

void Jump()
{
if (Input.GetKeyDown(KeyCode.Space) && m_RigidB2D.velocity.y == 0)
{
m_RigidB2D.velocity = (Vector2.up * m_JumpSpeed);
}
}

void OnGUI()
{
GUILayout.Button("x: " + m_RigidB2D.velocity.x + " \n y:" + m_RigidB2D.velocity.y);
}
#endregion



#region Private properties

Vector3 m_CurrentPosition;
Rigidbody2D m_RigidB2D;

#endregion


}
12 changes: 12 additions & 0 deletions Assets/Scripts/PlayerBehavior.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Assets/Scripts/WallBehaviour.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;

public class WallBehaviour : MonoBehaviour {


void Start () {

}


void Update () {

}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/WallBehaviour.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified ProjectSettings/TagManager.asset
Binary file not shown.
Binary file not shown.

0 comments on commit 910d82c

Please sign in to comment.