示例#1
0
 def __init__(self, game, data):
     super(BatCollider, self).__init__(game)
     # global static data to all of BatCollider components
     self.radius = 10.0
     self.damage = 1.0
     self.dim = Vec3(20, 8, 16)
     self.orig = Vec3(10, 4, 0)
示例#2
0
 def __init__(self, common_data, init=False):
     if init:
         pass
     else:
         pass
     self.orig = Vec3(12, 16, 4)
     self.dim = Vec3(24, 32, 12)
示例#3
0
	def receiveCollision(self, data, common_data, message=False):
		# log("Hero hit: "+message["name"])
		if message:
			if(message.damage_hero>0):
				data.vel += message.force / data.mass
				if (common_data.state not in self.invincible_states
					and not data.invincible>0):
					# hero has been hit
					data.health-=message.damage_hero
					hurt_cool = 1
					fall_cool = 3
					if data.facing == eDirections.left:
						data.vel += Vec3(3,0,0)
						if data.health <= 0:
							self.setState(data, common_data, eStates.fallLeft, fall_cool)
							data.health =-1
						else:
							self.setState(data, common_data, eStates.hurtLeft, hurt_cool)

					else:
						data.vel += Vec3(-3,0,0)
						if data.health <= 0:
							self.setState(data, common_data, eStates.fallRight, fall_cool)
							data.health =-1
						else:
							self.setState(data, common_data, eStates.hurtRight, hurt_cool)
					data.invincible = data.invincible_cooldown
示例#4
0
 def __init__(self, common_data, init=False):
     if init:
         pass
     else:
         pass
     self.dim = Vec3(10, 16, 8)
     self.orig = Vec3(5, 8, 4)
示例#5
0
		def __init__(self, common_data, init=False):
			if init:
				pass
			else:
				pass
			self.dim = Vec3(50,30,10)
			self.orig = Vec3(25,20,5)
示例#6
0
def director_meet(game):
    bunnies = game.game_data['bunnies']
    return [
        FadeToClearColor(Color(0, 0, 0), 2),
        FadeRenderLayer('overlay', Color(1, 1, 1, 1), 1),
        FadeRenderLayer('game', Color(1, 1, 1, 1), 1),
        Message("Meet the bunnies.", Vec3(240, 250, 0), Color(1, 1, 1, 1), 4,
                px_graphics.eAlign.centre),
        Delay(1.5),
        Message("Pinkie.", Vec3(220, 180, 0), bunnies['pinkie'].color, 2,
                px_graphics.eAlign.centre),
        MakeEntity('pinkie meet', 'pinkie', Vec3(220, 150, 1), game),
        Delay(1.6),
        Message("Blue.", Vec3(240, 180, 0), bunnies['blue'].color, 2,
                px_graphics.eAlign.centre),
        MakeEntity('blue meet', 'blue', Vec3(240, 150, 1), game),
        Delay(0.9),
        Message("Bowie.", Vec3(260, 180, 0), bunnies['bowie'].color, 2,
                px_graphics.eAlign.centre),
        MakeEntity('bowie meet', 'bowie', Vec3(260, 150, 1), game),
        Delay(1.5),
        Message("and of course:", Vec3(240, 130, 0), Color(1, 1, 1), 2.5,
                px_graphics.eAlign.centre),
        Delay(2),
        Message("Pac-Bun", Vec3(240, 120, 0), bunnies['pacbun'].color, 3,
                px_graphics.eAlign.centre),
        MakeEntity('pacbun meet', 'pacbun', Vec3(240, 85, 1), game),
        Delay(3),
        MakeDirector('fade_to_next_scene')
    ]
示例#7
0
 def __init__(self, common_data, init=False):
     if init:
         pass
     else:
         pass
     self.dim = Vec3(64, 20, 64)
     self.orig = Vec3(32, 10, 0)
		def __init__(self, common_data, init=False):
			if init:
				pass
			else:
				pass
			self.dim = Vec3(20,12,12)
			self.orig = Vec3(10,6,6)
