adding block dash, canon fight mini games

This commit is contained in:
Ayush Saini 2024-03-17 02:32:19 +05:30
parent 16570cdcab
commit d6e457c821
4 changed files with 1125 additions and 0 deletions

479
dist/ba_root/mods/games/block_dash.py vendored Normal file
View file

@ -0,0 +1,479 @@
# Porting to api 8 made easier by baport.(https://github.com/bombsquad-community/baport)
# Released under the MIT License. See LICENSE for details.
#
"""Elimination mini-game."""
# ba_meta require api 8
# (see https://ballistica.net/wiki/meta-tag-system)
from __future__ import annotations
from typing import TYPE_CHECKING
import babase
import bascenev1 as bs
from bascenev1lib.actor.spazfactory import SpazFactory
from bascenev1lib.actor.scoreboard import Scoreboard
from bascenev1lib.gameutils import SharedObjects
if TYPE_CHECKING:
from typing import Any, Sequence, Optional, Union
import random
from bascenev1lib.game.elimination import EliminationGame,Player,Team
# ba_meta export bascenev1.GameActivity
class BlockDashGame(EliminationGame):
"""Game type where last player(s) left alive win."""
name = 'Block Dash'
description = 'Last remaining alive wins.'
scoreconfig = bs.ScoreConfig(label='Survived',
scoretype=bs.ScoreType.SECONDS,
none_is_winner=True)
# Show messages when players die since it's meaningful here.
announce_player_deaths = True
allow_mid_activity_joins = False
@classmethod
def get_supported_maps(cls, sessiontype: type[bs.Session]) -> list[str]:
return ["Wooden Floor"]
def __init__(self, settings: dict):
super().__init__(settings)
shared=SharedObjects.get()
self._scoreboard = Scoreboard()
self._start_time: Optional[float] = None
self._vs_text: Optional[bs.Actor] = None
self._round_end_timer: Optional[bs.Timer] = None
self._epic_mode = bool(settings['Epic Mode'])
self._lives_per_player =1
self._time_limit = float(settings['Time Limit'])
self._balance_total_lives = bool(
settings.get('Balance Total Lives', False))
self._solo_mode = bool(settings.get('Solo Mode', False))
# Base class overrides:
self.slow_motion = self._epic_mode
self.default_music = (bs.MusicType.EPIC
if self._epic_mode else bs.MusicType.SURVIVAL)
self.laser_material=bs.Material()
self.laser_material.add_actions(
conditions=('they_have_material',
shared.player_material),
actions=(('modify_part_collision', 'collide',True),
('message','their_node','at_connect',bs.DieMessage()))
)
def get_instance_description(self) -> Union[str, Sequence]:
return 'Last team standing wins.' if isinstance(
self.session, bs.DualTeamSession) else 'Last one standing wins.'
def get_instance_description_short(self) -> Union[str, Sequence]:
return 'last team standing wins' if isinstance(
self.session, bs.DualTeamSession) else 'last one standing wins'
def on_player_join(self, player: Player) -> None:
player.lives = self._lives_per_player
if self._solo_mode:
player.team.spawn_order.append(player)
self._update_solo_mode()
else:
# Create our icon and spawn.
# player.icons = [Icon(player, position=(0, 50), scale=0.8)]
if player.lives > 0:
self.spawn_player(player)
# Don't waste time doing this until begin.
if self.has_begun():
self._update_icons()
def on_begin(self) -> None:
super().on_begin()
self._start_time = bs.time()
self.setup_standard_time_limit(self._time_limit)
# self.setup_standard_powerup_drops()
self.add_wall()
if self._solo_mode:
self._vs_text = bs.NodeActor(
bs.newnode('text',
attrs={
'position': (0, 105),
'h_attach': 'center',
'h_align': 'center',
'maxwidth': 200,
'shadow': 0.5,
'vr_depth': 390,
'scale': 0.6,
'v_attach': 'bottom',
'color': (0.8, 0.8, 0.3, 1.0),
'text': babase.Lstr(resource='vsText')
}))
# If balance-team-lives is on, add lives to the smaller team until
# total lives match.
if (isinstance(self.session, bs.DualTeamSession)
and self._balance_total_lives and self.teams[0].players
and self.teams[1].players):
if self._get_total_team_lives(
self.teams[0]) < self._get_total_team_lives(self.teams[1]):
lesser_team = self.teams[0]
greater_team = self.teams[1]
else:
lesser_team = self.teams[1]
greater_team = self.teams[0]
add_index = 0
while (self._get_total_team_lives(lesser_team) <
self._get_total_team_lives(greater_team)):
lesser_team.players[add_index].lives += 1
add_index = (add_index + 1) % len(lesser_team.players)
self._update_icons()
# We could check game-over conditions at explicit trigger points,
# but lets just do the simple thing and poll it.
bs.timer(1.0, self._update, repeat=True)
def _update_solo_mode(self) -> None:
# For both teams, find the first player on the spawn order list with
# lives remaining and spawn them if they're not alive.
for team in self.teams:
# Prune dead players from the spawn order.
team.spawn_order = [p for p in team.spawn_order if p]
for player in team.spawn_order:
assert isinstance(player, Player)
if player.lives > 0:
if not player.is_alive():
self.spawn_player(player)
break
def _update_icons(self) -> None:
return
# lets do nothing ;Eat 5 Star
def _get_spawn_point(self, player: Player) -> Optional[babase.Vec3]:
del player # Unused.
# In solo-mode, if there's an existing live player on the map, spawn at
# whichever spot is farthest from them (keeps the action spread out).
if self._solo_mode:
living_player = None
living_player_pos = None
for team in self.teams:
for tplayer in team.players:
if tplayer.is_alive():
assert tplayer.node
ppos = tplayer.node.position
living_player = tplayer
living_player_pos = ppos
break
if living_player:
assert living_player_pos is not None
player_pos = babase.Vec3(living_player_pos)
points: list[tuple[float, babase.Vec3]] = []
for team in self.teams:
start_pos = babase.Vec3(self.map.get_start_position(team.id))
points.append(
((start_pos - player_pos).length(), start_pos))
# Hmm.. we need to sorting vectors too?
points.sort(key=lambda x: x[0])
return points[-1][1]
return None
def spawn_player(self, player: Player) -> bs.Actor:
p=[-6,-4.3,-2.6,-0.9,0.8,2.5,4.2,5.9]
q=[-4,-2.3,-0.6,1.1,2.8,4.5]
x=random.randrange(0,len(p))
y=random.randrange(0,len(q))
actor = self.spawn_player_spaz(player, position=(0,1.8,0))
actor.connect_controls_to_player(enable_punch=False,
enable_bomb=False,
enable_pickup=False)
if not self._solo_mode:
bs.timer(0.3, babase.Call(self._print_lives, player))
# If we have any icons, update their state.
for icon in player.icons:
icon.handle_player_spawned()
return actor
def _print_lives(self, player: Player) -> None:
from bascenev1lib.actor import popuptext
# We get called in a timer so it's possible our player has left/etc.
if not player or not player.is_alive() or not player.node:
return
popuptext.PopupText('x' + str(player.lives - 1),
color=(1, 1, 0, 1),
offset=(0, -0.8, 0),
random_offset=0.0,
scale=1.8,
position=player.node.position).autoretain()
def on_player_leave(self, player: Player) -> None:
super().on_player_leave(player)
player.icons = []
# Remove us from spawn-order.
if self._solo_mode:
if player in player.team.spawn_order:
player.team.spawn_order.remove(player)
# Update icons in a moment since our team will be gone from the
# list then.
bs.timer(0, self._update_icons)
# If the player to leave was the last in spawn order and had
# their final turn currently in-progress, mark the survival time
# for their team.
if self._get_total_team_lives(player.team) == 0:
assert self._start_time is not None
player.team.survival_seconds = int(bs.time() - self._start_time)
def _get_total_team_lives(self, team: Team) -> int:
return sum(player.lives for player in team.players)
def handlemessage(self, msg: Any) -> Any:
if isinstance(msg, bs.PlayerDiedMessage):
# Augment standard behavior.
super().handlemessage(msg)
player: Player = msg.getplayer(Player)
player.lives -= 1
if player.lives < 0:
babase.print_error(
"Got lives < 0 in Elim; this shouldn't happen. solo:" +
str(self._solo_mode))
player.lives = 0
# If we have any icons, update their state.
for icon in player.icons:
icon.handle_player_died()
# Play big death sound on our last death
# or for every one in solo mode.
if self._solo_mode or player.lives == 0:
SpazFactory.get().single_player_death_sound.play()
# If we hit zero lives, we're dead (and our team might be too).
if player.lives == 0:
# If the whole team is now dead, mark their survival time.
if self._get_total_team_lives(player.team) == 0:
assert self._start_time is not None
player.team.survival_seconds = int(bs.time() -
self._start_time)
else:
# Otherwise, in regular mode, respawn.
if not self._solo_mode:
self.respawn_player(player)
# In solo, put ourself at the back of the spawn order.
if self._solo_mode:
player.team.spawn_order.remove(player)
player.team.spawn_order.append(player)
def _update(self) -> None:
if self._solo_mode:
# For both teams, find the first player on the spawn order
# list with lives remaining and spawn them if they're not alive.
for team in self.teams:
# Prune dead players from the spawn order.
team.spawn_order = [p for p in team.spawn_order if p]
for player in team.spawn_order:
assert isinstance(player, Player)
if player.lives > 0:
if not player.is_alive():
self.spawn_player(player)
self._update_icons()
break
# If we're down to 1 or fewer living teams, start a timer to end
# the game (allows the dust to settle and draws to occur if deaths
# are close enough).
if len(self._get_living_teams()) < 2:
self._round_end_timer = bs.Timer(0.5, self.end_game)
def _get_living_teams(self) -> list[Team]:
return [
team for team in self.teams
if len(team.players) > 0 and any(player.lives > 0
for player in team.players)
]
def end_game(self) -> None:
if self.has_ended():
return
results = bs.GameResults()
self._vs_text = None # Kill our 'vs' if its there.
for team in self.teams:
results.set_team_score(team, team.survival_seconds)
self.end(results=results)
def add_wall(self):
# FIXME: Chop this into vr and non-vr chunks.
shared = SharedObjects.get()
pwm=bs.Material()
cwwm=bs.Material()
# pwm.add_actions(
# actions=('modify_part_collision', 'friction', 0.0))
# anything that needs to hit the wall should apply this.
pwm.add_actions(
actions=(
('modify_part_collision', 'collide', True),
('modify_part_collision', 'physical', True)
))
self.mat = bs.Material()
self.mat.add_actions(
actions=( ('modify_part_collision','physical',False),
('modify_part_collision','collide',False))
)
ud_1_r=bs.newnode('region',attrs={'position': (-2,0,-4),'scale': (14.5,1,14.5),'type': 'box','materials': [shared.footing_material,pwm ]})
node = bs.newnode('prop',
owner=ud_1_r,
attrs={
'mesh':bs.getmesh('image1x1'),
'light_mesh':bs.getmesh('powerupSimple'),
'position':(2,7,2),
'body':'puck',
'shadow_size':0.0,
'velocity':(0,0,0),
'color_texture':bs.gettexture('flagColor'),
'mesh_scale':14.5,
'reflection_scale':[1.5],
'materials':[self.mat, shared.object_material,shared.footing_material],
})
mnode = bs.newnode('math',
owner=ud_1_r,
attrs={
'input1': (0, 0.7, 0),
'operation': 'add'
})
node.changerotation(1,0,0)
ud_1_r.connectattr('position', mnode, 'input2')
mnode.connectattr('output', node, 'position')
bs.timer(8,babase.Call(self.create_block_wall_easy))
self.gate_count=4
self.wall_count=0
def create_wall(self):
x=-9
for i in range(0,17):
self.create_block(x,0.5)
self.create_block(x,1.2)
x=x+0.85
def create_block_wall_hardest(self):
x=-3
for i in range(0,7):
self.create_block(x,0.4)
x=x+0.85
bs.timer(1.5,babase.Call(self.create_wall))
bs.timer(15,babase.Call(self.create_block_wall_hardest))
def create_block_wall_hard(self):
x=-9
self.wall_count+=1
for i in range(0,17):
self.create_block(x,0.4)
x=x+0.85
if self.wall_count <4:
bs.timer(12,babase.Call(self.create_block_wall_hard))
else:
bs.timer(7,babase.Call(self.create_block_wall_hard)) #hardest too heavy to play
def create_block_wall_easy(self):
x=-9
c=0
for i in range(0,17):
if random.randrange(0,2) and c<self.gate_count:
pass
else:
self.create_block(x,0.5)
c+=1
x=x+0.85
self.wall_count+=1
if self.wall_count < 5:
bs.timer(11,babase.Call(self.create_block_wall_easy))
else:
self.wall_count=0
bs.timer(15,babase.Call(self.create_block_wall_hard))
def create_block(self,x,y):
shared = SharedObjects.get()
pwm=bs.Material()
cwwm=bs.Material()
# pwm.add_actions(
# actions=('modify_part_collision', 'friction', 0.0))
# anything that needs to hit the wall should apply this.
pwm.add_actions(
actions=(
('modify_part_collision', 'collide', True),
('modify_part_collision', 'physical', True)
))
self.mat = bs.Material()
self.mat.add_actions(
actions=( ('modify_part_collision','physical',False),
('modify_part_collision','collide',False))
)
cmesh = bs.getcollisionmesh('courtyardPlayerWall')
ud_1_r=bs.newnode('region',attrs={'position': (x,y,-13),'scale': (1,1.5,1),'type': 'box','materials': [shared.footing_material,pwm ]})
node = bs.newnode('prop',
owner=ud_1_r,
attrs={
'mesh':bs.getmesh('tnt'),
'light_mesh':bs.getmesh('powerupSimple'),
'position':(2,7,2),
'body':'puck',
'shadow_size':0.0,
'velocity':(0,0,0),
'color_texture':bs.gettexture('tnt'),
'mesh_scale':1.2,
'reflection_scale':[1.5],
'materials':[self.mat, shared.object_material,shared.footing_material],
'density':9000000000
})
mnode = bs.newnode('math',
owner=ud_1_r,
attrs={
'input1': (0, 0.5, 0),
'operation': 'add'
})
node.changerotation(1,0,0)
ud_1_r.connectattr('position', mnode, 'input2')
mnode.connectattr('output', node, 'position')
_rcombine=bs.newnode('combine',
owner=ud_1_r,
attrs={
'input0':x,
'input1':y,
'size':3
})
bs.animate(_rcombine,'input2',{
0:-12,
11:4
})
_rcombine.connectattr('output',ud_1_r,'position')
bs.timer(11,babase.Call(ud_1_r.delete))

