Ejemplo n.º 1
0
 def object_line(self, start, end, height, img):
     for x in range(start, end, 32):
         object_f = arcade.Sprite(img, char_scaling)
         object_f.center_x = x
         object_f.center_y = height
         self.object_list.append(object_f)
Ejemplo n.º 2
0
    def setup(self):
        """ Set up the game and initialize the variables. """

        # Sprite lists
        self.player_list = arcade.SpriteList()
        self.wall_list = arcade.SpriteList()
        self.coin_list = arcade.SpriteList()

        # Set up the player
        self.player_sprite = arcade.Sprite(
            ":resources:images/animated_characters/female_person/femalePerson_idle.png",
            0.4)
        self.player_sprite.center_x = 64
        self.player_sprite.center_y = 270
        self.player_list.append(self.player_sprite)

        for x in range(0, 1000, 64):
            wall = arcade.Sprite("brickGrey.png", SPRITE_SCALING)
            wall.center_x = x
            wall.center_y = SCREEN_HEIGHT
            self.wall_list.append(wall)

        for x in range(0, 1000, 64):
            wall = arcade.Sprite("dirt.png", SPRITE_SCALING)
            wall.center_x = x
            wall.center_y = 0
            self.wall_list.append(wall)

        for y in range(0, 1000, 64):
            wall = arcade.Sprite("brickGrey.png", SPRITE_SCALING)
            wall.center_x = 0
            wall.center_y = y
            self.wall_list.append(wall)

        for y in range(0, 1000, 64):
            wall = arcade.Sprite("brickGrey.png", SPRITE_SCALING)
            wall.center_x = 1000
            wall.center_y = y
            self.wall_list.append(wall)

        wall = arcade.Sprite("bush.png", SPRITE_SCALING)
        wall.center_x = 300
        wall.center_y = 400
        self.wall_list.append(wall)

        wall = arcade.Sprite("bush.png", SPRITE_SCALING)
        wall.center_x = 600
        wall.center_y = 400
        self.wall_list.append(wall)

        wall = arcade.Sprite("bush.png", SPRITE_SCALING)
        wall.center_x = 400
        wall.center_y = 100
        self.wall_list.append(wall)

        coordinate_list = [[400, 40], [600, 340], [300, 340]]

        for coordinate in coordinate_list:
            wall = arcade.Sprite("dirt.png", SPRITE_SCALING)
            wall.center_x = coordinate[0]
            wall.center_y = coordinate[1]
            self.wall_list.append(wall)

        for item in range(50, 200, 2):
            random_number = random.randrange(6)
            if random_number > 4:
                wall = arcade.Sprite("brickGrey.png", SPRITE_SCALING)
                wall.center_x = item * 4
                wall.center_y = SCREEN_HEIGHT / 2
                self.wall_list.append(wall)

        for item in range(50, 200, 2):
            random_number = random.randrange(6)
            if random_number > 4:
                wall = arcade.Sprite("brickGrey.png", SPRITE_SCALING)
                wall.center_x = item * 4
                wall.center_y = SCREEN_HEIGHT / 3.5
                self.wall_list.append(wall)

        for item in range(50, 200, 2):
            random_number = random.randrange(6)
            if random_number > 4:
                wall = arcade.Sprite("brickGrey.png", SPRITE_SCALING)
                wall.center_x = item * 4
                wall.center_y = SCREEN_HEIGHT / 1.2
                self.wall_list.append(wall)

        for i in range(NUMBER_OF_COINS):

            coin_placed_successfully = False

            coin = arcade.Sprite("coinGold.png", SPRITE_SCALING)

            while not coin_placed_successfully:
                coin.center_x = random.randrange(SCREEN_WIDTH)
                coin.center_y = random.randrange(SCREEN_HEIGHT)

                wall_hit_list = arcade.check_for_collision_with_list(
                    coin, self.wall_list)

                coin_hit_list = arcade.check_for_collision_with_list(
                    coin, self.coin_list)

                if len(wall_hit_list) == 0 and len(coin_hit_list) == 0:
                    coin_placed_successfully = True

            self.coin_list.append(coin)

        self.physics_engine = arcade.PhysicsEngineSimple(
            self.player_sprite, self.wall_list)

        # Set the background color
        arcade.set_background_color(arcade.color.AMAZON)

        # Set the viewport boundaries
        # These numbers set where we have 'scrolled' to.
        self.view_left = 0
        self.view_bottom = 0
Ejemplo n.º 3
0
    def on_key_press(self, key, modifiers):
        """Called whenever a key is pressed. 
        TODO: More dynamic attacks/interactions"""

        if self.current_state == TITLE_SCREEN or self.current_state == GAME_WON:
            if key == arcade.key.SPACE:
                # Starts the game initially
                self.setup()
                self.current_state = GAME_RUNNING
        elif self.current_state == GAME_OVER:
            if key == arcade.key.SPACE:
                # Restarts after death
                self.setup()
                self.current_state = GAME_RUNNING

        if self.current_state == GAME_RUNNING:
            # Movement
            if self.player_sprite.movable:
                if key == arcade.key.UP:
                    self.player_sprite.change_y = MOVEMENT_SPEED
                    self.player_sprite.angle = 0
                elif key == arcade.key.DOWN:
                    self.player_sprite.change_y = -MOVEMENT_SPEED
                    self.player_sprite.angle = 180
                elif key == arcade.key.LEFT:
                    self.player_sprite.change_x = -MOVEMENT_SPEED
                    self.player_sprite.angle = 90
                elif key == arcade.key.RIGHT:
                    self.player_sprite.change_x = MOVEMENT_SPEED
                    self.player_sprite.angle = 270

                if key == arcade.key.SPACE and self.laser == True:
                    # Special Shooting (LASER)

                    laser = arcade.Sprite("Resources/laser.png",
                                          SPRITE_SCALING_LASER)
                    laser.health = 30
                    laser.height = SCREEN_HEIGHT / 2
                    laserDistFromPlayer = laser.height / 2 + 25
                    self.player_sprite.set_texture(0)

                    if self.player_sprite.angle == 0:
                        laser.center_x = self.player_sprite.center_x
                        laser.center_y = self.player_sprite.center_y + laserDistFromPlayer

                    elif self.player_sprite.angle == 180:
                        laser.center_x = self.player_sprite.center_x
                        laser.center_y = self.player_sprite.center_y - laserDistFromPlayer

                    elif self.player_sprite.angle == 90:
                        laser.center_x = self.player_sprite.center_x - laserDistFromPlayer
                        laser.center_y = self.player_sprite.center_y
                        laser.angle = 90

                    elif self.player_sprite.angle == 270:
                        laser.center_x = self.player_sprite.center_x + laserDistFromPlayer
                        laser.center_y = self.player_sprite.center_y
                        laser.angle = 270

                    self.laser_list.append(laser)
                #Big Bolts
                elif key == arcade.key.SPACE and self.bb > 0 and self.player_sprite.timer < 0:
                    bolt = arcade.Sprite("Resources/bolt.png",
                                         4 * SPRITE_SCALING_BOLT)
                    self.player_sprite.timer = 10
                    boltDistFromPlayer = 50
                    bolt.type = 1
                    self.bb = self.bb - 1
                    if self.bb == 0:
                        self.player_sprite.set_texture(0)
                        self.pow = False

                    if self.player_sprite.angle == 0:
                        bolt.center_x = self.player_sprite.center_x
                        bolt.center_y = self.player_sprite.center_y + boltDistFromPlayer
                        bolt.change_x = 0
                        bolt.change_y = 0.5 * BOLT_SPEED
                    elif self.player_sprite.angle == 180:
                        bolt.center_x = self.player_sprite.center_x
                        bolt.center_y = self.player_sprite.center_y - boltDistFromPlayer
                        bolt.change_x = 0
                        bolt.change_y = -0.5 * BOLT_SPEED
                    elif self.player_sprite.angle == 90:
                        bolt.center_x = self.player_sprite.center_x - boltDistFromPlayer
                        bolt.center_y = self.player_sprite.center_y
                        bolt.change_x = -0.5 * BOLT_SPEED
                        bolt.change_y = 0
                    elif self.player_sprite.angle == 270:
                        bolt.center_x = self.player_sprite.center_x + boltDistFromPlayer
                        bolt.center_y = self.player_sprite.center_y
                        bolt.change_x = 0.5 * BOLT_SPEED
                        bolt.change_y = 0
                    self.bolt_list.append(bolt)
                # General Shooting
                elif key == arcade.key.SPACE and self.player_sprite.timer < 0:
                    bolt = arcade.Sprite("Resources/bolt.png",
                                         SPRITE_SCALING_BOLT)
                    boltDistFromPlayer = 25
                    bolt.type = 0
                    self.player_sprite.timer = 10

                    if self.player_sprite.angle == 0:
                        bolt.center_x = self.player_sprite.center_x
                        bolt.center_y = self.player_sprite.center_y + boltDistFromPlayer
                        bolt.change_x = 0
                        bolt.change_y = BOLT_SPEED
                    elif self.player_sprite.angle == 180:
                        bolt.center_x = self.player_sprite.center_x
                        bolt.center_y = self.player_sprite.center_y - boltDistFromPlayer
                        bolt.change_x = 0
                        bolt.change_y = -BOLT_SPEED
                    elif self.player_sprite.angle == 90:
                        bolt.center_x = self.player_sprite.center_x - boltDistFromPlayer
                        bolt.center_y = self.player_sprite.center_y
                        bolt.change_x = -BOLT_SPEED
                        bolt.change_y = 0
                    elif self.player_sprite.angle == 270:
                        bolt.center_x = self.player_sprite.center_x + boltDistFromPlayer
                        bolt.center_y = self.player_sprite.center_y
                        bolt.change_x = BOLT_SPEED
                        bolt.change_y = 0
                    self.bolt_list.append(bolt)
 def setup(self):
     self.menu_list = arcade.SpriteList(use_spatial_hash=True)
     self.mouse_sprite = arcade.Sprite("pic/default/char.png", char_scaling)
     self.menu_line(96, 32, "pic/menu/back.png")  # back
     self.mouse_list = arcade.SpriteList()
     self.mouse_list.append(self.mouse_sprite)