示例#9
0
def director_play(game, data):
    bunnies = game.game_data['bunnies']
    events = [
        FadeRenderLayer('overlay', Color(1, 1, 1, 1), 1),
    ]
    for message in data['title']:
        events.extend([
            Message(message, Vec3(240, 200, 0),
                    bunnies.index(game.current_bun[0]).color, 2,
                    px_graphics.eAlign.centre),
            Delay(2.5),
        ])
    events.extend([
        MakeEntity('map', data=data['map']),
        FadeToClearColor(Color.fromInts(219, 182, 85), 1),
        FadeRenderLayer('game', Color(1, 1, 1, 1), 1),
        MakeDirector('bun_caught'),
        WaitForFlag('escape'),
        MakeEntity('escape', pos=Vec3(92, 200, 0)),
        WaitForFlag('next_scene'),
        KillEntity('escape'),

        # # fade out at end of scene
        Delay(1),
        # MakeEntity('director', init="import PB_directors\n"
        # 																					 "self.events = PB_directors.director_fade_to_next_scene(self.game)"),
        MakeDirector('fade_to_next_scene')
    ])
    return events
示例#10
0
    def update(self, data, common_data, dt):
        speed = 0.3
        # if doing something that can't be interrupted then countdown to end of it

        if self.coolDown(data, dt):
            pass
        else:
            if data.health <= 0:
                self.setState(data, common_data, eStates.dead)
                return
            self.setState(data, common_data, eStates.stationary)
            if rand_num(10) == 0:
                #				self.setState(data, common_data, eStates.stationary)
                data.vel = Vec3(0, 0, 0)
                data.cooldown = rand_num(5) / 8.0 + 0.3
            else:
                # chase hero
                if data.target_cool <= 0:
                    data.target = Vec3(rand_num(600), rand_num(200),
                                       rand_num(200))
                    data.target_cool = rand_num(20)
                else:
                    data.target_cool -= 1
                if (data.target.x < common_data.pos.x):
                    #					self.setState(data, common_data, eStates.runLeft)
                    data.vel = Vec3(-speed, 0, 0)
                    data.facing = eDirections.left
                else:
                    #					self.setState(data, common_data, eStates.runRight)
                    data.vel = Vec3(speed, 0, 0)
                    data.facing = eDirections.right
                if (data.target.z < common_data.pos.z):
                    data.vel.z = -speed
                else:
                    data.vel.z = speed

                if common_data.pos.distSq(
                        Vec3(data.target.x, data.target.y,
                             common_data.pos.z)) < 800:
                    data.vel.y = 0  # drop on target
                elif (common_data.pos.z < 80 + rand_num(200)) and (data.vel.z <
                                                                   3):
                    data.vel.y += 2 + rand_num(5)  # otherwise flap
                    self.setState(data,
                                  common_data,
                                  eStates.stationary,
                                  force_new_state=True)

                data.cooldown = 0.2

        if common_data.pos.y > 0:
            px_controller.friction(data.vel, 0.01)
        else:
            px_controller.friction(data.vel, 0.1)

        px_controller.basic_gravity(data.vel)
        px_controller.basic_physics(common_data.pos, data.vel)

        restrictToArena(common_data.pos, data.vel)
示例#11
0
 def __init__(self, common_data, init=False):
     if init:
         pass
     else:
         pass
     self.dim = Vec3(20, 16, 10)
     self.orig = Vec3(10, 0, 2)
     self.damage_hero = 1
示例#12
0
def runTests():

    fails = []

    res_x = 320
    res_y = 200
    zoom = 2

    # Initialize the video system - this implicitly initializes some
    # necessary parts within the SDL2 DLL used by the video module.
    #
    # You SHOULD call this before using any video related methods or
    # classes.
    sdl2.ext.init()

    # Create a new window (like your browser window or editor window,
    # etc.) and give it a meaningful title and size. We definitely need
    # this, if we want to present something to the user.

    window = sdl2.ext.Window("Graphics Tests",
                             size=(res_x * zoom, res_y *
                                   zoom))  # ,flags=sdl2.SDL_WINDOW_FULLSCREEN)

    # By default, every Window is hidden, not shown on the screen right
    # after creation. Thus we need to tell it to be shown now.
    window.show()

    # set up a renderer to draw stuff. This is a HW accelerated one.
    # Switch on VSync to avoid running too fast, nasty artefacts
    # and wasting power and keep graphics nice and clean
    ren = sdl2.ext.Renderer(window,
                            flags=sdl2.SDL_RENDERER_ACCELERATED
                            | sdl2.SDL_RENDERER_PRESENTVSYNC)
    # makes zoomed graphics blocky (for retro effect)
    sdl2.SDL_SetHint(sdl2.SDL_HINT_RENDER_SCALE_QUALITY, b"nearest")
    # makes the graphics look and act like the requested screen size, even though
    # they may be rendered much larger
    sdl2.SDL_RenderSetLogicalSize(ren.sdlrenderer, res_x, res_y)

    # test 1 example
    # if not (a+b)==Vec3(2,3,4):
    # 	log("Fail in test 1: a+b")
    # 	fails.append(1)

    rl = RenderLayer(ren)

    rl.setOrigin(1, 2, 3)
    if (rl.getOrigin() != Vec3(1, 2, 3)):
        fails.append(1)

    rl.setOriginByVec3(Vec3(1, 2, 3))
    if (rl.getOrigin() != Vec3(1, 2, 3)):
        fails.append(2)

    rl.addImageFromFile("GraphicsTest/test.png")

    return fails
