wobblyhead hg > minor_monsters
comparison game/js/tower.js @ 6:910b26feca76
full game flow
| author | ark |
|---|---|
| date | 2026-10-19 01:05 +0200 |
| parents | 2d46729a022e |
| children | 8df95050fc8b |
comparison
equal
deleted
inserted
replaced
| 5:67bf3c505145 | 6:910b26feca76 |
|---|---|
| 1 // towers: targeting and attacks | 1 // towers: targeting, attacks, upgrade, sell |
| 2 | 2 |
| 3 window.MM = window.MM || {}; | 3 window.MM = window.MM || {}; |
| 4 | 4 |
| 5 MM.tower = (function () { | 5 MM.tower = (function () { |
| 6 "use strict"; | 6 "use strict"; |
| 7 | 7 |
| 8 var cfg = MM.config; | 8 var cfg = MM.config; |
| 9 // how long a melee attack shows its spikes pushed out | 9 // how long a melee attack shows its spikes pushed out |
| 10 var BURST_TIME = 0.3; | 10 var BURST_TIME = 0.3; |
| 11 | 11 |
| 12 function create(type, x, y) { | 12 // sides: for t0, which sides draw spikes (map.facingSides); all four |
| 13 // when left out | |
| 14 function create(type, x, y, sides) { | |
| 13 return { | 15 return { |
| 14 type: type, | 16 type: type, |
| 15 def: cfg.tower[type], | 17 def: cfg.tower[type], |
| 16 level: 1, | 18 level: 1, |
| 17 x: x, | 19 x: x, |
| 18 y: y, | 20 y: y, |
| 21 sides: sides || [true, true, true, true], | |
| 22 // purchases, {cost, pause}: pause is the number of the pause | |
| 23 // the purchase was made in, 0 while the game ran | |
| 24 paid: [], | |
| 19 angle: -Math.PI / 2, | 25 angle: -Math.PI / 2, |
| 20 cooldown: 0, | 26 cooldown: 0, |
| 21 burst: 0 | 27 burst: 0 |
| 22 }; | 28 }; |
| 29 } | |
| 30 | |
| 31 // cost of the next level, null at the top level. level n costs the | |
| 32 // base cost x n. | |
| 33 function upgradeCost(t) { | |
| 34 return t.level < t.def.damage.length ? t.def.cost * (t.level + 1) : null; | |
| 35 } | |
| 36 | |
| 37 // coins back for selling the tower: half of everything paid for it, | |
| 38 // rounded down, except purchases made during the current pause, which | |
| 39 // come back in full. pause is the number of the current pause, 0 while | |
| 40 // the game runs. | |
| 41 function refund(t, pause) { | |
| 42 var rest = 0, full = 0; | |
| 43 t.paid.forEach(function (p) { | |
| 44 if (pause && p.pause === pause) full += p.cost; | |
| 45 else rest += p.cost; | |
| 46 }); | |
| 47 return Math.floor(rest * cfg.tower_rules.sell_refund) + full; | |
| 23 } | 48 } |
| 24 | 49 |
| 25 function sprite(t) { | 50 function sprite(t) { |
| 26 return t.level === 1 ? t.type : t.type + "_" + t.level; | 51 return t.level === 1 ? t.type : t.type + "_" + t.level; |
| 27 } | 52 } |
| 76 game.projectiles.push(MM.projectile.create(t, m, damage(t))); | 101 game.projectiles.push(MM.projectile.create(t, m, damage(t))); |
| 77 } | 102 } |
| 78 } | 103 } |
| 79 | 104 |
| 80 return { create: create, update: update, sprite: sprite, range: range, | 105 return { create: create, update: update, sprite: sprite, range: range, |
| 81 BURST_TIME: BURST_TIME }; | 106 upgradeCost: upgradeCost, refund: refund, BURST_TIME: BURST_TIME }; |
| 82 })(); | 107 })(); |