Ejemplo n.º 5
0
    def setup(self):
        arcade.set_background_color((20, 20, 20))
        self.player_list = arcade.SpriteList()
        self.ambi = arcade.SpriteList()
        self.walls = arcade.SpriteList()
        self.gems = arcade.SpriteList()
        self.score = 0
        self.time = 0.0
        self.view_left = 0
        self.view_bottom = 0

        self.player_sprite = AnimatedSprite(scale=PLAYER_SCALE,
                                            center_x=90,
                                            center_y=80)
        self.player_sprite.stand_right_textures = []
        self.player_sprite.stand_left_textures = []
        self.player_sprite.walk_right_textures = []
        self.player_sprite.walk_left_textures = []
        self.player_sprite.jump_right_textures = []
        self.player_sprite.jump_left_textures = []
        self.player_sprite.stand_right_textures.append(
            arcade.load_texture("img/player_stand.png", scale=.8))
        self.player_sprite.stand_left_textures.append(
            arcade.load_texture("img/player_stand.png",
                                scale=.8,
                                mirrored=True))
        self.player_sprite.walk_right_textures.append(
            arcade.load_texture("img/player_walk1.png", scale=.8))
        self.player_sprite.walk_right_textures.append(
            arcade.load_texture("img/player_walk2.png", scale=.8))
        self.player_sprite.walk_left_textures.append(
            arcade.load_texture("img/player_walk1.png",
                                scale=.8,
                                mirrored=True))
        self.player_sprite.walk_left_textures.append(
            arcade.load_texture("img/player_walk2.png",
                                scale=.8,
                                mirrored=True))
        self.player_sprite.jump_right_textures.append(
            arcade.load_texture("img/player_jump.png", scale=.8))
        self.player_sprite.jump_left_textures.append(
            arcade.load_texture("img/player_jump.png", scale=.8,
                                mirrored=True))
        self.player_list.append(self.player_sprite)

        for row_index, row in enumerate(get_map("map.map")):
            for column_index, item in enumerate(row):

                x = 16 + column_index * 32
                y = SCREEN_HEIGHT - (16 + row_index * 32)
                if item == "0":  # empty space
                    continue
                elif item == "1":
                    self.walls.append(
                        arcade.Sprite("img/boxCrate_double.png",
                                      .25,
                                      center_x=x,
                                      center_y=y))
                elif item == "2":
                    self.walls.append(
                        arcade.Sprite("img/sandMid.png",
                                      .25,
                                      center_x=x,
                                      center_y=y))
                elif item == "3":
                    self.walls.append(
                        arcade.Sprite("img/sandCenter.png",
                                      .25,
                                      center_x=x,
                                      center_y=y))
                elif item == "4":
                    self.walls.append(
                        arcade.Sprite("img/sandCliff_left.png",
                                      .25,
                                      center_x=x,
                                      center_y=y))
                elif item == "5":
                    self.walls.append(
                        arcade.Sprite("img/sandCliff_right.png",
                                      .25,
                                      center_x=x,
                                      center_y=y))
                elif item == "8":
                    self.ambi.append(
                        arcade.Sprite("img/rock.png",
                                      .25,
                                      center_x=x,
                                      center_y=y))
                elif item == "9":
                    self.ambi.append(
                        arcade.Sprite("img/signRight.png",
                                      .5,
                                      center_x=x,
                                      center_y=y))

        self.physics = arcade.physics_engines.PhysicsEnginePlatformer(
            self.player_sprite, self.walls, .4)

        for __ in range(NUMBER_OF_GEMS):

            gem = arcade.Sprite("img/gemRed.png", .3)
            gem_placed = False

            while not gem_placed:
                gem.center_x = random.randrange(2200)
                gem.center_y = random.randrange(SCREEN_HEIGHT)

                wall_hit_list = len(
                    arcade.check_for_collision_with_list(gem, self.walls)) == 0
                gem_hit_list = len(
                    arcade.check_for_collision_with_list(gem, self.gems)) == 0
                player_hit_list = len(
                    arcade.check_for_collision_with_list(
                        gem, self.player_list)) == 0

                if wall_hit_list and gem_hit_list and player_hit_list:
                    gem_placed = True

            self.gems.append(gem)
Ejemplo n.º 6
0
 def setup(self):
     self.player = arcade.Sprite(filename="game/images/sonic.jpg",
                                 center_x=200,
                                 center_y=200,
                                 scale=0.2)
Ejemplo n.º 7
0
    def setup(self):
        self.upgradeButton1 = arcade.Sprite("upgrade.png")
        self.upgradeButton2 = arcade.Sprite("upgrade.png")
        self.upgradeButton3 = arcade.Sprite("upgrade.png")
        self.upgradeButton4 = arcade.Sprite("upgrade.png")
        self.upgradeButton5 = arcade.Sprite("upgrade.png")
        self.upgradeButton6 = arcade.Sprite("upgrade.png")
        self.upgradeButton7 = arcade.Sprite("upgrade.png")
        self.upgradeButton8 = arcade.Sprite("upgrade.png")
        self.upgradeButton9 = arcade.Sprite("upgrade.png")
        self.upgradeButton10 = arcade.Sprite("upgrade.png")
        self.upgradeButton11 = arcade.Sprite("upgrade.png")
        self.upgradeButton12 = arcade.Sprite("upgrade.png")
        self.upgradeButton13 = arcade.Sprite("upgrade.png")
        self.upgradeButton14 = arcade.Sprite("upgrade.png")
        self.upgradeButton15 = arcade.Sprite("upgrade.png")
        self.upgradeButton16 = arcade.Sprite("upgrade.png")

        self.upgradeButtons = []
        self.upgradeButtons.append(self.upgradeButton1)
        self.upgradeButtons.append(self.upgradeButton2)
        self.upgradeButtons.append(self.upgradeButton3)
        self.upgradeButtons.append(self.upgradeButton4)
        self.upgradeButtons.append(self.upgradeButton5)
        self.upgradeButtons.append(self.upgradeButton6)
        self.upgradeButtons.append(self.upgradeButton7)
        self.upgradeButtons.append(self.upgradeButton8)
        self.upgradeButtons.append(self.upgradeButton9)
        self.upgradeButtons.append(self.upgradeButton10)
        self.upgradeButtons.append(self.upgradeButton11)
        self.upgradeButtons.append(self.upgradeButton12)
        self.upgradeButtons.append(self.upgradeButton13)
        self.upgradeButtons.append(self.upgradeButton14)
        self.upgradeButtons.append(self.upgradeButton15)
        self.upgradeButtons.append(self.upgradeButton16)

        for i in range(16):
            self.upgradeButtons[i].width = 85
            self.upgradeButtons[i].height = 25
            self.upgradeButtons[i].center_x = 200
            self.upgradeButtons[i].center_y = 591 - i * 37

        print(self.upgradeButton1.width)

        self.coinText = arcade.draw_text("Coins: " + str(self.coins), 395, 700,
                                         arcade.color.BLACK, 20)
        self.coinText.bold = True

        self.enemy2 = arcade.Sprite("enemy" + str(self.enemySprites) + ".png",
                                    8)
        #self.enemy2.width = 200
        #self.enemy2.height = 200
        self.enemy2.center_x = 650
        self.enemy2.center_y = 350

        print(self.level % 7)
        if gameview:
            # Set the background color

            arcade.set_background_color(arcade.color.DARK_BLUE)
            #### CONFIGURING ALL UPGRADE BUTTONS, MAY NOT NEED SPECIFIC VARIABLES IN THE FUTURE --> SEE IN NOTES BELOW ####

        if startview:
            arcade.set_background_color(arcade.csscolor.DARK_SLATE_BLUE)
            arcade.set_viewport(0, SCREEN_WIDTH - 1, 0, SCREEN_HEIGHT - 1)
Ejemplo n.º 8
0
 def setup(self):
     self.animal_sprite = arcade.Sprite("assets/moose.png", 0.5)
     self.animal_sprite.center_x = 400
     self.animal_sprite.center_y = 300
     self.animal_list.append(self.animal_sprite)