432
dist/ba_root/mods/games/canon_fight.py vendored Normal file
View file

@ -0,0 +1,432 @@
# Porting to api 8 made easier by baport.(https://github.com/bombsquad-community/baport)
# Released under the MIT License. See LICENSE for details.
#
"""DeathMatch game and support classes."""
# ba_meta require api 8
# (see https://ballistica.net/wiki/meta-tag-system)
from __future__ import annotations
from typing import TYPE_CHECKING
import babase
import bascenev1 as bs
import random
from bascenev1lib.actor.playerspaz import PlayerSpaz
from bascenev1lib.actor.scoreboard import Scoreboard
from bascenev1lib.gameutils import SharedObjects
from bascenev1lib.actor.bomb import BombFactory
from bascenev1lib.actor.bomb import Bomb
from bascenev1lib.game.deathmatch import DeathMatchGame,Player,Team
if TYPE_CHECKING:
from typing import Any, Union, Sequence, Optional
# ba_meta export bascenev1.GameActivity
class CanonFightGame(DeathMatchGame):
"""A game type based on acquiring kills."""
name = 'Canon Fight'
description = 'Kill a set number of enemies to win.'
# Print messages when players die since it matters here.
announce_player_deaths = True
@classmethod
def get_available_settings(
cls, sessiontype: type[bs.Session]) -> list[babase.Setting]:
settings = [
bs.IntSetting(
'Kills to Win Per Player',
min_value=1,
default=5,
increment=1,
),
bs.IntChoiceSetting(
'Time Limit',
choices=[
('None', 0),
('1 Minute', 60),
('2 Minutes', 120),
('5 Minutes', 300),
('10 Minutes', 600),
('20 Minutes', 1200),
],
default=0,
),
bs.FloatChoiceSetting(
'Respawn Times',
choices=[
('Shorter', 0.25),
('Short', 0.5),
('Normal', 1.0),
('Long', 2.0),
('Longer', 4.0),
],
default=1.0,
),
bs.BoolSetting('Epic Mode', default=False),
]
# In teams mode, a suicide gives a point to the other team, but in
# free-for-all it subtracts from your own score. By default we clamp
# this at zero to benefit new players, but pro players might like to
# be able to go negative. (to avoid a strategy of just
# suiciding until you get a good drop)
if issubclass(sessiontype, bs.FreeForAllSession):
settings.append(
bs.BoolSetting('Allow Negative Scores', default=False))
return settings
@classmethod
def supports_session_type(cls, sessiontype: type[bs.Session]) -> bool:
return (issubclass(sessiontype, bs.DualTeamSession)
or issubclass(sessiontype, bs.FreeForAllSession))
@classmethod
def get_supported_maps(cls, sessiontype: type[bs.Session]) -> list[str]:
return ["Step Right Up"]
def __init__(self, settings: dict):
super().__init__(settings)
self._scoreboard = Scoreboard()
self._score_to_win: Optional[int] = None
self._dingsound = bs.getsound('dingSmall')
self._epic_mode = bool(settings['Epic Mode'])
self._kills_to_win_per_player = int(
settings['Kills to Win Per Player'])
self._time_limit = float(settings['Time Limit'])
self._allow_negative_scores = bool(
settings.get('Allow Negative Scores', False))
# Base class overrides.
self.slow_motion = self._epic_mode
self.default_music = (bs.MusicType.EPIC if self._epic_mode else
bs.MusicType.TO_THE_DEATH)
self.wtindex=0
self.wttimer = bs.timer(5, babase.Call(self.wt_), repeat=True)
self.wthighlights=["Created by Mr.Smoothy","hey smoothy youtube","smoothy#multiverse"]
def wt_(self):
node = bs.newnode('text',
attrs={
'text': self.wthighlights[self.wtindex],
'flatness': 1.0,
'h_align': 'center',
'v_attach':'bottom',
'scale':0.7,
'position':(0,20),
'color':(0.5,0.5,0.5)
})
self.delt = bs.timer(4,node.delete)
self.wtindex = int((self.wtindex+1)%len(self.wthighlights))
def get_instance_description(self) -> Union[str, Sequence]:
return 'Crush ${ARG1} of your enemies.', self._score_to_win
def get_instance_description_short(self) -> Union[str, Sequence]:
return 'kill ${ARG1} enemies', self._score_to_win
def on_team_join(self, team: Team) -> None:
if self.has_begun():
self._update_scoreboard()
def on_begin(self) -> None:
super().on_begin()
self.setup_standard_time_limit(self._time_limit)
self.setup_standard_powerup_drops()
# Base kills needed to win on the size of the largest team.
self._score_to_win = (self._kills_to_win_per_player *
max(1, max(len(t.players) for t in self.teams)))
self._update_scoreboard()
self.create_canon_A()
self.create_canon_B()
self.create_wall()
def handlemessage(self, msg: Any) -> Any:
if isinstance(msg, bs.PlayerDiedMessage):
# Augment standard behavior.
super().handlemessage(msg)
player = msg.getplayer(Player)
self.respawn_player(player)
killer = msg.getkillerplayer(Player)
if killer is None:
return None
# Handle team-kills.
if killer.team is player.team:
# In free-for-all, killing yourself loses you a point.
if isinstance(self.session, bs.FreeForAllSession):
new_score = player.team.score - 1
if not self._allow_negative_scores:
new_score = max(0, new_score)
player.team.score = new_score
# In teams-mode it gives a point to the other team.
else:
self._dingsound.play()
for team in self.teams:
if team is not killer.team:
team.score += 1
# Killing someone on another team nets a kill.
else:
killer.team.score += 1
self._dingsound.play()
# In FFA show scores since its hard to find on the scoreboard.
if isinstance(killer.actor, PlayerSpaz) and killer.actor:
killer.actor.set_score_text(str(killer.team.score) + '/' +
str(self._score_to_win),
color=killer.team.color,
flash=True)
self._update_scoreboard()
# If someone has won, set a timer to end shortly.
# (allows the dust to clear and draws to occur if deaths are
# close enough)
assert self._score_to_win is not None
if any(team.score >= self._score_to_win for team in self.teams):
bs.timer(0.5, self.end_game)
else:
return super().handlemessage(msg)
return None
def _update_scoreboard(self) -> None:
for team in self.teams:
self._scoreboard.set_team_value(team, team.score,
self._score_to_win)
def end_game(self) -> None:
results = bs.GameResults()
self.delete_text_nodes()
for team in self.teams:
results.set_team_score(team, team.score)
self.end(results=results)
def delete_text_nodes(self):
self.canon.delete()
self.canon_.delete()
self.canon2.delete()
self.canon_2.delete()
self.curve.delete()
self.curve2.delete()
def _handle_canon_load_A(self):
try:
bomb = bs.getcollision().opposingnode.getdelegate(Bomb,True)
# pos=bomb.position
owner=bomb.owner
type=bomb.bomb_type
source_player=bomb.get_source_player(bs.Player)
bs.getcollision().opposingnode.delete()
# bomb.delete()
self.launch_bomb_byA(owner,type,source_player,2)
except bs.NotFoundError:
# This can happen if the flag stops touching us due to being
# deleted; that's ok.
return
def _handle_canon_load_B(self):
try:
bomb = bs.getcollision().opposingnode.getdelegate(Bomb,True)
# pos=bomb.position
owner=bomb.owner
type=bomb.bomb_type
source_player=bomb.get_source_player(bs.Player)
bs.getcollision().opposingnode.delete()
# bomb.delete()
self.launch_bomb_byB(owner,type,source_player,2)
except bs.NotFoundError:
# This can happen if the flag stops touching us due to being
# deleted; that's ok.
return
def launch_bomb_byA(self,owner,type,source_player,count):
if count>0:
y=random.randrange(2,9,2)
z=random.randrange(-4,6)
self.fake_explosion( (-5.708631629943848, 7.437141418457031, -4.525400638580322))
Bomb(position=(-6,7.5,-4),bomb_type=type,owner=owner,source_player=source_player,velocity=(19,y,z)).autoretain()
bs.timer(0.6,babase.Call(self.launch_bomb_byA,owner,type,source_player,count-1))
else:
return
def launch_bomb_byB(self,owner,type,source_player,count):
if count>0:
y=random.randrange(2,9,2)
z=random.randrange(-4,6)
self.fake_explosion( (5.708631629943848, 7.437141418457031, -4.525400638580322))
Bomb(position=(6,7.5,-4),bomb_type=type,owner=owner,source_player=source_player,velocity=(-19,y,z)).autoretain()
bs.timer(0.6,babase.Call(self.launch_bomb_byB,owner,type,source_player,count-1))
else:
return
def fake_explosion(self, position: Sequence[float]):
explosion = bs.newnode('explosion',
attrs={'position': position,
'radius': 1, 'big': False})
bs.timer(0.4, explosion.delete)
sounds = ['explosion0'+str(n) for n in range(1,6)]
sound = random.choice(sounds)
bs.getsound(sound).play()
def create_canon_A(self):
shared = SharedObjects.get()
canon_load_mat=bs.Material()
factory = BombFactory.get()
canon_load_mat.add_actions(
actions=(
('modify_part_collision', 'collide', False),
('modify_part_collision', 'physical', False)
))
canon_load_mat.add_actions(
conditions=('they_have_material', factory.bomb_material),
actions=(
('modify_part_collision', 'collide', True),
('modify_part_collision', 'physical', True),
('call','at_connect',babase.Call(self._handle_canon_load_A))
),
)
self.ud_1_r=bs.newnode('region',attrs={'position': (-8.908631629943848, 7.337141418457031, -4.525400638580322),'scale': (2,1,1),'type': 'box','materials': [canon_load_mat ]})
self.node = bs.newnode('shield',
delegate=self,
attrs={
'position':(-8.308631629943848, 7.337141418457031, -4.525400638580322),
'color': (0.3, 0.2, 2.8),
'radius': 1.3
})
self.canon=bs.newnode('text',
attrs={
'text': '___________',
'in_world': True,
'shadow': 1.0,
'flatness': 1.0,
'color':(0.3,0.3,0.8),
'scale':0.019,
'h_align': 'left',
'position':(-8.388631629943848, 7.837141418457031, -4.525400638580322)
})
self.canon_=bs.newnode('text',
attrs={
'text': '_________',
'in_world': True,
'shadow': 1.0,
'flatness': 1.0,
'color':(0.3,0.3,0.8),
'scale':0.019,
'h_align': 'left',
'position':(-7.888631629943848, 7.237141418457031, -4.525400638580322)
})
self.curve=bs.newnode('text',
attrs={
'text': '/\n',
'in_world': True,
'shadow': 1.0,
'flatness': 1.0,
'color':(0.3,0.3,0.8),
'scale':0.019,
'h_align': 'left',
'position':(-8.788631629943848, 7.237141418457031, -4.525400638580322)
})
def create_canon_B(self):
shared = SharedObjects.get()
canon_load_mat=bs.Material()
factory = BombFactory.get()
canon_load_mat.add_actions(
actions=(
('modify_part_collision', 'collide', False),
('modify_part_collision', 'physical', False)
))
canon_load_mat.add_actions(
conditions=('they_have_material', factory.bomb_material),
actions=(
('modify_part_collision', 'collide', True),
('modify_part_collision', 'physical', True),
('call','at_connect',babase.Call(self._handle_canon_load_B))
),
)
self.ud_1_r2=bs.newnode('region',attrs={'position': (8.908631629943848+0.81, 7.327141418457031, -4.525400638580322),'scale': (2,1,1),'type': 'box','materials': [canon_load_mat ]})
self.node2 = bs.newnode('shield',
delegate=self,
attrs={
'position':(8.308631629943848+0.81, 7.327141418457031, -4.525400638580322),
'color': (2.3, 0.2, 0.3),
'radius': 1.3
})
self.canon2=bs.newnode('text',
attrs={
'text': '___________',
'in_world': True,
'shadow': 1.0,
'flatness': 1.0,
'color':(0.8,0.3,0.3),
'scale':0.019,
'h_align': 'right',
'position':(8.388631629943848+0.81, 7.837141418457031, -4.525400638580322)
})
self.canon_2=bs.newnode('text',
attrs={
'text': '_________',
'in_world': True,
'shadow': 1.0,
'flatness': 1.0,
'color':(0.8,0.3,0.3),
'scale':0.019,
'h_align': 'right',
'position':(7.888631629943848+0.81, 7.237141418457031, -4.525400638580322)
})
self.curve2=bs.newnode('text',
attrs={
'text': '\\',
'in_world': True,
'shadow': 1.0,
'flatness': 1.0,
'color':(0.8,0.3,0.3),
'scale':0.019,
'h_align': 'right',
'position':(8.788631629943848+0.81, 7.237141418457031, -4.525400638580322)
})
def create_wall(self):
shared = SharedObjects.get()
factory = BombFactory.get()
mat=bs.Material()
mat.add_actions(
conditions=('they_have_material',shared.player_material),
actions=(
('modify_part_collision', 'collide', True),
('modify_part_collision','physical',True)
))
mat.add_actions(
conditions=(
('they_have_material',factory.bomb_material)),
actions=(
('modify_part_collision', 'collide', False)
))
self.wall=bs.newnode('region',attrs={'position': (0.61877517104148865, 4.312626838684082, -8.68477725982666),'scale': (3,7,27),'type': 'box','materials': [mat ]})

