[ci] auto-format

This commit is contained in:
Loup-Garou911XD 2023-05-15 10:58:00 +00:00 committed by github-actions[bot]
parent 4af785998d
commit 2ac90c8677
10 changed files with 1225 additions and 1214 deletions

View file

@ -1,10 +1,9 @@
#Ported by: Freaku / @[Just] Freak#4999
# Ported by: Freaku / @[Just] Freak#4999
#Join BCS:
# Join BCS:
# https://discord.gg/ucyaesh
# ba_meta require api 7
from __future__ import annotations
@ -18,7 +17,6 @@ if TYPE_CHECKING:
from typing import Any, Type, List, Dict, Tuple, Union, Sequence, Optional
class State:
def __init__(self, bomb=None, grab=False, punch=False, curse=False, required=False, final=False, name=''):
self.bomb = bomb
@ -48,16 +46,18 @@ class State:
return (self.name)
states = [ State(bomb='normal', name='Basic Bombs'),
states = [State(bomb='normal', name='Basic Bombs'),
State(bomb='ice', name='Frozen Bombs'),
State(bomb='sticky', name='Sticky Bombs'),
State(bomb='impact', name='Impact Bombs'),
State(grab=True, name='Grabbing only'),
State(punch=True, name='Punching only'),
State(curse=True, name='Cursed', final=True) ]
State(curse=True, name='Cursed', final=True)]
class Player(ba.Player['Team']):
"""Our player type for this game."""
def __init__(self):
self.state = None

View file

@ -475,12 +475,12 @@ class CollectorGame(ba.TeamGameActivity[Player, Team]):
count=int(6.4+random.random()*24),
scale=1.2,
spread=2.0,
chunk_type='spark');
chunk_type='spark')
ba.emitfx(
position=capsule.node.position,
velocity=(0, 0, 0),
count=int(4.0+random.random()*6),
emit_type='tendrils');
emit_type='tendrils')
else:
player.capsules += 1
ba.playsound(
@ -514,6 +514,7 @@ class CollectorGame(ba.TeamGameActivity[Player, Team]):
0.0: player.light.intensity,
0.1: intensity
})
def newintensity():
player.light.intensity = intensity
ba.timer(0.1, newintensity)
@ -596,7 +597,7 @@ class Capsule(ba.Actor):
'body': 'crate' if lucky else 'capsule',
'reflection': 'powerup' if lucky else 'soft',
'body_scale': 0.65 if lucky else 0.3,
'density':6.0 if lucky else 4.0,
'density': 6.0 if lucky else 4.0,
'reflection_scale': [0.15],
'shadow_size': 0.65 if lucky else 0.6,
'position': self._spawn_pos,

View file