Ejemplo n.º 9
0
    def update(self, delta_time):
        self.time_elapsed += delta_time

        #movimento
        esquerda = abs(self.car.position[1] - esqYpos)
        if (esquerda > SCALE):
            esquerda = SCALE
        #print(esquerda)

        direita = abs(self.car.position[1] - dirYpos)
        if (direita > SCALE):
            direita = SCALE
        sensE = SENS_SCALE
        sensD = SENS_SCALE

        for cone in self.cone_list:
            if (cone.position[0] > self.car.position[0] - 55):
                if (cone.position[1] > self.car.position[1]):
                    #print("cone a esquerda")
                    sensE_ = math.sqrt(
                        (self.car.position[0] - cone.position[0])**2 +
                        (self.car.position[1] - cone.position[1])**2)
                    if (sensE_ < sensE):
                        sensE = sensE_
                else:
                    #print("cone a direita")
                    sensD_ = math.sqrt(
                        (self.car.position[0] - cone.position[0])**2 +
                        (self.car.position[1] - cone.position[1])**2)
                    if (sensD_ < sensD):
                        sensD = sensD_
        '''
        senHit = arcade.check_for_collision_with_list(self.sensorE, self.cone_list)
        if senHit:
            for cone in senHit:            
                if(cone.position[1]>self.car.position[1]):                    
                    print("cone a esquerda")                   
                    sensE_ = math.sqrt((self.car.position[0]-cone.position[0])**2+(self.car.position[1]-cone.position[1])**2)
                    if(sensE_<sensE):
                        sensE=sensE_

        senHit = arcade.check_for_collision_with_list(self.sensorD, self.cone_list)
        if senHit:
            for cone in senHit:       
                if(cone.position[1]<self.car.position[1]): 
                    print("cone a direita")                   
                    sensD_ = math.sqrt((self.car.position[0]-cone.position[0])**2+(self.car.position[1]-cone.position[1])**2)
                    if(sensD_<sensD):
                        sensD=sensD_
        '''

        direita /= SCALE
        esquerda /= SCALE

        self.entrada = [[
            esquerda, direita, sensE / SENS_SCALE, sensD / SENS_SCALE
        ]]

        saida = otimizador.predict(self.entrada)
        self.spdX_ = saida[0][0]
        self.spdY_esq = saida[0][1]
        self.spdY_dir = saida[0][2]
        #print("testando")

        speedX = TOP_SPEED * self.spdX_

        self.car.center_x = self.car.position[0] + speedX
        self.sensorD.center_x = self.sensorD.position[0] + speedX
        self.sensorE.center_x = self.sensorE.position[0] + speedX

        self.distance_car += speedX

        if (self.car.position[0] > 500):
            self.car.center_x = self.car.position[0] - speedX
            self.sensorD.center_x = self.sensorD.position[0] - speedX
            self.sensorE.center_x = self.sensorE.position[0] - speedX
            self.distance_map + speedX
            for cone in self.cone_list:
                cone.center_x = cone.position[0] - speedX
                if (cone.center_x <= 20):
                    cone.kill()

        speedY = TOP_SPEED_TURNING * (self.spdY_esq - self.spdY_dir)

        self.car.center_y = self.car.position[1] + speedY
        self.sensorD.center_y = self.sensorD.position[1] + speedY
        self.sensorE.center_y = self.sensorE.position[1] + speedY

        hit = arcade.check_for_collision_with_list(self.car,
                                                   self.barreira_list)

        #colidiu com parede/fundo
        if hit:
            print("colidiu")
            self.reset_log()
            #learn
            y_dir = self.spdY_dir
            y_esq = self.spdY_esq
            x_ = self.spdX_

            for fundo in hit:
                if (fundo.center_y == esqYpos):  #esquerda
                    print("esquerda")
                    y_esq = 0
                    y_dir = 1
                elif (fundo.center_y == dirYpos):  #direita
                    print("direita")
                    y_esq = 1
                    y_dir = 0
                elif (fundo.center_y == 300):  #fundo
                    print("fundo")
                    x_ = 0.7
                    y_esq = self.spdY_esq
                    y_dir = self.spdY_dir
                    #print(f"{self.spdX_} {self.spdY_esq-self.spdY_dir}")
            if (x_ < 0.01):
                x_ = 0.7
            #print(x_)
            y_esperado = [[x_, y_esq, y_dir]]

            print(f"{self.entrada} {y_esperado}")

            otimizador.train(self.entrada, y_esperado)

            #reset position
            self.resetCount += 1
            self.car.center_x = 80
            self.car.center_y = 300
            self.sensorD.center_x = 160
            self.sensorD.center_y = 285
            self.sensorE.center_x = 160
            self.sensorE.center_y = 315
            self.distance_car = 0
            self.trained = True
            for cone in self.cone_list:
                cone.kill()

        hit = arcade.check_for_collision_with_list(self.car, self.cone_list)
        if hit:  #colidiu com cone
            print("colidiu")
            self.reset_log()
            #learn
            y_dir = self.spdY_dir
            y_esq = self.spdY_esq
            x_ = self.spdX_

            for cone in hit:
                if (cone.center_y >= self.car.position[1]):  #esquerda
                    print("cone - esquerda")
                    #if() #se estava no canto direito
                    y_esq = 0.0
                    y_dir = 1
                    #x_ = 0.5
                elif (cone.center_y < self.car.position[1]):  #direita
                    print("cone - direita")
                    #if(esquerda<40): #se estava no canto esquerdo
                    y_esq = 1
                    y_dir = 0.0
                    #x_ = 0.5
            if (x_ < 0.05):
                x_ = 0.7

            y_esperado = [[x_, y_esq, y_dir]]

            #print("{self.entrada} {y_esperado}")

            otimizador.train(self.entrada, y_esperado)

            #reset position
            self.resetCount += 1
            self.car.center_x = 80
            self.car.center_y = 300
            self.distance_car = 0
            self.trained = True
            self.sensorD.center_x = 160
            self.sensorD.center_y = 285
            self.sensorE.center_x = 160
            self.sensorE.center_y = 315
            for cone in self.cone_list:
                cone.kill()
        '''
        #trigger de 1.5s
        if(self.time_elapsed>self.last):
            self.trigger=True        
            self.last+=1.5            
        '''
        #se nao treinou e ativou o trigger
        #if(self.trigger==True and self.trained==False):
        #if(self.trigger==True):
        if (abs(self.distance_car - self.last_checkUpX) < MIN_SPEED and
            (sensE >= SENS_SCALE or sensD >= SENS_SCALE)):  #checa se "parou"
            print("parou")
            self.reset_log()
            #learn
            x_ = 0.8
            y_esq = self.spdY_esq
            y_dir = self.spdY_dir
            y_esperado = [[x_, y_esq, y_dir]]

            #print("{self.entrada} {y_esperado}")
            otimizador.train(self.entrada, y_esperado)
            #reset position
            self.car.center_x = 80
            self.car.center_y = 300
            self.sensorD.center_x = 160
            self.sensorD.center_y = 285
            self.sensorE.center_x = 160
            self.sensorE.center_y = 315
            self.resetCount += 1
            self.distance_car = 0
            for cone in self.cone_list:
                cone.kill()
        else:
            self.last_checkUpX = self.distance_car
        #self.trained = False
        #self.trigger=False
        '''
        if(self.resetCount>=self.save):                    
            storage.save(nn, filepath=f"Saves/Rede1_4-3/motorista{amostra}_{CODINOME}_g{self.save}_d{self.maxDistance:.0f}.hdf5")
            self.save+= SAVE_SPAN
        '''
        if (self.coneTimer >= CONE_TIMER and self.car.position[0] > 400):
            cone = arcade.Sprite("cone.png", SPRITE_SCALING_CONE)
            cone.center_x = 900
            cone.center_y = randint(int(self.car.position[1] - 50),
                                    int(self.car.position[1] + 50))
            if (len(self.cone_list) < 5):
                self.cone_list.append(cone)
            self.coneTimer = 0
        else:
            self.coneTimer += 1

        if (self.distance_car > self.maxDistance):
            self.maxDistance = self.distance_car

        if (self.car.position[0] < 400):
            for cone in self.cone_list:
                cone.kill()

        #self.car.center_x = x
        #self.car.center_y = y
        #self.car.center_x = self.car.position[0]+distX
        #self.car.center_y = self.car.position[1]+distY
        #self.car.change_x = 10

        #self.physics_engine.update()
        """ All the logic to move, and the game logic goes here. """
        pass
Ejemplo n.º 10
0
    def update(self, delta_time):

        self.tie_fighter_list.update()
        self.bullet_list.update()
        self.player_list.update()
        # self.explosions_list.update()

        # Damage to fighter
        for bullet in self.bullet_list:

            hit_list = arcade.check_for_collision_with_list(
                bullet, self.tie_fighter_list)

            if len(hit_list) > 0:
                # explosion = Explosion(self.explosion_texture_list)
                # explosion.center_x = hit_list[0].center_x
                # explosion.center_y = hit_list[0].center_y
                # self.explosions_list.append(explosion)
                bullet.remove_from_sprite_lists()

            for tie_fighter in hit_list:
                tie_fighter.remove_from_sprite_lists()
                self.score += 1

            if bullet.bottom > SCREEN_HEIGHT:
                bullet.remove_from_sprite_lists()

        # Damage to Player
        for bullet in self.bullet_list:

            hit_list = arcade.check_for_collision_with_list(
                bullet, self.player_list)

            if len(hit_list) > 0:
                bullet.remove_from_sprite_lists()

            for self.player in hit_list:
                self.health -= 1

            if bullet.bottom > SCREEN_HEIGHT:
                bullet.remove_from_sprite_lists()

        # Tie Fighter bullets
        for tie_fighter in self.tie_fighter_list:

            if random.randrange(200) == 0:
                bullet = arcade.Sprite("laserBlue01.png")
                bullet.center_x = tie_fighter.center_x
                bullet.angle = -90
                bullet.top = tie_fighter.bottom
                bullet.change_y = -6
                self.bullet_list.append(bullet)

        self.bullet_list.update()

        # done = False

        # while not done:
        #     if self.health == 0:
        #         done = True
        # print("You have lost")

        for fighter_1 in self.tie_fighter_list:
            if fighter_1.right > SCREEN_WIDTH and fighter_1.change_x > 0:
                for fighter_2 in self.tie_fighter_list:
                    fighter_2.change_x *= -1
Ejemplo n.º 11
0
    def start_new_game(self):
        """ 设置与初始化游戏 """

        self.shoot_sound = arcade.sound.load_sound("images/midway/Shot.wav")
        self.background_music = arcade.sound.load_sound(
            "images/midway/background.wav")
        arcade.sound.play_sound(self.background_music)

        # 实例化所有角色列表
        self.enemy_list = arcade.SpriteList()            # 敌人列表
        self.bullet_list = arcade.SpriteList()           # 玩家子弹列表
        self.all_sprites_list = arcade.SpriteList()      # 所有角色列表
        self.enemy_explosion_list = arcade.SpriteList()  # 所有敌人的爆炸角色列表

        self.enemy_explosion_images = []
        for i in range(55):
            # 加载从 explosion0000.png 到 explosion0054.png 的所有图片为敌人的爆炸效果动画帧
            texture_name = f"images/enemy_explosion/explosion{i:04d}.png"
            self.enemy_explosion_images.append(
                arcade.load_texture(texture_name))

        # 设置玩家操作的飞机
        self.score = 0
        self.player_sprite = arcade.AnimatedTimeSprite(
            "images/midway/Plane 1.png", SPRITE_SCALING)
        self.player_sprite.textures.append(arcade.load_texture(
            "images/midway/Plane 2.png", scale=SPRITE_SCALING))
        self.player_sprite.textures.append(arcade.load_texture(
            "images/midway/Plane 3.png", scale=SPRITE_SCALING))
        self.player_sprite.center_x = 50
        self.player_sprite.center_y = 70
        self.player_sprite.health = 10             # 血条,在左上角画一根即可
        self.all_sprites_list.append(self.player_sprite)

        # 敌人角色生成
        for i in range(ENEMY_COUNT):
            enemy = Enemy("images/midway/Fighters.png")
            self.enemy_list.append(enemy)
            self.all_sprites_list.append(enemy)

        sea_image = "images/midway/sea.png"
        # Setting a Fixed Background 设置不动的背景 To cover up rolling background cracks
        self.background = arcade.Sprite(sea_image)
        self.background.center_x = SCREEN_WIDTH // 2
        self.background.bottom = 0

        # 设置滚动背景,两个最先画的角色往下移,移到一定坐标就到上面去
        self.background1 = Background(sea_image)
        self.background1.center_x = SCREEN_WIDTH // 2
        self.background1.bottom = 0
        self.all_sprites_list.append(self.background1)

        self.background2 = Background(sea_image)
        self.background2.center_x = SCREEN_WIDTH // 2
        self.background2.bottom = SCREEN_HEIGHT
        self.all_sprites_list.append(self.background2)

        # 1943logo
        self.logo_1943 = arcade.Sprite("images/midway/1943Logo2.png")
        self.logo_1943.center_x = SCREEN_WIDTH // 2
        self.logo_1943.center_y = SCREEN_HEIGHT // 2
        self.interval = 60
        self.interval_counter = 0
