Ejemplo n.º 1
0
 def sprites(self, image, x, y, scale=1.0):
     from pyglet.sprite import Sprite
     for i in range(len(x)):
         sprite = Sprite(image, batch=self._batch, group=background)
         sprite.x = x[i]
         sprite.y = y[i]
         sprite.scale = scale
         self._sprites.append(sprite)
Ejemplo n.º 2
0
    def fire(self):
        """Create a new bullet"""
        bullet = Sprite(images['bullet'], batch=self.bullet_batch)
        
        bullet.x = self.player.x + self.player.width  
        bullet.y = self.player.y + self.player.height / 2 - bullet.height / 2

        self.bullets.append(bullet)
Ejemplo n.º 3
0
 def sprites(self, image, x, y, scale=1.0):
     from pyglet.sprite import Sprite
     for i in range(len(x)):
         sprite = Sprite(image, batch=self._batch)
         sprite.x = x[i]
         sprite.y = y[i]
         sprite.scale = scale
         self._sprites.append(sprite)
Ejemplo n.º 4
0
    def background_2(self, dt):
	"""Random stars created in back moving faster"""
	fast_star = Sprite(images['star'], batch=self.fast_star_batch)

	fast_star.y = random.uniform(0, self.height)
	fast_star.x = self.width
	
	fast_star.scale = random.uniform(0.2, 2)

	self.fast_stars.append(fast_star)
Ejemplo n.º 5
0
    def enemy(self, dt):
	"""creates enemies """
        enemy = Sprite(images['windows'], batch=self.enemy_batch)

	enemy.y = random.uniform(0, self.width)
	enemy.x = self.width
	enemy.startX = enemy.x
	enemy.startY = enemy.y

	self.win_enemy.append(enemy)	
Ejemplo n.º 6
0
    def background_1(self, dt):
	"""create random number of stars at random y co ordinates"""
	#for star in self.star:
	star = Sprite(images['star'], batch=self.star_batch)
	
	star.y = random.uniform(0,self.width-2)
	star.x = self.width 

	star.scale = random.uniform(0.2, 2)
	
	self.stars.append(star) 
Ejemplo n.º 7
0
    def on_collide(self, player):
        original_modifier = player.damage_modifier
        immunity_shield = Sprite(load(join('images', 'Shield-B-13_17.png')),
                                 batch=self.batch)
        immunity_shield.image.anchor_x = immunity_shield.width / 2
        immunity_shield.image.anchor_y = immunity_shield.height / 2
        immunity_shield.x = player.x
        immunity_shield.y = player.y

        def reset_player_shield(dt):
            player.damage_modifier = original_modifier
            immunity_shield.delete()
            player.on_move = None

        clock.schedule_once(reset_player_shield, 10)

        def on_move(x, y):
            immunity_shield.x = x
            immunity_shield.y = y

        player.on_move = on_move

        player.damage_modifier = 0
        super().on_collide(player)
Ejemplo n.º 8
0
from pyglet import app, resource, clock
from pyglet.media import Player
from pyglet.sprite import Sprite
from pyglet.text import Label
from pyglet.window import Window, key

window = Window()

MAX_BALL_SPEED = 500
INITIAL_BALL_SPEED = 400

ball_image = resource.image('images/ball.png')
ball = Sprite(ball_image)
ball.x = window.width / 2 - ball.width/2
ball.y = window.height / 2 - ball.width/2

ball.speed_x = INITIAL_BALL_SPEED
ball.speed_y = INITIAL_BALL_SPEED

PADDLE_MARGIN = 10

paddle_image = resource.image('images/paddle.png')
paddle1 = Sprite(paddle_image)
paddle1.x = PADDLE_MARGIN
paddle1.y = window.height / 2 - paddle1.height / 2
paddle1.speed = 400
paddle2 = Sprite(paddle_image)
paddle2.x = window.width - paddle2.width - PADDLE_MARGIN
paddle2.y = window.height / 2 - paddle2.height / 2
paddle2.speed = 400