@ -39,15 +39,18 @@ class BallType(Enum):
# increase the next ball speed but less than MEDIUM.
# Ball color is crimson(purple+red = pinky color type).
# this dict decide the ball_type spawning rate like powerup box
ball_type_dict: dict[BallType, int] = {
BallType.EASY: 3,
BallType.MEDIUM: 2,
BallType.HARD: 1,
};
}
class Ball(ba.Actor):
""" Shooting Ball """
def __init__(self,
position: Sequence[float],
velocity: Sequence[float],
@ -56,11 +59,11 @@ class Ball(ba.Actor):
gravity_scale: float = 1.0,
) -> NoReturn:
super().__init__();
super().__init__()
shared = SharedObjects.get();
shared = SharedObjects.get()
ball_material = ba.Material();
ball_material = ba.Material()
ball_material.add_actions(
conditions=(
(
@ -72,7 +75,7 @@ class Ball(ba.Actor):
('they_have_material', shared.object_material),
),
actions=('modify_node_collision', 'collide', False),
);
)
self.node = ba.newnode(
'prop',
@ -89,19 +92,19 @@ class Ball(ba.Actor):
'density': 4.0, # increase density of ball so ball collide with player with heavy force. # ammm very bad grammer
'materials': (ball_material,),
},
);
)
# die the ball manually incase the ball doesn't fall the outside of the map
ba.timer(2.5, ba.WeakCall(self.handlemessage, ba.DieMessage()));
ba.timer(2.5, ba.WeakCall(self.handlemessage, ba.DieMessage()))
# i am not handling anything in this ball Class(except for diemessage).
# all game things and logics going to be in the box class
def handlemessage(self, msg: Any) -> Any:
if isinstance(msg, ba.DieMessage):
self.node.delete();
self.node.delete()
else:
super().handlemessage(msg);
super().handlemessage(msg)
class Box(ba.Actor):
@ -112,11 +115,11 @@ class Box(ba.Actor):
velocity: Sequence[float],
) -> NoReturn:
super().__init__();
super().__init__()
shared = SharedObjects.get();
shared = SharedObjects.get()
# self.ball_jump = 0.0;
no_hit_material = ba.Material();
no_hit_material = ba.Material()
# we don't need that the box was move and collide with objects.
no_hit_material.add_actions(
conditions=(
@ -125,7 +128,7 @@ class Box(ba.Actor):
('they_have_material', shared.attack_material),
),
actions=('modify_part_collision', 'collide', False),
);
)
no_hit_material.add_actions(
conditions=(
@ -137,7 +140,7 @@ class Box(ba.Actor):
('modify_part_collision', 'collide', False),
('modify_part_collision', 'physical', False),
),
);
)
self.node = ba.newnode(
'prop',
@ -155,25 +158,25 @@ class Box(ba.Actor):
'reflection_scale': [1.0],
'materials': (no_hit_material,),
},
);
)
# light
self.light = ba.newnode(
"light",
owner = self.node,
owner=self.node,
attrs={
'radius' : 0.2,
'intensity' : 0.8,
'radius': 0.2,
'intensity': 0.8,
'color': (0.0, 1.0, 0.0),
}
);
self.node.connectattr("position", self.light, "position");
)
self.node.connectattr("position", self.light, "position")
# Drawing circle and circleOutline in radius of 3,
# so player can see that how close he is to the box.
# If player is inside this circle the ball speed will increase.
circle = ba.newnode(
"locator",
owner = self.node,
attrs = {
owner=self.node,
attrs={
'shape': 'circle',
'color': (1.0, 0.0, 0.0),
'opacity': 0.1,
@ -182,12 +185,12 @@ class Box(ba.Actor):
'additive': True,
},
)
self.node.connectattr("position", circle, "position");
self.node.connectattr("position", circle, "position")
# also adding a outline cause its look nice.
circle_outline = ba.newnode(
"locator",
owner = self.node,
attrs = {
owner=self.node,
attrs={
'shape': 'circleOutline',
'color': (1.0, 1.0, 0.0),
'opacity': 0.1,
@ -195,92 +198,92 @@ class Box(ba.Actor):
'draw_beauty': False,
'additive': True,
},
);
self.node.connectattr("position", circle_outline, "position");
)
self.node.connectattr("position", circle_outline, "position")
# all ball attribute that we need.
self.ball_type: BallType = BallType.EASY;
self.shoot_timer: ba.Timer | None = None;
self.shoot_speed: float = 0.0;
self.ball_type: BallType = BallType.EASY
self.shoot_timer: ba.Timer | None = None
self.shoot_speed: float = 0.0
# this force the shoot if player is inside the red circle.
self.force_shoot_speed: float = 0.0;
self.ball_mag = 3000;
self.ball_gravity: float = 1.0;
self.ball_tex: ba.Texture | None = None;
self.force_shoot_speed: float = 0.0
self.ball_mag = 3000
self.ball_gravity: float = 1.0
self.ball_tex: ba.Texture | None = None
# only for Hard ball_type
self.player_facing_direction: list[float, float] = [0.0, 0.0];
self.player_facing_direction: list[float, float] = [0.0, 0.0]
# ball shoot soound.
self.shoot_sound = ba.getsound('laserReverse');
self.shoot_sound = ba.getsound('laserReverse')
# same as "powerupdist"
self.ball_type_dist: list[BallType] = [];
self.ball_type_dist: list[BallType] = []
for ball in ball_type_dict:
for _ in range(ball_type_dict[ball]):
self.ball_type_dist.append(ball);
self.ball_type_dist.append(ball)
# Here main logic of game goes here.
# like shoot balls, shoot speed, anything we want goes here(except for some thing).
def start_shoot(self) -> NoReturn:
# getting all allive players in a list.
alive_players_list = self.activity.get_alive_players();
alive_players_list = self.activity.get_alive_players()
# make sure that list is not Empty.
if len(alive_players_list) > 0:
# choosing a random player from list.
target_player = choice(alive_players_list);
target_player = choice(alive_players_list)
# highlight the target player
self.highlight_target_player(target_player);
self.highlight_target_player(target_player)
# to finding difference between player and box.
# we just need to subtract player pos and ball pos.
# Same logic as eric applied in Target Practice Gamemode.
difference = ba.Vec3(target_player.position) - ba.Vec3(self.node.position);
difference = ba.Vec3(target_player.position) - ba.Vec3(self.node.position)
# discard Y position so ball shoot more straight.
difference[1] = 0.0
# and now, this length method returns distance in float.
# we're gonna use this value for calculating player analog stick
distance = difference.length();
distance = difference.length()
# shoot a random BallType
self.upgrade_ball_type(choice(self.ball_type_dist));
self.upgrade_ball_type(choice(self.ball_type_dist))
# and check the ball_type and upgrade it gravity_scale, texture, next ball speed.
self.check_ball_type(self.ball_type);
self.check_ball_type(self.ball_type)
# For HARD ball i am just focusing on player analog stick facing direction.
# Not very accurate and that's we need.
if self.ball_type == BallType.HARD:
self.calculate_player_analog_stick(target_player, distance);
self.calculate_player_analog_stick(target_player, distance)
else:
self.player_facing_direction = [0.0, 0.0];
self.player_facing_direction = [0.0, 0.0]
pos = self.node.position;
pos = self.node.position
if self.ball_type == BallType.MEDIUM or self.ball_type == BallType.HARD:
# Target head by increasing Y pos.
# How this work? cause ball gravity_scale is ......
pos = (pos[0], pos[1]+.25, pos[2]);
pos = (pos[0], pos[1]+.25, pos[2])
# ball is generating..
ball = Ball(
position = pos,
velocity = (0.0, 0.0, 0.0),
texture = self.ball_tex,
gravity_scale = self.ball_gravity,
body_scale = 1.0,
).autoretain();
position=pos,
velocity=(0.0, 0.0, 0.0),
texture=self.ball_tex,
gravity_scale=self.ball_gravity,
body_scale=1.0,
).autoretain()
# shoot Animation and sound.
self.shoot_animation();
self.shoot_animation()
# force the shoot speed if player try to go inside the red circle.
if self.force_shoot_speed != 0.0:
self.shoot_speed = self.force_shoot_speed;
self.shoot_speed = self.force_shoot_speed
# push the ball to the player
ball.node.handlemessage(
@ -294,72 +297,72 @@ class Box(ba.Actor):
0.000, # radius
0.000, # idk
difference[0] + self.player_facing_direction[0], # force direction X
difference[1] , # force direction Y
difference[1], # force direction Y
difference[2] + self.player_facing_direction[1], # force direction Z
);
)
# creating our timer and shoot the ball again.(and we create a loop)
self.shoot_timer = ba.Timer(self.shoot_speed, self.start_shoot);
self.shoot_timer = ba.Timer(self.shoot_speed, self.start_shoot)
def upgrade_ball_type(self, ball_type: BallType) -> NoReturn:
self.ball_type = ball_type;
self.ball_type = ball_type
def check_ball_type(self, ball_type: BallType) -> NoReturn:
if ball_type == BallType.EASY:
self.shoot_speed = 0.8;
self.ball_gravity = 1.0;
self.shoot_speed = 0.8
self.ball_gravity = 1.0
# next ball shoot speed
self.ball_mag = 3000;
self.ball_mag = 3000
# box light color and ball tex
self.light.color = (1.0, 1.0, 0.0);
self.ball_tex = ba.gettexture('egg4');
self.light.color = (1.0, 1.0, 0.0)
self.ball_tex = ba.gettexture('egg4')
elif ball_type == BallType.MEDIUM:
self.ball_mag = 3000;
self.ball_mag = 3000
# decrease the gravity scale so, ball shoot without falling and straight.
self.ball_gravity = 0.0;
self.ball_gravity = 0.0
# next ball shoot speed.
self.shoot_speed = 0.4;
self.shoot_speed = 0.4
# box light color and ball tex.
self.light.color = (1.0, 0.0, 1.0);
self.ball_tex = ba.gettexture('egg3');
self.light.color = (1.0, 0.0, 1.0)
self.ball_tex = ba.gettexture('egg3')
elif ball_type == BallType.HARD:
self.ball_mag = 2500;
self.ball_gravity = 0.0;
self.ball_mag = 2500
self.ball_gravity = 0.0
# next ball shoot speed.
self.shoot_speed = 0.6;
self.shoot_speed = 0.6
# box light color and ball tex.
self.light.color = (1.0, 0.2, 1.0);
self.ball_tex = ba.gettexture('egg1');
self.light.color = (1.0, 0.2, 1.0)
self.ball_tex = ba.gettexture('egg1')
def shoot_animation(self) -> NoReturn:
ba.animate(
self.node,
"model_scale",{
"model_scale", {
0.00: 1.4,
0.05: 1.7,
0.10: 1.4,
}
);
)
# playing shoot sound.
ba.playsound(self.shoot_sound, position = self.node.position);
ba.playsound(self.shoot_sound, position=self.node.position)
def highlight_target_player(self, player: ba.Player) -> NoReturn:
# adding light
light = ba.newnode(
"light",
owner = self.node,
owner=self.node,
attrs={
'radius':0.0,
'intensity':1.0,
'radius': 0.0,
'intensity': 1.0,
'color': (1.0, 0.0, 0.0),
}
);
)
ba.animate(
light,
"radius",{
"radius", {
0.05: 0.02,
0.10: 0.07,
0.15: 0.15,
@ -369,11 +372,11 @@ class Box(ba.Actor):
0.35: 0.02,
0.40: 0.00,
}
);
)
# And a circle outline with ugly animation.
circle_outline = ba.newnode(
"locator",
owner = player.actor.node,
owner=player.actor.node,
attrs={
'shape': 'circleOutline',
'color': (1.0, 0.0, 0.0),
@ -381,7 +384,7 @@ class Box(ba.Actor):
'draw_beauty': False,
'additive': True,
},
);
)
ba.animate_array(
circle_outline,
'size',
@ -395,31 +398,31 @@ class Box(ba.Actor):
0.35: [0.6],
0.40: [0.0],
}
);
)
# coonect it and...
player.actor.node.connectattr("position", light, "position");
player.actor.node.connectattr("position", circle_outline, "position");
player.actor.node.connectattr("position", light, "position")
player.actor.node.connectattr("position", circle_outline, "position")
# immediately delete the node after another player has been targeted.
self.shoot_speed = 0.5 if self.shoot_speed == 0.0 else self.shoot_speed;
ba.timer(self.shoot_speed, light.delete);
ba.timer(self.shoot_speed, circle_outline.delete);
self.shoot_speed = 0.5 if self.shoot_speed == 0.0 else self.shoot_speed
ba.timer(self.shoot_speed, light.delete)
ba.timer(self.shoot_speed, circle_outline.delete)
def calculate_player_analog_stick(self, player:ba.Player, distance: float) -> NoReturn:
def calculate_player_analog_stick(self, player: ba.Player, distance: float) -> NoReturn:
# at first i was very confused how i can read the player analog stick \
# then i saw TheMikirog#1984 autorun plugin code.
# and i got it how analog stick values are works.
# just need to store analog stick facing direction and need some calculation according how far player pushed analog stick.
# Notice that how vertical direction is inverted, so we need to put a minus infront of veriable.(so ball isn't shoot at wrong direction).
self.player_facing_direction[0] = player.actor.node.move_left_right;
self.player_facing_direction[1] = -player.actor.node.move_up_down;
self.player_facing_direction[0] = player.actor.node.move_left_right
self.player_facing_direction[1] = -player.actor.node.move_up_down
# if player is too close and the player pushing his analog stick fully the ball shoot's too far away to player.
# so, we need to reduce the value of "self.player_facing_direction" to fix this problem.
if distance <= 3:
self.player_facing_direction[0] = 0.4 if self.player_facing_direction[0] > 0 else -0.4;
self.player_facing_direction[1] = 0.4 if self.player_facing_direction[0] > 0 else -0.4;
self.player_facing_direction[0] = 0.4 if self.player_facing_direction[0] > 0 else -0.4
self.player_facing_direction[1] = 0.4 if self.player_facing_direction[0] > 0 else -0.4
# same problem to long distance but in reverse, the ball can't reach to the player,
# its because player analog stick value is between 1 and -1,
# and this value is low to shoot ball forward to Player if player is too far from the box.
@ -428,34 +431,34 @@ class Box(ba.Actor):
# So many calculation according to how analog stick pushed by player.
# Horizontal(left-right) calculation
if self.player_facing_direction[0] > 0.4:
self.player_facing_direction[0] = 1.5;
self.player_facing_direction[0] = 1.5
elif self.player_facing_direction[0] < -0.4:
self.player_facing_direction[0] = -1.5;
self.player_facing_direction[0] = -1.5
else:
if self.player_facing_direction[0] > 0.0:
self.player_facing_direction[0] = 0.2;
self.player_facing_direction[0] = 0.2
elif self.player_facing_direction[0] < 0.0:
self.player_facing_direction[0] = -0.2;
self.player_facing_direction[0] = -0.2
else:
self.player_facing_direction[0] = 0.0;
self.player_facing_direction[0] = 0.0
# Vertical(up-down) calculation.
if self.player_facing_direction[1] > 0.4:
self.player_facing_direction[1] = 1.5;
self.player_facing_direction[1] = 1.5
elif self.player_facing_direction[1] < -0.4:
self.player_facing_direction[1] = -1.5;
self.player_facing_direction[1] = -1.5
else:
if self.player_facing_direction[1] > 0.0:
self.player_facing_direction[1] = 0.2;
self.player_facing_direction[1] = 0.2
elif self.player_facing_direction[1] < 0.0:
self.player_facing_direction[1] = -0.2;
self.player_facing_direction[1] = -0.2
else:
self.player_facing_direction[1] = -0.0;
self.player_facing_direction[1] = -0.0
# if we want stop the ball shootes
def stop_shoot(self) -> NoReturn:
# Kill the timer.
self.shoot_timer = None;
self.shoot_timer = None
class Player(ba.Player['Team']):
@ -470,31 +473,33 @@ class Team(ba.Team[Player]):
# and main thing don't allow player to camp inside of box are going in this class.
# ba_meta export game
class DodgeTheBall(ba.TeamGameActivity[Player, Team]):
# defining name, description and settings..
name = 'Dodge the ball';
description = 'Survive from shooting balls';
name = 'Dodge the ball'
description = 'Survive from shooting balls'
available_settings = [
ba.IntSetting(
'Cooldown',
min_value = 20,
default = 45,
increment = 5,
min_value=20,
default=45,
increment=5,
),
ba.BoolSetting('Epic Mode', default=False)
]
# Don't allow joining after we start.
allow_mid_activity_joins = False;
allow_mid_activity_joins = False
@classmethod
def supports_session_type(cls, sessiontype: type[ba.Session]) -> bool:
# We support team and ffa sessions.
return issubclass(sessiontype, ba.FreeForAllSession) or issubclass(
sessiontype, ba.DualTeamSession,
);
)
@classmethod
def get_supported_maps(cls, sessiontype: type[ba.Session]) -> list[str]:
@ -502,75 +507,75 @@ class DodgeTheBall(ba.TeamGameActivity[Player, Team]):
# bombsquad have "Doom Shroom" map.
# Not perfect map for this game mode but its fine for this gamemode.
# the problem is that Doom Shroom is not a perfect circle and not flat also.
return ['Doom Shroom'];
return ['Doom Shroom']
def __init__(self, settings: dict):
super().__init__(settings);
self._epic_mode = bool(settings['Epic Mode']);
self.countdown_time = int(settings['Cooldown']);
super().__init__(settings)
self._epic_mode = bool(settings['Epic Mode'])
self.countdown_time = int(settings['Cooldown'])
self.check_player_pos_timer: ba.Timer | None = None;
self.shield_drop_timer: ba.Timer | None = None;
self.check_player_pos_timer: ba.Timer | None = None
self.shield_drop_timer: ba.Timer | None = None
# cooldown and Box
self._countdown: OnScreenCountdown | None = None;
self.box: Box | None = None;
self._countdown: OnScreenCountdown | None = None
self.box: Box | None = None
# this lists for scoring.
self.joined_player_list: list[ba.Player] = [];
self.dead_player_list: list[ba.Player] = [];
self.joined_player_list: list[ba.Player] = []
self.dead_player_list: list[ba.Player] = []
# normally play RUN AWAY music cause is match with our gamemode at.. my point,
# but in epic switch to EPIC.
self.slow_motion = self._epic_mode;
self.slow_motion = self._epic_mode
self.default_music = (
ba.MusicType.EPIC if self._epic_mode else ba.MusicType.RUN_AWAY
);
)
def get_instance_description(self) -> str | Sequence:
return 'Keep away as possible as you can';
return 'Keep away as possible as you can'
# add a tiny text under our game name.
def get_instance_description_short(self) -> str | Sequence:
return 'Dodge the shooting balls';
return 'Dodge the shooting balls'
def on_begin(self) -> NoReturn:
super().on_begin();
super().on_begin()
# spawn our box at middle of the map
self.box = Box(
position=(0.5, 2.7, -3.9),
velocity=(0.0, 0.0, 0.0),
).autoretain();
).autoretain()
# create our cooldown
self._countdown = OnScreenCountdown(
duration = self.countdown_time,
endcall = self.play_victory_sound_and_end,
);
duration=self.countdown_time,
endcall=self.play_victory_sound_and_end,
)
# and starts the cooldown and shootes.
ba.timer(5.0, self._countdown.start);
ba.timer(5.0, self.box.start_shoot);
ba.timer(5.0, self._countdown.start)
ba.timer(5.0, self.box.start_shoot)
# start checking all player pos.
ba.timer(5.0, self.check_player_pos);
ba.timer(5.0, self.check_player_pos)
# drop shield every ten Seconds
# need five seconds delay Because shootes start after 5 seconds.
ba.timer(15.0, self.drop_shield);
ba.timer(15.0, self.drop_shield)
# This function returns all alive players in game.
# i thinck you see this function in Box class.
def get_alive_players(self) -> Sequence[ba.Player]:
alive_players = [];
alive_players = []
for team in self.teams:
for player in team.players:
if player.is_alive():
alive_players.append(player);
alive_players.append(player)
return alive_players;
return alive_players
# let's disallowed camping inside of box by doing a blast and increasing ball shoot speed.
def check_player_pos(self):
@ -578,76 +583,76 @@ class DodgeTheBall(ba.TeamGameActivity[Player, Team]):
for player in self.get_alive_players():
# same logic as applied for the ball
difference = ba.Vec3(player.position) - ba.Vec3(self.box.node.position);
difference = ba.Vec3(player.position) - ba.Vec3(self.box.node.position)
distance = difference.length();
distance = difference.length()
if distance < 3:
self.box.force_shoot_speed = 0.2;
self.box.force_shoot_speed = 0.2
else:
self.box.force_shoot_speed = 0.0;
self.box.force_shoot_speed = 0.0
if distance < 0.5:
Blast(
position = self.box.node.position,
velocity = self.box.node.velocity,
blast_type = 'normal',
blast_radius = 1.0,
).autoretain();
position=self.box.node.position,
velocity=self.box.node.velocity,
blast_type='normal',
blast_radius=1.0,
).autoretain()
PopupText(
position = self.box.node.position,
text = 'Keep away from me',
random_offset = 0.0,
scale = 2.0,
color = self.box.light.color,
).autoretain();
position=self.box.node.position,
text='Keep away from me',
random_offset=0.0,
scale=2.0,
color=self.box.light.color,
).autoretain()
# create our timer and start looping it
self.check_player_pos_timer = ba.Timer(0.1, self.check_player_pos);
self.check_player_pos_timer = ba.Timer(0.1, self.check_player_pos)
# drop useless shield's too give player temptation.
def drop_shield(self) -> NoReturn:
pos = self.box.node.position;
pos = self.box.node.position
PowerupBox(
position = (pos[0] + 4.0, pos[1] + 3.0, pos[2]),
poweruptype = 'shield',
).autoretain();
position=(pos[0] + 4.0, pos[1] + 3.0, pos[2]),
poweruptype='shield',
).autoretain()
PowerupBox(
position = (pos[0] - 4.0, pos[1] + 3.0, pos[2]),
poweruptype = 'shield',
).autoretain();
position=(pos[0] - 4.0, pos[1] + 3.0, pos[2]),
poweruptype='shield',
).autoretain()
self.shield_drop_timer = ba.Timer(10.0, self.drop_shield);
self.shield_drop_timer = ba.Timer(10.0, self.drop_shield)
# when cooldown time up i don't want that the game end immediately.
def play_victory_sound_and_end(self) -> NoReturn:
# kill timers
self.box.stop_shoot();
self.box.stop_shoot()
self.check_player_pos_timer = None
self.shield_drop_timer = None
ba.timer(2.0, self.end_game);
ba.timer(2.0, self.end_game)
# this function runs when A player spawn in map
def spawn_player(self, player: Player) -> NoReturn:
spaz = self.spawn_player_spaz(player);
spaz = self.spawn_player_spaz(player)
# reconnect this player's controls.
# without bomb, punch and pickup.
spaz.connect_controls_to_player(
enable_punch=False, enable_bomb=False, enable_pickup=False,
);
)
# storing all players for ScorinG.
self.joined_player_list.append(player);
self.joined_player_list.append(player)
# Also lets have them make some noise when they die.
spaz.play_big_death_sound = True;
spaz.play_big_death_sound = True
# very helpful function to check end game when player dead or leav.
def _check_end_game(self) -> bool:
@ -669,10 +674,10 @@ class DodgeTheBall(ba.TeamGameActivity[Player, Team]):
# this function called when player leave.
def on_player_leave(self, player: Player) -> NoReturn:
# Augment default behavior.
super().on_player_leave(player);
super().on_player_leave(player)
# checking end game.
self._check_end_game();
self._check_end_game()
# this gamemode needs to handle only one msg "PlayerDiedMessage".
def handlemessage(self, msg: Any) -> Any:
@ -680,13 +685,13 @@ class DodgeTheBall(ba.TeamGameActivity[Player, Team]):
if isinstance(msg, ba.PlayerDiedMessage):
# Augment standard behavior.
super().handlemessage(msg);
super().handlemessage(msg)
# and storing the dead player records in our dead_player_list.
self.dead_player_list.append(msg.getplayer(Player));
self.dead_player_list.append(msg.getplayer(Player))
# check the end game.
ba.timer(1.0, self._check_end_game);
ba.timer(1.0, self._check_end_game)
def end_game(self):
# kill timers
@ -758,5 +763,3 @@ class DodgeTheBall(ba.TeamGameActivity[Player, Team]):
results.set_team_score(team, int(10 * max_index))
# and end the game
self.end(results=results)