Ejemplo n.º 12
0
    def setup(self, level):
        """ Set up the game here. Call this function to restart the game. """

        # Used to keep track of our scrolling
        self.view_bottom = 0
        self.view_left = 0

        # Keep track of the score
        self.score = 0

        # Create the Sprite lists
        self.player_list = arcade.SpriteList()
        self.foreground_list = arcade.SpriteList()
        self.background_list = arcade.SpriteList()
        self.wall_list = arcade.SpriteList()
        self.coin_list = arcade.SpriteList()

        # Set up the player, specifically placing it at these coordinates.
        image_source = "images/yandare.png"
        #image_source = "images/chris.png"
        #image_source = "images/player.png"
        self.player_sprite = arcade.Sprite(image_source, CHARACTER_SCALING)
        self.player_sprite.center_x = PLAYER_START_X
        self.player_sprite.center_y = PLAYER_START_Y
        self.player_list.append(self.player_sprite)

        # --- Load in a map from the tiled editor ---

        # Name of the layer in the file that has our platforms/walls
        platforms_layer_name = 'Platforms'
        # Name of the layer that has items for pick-up
        coins_layer_name = 'Coins'
        # Name of the layer that has items for foreground
        foreground_layer_name = 'Foreground'
        # Name of the layer that has items for background
        background_layer_name = 'Background'
        # Name of the layer that has items we shouldn't touch
        death_layer_name = "deathlayer"

        # Map name
        map_name = f"tmx_maps/map_{level}.tmx"

        # Read in the tiled map
        my_map = arcade.tilemap.read_tmx(map_name)

        # Calculate the right edge of the my_map in pixels
        self.end_of_map = my_map.map_size.width * GRID_PIXEL_SIZE

        # -- Background
        self.background_list = arcade.tilemap.process_layer(
            my_map, background_layer_name, TILE_SCALING)

        # -- Foreground
        self.foreground_list = arcade.tilemap.process_layer(
            my_map, foreground_layer_name, TILE_SCALING)

        # -- Platforms
        self.wall_list = arcade.tilemap.process_layer(
            map_object=my_map,
            layer_name=platforms_layer_name,
            scaling=TILE_SCALING,
            use_spatial_hash=True)

        # -- Coins
        self.coin_list = arcade.tilemap.process_layer(my_map,
                                                      coins_layer_name,
                                                      TILE_SCALING,
                                                      use_spatial_hash=True)

        # -- Death Layer
        self.death_list = arcade.tilemap.process_layer(my_map,
                                                       death_layer_name,
                                                       TILE_SCALING,
                                                       use_spatial_hash=True)

        # --- Other stuff
        # Set the background color
        if my_map.background_color:
            arcade.set_background_color(my_map.background_color)

        # Create the 'physics engine'
        self.physics_engine = arcade.PhysicsEnginePlatformer(
            self.player_sprite, self.wall_list, GRAVITY)
Ejemplo n.º 13
0
 def __init__(self, snake):
     self.snake = snake
     self.block_sprite = arcade.Sprite('images/block.png')
Ejemplo n.º 14
0
 def update(self):
     coin = arcade.Sprite(":resources:images/items/coinGold.png",
                          sprite_scaling)
     coin.center_x = random.randrange(width)
     coin.center_y = random.randrange(height)
Ejemplo n.º 15
0
    def setup(self):
        animals = [
            'bear', 'buffalo', 'chick', 'chicken', 'cow', 'crocodile', 'dog',
            'duck', 'elephant', 'frog', 'giraffe', 'goat', 'gorilla', 'hippo',
            'horse', 'monkey', 'moose', 'narwhal', 'owl', 'panda', 'parrot',
            'penguin', 'pig', 'rabbit', 'rhino', 'sloth', 'snake', 'walrus',
            'whale', 'zebra'
        ]
        trees = [
            'foliagePack_005', 'foliagePack_006', 'foliagePack_007',
            'foliagePack_008', 'foliagePack_009', 'foliagePack_010',
            'foliagePack_011'
        ]
        flowers = [
            'foliagePack_001', 'foliagePack_002', 'foliagePack_003',
            'foliagePack_062'
        ]

        animal = 'panda'

        x = 16

        for i in range(30):
            self.animal_sprite = arcade.Sprite(
                "assets/BG/Leaves/foliagepack_leaves_018.png".format(
                    animal=animal), 0.5)
            self.animal_sprite.center_x = x
            self.animal_sprite.center_y = 16
            self.animal_list.append(self.animal_sprite)
            x += 32

        x = 16

        for i in range(30):
            self.animal_sprite = arcade.Sprite(
                "assets/BG/Leaves/foliagepack_leaves_026.png".format(
                    animal=animal), 0.5)
            self.animal_sprite.center_x = x
            self.animal_sprite.center_y = 48
            self.animal_list.append(self.animal_sprite)
            x += 32

        x = 16

        for i in range(30):
            self.animal_sprite = arcade.Sprite(
                "assets/BG/Leaves/foliagepack_leaves_002.png".format(
                    animal=animal), 0.5)
            self.animal_sprite.center_x = x
            self.animal_sprite.center_y = 80
            self.animal_list.append(self.animal_sprite)
            x += 32

        x = 40

        for i in range(10):
            tree = random.choice(trees)

            y = random.randint(181, 187)
            self.animal_sprite = arcade.Sprite(
                "assets/BG/{tree}.png".format(tree=tree), 1)
            self.animal_sprite.center_x = x
            self.animal_sprite.center_y = y
            self.animal_list.append(self.animal_sprite)
            x += random.randint(75, 100)

        x = 50

        for i in range(6):
            animal = random.choice(animals)

            self.animal_sprite = arcade.Sprite(
                "assets/{animal}.png".format(animal=animal), 0.5)
            self.animal_sprite.center_x = x
            self.animal_sprite.center_y = 70
            self.animal_list.append(self.animal_sprite)
            x += random.randint(75, 175)

        x = 20

        for i in range(10):
            flower = random.choice(flowers)

            y = random.randint(32, 40)
            self.animal_sprite = arcade.Sprite(
                "assets/BG/{flower}.png".format(flower=flower), 1)
            self.animal_sprite.center_x = x
            self.animal_sprite.center_y = y
            self.animal_list.append(self.animal_sprite)
            x += random.randint(75, 100)
Ejemplo n.º 16
0
def test_it_can_give_other_orientations(attr, expected):
    sprite = arcade.Sprite(center_x=500, center_y=650)
    sprite.width = 100
    sprite.height = 150
    assert getattr(sprite, attr) == expected
Ejemplo n.º 17
0
    def setup(self):
        """ Set up the game and initialize the variables. """

        self.wall_list = arcade.SpriteList()
        self.enemy_list = arcade.SpriteList()
        self.player_list = arcade.SpriteList()
        self.coin_list = arcade.SpriteList()

        for x in range(0, SCREEN_WIDTH, SPRITE_SIZE):
            wall = arcade.Sprite(
                "C:/Git/Skoli-haust-2020/Forritun/Verkefni með einkunn/Lokaverkefni/images/rpgTile019.png",
                SPRITE_SCALING)

            wall.bottom = 0
            wall.left = x
            self.wall_list.append(wall)

        # Draw the platform
        for x in range(SPRITE_SIZE * 3, SPRITE_SIZE * 8, SPRITE_SIZE):
            wall = arcade.Sprite(
                "C:/Git/Skoli-haust-2020/Forritun/Verkefni með einkunn/Lokaverkefni/images/rpgTile019.png",
                SPRITE_SCALING)

            wall.bottom = SPRITE_SIZE * 3
            wall.left = x
            self.wall_list.append(wall)

        # Draw the crates
        for x in range(0, SCREEN_WIDTH, SPRITE_SIZE * 5):
            wall = arcade.Sprite(
                "C:/Git/Skoli-haust-2020/Forritun/Verkefni með einkunn/Lokaverkefni/images/boxCrate_double.png",
                SPRITE_SCALING)

            wall.bottom = SPRITE_SIZE
            wall.left = x
            self.wall_list.append(wall)

        for i in range(7):

            # Create the coin instance
            coin = arcade.Sprite(
                "C:\Git\Skoli-haust-2020\Forritun\Verkefni með einkunn\Lokaverkefni\images\coinGold.png",
                SPRITE_SCALING / 2)

            # Position the coin
            coin.center_x = random.randrange(SCREEN_WIDTH)
            coin.center_y = random.randrange(600)

            # Add the coin to the lists
            self.coin_list.append(coin)
        # -- Draw an enemy on the ground
        enemy = arcade.Sprite(
            "C:/Git/Skoli-haust-2020/Forritun/Verkefni með einkunn/Lokaverkefni/images/character_zombie_idle.png",
            SPRITE_SCALING)

        enemy.bottom = SPRITE_SIZE
        enemy.left = SPRITE_SIZE * 2

        # Set enemy initial speed
        enemy.change_x = 2
        self.enemy_list.append(enemy)

        # -- Draw a enemy on the platform
        enemy = arcade.Sprite(
            "C:/Git/Skoli-haust-2020/Forritun/Verkefni með einkunn/Lokaverkefni/images/character_zombie_idle.png",
            SPRITE_SCALING)

        enemy.bottom = SPRITE_SIZE * 4
        enemy.left = SPRITE_SIZE * 4

        # Set boundaries on the left/right the enemy can't cross
        enemy.boundary_right = SPRITE_SIZE * 8
        enemy.boundary_left = SPRITE_SIZE * 3
        enemy.change_x = 2
        self.enemy_list.append(enemy)

        # -- Set up the player
        self.player_sprite = arcade.Sprite(
            "C:/Git/Skoli-haust-2020/Forritun/Verkefni með einkunn/Lokaverkefni/images/character1.png",
            SPRITE_SCALING)
        self.player_list.append(self.player_sprite)

        # Starting position of the player
        self.player_sprite.center_x = 64
        self.player_sprite.center_y = 270

        self.physics_engine = arcade.PhysicsEnginePlatformer(
            self.player_sprite, self.wall_list, gravity_constant=GRAVITY)

        # Set the background color
        arcade.set_background_color(arcade.color.AMAZON)
Ejemplo n.º 18
0
def test_it_can_set_other_orientations(attr, value):
    sprite = arcade.Sprite()
    sprite.width = 100
    sprite.height = 150
    setattr(sprite, attr, value)
    assert sprite.position == (500, 650)
