Example #1
0
 def __init__(self, location, angle):
   GameObject.__init__(self,
     './images/laser.png',
     location,
     angle,
     10)
   self.time = 60
	def __init__(self, world, parent, color, pos, dir, radius, density, posParent=None):
		GameObject.__init__(self, world)

		self.node = parent.attachNewNode("")
		if posParent == None:
			self.node.setPos(*pos)
		else:
			self.node.setPos(posParent, *pos)
		self.node.setColor(*color)
		self.node.setScale(radius)
		self.node.lookAt(self.node, *dir)
		self.parent = parent

		self.color = color
		self.scale = radius

		self.model = loader.loadModel("models/smiley.egg")
		self.model.reparentTo(self.node)

		self.mass = OdeMass()
		self.mass.setSphere(density, radius)
		self.body = OdeBody(world.world)
		self.body.setMass(self.mass)
		self.body.setPosition(self.node.getPos())
		self.body.setQuaternion(self.node.getQuat())
		self.body.setData(self)
		self.geom = OdeSphereGeom(world.space, radius)
		self.geom.setBody(self.body)
		world.space.setSurfaceType(self.geom, world.surfaces["sphere"])
Example #3
0
 def kill(self):
     GameObject.kill(self)
     #from random import randint
     from math import sin,cos
     for i in xrange(8):
         self.parent.addBoulderFragment(pos=self.position,
         vel=(cos((2*3.14159)/8.0*i),sin((2*3.14159)/8.0*i)),id=i)
Example #4
0
 def update(self):
     GameObject.update(self)
     if not self.is_active:
         p = choice(pData)
         self.x = p.x
         self.y = p.y
         self.is_active = True
Example #5
0
    def __init__(self, parent, pos=(0, 0), vel=(0, 0), screenBoundaries=None):
        boulderPath = pathJoin(('images', 'boulder.png'))
        boulderImage = self.imageCache.getImage(boulderPath,
                                                colorkey='alpha',
                                                mask=True)

        GameObject.__init__(self, boulderImage, parent, pos, vel)

        self.minXPos = screenBoundaries[0] + self.rect.width / 2
        self.maxXPos = screenBoundaries[2] - self.rect.width / 2

        if self.position[0] < self.minXPos:
            self.moveTo((self.minXPos, self.position[1]))
        elif self.position[0] > self.maxXPos:
            self.moveTo((self.maxXPos, self.position[1]))
        self.moveTo(
            (self.position[0], self.position[1] - self.rect.height / 2))

        self.mask = self.imageCache.getMask(boulderPath)
        if screenBoundaries == None:
            raise Exception('Boulders must have screen boundaries')
        self.boundaries = screenBoundaries
        self.acceleration = (0, .001)
        self.damage = 5  #Damage done to ship when it hits
        self.value = 5  #How many points the boulder is worth
Example #6
0
    def __init__(self, gameScene, x, y):
        GameObject.__init__(self, gameScene, x, y, 16, 16)

        self.direction = "right"
        self.img = "stationary"

        #Flag indicating if the player is in mid air
        self.jumping = True

        #The number of renders until the animation is updated
        self.animationTick = TICKS_BETWEEN_ANIM_FRAMES

        #The current frame of the animation
        self.animationFrame = 0

        #x and y speeds
        self.xspeed = 0.0
        self.yspeed = 0.0

        #The accurate x and y locations
        self.x = x
        self.y = y

        #Colours
        self.colour = (255, 0, 0)  #active colour
        self.rColour1 = (0, 255, 0)  #reserve colour 1
        self.rColour2 = (0, 0, 255)  #reserve colour 2
Example #7
0
    def enemy_spawn(self, dt):

        self.enemy_typeA_spawner -= dt
        self.enemy_typeB_spawner -= dt
        if self.player_is_alive:
            if self.enemy_typeA_spawner <= 0:
                self.enemy_list.append(
                    GameObject(1000,
                               800,
                               Sprite(self.enemy_imgA, batch=self.main_batch),
                               health=2))
                self.enemy_list[-1].vel_x = randint(100, 300) * choice(
                    self.directions)  # last spawned entity in entity list
                self.enemy_list[-1].vel_y = 30

                self.enemy_typeA_spawner += self.enemy_typeA_counter

            if self.enemy_typeB_spawner <= 0:
                self.enemy_list.append(
                    GameObject(600,
                               950,
                               Sprite(self.enemy_imgB, batch=self.main_batch),
                               health=5))
                self.enemy_list[-1].vel_x = randint(100, 300) * choice(
                    self.directions)  # last spawned entity in entity list
                self.enemy_list[-1].vel_y = 30

                self.enemy_typeB_spawner += self.enemy_typeB_counter

        if self.next_wave >= 20:
            self.enemy_typeA_counter -= 0.05
            self.enemy_typeB_counter -= 0.2
            self.next_wave = 0