示例#13
0
		def __init__(self, common_data, init=False):
			if init:
				pass
			else:
				pass
			self.dim = Vec3(20,16,8)
			self.orig = Vec3(10,0,4)
			self.damage = 1
			self.damage_hero = 1
			self.force = Vec3(0,0,0)
示例#14
0
 def __init__(self, common_data, init=False):
     if init:
         pass
     else:
         pass
     self.dim = Vec3(30, 20, 8)
     self.orig = Vec3(15, 0, 4)
     self.absorb = 3
     self.impassable = True
     self.radius = 10.0
     self.mass = 10.0
示例#15
0
def restrictToArena(pos, vel):
	# stop running through walls at either side
	# if pos on left side of line then force to right side
	# while pos.whichSidePlane(Plane(1, -1, 0, 0)):
	# 	controller.basic_physics(pos, Vec3(0.1, -0.1, 0)) # normal vector to plane

	# stop running through walls at either side
	# if pos on left side of line then force to right side
	# while not pos.whichSidePlane(Plane(1, 1, 0, -1920)):
	# 	controller.basic_physics(pos, Vec3(-0.1, -0.1, 0)) # normal vector to plane

	# stop running off screen bottom, top and sides
	pos.clamp(Vec3(100, 0, 0), Vec3(600, 1000, 200))
示例#16
0
 def initEntity(self, entity, data=False):
     if entity.data:
         entity.game_pad = entity.data['game_pad']
     else:
         entity.game_pad = False
     entity.cooldown = -1
     entity.vel = Vec3(0.0, 0.0, 0.0)
     entity.queued_vel = Vec3(0.0, 0.0, 0.0)
     entity.facing = None
     entity.queued_facing = 4
     entity.state = PacBun.eStates.idle
     entity.queued_state = entity.state
     entity.score = 0
     entity.invulnerable = False
示例#17
0
	def update(self, data, common_data, dt):
		speed = 0.3
		# if doing something that can't be interrupted then countdown to end of it

		if self.coolDown(data, dt):
			pass
		else:
			if data.health <= 0:
				self.setState(data, common_data, px_entity.eStates.dead)
				return
			self.setState(data, common_data, px_entity.eStates.stationary)
			if rand_num(10)==0:
#				self.setState(data, common_data, eStates.stationary)
				data.vel = Vec3(0,0,0)
				data.cooldown = rand_num(10)/8.0+0.3
			else:
				# chase hero
				target = common_data.game.requestTarget(common_data.pos)
				if(target.x<common_data.pos.x):
#					self.setState(data, common_data, eStates.runLeft)
					data.vel = Vec3(-speed, 0, 0)
					data.facing = px_entity.eDirections.left
				else:
#					self.setState(data, common_data, eStates.runRight)
					data.vel = Vec3(speed, 0, 0)
					data.facing = px_entity.eDirections.right
				if(target.z<common_data.pos.z):
					data.vel.z = -speed
				else:
					data.vel.z = speed

				if common_data.pos.distSq(Vec3(target.x,target.y,common_data.pos.y))<800:
					data.vel.y = 0 # drop on target
				elif (common_data.pos.z<80) and (data.vel.z<3):
					data.vel.y += 2 # otherwise flap
					# common_data.entity.graphics.startAnim(data = common_data.entity.graphics_data)
					self.setState(data, common_data, px_entity.eStates.stationary, force_new_state=True)
					common_data.entity.sounds.playEvent(data, common_data, eEvents.flap)

				data.cooldown = 0.2

		if common_data.pos.y>0:
			px_controller.friction(data.vel, 0.01)
		else:
			px_controller.friction(data.vel, 0.1)

		px_controller.basic_gravity(data.vel)
		px_controller.basic_physics(common_data.pos, data.vel)

		background.restrictToArena(common_data.pos, data.vel)