View file

@ -225,7 +225,6 @@ class InvicibleOneGame(ba.TeamGameActivity[Player, Team]):
scoring_team.time_remaining = max(
0, scoring_team.time_remaining - 1)
self._update_scoreboard()
# announce numbers we have sounds for
@ -286,7 +285,8 @@ class InvicibleOneGame(ba.TeamGameActivity[Player, Team]):
self._invicible_one_player = player
if self._invicible_one_is_lazy:
player.actor.connect_controls_to_player(enable_punch = False, enable_pickup = False, enable_bomb = False)
player.actor.connect_controls_to_player(
enable_punch=False, enable_pickup=False, enable_bomb=False)
if player.actor.node.torso_model != None:
player.actor.node.color_mask_texture = None
player.actor.node.color_texture = None
@ -310,7 +310,6 @@ class InvicibleOneGame(ba.TeamGameActivity[Player, Team]):
player.actor.node.name = ''
def handlemessage(self, msg: Any) -> Any:
if isinstance(msg, ba.PlayerDiedMessage):
# Augment standard behavior.

View file

@ -1,12 +1,16 @@
# ba_meta require api 7
from typing import Sequence
import ba, _ba, random
import ba
import _ba
import random
from bastd.actor.spaz import Spaz
from bastd.actor.scoreboard import Scoreboard
class Player(ba.Player['Team']):
"""Our player type for this game."""
class Team(ba.Team[Player]):
"""Our team type for this game."""
@ -14,18 +18,21 @@ class Team(ba.Team[Player]):
super().__init__()
self.score = 1
class ChooseingSpazHitMessage:
def __init__(self, hitter:Player) -> None:
def __init__(self, hitter: Player) -> None:
self.hitter = hitter
class ChooseingSpazDieMessage:
def __init__(self, killer:Player) -> None:
def __init__(self, killer: Player) -> None:
self.killer = killer
class ChooseingSpaz(Spaz):
def __init__(
self,
pos:Sequence[float],
pos: Sequence[float],
color: Sequence[float] = (1.0, 1.0, 1.0),
highlight: Sequence[float] = (0.5, 0.5, 0.5),
):
@ -44,14 +51,14 @@ class ChooseingSpaz(Spaz):
},
)
self.node.connectattr("position", self.loc, "position")
ba.animate_array(self.loc, "size", 1, keys={0:[0.5,], 1:[2,], 1.5:[0.5]}, loop=True)
ba.animate_array(self.loc, "size", 1, keys={0: [0.5,], 1: [2,], 1.5: [0.5]}, loop=True)
def handlemessage(self, msg):
if isinstance(msg, ba.FreezeMessage):
return
if isinstance(msg, ba.PowerupMessage):
if not(msg.poweruptype == "health"):
if not (msg.poweruptype == "health"):
return
super().handlemessage(msg)
@ -64,7 +71,6 @@ class ChooseingSpaz(Spaz):
self.activity.handlemessage(ChooseingSpazHitMessage(player))
self.last_player_attacked_by = player
elif isinstance(msg, ba.DieMessage):
player = self.last_player_attacked_by
@ -74,18 +80,17 @@ class ChooseingSpaz(Spaz):
self.loc.delete()
def stand(self, pos=(0, 0, 0), angle=0):
self.handlemessage(ba.StandMessage(pos, angle))
def stand(self, pos = (0,0,0), angle = 0):
self.handlemessage(ba.StandMessage(pos,angle))
def recolor(self, color, highlight = (1,1,1)):
def recolor(self, color, highlight=(1, 1, 1)):
self.node.color = color
self.node.highlight = highlight
self.loc.color = color
class ChooseBilbord(ba.Actor):
def __init__(self, player:Player, delay = 0.1) -> None:
def __init__(self, player: Player, delay=0.1) -> None:
super().__init__()
icon = player.get_icon()
@ -95,7 +100,7 @@ class ChooseBilbord(ba.Actor):
'image',
delegate=self,
attrs={
"position":(60,-125),
"position": (60, -125),
'texture': icon['texture'],
'tint_texture': icon['tint_texture'],
'tint_color': icon['tint_color'],
@ -110,7 +115,7 @@ class ChooseBilbord(ba.Actor):
'text',
owner=self.node,
attrs={
'position': (60,-185),
'position': (60, -185),
'text': ba.Lstr(value=player.getname()),
'color': ba.safecolor(player.team.color),
'h_align': 'center',
@ -119,18 +124,19 @@ class ChooseBilbord(ba.Actor):
'flatness': 1.0,
'h_attach': 'left',
'v_attach': 'top',
'maxwidth':self.scale
'maxwidth': self.scale
},
)
ba.animate_array(self.node, "scale", keys={0 + delay:[0,0], 0.05 + delay:[self.scale, self.scale]}, size=1)
ba.animate(self.name_node, "scale", {0 + delay:0, 0.07 + delay:1})
ba.animate_array(self.node, "scale", keys={
0 + delay: [0, 0], 0.05 + delay: [self.scale, self.scale]}, size=1)
ba.animate(self.name_node, "scale", {0 + delay: 0, 0.07 + delay: 1})
def handlemessage(self, msg):
super().handlemessage(msg)
if isinstance(msg, ba.DieMessage):
ba.animate_array(self.node, "scale", keys={0:self.node.scale, 0.05:[0,0]}, size=1)
ba.animate(self.name_node, "scale", {0:self.name_node.scale, 0.07:0})
ba.animate_array(self.node, "scale", keys={0: self.node.scale, 0.05: [0, 0]}, size=1)
ba.animate(self.name_node, "scale", {0: self.name_node.scale, 0.07: 0})
def __delete():
self.node.delete()
@ -139,6 +145,8 @@ class ChooseBilbord(ba.Actor):
ba.timer(0.2, __delete)
# ba_meta export game
class LastPunchStand(ba.TeamGameActivity[Player, Team]):
name = "Last Punch Stand"
description = "Last one punchs the choosing spaz wins"
@ -163,7 +171,7 @@ class LastPunchStand(ba.TeamGameActivity[Player, Team]):
if (self._min_timelimit > self._max_timelimit):
self._max_timelimit = self._min_timelimit
self._choosing_spaz_defcolor = (0.5,0.5,0.5)
self._choosing_spaz_defcolor = (0.5, 0.5, 0.5)
self.choosing_spaz = None
self.choosed_player = None
self.times_uped = False
@ -202,11 +210,12 @@ class LastPunchStand(ba.TeamGameActivity[Player, Team]):
def end_game(self) -> None:
results = ba.GameResults()
for team in self.teams:
if self.choosed_player and (team.id == self.choosed_player.team.id): team.score += 100
if self.choosed_player and (team.id == self.choosed_player.team.id):
team.score += 100
results.set_team_score(team, team.score)
self.end(results=results)
def change_choosed_player(self, hitter:Player):
def change_choosed_player(self, hitter: Player):
if hitter:
self.choosing_spaz.recolor(hitter.color, hitter.highlight)
self.choosed_player = hitter
@ -229,10 +238,10 @@ class LastPunchStand(ba.TeamGameActivity[Player, Team]):
def _watch_dog_(self):
"checks if choosing spaz exists"
#choosing spaz wont respawn if death type if generic
#this becuse we dont want to keep respawn him when he dies because of losing referce
#but sometimes "choosing spaz" dies naturaly and his death type is generic! so it wont respawn back again
#thats why we have this function; to check if spaz exits in the case that he didnt respawned
# choosing spaz wont respawn if death type if generic
# this becuse we dont want to keep respawn him when he dies because of losing referce
# but sometimes "choosing spaz" dies naturaly and his death type is generic! so it wont respawn back again
# thats why we have this function; to check if spaz exits in the case that he didnt respawned
if self.choosing_spaz:
if self.choosing_spaz._dead:

