def start(self): pygame.init() self.screen = pygame.display.set_mode((800, 600)) self.stage = Stage(self) self.background = Background(self) self.player = Player(self) self.bullet = Bullet(self) self.enemies = Enemies(self) self.game_text = GameText(self) self.explosion = Explosion(self) self.caption = Caption(self) self.score = Score(self) self.next_stage() while self.running: self.screen.fill((0, 0, 0)) self.background.show() self.handle_event() self.player.move() self.bullet.move() self.enemies.move() self.score.show() self.stage.show() self.check_win() pygame.display.update()
def __init__(self, screen): Stage.__init__(self, screen) self.key_handlers = { pygame.K_UP: self.cursor_up, pygame.K_DOWN: self.cursor_down, pygame.K_LEFT: self.cursor_left, pygame.K_RIGHT: self.cursor_right, pygame.K_ESCAPE: self.end, pygame.K_KP_ENTER: self.choose_this, pygame.K_RETURN: self.choose_this } self.all_buttons = [] # fill list with buttons x = 20 y = 20 # random self.all_buttons.append(ListButton(screen, x, y, "Random Round 1", 1)) self.all_buttons[0].cursor_here = True self.cursored = 0 y += ListButton.height self.all_buttons.append(ListButton(screen, x, y, "Random Round 2", 2)) y += ListButton.height self.all_buttons.append(ListButton(screen, x, y, "Random Round 3", 3)) # from list x += 20 + ListButton.width y = 20 for template in self.templates: self.all_buttons.append(ListButton(screen, x, y, template[0], template[1])) y += ListButton.height if y > 700: x += 20 + ListButton.width y = 20
def __init__(self): self.Stage = Stage(screen, 1, '1-1') self.Player = Player(screen, self.Stage) self.Enemy = Enemy(screen) remain_show() Sound.play_BGM('titerman') self.main()
class Stage_1: def __init__(self): self.Stage = Stage(screen, 1, '1-1') self.Player = Player(screen, self.Stage) self.Enemy = Enemy(screen) remain_show() Sound.play_BGM('titerman') self.main() def main(self): while 1: screen.fill((160, 180, 250)) # 強制アニメーション if self.Player.goal_animation(): global REMAIN REMAIN += 1 state_change(2) return if self.Player.dokan_animation() or self.Player.death_animation(): return self.Player.update() self.Enemy.update() self.Player.item_animation() self.Stage.update() Text.update() # スペースキーで2倍速 variable_FPS = FPS * (2 if pygame.key.get_pressed()[K_SPACE] else 1) clock.tick(variable_FPS) pygame.display.update(Rect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)) for event in pygame.event.get(): # 「×」ボタンが押されたら終了 if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: # ESCキーが押されたら終了 if event.key == K_ESCAPE: pygame.quit() sys.exit() # F1キーが押されたらタイトルに戻る if event.key == K_F1: state_change(0) return # oキーが押されたら自殺 if event.key == K_o: Stage.player_object.isDeath = True
def create_objects(): global stage, cat, lands, man, heart, enemy, stone stage = Background() cat = Cat() heart = Heart() lands = Land(stage) man = Man(stage) enemy = Enemy(stage) stone = Stone(stage) stage.set_center_object(cat) cat.set_background(stage)
def initialize(self, amount: int, sensing_range: Tuple[int, int], speed_range: Tuple[int, int], aggression_range: Tuple[int, int], stage: Stage): self.__stage_limits = stage.get_stage_limits() self.__stage_color = stage.get_stage_color() self.__walls_color = stage.get_walls_color() self.__characters.clear() self.__span_random_characters(amount, sensing_range, speed_range, aggression_range) self.__initial_amount = amount
def initialize(self, amount: int, target_amount: int, range_of_values: Tuple[int, int], stage: Stage.Stage, blockings: List[Rectangle.Rectangle]): foods = list() width, height = blockings[0].get_size() limits = stage.get_stage_limits() self.__stage_limits = Limits(limits.x_min + width, limits.y_min + height, limits.x_max - width, limits.y_max - height) self.__stage_color = stage.get_stage_color() self.__range_of_values = range_of_values self.__foods = self.__span_random_food(amount, blockings) self.__initial_amount = amount self.__target_amount = target_amount
def move_characters(self, food_manager: FoodManager, stage: Stage, only_walls: bool): characters_left = self.characters_left() i = 0 while i < characters_left: movement = self.__get_direction(i, stage, food_manager) if self.__characters[i].finished(): self.__move_home(i) i -= 1 characters_left -= 1 elif self.__characters[i].no_energy(): self.__kill(i) i -= 1 characters_left -= 1 else: self.__move_character(i, movement, self.__get_blockings(i, stage.get_walls(), only_walls), food_manager) i += 1 self.__maybe_someone_is_eating_someone() for j in range(self.characters_left()): food_manager.maybe_is_eating(self.__characters[j]) self.__characters[j].draw()
def __goto_closest_wall(self, index: int, stage: Stage) -> Tuple[Direction, int]: wall, movement, distance = \ stage.closest_wall_to(self.__characters[index]) if self.__characters[index].would_collide(wall, movement): self.__characters[index].arrived_home() return (0, 0) return movement, distance
def __initialize_stage(self, window_size: Size, window_title: str, stage_size: Size, stage_colors: Tuple[Color, Color], clock_font: Font, clock_font_color: Color, text_font: Font) -> Stage: stage = Stage(window_size, window_title, stage_size, stage_colors, clock_font, clock_font_color, text_font) pygame.display.update() return stage
def addStage(self, type_sampling='MH', limit_time=10, limit_samples=100, name_stage='default_name', type_proposal='Gauss', proposalStd=0.5): if name_stage == 'default_name': name_stage += str(len(self.stages)) s = Stage(type_sampling, limit_time, limit_samples, name_stage, type_proposal, proposalStd) self.stages.append(s)
def __init__(self, bus, device, position): Stage.__init__(self, position) self.position = position self.bus = bus self.device = device self.home = 6000 #self.axis = axis #stageAxis = axis #axis = spidev.SpiDev() #axis.open(bus, device) #axis.mode = 0b01 #axis.max_speed_hz = 1000000 #this is definitely not the right way to do this. Should do something with self here. axis = spidev.SpiDev() axis.open(self.bus, self.device) axis.mode = 0b01 axis.max_speed_hz = 1000000 self.axis = axis
def load_stage(name): normal_font = pygame.font.SysFont("calibri", 27) stages_dir = Path("stages") file_path = stages_dir / (name + ".txt") raw_arr = read_from_file(file_path) opening = raw_arr['opening'] opening_arr = parse_str(opening) buttons = init_buttons(raw_arr) return Stage(opening_arr, buttons)
def __init__(self, screen, saved=None): Stage.__init__(self, screen) temprect = pygame.Rect((0, 0), (1220, 800)) self.robot_creator = Robot_Creator(screen, temprect.center) self.focused = None self.global_objects.append(self.robot_creator) self.mouse_objects = [] self.mouse = MouseEvents(self.mouse_objects) self.mouse_objects.append( Distance_Sensor_Creator(self.screen, self.mouse, self, (100, 100))) self.mouse_objects.append( Electromagnetic_Sensor_Creator(self.screen, self.mouse, self, (100, 150))) self.mouse_objects.append( Capacitive_Sensor_Creator(self.screen, self.mouse, self, (100, 200))) if saved != None: listLoad = self.load_robot(saved) #print listLoad self.mouse_objects.extend(listLoad) self.global_objects.extend(self.mouse_objects) #print self.global_objects self.color_HIGHLIGHT = (255, 255, 0)
def __init__(self, screen): Stage.__init__(self, screen) self.key_handlers = { pygame.K_UP: self.cursor_up, pygame.K_DOWN: self.cursor_down, pygame.K_LEFT: self.cursor_left, pygame.K_RIGHT: self.cursor_right, pygame.K_ESCAPE: self.end, pygame.K_KP_ENTER: self.choose_this, pygame.K_RETURN: self.choose_this } self.all_buttons = [] # fill list with buttons x = 20 y = 20 # random self.all_buttons.append( ListButton(screen, x, y, "AI_17", self.algorithms[0])) self.all_buttons[0].cursor_here = True self.cursored = 0 y += ListButton.height self.all_buttons.append( ListButton(screen, x, y, "AI_JED", self.algorithms[1]))
def __init__(self, config): self.task_queue: Queue = Queue() self.arduino_type: str = config['arduino_type'] self.telemetry: Telemetry = Telemetry.from_config( config['telemetry'], self.task_queue.put) self.sensors: SensorMap = SensorMap.from_config( config['sensors'], self.arduino_type) self.valves: ValveMap = ValveMap.from_config(config['valves'], self.arduino_type) self.delay: float = config['timer']['delay'] self.start_time: float = None self.hard_abort: bool = False self.soft_abort: bool = False self.task_executor: Thread = Thread(target=self.execute_tasks, daemon=True) self.stage: Stage = Stage('stage_1')
def redraw(stage): """ ステージを書き直す """ #:HACK new_stage = Stage() for y_i in range(1, stage.YMax - 1): for x_j in range(1, stage.XMax - 1): #生命が存在しないとき if stage[y_i][x_j] == 0: new_stage[y_i][x_j] = LifeGameRules.rule_1(stage, x_j, y_i) #生命が存在するとき elif stage[y_i][x_j] == 1: new_stage[y_i][x_j] = LifeGameRules.rule_2(stage, x_j, y_i) return new_stage
def main(): #ステージの設立 generation_stage = Stage() #初期化 generation_stage = big_bang(generation_stage) #ゲームスタート while True: try: #可視化 visalize(generation_stage) #ライフゲームのルールに則り、変化 generation_stage = redraw(generation_stage) #コマ送り key = input() #ctrl + C で終了 except KeyboardInterrupt: print('end of game') break
def test_system(theta: float) -> int: rocket = Rocket.saturn_v( Stage(123000 - 36135, 123000, last_dur, 165 * 1000000 / last_dur)) rocket.velocity = np.array((-460, 0)) rocket.theta = 2 * np.pi * theta / 360 earth = Body(5.97e24, 12756e3 / 2, (0, 0), (0, 0), (0.0, 0.0, 7.292115053925690e-05)) ss = SolarSystem(dt / 10.0, tol) ss.add_body(earth) ss.add_body(rocket) t = 0 while rocket.dist(earth) < earth.radius * 1.1: try: ss.step(dt) t += dt if t >= 56540: return 0 # orbit except ZeroDivisionError: return -1 # crash into earth return 1 # escape from earth
def test_system(theta: float) -> int: earth = Body(5.97e24, 12756e3 / 2, (0, 0), (0, 0), (0.0, 0.0, 7.292115053925690e-05)) rocket = Rocket.saturn_v(Stage(13500, 13500 + 36135, 0, 0)) rocket.theta = 2 * np.pi * theta / 360 rocket.velocity = np.array((-earth.speed_at_surface(), 0.0)) ss = SolarSystem(dt / 10.0, 1e-14) ss.add_body(earth) ss.add_body(rocket) while True: try: ss.step(dt) if rocket.t >= 25000: return 0 # orbit except ValueError: # crash into earth # probably not the best metric to use, but simple and it works pretty well if rocket.t < 3000: return -1 else: return 1
vm = np.sqrt(G * (m + n) / rm) # Moon orbital velocity around barycenter ve = vm * n / m # Earth orbital velocity around barycenter moon = Body(n, 3475e3 / 2, (rm, 0.0), (0.0, vm), (0.0, 0.0, 2.6617e-06)) earth = Body(m, 12756e3 / 2, (-re, 0.0), (0.0, -ve), (0.0, 0.0, 7.29212e-05)) burn_angle = 2 * np.pi * 225 / 360 # 225 for free return trajectory, 224 for crash into moon rocket = Rocket( 1.95, (earth.coord[0] + np.cos(burn_angle) * (earth.radius + 300e3), earth.coord[1] + np.sin(burn_angle) * (earth.radius + 300e3)), (earth.velocity[0] + np.cos(burn_angle + np.pi / 2) * 7.731e3, earth.velocity[1] + np.sin(burn_angle + np.pi / 2) * 7.731e3), 0.0011577, (np.cos(burn_angle + np.pi / 2), np.sin(burn_angle + np.pi / 2))) rocket.add_stage( Stage(11900, 28800, 100, 248500)) # values somewhat based on csm values, but adjusted # Earth moon ss.add_body(moon) # The Moon ss.add_body(earth) # The Earth ss.add_body(rocket) # Visualization fig = plot.figure() axes = fig.add_subplot(111, aspect='equal', autoscale_on=True, xlim=(-6e8, 6e8), ylim=(-6e8, 6e8)) body_count = len(ss.bodies)
def get_user_stage(self, user_id): stage_code = self.__stages.get(user_id) if not stage_code: return None return Stage(int(stage_code))
class Game: running = True screen = None background = None player = None bullet = None enemies = None explosion = None caption = None game_text = None score = None stage = None def start(self): pygame.init() self.screen = pygame.display.set_mode((800, 600)) self.stage = Stage(self) self.background = Background(self) self.player = Player(self) self.bullet = Bullet(self) self.enemies = Enemies(self) self.game_text = GameText(self) self.explosion = Explosion(self) self.caption = Caption(self) self.score = Score(self) self.next_stage() while self.running: self.screen.fill((0, 0, 0)) self.background.show() self.handle_event() self.player.move() self.bullet.move() self.enemies.move() self.score.show() self.stage.show() self.check_win() pygame.display.update() def handle_event(self): for event in pygame.event.get(): if event.type == pygame.QUIT: self.running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: self.player.move_left() if event.key == pygame.K_RIGHT: self.player.move_right() if event.key == pygame.K_SPACE: self.bullet.fire(self.player.x, self.player.y) if event.key == pygame.K_RETURN: self.next_stage() if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: self.player.stop_move() def check_win(self): if self.enemies.finished(): self.game_text.show_win() self.game_text.show_enter() def loose(self): self.game_text.show_loose() def next_stage(self): if not self.enemies.finished(): return if not self.stage.next(): return self.background.load() self.player.load() self.bullet.load() self.enemies.load() self.game_text.load() self.explosion.load() self.caption.load() self.score.load()
temp = [["O", "O", "O", "O", "O", "O"], ["O", "O", "O", "O", "O", "O"], ["O", "O", "O", "O", "O", "O"], ["O", "O", "O", "O", "O", "O"], ["O", "O", "O", "O", "O", "O"], ["O", "O", "O", "O", "O", "O"], ["O", "O", "O", "O", "O", "O"], ["O", "O", "O", "O", "O", "O"]] colors = ["blue", "green", "orange", "purple", "red", "yellow"] size = (len(temp[0])*JEWELSIZE+100, len(temp)*JEWELSIZE+100) windowObj = pygame.display.set_mode(size) pygame.display.set_caption("Joalheiro") stg = Stage(temp, colors, windowObj, fpsClock) font = pygame.font.SysFont(None, 48) while True: windowObj.fill(pygame.Color(255, 255, 255)) stg.draw(font) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == MOUSEBUTTONDOWN: x, y = event.pos stg.click(x, y)
def step_state(Event_list): #Problem print('This is step_state') Stage(Chest, Head) return ("Trans", Event_list)
def test_download_files(self): stage = Stage() stage.download_zip_file(url=) if not os.path.exists(stage.get_downloads_location()): self.fail()
def build(self): Window.size = (600, 600) s = Stage('images1/') return s
import numpy as np import math as ma import time from matplotlib import animation import matplotlib.pyplot as plot from matplotlib.patches import Circle from mpl_toolkits.axes_grid1.anchored_artists import AnchoredDrawingArea from Rocket import Rocket from Body import Body from SolarSystem import SolarSystem from Stage import Stage rocket = Rocket.saturn_v( Stage(123000 - 36135, 123000, 165, 165 * 1000000 / 165)) rocket.theta = 2 * np.pi * 0 / 360 rocket.velocity = np.array((-460.0, 0.0)) earth = Body(5.97e24, 12756e3 / 2, (0, 0), (0, 0), (0.0, 0.0, 7.292115053925690e-05)) dt = 24 * 1. / 60 ss = SolarSystem(dt / 10.0, 1e-14) ss.add_body(earth) ss.add_body(rocket) # Visualization fig = plot.figure() axes = fig.add_subplot(111, aspect='equal', autoscale_on=True,
Demand = Demand() Fleet = Fleet() airportsList = Airports.airportsList STAGE_RESOLUTION = 6 # 6 minutes TOTAL_HOURS = 120 numberOfStages = int(TOTAL_HOURS * 60 / STAGE_RESOLUTION + 1) for type, aircraft in Fleet.aircraftList.items(): print("Aircraft type: ", type) stagesList = [None] * numberOfStages # create last stage and add HUB node airportHUB = airportsList[Airports.HUB] lastStage = Stage(TOTAL_HOURS, numberOfStages - 1) lastStage.addNode(airportHUB) stagesList[-1] = lastStage print("Creating stages and nodes...") # create other stages for i in range(1, numberOfStages): stageTime = TOTAL_HOURS - i * 0.1 stageNumber = numberOfStages - i - 1 newStage = Stage(stageTime, stageNumber) stagesList[stageNumber] = newStage # for each stage create airport nodes newStage.addNode(airportHUB) for IATA, airport in Airports.airportsList.items(): # only add airport nodes to stage that have the runway required
Update(options) elif options.action == 'status': from Info import Status pyhg_action = Status() elif options.action == 'log': from Info import Log Log(options) elif options.action == 'incoming': from Incoming import Incoming Incoming(options) elif options.action == 'commit': from Commit import Commit Commit(options) elif options.action == 'stage': from Stage import Stage Stage(options) elif options.action == 'unstage': from Stage import Unstage Unstage(options) elif options.action == 'staged': from Stage import Staged pyhg_action = Staged() elif options.action == 'rebase': from Rebase import Rebase Rebase(options) # elif options.action == 'backup': # from Backup import Backup # Backup(options) elif options.action == 'shelve': from Shelf import Shelve pyhg_action = Shelve()
config.EMULATOR.BOTTOM, config.EMULATOR.RIGHT), window_name = config.EMULATOR.WINDOW_NAME, keylog_length = config.KEYLOG.MAXLEN, logdir = join(here,config.EMULATOR.LOGDIR)) print emulator #Define stage stage = Stage(box = Box(config.STAGE.TOP, config.STAGE.LEFT, config.STAGE.BOTTOM, config.STAGE.RIGHT), controller_box = controller.box, emulator_box = emulator.box, keylog_box = Box(config.KEYLOG.TOP, config.KEYLOG.LEFT, config.KEYLOG.BOTTOM, config.KEYLOG.RIGHT), keylog_step = config.KEYLOG.STEP, infopanel_box = Box(config.INFOPANEL.TOP, config.INFOPANEL.LEFT, config.INFOPANEL.BOTTOM, config.INFOPANEL.RIGHT), infopanel_text = config.INFOPANEL.TEXT) stage_frame = stage.init_stage_frame() print stage #Define stream if hasattr(config, 'STREAM'): stream = Stream(stage = stage, emulator = emulator,
def __init__(self, parent=None): QGraphicsScene.__init__(self, parent) # hold the set of keys we're pressing self.keys_pressed = set() # use a timer to get 60Hz refresh (hopefully) 1000 / 16 == 62.5 self.timer = QBasicTimer() self.timer.start(FRAME_TIME_MS, self) # bg = QGraphicsRectItem() # bg.setRect(-1,-1,SCREEN_WIDTH+2,SCREEN_HEIGHT+2) # bg.setBrush(QBrush(Qt.black)) # BackGround self.bg = BackGround() self.addItem(self.bg) # Stage self.stage = Stage() self.addItem(self.stage) # Player self.player = Player() self.player.setPos((SCREEN_WIDTH - self.player.pixmap().width()) / 2, (SCREEN_HEIGHT - self.player.pixmap().height()) / 2) self.addItem(self.player) # Player Life self.playerIcon = PlayerIcon() self.xIcon = XIcon() self.life = Life() self.playerIcon.setPos(20, 20) self.xIcon.setPos(60, 25) self.life.setPos(83, 24) self.addItem(self.playerIcon) self.addItem(self.xIcon) self.addItem(self.life) # Bullets self.bullets = [ Bullet(PLAYER_BULLET_X_OFFSETS[0], PLAYER_BULLET_Y), Bullet(PLAYER_BULLET_X_OFFSETS[1], PLAYER_BULLET_Y - 30), Bullet(PLAYER_BULLET_X_OFFSETS[2], PLAYER_BULLET_Y) ] for b in self.bullets: b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT) self.addItem(b) # Enemies self.enemies = [Enemy()] self.enemies[0].setPos(SCREEN_WIDTH, 0) self.addItem(self.enemies[0]) self.idx = [0] # Execution Point self.EXP = EXP() self.EXP.score = 8 self.EXP.setPos(SCREEN_WIDTH - 40, 20) self.addItem(self.EXP) self.EXP1 = EXP() self.EXP1.score = 1 self.EXP1.setPos(SCREEN_WIDTH - 60, 20) self.addItem(self.EXP1) self.view = QGraphicsView(self) self.view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.view.show() self.view.setFixedSize(SCREEN_WIDTH, SCREEN_HEIGHT) self.setSceneRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) self.ask = AskClose(self)