-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCannonController.cs
More file actions
93 lines (89 loc) · 4.11 KB
/
Copy pathCannonController.cs
File metadata and controls
93 lines (89 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Threading.Tasks;
using UnityEngine;
public class CannonController : ComponentController {
public bool automatic;
public GameObject Shell;
public AudioClip ShellFireSfx;
float[] reload_timer;
public const float RELOAD_TIME = 1f;
private int shell_count = 0;
public override float GetCost() {
return 101; //1 metal 1 carbon
}
public override void Focus() {
}
public override void Design() {
launched = false;
GetComponent<SpriteRenderer>().sprite = inverse;
}
public override void Ping() {
int num_cannons = Mathf.FloorToInt(GetComponent<SpriteRenderer>().size.x - 1);
if (reload_timer == null || reload_timer.Length != num_cannons) reload_timer = new float[num_cannons];
for (int i = 0; i < reload_timer.Length; i++)
{
reload_timer[i] = Mathf.Clamp(reload_timer[i] - .01f, 0, 10);
}
if (automatic) Action(0);
}
public override float Action ()
{
return Action(0);
}
public override float Action (float input)
{
if (this == null) { Destroy(this); return -999; }
if (reload_timer == null) Ping();
for (int i = 0; i < reload_timer.Length; i++) {
if (reload_timer[i] <= 0)
{
if (automatic && i == 0 || !automatic) {
GetComponent<AudioSource>().clip = ShellFireSfx;
GetComponent<AudioSource>().volume = .1f;
GetComponent<AudioSource>().Play();
}
// Interactor.Sound("Cannon" + ((i % 3) + 1));
reload_timer[i] = Mathf.FloorToInt(GetComponent<SpriteRenderer>().size.y) * this.transform.localScale.y / 2.5f;
GameObject shell = Instantiate(
Shell,
this.transform.position,
this.transform.rotation,
this.transform
) as GameObject;
shell.transform.Translate(new Vector2(this.transform.localScale.x * ((i + .5f) - reload_timer.Length / 2f), this.transform.localScale.y * GetComponent<SpriteRenderer>().size.y / 2f));
shell.name = "⤒" + this.name + shell_count++;
shell.transform.SetParent(GameObject.Find("World").transform);
shell.GetComponent<ProjectileController>().speed = GetComponent<SpriteRenderer>().size.y * 5f + (GetComponentInParent<StructureController>().translation.magnitude * 55f);
shell.GetComponent<ProjectileController>().damage = Mathf.FloorToInt((GetComponent<SpriteRenderer>().size.y + 1) / 2f);
if (this.name == "HeatRay") shell.GetComponent<ProjectileController>().speed = 100;
return 1;
}
}
return 0;
}
public override Vector2 GetMinimumSize ()
{
return new Vector2(2, 2);
}
public override void Launch() {
launched = true;
GetComponent<SpriteRenderer>().sprite = sprite;
}
public string GetReloadString() {
if (reload_timer == null) Ping();
string output = "";
for (int i = 0; i < reload_timer.Length; i++) {
if (i == reload_timer.Length - 1) output += $"{reload_timer[i].ToString("0.00").TrimEnd('0').TrimEnd('.')}";
else output += $"{reload_timer[i].ToString("0.00").TrimEnd('0').TrimEnd('.')}, ";
}
return $"{{ {output} }}";
}
public override string GetIcon() { return "◍"; }
public override string ToString()
{
return $"{GetIcon()} {this.name}\n{base.ToString()}\n barrels = {GetReloadString()};\n /*_Weapon_control_*/\n void Fire_() {{\n int b = getBarrel();\n if (b != -1) {{\n Shell s = new Shell (b, size.y);\n barrels[b] = size.y;\n }}\n }}\n /*_Get_loaded_barrel_*/\n int GetBarrel_() {{\n for (int b = 0; b < barrels.length; b++) {{\n if (barrels[b] == 0) {{ \n return b;\n }}\n }}\n return -1;\n }}\n}}\n☑_Ok\n☒_Cancel\n☒_Delete\n⍰⍰_Help";
}
}