View file

@ -6,16 +6,17 @@ from typing import TYPE_CHECKING
import random
import enum
import ba, _ba
import ba
import _ba
from bastd.actor.scoreboard import Scoreboard
from bastd.actor.powerupbox import PowerupBox
from bastd.gameutils import SharedObjects
#from rocket
# from rocket
from bastd.actor.bomb import Blast
#from railgun
# from railgun
from bastd.actor.playerspaz import PlayerSpaz
from bastd.actor.spaz import Spaz
@ -27,7 +28,7 @@ if TYPE_CHECKING:
STORAGE_ATTR_NAME = f'_shared_{__name__}_factory'
#+++++++++++++++++++Rocket++++++++++++++++++++++++
# +++++++++++++++++++Rocket++++++++++++++++++++++++
class RocketFactory:
"""Quake Rocket factory"""
@ -182,10 +183,10 @@ class Rocket(ba.Actor):
elif isinstance(msg, ba.OutOfBoundsMessage):
self.handlemessage(ba.DieMessage())
#-------------------Rocket--------------------------
# -------------------Rocket--------------------------
#++++++++++++++++++Railgun++++++++++++++++++++++++++
# ++++++++++++++++++Railgun++++++++++++++++++++++++++
class Railgun:
"""Very dangerous weapon"""
@ -298,7 +299,8 @@ class RailBullet(ba.Actor):
elif isinstance(msg, ba.OutOfBoundsMessage):
self.handlemessage(ba.DieMessage())
#------------------Railgun-------------------------
# ------------------Railgun-------------------------
class Player(ba.Player['Team']):
"""Our player"""
@ -306,6 +308,7 @@ class Player(ba.Player['Team']):
class Team(ba.Team[Player]):
"""Our team"""
def __init__(self) -> None:
self.score = 0

