def __shoot(self, gun1, events, dt, game): """Manages the shooting of the player Player shoot with pressing the SPACE key. The weapon power and bullet count depend on the level of the weapon (gun_level) Manages the weapon cooldown. """ key = pygame.key.get_pressed() if key[pygame.K_SPACE] and not self.gun_cooldown and self.can_shoot: gun_power = self._get_gun_power() idx = self.gun_level while idx > 0: gun.Gun(self.gun_type, gun_power, self.gun_speed, False, self._get_gun_position(idx), self.gun_direction, game.sprites) idx -= 1 self.gun_cooldown = self.gun_cooldown_delay self.gun_overflow += self.gun_overflow_step if self.gun_overflow >= self.gun_overflow_max: self.can_shoot = False sounds.Sound('overflow').play() sounds.Sound('shot').play() self.gun_cooldown = max(0, self.gun_cooldown - dt)
def make_opt(precondition=False): import gun import stick import eos nominal_eos = eos.Spline_eos(eos.Nominal(), precondition=precondition) experiment = { 'gun': gun.Gun(nominal_eos), 'stick': stick.Stick(nominal_eos), } data = {'gun': gun.data(), 'stick': stick.data()} return Opt(nominal_eos, experiment, data)
def __regular_shoot(self, game, dt): """Creates the bullets for the regular enemy""" rand = random.randint(1, 1000) if rand > self.gun_bullets_rate and not self.gun_cooldown: gun_dmg = self.gun_dmg_by_level() gun_speed = random.randint(self.gun_min_speed, self.gun_max_speeds.get(self.level)) gun.Gun(self.gun_type, gun_dmg, gun_speed, True, self.rect.midtop, self.gun_direction, game.sprites) self.gun_cooldown = random.uniform(self.gun_cooldown_range[0], self.gun_cooldown_range[1]) self.gun_cooldown = max(0, self.gun_cooldown - dt)
def __boss_shoot(self, game, dt): """Creates the bullets for the boss.""" rand = random.randint(1, 1000) if rand > self.gun_bullets_rate and not self.gun_cooldown: gun_dmg = self.gun_dmg_by_level() gun_speed = random.randint(self.gun_min_speed, self.gun_max_speeds.get(self.level)) count = 4 while count > 0: gun.Gun(self.gun_type, gun_dmg, gun_speed, True, self.__get_bullet_pos(count), self.gun_direction, game.sprites) count -= 1 self.gun_cooldown = random.uniform(self.boss_gun_cooldown_range[0], self.boss_gun_cooldown_range[1]) self.gun_cooldown = max(0, self.gun_cooldown - dt)
heartfull = "<:hearthalf:717115233889550457>" catnolike = "<:catnolike:717123162424344654>" pressf = "<:pressf:717111874730066041>" pepega = "<:pepega:717107929274122291>" random_events = [ ThrowEvent("<@!{0.id}> кинул {1} в <@!{2.id}>", 3), ThrowEvent("<@!{0.id}> кинул {1} в <@!{2.id}>, но промахнулся.", 3), ThrowEvent( "<@!{0.id}> кинул {1} в <@!{2.id}>, но {3} отскочил, и полетел обратно в <@!{0.id}>", 4), ThrowEvent("<@!{0.id}>, хватит кидаться! " + Emoji.catnolike, 1) ] RussianGun = gun.Gun() @bot.event async def on_ready(): print('Logged in as {0} ({0.id})'.format(bot.user)) @bot.command(pass_context=True) async def check(ctx, *args): tf = bool(random.randint(0, 1)) name = ctx.author.name ret_string = "{0}: {1} - {2}".format(name, " ".join(args), "удачно" if tf else "неудачно") await ctx.send(ret_string)
def __init__(self, name): self.name = name self.blood = 100 self.gun = gun.Gun()
def setUp(self): groups = pygame.sprite.Group() self.gun = gun.Gun('green', 100, 100, False, (500, 400), 1, groups)
tilewidth = int(width / visibletilesx) tileheight = int(height / visibletilesy) cameraposx = 0 cameraposy = 0 camerarangex = int(width / tilewidth) + cameraposx camerarangey = int(height / tileheight) + cameraposy cameraoffsetx = ((width / 2) / tilewidth) - ((tilewidth / 2) / tilewidth) cameraoffsety = ((height / 2) / tileheight) - ((tileheight / 2) / tileheight) pspeed = 0.35 revolver = gun.Gun() shotgun = gun.Gun(5, 25, 35, 0.5, 5, 4) p1 = player.Player(pspeed, level, width, height, tilewidth, tileheight, revolver, shotgun) hudfont = pygame.font.SysFont('arial', 30) render = draw.Render(level, tilewidth, tileheight) render.initImages() run = True clock = pygame.time.Clock() while (run): elapsedtime = clock.tick(30) / 33
def main(argv=None): import argparse import os import os.path if argv is None: # Usual case argv = sys.argv[1:] parser = argparse.ArgumentParser(description='Make plots for notes.pdf') parser.add_argument('--show', action='store_true') parser.add_argument('--fig_dir', type=str, default='figs', help= 'Directory of figures') # Plot requests h_format = lambda s:'File for figure of {0}'.format(s) parser.add_argument('--tx_stick', type=str, help=h_format('t(x)')) parser.add_argument('--C_gun', type=str, help=h_format('d c_v/ d c_p')) parser.add_argument('--vt_gun', type=str, help=h_format('v(t)')) parser.add_argument('--BC_gun', type=str, help=h_format('d v(t)/ d c_p')) parser.add_argument('--opt_result', type=str, help=h_format( 'one optimization step')) parser.add_argument('--big_d', type=str, help=h_format( 'finite difference derivative with 9 subplots')) parser.add_argument('--fve_gun', type=str, help=h_format( 'force, velocity and sequence of errors')) args = parser.parse_args(argv) params = {'axes.labelsize': 18, # Plotting parameters for latex 'font.size': 15, 'legend.fontsize': 15, 'text.usetex': True, 'font.family':'serif', 'font.serif':'Computer Modern Roman', 'xtick.labelsize': 15, 'ytick.labelsize': 15} mpl.rcParams.update(params) if args.show: mpl.rcParams['text.usetex'] = False else: mpl.use('PDF') import matplotlib.pyplot as plt # must be after mpl.use if not os.path.exists(args.fig_dir): os.mkdir(args.fig_dir) # Do quick calculations to create exp and nom import eos import gun import stick t=np.linspace(0, gun.magic.t_max, gun.magic.n_t_sim) exp = Go(eos=eos.Experiment()) nom = Go(eos=eos.Spline_eos(eos.Nominal(), precondition=True)) for go in (exp, nom): go.add(t=t, gun=gun.Gun(go.eos), stick=stick.Stick(go.eos)) go.add(x=np.linspace(go.gun.x_i, go.gun.x_f, 500)) go.add(t2v=go.gun.fit_t2v()) go.add(v=go.t2v(t)) go.add(vt=(go.v, go.t)) go.add(stick_data=stick.data(go.eos)) C=nom.gun.fit_C() B,ep = nom.gun.fit_B_ep(exp.vt) nom.add(C=C, B=B, ep=ep, BC=np.dot(B,C)) # Make requested plots do_show = args.show for key in args.__dict__: if key not in plot_dict: continue if args.__dict__[key] == None: continue print('work on %s'%(key,)) fig = plot_dict[key](exp, nom, plt) file_name = getattr(args, key) if file_name == 'show': do_show = True else: fig.savefig(os.path.join(args.fig_dir, file_name), format='pdf') if do_show: plt.show() return 0