Ejemplo n.º 19
0
    def on_mouse_press(self, x, y, button, modifiers):
        global gameview
        if gameview:
            if button == arcade.MOUSE_BUTTON_LEFT:
                print("Left mouse button pressed at", x, y)
                ####Checks to see if player has clicked on enemy####
                if (x >= 550 and x <= 750 and y >= 250 and y <= 450):
                    #Will respawn a new enemy if the attack is more than the remaining health of the enemy; this stops errors with the HP bar because the width can't go below zero
                    if self.attack >= self.hp and self.is_boss != True or self.attack >= self.hp and self.bossKilled == True:
                        self.hp = self.baseHp

                        self.enemy2 = arcade.Sprite(
                            "enemy" + str(self.wave) + ".png", 8)

                        if self.level % 10 == 0:
                            self.hpbar = hpbar(200 -
                                               self.hp / self.bossHp * 200)
                        else:
                            self.hpbar = hpbar(200 -
                                               self.hp / self.baseHp * 200)
                        self.coins += round(2 * self.level *
                                            math.ceil(self.level / 10) * 2)
                        print(
                            round(2 * self.level * math.ceil(self.level / 10) *
                                  2))
                        self.coinsAdded = arcade.draw_text(
                            "+ " + str(
                                round(2 * self.level *
                                      math.ceil(self.level / 10) * 2)), 600,
                            700, arcade.color.YELLOW, 20)
                        self.coinText = arcade.draw_text(
                            "Coins: " + str(self.coins), 395, 700,
                            arcade.color.BLACK, 20)

                        print("coins: " + str(self.coins))
                        self.hpbar.draw()
                        #### Wave goes up by one every time you kill an enemy, new level every 5 waves ####
                        if self.wave < 5:
                            self.wave += 1
                            #### !IMPORTANT NOTEE! I CHANGE THE TEXT IN THIS FUNCTION INSTEAD OF THE ON_DRAW FUNCTION BECAUSE I THINK IT IS LESS CPU DEMANDING AS YOU ARE NOT RUNNING IT 80 TIMES A SECOND ####
                            self.levelWave = arcade.draw_text(
                                "Level " + str(self.level) + ", Wave (" +
                                str(self.wave) + "/5)", 545, 604,
                                arcade.color.BLACK, 20)
                        else:
                            self.level += 1
                            if self.level % 10 == 0:
                                self.bossKilled = False
                                self.is_boss = True
                                self.bossHp = self.level / 10 * 2500 * self.level / 10
                                self.hp = self.bossHp
                                self.hpbar = hpbar(200 -
                                                   self.hp / self.bossHp * 200)
                                self.start = datetime.datetime.now()
                                self.bossTime = 30

                            else:

                                self.wave = 1

                                self.baseHp *= (
                                    1.1 + round(self.level % 5) / 10 * 0.2)
                                self.hp = round(self.baseHp)
                                self.hpbar = hpbar(200 -
                                                   self.hp / self.baseHp * 200)
                                self.levelWave = arcade.draw_text(
                                    "Level " + str(self.level) + ", Wave (" +
                                    str(self.wave) + "/5)", 545, 604,
                                    arcade.color.BLACK, 20)
                                #### Error must be fixed ####
                                """def gfg():
                                    print("Worked")
    
                                timer = threading.Timer(2.0, gfg)
                                timer.start()"""
                    elif self.is_boss == True and self.attack >= self.hp:
                        self.bossKilled = True
                        self.is_boss = False

                    #### TAKES A WAY HEALTH ON HP VARIABLE AND THE HP BAR USING A SPECIAL ALGORITHM
                    else:
                        self.hp -= self.attack
                        #### Width of HP bar is 200 pixels, therfore to workout how much of the bar is remaining, you need to convert the remaining hp as a percentage of the base hp (which will create 100 pixels of data) then multiply by 2 to get the doubled percentage and therfore the amount of pixels to fill the hp bar by
                        if self.level % 10 == 0:
                            self.hpbar = hpbar(200 -
                                               self.hp / self.bossHp * 200)
                        else:
                            self.hpbar = hpbar(200 -
                                               self.hp / self.baseHp * 200)
                        self.hpbar.draw()

                    print("Hit on enemy", self.hp)

                #### This loop checks to see if the user has hit one of the upgrade buttons and if so which one, using the i operator to decipher the y co-ordinate and therfore which button
                for i in range(16):
                    if x >= 160 and x <= 240 and y >= 580 - i * 37 and y <= 600 - i * 37:
                        #### Uses lists as an easy way to set costs and buffs ####
                        if self.coins >= self.upgradeCostList[i]:
                            self.coins -= self.upgradeCostList[i]
                            #### Fixing can't divide by zero error ####
                            if i != 0:
                                #### Algorithm creates exponential growth for the upgrades to ensure a more challenging game, exponent increases as the upgrades get higher ####
                                self.upgradeCostList[i] *= 1 + i * (0.15 / i)
                            else:
                                self.upgradeCostList[i] *= 1.1
                            self.attack += self.upgradeAttackBuffList[i]

                            print("Upgrade " + str(i + 1) + " Purchased",
                                  "You have " + str(self.coins) + " left",
                                  "Your attack power is " + str(self.attack))
                        else:
                            print("You do not have the funds for this sir")
                    self.coinText = arcade.draw_text(
                        "Coins: " + str(round(self.coins)), 395, 700,
                        arcade.color.BLACK, 20)
        global startview
        if startview:
            startview = False
            gameview = True
Ejemplo n.º 20
0
def test_it_can_make_anchor_from_sprite():
    sprite1 = arcade.Sprite()
    sprite1.position = (100, 100)
    anchor = c.helpers.AnchorPoint.from_sprite(sprite1, orientation='position')
    assert anchor.position == (100, 100)
Ejemplo n.º 21
0
    def setup(self):
        """ Set up the game and initialize the variables. """

        # Sprite lists
        self.all_sprites_list = arcade.SpriteList()
        self.wall_list = arcade.SpriteList()
        self.coin_list = arcade.SpriteList()

        # Set up the player
        self.player_sprite = arcade.Sprite("images/character.png",
                                           SPRITE_SCALING)
        self.player_sprite.center_x = 50
        self.player_sprite.center_y = 64

        # -- Set up the walls
        # Create a series of horizontal walls
        for y in range(0, 800, 200):
            for x in range(100, 700, 64):
                wall = arcade.Sprite("images/boxCrate_double.png",
                                     SPRITE_SCALING)
                wall.center_x = x
                wall.center_y = y
                self.wall_list.append(wall)

        # -- Randomly place coins where there are no walls
        # Create the coins
        for i in range(NUMBER_OF_COINS):

            # Create the coin instance
            # Coin image from kenney.nl
            coin = arcade.Sprite("images/coin_01.png", SPRITE_SCALING_COIN)

            # --- IMPORTANT PART ---

            # Boolean variable if we successfully placed the coin
            coin_placed_successfully = False

            # Keep trying until success
            while not coin_placed_successfully:
                # Position the coin
                coin.center_x = random.randrange(SCREEN_WIDTH)
                coin.center_y = random.randrange(SCREEN_HEIGHT)

                # See if the coin is hitting a wall
                wall_hit_list = arcade.check_for_collision_with_list(
                    coin, self.wall_list)

                # See if the coin is hitting another coin
                coin_hit_list = arcade.check_for_collision_with_list(
                    coin, self.coin_list)

                if len(wall_hit_list) == 0 and len(coin_hit_list) == 0:
                    # It is!
                    coin_placed_successfully = True

            # Add the coin to the lists
            self.coin_list.append(coin)

            # --- END OF IMPORTANT PART ---

        self.physics_engine = arcade.PhysicsEngineSimple(
            self.player_sprite, self.wall_list)

        # Set the background color
        arcade.set_background_color(arcade.color.AMAZON)
Ejemplo n.º 22
0
dist_card = 4
pos_card = [1 / 4, 3 / 4]
val_glob = {
    1: "ace",
    2: "two",
    3: "three",
    4: "four",
    5: "five",
    6: "six",
    7: "seven",
    8: "jack",
    9: "horse",
    10: "king"
}
suit_glob = {"Denari": "g", "Coppe": "c", "Bastoni": "b", "Spade": "s"}
back = arcade.Sprite("sprite/briscola-cards/n_back.png")
back._set_scale(pixel_w / back._get_width())


class Card:
    """ Text-based button """
    def __init__(self, suit, value):
        self.value = value
        self.suit = suit
        self.pressed = False
        self.center_x = None
        self.center_y = None
        self.width = pixel_w
        self.height = pixel_w / rapp_xony
        self.index = None
        self.text = "card"
 def menu_line(self, center_x, center_y, img):
     menu = arcade.Sprite(img)
     menu.center_x = center_x
     menu.center_y = center_y
     self.menu_list.append(menu)
Ejemplo n.º 24
0
    def setup(self, level):
        """ Set up the game here. Call this function to restart the game. """

        # Used to keep track of our scrolling
        self.view_bottom = 0
        self.view_left = 0

        # Keep track of the score
        self.score = 0

        self.death = 0

        # Create the Sprite lists
        self.player_list = arcade.SpriteList()
        self.foreground_list = arcade.SpriteList()
        self.background_list = arcade.SpriteList()
        self.wall_list = arcade.SpriteList()
        self.coin_list = arcade.SpriteList()
        self.enemy_list = arcade.SpriteList()
        self.arrow_list = arcade.SpriteList()

        # Set up the player, specifically placing it at these coordinates.
        self.player_sprite = arcade.Sprite(
            "images/characters/player_standing.png", CHARACTER_SCALING)
        self.player_sprite.center_x = PLAYER_START_X
        self.player_sprite.center_y = PLAYER_START_Y
        self.player_list.append(self.player_sprite)

        # --- Load in a map from the tiled editor ---

        # Name of the layer in the file that has our platforms/walls
        platforms_layer_name = 'Platform'
        # Name of the layer that has items for pick-up
        coins_layer_name = 'Coins'
        # Name of the layer that has items for foreground
        foreground_layer_name = 'Foreground'
        # Name of the layer that has items for background
        background_layer_name = 'Background'
        # Name of the layer that has items we shouldn't touch
        dont_touch_layer_name = "Don't Touch"
        enemy_layer_name = "Enemies"

        # Map name
        map_name = f"map_level_{level}.tmx"

        # Read in the tiled map
        my_map = arcade.tilemap.read_tmx(map_name)

        # Calculate the right edge of the my_map in pixels
        self.end_of_map = my_map.map_size.width * GRID_PIXEL_SIZE

        # -- Background
        self.background_list = arcade.tilemap.process_layer(
            my_map, background_layer_name, TILE_SCALING)

        # -- Foreground
        self.foreground_list = arcade.tilemap.process_layer(
            my_map, foreground_layer_name, TILE_SCALING)

        # -- Platforms
        self.wall_list = arcade.tilemap.process_layer(my_map,
                                                      platforms_layer_name,
                                                      TILE_SCALING)

        # -- Coins
        self.coin_list = arcade.tilemap.process_layer(my_map, coins_layer_name,
                                                      TILE_SCALING)

        # -- Don't Touch Layer
        self.dont_touch_list = arcade.tilemap.process_layer(
            my_map, dont_touch_layer_name, TILE_SCALING)
        # Enemy Layer
        self.enemy_list = arcade.tilemap.process_layer(my_map,
                                                       enemy_layer_name,
                                                       CHARACTER_SCALING)

        enemy = arcade.Sprite("images/characters/enemy_hexagon.png",
                              CHARACTER_SCALING)
        enemy.change_x = 2
        self.enemy_list.append(enemy)

        # set boundaries for the enemies
        enemy.boundary_right = SPRITE_PIXEL_SIZE * 8
        enemy.boundary_left = SPRITE_PIXEL_SIZE * 3
        enemy.change_x = 2
        self.enemy_list.append(enemy)

        # --- Other stuff
        # Set the background color
        if my_map.background_color:
            arcade.set_background_color(my_map.background_color)

        # Create the 'physics engine'
        self.physics_engine = arcade.PhysicsEnginePlatformer(
            self.player_sprite, self.wall_list, GRAVITY)
