Needs some testing

This commit is contained in:
brostosjoined 2024-01-17 23:09:18 +03:00
parent 1bce1d7d76
commit 4719c3e718
23 changed files with 2124 additions and 1626 deletions

View file

@ -1,6 +1,7 @@
# Porting to api 8 made easier by baport.(https://github.com/bombsquad-community/baport)
# SimonSays
# you had really better do what Simon says...
# ba_meta require api 7
# ba_meta require api 8
from __future__ import annotations
from typing import TYPE_CHECKING
@ -8,19 +9,21 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Any, Union, Sequence
from ba import _gameutils
import ba
from bascenev1 import _gameutils
import babase
import bauiv1 as bui
import bascenev1 as bs
import random
class CustomText(ba.Actor):
class CustomText(bs.Actor):
"""Text that pops up above a position to denote something special.
category: Gameplay Classes
"""
def __init__(self,
text: Union[str, ba.Lstr],
text: Union[str, babase.Lstr],
position: Sequence[float] = (0.0, 0.0, 0.0),
color: Sequence[float] = (1.0, 1.0, 1.0, 1.0),
random_offset: float = 0.5,
@ -34,7 +37,7 @@ class CustomText(ba.Actor):
(0.5 - random.random()), position[1] + offset[0] +
random_offset * (0.5 - random.random()), position[2] +
offset[0] + random_offset * (0.5 - random.random()))
self.node = ba.newnode('text',
self.node = bs.newnode('text',
attrs={
'text': text,
'in_world': True,
@ -42,27 +45,27 @@ class CustomText(ba.Actor):
'flatness': 1.0,
'h_align': 'center'}, delegate=self)
lifespan = duration
ba.animate(
bs.animate(
self.node, 'scale', {
0: 0.0,
lifespan * 0.11: 0.020 * 0.7 * scale,
lifespan * 0.16: 0.013 * 0.7 * scale,
lifespan * 0.25: 0.014 * 0.7 * scale
})
self._tcombine = ba.newnode('combine',
self._tcombine = bs.newnode('combine',
owner=self.node,
attrs={
'input0': pos[0],
'input2': pos[2],
'size': 3
})
ba.animate(self._tcombine, 'input1', {
bs.animate(self._tcombine, 'input1', {
0: pos[1] + 1.5,
lifespan: pos[1] + 2.0
})
self._tcombine.connectattr('output', self.node, 'position')
# fade our opacity in/out
self._combine = ba.newnode('combine',
self._combine = bs.newnode('combine',
owner=self.node,
attrs={
'input0': color[0],
@ -71,64 +74,64 @@ class CustomText(ba.Actor):
'size': 4
})
for i in range(4):
ba.animate(
bs.animate(
self._combine, 'input' + str(i), {
0.13 * lifespan: color[i],
0.18 * lifespan: 4.0 * color[i],
0.22 * lifespan: color[i]})
ba.animate(self._combine, 'input3', {
bs.animate(self._combine, 'input3', {
0: 0,
0.1 * lifespan: color[3],
0.7 * lifespan: color[3],
lifespan: 0})
self._combine.connectattr('output', self.node, 'color')
self._die_timer = ba.Timer(
lifespan, ba.WeakCall(self.handlemessage, ba.DieMessage()))
self._die_timer = bs.Timer(
lifespan, bs.WeakCall(self.handlemessage, bs.DieMessage()))
def handlemessage(self, msg: Any) -> Any:
assert not self.expired
if isinstance(msg, ba.DieMessage):
if isinstance(msg, bs.DieMessage):
if self.node:
self.node.delete()
else:
super().handlemessage(msg)
class Player(ba.Player['Team']):
class Player(bs.Player['Team']):
"""Our player type for this game."""
def __init__(self) -> None:
self.score = 0
class Team(ba.Team[Player]):
class Team(bs.Team[Player]):
"""Our team type for this game."""
def __init__(self) -> None:
self.score = 0
# ba_meta export game
# ba_meta export bascenev1.GameActivity
class SimonSays(ba.TeamGameActivity[Player, Team]):
class SimonSays(bs.TeamGameActivity[Player, Team]):
name = "Simon Says"
description = "You have to better do what Simon says!"
@classmethod
def get_available_settings(cls, sessiontype: Type[ba.Session]) -> List[ba.Setting]:
def get_available_settings(cls, sessiontype: Type[bs.Session]) -> List[babase.Setting]:
settings = [
ba.BoolSetting("Epic Mode", default=False),
ba.BoolSetting("Enable Jumping", default=False),
ba.BoolSetting("Enable Punching", default=False),
ba.BoolSetting("Enable Picking Up", default=False),
ba.IntChoiceSetting("Timer Speed",
bs.BoolSetting("Epic Mode", default=False),
bs.BoolSetting("Enable Jumping", default=False),
bs.BoolSetting("Enable Punching", default=False),
bs.BoolSetting("Enable Picking Up", default=False),
bs.IntChoiceSetting("Timer Speed",
choices=[("Snaily", 1200),
("Slow", 900),
("Normal", 655),
("Fast", 544),
("Turbo", 460)], default=655),
ba.FloatChoiceSetting("Text Duration",
bs.FloatChoiceSetting("Text Duration",
choices=[("Slow", 2.5),
("Normal", 1.5),
("Mediocre", 1.0),
@ -136,12 +139,12 @@ class SimonSays(ba.TeamGameActivity[Player, Team]):
return settings
@classmethod
def get_supported_maps(cls, sessiontype: Type[ba.Session]) -> List[str]:
def get_supported_maps(cls, sessiontype: Type[bs.Session]) -> List[str]:
return ["Courtyard"]
@classmethod
def supports_session_type(cls, sessiontype: Type[ba.Session]) -> bool:
return issubclass(sessiontype, ba.FreeForAllSession)
def supports_session_type(cls, sessiontype: Type[bs.Session]) -> bool:
return issubclass(sessiontype, bs.FreeForAllSession)
def __init__(self, settings: dict):
super().__init__(settings)
@ -157,7 +160,7 @@ class SimonSays(ba.TeamGameActivity[Player, Team]):
self.counter_loop = None
self.time = 5000
self._r1 = 2
self.ct_text = ba.newnode('text', attrs={
self.ct_text = bs.newnode('text', attrs={
'in_world': True,
'text': '......',
'shadow': 1.0,
@ -165,44 +168,44 @@ class SimonSays(ba.TeamGameActivity[Player, Team]):
'flatness': 0.5,
'position': (-5.627144702, 3.3275475, -9.572879116),
'scale': 0.05})
self.n1 = ba.newnode('locator', attrs={'shape': 'circle', 'position': (-4, 0, -6),
self.n1 = bs.newnode('locator', attrs={'shape': 'circle', 'position': (-4, 0, -6),
'color': (1, 0, 0), 'opacity': 0.5,
'draw_beauty': True, 'additive': True})
self.n2 = ba.newnode('locator', attrs={'shape': 'circle', 'position': (0, 0, -6),
self.n2 = bs.newnode('locator', attrs={'shape': 'circle', 'position': (0, 0, -6),
'color': (0, 1, 0), 'opacity': 0.5,
'draw_beauty': True, 'additive': True})
self.n3 = ba.newnode('locator', attrs={'shape': 'circle', 'position': (4, 0, -6),
self.n3 = bs.newnode('locator', attrs={'shape': 'circle', 'position': (4, 0, -6),
'color': (0, 0, 1), 'opacity': 0.5,
'draw_beauty': True, 'additive': True})
self.n4 = ba.newnode('locator', attrs={'shape': 'circle', 'position': (-4, 0, -2),
self.n4 = bs.newnode('locator', attrs={'shape': 'circle', 'position': (-4, 0, -2),
'color': (1, 1, 0), 'opacity': 0.5,
'draw_beauty': True, 'additive': True})
self.n5 = ba.newnode('locator', attrs={'shape': 'circle', 'position': (0, 0, -2),
self.n5 = bs.newnode('locator', attrs={'shape': 'circle', 'position': (0, 0, -2),
'color': (0, 1, 1), 'opacity': 0.5,
'draw_beauty': True, 'additive': True})
self.n6 = ba.newnode('locator', attrs={'shape': 'circle', 'position': (4, 0, -2),
self.n6 = bs.newnode('locator', attrs={'shape': 'circle', 'position': (4, 0, -2),
'color': (1, 0, 1), 'opacity': 0.5,
'draw_beauty': True, 'additive': True})
self.n7 = ba.newnode('locator', attrs={'shape': 'circle', 'position': (-4, 0, 2),
self.n7 = bs.newnode('locator', attrs={'shape': 'circle', 'position': (-4, 0, 2),
'color': (.5, .5, .5), 'opacity': 0.5,
'draw_beauty': True, 'additive': True})
self.n8 = ba.newnode('locator', attrs={'shape': 'circle', 'position': (0, 0, 2),
self.n8 = bs.newnode('locator', attrs={'shape': 'circle', 'position': (0, 0, 2),
'color': (.5, .325, 0), 'opacity': 0.5,
'draw_beauty': True, 'additive': True})
self.n9 = ba.newnode('locator', attrs={'shape': 'circle', 'position': (4, 0, 2),
self.n9 = bs.newnode('locator', attrs={'shape': 'circle', 'position': (4, 0, 2),
'color': (1, 1, 1), 'opacity': 0.5,
'draw_beauty': True, 'additive': True})
self.options = ["red", "green", "blue", "yellow", "teal", "purple", "gray", "orange",
"white", "top", "bottom", "middle row", "left", "right", "center column", "outside"]
self.default_music = ba.MusicType.FLAG_CATCHER
self.default_music = bs.MusicType.FLAG_CATCHER
def get_instance_description(self) -> str:
return 'Follow the commands... but only when \"Simon says!"'
def on_player_join(self, player: Player) -> None:
if self.has_begun():
ba.screenmessage(
ba.Lstr(resource='playerDelayedJoinText',
bs.broadcastmessage(
babase.Lstr(resource='playerDelayedJoinText',
subs=[('${PLAYER}', player.getname(full=True))]),
color=(0, 1, 0),)
return
@ -227,11 +230,11 @@ class SimonSays(ba.TeamGameActivity[Player, Team]):
player.score = 0
# check for immediate end if theres only 1 player
if len(self.players) == 1:
ba.timer(4000, lambda: self.check_end(), timeformat=ba.TimeFormat.MILLISECONDS)
bs.timer(4000/1000, lambda: self.check_end())
else:
ba.timer(6000, self.call_round, timeformat=ba.TimeFormat.MILLISECONDS)
bs.timer(6000/1000, self.call_round)
def spawn_player(self, player: PlayerType) -> ba.Actor:
def spawn_player(self, player: PlayerT) -> bs.Actor:
assert player
spaz = self.spawn_player_spaz(player, position=(
0 + random.uniform(-3.6, 3.6), 2.9, -2 + random.uniform(-3.6, 3.6)))
@ -291,12 +294,11 @@ class SimonSays(ba.TeamGameActivity[Player, Team]):
self.string = "0"
self.ct_text.text = self.string
self.counter_loop = None
ba.timer(1, dummy_check, timeformat=ba.TimeFormat.MILLISECONDS)
bs.timer(1/1000, dummy_check)
else:
self.ct_text.text = str(self.now)
ba.playsound(ba.getsound('tick'))
self.counter_loop = ba.Timer(self.speed, set_counter,
timeformat=ba.TimeFormat.MILLISECONDS, repeat=True)
bs.getsound('tick').play()
self.counter_loop = bs.Timer(self.speed/1000, set_counter, repeat=True)
def check_round(self) -> None:
if self.ended:
@ -307,8 +309,8 @@ class SimonSays(ba.TeamGameActivity[Player, Team]):
player.actor.node.position_center) else False
if ((self.simon and safe == False) or ((not self.simon) and safe == True)):
player.team.score = self.round_num
player.actor.handlemessage(ba.DieMessage())
ba.timer(1633, self.call_round, timeformat=ba.TimeFormat.MILLISECONDS)
player.actor.handlemessage(bs.DieMessage())
bs.timer(1633/1000, self.call_round)
def in_circle(self, pos) -> None:
circles = []
@ -349,14 +351,14 @@ class SimonSays(ba.TeamGameActivity[Player, Team]):
return circles
def handlemessage(self, msg) -> None:
if isinstance(msg, ba.PlayerDiedMessage):
if isinstance(msg, bs.PlayerDiedMessage):
self.check_end()
else:
super().handlemessage(msg)
def end_game(self) -> None:
self.ended = True
results = ba.GameResults()
results = bs.GameResults()
for team in self.teams:
results.set_team_score(team, team.score)
self.end(results=results)
@ -367,4 +369,4 @@ class SimonSays(ba.TeamGameActivity[Player, Team]):
if player.is_alive():
i += 1
if i <= 2:
ba.timer(0.6, lambda: self.end_game())
bs.timer(0.6, lambda: self.end_game())