-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodules.js
More file actions
140 lines (111 loc) · 2.73 KB
/
modules.js
File metadata and controls
140 lines (111 loc) · 2.73 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* global game, Ship, ShieldEntity, traits */
"use strict";
// Base class for modules.
var Module = extend(Object, traits.HasAttributes,
{
init: function()
{
this.ship = null;
if (!this.relativePos)
this.relativePos = new V(0, 0);
this.recalculateAttributes();
},
model: null,
modelColor: null,
equip: function()
{
},
unequip: function()
{
},
step: function(t, dt)
{
},
render: function()
{
if (this.model) {
var targetDir = this.ship.getModuleTargetPos(this).sub_(this.ship.p);
this.model.render(this.modelColor, this.ship.relativePos(this.relativePos), targetDir);
}
},
});
var modules = {
// Shield module.
Shield: extend(Module,
{
name: "Shield",
modelName: "itemShield",
description: "Generates a shield that blocks incoming projectiles.",
shieldRadius: 15,
shieldMaxHp: 50,
shieldRegen: 2,
shieldRegenDelay: 5,
shieldInactiveRegenDelay: 5,
// Creates the actual shield entity that handles collisions.
equip: function()
{
var param = { radius: this.shieldRadius, maxHp: this.shieldMaxHp, regen: this.shieldRegen,
regenDelay: this.shieldRegenDelay, inactiveRegenDelay: this.shieldInactiveRegenDelay};
// We can link the shield position/movement with the ship because it has no movement handling
// of its own. However we gotta be careful to never create new p/v vector for either entity.
param.p = this.ship.p; // No clone()!
param.v = this.ship.v; // No clone()!
param.m = this.ship.m;
param.faction = this.ship.faction;
this.shield = game.addEntity(ShieldEntity(param));
this.ship.shield = this.shield; // For GUI.
},
unequip: function()
{
this.ship.shield = null;
// Kill the shield entity so it doesn't stay behind.
this.shield.hp = 0;
this.shield.regen = 0;
this.shield = null;
},
}),
// Repairs ship over time.
RepairModule: extend(Module,
{
name: "Repair module",
modelName: "itemRepairModule",
description: "Restore's hit points over time.",
repairSpeed: 0.5,
step: function(t, dt)
{
this.ship.hp = Math.min(this.ship.hp + dt * this.repairSpeed, this.ship.maxHp);
}
}),
// Reduces all incoming damage.
ArmorHardener: extend(Module,
{
name: "Armor Hardener",
modelName: "itemArmorHardener",
description: "Reduces amount of damage taken.",
damageReduction: 0.2,
equip: function()
{
this.ship.damageReduction += this.damageReduction;
},
unequip: function()
{
this.ship.damageReduction -= this.damageReduction;
}
}),
// Increases ship's energy output.
PowerPlant: extend(Module,
{
name: "Power Plant",
modelName: "itemPowerPlant",
description: "Increases ship's energy output.",
powerOutput: 7,
equip: function()
{
this.ship.powerOutput += this.powerOutput;
},
unequip: function()
{
this.ship.powerOutput -= this.powerOutput;
}
}),
};