Example #8
0
 def __init__(self,gameScene,x,y):
    GameObject.__init__(self,gameScene,x,y,16,16)
    
    self.direction = "right"
    self.img = "stationary"
    
    #Flag indicating if the player is in mid air
    self.jumping = True
    
    #The number of renders until the animation is updated
    self.animationTick = TICKS_BETWEEN_ANIM_FRAMES
    
    #The current frame of the animation
    self.animationFrame = 0
    
    #x and y speeds
    self.xspeed = 0.0
    self.yspeed = 0.0
    
    #The accurate x and y locations
    self.x = x
    self.y = y
    
    #Colours
    self.colour = (255,0,0) #active colour
    self.rColour1 = (0,255,0) #reserve colour 1
    self.rColour2 = (0,0,255) #reserve colour 2
Example #9
0
 def __init__(self, speed, location, image, direction=const.rightDir):
     self.direction = direction
     self.speed = speed
     GameObject.__init__(
         self,
         location,
         image
     )
Example #10
0
    def update(self, *args):
        GameObject.update(self, *args)

        #kill when off-screen:
        if ((self.rect.topleft[0] < self.boundaries[0]) or
           (self.rect.topleft[0] + self.rect.width > self.boundaries[2]) or
           (self.rect.topleft[1] + self.rect.height > self.boundaries[3])):
            self.kill()
Example #11
0
 def __init__(self, x1, y1, x2, y2, length):
     GameObject.__init__(self, 0, 0)
     self.x1 = x1
     self.y1 = y1
     self.x2 = x2
     self.y2 = y2
     self.length = length
     self.collider = False
Example #12
0
    def update(self, *args):
        GameObject.update(self, *args)

        #kill when off-screen:
        if ((self.rect.topleft[0] < self.boundaries[0]) or
            (self.rect.topleft[0] + self.rect.width > self.boundaries[2]) or
            (self.rect.topleft[1] + self.rect.height > self.boundaries[3])):
            self.kill()
Example #13
0
 def __init__(self, x, y, color, brain):
     GameObject.__init__(self, x, y, BIRD_RADIUS, BIRD_RADIUS, FALL_VELOCITY)
     self.color = color
     self.isFlapping = False
     self.flappingTime = 0
     self.brain = brain
     self.isAlive = True
     self.score = 0
     self.drawable = True
Example #14
0
 def kill(self):
     GameObject.kill(self)
     #from random import randint
     from math import sin, cos
     for i in xrange(8):
         self.parent.addBoulderFragment(pos=self.position,
                                        vel=(cos((2 * 3.14159) / 8.0 * i),
                                             sin((2 * 3.14159) / 8.0 * i)),
                                        id=i)
Example #15
0
 def update(self):
     GameObject.update(self)
     for b in bs:
         overlap = BoxCollider.overlap(
             b.boxa, self.box_collider) or BoxCollider.overlap(
                 b.boxb, self.box_collider) or BoxCollider.overlap(
                     b.boxmid, self.box_collider)
         if overlap:
             b.player.run = False
             break
Example #16
0
    def __init__(self, type, name, position, orientation, scale, mass, objects, server=False, guid=None):
        self.objects = objects

        GameObject.__init__(self, type, name, position, orientation, scale, mass, (0.0, 0.0, 0.0), guid)

        self.intelligenceThread = None

        if server:
            return

        vertices, vnormals, f, self.vertexCount = graphics.loadObj(self.objPath())
        self.verticesId, self.normalsId = graphics.createVBO(self.data.type, vertices, vnormals)
