def __init__(self): super(Game, self).__init__(255, 255, 255, 255) self.player = player.Player() self.collision_manager = cm.CollisionManagerBruteForce() self.add(self.player, z=1) self.player.do(Move()) self.player.jumping = False self.collision_manager.add(self.player) self.obstacle = cocos.sprite.Sprite(resources.obstacle) self.obstacle.position = 770, 30 self.obstacle.velocity = -100, 0 self.obstacle.speed = 50 self.add(self.obstacle, z=1) self.obstacle.do(Move()) self.obstacle.cshape = cm.AARectShape(self.obstacle.position, self.obstacle.width / 3, self.obstacle.height / 2) self.collision_manager.add(self.obstacle) self.player.schedule(self.update)
def __init__(self): super(Game,self).__init__(202, 202, 125, 155) self.collision_manager = cm.CollisionManagerBruteForce() img = pyglet.image.load("resources/sprite.png") self.img2= pyglet.image.load("resources/fireball.png") self.bullets = [] self.kierunek = "Right" self.img_grid = pyglet.image.ImageGrid(img, 8,10, item_width = 120, item_height=130) self.anim = pyglet.image.Animation.from_image_sequence(self.img_grid[50:51], 1/150 , True) self.animWalkUp = pyglet.image.Animation.from_image_sequence(self.img_grid[10:20], 1/15 , True) self.animWalkDown = pyglet.image.Animation.from_image_sequence(self.img_grid[30:40], 1/15 , True) self.animWalkRight = pyglet.image.Animation.from_image_sequence(self.img_grid[0:10], 1/15 , True) self.animWalkLeft = pyglet.image.Animation.from_image_sequence(self.img_grid[20:30], 1/15 , True) self.leftPressed = False self.righPressed = False self.upPressed = False self.downPressed = False self.spacePressed= False self.keysPressed = [] self.keysPressed.append(None) self.keysPressed.append(None) self.keysPressed.append(None) self.player = cocos.sprite.Sprite(self.anim) self.player.position = 400, 225 self.player.velocity = 0, 0 self.player.speed =150 super().add(self.player) self.player.do(Move())
def __init__(self): super(Game, self).__init__(102, 102, 225, 255) self.player = cocos.sprite.Sprite(resources.player) self.player.position = 400, 25 self.player.velocity = 0, 0 self.player.speed = 150 self.add(self.player, z=2) self.boss = cocos.sprite.Sprite(resources.boss) self.boss.position = 400, 600 self.boss.scale = 0.4 self.add(self.boss, z=1) self.batch = cocos.batch.BatchNode() self.enemies = [cocos.sprite.Sprite(resources.enemy) for i in range(6)] positions = ((250, 125), (550, 125), (300, 325), (500, 325), (150, 475), (650, 475)) for num, enem in enumerate(self.enemies): enem.position = positions[num] self.batch.add(enem) self.add(self.batch, z=1) self.player.do(Move())
def __init__(self): super(Game, self).__init__(202, 202, 125, 155) self.collision_manager = cm.CollisionManagerBruteForce() self.image = pyglet.image.load("resources/sprite.png") self.fireballImage = pyglet.image.load("resources/fireball.png") self.wolfImage = pyglet.image.load("resources/wolf.png") self.image_grid = pyglet.image.ImageGrid(self.image, 8, 10, item_width=120, item_height=130) self.image_grid2 = pyglet.image.ImageGrid(self.wolfImage, 6, 20, item_width=32, item_height=64) self.walkingWolf = pyglet.image.Animation.from_image_sequence( self.image_grid2[40:45], 0.1, True) self.wolfKnockout = pyglet.image.Animation.from_image_sequence( self.image_grid2[66:70], 0.1, True) self.image_grid_fireball = pyglet.image.ImageGrid(self.fireballImage, 8, 8, item_width=64, item_height=64) self.fireballAnimation = pyglet.image.Animation.from_image_sequence( self.image_grid_fireball[8:16], 0.1, True) self.animationStop = pyglet.image.Animation.from_image_sequence( self.image_grid[10:11], 0.1, True) self.animationUp = pyglet.image.Animation.from_image_sequence( self.image_grid[10:20], 0.1, True) self.animationDown = pyglet.image.Animation.from_image_sequence( self.image_grid[30:40], 0.1, True) self.animationRight = pyglet.image.Animation.from_image_sequence( self.image_grid[0:10], 0.1, True) self.animationLeft = pyglet.image.Animation.from_image_sequence( self.image_grid[20:30], 0.1, True) self.player = cocos.sprite.Sprite(self.animationStop) self.kierunek = "left" self.bullets = [] self.player.position = 400, 100 self.player.velocity = 0, 0 self.player.speed = 500 super().add(self.player) self.player.do(Move()) self.schedule(self.update) self.lives = 10 self.motion = True self.points = 0
def __init__(self): super(Game, self).__init__(102, 102, 225, 255) self.collision_manager = cm.CollisionManagerBruteForce() self.player = cocos.sprite.Sprite('eleph2.png') self.player.position = 400, 25 self.player.velocity = 0, 0 self.player.speed = 150 self.player.scale = .5 self.add(self.player, z=2) self.player.cshape = cm.AARectShape(self.player.position, self.player.width // 2, self.player.height // 2) self.collision_manager.add(self.player) self.boss = cocos.sprite.Sprite('flaregun.png') self.boss.position = 400, 600 self.boss.scale = 0.4 self.add(self.boss, z=1) self.boss.cshape = cm.AARectShape(self.boss.position, self.boss.width // 2, self.boss.height // 2) self.collision_manager.add(self.boss) self.batch = cocos.batch.BatchNode() self.enemies = [cocos.sprite.Sprite('compass.png') for i in range(6)] positions = ((250, 125), (550, 125), (300, 325), (500, 325), (150, 475), (650, 475)) for num, enem in enumerate(self.enemies): enem.position = positions[num] enem.cshape = cm.AARectShape(enem.position, enem.width // 2, enem.height // 2) self.collision_manager.add(enem) self.batch.add(enem) self.add(self.batch, z=1) self.player.do(Move()) move_basic = MoveBy((120, 0), 1) self.enemies[0].do(Repeat(move_basic + Reverse(move_basic))) self.enemies[1].do(Repeat(Reverse(move_basic) + move_basic)) move_complex = (MoveBy((-75, 75), 1) + Delay(0.5) + MoveBy( (-75, -75), 1) + Delay(0.5) + MoveBy( (75, -75), 1) + Delay(0.5) + MoveBy((75, 75), 1) + Delay(0.5)) self.enemies[2].do(Repeat(move_complex)) self.enemies[3].do(Repeat(Reverse(move_complex))) move_jump = AccelDeccel(JumpBy((200, 0), 75, 3, 3)) move_jump_rot = AccelDeccel(RotateBy(360, 3)) self.enemies[4].do(Repeat(move_jump + Reverse(move_jump))) self.enemies[4].do(Repeat(move_jump_rot + Reverse(move_jump_rot))) self.enemies[5].do(Repeat(Reverse(move_jump) + move_jump)) self.enemies[5].do(Repeat(Reverse(move_jump_rot) + move_jump_rot)) self.schedule(self.update)
def __init__(self): super(Game,self).__init__(202, 202, 125, 155) self.collision_manager = cm.CollisionManagerBruteForce() self.collision_manager.enabled = True self.collision_manager.enabledDrawBoundingBox = True; img = pyglet.image.load("resources/sprite.png") self.img2= pyglet.image.load("resources/fireball.png") self.bullets = [] self.kierunek = "Right" self.img_grid = pyglet.image.ImageGrid(img, 8,10, item_width = 120, item_height=130) self.anim = pyglet.image.Animation.from_image_sequence(self.img_grid[50:51], 1/150 , True) self.animWalkUp = pyglet.image.Animation.from_image_sequence(self.img_grid[10:20], 1/15 , True) self.animWalkDown = pyglet.image.Animation.from_image_sequence(self.img_grid[30:40], 1/15 , True) self.animWalkRight = pyglet.image.Animation.from_image_sequence(self.img_grid[0:10], 1/15 , True) self.animWalkLeft = pyglet.image.Animation.from_image_sequence(self.img_grid[20:30], 1/15 , True) self.leftPressed = False self.righPressed = False self.upPressed = False self.downPressed = False self.spacePressed= False self.keysPressed = [] self.keysPressed.append(None) self.keysPressed.append(None) self.keysPressed.append(None) self.player = cocos.sprite.Sprite(self.anim) self.player.position = 400, 225 self.player.velocity = 0, 0 self.player.speed =150 self.player.scale = 0.2 self.player.cshape = cm.AARectShape( self.player.position, self.player.width/2, self.player.height/2 ) super().add(self.player) self.collision_manager.add(self.player) super().add(self.player) #super().add(mapWalls().returnMapWalls()) self.mapWalls= mapWalls(self.collision_manager) self.wallsColliding = self.mapWalls.returnMapWalls() for obj in self.wallsColliding: self.collision_manager.add(obj) super().add(self.mapWalls.returnMapWallsBatch()) brick=segment(100,500).returnSprite() brick.cshape = cm.AARectShape( brick.position, brick.width, brick.height ) self.collision_manager.add(brick) super().add(brick) #self.collision_manager.add(self.mapWalls self.licznik = 0 self.player.do(Move()) self.schedule(self.update)
def update(self,dt): self.player.cshape.center = self.player.position collidingWithPlayer = self.collision_manager.objs_colliding(self.player) if(collidingWithPlayer): for obj in self.wallsColliding: if(obj in collidingWithPlayer): self.licznik = self.licznik + 1 self.playerBack() self.player.do(Move())
def __init__(self, e): super(EnemyObject, self).__init__(e[0].R.ENEMY[e[1]]) #X(axis)-Location for enemy self.e = e self.isDead = False self.scale = 0.7 self.position = (director._window_virtual_width, random.randint(30,director._window_virtual_height - 34 - self.height/2)) self.velocity = (-100, 0) self.deadtemplate = Delay(0.5) + CallFunc(self.destroy) self.do(Move()) #Collision Shape self.cshape = CollisionModel.AARectShape(self.position, self.width/2, self.height/2)
def shootBullet(self): if gVariables.g_IS_FX: SFX(self.R._SFX[0]) bullet = Sprite(self.R._BULLET[gVariables.g_PlayerIndex]) bullet.position = (self.PLAYER.position[0] + bullet.width / 2, self.PLAYER.position[1]) bullet.cshape = CollisionModel.AARectShape(bullet.position, bullet.width / 2, bullet.height / 2) bullet.scale = 0.8 bullet.velocity = (self.bullet_speed, 0) bullet.do(Move()) self.bullet_Lists.add(bullet) self.collisionManager.add(bullet) self.batch.add(bullet, self.bulletZ)
def set(self, gScene): self.gScene = gScene self.R = gScene.R self.enemy = gScene.ENEMY self.batch = gScene.batch self.collisionManager = gScene.collisionManager self.startLocation = (50, director._window_virtual_height - 120) self.PLAYER = Sprite(self.R.PLAYERANIME[gVariables.g_PlayerIndex]) self.PLAYER.position = self.startLocation self.PLAYER.scale = 0.5 self.PLAYER.velocity = (0, 0) self.PLAYER.speed = 200 self.collisionManager.add(self.PLAYER) self.PLAYER.do(Move()) self.PLAYER.do(MoveBy((400, 0), 2) + MoveBy((-400, 0), 2)) self.batch.add(self.PLAYER) self.PLAYER.cshape = CollisionModel.AARectShape( self.PLAYER.position, self.PLAYER.width / 2, self.PLAYER.height / 2) self.schedule(self.update)
def __init__(self): super(Game, self).__init__(102, 102, 225, 255) self.player = cocos.sprite.Sprite(resources.player) self.player.position = 400, 25 self.player.velocity = 0, 0 self.player.speed = 150 self.add(self.player, z=2) self.boss = cocos.sprite.Sprite(resources.boss) self.boss.position = 400, 600 self.boss.scale = 0.4 self.add(self.boss, z=1) self.batch = cocos.batch.BatchNode() self.enemies = [cocos.sprite.Sprite(resources.enemy) for i in range(6)] positions = ((250, 125), (550, 125), (300, 325), (500, 325), (150, 475), (650, 475)) for num, enem in enumerate(self.enemies): enem.position = positions[num] self.batch.add(enem) self.add(self.batch, z=1) self.player.do(Move()) move_basic = MoveBy((120, 0), 1) self.enemies[0].do(Repeat(move_basic + Reverse(move_basic))) self.enemies[1].do(Repeat(Reverse(move_basic) + move_basic)) move_complex = (MoveBy((-75, 75), 1) + Delay(0.5) + MoveBy( (-75, -75), 1) + Delay(0.5) + MoveBy( (75, -75), 1) + Delay(0.5) + MoveBy((75, 75), 1) + Delay(0.5)) self.enemies[2].do(Repeat(move_complex)) self.enemies[3].do(Repeat(Reverse(move_complex))) move_jump = AccelDeccel(JumpBy((200, 0), 75, 3, 3)) move_jump_rot = AccelDeccel(RotateBy(360, 3)) self.enemies[4].do(Repeat(move_jump + Reverse(move_jump))) self.enemies[4].do(Repeat(move_jump_rot + Reverse(move_jump_rot))) self.enemies[5].do(Repeat(Reverse(move_jump) + move_jump)) self.enemies[5].do(Repeat(Reverse(move_jump_rot) + move_jump_rot))
def __init__(self): super(Game, self).__init__(202, 202, 125, 155) self.collision_manager = cm.CollisionManagerBruteForce() self.image = pyglet.image.load("resources/sprite.png") self.fireballImage = pyglet.image.load("resources/fireball.png") self.wolfImage = pyglet.image.load("resources/wolf.png") self.image_grid = pyglet.image.ImageGrid(self.image, 8, 10, item_width=120, item_height=130) self.image_grid2 = pyglet.image.ImageGrid(self.wolfImage, 6, 20, item_width=32, item_height=64) self.walkingWolf = pyglet.image.Animation.from_image_sequence( self.image_grid2[40:45], 0.1, True) self.wolfKnockout = pyglet.image.Animation.from_image_sequence( self.image_grid2[66:70], 0.1, True) self.image_grid_fireball = pyglet.image.ImageGrid(self.fireballImage, 8, 8, item_width=64, item_height=64) self.fireballAnimation = pyglet.image.Animation.from_image_sequence( self.image_grid_fireball[8:16], 0.1, True) self.animationStop = pyglet.image.Animation.from_image_sequence( self.image_grid[10:11], 0.1, True) self.animationUp = pyglet.image.Animation.from_image_sequence( self.image_grid[10:20], 0.1, True) self.animationDown = pyglet.image.Animation.from_image_sequence( self.image_grid[30:40], 0.1, True) self.animationRight = pyglet.image.Animation.from_image_sequence( self.image_grid[0:10], 0.1, True) self.animationLeft = pyglet.image.Animation.from_image_sequence( self.image_grid[20:30], 0.1, True) self.player = cocos.sprite.Sprite(self.animationStop) self.kierunek = "left" self.bullets = [] self.player.position = 400, 100 self.player.velocity = 0, 0 self.player.speed = 500 self.wolves = [] for i in range(5): wilk = enemy(randint(50, 750), self.walkingWolf) super().add(wilk.returnSprite()) self.collision_manager.add(wilk.returnSprite) self.wolves.append(wilk) super().add(self.player) self.player.do(Move()) self.schedule(self.update) self.lives = 10 self.motion = True self.points = 0 self.labelPoints = cocos.text.Label(str(self.points), font_size=32, font_name="Comic Sans", color=(255, 20, 147, 100)) self.labelLives = cocos.text.Label(str(self.lives), font_size=32, font_name="Comic Sans", color=(25, 255, 25, 100)) self.naszaEtykieta = cocos.text.Label("Antek", font_size=20, font_name="Comic Sans", color=(25, 255, 25, 30)) self.naszaEtykieta.position = 0, 400 super().add(self.naszaEtykieta) self.labelPoints.position = 700, 600 self.labelLives.position = 50, 600 super().add(self.labelPoints) super().add(self.labelLives) self.canGo = True