def __init__(self): """Инициализация главных настроек приложения""" pg.init() # Настройки окна. self.WIDTH = 600 self.HEIGHT = 900 self.TITLE = "Ping Pong" self.ICON = pg.image.load('images/icon_app.png') self.WINDOW = pg.display.set_mode((self.WIDTH, self.HEIGHT)) self._color = (0, 102, 51) pg.display.set_caption(self.TITLE) pg.display.set_icon(self.ICON) # Настройки производительности self._CLOCK = pg.time.Clock() self._fps = 75 # Инициализация платформ self.PLATFORM_TOP = platform.Platform(self.WINDOW, 0) self.PLATFORM_BOTTOM = platform.Platform(self.WINDOW, self.HEIGHT - 80) # Инициализация мячика self._BALL = ball.Ball(self.WINDOW, self.PLATFORM_TOP, self.PLATFORM_BOTTOM)
def setLabel(self, str): ''' Changes the string stored within the GLabel object, so that a new text string appears on the display. @type str: string @rtype: void ''' self.str = str platform.Platform().setLabel(self, str) size = platform.Platform().getGLabelSize(self) self.width = size.getWidth() self.height = size.getHeight()
def __del__(self): ''' Informs the Java backend that the sound should be deleted @rtype: void ''' platform.Platform().deleteSound(self)
def isSelected(self): ''' Returns true if the check box is selected. @rtype: boolean ''' return platform.Platform().isSelected(self)
def setFilled(self, flag): ''' Sets the fill status for the arc, where false is outlined and true is filled. If a GArc is unfilled, the figure consists only of the arc itself. If a GArc is filled, the figure consists of the pie-shaped wedge formed by connecting the endpoints of the arc to the center. As an example, the following program draws a 270-degree arc starting at 45 degrees, filled in yellow, much like the character in the PacMan video game:: gw = gwindow.GWindow() print "This program draws the PacMan character." cx = gw.getWidth() / 2 cy = gw.getHeight() / 2 r = 25 pacman = gobjects.GArc(cx - r, cy - r, 2*r, 2*r, 45, 270) pacman.setFilled(True) pacman.setFillColor("YELLOW") gw.add(pacman) @type flag: boolean @rtype: void ''' self.fillFlag = flag platform.Platform().setFilled(self, flag)
def waitForEvent(mask = EventClassType.ANY_EVENT): ''' Dismisses the process until an event occurs whose type is covered by the event mask. The mask parameter is a combination of the events of interest. For example, to wait for a mouse event or an action event, clients can use the following call: e = waitForEvent(MOUSE_EVENT + ACTION_EVENT); The mask parameter is optional. If it is missing, waitForEvent accepts any event. As a more sophisticated example, the following code is the canonical event loop for an animated application that needs to respond to mouse, key, and timer events:: timer = gtimer.GTimer(ANIMATION_DELAY_IN_MILLISECONDS); timer.start() while(True): e = gevents.waitForEvent(TIMER_EVENT + MOUSE_EVENT + KEY_EVENT) if(e.getEventClass == gevents.EventClassType.TIMER_EVENT): takeAnimationStep() elif(e.getEventClass == gevents.EventClassType.MOUSE_EVENT): handleMouseEvent(e) elif(e.getEventClass == gevents.EventClassType.KEY_EVENT): handleKeyEvent(e) @type mask: EventClassType @param mask: EventClassType to wait for, defaults to ANY_EVENT @rtype: GEvent ''' return platform.Platform().waitForEvent(mask)
def __init__(self, width, height, x=0, y=0, raised=False): ''' Initializes a new 3D rectangle with the specified width and height. If the x and y parameters are specified, they are used to specify the origin. The raised parameter determines whether the rectangle should be drawn with highlights that suggest that it is raised about the background. @type width: float @type height: float @type x: float @type y: float @type raised: boolean @rtype: void ''' GRect.__init__(self, width, height) self.x = x self.y = y self.width = width self.height = height self.raised = raised self.fillFlag = False self.fillColor = "" platform.Platform().createG3DRect(self, width, height, str(raised).lower()) self.setLocation(x=x, y=y)
def getText(self): ''' Returns the contents of the text field. @rtype: string ''' return platform.Platform().getText(self)
def getValue(self): ''' Returns the current value of the slider. @rtype: int ''' return platform.Platform().getValue(self)
def getSelectedItem(self): ''' Returns the current item selected in the chooser. @rtype: string ''' return platform.Platform().getSelectedItem(self)
def setFrameRectangle(self, x=None, y=None, width=None, height=None, rect=None): ''' Changes the boundaries of the rectangle used to frame the arc. @type x: float @type y: float @type width: float @type height: float @type rect: GRectangle @param rect: bounding frame, will override other parameters @rtype: void ''' if (rect != None): x = rect.getX() y = rect.getY() width = rect.getWidth() height = rect.getHeight() self.x = x self.y = y self.frameWidth = width self.frameHeight = height platform.Platform().setFrameRectangle(self, x, y, width, height)
def getBounds(self): ''' Gets the bounding rectangle for this object @rtype: GRectangle ''' if (self.transformed): return platform.Platform().getBounds(self) rx = self.frameWidth / 2 ry = self.frameHeight / 2 cx = self.x + rx cy = self.y + ry startRadians = self.start * gmath.PI / 180 sweepRadians = self.sweep * gmath.PI / 180 p1x = cx + math.cos(startRadians) * rx p1y = cy - math.sin(startRadians) * ry p2x = cx + math.cos(startRadians + sweepRadians) * rx p2y = cy - math.sin(startRadians + sweepRadians) * ry xMin = min(p1x, p2x) xMax = max(p1x, p2x) yMin = min(p1y, p2y) yMax = max(p1y, p2y) if (self.containsAngle(0)): xMax = cx + rx if (self.containsAngle(90)): yMin = cy - ry if (self.containsAngle(180)): xMin = cx - rx if (self.containsAngle(270)): yMax = cy + ry if (self.isFilled()): xMin = min(xMin, cx) yMin = min(yMin, cy) xMax = max(xMax, cx) yMax = max(yMax, cy) return gtypes.GRectangle(xMin, yMin, xMax - xMin, yMax - yMin)
def __init__(self, width, height, start, sweep, x=0, y=0): ''' Initializes a new GArc object consisting of an elliptical arc. The first form creates a GArc whose origin is the point (0, 0); the second form positions the GArc at the point (x, y). @type width: float @type height: float @type start: float @param start: degrees @type sweep: float @param sweep: degrees @type x: float @type y: float @rtype: void ''' GObject.__init__(self) self.x = x self.y = y self.frameWidth = width self.frameHeight = height self.start = start self.sweep = sweep self.fillFlag = False self.fillColor = "" platform.Platform().createGArc(self, width, height, start, sweep) self.setLocation(x=x, y=y)
def stop(self): ''' Stops the timer so that it stops generating events until it is restarted. @rtype: void ''' platform.Platform().stopTimer(self)
def act(self): self.timer.tick(60) self.check_platforms() keys = pygame.key.get_pressed() if keys[K_LEFT]: self.movePlatformsLeft() if self.bonus != None: self.moveShirukenPULeft() elif keys[K_RIGHT]: self.movePlatformsRight() if self.bonus != None: self.moveShirukenPURight() ## we can choose the distance between the number of platforms if self.weShouldAddPlatform(): new_platform = platform.Platform(getLevelPlatformImage()) surface_manager.add(new_platform) self.current_platforms.append(new_platform) if self.weShouldAddPowerUp(): self.bonus = powerup.ShurikenPU() surface_manager.add(self.bonus) self.time_since_last_powerup = time.clock() if self.weShouldAddEnemy(): self.ennemies = enemy.Enemy() surface_manager.add(self.ennemies) self.time_since_last_enemyspawn = time.clock()
def play(self): ''' Starts playing the sound. This call returns immediately without waiting for the sound to finish. @rtype: void ''' platform.Platform().playSound(self)
def getBounds(self): ''' Returns the GRectangle bounding this object @rtype: GRectangle ''' if (self.transformed): return platform.Platform().getBounds(self) return gtypes.GRectangle(self.x, self.y, self.width, self.height)
def __init__(self, clustername, username, password, services=["platform", "namespace"]): self.session = session.Session(clustername, username, password, services) self.platform = platform.Platform(self.session)
def removeAt(self, index): ''' Internal method ''' gobj = self.contents[index] self.contents.pop(index) platform.Platform().remove(gobj) gobj.parent = None
def addItem(self, item): ''' Adds a new item consisting of the specified string. @type item: string @rtype: void ''' platform.Platform().addItem(self, item)
def setValue(self, value): ''' Sets the current value of the slider. @type value: int @rtype: void ''' platform.Platform().setValue(self, value)
def setText(self, str): ''' Sets the text of the field to the specified string. @type str: string @rtype: void ''' platform.Platform().setText(self, str)
def setSelected(self, state): ''' Sets the state of the check box. @type state: boolean @rtype: void ''' platform.Platform().setSelected(self, state)
def getBounds(self): ''' Returns the bounding GRectangle of the GInteractor @rtype: GRectangle ''' size = platform.Platform().getSize(self) return gtypes.GRectangle(self.x, self.y, size.getWidth(), size.getHeight())
def setSelectedItem(self, item): ''' Sets the chooser so that it shows the specified item. If the item does not exist in the chooser, no change occurs. @type item: string @rtype: void ''' platform.Platform().setSelectedItem(self, item)
def setLineWidth(self, lineWidth): ''' Sets the width of the line used to draw this object. @type lineWidth: int @rtype: void ''' self.lineWidth = lineWidth platform.Platform().setLineWidth(self, lineWidth)
def setVisible(self, flag): ''' Sets whether this object is visible. @type flag: boolean @rtype: void ''' self.visible = flag platform.Platform().setVisible(flag, gobj=self)
def __init__(self): ''' Creates a GCompound object with no internal components. @rtype: void ''' GObject.__init__(self) self.contents = [] platform.Platform().createGCompound(self)
def setRaised(self, raised): ''' Indicates whether this object appears raised. @type raised: boolean @rtype: void ''' self.raised = raised platform.Platform().setRaised(self, str(raised).lower())
def setFilled(self, flag): ''' Sets the fill status for the oval, where false is outlined and true is filled. @type flag: boolean @rtype: void ''' self.fillFlag = flag platform.Platform().setFilled(self, flag)