Example #17
0
 def update(self, *args):
     GameObject.update(self, *args)
     if (self.stage == 0 or self.stage == 2) and self.position[0] < self.minXPos:
         self.velocity = (-self.velocity[0], self.velocity[1])
         self.stage += 1
     elif (self.stage == 1 or self.stage == 3) and self.position[0] > self.maxXPos:
         self.stage += 1
         self.velocity = (-self.velocity[0], self.velocity[1])
     elif self.stage == 4 and self.position[0] < (self.minXPos + self.maxXPos)/2:
         self.stage += 1
         self.velocity = (0,0)
         self.finished = True
Example #18
0
	def __init__(self, name = "Fireball 1", position = (0.0, 20.0, -40.0), \
			orientation = (0.0, 180.0, 0.0), scale = 0.1, mass = 20, \
			velocity = (0.0, 0.0, 0.0), guid = None, sound = None):
		GameObject.__init__(self, "Fireball", name, position,
				orientation, scale, mass, velocity, guid)

		vertices, vnormals, f, self.vertexCount = \
				graphics.loadObj("data/model/Fireball.obj")
		self.verticesId, self.normalsId = \
				graphics.createVBO(self.data.type, vertices, vnormals)

		self.sound = sound
Example #19
0
    def load_player(self, imagaPlayer, imageLaser):
        player_spr = Sprite(preload(imagaPlayer), batch=self.main_batch)
        self.player = GameObject(500, 100, player_spr, health=5)

        self.player_laser_img = preload(imageLaser)
        self.player_laser = list()

        self.player_gun_sound = pyglet.media.load(
            './res/sounds/player_gun.wav', streaming=False)

        self.player_speed = 300
        self.player_fire_rate = 0
Example #20
0
 def init(self):
     self.handler.init()
     self.assets = self.handler.game.assets
     self.assets.initGameAssets()
     self.camera = GameCamera(self.handler)
     self.player = Player(self.handler)
     self.colors = ['green', 'yellow', 'white', 'blue']
     self.sprites = pygame.sprite.Group()
     self.objects = pygame.sprite.Group()
     
     for _ in range(20):
         pos = random.randint(100, 700), random.randint(100, 600)
         self.circle = GameObject(self.handler, pos, random.choice(self.colors), self.sprites, self.objects)
Example #21
0
    def __init__(self):
        self.width = 800
        self.height = 800
        self.color = (0, 0, 0)
        self.game_window = pygame.display.set_mode((self.width, self.height))
        self.clock = pygame.time.Clock()

        self.background_image = GameObject(0, 0, self.width, self.height, 'assets/background.png')
        self.treasure = GameObject(375, 50, 50, 50, 'assets/treasure.png')

        self.level = 1.0

        self.reset_map()
Example #22
0
    def __init__(self, inputManganer):
        GameObject.__init__(self, 200, 100)
        self.width = 24
        self.height = 12
        self.speed = Vector(3, 0)
        self.inputManganer = inputManganer
        self.center = Vector(200, 100)
        self.check = True

        self.a = None
        self.b = None
        self.mid = self.center.addNew(self.speed.unit().mul(self.width / 2))
        self.run = True
Example #23
0
    def __init__(self, parent, pos=(0,0), vel=(0,0), screenBoundaries=None):

        shipPath = pathJoin(('images','ship.png'))
        shipImage = self.imageCache.getImage(shipPath, colorkey='alpha', mask=True)

        GameObject.__init__(self, shipImage, parent, pos, vel)
        self.targetPosition = pos
        self.mask = self.imageCache.getMask(shipPath)
        self.screenBoundaries = screenBoundaries
        self.health = 100
        self.score = 0
        if screenBoundaries != None:
            self.minXPos = screenBoundaries[0] + self.rect.width/2
            self.maxXPos = screenBoundaries[2] - self.rect.width/2
Example #24
0
	def __init__(self, name = "Player 1", position = (0.0, 20.0, -40.0), \
			orientation = (0.0, 180.0, 0.0), scale = 1.0, mass = 100, \
			guid = None, sound = None):
		GameObject.__init__(self, "player1", name, position,
				orientation, scale, mass, (0.0, 0.0, 0.0), guid)
		vertices, vnormals, f, self.vertexCount = \
				graphics.loadObj("data/model/player1.obj")
		self.verticesId, self.normalsId = \
				graphics.createVBO(self.data.type, vertices, vnormals)

		self.sound = sound

		self.can_jump = 0
		self.rotated = 0.0