Ejemplo n.º 25
0
 def setup(self):
     self.player = arcade.Sprite(filename="rough/images/officeguy.png", center_x= 200, center_y = 200, scale=0.2)
Ejemplo n.º 26
0
    def setup(self):
        """ Set up the game and initialize the variables. """

        # Sprite lists
        self.all_sprites_list = arcade.SpriteList()
        self.wall_list = arcade.SpriteList()
        self.coin_list = arcade.SpriteList()
        self.ghost_list = arcade.SpriteList()

        # Set up the player
        self.score = 0
        self.coins_left = 25
        self.player_sprite = arcade.Sprite("pumpkin.png", SPRITE_SCALING)
        self.player_sprite.center_x = 50
        self.player_sprite.center_y = 64


        self.boo_sprite = arcade.Sprite("boo.png", 1)
        self.boo_sprite.set_position(500,500)

        self.game_over_sprite = arcade.Sprite("game_over.png",1)
        self.game_over_sprite.set_position(500,500)

        

#MAPPING START ###################################################


        mapArray = []

        mapFile = open("map.txt","r")

        content = mapFile.readline()

        line = 1

        while content:

            mapArray.append(content)

            content = mapFile.readline()

        """ SET UP THE MAIN MAP FILE """
        MapFinal = []
        for row in range(32):
            MapRow = ['']
            for column in range(24):
                MapColumn = ['']
                MapRow.append(MapColumn)
            MapFinal.append(MapRow)

        for a in range(32):
            for b in range(24):
                if mapArray[a][b] == "w":
                    MapFinal[a][b] = "w"
                elif mapArray[a][b] == "t":
                    MapFinal[a][b] = "t"
                elif mapArray[a][b] == "-":
                    MapFinal[a][b] = "-"


        for x in range(32):
            for y in range(24):

                if MapFinal[x][y] == 'w':
                    x_block, y_block = locator(x,y)
                    wall = arcade.Sprite("box.png", BOX_SCALING)
                    wall.center_x = x_block
                    wall.center_y = y_block
                    self.wall_list.append(wall)

        ## MAPPING END #############################################

        # -- Randomly place coins where there are no walls
        # Create the coins
        for i in range(NUMBER_OF_COINS):

            coin = arcade.Sprite("apple.png", APPLE_SCALING)

            # --- IMPORTANT PART ---

            # Boolean variable if we successfully placed the coin
            coin_placed_successfully = False

            # Keep trying until success
            while not coin_placed_successfully:
                # Position the coin
                coin.center_x = random.randrange(SCREEN_WIDTH)
                coin.center_y = random.randrange(SCREEN_HEIGHT)

                # See if the coin is hitting a wall
                wall_hit_list = arcade.check_for_collision_with_list(coin, self.wall_list)

                # See if the coin is hitting another coin
                coin_hit_list = arcade.check_for_collision_with_list(coin, self.coin_list)

                if len(wall_hit_list) == 0 and len(coin_hit_list) == 0:
                    # It is!
                    coin_placed_successfully = True

            # Add the coin to the lists
            self.coin_list.append(coin)


        #Create the ghosts
        for i in range(NUMBER_OF_GHOSTS):

            ghost = arcade.Sprite("ghost.png", GHOST_SCALING)
            ghost_placed_successfully = False
            while not ghost_placed_successfully:
                ghost.center_x = random.randrange(SCREEN_WIDTH)
                ghost.center_y = random.randrange(SCREEN_HEIGHT)

                wall_hit_list = arcade.check_for_collision_with_list(ghost, self.wall_list)
                coin_hit_list = arcade.check_for_collision_with_list(ghost, self.coin_list)
                ghost_hit_list = arcade.check_for_collision_with_list(ghost, self.ghost_list)
                player_hit_list = arcade.check_for_collision(ghost, self.player_sprite)
                
                if len(wall_hit_list)==0 and len(coin_hit_list)==0 and len(ghost_hit_list)== 0 and (player_hit_list)==0:
                    ghost_placed_successfully = True

            self.ghost_list.append(ghost)



            # --- END OF IMPORTANT PART ---

        self.physics_engine = arcade.PhysicsEngineSimple(self.player_sprite, self.wall_list)

        # Set the background color
        arcade.set_background_color(arcade.color.BLACK)
