Ejemplo n.º 1
0
def create_star(ai_settings, screen, stars, star_number, row_number):
    """Создает звезду и размещает его в ряду."""
    star = Star(ai_settings, screen)
    star_width = star.rect.width
    star.x = star_width + 4 * star_width * star_number + randint(-32, 32)
    star.rect.x = star.x
    star.rect.y = star.rect.height + 4 * star.rect.height * \
                   row_number + randint(-32,32)
    stars.add(star)
Ejemplo n.º 2
0
def create_star(ai_settings, screen, stars, x_number, y_number):
    random_star = random.randint(0, 3)
    star = Star(ai_settings, screen, random_star)
    star_width = star.rect.width
    star_height = star.rect.height

    star.x = 2 * star_width * x_number + star_width * (random.randint(-8, 8) / 16 + 1)
    star.y = 2 * star_height * y_number + star_height * random.randint(0, 16) / 16

    star.rect.x = star.x
    star.rect.y = star.y
    stars.add(star)
Ejemplo n.º 3
0
def create_star(ai_settings, screen, stars):
    """Add stars to the group until it reach its limit"""
    count = 0
    while count < ai_settings.star_max:
        new_star = Star(ai_settings, screen)
        stars.add(new_star)
        count += 1
    def _create_star(self, x, y):
        star = Star(self)

        star.rect.x = x
        star.rect.y = y

        self.stars.add(star)
Ejemplo n.º 5
0
 def __init__(self):
     '''初始化游戏'''
     Settings.__init__(self)
     # boom init
     self.booms = Group()
     self.ship_boom = Boom1()
     self.boom_count = 0
     # background
     self.background_picture = "images/background_1.jpg"
     self.background_arrow = 0
     # music init
     self.music_count = 0
     # screen init
     self.screen_size = (self.screen_width, self.screen_height)
     # stars init
     self.stars = Group()
     for i in range(self.num_stars):
         new_star = Star()
         self.stars.add(new_star)
         pass
     # ship
     self.ship = Ship()
     self.ship_bullets = Group()
     # aliens
     self.aliens = Group()
     self.aliens_bullets = Group()
     pass
Ejemplo n.º 6
0
def create_stars(ai_settings, screen, stars):
    star = Star(ai_settings, screen, random.randint(0, 3))
    number_stars_x, number_stars_y = get_number_stars_x_y(ai_settings, star.rect.width,
                                                          star.rect.height)

    for x_number in range(number_stars_x):
        for y_number in range(number_stars_y):
            create_star(ai_settings, screen, stars, x_number, y_number)
Ejemplo n.º 7
0
def parse_line(line, name):
    alpha = convert_hours_to_angle(line[4:14].replace(' ', '0'))
    delta = convert_str_to_angle(line[16:24].replace(' ', '0'))
    if line[15] == '-':
        delta = -delta
    delta = 90 - delta
    color = line[49]
    let = line[103:106]
    m = float(line[41:46].replace(' ', '0'))
    return Star(spherical_to_decart(alpha, delta), color, m, name, GREEK[let])
Ejemplo n.º 8
0
def add_star(ai_settings, screen, stars):
	'''Создает звезды'''

	star = Star(screen, ai_settings)

	available_space_x = ai_settings.screen_width - 25
	number_star_x = int(available_space_x/15)

	available_space_y = ai_settings.screen_height - 25
	number_rows = int(available_space_y / 15)

	for row_number in range(12):
		for star_number in range(17):
			star = Star(screen, ai_settings)


			star.rect.x = 50 * star_number + randint(-20, 20)
			star.rect.y = 50 * row_number + randint(-20, 20)
			stars.add(star)
Ejemplo n.º 9
0
def create_many_stars(ai_settings, screen, ship, stars):
    """Создает звёзды."""
    # Создание звезды и вычисление количества заёзд в ряду.
    star = Star(ai_settings, screen)
    number_stars_x = get_number_stars_x(ai_settings, star.rect.width)
    number_rows = get_number_star_rows(ai_settings, ship.rect.height,
                                       star.rect.height)
    # Создание множества звёзд.
    for row_number in range(number_rows):
        for star_number in range(number_stars_x):
            create_star(ai_settings, screen, stars, star_number, row_number)
    def _create_stars_grid(self):
        """Создание сетки звёзд"""

        # Создание одной звезды
        star = Star(self)

        avaible_star_space_x = self.settings.screen_width
        avaible_star_space_y = self.settings.screen_height

        star_height = star.rect.y
        star_width = star.rect.x

        i = 0

        star_x = [0]
        star_y = [0]
        for i in range(60):
            cur_pos_x = randrange(0, 1900, 50)
            cur_pos_y = randrange(0, 1080, 45)
            for x in star_x:
                if cur_pos_x == x:
                    cur_pos_x = randrange(0, 1900, 50)
                    star_x.append(cur_pos_x)
                    break
                else:
                    star_x.append(cur_pos_x)
                    break

            for y in star_y:
                if cur_pos_y == y:
                    cur_pos_y = randrange(0, 1080, 45)
                    star_y.append(cur_pos_y)
                    break
                else:
                    star_y.append(cur_pos_y)
                    break
            if star_x[i] == 0 and star_y[i] == 0:
                star.remove()

            else:
                self._create_star(star_x[i], star_y[i])
def creat_bg(ai_settings, screen, stars):

    star = Star(ai_settings, screen)
    star_width = star.rect.width
    number_rows = get_star_row_number(star, ai_settings)
    star_numbers = get_star_number_x(star, ai_settings)

    if len(stars) <= 400:
        for star_y in range(number_rows):
            for star_x in range(star_numbers):
                creat_star(ai_settings, screen, star_y, star_x,
                           star.rect.width, star.rect.height, stars)
Ejemplo n.º 12
0
def create_stars_background(ai_settings, screen, stars):
    """Create a full screen of stars"""
    star = Star(screen)

    if len(stars) < 50:
        for star_number in range(1):
            star = Star(screen)
            star.x = randint(0, ai_settings.screen_width)
            star.y = randint(0, ai_settings.screen_height)
            star.rect.x = star.x
            star.rect.y = star.y
            stars.add(star)
Ejemplo n.º 13
0
def main(input_file):

    with open(input_file, 'r') as f:
        lines = f.readlines()

    stars_not_in_const = []
    for line in lines:
        x, y, z, w = [int(a) for a in line.split(',')]
        stars_not_in_const.append(Star(x, y, z, w))

    constellations = []
    while len(stars_not_in_const) > 0:

        # Create new const
        new_const = Constellation()
        new_const.add_star(stars_not_in_const.pop(0))

        for star in new_const.stars:
            # add to the constellation all non-placed stars
            # which are in distance with a star of the constellation

            # search for nearby stars
            remaining_stars = copy(stars_not_in_const)
            for star2 in stars_not_in_const:
                if star.manhattan_dist(star2) <= 3:
                    new_const.add_star(star2)
                    remaining_stars.remove(star2)

                stars_not_in_const = remaining_stars

        constellations.append(new_const)

    print('PART 1')
    print('List of constellations:')
    for i, c in enumerate(constellations):
        print(f'- Constellation {i}: {c}')

    print()
    print(f'Number of constellations = {len(constellations)}')
Ejemplo n.º 14
0
def create_star_and_vz(stars, vzs, screen, ai_settings, num):
    star = Star(screen, stars, ai_settings, num)
    vz = Visualization(screen, ai_settings, star)

    stars.add(star)
    vzs.add(vz)