View file

@ -1,7 +1,7 @@
# Released under the MIT License. See LICENSE for details.
# y me (: itsre3
# =>2<=
#BCS RULES
# BCS RULES
#
"""Defines Race mini-game."""
@ -14,7 +14,8 @@ import random
from typing import TYPE_CHECKING
from dataclasses import dataclass
import ba, _ba
import ba
import _ba
from bastd.actor.bomb import Bomb
from bastd.actor.playerspaz import PlayerSpaz
from bastd.actor.scoreboard import Scoreboard
@ -435,7 +436,6 @@ class SleepRaceGame(ba.TeamGameActivity[Player, Team]):
'text': 'By itsre3'
}))
# Throw a timer up on-screen.
self._time_text = ba.NodeActor(
ba.newnode('text',
@ -543,12 +543,11 @@ class SleepRaceGame(ba.TeamGameActivity[Player, Team]):
self._spawn_bomb,
repeat=True)
def knock_players():
activity = _ba.get_foreground_host_activity()
gnode = ba.getactivity().globalsnode
for players in activity.players:
gnode.tint = (0.5,0.5,0.5)
gnode.tint = (0.5, 0.5, 0.5)
node = players.actor.node
node.handlemessage('knockout', 600.0)
self.text_offset = ba.newnode('math',
@ -583,7 +582,6 @@ class SleepRaceGame(ba.TeamGameActivity[Player, Team]):
self._race_started = True
def _update_player_order(self) -> None:
# Calc all player distances.

View file

@ -1,4 +1,4 @@
#snake
# snake
# Released under the MIT License. See LICENSE for details.
#
"""Snake game by SEBASTIAN2059"""
@ -18,27 +18,33 @@ from bastd.actor import bomb as stdbomb
if TYPE_CHECKING:
from typing import Any, Type, List, Dict, Tuple, Union, Sequence, Optional
class ScoreMessage:
"""It will help us with the scores."""
def __init__(self,player: Player):
def __init__(self, player: Player):
self.player = player
def getplayer(self):
return self.player
class Player(ba.Player['Team']):
"""Our player type for this game."""
def __init__(self) -> None:
self.mines = []
self.actived = None
class Team(ba.Team[Player]):
"""Our team type for this game."""
def __init__(self) -> None:
self.score = 0
lang = ba.app.lang.language
if lang == 'Spanish':
description = 'Sobrevive a un número determinado de minas para ganar.'
@ -50,18 +56,23 @@ else:
join_description = "Run and don't get killed."
view_description = 'survive ${ARG1} mines'
class Custom_Mine(stdbomb.Bomb):
"""Custom a mine :)"""
def __init__(self,position,source_player):
stdbomb.Bomb.__init__(self,position=position,bomb_type='land_mine',source_player=source_player)
def handlemessage(self,msg: Any) -> Any:
def __init__(self, position, source_player):
stdbomb.Bomb.__init__(self, position=position, bomb_type='land_mine',
source_player=source_player)
def handlemessage(self, msg: Any) -> Any:
if isinstance(msg, ba.HitMessage):
return
else:
super().handlemessage(msg)
# ba_meta export game
class SnakeGame(ba.TeamGameActivity[Player, Team]):
"""A game type based on acquiring kills."""
@ -151,14 +162,13 @@ class SnakeGame(ba.TeamGameActivity[Player, Team]):
def on_begin(self) -> None:
super().on_begin()
self.setup_standard_time_limit(self._time_limit)
#self.setup_standard_powerup_drops()
# 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()
if self.slow_motion:
t_scale = 0.4
light_y = 50
@ -240,16 +250,13 @@ class SnakeGame(ba.TeamGameActivity[Player, Team]):
self.generate_mines(player)
return spaz
def generate_mines(self,player: Player):
def generate_mines(self, player: Player):
try:
player.actived = ba.Timer(0.5,ba.Call(self.spawn_mine, player),repeat=True)
player.actived = ba.Timer(0.5, ba.Call(self.spawn_mine, player), repeat=True)
except Exception as e:
print('Exception -> '+ str(e))
print('Exception -> ' + str(e))
def spawn_mine(self,player: Player):
def spawn_mine(self, player: Player):
if player.team.score >= self._score_to_win:
return
pos = player.actor.node.position
@ -264,7 +271,7 @@ class SnakeGame(ba.TeamGameActivity[Player, Team]):
def arm():
mine.arm()
ba.timer(0.5,arm)
ba.timer(0.5, arm)
player.mines.append(mine)
if len(player.mines) > 15:
@ -297,7 +304,7 @@ class SnakeGame(ba.TeamGameActivity[Player, Team]):
assert self._score_to_win is not None
if any(team.score >= self._score_to_win for team in self.teams):
self.end_game() #ba.timer(0.5, self.end_game)
self.end_game() # ba.timer(0.5, self.end_game)
else:
return super().handlemessage(msg)
return None

View file

@ -15,7 +15,8 @@ from __future__ import annotations
import random
from typing import TYPE_CHECKING
import ba, _ba
import ba
import _ba
from bastd.actor.playerspaz import PlayerSpaz
from bastd.actor.spaz import Spaz
from bastd.actor.bomb import Blast, Bomb
@ -56,8 +57,6 @@ class RoboBot(StickyBot):
highlight = (3, 3, 3)
class UFO(ba.Actor):
"""
New AI for Boss
@ -299,7 +298,6 @@ class UFO(ba.Actor):
node.position[2], 0, 5, 0, 3, 10, 0,
0, 0, 5, 0)
except:
pass
@ -314,7 +312,6 @@ class UFO(ba.Actor):
if not self.node:
return None
damage = abs(msg.magnitude)
if msg.hit_type == 'explosion':
damage /= 20
@ -519,7 +516,6 @@ class UFO(ba.Actor):
{0: self.shield_deco.color, 0.2: (5, 0.2, 0.2)})
self.bot_count = 6
def update_ai(self) -> None:
"""Should be called periodically to update the spaz' AI."""
# pylint: disable=too-many-branches
@ -572,7 +568,7 @@ class UFO(ba.Actor):
self.to_target.y,
self.to_target.z * self.xz_pos))
setattr(self.node, 'extra_acceleration',
(self.to_target.x * self.xz_pos ,
(self.to_target.x * self.xz_pos,
self.to_target.y * 80 + 70,
self.to_target.z * self.xz_pos))
@ -656,7 +652,6 @@ class UFO(ba.Actor):
self.xz_pos = 0.01
self.node.reflection_scale = [2]
def unfrozen():
self.frozen = False
if self.bot_dur_froze:
@ -666,7 +661,6 @@ class UFO(ba.Actor):
self.xz_pos = 1
self.node.reflection_scale = [0.25]
ba.timer(5.0, unfrozen)
else:
@ -870,8 +864,6 @@ class UFOightGame(ba.TeamGameActivity[Player, Team]):
'text': 'By Cross Joy'
})
def on_transition_in(self) -> None:
super().on_transition_in()
gnode = ba.getactivity().globalsnode
@ -882,8 +874,6 @@ class UFOightGame(ba.TeamGameActivity[Player, Team]):
super().on_begin()
self.setup_standard_powerup_drops()
# In pro mode there's no powerups.
# Make our on-screen timer and start it roughly when our bots appear.
@ -991,4 +981,3 @@ class MyUFOFightLevel(ba.Plugin):
preview_texture_name='footballStadiumPreview',
)
)

