Update VolleyBall.py to 1.7

- Code cleanup
- No longer requires a plugin
- More accurate Goal positions
This commit is contained in:
Freaku17 2022-07-30 21:52:04 +05:30 committed by GitHub
parent f5fd4eb2a3
commit 49cd2b997b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,27 +1,25 @@
from __future__ import annotations
# Volley Ball (final)
#Volley Ball (updated)
#Made for 1.6 by your friend: @[Just] Freak#4999 / Freaku
"""Defines Volley Ball mini-game"""
# Made by your friend: Freaku / @[Just] Freak#4999
## This thing was originally made for 1.4 by someone (but had errors/bugs/missing features) so I edited/ported to 1.6/added all useful features :D
## I suggest to join this discord servers:
## https://discord.gg/ucyaesh
## https://discord.gg/NCvfPG2N9A
# Join BCS:
# https://discord.gg/ucyaesh
## Made on Android with the help of Terminal.py
## https://github.com/Freaku17/BombSquad-Mods-byFreaku/blob/main/Utilities/Terminal.py
## MY (Freak's) comments are double-tagged btw ##
# My GitHub:
# https://github.com/Freaku17/BombSquad-Mods-byFreaku
## UPDATED:
# CHANGELOG:
"""
## 2021
- Fixed Puck's mass/size/positions/texture/effects
- Fixed Goal positions
- Better center wall
@ -29,10 +27,15 @@ from __future__ import annotations
- Added more customisable options
- Map lights locators are now looped (thus reducing the size of the file and lengthy work...)
- Merged map & minigame in one file
- Puck spawns according to scored team (if right team scored, ball will spawn on left side)
- Puck spawns according to scored team
- Also puck now spawns in airrr
- Server support added :)
- Fixed **LOTS** of errors/bugs
## 2022
- Code cleanup
- No longer requires a plugin
- More accurate Goal positions
"""
@ -44,14 +47,17 @@ from __future__ import annotations
# ba_meta require api 6
# ba_meta require api 7
from __future__ import annotations
from typing import TYPE_CHECKING
import bastd, _ba, ba, random
import _ba, ba, random
from bastd.actor.playerspaz import PlayerSpaz
from bastd.actor.scoreboard import Scoreboard
from bastd.actor.powerupbox import PowerupBoxFactory
from bastd.actor.bomb import BombFactory
from bastd.gameutils import SharedObjects
if TYPE_CHECKING:
@ -67,15 +73,13 @@ class PuckDiedMessage:
class Puck(ba.Actor):
"""A lovely giant hockey puck."""
def __init__(self, position: Sequence[float] = (0.0, 1.0, 0.0)):
super().__init__()
shared = SharedObjects.get()
activity = self.getactivity()
# Spawn just above the provided point.
self._spawn_pos = (position[0], position[1] + 1.8, position[2])
self._spawn_pos = (position[0], position[1] + 1.05, position[2])
self.last_players_to_touch: Dict[int, Player] = {}
self.scored = False
assert activity is not None
@ -97,14 +101,11 @@ class Puck(ba.Actor):
'materials': pmats
})
## Since it rolls on spawn, lets make gravity
## to 0, and when another node (bomb/spaz)
## touches it. It'll act back as our normie puck!
ba.animate(self.node, 'gravity_scale', {0:-0.1, 2:1}, False)
## When other node touches, it realises its new gravity_scale
## Jugad for now...
# Since it rolls on spawn, lets make gravity
# to 0, and when another node (bomb/spaz)
# touches it. It'll act back as our normie puck!
ba.animate(self.node, 'gravity_scale', {0:-0.1, 0.2:1}, False)
# When other node touches, it realises its new gravity_scale
def handlemessage(self, msg: Any) -> Any:
@ -147,17 +148,14 @@ class Player(ba.Player['Team']):
class Team(ba.Team[Player]):
"""Our team type for this game."""
def __init__(self) -> None:
self.score = 0
# ba_meta export game
class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
"""Volley Ball game."""
name = 'Volley Ball'
description = 'Score some goals.\nbyFREAK'
description = 'Score some goals.\nby \ue048Freaku'
available_settings = [
ba.IntSetting(
'Score to Win',
@ -203,7 +201,7 @@ class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
@classmethod
def get_supported_maps(cls, sessiontype: Type[ba.Session]) -> List[str]:
return ['Open Field','Closed Arena']
return ['Open Field', 'Closed Arena']
def __init__(self, settings: dict):
super().__init__(settings)
@ -283,7 +281,7 @@ class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
('modify_part_collision', 'friction', 9999.5),
))
self._wall_material.add_actions(
conditions=('they_have_material', bastd.actor.bomb.BombFactory.get().blast_material),
conditions=('they_have_material', BombFactory.get().blast_material),
actions=(
('modify_part_collision', 'collide', False),
('modify_part_collision', 'physical', False)
@ -358,20 +356,17 @@ class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
self.setup_standard_time_limit(self._time_limit)
if self._night_mode:
ba.getactivity().globalsnode.tint = (0.5, 0.7, 1)
else:
pass
self._puck_spawn_pos = self.map.get_flag_position(None)
self._spawn_puck()
# Set up the two score regions.
defs = self.map.defs
self._score_regions = []
self._score_regions.append(
ba.NodeActor(
ba.newnode('region',
attrs={
'position':(5,0,0),
'scale': defs.boxes['goal1'],
'position':(5.7, 0, -0.065),
'scale': (10.7, 0.001, 8),
'type': 'box',
'materials': [self._score_region_material]
})))
@ -379,17 +374,17 @@ class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
ba.NodeActor(
ba.newnode('region',
attrs={
'position':(-5,0,0),
'scale': defs.boxes['goal2'],
'position':(-5.7, 0, -0.065),
'scale': (10.7, 0.001, 8),
'type': 'box',
'materials': [self._score_region_material]
})))
self._update_scoreboard()
ba.playsound(self._chant_sound)
import base64
exec(base64.b64decode("aWYgc2VsZi5jcmVkaXRfdGV4dDoKICAgICMjIFBlb3BsZSBzdGVhbGVkIGNyZWRpdHMgc28gdGhhdHMgd2h5IEkgZW5jb2RlZCB0aGlzLi4uCiAgICAjIyBFdmVuIHRobyB0aGVyZSBpcyBhIG9wdGlvbiwgdGhleSBjaGFuZ2VkIGNyZWF0ZWQgYnkKICAgICMjIGxpa2Ugd3RmIGlzIHRoaWVyIHByb2JsZW0/PwogICAgCiAgICAjIyBBbnl3YXlzIGhhdmUgYSBnb29kIGRheSEKICAgIHQgPSBiYS5uZXdub2RlKCd0ZXh0JywKICAgICAgICAgICAgICAgYXR0cnM9eyAndGV4dCc6IkNyZWF0ZWQgYnkg7oCgRlJFw4JLL+6BiEZyZWFrdVxuVm9sbGV5QmFsbCAxLjYiLCAjIyBEaXNhYmxlICdFbmFibGUgQm90dG9tIENyZWRpdHMnIHdoZW4gbWFraW5nIHBsYXlsaXN0LCBObyBuZWVkIHRvIGVkaXQgdGhpcyBsb3ZlbH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nbic6J2NlbnRlcicsCiAgICAgICAgJ3ZfYXR0YWNoJzonYm90dG9tJ30p").decode('UTF-8'))
shared = SharedObjects.get()
self.blocks.append(ba.NodeActor(ba.newnode('region',attrs={'position': (0,2.4,0),'scale': (1,6,20),'type': 'box','materials': (self._fake_wall_material, )})))
self.blocks.append(ba.NodeActor(ba.newnode('region',attrs={'position': (0,2.4,0),'scale': (0.8,6,20),'type': 'box','materials': (self._fake_wall_material, )})))
self.net_blocc.append(ba.NodeActor(ba.newnode('region',attrs={'position': (0,0,0),'scale': (0.6,2.4,20),'type': 'box','materials': (self._net_wall_material, )})))
@ -412,8 +407,6 @@ class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
self._puck = None
def _handle_score(self) -> None:
"""A point has been scored."""
assert self._puck is not None
assert self._score_regions is not None
@ -435,14 +428,14 @@ class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
## Spawn puck on opponent's Area
# Change puck Spawn
if team.id == 0: # left side scored
self._puck_spawn_pos= (5, -0.3, 0)
self._puck_spawn_pos= (5, 0.42, 0)
elif team.id == 1: # right side scored
self._puck_spawn_pos= (-5, -0.3, 0)
else: # incase, this dude is oversmart and using 3+ teams...
self._puck_spawn_pos= (0, 0.2, 0)
## Easy pizzy
self._puck_spawn_pos= (-5, 0.42, 0)
else: # normally shouldn't occur
self._puck_spawn_pos= (0, 0.42, 0)
# Easy pizzy
for player in team.players:
@ -486,8 +479,6 @@ class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
activity = ba.getactivity()
if self._icy_flooor:
activity.map.is_hockey = True
else:
return
def _update_scoreboard(self) -> None:
winscore = self._score_to_win
@ -499,9 +490,9 @@ class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
spaz = self.spawn_player_spaz(player)
if self._bombies_:
## We wantthe button to work, justno bombs...
# We want the button to work, just no bombs...
spaz.bomb_count = 0
## Imagine not being able to swipe those colorful buttons ;(
# Imagine not being able to swipe those colorful buttons ;(
if self._punchie_:
@ -525,7 +516,7 @@ class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
super().handlemessage(msg)
def _flash_puck_spawn(self) -> None:
## Effect >>>>>> Flashly
# Effect >>>>>> Flashly
ba.emitfx(position= self._puck_spawn_pos, count=int(6.0 + 7.0 * 12), scale=1.7, spread=0.4, chunk_type='spark')
def _spawn_puck(self) -> None:
@ -536,8 +527,6 @@ class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
self._puck = Puck(position=self._puck_spawn_pos)
## Can be done:
# Add a return timer and reset it when ball goes from one area to other (i.e Left/Right) To avoid people camping with the Ball in thier own area...
@ -556,63 +545,33 @@ class VolleyBallGame(ba.TeamGameActivity[Player, Team]):
####### DONT DIE READING THIS #########
## The reason I made maps differently (instead of keeping it in minigame only) was to avoid getting some jittery starts... ##
a=0.0
class Pointzz:
points, boxes = {}, {}
points['ffa_spawn1'] = (-0.08016, 0.02275, -4.37367) + (8.89506, 0.05, 0.44435)
points['ffa_spawn2'] = (-0.08016, 0.02275, 4.07629) + (8.89506, 0.05, 0.44435)
points['flag1'] = (-10.72073, 0.06537, 0.14648)
points['flag2'] = (10.7587, 0.04779, 0.14648)
points['flag_default'] = (-0.10014, 0.0418, 0.10956)
points['powerup_spawn1'] = (500000000.41468, 50000.9515, -500000.03791)
points['powerup_spawn2'] = (-500000.5554, 500000.9515, -500000.03791)
points['powerup_spawn3'] = (500000.41468, 50000.9515, 5000.14822)
points['powerup_spawn4'] = (-50000.73727, 50000.9515, 500.14822)
points['spawn1'] = (-8.03866, 0.02275, 0.0) + (0.5, 0.05, 4.0)
points['spawn2'] = (8.82311, 0.01092, 0.0) + (0.5, 0.05, 4.0)
boxes['area_of_interest_bounds'] = (0.0, 1.18575, 0.43262) + (0, 0, 0) + (29.81803, 11.57249, 18.89134)
boxes['tnt1'] = (-0.10387, 0.41333, 0.42947) + (0, 0, 0) + (22.48296, 1.29024, 8.99025)
boxes['goal1'] = (10,0.001,8)
boxes['goal2'] = (10,0.001,8)
boxes['map_bounds'] = (0.0, 1.185751251, 0.4326226188) + (0.0, 0.0, 0.0) + (
points, boxes = {}, {}
points['spawn1'] = (-8.03866, 0.02275, 0.0) + (0.5, 0.05, 4.0)
points['spawn2'] = (8.82311, 0.01092, 0.0) + (0.5, 0.05, 4.0)
boxes['area_of_interest_bounds'] = (0.0, 1.18575, 0.43262) + (0, 0, 0) + (29.81803, 11.57249, 18.89134)
boxes['map_bounds'] = (0.0, 1.185751251, 0.4326226188) + (0.0, 0.0, 0.0) + (
42.09506485, 22.81173179, 29.76723155)
class PointzzforH:
points, boxes = {}, {}
boxes['area_of_interest_bounds'] = (0.0, 0.7956858119, 0.0) + (
0.0, 0.0, 0.0) + (30.80223883, 0.5961646365, 13.88431707)
points['ffa_spawn1'] = (-0.001925625146, 0.02305323209,
-3.81971842) + (7.828121539, 1.0, 0.1588021252)
points['ffa_spawn2'] = (-0.001925625146, 0.02305323209,
3.560115735) + (7.828121539, 1.0, 0.05859841271)
points['flag1'] = (-11.21689747, 0.09527878981, -0.07659307272)
points['flag2'] = (11.08204909, 0.04119542459, -0.07659307272)
points['flag_default'] = (-0.01690735171, 0.06139940044, -0.07659307272)
boxes['goal1'] = (10,0.001,8)
boxes['goal2'] = (10,0.001,8)
boxes['area_of_interest_bounds'] = (0.0, 0.7956858119, 0.0) + (0.0, 0.0, 0.0) + (30.80223883, 0.5961646365, 13.88431707)
boxes['map_bounds'] = (0.0, 0.7956858119, -0.4689020853) + (0.0, 0.0, 0.0) + (
35.16182389, 12.18696164, 21.52869693)
points['powerup_spawn1'] = (-3.654355317, 1.080990833, -4.765886164)
points['powerup_spawn2'] = (-3.654355317, 1.080990833, 4.599802158)
points['powerup_spawn3'] = (2.881071011, 1.080990833, -4.765886164)
points['powerup_spawn4'] = (2.881071011, 1.080990833, 4.599802158)
points['spawn1'] = (-6.835352227, 0.02305323209, 0.0) + (1.0, 1.0, 3.0)
points['spawn2'] = (6.857415055, 0.03938567998, 0.0) + (1.0, 1.0, 3.0)
points['tnt1'] = (-0.05791962398, 1.080990833, -4.765886164)
class VolleyBallMap(ba.Map):
from VolleyBall import Pointzz as defs
defs = Pointzz()
name = "Open Field"
@classmethod
def get_play_types(cls) -> List[str]:
"""Return valid play types for this map."""
return []
@classmethod
@ -632,10 +591,6 @@ class VolleyBallMap(ba.Map):
def __init__(self):
super().__init__()
shared = SharedObjects.get()
x = -5
while x<5:
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(0,0,x),
@ -649,15 +604,7 @@ class VolleyBallMap(ba.Map):
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(0,1,x),
'color':(1,1,0),'opacity':1,'draw_beauty':True,'additive':False,'size':[0.40]})
x = x + 0.5
y = -1
while y>-11:
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(y,0.01,4),
@ -669,9 +616,7 @@ class VolleyBallMap(ba.Map):
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(-y,0.01,-4),
'color':(1,0,0),'opacity':1,'draw_beauty':True,'additive':False,'size':[0.40]})
y-=1
z = 0
while z<5:
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(11,0.01,z),
@ -683,9 +628,7 @@ class VolleyBallMap(ba.Map):
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(-11,0.01,-z),
'color':(0,0,1),'opacity':1,'draw_beauty':True,'additive':False,'size':[0.40]})
z+=1
self.node = ba.newnode(
'terrain',
delegate=self,
@ -711,24 +654,14 @@ class VolleyBallMap(ba.Map):
gnode.vr_camera_offset = (0, -0.8, -1.1)
gnode.vr_near_clip = 0.5
def is_point_near_edge(self,
point: ba.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
class VolleyBallMapH(ba.Map):
"""Stadium map used for ice hockey games."""
from VolleyBall import PointzzforH as defs
defs = PointzzforH()
name = 'Closed Arena'
@classmethod
def get_play_types(cls) -> List[str]:
"""Return valid play types for this map."""
return []
@classmethod
@ -752,9 +685,6 @@ class VolleyBallMapH(ba.Map):
def __init__(self) -> None:
super().__init__()
shared = SharedObjects.get()
x = -5
while x<5:
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(0,0,x),
@ -768,15 +698,7 @@ class VolleyBallMapH(ba.Map):
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(0,1,x),
'color':(1,1,0),'opacity':1,'draw_beauty':True,'additive':False,'size':[0.40]})
x = x + 0.5
y = -1
while y>-11:
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(y,0.01,4),
@ -788,9 +710,7 @@ class VolleyBallMapH(ba.Map):
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(-y,0.01,-4),
'color':(1,0,0),'opacity':1,'draw_beauty':True,'additive':False,'size':[0.40]})
y-=1
z = 0
while z<5:
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(11,0.01,z),
@ -802,16 +722,14 @@ class VolleyBallMapH(ba.Map):
self.zone = ba.newnode('locator',attrs={'shape':'circle','position':(-11,0.01,-z),
'color':(0,0,1),'opacity':1,'draw_beauty':True,'additive':False,'size':[0.40]})
z+=1
self.node = ba.newnode('terrain',
delegate=self,
attrs={
'model':
None,
'collide_model':
ba.getcollidemodel('footballStadiumCollide'), ## we dont want Goalposts...
ba.getcollidemodel('footballStadiumCollide'), # we dont want Goalposts...
'color_texture':
self.preloaddata['tex'],
'materials': [
@ -857,10 +775,7 @@ class VolleyBallMapH(ba.Map):
#self.is_hockey = True
## Plugin only for our dirty map UwU ##
# ba_meta export plugin
class byFreaku(ba.Plugin):
def on_app_launch(self):
ba._map.register_map(VolleyBallMap)
ba._map.register_map(VolleyBallMapH)
ba._map.register_map(VolleyBallMap)
ba._map.register_map(VolleyBallMapH)