Ejemplo n.º 27
0
    def update(self, delta_time):
        """ All the logic to move, and the game logic goes here. 
        TODO: have ship explode each life, balance level design 
        player invulnerability on respawn"""

        if self.current_state == GAME_RUNNING:
            # Collision Checking for Asteroid and Player, and bolt and player, and alien and player
            hit_list = arcade.check_for_collision_with_list(
                self.player_sprite, self.asteroid_list)
            bolt_hit_list = arcade.check_for_collision_with_list(
                self.player_sprite, self.bolt_list)
            alien_hit_list = arcade.check_for_collision_with_list(
                self.player_sprite, self.alien_list)
            boss_hit_list = arcade.check_for_collision_with_list(
                self.player_sprite, self.boss_list)
            beam_hit_list = arcade.check_for_collision_with_list(
                self.player_sprite, self.beam_list)

            # Player timers
            self.player_sprite.timer = self.player_sprite.timer - 1
            self.player_sprite.invul = self.player_sprite.invul - 1

            # Player invulnerability coating
            if self.player_sprite.invul == 0:
                self.player_sprite.set_texture(0)
            elif self.player_sprite.invul == PLAYER_INVULNERABILITY - 1:
                self.player_sprite.set_texture(4)

            # Player Bounds Checking
            if self.player_sprite.center_x > SCREEN_WIDTH:
                self.player_sprite.center_x = 0
            elif self.player_sprite.center_x < 0:
                self.player_sprite.center_x = SCREEN_WIDTH
            elif self.player_sprite.center_y > SCREEN_HEIGHT:
                self.player_sprite.center_y = 0
            elif self.player_sprite.center_y < 0:
                self.player_sprite.center_y = SCREEN_HEIGHT

            # Checking player collisions
            if (hit_list or bolt_hit_list or alien_hit_list or boss_hit_list or beam_hit_list) \
                and self.player_sprite.invul < 0:
                if self.lives > 1:
                    self.player_sprite.center_x = SCREEN_WIDTH / 2
                    self.player_sprite.center_y = SCREEN_HEIGHT / 2
                    self.player_sprite.invul = PLAYER_INVULNERABILITY
                    self.lives = self.lives - 1
                    self.score = self.score - 10
                else:
                    self.lives = 0
                    self.player_sprite.set_texture(1)
                    self.player_sprite.movable = False
                    self.player_sprite.stop()
                    self.current_state = GAME_OVER

            # Creation of Powerups
            if self.numOfPow < 1 and random.randint(1, 10000) < 50:
                powType = 1
                self.numOfPow = self.numOfPow + 1
                self.powerup_list = Powerup.createPowerUp\
                                    (self,self.powerup_list, powType, SCREEN_HEIGHT, SCREEN_WIDTH)

            pow_hit_list = arcade.check_for_collision_with_list(
                self.player_sprite, self.powerup_list)

            for pow in pow_hit_list:
                # Dealing with collision with player
                if self.pow == False:
                    pow.kill()
                    self.numOfPow = 0
                    if pow.type == 1:
                        self.player_sprite.set_texture(2)
                        self.laser = True
                        self.pow = True
                    elif pow.type == 2:
                        self.player_sprite.set_texture(3)
                        self.bb = 4
                        self.pow = True

            # Boss summoning
            if self.score > 1000 and self.numOfBoss < 1:
                self.boss_list = Alien.createBoss(MyGame, self.boss_list,
                                                  SCREEN_HEIGHT, SCREEN_WIDTH)
                self.numOfBoss = 1
                if self.numOfAliens > 0:
                    for alien_left in self.alien_list:
                        alien_left.kill()
                        self.numOfAliens = 0

            for boss in self.boss_list:
                boss.center_x = boss.center_x + boss.change_x
                boss.center_y = boss.center_y + boss.change_y
                boss.beamTimer = boss.beamTimer - 1

                if self.player_sprite.center_x > boss.center_x:
                    boss.change_x = 0.2
                elif self.player_sprite.center_x < boss.center_x:
                    boss.change_x = -0.2

                # Boss Beaming
                if boss.beamTimer < 500 and not boss.beamActive:
                    beam = arcade.Sprite("Resources/alienlaser.png",
                                         SPRITE_SCALING_BEAM)  # Change to beam
                    beam.height = SCREEN_HEIGHT / 1.2
                    beam.center_x = boss.center_x
                    beam.center_y = boss.center_y - 350
                    boss.beamActive = True
                    self.beam_list.append(beam)
                elif boss.beamTimer < 500 and boss.beamTimer > 0:
                    for beam in self.beam_list:
                        beam.center_x = boss.center_x
                        beam.center_y = boss.center_y - 350
                        boss.beamTimer = boss.beamTimer - 1
                elif boss.beamTimer <= 0:
                    for beam in self.beam_list:
                        beam.kill()
                    boss.beamActive = False
                    boss.beamTimer = 1000

                # Boss Shooting
                if boss.shootTimer <= 0:
                    for i in range(1, 6):
                        bolt = arcade.Sprite("Resources/alienbolt.png",
                                             SPRITE_SCALING_BOLT)
                        bolt.type = 0
                        bolt.center_x = boss.center_x - 100 + (30 * i)
                        bolt.center_y = boss.center_y - 60
                        if i == 1:
                            bolt.change_x = -2
                        elif i == 2:
                            bolt.change_x = -1
                        elif i == 3:
                            bolt.change_x = 0
                        elif i == 4:
                            bolt.change_x = 1
                        elif i == 5:
                            bolt.change_x = 2

                        bolt.change_y = -BOLT_SPEED * .35
                        self.bolt_list.append(bolt)
                        boss.shootTimer = 50
                else:
                    boss.shootTimer = boss.shootTimer - 1

            if self.numOfBoss < 1 or self.score > 5000:
                # Creation of Aliens (ultimately want to put on a timer)
                if self.score < 250:
                    spawn = random.randint(1, 200)
                elif self.score < 500:
                    spawn = random.randint(1, 100)
                else:
                    spawn = random.randint(1, 50)

                if spawn == 1:
                    alienType = random.randint(1, 4)
                    self.alien_list, self.numOfAliens = Alien.createAlien\
                                        (MyGame, self.alien_list, self.numOfAliens, alienType, SCREEN_HEIGHT, SCREEN_WIDTH)

                # Alien Movement
                for alien in self.alien_list:
                    alien.center_x = alien.center_x + alien.change_x
                    alien.center_y = alien.center_y + alien.change_y

                    #Alien 3 follow pattern
                    if alien.type == 3:
                        if self.player_sprite.center_x > alien.center_x:
                            alien.change_x = 2
                        elif self.player_sprite.center_x < alien.center_x:
                            alien.change_x = -2

    #                 # Aliens collide with asteroid
    #                 alien_hit_list = arcade.check_for_collision_with_list(alien, self.asteroid_list)
    #                 if alien_hit_list:
    #                     #TODO: Add result of alien death
    #                     alien.kill()

    # Alien shooting
                    degreeOfSpace = 3
                    alien.timer = alien.timer - 1
                    if alien.center_x < self.player_sprite.center_x + degreeOfSpace \
                    and alien.center_x > self.player_sprite.center_x - degreeOfSpace \
                    and alien.center_y > self.player_sprite.center_y:
                        if alien.type <= 3 and alien.timer < 0:
                            alien.timer = 10
                            bolt = arcade.Sprite("Resources/alienbolt.png",
                                                 SPRITE_SCALING_BOLT)
                            bolt.type = 0
                            bolt.center_x = alien.center_x
                            bolt.center_y = alien.center_y - 20
                            bolt.change_x = 0
                            bolt.change_y = -BOLT_SPEED * .65
                            self.bolt_list.append(bolt)
                        if alien.type == 4 and alien.timer < 0:
                            alien.timer = 10
                            bolt = arcade.Sprite("Resources/alienbolt.png",
                                                 5 * SPRITE_SCALING_BOLT)
                            bolt.type = 1
                            bolt.center_x = alien.center_x
                            bolt.center_y = alien.center_y - 60
                            bolt.change_x = 0
                            bolt.change_y = -BOLT_SPEED * .35
                            self.bolt_list.append(bolt)

                    # Off Screen
                    if alien.center_x > SCREEN_WIDTH:
                        alien.center_x = 1

                    if alien.center_x < 0:
                        alien.center_x = SCREEN_WIDTH - 1

                    if alien.center_y > SCREEN_HEIGHT:
                        alien.kill()

                    if alien.center_y < 0:
                        alien.kill()

            # Asteroid Movement
            for asteroid in self.asteroid_list:
                asteroid.center_x = asteroid.center_x + asteroid.change_x
                asteroid.center_y = asteroid.center_y + asteroid.change_y
                asteroid_hit_list = arcade.check_for_collision_with_list(
                    asteroid, self.asteroid_list)

                # Collision between asteroid physics
                for asteroid2 in asteroid_hit_list:
                    if asteroid2 != asteroid:
                        Asteroid.physics(asteroid, asteroid2)

                # Off Screen
                if asteroid.center_x - asteroid.collision_radius > SCREEN_WIDTH:
                    asteroid.center_x = 10 - asteroid.collision_radius

                if asteroid.center_x + asteroid.collision_radius < 0:
                    asteroid.center_x = SCREEN_WIDTH + asteroid.collision_radius

                if asteroid.center_y - asteroid.collision_radius > SCREEN_HEIGHT:
                    asteroid.center_y = 10 - asteroid.collision_radius

                if asteroid.center_y + asteroid.collision_radius < 0:
                    asteroid.center_y = SCREEN_HEIGHT + asteroid.collision_radius

            # Bolt Movement
            for bolt in self.bolt_list:
                bolt.center_x = bolt.center_x + bolt.change_x
                bolt.center_y = bolt.center_y + bolt.change_y

                # Collision with alien
                bolt_hit_list = arcade.check_for_collision_with_list(
                    bolt, self.alien_list)
                for alien_hit in bolt_hit_list:
                    alien_hit.kill()
                    bolt.kill()
                    self.numOfAliens = self.numOfAliens - 1
                    self.score = self.score + 50

                # Collision with boss
                bolt_hit_list = arcade.check_for_collision_with_list(
                    bolt, self.boss_list)
                for boss_hit in bolt_hit_list:
                    if boss_hit.health > 0:
                        if bolt.type == 0:
                            boss_hit.health = boss_hit.health - 1
                        elif bolt.type == 1:
                            boss_hit.health = boss_hit.health - 75
                    elif boss_hit.health <= 0:
                        boss_hit.kill()
                        self.numOfBoss = self.numOfBoss - 1
                        self.score = self.score + BOSSPOINTS
                    bolt.kill()

                # Collision with asteroid
                bolt_hit_list = arcade.check_for_collision_with_list(
                    bolt, self.asteroid_list)
                for asteroid_hit in bolt_hit_list:

                    if asteroid_hit.health > 1:
                        if bolt.type == 0:
                            asteroid_hit.health = asteroid_hit.health - 1
                        elif bolt.type == 1:
                            asteroid_hit.health = asteroid_hit.health - 75

                        bolt.kill()
                        self.score = self.score + 1
                        if asteroid_hit.health <= .25 * (
                                5 * SPRITE_MAX_SCALING_ASTEROID):
                            asteroid_hit.set_texture(3)
                            asteroid_hit._set_scale(asteroid_hit.scale)
                        elif asteroid_hit.health <= .5 * (
                                5 * SPRITE_MAX_SCALING_ASTEROID):
                            asteroid_hit.set_texture(2)
                            asteroid_hit._set_scale(asteroid_hit.scale)
                        elif asteroid_hit.health <= .75 * (
                                5 * SPRITE_MAX_SCALING_ASTEROID):
                            asteroid_hit.set_texture(1)
                            asteroid_hit._set_scale(asteroid_hit.scale)
                    else:
                        # Splits asteroid into two unless it is of smallest size
                        if asteroid_hit.scale > SPRITE_MAX_SCALING_ASTEROID / 2:
                            x1 = asteroid_hit.center_x + asteroid_hit.collision_radius / 2
                            y1 = asteroid_hit.center_y + asteroid_hit.collision_radius / 2
                            x2 = asteroid_hit.center_x - asteroid_hit.collision_radius / 2
                            y2 = asteroid_hit.center_y - asteroid_hit.collision_radius / 2

                            self.asteroid_list = Asteroid.createMiniAsteroid(
                                MyGame, self.asteroid_list, x1, y1,
                                SPRITE_MAX_SCALING_ASTEROID,
                                MAX_ASTEROID_SPEED)

                            self.asteroid_list = Asteroid.createMiniAsteroid(
                                MyGame, self.asteroid_list, x2, y2,
                                SPRITE_MAX_SCALING_ASTEROID,
                                MAX_ASTEROID_SPEED)
                            self.numOfAsteroids = self.numOfAsteroids + 2

                        asteroid_hit.kill()
                        bolt.kill()
                        self.numOfAsteroids = self.numOfAsteroids - 1
                        self.score = self.score + 10

                # Off Screen Deletion of Bolts
                if bolt.center_x > SCREEN_WIDTH or bolt.center_x < 0 \
                or bolt.center_y > SCREEN_HEIGHT or bolt.center_y < 0:
                    bolt.kill()

            for beam in self.beam_list:
                # Collision with asteroid
                laser_hit_list = arcade.check_for_collision_with_list(
                    beam, self.asteroid_list)
                for asteroid_hit in laser_hit_list:

                    if asteroid_hit.health > 1:
                        asteroid_hit.health = asteroid_hit.health - 1
                        self.score = self.score + 1
                        if asteroid_hit.health <= .25 * (
                                5 * SPRITE_MAX_SCALING_ASTEROID):
                            asteroid_hit.set_texture(3)
                            asteroid_hit._set_scale(asteroid_hit.scale)
                        elif asteroid_hit.health <= .5 * (
                                5 * SPRITE_MAX_SCALING_ASTEROID):
                            asteroid_hit.set_texture(2)
                            asteroid_hit._set_scale(asteroid_hit.scale)
                        elif asteroid_hit.health <= .75 * (
                                5 * SPRITE_MAX_SCALING_ASTEROID):
                            asteroid_hit.set_texture(1)
                            asteroid_hit._set_scale(asteroid_hit.scale)
                    else:
                        # Splits asteroid into two unless it is of smallest size
                        if asteroid_hit.scale > SPRITE_MAX_SCALING_ASTEROID / 2:
                            x1 = asteroid_hit.center_x + asteroid_hit.collision_radius / 2
                            y1 = asteroid_hit.center_y + asteroid_hit.collision_radius / 2
                            x2 = asteroid_hit.center_x - asteroid_hit.collision_radius / 2
                            y2 = asteroid_hit.center_y - asteroid_hit.collision_radius / 2

                            self.asteroid_list = Asteroid.createMiniAsteroid(
                                MyGame, self.asteroid_list, x1, y1,
                                SPRITE_MAX_SCALING_ASTEROID,
                                MAX_ASTEROID_SPEED)

                            self.asteroid_list = Asteroid.createMiniAsteroid(
                                MyGame, self.asteroid_list, x2, y2,
                                SPRITE_MAX_SCALING_ASTEROID,
                                MAX_ASTEROID_SPEED)
                            self.numOfAsteroids = self.numOfAsteroids + 2

                        asteroid_hit.kill()

            for laser in self.laser_list:
                # Movement
                laserDistFromPlayer = laser.height / 2 + 25
                if self.player_sprite.angle == 0:
                    laser.center_x = self.player_sprite.center_x
                    laser.center_y = self.player_sprite.center_y + laserDistFromPlayer
                    laser.angle = 0

                elif self.player_sprite.angle == 180:
                    laser.center_x = self.player_sprite.center_x
                    laser.center_y = self.player_sprite.center_y - laserDistFromPlayer
                    laser.angle = 180

                elif self.player_sprite.angle == 90:
                    laser.center_x = self.player_sprite.center_x - laserDistFromPlayer
                    laser.center_y = self.player_sprite.center_y
                    laser.angle = 90

                elif self.player_sprite.angle == 270:
                    laser.center_x = self.player_sprite.center_x + laserDistFromPlayer
                    laser.center_y = self.player_sprite.center_y
                    laser.angle = 270

                # Collision with alien
                laser_hit_list = arcade.check_for_collision_with_list(
                    laser, self.alien_list)
                for alien_hit in laser_hit_list:
                    alien_hit.kill()
                    laser.health = laser.health - 1
                    self.numOfAliens = self.numOfAliens - 1
                    self.score = self.score + 50
                    if laser.health <= 0:
                        laser.kill()

                # Collision with boss
                laser_hit_list = arcade.check_for_collision_with_list(
                    laser, self.alien_list)
                for boss_hit in laser_hit_list:
                    if boss_hit.health > 1:
                        boss_hit.health = boss_hit.health - 1
                        laser.health = laser.health - 1
                        if laser.health <= 0:
                            laser.kill()
                    else:
                        boss_hit.kill()
                        self.score = self.score + BOSSPOINTS
                        laser.health = laser.health - 1
                        if laser.health <= 0:
                            laser.kill()
                        self.numOfBoss = self.numOfBoss - 1

                # Collision with asteroid
                laser_hit_list = arcade.check_for_collision_with_list(
                    laser, self.asteroid_list)
                for asteroid_hit in laser_hit_list:

                    if asteroid_hit.health > 1:
                        asteroid_hit.health = asteroid_hit.health - 1
                        laser.health = laser.health - 1
                        if laser.health <= 0:
                            laser.kill()
                        self.score = self.score + 1
                        if asteroid_hit.health <= .25 * (
                                5 * SPRITE_MAX_SCALING_ASTEROID):
                            asteroid_hit.set_texture(3)
                            asteroid_hit._set_scale(asteroid_hit.scale)
                        elif asteroid_hit.health <= .5 * (
                                5 * SPRITE_MAX_SCALING_ASTEROID):
                            asteroid_hit.set_texture(2)
                            asteroid_hit._set_scale(asteroid_hit.scale)
                        elif asteroid_hit.health <= .75 * (
                                5 * SPRITE_MAX_SCALING_ASTEROID):
                            asteroid_hit.set_texture(1)
                            asteroid_hit._set_scale(asteroid_hit.scale)
                    else:
                        # Splits asteroid into two unless it is of smallest size
                        if asteroid_hit.scale > SPRITE_MAX_SCALING_ASTEROID / 2:
                            x1 = asteroid_hit.center_x + asteroid_hit.collision_radius / 2
                            y1 = asteroid_hit.center_y + asteroid_hit.collision_radius / 2
                            x2 = asteroid_hit.center_x - asteroid_hit.collision_radius / 2
                            y2 = asteroid_hit.center_y - asteroid_hit.collision_radius / 2

                            self.asteroid_list = Asteroid.createMiniAsteroid(
                                MyGame, self.asteroid_list, x1, y1,
                                SPRITE_MAX_SCALING_ASTEROID,
                                MAX_ASTEROID_SPEED)

                            self.asteroid_list = Asteroid.createMiniAsteroid(
                                MyGame, self.asteroid_list, x2, y2,
                                SPRITE_MAX_SCALING_ASTEROID,
                                MAX_ASTEROID_SPEED)
                            self.numOfAsteroids = self.numOfAsteroids + 2

                        asteroid_hit.kill()
                        laser.health = laser.health - 1
                        if laser.health <= 0:
                            laser.kill()
                        self.numOfAsteroids = self.numOfAsteroids - 1
                        self.score = self.score + 10
                # Laser Decay
                laser.health = laser.health - 1
                if laser.health <= 0:
                    laser.kill()
                    self.laser = False
                    self.pow = False

            # Creation of More Asteroids When One Is Destroyed
            extraAsteroid = round(self.score / 400)

            if self.numOfAsteroids < START_ASTEROID + extraAsteroid:
                self.asteroid_list, self.numOfAsteroids = Asteroid.createAsteroid(
                    MyGame, True, self.asteroid_list, self.numOfAsteroids,
                    SCREEN_HEIGHT, SCREEN_WIDTH, SPRITE_MAX_SCALING_ASTEROID,
                    MAX_ASTEROID_SPEED)

            # End of Game when score > 1,000,000
            if self.score >= 10000:
                self.current_state = GAME_WON

            self.physics_engine.update()
