mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-26 08:53:32 +08:00
Fix TNT respawn
This commit is contained in:
parent
2b1226cc2d
commit
8e46b70dbd
@ -330,7 +330,7 @@ class GameActivity(Activity):
|
||||
self._map_type.preload()
|
||||
self._map: Optional[ba.Map] = None
|
||||
self._powerup_drop_timer: Optional[ba.Timer] = None
|
||||
self._tnt_objs: Optional[Dict[int, Any]] = None
|
||||
self._tnt_spawners: Optional[Dict[int, Any]] = None
|
||||
self._tnt_drop_timer: Optional[ba.Timer] = None
|
||||
self.initial_player_info: Optional[List[Dict[str, Any]]] = None
|
||||
self._game_scoreboard_name_text: Optional[ba.Actor] = None
|
||||
@ -1111,12 +1111,8 @@ class GameActivity(Activity):
|
||||
repeat=True)
|
||||
self._standard_drop_powerups()
|
||||
if enable_tnt:
|
||||
self._tnt_objs = {}
|
||||
self._tnt_drop_timer = _ba.Timer(5.5,
|
||||
_general.WeakCall(
|
||||
self._standard_drop_tnt),
|
||||
repeat=True)
|
||||
self._standard_drop_tnt()
|
||||
self._tnt_spawners = {}
|
||||
self._setup_standard_tnt_drops()
|
||||
|
||||
def _standard_drop_powerup(self, index: int, expire: bool = True) -> None:
|
||||
# pylint: disable=cyclic-import
|
||||
@ -1136,24 +1132,15 @@ class GameActivity(Activity):
|
||||
_ba.timer(i * 0.4, _general.WeakCall(self._standard_drop_powerup,
|
||||
i))
|
||||
|
||||
def _standard_drop_tnt(self) -> None:
|
||||
def _setup_standard_tnt_drops(self) -> None:
|
||||
"""Standard tnt drop."""
|
||||
# pylint: disable=cyclic-import
|
||||
from bastd.actor import bomb
|
||||
|
||||
# Drop TNT on the map for any tnt location with no existing tnt box.
|
||||
for i, point in enumerate(self.map.tnt_points):
|
||||
assert self._tnt_objs is not None
|
||||
if i not in self._tnt_objs:
|
||||
self._tnt_objs[i] = {'absent_ticks': 9999, 'obj': None}
|
||||
tnt_obj = self._tnt_objs[i]
|
||||
|
||||
# Respawn once its been dead for a while.
|
||||
if not tnt_obj['obj']:
|
||||
tnt_obj['absent_ticks'] += 1
|
||||
if tnt_obj['absent_ticks'] > 3:
|
||||
tnt_obj['obj'] = bomb.Bomb(position=point, bomb_type='tnt')
|
||||
tnt_obj['absent_ticks'] = 0
|
||||
assert self._tnt_spawners is not None
|
||||
if self._tnt_spawners.get(i) is None:
|
||||
self._tnt_spawners[i] = bomb.TNTSpawner(point)
|
||||
|
||||
def setup_standard_time_limit(self, duration: float) -> None:
|
||||
"""
|
||||
|
||||
@ -1047,17 +1047,17 @@ class TNTSpawner:
|
||||
category: Gameplay Classes
|
||||
"""
|
||||
|
||||
def __init__(self, position: Sequence[float], respawn_time: float = 30.0):
|
||||
def __init__(self, position: Sequence[float], respawn_time: float = 20.0):
|
||||
"""Instantiate with given position and respawn_time (in seconds)."""
|
||||
self._position = position
|
||||
self._tnt: Optional[Bomb] = None
|
||||
self._respawn_time = random.uniform(0.8, 1.2) * respawn_time
|
||||
self._wait_time = 0.0
|
||||
self._update()
|
||||
# (go with slightly more than 1 second to avoid timer stacking)
|
||||
self._update_timer = ba.Timer(1.1,
|
||||
ba.WeakCall(self._update),
|
||||
repeat=True)
|
||||
self._respawn_time = random.uniform(0.8, 1.2) * respawn_time
|
||||
self._wait_time = 0.0
|
||||
|
||||
def _update(self) -> None:
|
||||
tnt_alive = self._tnt is not None and self._tnt.node
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user