示例#18
0
    def update(self, data, common_data, dt):
        speed = 0.3
        # if doing something that can't be interrupted then countdown to end of it

        if self.coolDown(data, dt):
            pass
        else:
            if data.health <= 0:
                self.setState(data, common_data, eStates.dead)
                return
            self.setState(data, common_data, eStates.stationary)
            if rand_num(10) == 0:
                #				self.setState(data, common_data, eStates.stationary)
                data.vel = Vec3(0, 0, 0)
                data.cooldown = rand_num(5) / 10.0 + 0.1
            else:
                # chase hero
                target = common_data.game.requestTarget(common_data.pos)
                if (target.x < common_data.pos.x):
                    #					self.setState(data, common_data, eStates.runLeft)
                    data.vel = Vec3(-speed, 0, 0)
                    data.facing = eDirections.left
                else:
                    #					self.setState(data, common_data, eStates.runRight)
                    data.vel = Vec3(speed, 0, 0)
                    data.facing = eDirections.right
                if (target.y < common_data.pos.y):
                    data.vel.y = -speed
                else:
                    data.vel.y = speed

                if common_data.pos.distSq(
                        Vec3(target.x, target.y, common_data.pos.z)) < 800:
                    data.vel.z = 0  # drop on target
                elif (common_data.pos.z < 80) and (data.vel.z < 3):
                    data.vel.z += 2  # otherwise flap
                    common_data.entity.graphics.startAnim(
                        data=common_data.entity.graphics_data)

                data.cooldown = 0.2

        if common_data.pos.z > 0:
            friction(data.vel, 0.01)
        else:
            friction(data.vel, 0.1)

        basic_gravity(data.vel)
        basic_physics(common_data.pos, data.vel)

        restrictToArena(common_data.pos, data.vel)
示例#19
0
	def initEntity(self, entity, data=False):
			# values for each instance

			entity.cooldown = -1
			entity.pause = 7
			entity.vel = Vec3(0.0,0.0,0.0)
			entity.queued_vel = Vec3(0.0,0.0,0.0)
			entity.facing = False
			entity.queued_facing = 4
			entity.health = 3
			entity.state = PacBun.eStates.idle
			entity.queued_state = entity.state
			entity.AI_cooldown = 1 + px_vector.rand_num(15) / 5.
			entity.type = data['type']
			entity.fox_speed = 1
示例#20
0
 def shoot(
     self,
     data,
     common_data,
     flippedX=False,
 ):
     arrow = self.game.requestNewEntity(entity_template=self.arrow_t,
                                        pos=common_data.pos +
                                        Vec3(-5 if flippedX else 5, 20, 0),
                                        parent=common_data.entity,
                                        name="Goblin archer arrow")
     arrow.collider_data.force = 0  #Vec3(-1 if flippedX else 1,0,0)
     arrow.collider_data.hero_damage = 1
     arrow.common_data.state = (px_entity.eStates.runLeft
                                if flippedX else px_entity.eStates.runRight)
     arrow.controller_data.vel = Vec3(-7 if flippedX else 7, 1, 0)
示例#21
0
    def __init__(self,
                 name,
                 game,
                 graphics=False,
                 sounds=False,
                 controller=False,
                 collider=False,
                 init=False,
                 parent=False,
                 data=False):
        self.data = data  # note this is done first so things like init can use the data
        self.game = game
        self.name = name
        self.pos = Vec3(0, 0, 0)
        self.state = eStates.idle
        self.new_state = True
        self.blink = False
        self.parent = parent

        self.components = {}
        for type in [
            ['graphics', graphics],
            ['sounds', sounds],
            ['controller', controller],
            ['collider', collider],
        ]:
            if type[1]:
                self.components[type[0]] = type[1]
                type[1].initEntity(self, data)

        if init:
            # px_log.log(f"Init entity: {name} code: {init}")
            # execute init
            exec(init, globals(), locals())
示例#22
0
def director_drake_blue(game):
    return [
        Message("Drake Blue Games presents...", Vec3(240, 180, 0),
                Color(0.8, 0.75, 1.0, 1.0), -1, px_graphics.eAlign.centre),
        Delay(2),
        MakeDirector('fade_to_mode', 'title'),
    ]
示例#23
0
 def requestNewEnemy(self,
                     entity_template,
                     pos=Vec3(0, 0, 0),
                     parent=False,
                     name=False):
     self.num_monsters += 1
     self.requestNewEntity(entity_template, pos, parent, name)
