def update(self): FlxCore.update(self) for i in range(len(self._children)): if ((self._children[i] != None) and self._children[i].exists and self._children[i].active): self._children[i].update()
def __init__(self,X,Y,Width,Height,TileGraphic,Empties=0): FlxCore.__init__(self); self._tileSize=0; self.x = X; self.y = Y; self.width = Width; self.height = Height; if(TileGraphic == None): print "block None graphic" return; self._pixels = TileGraphic self._rects = FlxArray(); self._p = FlxPoint(); self._tileSize = self._pixels.height; self.widthInTiles = math.ceil(self.width/self._tileSize); self.heightInTiles = math.ceil(self.height/self._tileSize); self.width = self.widthInTiles*self._tileSize; self.height = self.heightInTiles*self._tileSize; self.numTiles = self.widthInTiles*self.heightInTiles; self.numGraphics = self._pixels.get_width()/self._tileSize; for i in range( numTiles): if(math.random()*(numGraphics+Empties) > Empties): self._rects.append(Rect(self._tileSize*Math.floor(Math.random()*self.numGraphics),0,self._tileSize,self._tileSize)); else: self._rects.append(None);
def __init__(self,X, Y, Width, Height, Sprites=None, Delay=-1, MinVelocityX=-100, MaxVelocityX=100, MinVelocityY=-100, MaxVelocityY=100, MinRotation=-360, MaxRotation=360, Gravity=500, Drag=0, Graphics=None, Quantity=0, Multiple=false, Parent=None): FlxCore.__init__(self); self.visible = false; self.x = X; self.y = Y; self.width = Width; self.height = Height; self.minVelocity = FlxPoint(MinVelocityX,MinVelocityY); self.maxVelocity = FlxPoint(MaxVelocityX,MaxVelocityY); self._minRotation = MinRotation; self._maxRotation = MaxRotation; self._gravity = Gravity; self._drag = Drag; self._delay = Delay; self._timer=0 self._particle = 0; if(Graphics != None): self._sprites = FlxArray(); for i in range(Quantity): if(Multiple): (self._sprites.add( FlxSprite(Graphics,0,0,true))).randomFrame(); else: self._sprites.add( FlxSprite(Graphics)); for i in range(len(self._sprites)): if(Parent == None): FlxG.state.add(self._sprites[i]); else: Parent.add(self._sprites[i]); else: self._sprites = Sprites; self.kill(); if(self._delay > 0): self.reset();
def __init__(self, MapData, TileGraphic, CollisionIndex=1, DrawIndex=1): #image = pyglet.resource.image("data/logo.png") FlxCore.__init__(self) self.CollideIndex = CollisionIndex self.DrawIndex = 1 self._ci = CollisionIndex self.widthInTiles = 0 self.heightInTiles = 0 self._data = FlxArray() #c; #cols:Array; rows = open(MapData).read().split("\n") rows.reverse() rows = rows[2:] self.heightInTiles = len(rows) for r in range(self.heightInTiles): cols = rows[r].split(",") if (len(cols) <= 1): self.heightInTiles -= 1 continue if (self.widthInTiles == 0): self.widthInTiles = len(cols) for c in range(self.widthInTiles): self._data.append(int(cols[c])) self._pixels = TileGraphic self._rects = FlxArray() self._p = FlxPoint() self._tileSize = self._pixels.height self.width = self.widthInTiles * self._tileSize self.height = self.heightInTiles * self._tileSize self.numTiles = self.widthInTiles * self.heightInTiles for i in range(self.numTiles): if (self._data[i] >= DrawIndex): self._rects.append( FlxRect(self._tileSize * self._data[i], 0, self._tileSize, self._tileSize)) else: self._rects.append(None) #self._block = FlxBlock(0,0,self._tileSize,self._tileSize,None); self._screenRows = int(Math.ceil(FlxG.height / self._tileSize) + 1) if (self._screenRows > self.heightInTiles): self._screenRows = self.heightInTiles self._screenCols = int(Math.ceil(FlxG.width / self._tileSize) + 1) if (self._screenCols > self.widthInTiles): self._screenCols = self.widthInTiles self._tileObjects = range(self._pixels.width / self._pixels.height) i = 0 while (i < self._pixels.width / self._pixels.height): collide = FlxCore.NONE if (i >= self.CollideIndex): collide = self.allowCollisions self._tileObjects[i] = FlxTile(self, i, self._tileSize, self._tileSize, (i >= self.DrawIndex), collide) i += 1
def __init__(self,MapData, TileGraphic, CollisionIndex=1, DrawIndex=1): #image = pyglet.resource.image("data/logo.png") FlxCore.__init__(self); self.CollideIndex = CollisionIndex;self.DrawIndex = 1; self._ci = CollisionIndex; self.widthInTiles = 0; self.heightInTiles = 0; self._data = FlxArray(); #c; #cols:Array; rows = open(MapData).read().split("\n"); rows.reverse() rows=rows[2:] self.heightInTiles = len(rows); for r in range(self.heightInTiles): cols = rows[r].split(","); if(len(cols) <= 1): self.heightInTiles-=1; continue; if(self.widthInTiles == 0): self.widthInTiles = len(cols); for c in range(self.widthInTiles): self._data.append(int(cols[c])); self._pixels = TileGraphic self._rects = FlxArray(); self._p = FlxPoint(); self._tileSize =self._pixels.height; self.width = self.widthInTiles*self._tileSize; self.height = self.heightInTiles*self._tileSize; self.numTiles = self.widthInTiles*self.heightInTiles; for i in range(self.numTiles): if(self._data[i] >= DrawIndex): self._rects.append(FlxRect(self._tileSize*self._data[i],0,self._tileSize,self._tileSize)); else: self._rects.append(None); #self._block = FlxBlock(0,0,self._tileSize,self._tileSize,None); self._screenRows =int( Math.ceil(FlxG.height/self._tileSize)+1); if(self._screenRows > self.heightInTiles): self._screenRows = self.heightInTiles; self._screenCols = int(Math.ceil(FlxG.width/self._tileSize)+1); if(self._screenCols > self.widthInTiles): self._screenCols = self.widthInTiles; self._tileObjects = range(self._pixels.width/self._pixels.height) i=0 while(i < self._pixels.width/self._pixels.height): collide=FlxCore.NONE if(i>= self.CollideIndex): collide=self.allowCollisions self._tileObjects[i] =FlxTile(self,i,self._tileSize,self._tileSize,(i >= self.DrawIndex),collide) i+=1;
def __init__(self, X, Y, Width, Height, Sprites=None, Delay=-1, MinVelocityX=-100, MaxVelocityX=100, MinVelocityY=-100, MaxVelocityY=100, MinRotation=-360, MaxRotation=360, Gravity=500, Drag=0, Graphics=None, Quantity=0, Multiple=false, Parent=None): FlxCore.__init__(self) self.visible = false self.x = X self.y = Y self.width = Width self.height = Height self.minVelocity = FlxPoint(MinVelocityX, MinVelocityY) self.maxVelocity = FlxPoint(MaxVelocityX, MaxVelocityY) self._minRotation = MinRotation self._maxRotation = MaxRotation self._gravity = Gravity self._drag = Drag self._delay = Delay self._timer = 0 self._particle = 0 if (Graphics != None): self._sprites = FlxArray() for i in range(Quantity): if (Multiple): (self._sprites.add(FlxSprite(Graphics, 0, 0, true))).randomFrame() else: self._sprites.add(FlxSprite(Graphics)) for i in range(len(self._sprites)): if (Parent == None): FlxG.state.add(self._sprites[i]) else: Parent.add(self._sprites[i]) else: self._sprites = Sprites self.kill() if (self._delay > 0): self.reset()
def render(self): FlxCore.render(self); self.getScreenXY(self._p); opx = self._p.x; for i in range( len(self._rects)): if(self._rects[i] != None): FlxG.buffer.blit(self._pixels,_rects[i],self._p,None,None,true); self._p.x += self._tileSize; if(self._p.x >= opx + self.width): self._p.x = opx; self._p.y += self._tileSize;
def __init__(self, Tilemap, Index, Width, Height, Visible, AllowCollisions): FlxCore.__init__(self) #,0, 0, Width, Height); # # /** # # * This function is called whenever an object hits a tile of this type. # # * This function should take the form <code>myFunction(Tile:FlxTile,Object:FlxObject):void</code>. # # * Defaults to null, set through <code>FlxTilemap.setTileProperties()</code>. # # */ # self.callback=None; # # /** # # * Each tile can store its own filter class for their callback functions. # # * That is, the callback will only be triggered if an object with a class # # * type matching the filter touched it. # # * Defaults to null, set through <code>FlxTilemap.setTileProperties()</code>. # # */ # self.filter=None; # # /** # # * A reference to the tilemap this tile object belongs to. # # */ # public var tilemap:FlxTilemap; # /** # * The index of this tile type in the core map data. # * For example, if your map only has 16 kinds of tiles in it, # * this number is usually between 0 and 15. # */ # public var index:uint; # /** # * The current map index of this tile object at this moment. # * You can think of tile objects as moving around the tilemap helping with collisions. # * This value is only reliable and useful if used from the callback function. # */ # public var mapIndex:uint; self.immovable = true self.moves = false self.callback = None self.filter = None self.width = Width self.height = Height self.tilemap = Tilemap self.index = Index self.visible = Visible self.allowCollisions = AllowCollisions self.velocity = FlxPoint() self.mapIndex = 0
def render(self): #NOTE: While this will only draw the tiles that are actually on screen, it will ALWAYS draw one screen's worth of tiles FlxCore.render(self) self.getScreenXY(self._p) #print self._p.x,self._p.y #self.position=(self._p.x,self._p.y) #raw_input() tx = Math.floor(-self._p.x / self._tileSize) ty = Math.floor(-self._p.y / self._tileSize) if (tx < 0): tx = 0 if (tx > self.widthInTiles - self._screenCols): tx = self.widthInTiles - self._screenCols if (ty < 0): ty = 0 if (ty > self.heightInTiles - self._screenRows): ty = self.heightInTiles - self._screenRows ri = int(ty * self.widthInTiles + tx) self._p.x += tx * self._tileSize self._p.y += ty * self._tileSize opx = self._p.x for r in range(self._screenRows): cri = ri for c in range(self._screenCols): #print self._rects[cri] #raw_input() if (self._rects[cri] != None): im = self._pixels.get_region( self._rects[cri].x, self._rects[cri].y, self._rects[cri].width, self._rects[cri].height ) #.x,self._rects[cri].y, self._rects[cri].width,self._rects[cri].height) #tmp=Sprite(im) #tmp.position=(self._p.x,self._p.y) #print r,c,"tile",self._p.x,self._p.y #self.add(tmp) r = FlxRect(self._p.x, self._p.y, self._rects[cri].width, self._rects[cri].height) im.blit(self._p.x, self._p.y) cri += 1 self._p.x += self._tileSize ri += self.widthInTiles self._p.x = opx self._p.y += self._tileSize
def __init__(self,Tilemap, Index, Width, Height, Visible, AllowCollisions): FlxCore.__init__(self)#,0, 0, Width, Height); # # /** # # * This function is called whenever an object hits a tile of this type. # # * This function should take the form <code>myFunction(Tile:FlxTile,Object:FlxObject):void</code>. # # * Defaults to null, set through <code>FlxTilemap.setTileProperties()</code>. # # */ # self.callback=None; # # /** # # * Each tile can store its own filter class for their callback functions. # # * That is, the callback will only be triggered if an object with a class # # * type matching the filter touched it. # # * Defaults to null, set through <code>FlxTilemap.setTileProperties()</code>. # # */ # self.filter=None; # # /** # # * A reference to the tilemap this tile object belongs to. # # */ # public var tilemap:FlxTilemap; # /** # * The index of this tile type in the core map data. # * For example, if your map only has 16 kinds of tiles in it, # * this number is usually between 0 and 15. # */ # public var index:uint; # /** # * The current map index of this tile object at this moment. # * You can think of tile objects as moving around the tilemap helping with collisions. # * This value is only reliable and useful if used from the callback function. # */ # public var mapIndex:uint; self.immovable = true; self.moves = false; self.callback = None; self.filter = None; self.width=Width self.height=Height self.tilemap = Tilemap; self.index = Index; self.visible = Visible; self.allowCollisions = AllowCollisions; self.velocity = FlxPoint(); self.mapIndex = 0;
def update(self): self.last.x=self.x self.last.y=self.y #print "last",self,self.last.x,self.last.y FlxCore.update(self); if(not self.active): return; #animation if((self._curAnim != None) and (self._curAnim.delay > 0) and (self._curAnim.looped or not self.finished)): self._frameTimer += FlxG.elapsed; #print self._frameTimer,self._curAnim.delay,FlxG.elapsed #raw_input() if(self._frameTimer > self._curAnim.delay): self._frameTimer -= self._curAnim.delay; if(self._curFrame == len(self._curAnim.frames)-1): if(self._curAnim.looped): self._curFrame = 0; self.finished = true; else: self._curFrame+=1; self.calcFrame(); #print "curframe",self._curFrame #motion + physics self.angularVelocity = FlxG.computeVelocity(self.angularVelocity,self.angularAacceleration,self.angularDrag,self.maxAngular) self.angle += (self.angularVelocity)*FlxG.elapsed; self.thrustComponents=FlxPoint(); if(self.thrust != 0): self.thrustComponents = FlxG.rotatePoint(-self.thrust,0,0,0,self.angle); maxComponents = FlxG.rotatePoint(-maxself.thrust,0,0,0,self.angle); maxself.velocity.x = Math.abs(maxComponents.x); maxself.velocity.y = Math.abs(maxComponents.y); else: self.thrustComponents = self._pZero; self.velocity.x = FlxG.computeVelocity(self.velocity.x,self.acceleration.x+self.thrustComponents.x,self.drag.x,self.maxVelocity.x) self.x += (self.velocity.x)*FlxG.elapsed; self.velocity.y = FlxG.computeVelocity(self.velocity.y,self.acceleration.y+self.thrustComponents.y,self.drag.y,self.maxVelocity.y) self.y += (self.velocity.y)*FlxG.elapsed;
def render(self): #NOTE: While this will only draw the tiles that are actually on screen, it will ALWAYS draw one screen's worth of tiles FlxCore.render(self) self.getScreenXY(self._p); #print self._p.x,self._p.y #self.position=(self._p.x,self._p.y) #raw_input() tx = Math.floor(-self._p.x/self._tileSize); ty = Math.floor(-self._p.y/self._tileSize); if(tx < 0): tx = 0; if(tx > self.widthInTiles-self._screenCols): tx = self.widthInTiles-self._screenCols; if(ty < 0): ty = 0; if(ty > self.heightInTiles-self._screenRows): ty = self.heightInTiles-self._screenRows; ri =int(ty*self.widthInTiles+tx); self._p.x += tx*self._tileSize; self._p.y += ty*self._tileSize; opx = self._p.x; for r in range(self._screenRows): cri = ri; for c in range(self._screenCols): #print self._rects[cri] #raw_input() if(self._rects[cri] != None): im=self._pixels.get_region(self._rects[cri].x,self._rects[cri].y,self._rects[cri].width,self._rects[cri].height)#.x,self._rects[cri].y, self._rects[cri].width,self._rects[cri].height) #tmp=Sprite(im) #tmp.position=(self._p.x,self._p.y) #print r,c,"tile",self._p.x,self._p.y #self.add(tmp) r=FlxRect(self._p.x,self._p.y,self._rects[cri].width,self._rects[cri].height) im.blit(self._p.x,self._p.y); cri+=1; self._p.x += self._tileSize; ri += self.widthInTiles; self._p.x = opx; self._p.y += self._tileSize;
def __init__(self): FlxCore.__init__(self) self._children = FlxArray();
def render(self): FlxCore.render(self); for i in range(len(self._children)): if((self._children[i] != None) and self._children[i].exists and self._children[i].visible): self._children[i].render();
def update(self): FlxCore.update(self); for i in range( len(self._children)): if((self._children[i] != None) and self._children[i].exists and self._children[i].active): self._children[i].update();
def __init__(self,Graphic=None,X=0,Y=0,Animated=false,Reverse=false,Width=0,Height=0,Color=0): if(Graphic != None): #image = pyglet.resource.image(Graphic) self.pixels = Graphic; pass else: self.pixels= pygame.image.load("data/logo.png") #pixels = FlxG.createBitmap(Width,Height,Color); FlxCore.__init__(self) #self.position=(X,FlxG.height-Y); #self.anchor=(0,0) #print dir(self.pixels) self.x = X; self.y = Y; if(Width == 0): if(Animated): Width = self.pixels.height; else: Width = self.pixels.width; self.width =Width self._bw = Width; self.height = self.pixels.height; self._bh = self.height; self.offset = FlxPoint(); self.velocity = FlxPoint(); self.acceleration = FlxPoint(); self.drag = FlxPoint(); self.maxVelocity = FlxPoint(10000,10000); self.angle = 0; self.angularVelocity = 0; self.angularAacceleration = 0; self.angularDrag = 0; self.maxAngular = 10000; self.thrust = 0; self.scale = FlxPoint(1,1); self.finished = false; self._facing = true; self._animations = FlxArray(); if(Reverse): #pass self._flipped = self.pixels.width>>1; else: self._flipped = 0; self._curAnim = None; self._curFrame = 0; self._frameTimer = 0; self._p = FlxPoint(self.x,self.y); self._pZero = FlxPoint(); self._r = FlxRect(0,0,self._bw,self._bh); #self._pixels = BitmapData(width,height); #print self._bw,self._bh #raw_input() self._pixels=self.pixels.get_region(0,0,self._bw,self._bh)#,self._pZero); self.health = 1; self._alpha = 1; self._callback = None;
def __init__(self,X, Y, Text="", Color=0xffffffff, Font=None, Size=18, Justification=None, Angle=0): pyglet.text.Label.__init__(self,Text,font_name=Font,font_size=Size,x=X,y=Y) FlxCore.__init__(self); self.x=X self.y=Y
def destroy(self): FlxCore.destroy(self) self.callback = None self.tilemap = None
def render(self): FlxCore.render(self) for i in range(len(self._children)): if ((self._children[i] != None) and self._children[i].exists and self._children[i].visible): self._children[i].render()
def __init__(self): FlxCore.__init__(self) self._children = FlxArray()
def destroy(self): FlxCore.destroy(self); self.callback = None; self.tilemap = None