wobblyhead hg > minor_monsters
comparison game/js/tower.js @ 13:8df95050fc8b
no more build during pause; tower popup closes on any click outside it
| author | ark |
|---|---|
| date | 2026-10-19 21:59 +0200 |
| parents | 910b26feca76 |
| children | c1c7e4f54bf6 |
comparison
equal
deleted
inserted
replaced
| 12:dc314bfbb1cf | 13:8df95050fc8b |
|---|---|
| 17 def: cfg.tower[type], | 17 def: cfg.tower[type], |
| 18 level: 1, | 18 level: 1, |
| 19 x: x, | 19 x: x, |
| 20 y: y, | 20 y: y, |
| 21 sides: sides || [true, true, true, true], | 21 sides: sides || [true, true, true, true], |
| 22 // purchases, {cost, pause}: pause is the number of the pause | 22 paid: 0, // coins paid for building and upgrades |
| 23 // the purchase was made in, 0 while the game ran | |
| 24 paid: [], | |
| 25 angle: -Math.PI / 2, | 23 angle: -Math.PI / 2, |
| 26 cooldown: 0, | 24 cooldown: 0, |
| 27 burst: 0 | 25 burst: 0 |
| 28 }; | 26 }; |
| 29 } | 27 } |
| 33 function upgradeCost(t) { | 31 function upgradeCost(t) { |
| 34 return t.level < t.def.damage.length ? t.def.cost * (t.level + 1) : null; | 32 return t.level < t.def.damage.length ? t.def.cost * (t.level + 1) : null; |
| 35 } | 33 } |
| 36 | 34 |
| 37 // coins back for selling the tower: half of everything paid for it, | 35 // coins back for selling the tower: half of everything paid for it, |
| 38 // rounded down, except purchases made during the current pause, which | 36 // rounded down |
| 39 // come back in full. pause is the number of the current pause, 0 while | 37 function refund(t) { |
| 40 // the game runs. | 38 return Math.floor(t.paid * cfg.tower_rules.sell_refund); |
| 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; | |
| 48 } | 39 } |
| 49 | 40 |
| 50 function sprite(t) { | 41 function sprite(t) { |
| 51 return t.level === 1 ? t.type : t.type + "_" + t.level; | 42 return t.level === 1 ? t.type : t.type + "_" + t.level; |
| 52 } | 43 } |
