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


Python Level.addEntity方法代码示例

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


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

示例1: Editor

# 需要导入模块: from Level import Level [as 别名]
# 或者: from Level.Level import addEntity [as 别名]
class Editor(Entity):

  #CONSTRUCTOR
  def __init__(self, levelName=None):

    self.focus = False

    #keyboard input
    self.keys = key.KeyStateHandler()
    game.globals.engine.window.push_handlers(self.keys)
    self.prevChange = False

    #set groups
    self.groups = self.groups | {'UI_editor'}
    self.drawLayer = 'UI_editor'
    self.batch = game.globals.engine.drawLayersBatch[self.drawLayer]

    #create variables
    self.cam = game.globals.engine.camera #the game camera
    self.numTabs = 8 #the number of tabs the editor has
    
    #mouse variables
    self.leftMouseDown = False #reflects the left mouse button's state
    self.prevLeftDown = False #if the left mouse was previously pressed down
    self.rightMouseDown = False #reflects the right mouse button's state
    self.prevRightDown = False #if the right mouse was previuosly pressed down
    self.mousePos = game.globals.engine.mousePos
    self.mouseClick = Vec2d() #stores the position where the mouse is pressed
    self.mousePressed = Vec2d() #stores the current position of where the pressed mouse
    self.dragBoxStart = Vec2d() #the start coords of the dragbox
    self.dragBoxEnd = Vec2d() #the end coords of the dragbox
    
    self.windowSize = Vec2d(game.globals.engine.window.get_size()) #gets the window size as a vector
    self.selected = "rectPlatform" #the current slected object
    self.brushShape = "rectangle" #the current brush shape
    self.gridOn = True #is the grid on
    self.snapToGrid = True #is snap to grid on?
    self.gridSize = Vec2d(16, 16) #the size of a grid unit
    self.gridOffset = Vec2d(0, 0) #the x and y offsets of the grid

    self.level = Level(levelName)  # The level that will store our entities
    if not levelName:
      levelName = 'test'
    self.level.levelName = levelName # having this after the constructor will avoid the level trying to load the file

    #until resources is implemented the editor currently loads its own images
    self.sideBarImage  = image.load("game/Resources/Graphics/EditorUI/editorUI.png")
    self.tab0Image     = image.load("game/Resources/Graphics/EditorUI/editorTab0.png") #deslected tab
    self.tab1Image     = image.load("game/Resources/Graphics/EditorUI/editorTab1.png") #selected tab
    
    #set sprites
    self.sideBarSprite = sprite.Sprite(self.sideBarImage, batch = self.batch)
    self.tabList = [] #list that contains all the sprites of the tabs
    for i in xrange(self.numTabs):
      self.tabList.append(sprite.Sprite(self.tab0Image, batch = self.batch)) #default load all the tabs to unselect

    #scaling
    self.scale = float(game.globals.engine.window.height)/1080.0 #find the scale
    self.sideBarSprite.scale  = self.scale
    for i in self.tabList:
      i.scale = self.scale

    #set positions
    self.sideBarSprite.position = (0, 0)
    j = 0
    for i in self.tabList:
      i.position = ((38.0*self.scale)+(i.width*j), 1004.0*self.scale)
      j += 1

    self.selectTab(0) #select the first tab
    
    #generate resources for creating the icons
    iconImages = ["squarePlatformIcon"]
    iconFunctions = [self.place]
    #create the side bar icons
    for img, func in zip(iconImages, iconFunctions):
      newImage = image.load("game/Resources/Graphics/EditorUI/"+img+".png")
      newSprite = sprite.Sprite(newImage, batch = self.batch)
      game.globals.engine.addEntity(EditorIcon(Vec2d(50, 940), newSprite, self.scale, func))

    #mouse event functions
    @game.globals.engine.window.event
    def on_mouse_press(x, y, button, modifiers):
      if button == 1: self.leftMouseDown = True
      elif button == 4: self.rightMouseDown = True

    @game.globals.engine.window.event
    def on_mouse_release(x, y, button, modifiers):
      if button == 1:
        self.leftMouseDown = False
        self.prevLeftDown = False
        self.place()
      elif button == 4:
        self.rightMouseDown = False


  #FUNCTIONS
  #Updates the editor
  def update(self, dt):

#.........这里部分代码省略.........
开发者ID:DomNomNom,项目名称:Jumpy2D,代码行数:103,代码来源:Editor.py


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