Ejemplo n.º 28
0
    def setup(self):
        """ Set up the game and initialize the variables. """

        # Sprite lists
        self.all_sprites_list = arcade.SpriteList()
        self.all_wall_list = arcade.SpriteList()
        self.static_wall_list = arcade.SpriteList()
        self.moving_wall_list = arcade.SpriteList()

        # Set up the player
        self.score = 0
        self.player_sprite = arcade.Sprite("images/character.png", SPRITE_SCALING)
        self.player_sprite.center_x = 2 * GRID_PIXEL_SIZE
        self.player_sprite.center_y = 3 * GRID_PIXEL_SIZE
        self.all_sprites_list.append(self.player_sprite)

        map_array = get_map()

        # Right edge of the map in pixels
        self.end_of_map = len(map_array[0]) * GRID_PIXEL_SIZE

        for row_index, row in enumerate(map_array):
            for column_index, item in enumerate(row):

                if item == -1:
                    continue
                elif item == 0:
                    wall = arcade.Sprite("images/boxCrate_double.png", SPRITE_SCALING)
                elif item == 1:
                    wall = arcade.Sprite("images/grassLeft.png", SPRITE_SCALING)
                elif item == 2:
                    wall = arcade.Sprite("images/grassMid.png", SPRITE_SCALING)
                elif item == 3:
                    wall = arcade.Sprite("images/grassRight.png", SPRITE_SCALING)

                wall.left = column_index * GRID_PIXEL_SIZE
                wall.top = (7 - row_index) * GRID_PIXEL_SIZE
                self.all_sprites_list.append(wall)
                self.all_wall_list.append(wall)
                self.static_wall_list.append(wall)

        # Create platform side to side
        wall = arcade.Sprite("images/grassMid.png", SPRITE_SCALING)
        wall.center_y = 3 * GRID_PIXEL_SIZE
        wall.center_x = 3 * GRID_PIXEL_SIZE
        wall.boundary_left = 2 * GRID_PIXEL_SIZE
        wall.boundary_right = 5 * GRID_PIXEL_SIZE
        wall.change_x = 2 * SPRITE_SCALING

        self.all_sprites_list.append(wall)
        self.all_wall_list.append(wall)
        self.moving_wall_list.append(wall)

        # Create platform side to side
        wall = arcade.Sprite("images/grassMid.png", SPRITE_SCALING)
        wall.center_y = 3 * GRID_PIXEL_SIZE
        wall.center_x = 7 * GRID_PIXEL_SIZE
        wall.boundary_left = 5 * GRID_PIXEL_SIZE
        wall.boundary_right = 9 * GRID_PIXEL_SIZE
        wall.change_x = -2 * SPRITE_SCALING

        self.all_sprites_list.append(wall)
        self.all_wall_list.append(wall)
        self.moving_wall_list.append(wall)

        # Create platform moving up and down
        wall = arcade.Sprite("images/grassMid.png", SPRITE_SCALING)
        wall.center_y = 5 * GRID_PIXEL_SIZE
        wall.center_x = 5 * GRID_PIXEL_SIZE
        wall.boundary_top = 8 * GRID_PIXEL_SIZE
        wall.boundary_bottom = 4 * GRID_PIXEL_SIZE
        wall.change_y = 2 * SPRITE_SCALING

        self.all_sprites_list.append(wall)
        self.all_wall_list.append(wall)
        self.moving_wall_list.append(wall)

        # Create platform moving diagonally
        wall = arcade.Sprite("images/grassMid.png", SPRITE_SCALING)
        wall.center_y = 5 * GRID_PIXEL_SIZE
        wall.center_x = 8 * GRID_PIXEL_SIZE
        wall.boundary_left = 7 * GRID_PIXEL_SIZE
        wall.boundary_right = 9 * GRID_PIXEL_SIZE

        wall.boundary_top = 8 * GRID_PIXEL_SIZE
        wall.boundary_bottom = 4 * GRID_PIXEL_SIZE
        wall.change_x = 2 * SPRITE_SCALING
        wall.change_y = 2 * SPRITE_SCALING

        self.all_sprites_list.append(wall)
        self.all_wall_list.append(wall)
        self.moving_wall_list.append(wall)

        self.physics_engine = \
            arcade.PhysicsEnginePlatformer(self.player_sprite,
                                           self.all_wall_list,
                                           gravity_constant=GRAVITY)

        # Set the background color
        arcade.set_background_color(arcade.color.AMAZON)

        # Set the viewport boundaries
        # These numbers set where we have 'scrolled' to.
        self.view_left = 0
        self.view_bottom = 0

        self.game_over = False
Ejemplo n.º 29
0
    def setup(self):
        self.wall_list = arcade.SpriteList(use_spatial_hash=True)
        self.player_list = arcade.SpriteList()

        # Create cave system using a 2D grid
        self.grid = create_grid(GRID_WIDTH, GRID_HEIGHT)
        initialize_grid(self.grid)
        for step in range(NUMBER_OF_STEPS):
            self.grid = do_simulation_step(self.grid)

        # Create sprites based on 2D grid
        if not MERGE_SPRITES:
            # This is the simple-to-understand method. Each grid location
            # is a sprite.
            for row in range(GRID_HEIGHT):
                for column in range(GRID_WIDTH):
                    if self.grid[row][column] == 1:
                        wall = arcade.Sprite("images/grassCenter.png",
                                             SPRITE_SCALING)
                        wall.center_x = column * SPRITE_SIZE + SPRITE_SIZE / 2
                        wall.center_y = row * SPRITE_SIZE + SPRITE_SIZE / 2
                        self.wall_list.append(wall)
        else:
            # This uses new Arcade 1.3.1 features, that allow me to create a
            # larger sprite with a repeating texture. So if there are multiple
            # cells in a row with a wall, we merge them into one sprite, with a
            # repeating texture for each cell. This reduces our sprite count.
            for row in range(GRID_HEIGHT):
                column = 0
                while column < GRID_WIDTH:
                    while column < GRID_WIDTH and self.grid[row][column] == 0:
                        column += 1
                    start_column = column
                    while column < GRID_WIDTH and self.grid[row][column] == 1:
                        column += 1
                    end_column = column - 1

                    column_count = end_column - start_column + 1
                    column_mid = (start_column + end_column) / 2

                    wall = arcade.Sprite("images/grassCenter.png",
                                         SPRITE_SCALING,
                                         repeat_count_x=column_count)
                    wall.center_x = column_mid * SPRITE_SIZE + SPRITE_SIZE / 2
                    wall.center_y = row * SPRITE_SIZE + SPRITE_SIZE / 2
                    wall.width = SPRITE_SIZE * column_count
                    self.wall_list.append(wall)

        # Set up the player
        self.player_sprite = arcade.Sprite("images/character.png",
                                           SPRITE_SCALING)
        self.player_list.append(self.player_sprite)

        # Randomly place the player. If we are in a wall, repeat until we aren't.
        placed = False
        while not placed:

            # Randomly position
            max_x = GRID_WIDTH * SPRITE_SIZE
            max_y = GRID_HEIGHT * SPRITE_SIZE
            self.player_sprite.center_x = random.randrange(max_x)
            self.player_sprite.center_y = random.randrange(max_y)

            # Are we in a wall?
            walls_hit = arcade.check_for_collision_with_list(
                self.player_sprite, self.wall_list)
            if len(walls_hit) == 0:
                # Not in a wall! Success!
                placed = True

        self.physics_engine = arcade.PhysicsEngineSimple(
            self.player_sprite, self.wall_list)
Ejemplo n.º 30
0
 def flag_line(self, x, y, img):
     flag = arcade.Sprite(img, char_scaling)
     flag.center_x = x
     flag.center_y = y
     self.flag_save(flag, 0)  # flag가 생성될때 마다, save
     self.flag_list.append(flag)