Example #25
0
 def __init__(self,gameScene,x,y):
    GameObject.__init__(self,gameScene,x,y,16,16)
    self.direction = "right"
    self.img = "stationary-right"
    
    #flag used to stop movement at the beginning of a life
    self.inMotion = False
    
    #Non-rounded versions of the x and y
    self.x = x
    self.y = y
    
    #X and Y speeds
    self.xmov = 0
    self.ymov = 0
Example #26
0
    def __init__(self, gameScene, x, y):
        GameObject.__init__(self, gameScene, x, y, 16, 16)
        self.direction = "right"
        self.img = "stationary-right"

        #flag used to stop movement at the beginning of a life
        self.inMotion = False

        #Non-rounded versions of the x and y
        self.x = x
        self.y = y

        #X and Y speeds
        self.xmov = 0
        self.ymov = 0
Example #27
0
    def update(self, *args):
        GameObject.update(self, *args)

        #observe wall boundaries
        if self.position[0] < self.minXPos:
            self.moveTo((self.minXPos, self.position[1]))
            self.velocity = -self.velocity[0], self.velocity[1]
        elif self.position[0] > self.maxXPos:
            self.moveTo((self.maxXPos, self.position[1]))
            self.velocity = -self.velocity[0], self.velocity[1]

        #hit the ground
        if self.rect.topleft[1] + self.rect.height > self.boundaries[3]:

            self.parent.killBoulder(self)
Example #28
0
 def update(self, *args):
     GameObject.update(self, *args)
     if (self.stage == 0
             or self.stage == 2) and self.position[0] < self.minXPos:
         self.velocity = (-self.velocity[0], self.velocity[1])
         self.stage += 1
     elif (self.stage == 1
           or self.stage == 3) and self.position[0] > self.maxXPos:
         self.stage += 1
         self.velocity = (-self.velocity[0], self.velocity[1])
     elif self.stage == 4 and self.position[0] < (self.minXPos +
                                                  self.maxXPos) / 2:
         self.stage += 1
         self.velocity = (0, 0)
         self.finished = True
Example #29
0
    def update(self, *args):
        GameObject.update(self, *args)

        #observe wall boundaries
        if self.position[0] < self.minXPos:
            self.moveTo((self.minXPos, self.position[1]))
            self.velocity = -self.velocity[0], self.velocity[1]
        elif self.position[0] > self.maxXPos:
            self.moveTo((self.maxXPos, self.position[1]))
            self.velocity = -self.velocity[0], self.velocity[1]

        #hit the ground
        if self.rect.topleft[1] + self.rect.height > self.boundaries[3]:

            self.parent.killBoulder(self)
Example #30
0
	def __init__(self, world, parent, color, pos, dir, size, density, unglueThreshold=None, shatterLimit=None, shatterThreshold=None):
		GameObject.__init__(self, world)

		if unglueThreshold == None: unglueThreshold = 20
		if shatterLimit == None: shatterLimit = 0
		if shatterThreshold == None: shatterThreshold = 30

		self.size = size
		self.density = density
		self.dir = dir
		self.parent = parent
		self.color = color = makeVec4Color(color)
		
		self.node = parent.attachNewNode("")
		self.node.setPos(*pos)
		self.node.setColorScale(color)
		self.node.setScale(*size)
		self.node.lookAt(self.node, *dir)

		self.model = loader.loadModel("models/box.egg")
		self.model.reparentTo(self.node)
		self.model.setScale(2.0)
		self.model.setPos(-1.0, -1.0, -1.0)

		self.applyTexture()

		self.mass = OdeMass()
		self.mass.setBox(density, Vec3(*size) * 2)
		self.body = OdeBody(world.world)
		self.body.setMass(self.mass)
		self.body.setPosition(self.node.getPos())
		self.body.setQuaternion(self.node.getQuat())
		self.body.setData(self)
		self.geom = OdeBoxGeom(world.space, Vec3(*size) * 2.0)
		self.geom.setBody(self.body)
		world.space.setSurfaceType(self.geom, world.surfaces["box"])

		# Adjust collision bitmasks.
		self.geom.setCategoryBits(GameObject.bitmaskBox)
		self.geom.setCollideBits(GameObject.bitmaskAll & ~GameObject.bitmaskTileGlued)

		# Tile, cement and shatter variables.
		self.tiles = []
		self.cements = []
		self.disableCount = 0
		self.unglueThreshold = unglueThreshold
		self.shatterLimit = shatterLimit
		self.shatterThreshold = shatterThreshold