View file

@ -1,4 +1,4 @@
#Made by your friend: @[Just] Freak#4999
# Made by your friend: @[Just] Freak#4999
# ba_meta require api 7
from __future__ import annotations
@ -116,26 +116,28 @@ class BoxingGame(ba.TeamGameActivity[Player, Team]):
def on_team_join(self, team: Team) -> None:
if self.has_begun():
self._update_scoreboard()
def getRandomPowerupPoint(self) -> None:
myMap = self.map.getname()
if myMap == 'Doom Shroom':
while True:
x = random.uniform(-1.0,1.0)
y = random.uniform(-1.0,1.0)
if x*x+y*y < 1.0: break
return ((8.0*x,2.5,-3.5+5.0*y))
x = random.uniform(-1.0, 1.0)
y = random.uniform(-1.0, 1.0)
if x*x+y*y < 1.0:
break
return ((8.0*x, 2.5, -3.5+5.0*y))
elif myMap == 'Rampage':
x = random.uniform(-6.0,7.0)
y = random.uniform(-6.0,-2.5)
x = random.uniform(-6.0, 7.0)
y = random.uniform(-6.0, -2.5)
return ((x, 5.2, y))
else:
x = random.uniform(-5.0,5.0)
y = random.uniform(-6.0,0.0)
x = random.uniform(-5.0, 5.0)
y = random.uniform(-6.0, 0.0)
return ((x, 8.0, y))
def on_begin(self) -> None:
super().on_begin()
ba.screenmessage("start Yeeting",color = (0.2,1,1))
ba.screenmessage("start Yeeting", color=(0.2, 1, 1))
self.setup_standard_time_limit(self._time_limit)
# Base kills needed to win on the size of the largest team.
self._score_to_win = (self._kills_to_win_per_player *