Day 1 Finished! Got the bare bones of the game functional. It's basically a game without any polish at the smallest scope possible.

This commit is contained in:
Gregory Campbell
2020-07-11 01:42:26 -04:00
parent c8f1a8291a
commit 0893d08a17
24 changed files with 1038 additions and 63 deletions
+43
View File
@@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletScript : MonoBehaviour
{
public float speed;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
rb.velocity = transform.up * speed;
}
void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.tag != "Player")
{
Destroy(gameObject);
}
if(other.gameObject.tag == "Player")
{
Physics2D.IgnoreCollision(
other.gameObject.GetComponent<Collider2D>(), GetComponent<Collider2D>());
}
}
void OnBecameInvisible()
{
Destroy(gameObject);
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a30097626420c2945aa94dc3cee845d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+38
View File
@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyScript : MonoBehaviour
{
public float speed;
private GameObject player;
void Start()
{
player = GameObject.FindWithTag("Player");
}
// Update is called once per frame
void Update()
{
if(player != null)
{
transform.position = Vector2.MoveTowards(
transform.position, player.transform.position, speed * Time.deltaTime);
}
}
void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.tag == "Bullet" || other.gameObject.tag == "Player")
{
Destroy(gameObject);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8fbb02e1dc3bc974aa589a68804bca34
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+75
View File
@@ -0,0 +1,75 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GMScript : MonoBehaviour
{
public GameObject obstacle;
public GameObject enemy;
private float obstacleSpawnTime;
private float obstacleTime = 0.0f;
private float enemySpawnTime;
private float enemyTime = 0.0f;
private Transform playerPos;
void Start()
{
playerPos = GameObject.FindWithTag("Player").transform;
obstacleSpawnTime = Random.Range(5.0f, 15.0f);
enemySpawnTime = Random.Range(5.0f, 15.0f);
}
// Update is called once per frame
void Update()
{
obstacleTime += Time.deltaTime;
enemyTime += Time.deltaTime;
if(obstacleTime > obstacleSpawnTime)
{
Instantiate(obstacle, new Vector2(Random.Range(-8.0f, 8.0f), Random.Range(-4.0f, 4.0f)),
Quaternion.Euler(0,0,Random.Range(0.0f, 360.0f)));
obstacleSpawnTime = Random.Range(5.0f, 15.0f);
obstacleTime = 0.0f;
}
if(enemyTime > enemySpawnTime)
{
Instantiate(enemy, new Vector2(Random.Range(-8.0f, 8.0f), Random.Range(-4.0f, 4.0f)),
Quaternion.identity);
enemySpawnTime = Random.Range(5.0f, 15.0f);
enemyTime = 0.0f;
}
}
Vector2 ValidSpawn()
{
bool valid = false;
Vector2 spawn;
do{
spawn = new Vector2(Random.Range(-8.0f, 8.0f), Random.Range(-4.0f, 4.0f));
if((spawn.x > playerPos.position.x + 2 || spawn.x < playerPos.position.x - 2)
&& (spawn.y > playerPos.position.y + 2 || spawn.y < playerPos.position.y - 2))
{
valid = true;
}
}while(!valid);
return spawn;
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4405a560ade36784d9d974387de13a1e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+30
View File
@@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObsctaleScript : MonoBehaviour
{
private float deathTime;
private float myTime = 0.0f;
void Start()
{
deathTime = Random.Range(5.0f, 15.0f);
}
// Update is called once per frame
void Update()
{
myTime += Time.deltaTime;
if(myTime > deathTime)
{
Destroy(gameObject);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 266e99c3ce69dbf44bf3ee5618791128
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+62
View File
@@ -0,0 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerScript : MonoBehaviour
{
public float speed;
public GameObject bullet;
private float translation;
private float rotation;
private float nextFire = 0.5f;
private float myTime = 0.0f;
private Rigidbody2D rb;
void Awake()
{
rb = this.GetComponent<Rigidbody2D>();
}
void Update()
{
myTime += Time.deltaTime;
if(Input.GetButton("Fire1") && myTime > nextFire)
{
nextFire = myTime + 0.5f;
Instantiate(bullet, transform.position, Quaternion.Euler(0,0,Random.Range(0.0f, 360.0f)));
nextFire = nextFire - myTime;
myTime = 0.0f;
}
}
void FixedUpdate()
{
rb.velocity =
new Vector2(Input.GetAxis("Horizontal") * speed, Input.GetAxis("Vertical") * speed);
}
void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.tag == "Bullet")
{
Physics2D.IgnoreCollision(
other.gameObject.GetComponent<Collider2D>(), GetComponent<Collider2D>());
}
if(other.gameObject.tag == "Enemy")
{
Destroy(gameObject);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 923134a8f7008664184d79f6f00e68da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: