コード例 #1
0
ファイル: levels.py プロジェクト: WonkySpecs/valkyrie-game
 def initial_game_state(self):
     assets = self.asset_factory
     terrain = [
         Terrain(initial_pos=pygame.Vector2(-200, 800),
                 animations=assets.wall_animation(900, 100)),
         Terrain(initial_pos=pygame.Vector2(-200, 0),
                 animations=assets.wall_animation(20, 800)),
         Terrain(initial_pos=pygame.Vector2(700, 0),
                 animations=assets.wall_animation(50, 900)),
         Terrain(initial_pos=pygame.Vector2(300, 300),
                 animations=assets.wall_animation(50, 50)),
         Terrain(initial_pos=pygame.Vector2(200, 500),
                 animations=assets.platform_animation(300, 8),
                 platform=True),
         Terrain(initial_pos=pygame.Vector2(200, 600),
                 animations=assets.platform_animation(300, 8),
                 platform=True)
     ]
     background_layers = defaultdict(list)
     fence_width = 373
     for bg in [
             Background(assets.background(), pygame.Vector2(0, 0), 0),
             Background(assets.foothills(), pygame.Vector2(-50, 50), 15),
             Background(assets.mountains(), pygame.Vector2(-50, 50), 30),
             Background(assets.chain_fence(), pygame.Vector2(400, 1090), 1),
             Background(assets.chain_fence(),
                        pygame.Vector2(400 + fence_width, 1090), 1)
     ]:
         background_layers[bg.z].append(bg)
     state = GameState(
         player=Player(animations=assets.player_animations(),
                       initial_pos=pygame.Vector2(320, 550)),
         enemies=[
             *[
                 enemy_classes.AssaultSoldier(
                     initial_pos=pygame.Vector2(50 + x, 400),
                     move_speed=random.randint(3, 6),
                     animations=assets.assault_soldier_green())
                 for x in range(50, 600, 25)
             ]
         ],
         terrain=terrain,
         background_layers=background_layers,
         clock=pygame.time.Clock(),
         hud={'font': pygame.font.Font(None, 20)})
     return state
コード例 #2
0
explosion_animation = pyganim.PygAnimation(
    [('assets/asteroid_explode{}.png'.format(i + 1), 50) for i in range(4)],
    loop=False)

music = pygame.mixer.Sound('assets/Scene1.ogg')
music.play(-1)

# Groups
all_objects = pygame.sprite.Group()
plasmoids = pygame.sprite.Group()
meteors = pygame.sprite.Group()

explosions = []

# Game objects
background = Background()
player = Player(clock, plasmoids)

all_objects.add(background)
all_objects.add(player)
# plasmoids.add(Plasmoid(player.rect.midtop))

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit(0)

    screen.fill(WHITE)

    # background.update()
    Meteorite.process_meteors(clock, meteors)
コード例 #3
0
ファイル: catch_this.py プロジェクト: McRain26/git
import game_fuction as gf
from stats import GameStats
from button import Button

pygame.init()
pygame.display.set_caption('Catch This')
ct_settings = Settings()
screen = pygame.display.set_mode((ct_settings.width, ct_settings.height))
clock = pygame.time.Clock()
stats = GameStats(ct_settings)
sb = Scoreboard(ct_settings, stats, screen)
play_button = Button(screen, 'Play')

#Groups
friends = Group()
enemies = Group()
bonus = Group()

#Game objects
player = Player(ct_settings, screen)
background = Background(ct_settings, screen)

while True:
    gf.check_events(bonus, ct_settings, enemies, friends, play_button, player, sb, stats)
    if stats.game_active:
        player.update()
        gf.update_enemies(bonus, clock, ct_settings, enemies, friends, player, sb, stats)
        gf.update_friends(ct_settings, clock, sb, stats, player, friends)
        gf.update_bonus(bonus, clock, ct_settings, player, sb, stats)
    gf.update_screen(background, bonus, ct_settings, sb, screen, stats, play_button, player, friends, enemies)
    clock.tick(30)
コード例 #4
0
ファイル: main.py プロジェクト: mister025/JumperKillerGame
import pygame
import sys

from settings import SIZE
from game_objects import Player, Background, Mob


pygame.init()
pygame.display.set_caption("Surprise, mutherfucker!")

screen = pygame.display.set_mode(SIZE)
running = True

#Game objects
player = Player()
background = Background()

#Groups of sprites
all_sprites = pygame.sprite.Group()
bullets = pygame.sprite.Group()
mobs = pygame.sprite.Group()
for i in range(4):
    mob = Mob()
    mobs.add(mob)
    all_sprites.add(mob)


while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
コード例 #5
0
ファイル: Asteroid.py プロジェクト: Pallad/Asteroid
def StartGame():
    pygame.init()
    pygame.display.set_caption('TestGame')
    screen = pygame.display.set_mode(SIZE)
    clock = pygame.time.Clock()

    #Group objects
    objects = pygame.sprite.Group()
    bullets = pygame.sprite.Group()
    asteroids = pygame.sprite.Group()

    #Game objects
    player = Player(bullets, clock)
    background = Background()

    objects.add(background)
    objects.add(player)

    active = True

    while active:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                active = False

        #Respoun asteroid
        Asteroid.respoun(asteroids, clock)

        #Change state player
        objects.update()
        bullets.update()
        asteroids.update()

        #Collise
        pygame.sprite.groupcollide(bullets, asteroids, True, True)

        if pygame.sprite.spritecollide(player, asteroids, True):
            badaboom = BadaBoom(player.rect.midtop)
            badaboom.draw(screen)
            pygame.display.flip()
            pygame.time.delay(1000)
            active = False

        #Fill background
        screen.fill(COLOR_BACKGROUND)

        #Draw Background
        background.draw(screen)

        #Draw player
        player.draw(screen)

        #Draw bullet
        bullets.draw(screen)

        #Draw asteroid
        asteroids.draw(screen)

        #Show frame
        pygame.display.flip()

        # Delay game loop -- frame per second
        clock.tick(60)

    pygame.quit()
    sys.exit(0)
コード例 #6
0
    [('game_data/blue_explosion/1_{}.png'.format(i), 50) for i in range(17)],
    loop=False)

#Music
music = pygame.mixer.Sound('game_data/music/space.wav')
music.play(-1)

#Создадим группы в которых будем хранить все объекты
all_game_objects = pygame.sprite.Group()
plasmoids = pygame.sprite.Group()
meteors = pygame.sprite.Group()
explosions = []

#Добавляем объекты в нашу игру
player = Player(clock, plasmoids)
back = Background(clock)
plasmoid = Plasmoid(player.rect.midtop)

all_game_objects.add(back)
all_game_objects.add(player)
# all_game_objects.add(plasmoid)
# all_game_objects.add(Meteor())

#тело цикла для игры
while True:
    #Метод pygame.event.get() возвращает массив событий который происходит с окном
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit(0)

    #Изменяем фон на белый и следующей командой отображаем экран