示例#24
0
	def __init__(self, source, damage=0, damage_hero=0, force=Vec3(0,0,0), absorb=0, impassable=False):
		self.source = source
		self.damage = damage
		self.absorb = absorb
		self.damage_hero = damage_hero
		self.force = force
		self.absorb = absorb
		self.impassable = impassable
示例#25
0
 def getCollisionMessage(self, data, common_data):
     if common_data.entity.controller_data.health > 0:
         return (px_collision.Message(source=common_data.entity,
                                      damage=0,
                                      damage_hero=1,
                                      force=Vec3(0, 0, 0)))
     else:
         return (px_collision.Message(source=common_data.entity))
示例#26
0
def director_bunny_select(game):
    return [
        SetRenderLayerColor('game', Color(0, 0, 0, 0)),
        SetRenderLayerColor('overlay', Color(0, 0, 0, 0)),
        FadeToClearColor(Color.fromInts(0, 0, 0), 1),
        Message("Choose your bunny:", Vec3(240, 220, 0), Color(1, 1, 1, 1), -1,
                px_graphics.eAlign.centre),
        MakeEntity('pacbun choose',
                   data={
                       'pos': Vec3(210, 160, 0),
                       'parent': 'bunny choice',
                       'bun num': 0,
                       'bun name': 'Pac-Bun',
                       'message color': px_graphics.Color(1, 1, 0, 1),
                   }),
        MakeEntity('pinkie choose',
                   data={
                       'pos': Vec3(230, 160, 0),
                       'parent': 'bunny choice',
                       'bun num': 1,
                       'bun name': 'Pinkie',
                       'message color': px_graphics.Color(1, 0.8, 0.8, 1),
                   }),
        MakeEntity('blue choose',
                   data={
                       'pos': Vec3(250, 160, 0),
                       'parent': 'bunny choice',
                       'bun num': 2,
                       'bun name': 'Blue',
                       'message color': px_graphics.Color(0.5, 0.5, 1.0, 1),
                   }),
        MakeEntity('bowie choose',
                   data={
                       'pos': Vec3(270, 160, 0),
                       'parent': 'bunny choice',
                       'bun num': 3,
                       'bun name': 'Bowie',
                       'message color': px_graphics.Color(1, 1, 1.0, 1),
                   }),
        FadeRenderLayer('overlay', Color(1, 1, 1, 1), 1),
        FadeRenderLayer('game', Color(1, 1, 1, 1), 1),
        WaitForFlag('next_scene'),
        MakeDirector('fade_to_mode', 'play')
    ]
示例#27
0
		def __init__(self, common_data, init=False):
			if init:
				self.game_pad = init.game_pad
			else:
				self.game_pad = False

			self.vel = Vec3(0.0,-3.0,0.0)
			self.cooldown = -1
			common_data.state = eRainStates.state_fall
			common_data.new_state = False
示例#28
0
	def __init__(self, game, data):
		super(HeroController, self).__init__(game)
		# values global to all heroes
		self.invincible_states = (eStates.dead, eStates.fallLeft, eStates.fallRight, eStates.dead)

		hit_controller = self.game.controller_manager.makeTemplate({"Template": HitController})
		hit_collider = self.game.collision_manager.makeTemplate({"Template": HitCollider})

		hit_t = self.game.entity_manager.makeEntityTemplate(graphics=False, controller=hit_controller,
																															 collider=hit_collider)

		# cool downs in seconds
		self.strikes = [
			#			cool	del		range					force		damage
			Strike(0.8, 0.2, Vec3(24, 0, 0), 3, 2, template=hit_t),  # big
			Strike(0.8, 0.4, Vec3(8, 0, 30), 2, 2, template=hit_t),  # big_up
			Strike(0.3, 0.1, Vec3(12, 0, 0), 1, 1, template=hit_t),  # small
			Strike(0.3, 0.2, Vec3(18, 0, 0), 2, 0, template=hit_t),  # block
		]
示例#29
0
		def __init__(self, common_data, init=False):
			if init:
				pass
			else:
				pass
			self.cooldown = 0
			self.health = 5
			self.vel = Vec3(0,0,0)
			self.mass = 4
			self.facing = px_entity.eDirections.left
示例#30
0
 def __init__(self, common_data, init=False):
     if init:
         pass
     else:
         pass
     self.cooldown = 0
     self.health = 5
     self.vel = Vec3(0, 0, 0)
     self.mass = 4
     self.facingleft = True
     self.fired = False