[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
@ -35,8 +33,8 @@ class State:
def apply(self, spaz):
spaz.disconnect_controls_from_player()
spaz.connect_controls_to_player(enable_punch=self.punch,
enable_bomb=self.bomb,
enable_pickup=self.grab)
enable_bomb=self.bomb,
enable_pickup=self.grab)
if self.curse:
spaz.curse_time = -1
spaz.curse()
@ -48,16 +46,18 @@ class State:
return (self.name)
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) ]
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)]
class Player(ba.Player['Team']):
"""Our player type for this game."""
def __init__(self):
self.state = None

File diff suppressed because it is too large Load diff

View file

@ -39,28 +39,31 @@ 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],
texture: ba.Texture,
body_scale: float = 1.0,
gravity_scale: float = 1.0,
) -> NoReturn:
position: Sequence[float],
velocity: Sequence[float],
texture: ba.Texture,
body_scale: float = 1.0,
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',
@ -86,37 +89,37 @@ class Ball(ba.Actor):
'model_scale': body_scale,
'color_texture': texture,
'gravity_scale': gravity_scale,
'density': 4.0, # increase density of ball so ball collide with player with heavy force. # ammm very bad grammer
'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):
""" A box that spawn midle of map as a decoration perpose """
def __init__(self,
position: Sequence[float],
velocity: Sequence[float],
) -> NoReturn:
position: Sequence[float],
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',
@ -154,26 +157,26 @@ class Box(ba.Actor):
'reflection': 'powerup',
'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,
'color': (0.0, 1.0, 0.0),
'radius': 0.2,
'intensity': 0.8,
'color': (0.0, 1.0, 0.0),
}
);
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.
)
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(
@ -293,87 +296,87 @@ class Box(ba.Actor):
0.000, # magnetude velocity
0.000, # radius
0.000, # idk
difference[0] + self.player_facing_direction[0], # force direction X
difference[1] , # force direction Y
difference[2] + self.player_facing_direction[1], # force direction Z
);
difference[0] + self.player_facing_direction[0], # force direction X
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;
# next ball shoot speed
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');
elif ball_type == BallType.MEDIUM:
self.ball_mag = 3000;
# decrease the gravity scale so, ball shoot without falling and straight.
self.ball_gravity = 0.0;
# next ball shoot speed.
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');
elif ball_type == BallType.HARD:
self.ball_mag = 2500;
self.ball_gravity = 0.0;
# next ball shoot speed.
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');
if ball_type == BallType.EASY:
self.shoot_speed = 0.8
self.ball_gravity = 1.0
# next ball shoot speed
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')
elif ball_type == BallType.MEDIUM:
self.ball_mag = 3000
# decrease the gravity scale so, ball shoot without falling and straight.
self.ball_gravity = 0.0
# next ball shoot speed.
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')
elif ball_type == BallType.HARD:
self.ball_mag = 2500
self.ball_gravity = 0.0
# next ball shoot speed.
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')
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,
'color': (1.0, 0.0, 0.0),
'radius': 0.0,
'intensity': 1.0,
'color': (1.0, 0.0, 0.0),
}
);
)
ba.animate(
light,
"radius",{
0.05: 0.02,
0.10: 0.07,
0.15: 0.15,
0.20: 0.13,
0.25: 0.10,
0.30: 0.05,
0.35: 0.02,
0.40: 0.00,
}
);
light,
"radius", {
0.05: 0.02,
0.10: 0.07,
0.15: 0.15,
0.20: 0.13,
0.25: 0.10,
0.30: 0.05,
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,45 +384,45 @@ class Box(ba.Actor):
'draw_beauty': False,
'additive': True,
},
);
)
ba.animate_array(
circle_outline,
'size',
1, {
0.05: [0.5],
0.10: [0.8],
0.15: [1.5],
0.20: [2.0],
0.25: [1.8],
0.30: [1.3],
0.35: [0.6],
0.40: [0.0],
}
);
0.05: [0.5],
0.10: [0.8],
0.15: [1.5],
0.20: [2.0],
0.25: [1.8],
0.30: [1.3],
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;
# Kill the timer.
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,152 +507,152 @@ 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):
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);
# same logic as applied for the ball
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;
else:
self.box.force_shoot_speed = 0.0;
if distance < 3:
self.box.force_shoot_speed = 0.2
else:
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();
if distance < 0.5:
Blast(
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();
PopupText(
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();
PowerupBox(
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();
PowerupBox(
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
@ -741,22 +746,20 @@ class DodgeTheBall(ba.TeamGameActivity[Player, Team]):
max_index = 0
for player in team.players:
# for the team, we choose only one player who survived longest.
# same logic..
if len(self.dead_player_list) > 0:
# for the team, we choose only one player who survived longest.
# same logic..
if len(self.dead_player_list) > 0:
for index, dead_player in enumerate(self.dead_player_list):
if player == dead_player:
index += 1
break
elif index == len(self.dead_player_list) - 1:
index = len(self.joined_player_list)
else:
else:
index = len(self.joined_player_list)
max_index = max(max_index, index)
max_index = max(max_index, index)
# set the team score
results.set_team_score(team, int(10 * max_index))
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,38 +1,45 @@
# 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."""
"""Our player type for this game."""
class Team(ba.Team[Player]):
"""Our team type for this game."""
"""Our team type for this game."""
def __init__(self) -> None:
super().__init__()
self.score = 1
def __init__(self) -> None:
super().__init__()
self.score = 1
class ChooseingSpazHitMessage:
def __init__(self, hitter:Player) -> None:
self.hitter = hitter
def __init__(self, hitter: Player) -> None:
self.hitter = hitter
class ChooseingSpazDieMessage:
def __init__(self, killer:Player) -> None:
self.killer = killer
def __init__(self, killer: Player) -> None:
self.killer = killer
class ChooseingSpaz(Spaz):
def __init__(
self,
pos:Sequence[float],
color: Sequence[float] = (1.0, 1.0, 1.0),
highlight: Sequence[float] = (0.5, 0.5, 0.5),
):
super().__init__(color, highlight, "Spaz", None, True, True, False, False)
self.last_player_attacked_by = None
self.stand(pos)
self.loc = ba.newnode(
def __init__(
self,
pos: Sequence[float],
color: Sequence[float] = (1.0, 1.0, 1.0),
highlight: Sequence[float] = (0.5, 0.5, 0.5),
):
super().__init__(color, highlight, "Spaz", None, True, True, False, False)
self.last_player_attacked_by = None
self.stand(pos)
self.loc = ba.newnode(
'locator',
attrs={
'shape': 'circleOutline',
@ -43,221 +50,223 @@ class ChooseingSpaz(Spaz):
'additive': True,
},
)
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)
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)
def handlemessage(self, msg):
if isinstance(msg, ba.FreezeMessage):
return
def handlemessage(self, msg):
if isinstance(msg, ba.FreezeMessage):
return
if isinstance(msg, ba.PowerupMessage):
if not(msg.poweruptype == "health"):
return
if isinstance(msg, ba.PowerupMessage):
if not (msg.poweruptype == "health"):
return
super().handlemessage(msg)
super().handlemessage(msg)
if isinstance(msg, ba.HitMessage):
self.handlemessage(ba.PowerupMessage("health"))
if isinstance(msg, ba.HitMessage):
self.handlemessage(ba.PowerupMessage("health"))
player = msg.get_source_player(Player)
if self.is_alive():
self.activity.handlemessage(ChooseingSpazHitMessage(player))
self.last_player_attacked_by = player
player = msg.get_source_player(Player)
if self.is_alive():
self.activity.handlemessage(ChooseingSpazHitMessage(player))
self.last_player_attacked_by = player
elif isinstance(msg, ba.DieMessage):
player = self.last_player_attacked_by
elif isinstance(msg, ba.DieMessage):
player = self.last_player_attacked_by
if msg.how.value != ba.DeathType.GENERIC.value:
self._dead = True
self.activity.handlemessage(ChooseingSpazDieMessage(player))
if msg.how.value != ba.DeathType.GENERIC.value:
self._dead = True
self.activity.handlemessage(ChooseingSpazDieMessage(player))
self.loc.delete()
self.loc.delete()
def stand(self, pos=(0, 0, 0), angle=0):
self.handlemessage(ba.StandMessage(pos, angle))
def recolor(self, color, highlight=(1, 1, 1)):
self.node.color = color
self.node.highlight = highlight
self.loc.color = color
def stand(self, pos = (0,0,0), angle = 0):
self.handlemessage(ba.StandMessage(pos,angle))
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:
super().__init__()
def __init__(self, player: Player, delay=0.1) -> None:
super().__init__()
icon = player.get_icon()
self.scale = 100
icon = player.get_icon()
self.scale = 100
self.node = ba.newnode(
'image',
delegate=self,
attrs={
"position":(60,-125),
'texture': icon['texture'],
'tint_texture': icon['tint_texture'],
'tint_color': icon['tint_color'],
'tint2_color': icon['tint2_color'],
'opacity': 1.0,
'absolute_scale': True,
'attach': "topLeft"
},
)
self.node = ba.newnode(
'image',
delegate=self,
attrs={
"position": (60, -125),
'texture': icon['texture'],
'tint_texture': icon['tint_texture'],
'tint_color': icon['tint_color'],
'tint2_color': icon['tint2_color'],
'opacity': 1.0,
'absolute_scale': True,
'attach': "topLeft"
},
)
self.name_node = ba.newnode(
'text',
owner=self.node,
attrs={
'position': (60,-185),
'text': ba.Lstr(value=player.getname()),
'color': ba.safecolor(player.team.color),
'h_align': 'center',
'v_align': 'center',
'vr_depth': 410,
'flatness': 1.0,
'h_attach': 'left',
'v_attach': 'top',
'maxwidth':self.scale
},
)
self.name_node = ba.newnode(
'text',
owner=self.node,
attrs={
'position': (60, -185),
'text': ba.Lstr(value=player.getname()),
'color': ba.safecolor(player.team.color),
'h_align': 'center',
'v_align': 'center',
'vr_depth': 410,
'flatness': 1.0,
'h_attach': 'left',
'v_attach': 'top',
'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})
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})
def __delete():
self.node.delete()
self.name_node.delete()
def __delete():
self.node.delete()
self.name_node.delete()
ba.timer(0.2, __delete)
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"
tips = [
'keep punching the choosing spaz to be last punched player at times up!',
'you can not frezz the choosing spaz',
"evry time you punch the choosing spaz, you will get one point",
]
name = "Last Punch Stand"
description = "Last one punchs the choosing spaz wins"
tips = [
'keep punching the choosing spaz to be last punched player at times up!',
'you can not frezz the choosing spaz',
"evry time you punch the choosing spaz, you will get one point",
]
default_music = ba.MusicType.TO_THE_DEATH
default_music = ba.MusicType.TO_THE_DEATH
available_settings = [
ba.FloatSetting("min time limit (in seconds)", 50.0, min_value=30.0),
ba.FloatSetting("max time limit (in seconds)", 160.0, 60),
available_settings = [
ba.FloatSetting("min time limit (in seconds)", 50.0, min_value=30.0),
ba.FloatSetting("max time limit (in seconds)", 160.0, 60),
]
]
def __init__(self, settings: dict):
super().__init__(settings)
self._min_timelimit = settings["min time limit (in seconds)"]
self._max_timelimit = settings["max time limit (in seconds)"]
if (self._min_timelimit > self._max_timelimit):
self._max_timelimit = self._min_timelimit
def __init__(self, settings: dict):
super().__init__(settings)
self._min_timelimit = settings["min time limit (in seconds)"]
self._max_timelimit = settings["max time limit (in seconds)"]
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 = None
self.choosed_player = None
self.times_uped = False
self.scoreboard = Scoreboard()
self._choosing_spaz_defcolor = (0.5, 0.5, 0.5)
self.choosing_spaz = None
self.choosed_player = None
self.times_uped = False
self.scoreboard = Scoreboard()
def times_up(self):
self.times_uped = True
def times_up(self):
self.times_uped = True
for player in self.players:
if self.choosed_player and (player.team.id != self.choosed_player.team.id):
player.actor._cursed = True
player.actor.curse_explode()
for player in self.players:
if self.choosed_player and (player.team.id != self.choosed_player.team.id):
player.actor._cursed = True
player.actor.curse_explode()
self.end_game()
self.end_game()
def __get_spaz_bot_spawn_point(self):
if len(self.map.tnt_points) > 0:
return self.map.tnt_points[random.randint(0, len(self.map.tnt_points)-1)]
else:
return (0, 6, 0)
def __get_spaz_bot_spawn_point(self):
if len(self.map.tnt_points) > 0:
return self.map.tnt_points[random.randint(0, len(self.map.tnt_points)-1)]
else:
return (0, 6, 0)
def spaw_bot(self):
"spawns a choosing bot"
def spaw_bot(self):
"spawns a choosing bot"
self.choosing_spaz = ChooseingSpaz(self.__get_spaz_bot_spawn_point())
self.choose_bilbord = None
self.choosing_spaz = ChooseingSpaz(self.__get_spaz_bot_spawn_point())
self.choose_bilbord = None
def on_begin(self) -> None:
super().on_begin()
time_limit = random.randint(self._min_timelimit, self._max_timelimit)
self.spaw_bot()
ba.timer(time_limit, self.times_up)
def on_begin(self) -> None:
super().on_begin()
time_limit = random.randint(self._min_timelimit, self._max_timelimit)
self.spaw_bot()
ba.timer(time_limit, self.times_up)
self.setup_standard_powerup_drops(False)
self.setup_standard_powerup_drops(False)
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
results.set_team_score(team, team.score)
self.end(results=results)
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
results.set_team_score(team, team.score)
self.end(results=results)
def change_choosed_player(self, hitter:Player):
if hitter:
self.choosing_spaz.recolor(hitter.color, hitter.highlight)
self.choosed_player = hitter
hitter.team.score += 1
self.choose_bilbord = ChooseBilbord(hitter)
self.hide_score_board()
else:
self.choosing_spaz.recolor(self._choosing_spaz_defcolor)
self.choosed_player = None
self.choose_bilbord = None
self.show_score_board()
def change_choosed_player(self, hitter: Player):
if hitter:
self.choosing_spaz.recolor(hitter.color, hitter.highlight)
self.choosed_player = hitter
hitter.team.score += 1
self.choose_bilbord = ChooseBilbord(hitter)
self.hide_score_board()
else:
self.choosing_spaz.recolor(self._choosing_spaz_defcolor)
self.choosed_player = None
self.choose_bilbord = None
self.show_score_board()
def show_score_board(self):
self.scoreboard = Scoreboard()
for team in self.teams:
self.scoreboard.set_team_value(team, team.score)
def show_score_board(self):
self.scoreboard = Scoreboard()
for team in self.teams:
self.scoreboard.set_team_value(team, team.score)
def hide_score_board(self):
self.scoreboard = None
def hide_score_board(self):
self.scoreboard = None
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
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
if self.choosing_spaz:
if self.choosing_spaz._dead:
self.spaw_bot()
else:
self.spaw_bot()
if self.choosing_spaz:
if self.choosing_spaz._dead:
self.spaw_bot()
else:
self.spaw_bot()
def handlemessage(self, msg):
super().handlemessage(msg)
def handlemessage(self, msg):
super().handlemessage(msg)
if isinstance(msg, ChooseingSpazHitMessage):
hitter = msg.hitter
if self.choosing_spaz.node and hitter:
self.change_choosed_player(hitter)
if isinstance(msg, ChooseingSpazHitMessage):
hitter = msg.hitter
if self.choosing_spaz.node and hitter:
self.change_choosed_player(hitter)
elif isinstance(msg, ChooseingSpazDieMessage):
self.spaw_bot()
self.change_choosed_player(None)
elif isinstance(msg, ChooseingSpazDieMessage):
self.spaw_bot()
self.change_choosed_player(None)
elif isinstance(msg, ba.PlayerDiedMessage):
player = msg.getplayer(Player)
if not (self.has_ended() or self.times_uped):
self.respawn_player(player, 0)
elif isinstance(msg, ba.PlayerDiedMessage):
player = msg.getplayer(Player)
if not (self.has_ended() or self.times_uped):
self.respawn_player(player, 0)
if self.choosed_player and (player.getname(True) == self.choosed_player.getname(True)):
self.change_choosed_player(None)
if self.choosed_player and (player.getname(True) == self.choosed_player.getname(True)):
self.change_choosed_player(None)
self._watch_dog_()
self._watch_dog_()

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
@ -618,10 +621,10 @@ class Obstacle(ba.Actor):
'color_texture':
ba.gettexture('bunnyColor'),
'materials': [SharedObjects.get().footing_material]
if mirror else [
SharedObjects.get().object_material,
SharedObjects.get().footing_material
]
if mirror else [
SharedObjects.get().object_material,
SharedObjects.get().footing_material
]
})
def handlemessage(self, msg: Any) -> Any:

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
@ -215,7 +216,7 @@ class SleepRaceGame(ba.TeamGameActivity[Player, Team]):
('modify_part_collision', 'physical', False),
('call', 'at_connect',
self._handle_race_point_collide),
))
))
for rpt in pts:
self._regions.append(RaceRegion(rpt, len(self._regions)))
@ -263,7 +264,7 @@ class SleepRaceGame(ba.TeamGameActivity[Player, Team]):
translate=('statements', 'Killing ${NAME} for'
' skipping part of the track!'),
subs=[('${NAME}', player.getname(full=True))]),
color=(1, 0, 0))
color=(1, 0, 0))
else:
# If this player is in first, note that this is the
# front-most race-point.
@ -378,7 +379,7 @@ class SleepRaceGame(ba.TeamGameActivity[Player, Team]):
'${TEAM} is disqualified because ${PLAYER} left'),
subs=[('${TEAM}', player.team.name),
('${PLAYER}', player.getname(full=True))]),
color=(1, 1, 0))
color=(1, 1, 0))
player.team.finished = True
player.team.time = None
player.team.lap = 0
@ -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,35 +543,34 @@ 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',
owner=node,
attrs={'input1': (-0.5, 0.5, 0.25),
'operation': 'add'})
owner=node,
attrs={'input1': (-0.5, 0.5, 0.25),
'operation': 'add'})
node.connectattr(
'torso_position',
self.text_offset,
'input2')
'torso_position',
self.text_offset,
'input2')
self.text = ba.newnode('text',
owner=node,
attrs={
'h_align': 'right',
'color': (1.0, 1.0, 1.0),
'shadow': 1.0,
'text': 'z z',
'scale': 0.01,
'in_world': True})
owner=node,
attrs={
'h_align': 'right',
'color': (1.0, 1.0, 1.0),
'shadow': 1.0,
'text': 'z z',
'scale': 0.01,
'in_world': True})
self.text_offset.connectattr(
'output',
self.text,
'position')
'output',
self.text,
'position')
ba.animate(self.text, 'scale', {0: 0.0, 1.0: 0.01})
ba.timer(2, self.text.delete)
@ -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,31 +250,28 @@ 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
# mine = stdbomb.Bomb(position=(pos[0], pos[1] + 2.0, pos[2]),
# velocity=(0, 0, 0),
# bomb_type='land_mine',
# #blast_radius=,
# source_player=player.actor.source_player,
# owner=player.actor.node).autoretain()
# velocity=(0, 0, 0),
# bomb_type='land_mine',
# #blast_radius=,
# source_player=player.actor.source_player,
# owner=player.actor.node).autoretain()
mine = Custom_Mine(position=(pos[0], pos[1] + 2.0, pos[2]),
source_player=player.actor.source_player)
source_player=player.actor.source_player)
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
@ -252,8 +251,8 @@ class UFO(ba.Actor):
1.0 + i,
lambda: self._bots.spawn_bot(
RoboBot, pos=(self.node.position[0],
self.node.position[1] - 1,
self.node.position[2]), spawn_time=0.0
self.node.position[1] - 1,
self.node.position[2]), spawn_time=0.0
),
)
else:
@ -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
@ -326,7 +323,7 @@ class UFO(ba.Actor):
self.handlemessage(ba.DieMessage())
def _get_target_player_pt(self) -> tuple[
ba.Vec3 | None, ba.Vec3 | None]:
ba.Vec3 | None, ba.Vec3 | None]:
"""Returns the position and velocity of our target.
Both values will be None in the case of no target.
@ -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,9 +568,9 @@ 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))
self.to_target.z * self.xz_pos))
def on_expire(self) -> None:
super().on_expire()
@ -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:
@ -710,8 +704,8 @@ class UFOSet:
+ str(self._ufo_bot_lists[self._ufo_bot_update_list])
)
self._bot_update_list = (
self._ufo_bot_update_list + 1
) % self._ufo_bot_list_count
self._ufo_bot_update_list + 1
) % self._ufo_bot_list_count
# Update our list of player points for the bots to use.
player_pts = []
@ -784,7 +778,7 @@ class UFOSet:
"""Add a ba.SpazBot instance to the set."""
self._ufo_bot_lists[self._ufo_bot_add_list].append(bot)
self._ufo_bot_add_list = (
self._ufo_bot_add_list + 1) % self._ufo_bot_list_count
self._ufo_bot_add_list + 1) % self._ufo_bot_list_count
def have_living_bots(self) -> bool:
"""Return whether any bots in the set are alive or spawning."""
@ -859,18 +853,16 @@ class UFOightGame(ba.TeamGameActivity[Player, Team]):
self._bots = UFOSet()
self._preset = str(settings['preset'])
self._credit = ba.newnode('text',
attrs={
'v_attach': 'bottom',
'h_align': 'center',
'color': (0.4, 0.4, 0.4),
'flatness': 0.5,
'shadow': 0.5,
'position': (0, 20),
'scale': 0.7,
'text': 'By Cross Joy'
})
attrs={
'v_attach': 'bottom',
'h_align': 'center',
'color': (0.4, 0.4, 0.4),
'flatness': 0.5,
'shadow': 0.5,
'position': (0, 20),
'scale': 0.7,
'text': 'By Cross Joy'
})
def on_transition_in(self) -> None:
super().on_transition_in()
@ -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 *