0
dist/ba_root/mods/maps/__init__.py vendored Normal file
View file

214
dist/ba_root/mods/maps/wooden_floor.py vendored Normal file
View file

@ -0,0 +1,214 @@
# Porting to api 8 made easier by baport.(https://github.com/bombsquad-community/baport)
from __future__ import annotations
from typing import TYPE_CHECKING
import babase
import bascenev1 as bs
from bascenev1lib.gameutils import SharedObjects
from bascenev1lib.actor.playerspaz import PlayerSpaz
import copy
if TYPE_CHECKING:
from typing import Any, List, Dict
class mapdefs:
points = {}
# noinspection PyDictCreation
boxes = {}
boxes['area_of_interest_bounds'] = (0.0, 1.185751251, 0.4326226188) + (
0.0, 0.0, 0.0) + (29.8180273, 11.57249038, 18.89134176)
boxes['edge_box'] = (-0.103873591, 0.4133341891, 0.4294651013) + (
0.0, 0.0, 0.0) + (22.48295719, 1.290242794, 8.990252454)
points['ffa_spawn1'] = (-0.08015551329, 0.02275111462,
-4.373674593) + (8.895057015, 1.0, 0.444350722)
points['ffa_spawn2'] = (-0.08015551329, 0.02275111462,
4.076288941) + (8.895057015, 1.0, 0.444350722)
points['flag1'] = (-10.99027878, 0.05744967453, 0.1095578275)
points['flag2'] = (11.01486398, 0.03986567039, 0.1095578275)
points['flag_default'] = (-0.1001374046, 0.04180340146, 0.1095578275)
boxes['goal1'] = (12.22454533, 1.0,
0.1087926362) + (0.0, 0.0, 0.0) + (2.0, 2.0, 12.97466313)
boxes['goal2'] = (-12.15961605, 1.0,
0.1097860203) + (0.0, 0.0, 0.0) + (2.0, 2.0, 13.11856424)
boxes['map_bounds'] = (0.0, 1.185751251, 0.4326226188) + (0.0, 0.0, 0.0) + (
42.09506485, 22.81173179, 29.76723155)
points['powerup_spawn1'] = (5.414681236, 0.9515026107, -5.037912441)
points['powerup_spawn2'] = (-5.555402285, 0.9515026107, -5.037912441)
points['powerup_spawn3'] = (5.414681236, 0.9515026107, 5.148223181)
points['powerup_spawn4'] = (-5.737266365, 0.9515026107, 5.148223181)
points['spawn1'] = (-10.03866341, 0.02275111462, 0.0) + (0.5, 1.0, 4.0)
points['spawn2'] = (9.823107149, 0.01092306765, 0.0) + (0.5, 1.0, 4.0)
points['tnt1'] = (-0.08421587483, 0.9515026107, -0.7762602271)
class WoodenFloor(bs.Map):
"""Stadium map for football games."""
defs = mapdefs
defs.points['spawn1'] = (-12.03866341, 0.02275111462, 0.0) + (0.5, 1.0, 4.0)
defs.points['spawn2'] = (12.823107149, 0.01092306765, 0.0) + (0.5, 1.0, 4.0)
name = 'Wooden Floor'
@classmethod
def get_play_types(cls) -> list[str]:
"""Return valid play types for this map."""
return ['melee', 'football', 'team_flag', 'keep_away']
@classmethod
def get_preview_texture_name(cls) -> str:
return 'footballStadiumPreview'
@classmethod
def on_preload(cls) -> Any:
data: dict[str, Any] = {
'mesh_bg': bs.getmesh('doomShroomBG'),
'bg_vr_fill_mesh': bs.getmesh('natureBackgroundVRFill'),
'collision_mesh': bs.getcollisionmesh('bridgitLevelCollide'),
'tex': bs.gettexture('bridgitLevelColor'),
'mesh_bg_tex': bs.gettexture('doomShroomBGColor'),
'collide_bg': bs.getcollisionmesh('natureBackgroundCollide'),
'railing_collision_mesh':
(bs.getcollisionmesh('bridgitLevelRailingCollide')),
'bg_material': bs.Material()
}
data['bg_material'].add_actions(actions=('modify_part_collision',
'friction', 10.0))
return data
def __init__(self) -> None:
super().__init__()
shared = SharedObjects.get()
self.background = bs.newnode(
'terrain',
attrs={
'mesh': self.preloaddata['mesh_bg'],
'lighting': False,
'background': True,
'color_texture': self.preloaddata['mesh_bg_tex']
})
bs.newnode('terrain',
attrs={
'mesh': self.preloaddata['bg_vr_fill_mesh'],
'lighting': False,
'vr_only': True,
'background': True,
'color_texture': self.preloaddata['mesh_bg_tex']
})
gnode = bs.getactivity().globalsnode
gnode.tint = (1.3, 1.2, 1.0)
gnode.ambient_color = (1.3, 1.2, 1.0)
gnode.vignette_outer = (0.57, 0.57, 0.57)
gnode.vignette_inner = (0.9, 0.9, 0.9)
gnode.vr_camera_offset = (0, -0.8, -1.1)
gnode.vr_near_clip = 0.5
# self.map_extend()
def is_point_near_edge(self,
point: babase.Vec3,
running: bool = False) -> bool:
box_position = self.defs.boxes['edge_box'][0:3]
box_scale = self.defs.boxes['edge_box'][6:9]
xpos = (point.x - box_position[0]) / box_scale[0]
zpos = (point.z - box_position[2]) / box_scale[2]
return xpos < -0.5 or xpos > 0.5 or zpos < -0.5 or zpos > 0.5
def map_extend(self):
pass
def ground(self):
shared = SharedObjects.get()
self._real_wall_material=bs.Material()
self._real_wall_material.add_actions(
actions=(
('modify_part_collision', 'collide', True),
('modify_part_collision', 'physical', True)
))
self.mat = bs.Material()
self.mat.add_actions(
actions=( ('modify_part_collision','physical',False),
('modify_part_collision','collide',False))
)
spaz_collide_mat=bs.Material()
spaz_collide_mat.add_actions(
conditions=('they_have_material',shared.player_material),
actions=(
('modify_part_collision', 'collide', True),
( 'call','at_connect',babase.Call(self._handle_player_collide )),
),
)
pos=(0,0.1,-5)
self.main_region=bs.newnode('region',attrs={'position': pos,'scale': (21,0.001,20),'type': 'box','materials': [shared.footing_material,self._real_wall_material,spaz_collide_mat]})
def create_ramp_111(self,x,z):
shared = SharedObjects.get()
self._real_wall_material=bs.Material()
self._real_wall_material.add_actions(
actions=(
('modify_part_collision', 'collide', True),
('modify_part_collision', 'physical', True)
))
self.mat = bs.Material()
self.mat.add_actions(
actions=( ('modify_part_collision','physical',False),
('modify_part_collision','collide',False))
)
spaz_collide_mat=bs.Material()
pos=(x,0,z)
ud_1_r=bs.newnode('region',attrs={'position': pos,'scale': (1.5,1,1.5),'type': 'box','materials': [shared.footing_material,self._real_wall_material ]})
node = bs.newnode('prop',
owner=ud_1_r,
attrs={
'mesh':bs.getmesh('image1x1'),
'light_mesh':bs.getmesh('powerupSimple'),
'position':(2,7,2),
'body':'puck',
'shadow_size':0.0,
'velocity':(0,0,0),
'color_texture':bs.gettexture('tnt'),
'mesh_scale':1.5,
'reflection_scale':[1.5],
'materials':[self.mat, shared.object_material,shared.footing_material],
'density':9000000000
})
mnode = bs.newnode('math',
owner=ud_1_r,
attrs={
'input1': (0, 0.6, 0),
'operation': 'add'
})
node.changerotation(1,0,0)
ud_1_r.connectattr('position', mnode, 'input2')
mnode.connectattr('output', node, 'position')
def _handle_player_collide(self):
try:
player = bs.getcollision().opposingnode.getdelegate(
PlayerSpaz, True)
except bs.NotFoundError:
return
if player.is_alive():
player.shatter(True)
bs._map.register_map(WoodenFloor)