Example #31
0
    def enemy_behavior(self, dt):
        for enemy in self.enemy_list:
            if enemy.pos_x >= 1000:
                enemy.pos_x = 1000
                enemy.vel_x *= -1

            if enemy.pos_x <= 100:
                enemy.pos_x = 100
                enemy.vel_x *= -1

            enemy.pos_y -= enemy.vel_y * dt
            enemy.pos_x += enemy.vel_x * dt
            enemy.sprite.x = enemy.pos_x
            enemy.sprite.y = enemy.pos_y
            if 450 >= enemy.pos_y >= 449.4 and self.player_is_alive:
                self.score -= 1
                self.num_score.text = str(self.score)

            if enemy.pos_y <= -100:
                self.enemy_list.remove(enemy)

            self.enemy_fire_rate -= dt

            if self.enemy_fire_rate <= 0:
                for enemy in self.enemy_list:
                    if randint(0, 10) >= 5:
                        self.enemy_laser.append(
                            GameObject(
                                enemy.pos_x + 50, enemy.pos_y,
                                Sprite(self.enemy_laser_img,
                                       batch=self.main_batch)))

                self.enemy_fire_rate += 10
Example #32
0
    def update(self, dt):
        if self.game:
            self.player_behavior(dt)
            self.enemy_behavior(dt)
            self.laser_shot(dt)

            for entity in self.enemy_list:
                if self.laser_collision(entity, self.player_laser):
                    self.enemy_hit(entity)

            if self.laser_collision(self.player,
                                    self.enemy_laser) and self.player_is_alive:
                self.player_hit()

            if self.player_flash:
                self.update_flash()

            self.update_explosion()
            self.enemy_spawn(dt)

            if self.enemy_explode:
                self.screen_shake()

            self.enemy_spawn(dt)

        for sheet in self.background:
            sheet.update(dt)
            if sheet.pos_y <= -1300:
                self.background.remove(sheet)
                self.background.append(
                    GameObject(0, 1100, Sprite(self.background_img)))
            sheet.vel_y = -100
Example #33
0
    def __init__(self, parent, pos=(0,0), vel=(0,0), id=0, screenBoundaries = None):
        fragmentPath = pathJoin(('images','fragments','fragment'+str(id)+'.png'))
        fragmentImage = self.imageCache.getImage(fragmentPath, colorkey='alpha', mask=False)

        rect = self.imageCache.getRect(fragmentPath)

        GameObject.__init__(self, fragmentImage, parent, pos, vel)

        if screenBoundaries == None:
            raise Exception('Boulders must have screen boundaries')
        self.boundaries = (screenBoundaries[0]-rect.width,
                           screenBoundaries[1]-rect.height,
                           screenBoundaries[2]+rect.width,
                           screenBoundaries[3]+rect.height)

        self.acceleration = (0,0.001)
Example #34
0
    def __init__(self, parent, pos=(0, 0), vel=(0, 0), screenBoundaries=None):

        shipPath = pathJoin(('images', 'ship.png'))
        shipImage = self.imageCache.getImage(shipPath,
                                             colorkey='alpha',
                                             mask=True)

        GameObject.__init__(self, shipImage, parent, pos, vel)
        self.targetPosition = pos
        self.mask = self.imageCache.getMask(shipPath)
        self.screenBoundaries = screenBoundaries
        self.health = 100
        self.score = 0
        if screenBoundaries != None:
            self.minXPos = screenBoundaries[0] + self.rect.width / 2
            self.maxXPos = screenBoundaries[2] - self.rect.width / 2
Example #35
0
    def getSurface(self):
        surface = GameObject.getSurface(self)

        edge = 16 * self.level
        newSize = (edge, edge)
        scaledSurface = pygame.transform.scale(surface, newSize)

        return scaledSurface