Ejemplo n.º 15
0
    def _build(self, review_data, app_version, logged_in_person, useful_votes):
        # all the attributes of review_data may need markup escape,
        # depending on if they are used as text or markup
        self.id = review_data.id
        self.person = review_data.reviewer_username
        displayname = review_data.reviewer_displayname
        # example raw_date str format: 2011-01-28 19:15:21
        cur_t = self._get_datetime_from_review_date(review_data.date_created)

        review_version = review_data.version
        self.useful_total = useful_total = review_data.usefulness_total
        useful_favorable = review_data.usefulness_favorable
        useful_submit_error = review_data.usefulness_submit_error
        delete_error = review_data.delete_error
        modify_error = review_data.modify_error

        # upstream version
        version = GLib.markup_escape_text(upstream_version(review_version))
        # default string
        version_string = _("For version %(version)s") % {
            'version': version,
        }
        # If its for the same version, show it as such
        if (review_version and app_version and upstream_version_compare(
                review_version, app_version) == 0):
            version_string = _("For this version (%(version)s)") % {
                'version': version,
            }

        m = '<small>%s</small>'
        self.version_label.set_markup(m % version_string)

        m = self._whom_when_markup(self.person, displayname, cur_t)
        who_when = Gtk.Label()
        who_when.set_name("subtle-label")
        who_when.set_justify(Gtk.Justification.RIGHT)
        who_when.set_markup(m)

        summary = Gtk.Label()
        try:
            s = GLib.markup_escape_text(review_data.summary.encode("utf-8"))
            summary.set_markup('<b>%s</b>' % s)
        except Exception:
            LOG.exception("_build() failed")
            summary.set_text("Error parsing summary")

        summary.set_ellipsize(Pango.EllipsizeMode.END)
        summary.set_selectable(True)
        summary.set_alignment(0, 0.5)

        text = Gtk.Label()
        text.set_text(review_data.review_text)
        text.set_line_wrap(True)
        text.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
        text.set_selectable(True)
        text.set_alignment(0, 0)

        stars = Star()
        stars.set_rating(review_data.rating)
        a = Gtk.Alignment.new(0.5, 0.5, 0, 0)
        a.add(stars)

        self.header.pack_start(a, False, False, 0)
        self.header.pack_start(summary, False, False, 0)
        self.header.pack_end(who_when, False, False, 0)
        self.body.pack_start(text, False, False, 0)

        current_user_reviewer = False
        if self.person == self.logged_in_person:
            current_user_reviewer = True

        self._build_usefulness_ui(current_user_reviewer, useful_total,
                                  useful_favorable, useful_votes,
                                  useful_submit_error)

        self.flagbox = Gtk.HBox()
        self.flagbox.set_spacing(4)
        self._build_delete_flag_ui(current_user_reviewer, delete_error,
                                   modify_error)
        self.footer.pack_end(self.flagbox, False, False, 0)

        # connect network signals
        self.connect("realize", lambda w: self._on_network_state_change())
        watcher = get_network_watcher()
        watcher.connect("changed",
                        lambda w, s: self._on_network_state_change())
Ejemplo n.º 16
0
pygame.display.set_caption("Elements Game")

all_sprites_list = pygame.sprite.Group()

all_flying = pygame.sprite.Group()

# ----------------------------------------------------------------------------
# This group stores the instances of all asteroids. There are always three of
# them. It is global as it is referred to in the main while loop 'carryOn'.
# ----------------------------------------------------------------------------
all_asteroids = pygame.sprite.Group()

# === Create background stars ===
for i in range(1, 40):
    surface2 = pygame.Surface([20, 20], pygame.SRCALPHA)
    newstar = Star(surface2, WHITE, (10, 10), random.randint(1, 2),
                   20)  # surface, colour, position, radius, speed
    all_flying.add(newstar)
    all_sprites_list.add(newstar)

# === initalise font object to render text later ===
font = pygame.font.Font('OpenSans-Semibold.ttf', 24)

carryOn = True
clock = pygame.time.Clock()

# === Two menu screens before main game ===

selection = game_difficulty(screen, BLACK, WHITE, BLUE, font, WIDTH, HEIGHT,
                            Star, clock)

username = game_intro(WIDTH, HEIGHT, screen, BLACK, WHITE, font, Star, clock)
Ejemplo n.º 17
0
def create_stars(ai_settings,screen,stars):
    for _ in range(ai_settings.stars_number):
        star=Star(ai_settings,screen)
        stars.add(star)
    return stars
