当前位置: 首页>>代码示例>>Python>>正文


Python Map.getStartY方法代码示例

本文整理汇总了Python中Map.getStartY方法的典型用法代码示例。如果您正苦于以下问题:Python Map.getStartY方法的具体用法?Python Map.getStartY怎么用?Python Map.getStartY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Map的用法示例。


在下文中一共展示了Map.getStartY方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import Map [as 别名]
# 或者: from Map import getStartY [as 别名]
class Game:
    # Initialize the game object
    def __init__(self, gfxObject, kbdObject):
        # Store the graphics and keyboard object
        self.gfx = gfxObject
        self.kbd = kbdObject

        # Init the map object
        self.m = Map()
        self.m.Load('forest1')

        # Init the player object
        self.p = Player(self.m.getStartX(), self.m.getStartY())
        # Tell the player about the game object
        self.p.SetGameObject(self)

        # Tell the Graphics object about the Game object
        self.gfx.SetGameObject(self)

        # Keep track of game ticks over time
        self.GameTick = 0

        self.isFalling = False
        self.PlayerFallAmount = 0
        self.PlayerFallDelay = 0
        self.PlayerFallPath = [1, 2, 4, 5, 7, 9, 10, 12, 14, 16, 19, 24]
        self.PlayerFallPathLength = 12
        self.PlayerFallPathIndex = 0

        self.isJumping = False
        self.wasJumping = False
        #self.PlayerJumpPath = [13, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1]
        self.PlayerJumpPath = [16, 14, 12, 10, 9, 7, 5, 4, 2, 1]
        self.JumpPathLength = 10
        self.PlayerJumpDelay = 0
        self.PlayerJumpPathIndex = 0
        self.NextJumpTick = 0
        self.jumpLatch = False


    def Tick(self, SomethingElse):

        px = self.p.GetPosX()
        py = self.p.GetPosY()


        self.GameTick += 1

        """ Jumping """
        # Reset jump latch
        if (self.kbd.A == False and self.jumpLatch == True):
            self.jumpLatch = False

        # Jump condition
        if (self.kbd.A == True and self.jumpLatch == False):
            if not self.isFalling:
                self.jumpLatch = True
                self.isJumping = True
                self.wasJumping = True
                self.NextJumpTick = self.GameTick + 1
                self.p.MoveVertical(self.PlayerJumpPath[self.PlayerJumpPathIndex])

        # Button released during mid-jump
        if (self.kbd.A == False and self.isJumping == True):
            self.isJumping = False
            self.PlayerJumpPathIndex = 0

        # Process height gained by player over time
        if (self.isJumping == True):
            self.PlayerJumpPathIndex += 1
            if self.PlayerJumpPathIndex > self.JumpPathLength-1:
                self.PlayerJumpPathIndex = 0
                self.isJumping = False
            else:
                self.p.MoveVertical(self.PlayerJumpPath[self.PlayerJumpPathIndex])


        """ Left & right movement """
        if (self.kbd.Left == True and self.kbd.Right == True) or (self.kbd.Left == False and self.kbd.Right == False):
            # This condition occurs if the player is holding left & right at the same time: freeze player
            self.p.SpriteID = 3
        else:
            if self.kbd.Left == True:
                # Check if something is in the way to the left
                if not (self.m.isSolid(px + 2, py + 1) or self.m.isSolid(px + 2, py + 63)):
                    self.p.MoveLeft()

            if self.kbd.Right == True:
                # Check if something is in the way to the right
                if not (self.m.isSolid(px + 30, py + 1) or self.m.isSolid(px + 30, py + 63)):
                    self.p.MoveRight()

        if not self.isJumping:
            self.PlayerFallTick()

    def PlayerFallTick(self):
        px = self.p.GetPosX()
        py = self.p.GetPosY()

        if self.m.isSolid(px + 3, py-1) or self.m.isSolid(px + 29, py-1):
#.........这里部分代码省略.........
开发者ID:F1shb0ne,项目名称:SideScroller,代码行数:103,代码来源:Game.py

示例2: usage

# 需要导入模块: import Map [as 别名]
# 或者: from Map import getStartY [as 别名]
		print "Took penalty for going off world"
		print "Agent's score would've been worse if they tried to reach goal"

def usage():
	print "Usage:"
	print "\tpython astar.py mapfile heuristic"
	print "\t\tmapfile   - the filename of a map to evaluate"
	print "\t\theuristic - the number of a heuristic to use (1 to 6)"

# This is the program's main function
if __name__== "__main__":
	if (len(sys.argv) != 3):
		print "Incorrect number of arguments"
		usage()


	openFileName = sys.argv[1]
	heuristicType = int(sys.argv[2])

	if (heuristicType > 6) or (heuristicType < 1):
		print "Heuristic value must be between 1 and 6. Using heuristic 1"

	# generate map based on file
	mapData = Map(openFileName)

	start = [mapData.getStartX(), mapData.getStartY()]
	goal = [mapData.getGoalX(), mapData.getGoalY()]

	# run A*
	a_star(start, goal, mapData, heuristicType)
开发者ID:sfmailand,项目名称:CS4341,代码行数:32,代码来源:a_star.py


注:本文中的Map.getStartY方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。