Example #36
0
	def __init__(self, world, parent, color, pos, dir, radius, density, posParent=None):
		GameObject.__init__(self, world)

		self.color = makeVec4Color(color)
		self.scale = radius
		self.collisionCount = 0

		diameter = 2 * radius
		length = 1.815 * diameter

		self.node = parent.attachNewNode("")
		if posParent == None:
			self.node.setPos(*pos)
		else:
			self.node.setPos(posParent, *pos)
		self.node.setColorScale(self.color)
		self.node.setTransparency(TransparencyAttrib.MAlpha)
		self.node.setScale(radius)
		self.node.lookAt(self.node, *dir)
		self.node.setHpr(self.node.getHpr() + Vec3(0, 270, 0))

		self.model = loader.loadModel("models/bullet.egg")
		self.model.reparentTo(self.node)
		self.model.setPos(-0.1, -0.1, 0.15)
		self.model.setScale(0.4)

		self.mass = OdeMass()
		self.mass.setCylinder(density, 3, radius, length)
		self.body = OdeBody(world.world)
		self.body.setMass(self.mass)
		self.body.setPosition(self.node.getPos())
		self.body.setQuaternion(self.node.getQuat())
		self.body.setData(self)
		self.body.setGravityMode(False)
		self.geom = OdeCylinderGeom(world.space, radius, length)
		self.geom.setBody(self.body)
		world.space.setSurfaceType(self.geom, world.surfaces["bullet"])

		# Adjust collision bitmasks.
		self.geom.setCategoryBits(GameObject.bitmaskBullet)
		self.geom.setCollideBits(GameObject.bitmaskAll & ~GameObject.bitmaskCharacter)

		# Keep the bullet hidden for a split second so it doesn't appear too close to the camera.
		self.node.hide()
		taskMgr.doMethodLater(0.1, self.showTask, 'show-bullet')
Example #37
0
    def __init__(self):

        #The loop - This is what makes the game go so it doesn't instantly quit out
        #Variables
        self.width = 800
        self.height = 800
        self.white_color = (255, 255, 255)
        # Game Screen - Takes in a Tuple: width, height in pixels
        self.game_window = pygame.display.set_mode((self.width, self.height))

        self.clock = pygame.time.Clock(
        )  # The Clock, or how often things update

        #Game Objects
        self.background = GameObject(0, 0, self.width, self.height,
                                     'assets/background.png')
        self.treasure = GameObject(375, 50, 50, 50, 'assets/treasure.png')

        self.level = 1.0

        self.reset_map()
Example #38
0
    def __init__(self, parent, pos=(0,0), vel=(0,0), screenBoundaries = None):
        boulderPath = pathJoin(('images','boulder.png'))
        boulderImage = self.imageCache.getImage(boulderPath, colorkey='alpha', mask=True)

        GameObject.__init__(self, boulderImage, parent, pos, vel)
        
        self.minXPos = screenBoundaries[0] + self.rect.width/2
        self.maxXPos = screenBoundaries[2] - self.rect.width/2
        
        if self.position[0] < self.minXPos:
            self.moveTo((self.minXPos, self.position[1]))
        elif self.position[0] > self.maxXPos:
            self.moveTo((self.maxXPos, self.position[1]))
        self.moveTo((self.position[0],self.position[1]-self.rect.height/2))
        
        self.mask = self.imageCache.getMask(boulderPath)
        if screenBoundaries == None:
            raise Exception('Boulders must have screen boundaries')
        self.boundaries = screenBoundaries
        self.acceleration = (0,.001)
        self.damage = 5 #Damage done to ship when it hits
        self.value = 5 #How many points the boulder is worth
Example #39
0
class GameState():

    def __init__(self, handler):
        self.handler = handler
        
    def init(self):
        self.handler.init()
        self.assets = self.handler.game.assets
        self.assets.initGameAssets()
        self.camera = GameCamera(self.handler)
        self.player = Player(self.handler)
        self.colors = ['green', 'yellow', 'white', 'blue']
        self.sprites = pygame.sprite.Group()
        self.objects = pygame.sprite.Group()
        
        for _ in range(20):
            pos = random.randint(100, 700), random.randint(100, 600)
            self.circle = GameObject(self.handler, pos, random.choice(self.colors), self.sprites, self.objects)

    # def switchState(self, state):
    #   self.currentState = state
    #   if type(state) is GameState:
    #       self.handler.setUIManager(self.handler.game.gameState.gameUiManager)
    #   elif type(state) is MenuState:
    #       self.handler.setUIManager(self.handler.game.menuState.menuUiManager)

    
        
    def tick(self):
        self.player.tick()
        self.handler.characterManager.tick()
        # self.gameObject.tick()
        
    def draw(self):
        self.handler.game.WIN.blit(self.assets.bg, (0 - self.camera.xOffset, 0 - self.camera.yOffset))
        # self.handler.characterManager.draw()
        self.player.draw()
        self.circle.draw()