def creat_star(ai_settings, screen, star_y, star_x, star_width, star_height,
               stars):
    star = Star(ai_settings, screen)
    star.rect.x = (star_width + 5 * star_width * star_x + randint(-20, 20))
    star.rect.y = -(star_height + 5 * star_height * star_y + randint(-20, 20))
    stars.add(star)
Ejemplo n.º 19
0
class Prediction(object):
    def __init__(self, body, date='2001-01-01', time='00:00:00'):
        self.setBody(body)
        self.setReferenceDateTime('2001-01-01', '00:00:00')
        self.setObservationDateTime(date, time)
        self.refGHA = Angle.parse('100d42.6')

    def setBody(self, body):
        self.star = Star(body)

    def setObservationDateTime(self, date, time):
        obsDate = datetime.strptime(date + ' ' + time, '%Y-%m-%d %H:%M:%S')
        if hasattr(self, 'refDate') and obsDate < self.refDate:
            raise ValueError('observation date > reference date')
        self.obsDate = obsDate

    def setReferenceDateTime(self, date, time):
        refDate = datetime.strptime(date + ' ' + time, '%Y-%m-%d %H:%M:%S')
        if hasattr(self, 'obsDate') and self.obsDate < refDate:
            raise ValueError('observation date > reference date')
        self.refDate = refDate

    def cumulativeProgression(self):
        return (self.obsDate.year - self.refDate.year) \
            * float(Angle.parse('-0d14.31667'))

    def leapProgression(self):
        leap = 0
        for i in xrange(self.refDate.year, self.obsDate.year):
            leap += 1 if i % 4 == 0 and (i % 100 != 0 or i % 400 == 0) else 0
        return 0.9829167 * leap

    def ariesGHA(self):
        return float(Angle(float(self.refGHA) + self.cumulativeProgression() \
            + self.leapProgression() + self.rotationAngle())
            .normalize(0.0, 360.0))

    def rotationAngle(self):
        return (self.obsDate - datetime(self.obsDate.year,
            self.obsDate.month, 1)).total_seconds() \
            / 86164.1 * 360.0

    def starGHA(self):
        return Angle(
            float(
                Angle(self.ariesGHA() + float(self.star.getSHA())).normalize(
                    0.0, 360.0)))

    def starDeclination(self):
        return self.star.getDeclination()

    @classmethod
    def dispatch(Prediction, values):
        try:
            if 'long' in values or 'lat' in values:
                raise ValueError('key "long" or "lat" can\'t be present')
            prediction = Prediction(
                values['body'],
                ('2001-01-01' if 'date' not in values else values['date']),
                ('00:00:00' if 'time' not in values else values['time']))
            values['long'], values['lat'] = str(prediction.starGHA()), \
                str(prediction.starDeclination())
        except Exception as e:
            values['error'] = str(e)
        return values
Ejemplo n.º 20
0
bossShipImages = [graphics.g_ships.boss01, graphics.g_ships.boss02, graphics.g_ships.boss03, graphics.g_ships.boss04]
explosionFrames = [graphics.g_explosion.explode01, graphics.g_explosion.explode02, graphics.g_explosion.explode03, graphics.g_explosion.explode04, graphics.g_explosion.explode05, graphics.g_explosion.explode06, graphics.g_explosion.explode07, graphics.g_explosion.explode08, graphics.g_explosion.explode09, graphics.g_explosion.explode10, graphics.g_explosion.explode11]
dropImages = [graphics.g_items.drop01, graphics.g_items.drop02, graphics.g_items.drop03, graphics.g_items.spaceman]
bulletImages = [graphics.g_bullets.bullet01, graphics.g_bullets.bullet02, graphics.g_bullets.bullet03, graphics.g_bullets.bullet04, graphics.g_bullets.bullet05]

# Create stars
for i in range(10):
    tmpX = random.getrandbits(7)
    tmpY = random.getrandbits(6)
    tmpSpd = random.getrandbits(2)
    if tmpSpd == 0:
        tmpSpd = 1
    tmpClr = random.getrandbits(4)
    if tmpClr == 0:
        tmpClr = 15
    starList.append(Star(tmpX, tmpY, tmpSpd, tmpClr))

# Create ship flames
for i in range(4):
    tmpX = playerPos[0] + random.getrandbits(3)
    tmpY = playerPos[0] + 20
    tmpSpd = random.getrandbits(3)
    if tmpSpd == 0:
        tmpSpd = 1
    if tmpClr == 0:
        tmpClr = 15
    flameList.append(Flames(tmpX, tmpY, tmpSpd))

# Create rocks
for i in range(6):
    tmpX = random.getrandbits(7)
Ejemplo n.º 21
0
    def _build(self, review_data, app_version, logged_in_person, useful_votes):
        # all the attributes of review_data may need markup escape,
        # depending on if they are used as text or markup
        self.id = review_data.id
        self.person = review_data.reviewer_username
        displayname = review_data.reviewer_displayname
        # example raw_date str format: 2011-01-28 19:15:21
        cur_t = self._get_datetime_from_review_date(review_data.date_created)

        review_version = review_data.version
        self.useful_total = useful_total = review_data.usefulness_total
        useful_favorable = review_data.usefulness_favorable
        useful_submit_error = review_data.usefulness_submit_error
        delete_error = review_data.delete_error
        modify_error = review_data.modify_error

        # upstream version
        version = GLib.markup_escape_text(upstream_version(review_version))
        # default string
        version_string = _("For version %(version)s") % {
            'version': version,
        }
        # If its for the same version, show it as such
        if (review_version and
                app_version and
                upstream_version_compare(review_version, app_version) == 0):
            version_string = _("For this version (%(version)s)") % {
                    'version': version,
            }

        m = '<small>%s</small>'
        self.version_label.set_markup(m % version_string)

        m = self._whom_when_markup(self.person, displayname, cur_t)
        who_when = Gtk.Label()
        who_when.set_name("subtle-label")
        who_when.set_justify(Gtk.Justification.RIGHT)
        who_when.set_markup(m)

        summary = Gtk.Label()
        try:
            s = GLib.markup_escape_text(review_data.summary.encode("utf-8"))
            summary.set_markup('<b>%s</b>' % s)
        except Exception:
            LOG.exception("_build() failed")
            summary.set_text("Error parsing summary")

        summary.set_ellipsize(Pango.EllipsizeMode.END)
        summary.set_selectable(True)
        summary.set_alignment(0, 0.5)

        text = Gtk.Label()
        text.set_text(review_data.review_text)
        text.set_line_wrap(True)
        text.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
        text.set_selectable(True)
        text.set_alignment(0, 0)

        stars = Star()
        stars.set_rating(review_data.rating)
        a = Gtk.Alignment.new(0.5, 0.5, 0, 0)
        a.add(stars)

        self.header.pack_start(a, False, False, 0)
        self.header.pack_start(summary, False, False, 0)
        self.header.pack_end(who_when, False, False, 0)
        self.body.pack_start(text, False, False, 0)

        current_user_reviewer = False
        if self.person == self.logged_in_person:
            current_user_reviewer = True

        self._build_usefulness_ui(current_user_reviewer, useful_total,
                                  useful_favorable, useful_votes,
                                  useful_submit_error)

        self.flagbox = Gtk.HBox()
        self.flagbox.set_spacing(4)
        self._build_delete_flag_ui(current_user_reviewer, delete_error,
            modify_error)
        self.footer.pack_end(self.flagbox, False, False, 0)

        # connect network signals
        self.connect("realize", lambda w: self._on_network_state_change())
        watcher = get_network_watcher()
        watcher.connect(
            "changed", lambda w, s: self._on_network_state_change())
Ejemplo n.º 22
0
def gen_stars(ai_settings, screen, stars):
    '''Generate stars that randomly appear at one edge of the screen and move left.'''
    # use a random function to randomly generate points for the start to appear
    if len(stars) < ai_settings.stars_allowed * 2:
        new_star = Star(ai_settings, screen)
        stars.add(new_star)
Ejemplo n.º 23
0
 def setBody(self, body):
     self.star = Star(body)