Example #40
0
    def __init__(self):         # constructor
        
        self.height = 700        # self. makes this a property rather than a variable
        self.width  = 800
        self.white_colour = (255, 255, 255)
        
        # part of pygame library
        self.clock = pygame.time.Clock()

        # set the game level, increment by 0.5
        self.level = 1.0

        # create the game window
        self.game_window = pygame.display.set_mode((self.width, self.height))

        # create the background image
        self.background = GameObject(0, 0, self.width, self.height, "assets/background.png")

        # create the treasure image
        self.treasure   = GameObject(375, 25, 50, 50, "assets/treasure.png")

        # set the game state based on the initial level
        self.reset_map()
    def __init__(self,
                 world,
                 parent,
                 color,
                 pos,
                 dir,
                 radius,
                 density,
                 posParent=None):
        GameObject.__init__(self, world)

        self.node = parent.attachNewNode("")
        if posParent == None:
            self.node.setPos(*pos)
        else:
            self.node.setPos(posParent, *pos)
        self.node.setColor(*color)
        self.node.setScale(radius)
        self.node.lookAt(self.node, *dir)
        self.parent = parent

        self.color = color
        self.scale = radius

        self.model = loader.loadModel("models/smiley.egg")
        self.model.reparentTo(self.node)

        self.mass = OdeMass()
        self.mass.setSphere(density, radius)
        self.body = OdeBody(world.world)
        self.body.setMass(self.mass)
        self.body.setPosition(self.node.getPos())
        self.body.setQuaternion(self.node.getQuat())
        self.body.setData(self)
        self.geom = OdeSphereGeom(world.space, radius)
        self.geom.setBody(self.body)
        world.space.setSurfaceType(self.geom, world.surfaces["sphere"])
Example #42
0
 def player_behavior(self, dt):
     self.player.update(dt)
     if self.right and self.player.pos_x < 1000 - self.player.sprite.width:
         self.player.pos_x += self.player_speed * dt
     if self.left and self.player.pos_x > 1:
         self.player.pos_x -= self.player_speed * dt
     if self.fire:
         self.player_fire_rate -= dt
         if self.player_fire_rate <= 0:
             self.player_laser.append(
                 GameObject(
                     self.player.pos_x + 7, self.player.pos_y + 30,
                     Sprite(self.player_laser_img, batch=self.main_batch)))
             self.player_fire_rate += 0.4
             self.player_gun_sound.play()
Example #43
0
    def __init__(self,
                 parent,
                 pos=(0, 0),
                 vel=(0, 0),
                 id=0,
                 screenBoundaries=None):
        fragmentPath = pathJoin(
            ('images', 'fragments', 'fragment' + str(id) + '.png'))
        fragmentImage = self.imageCache.getImage(fragmentPath,
                                                 colorkey='alpha',
                                                 mask=False)

        rect = self.imageCache.getRect(fragmentPath)

        GameObject.__init__(self, fragmentImage, parent, pos, vel)

        if screenBoundaries == None:
            raise Exception('Boulders must have screen boundaries')
        self.boundaries = (screenBoundaries[0] - rect.width,
                           screenBoundaries[1] - rect.height,
                           screenBoundaries[2] + rect.width,
                           screenBoundaries[3] + rect.height)

        self.acceleration = (0, 0.001)
Example #44
0
 def __init__(self,gameScene,x,y):
    GameObject.__init__(self,gameScene,x,y,16,16)
Example #45
0
 def __init__(self):
     ''' target: 'player' lub 'enemy'. Określa z czym rakieta koliduje '''
     GameObject.__init__(self)
     self.__target = None       # W co powinna trafić. Możliwe wartości to: 'player' i 'enemy'
     self.__damage = 2          # Obrażenia zadawane przez rakietę
Example #46
0
 def kill(self):
     GameObject.kill(self)
Example #47
0
 def __init__(self,gameScene,x,y,colour):
    GameObject.__init__(self,gameScene,x,y,16,16,colour)
Example #48
0
 def __init__(self):
     GameObject.__init__(self)
	def destroy(self):
		for tile in self.tiles:
			tile.unglue()
		for cement in self.cements:
			cement.destroy()
		GameObject.destroy(self)