久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <tfoot id='yIzP9'></tfoot>
    1. <small id='yIzP9'></small><noframes id='yIzP9'>

      1. <i id='yIzP9'><tr id='yIzP9'><dt id='yIzP9'><q id='yIzP9'><span id='yIzP9'><b id='yIzP9'><form id='yIzP9'><ins id='yIzP9'></ins><ul id='yIzP9'></ul><sub id='yIzP9'></sub></form><legend id='yIzP9'></legend><bdo id='yIzP9'><pre id='yIzP9'><center id='yIzP9'></center></pre></bdo></b><th id='yIzP9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='yIzP9'><tfoot id='yIzP9'></tfoot><dl id='yIzP9'><fieldset id='yIzP9'></fieldset></dl></div>

        • <bdo id='yIzP9'></bdo><ul id='yIzP9'></ul>
      2. <legend id='yIzP9'><style id='yIzP9'><dir id='yIzP9'><q id='yIzP9'></q></dir></style></legend>

        如何在kivy Pong球賽中從另一個類中調用一個類的

        How to call a function from a class from another class in kivy Pong ball game(如何在kivy Pong球賽中從另一個類中調用一個類的函數)

            <small id='WuT7D'></small><noframes id='WuT7D'>

              <i id='WuT7D'><tr id='WuT7D'><dt id='WuT7D'><q id='WuT7D'><span id='WuT7D'><b id='WuT7D'><form id='WuT7D'><ins id='WuT7D'></ins><ul id='WuT7D'></ul><sub id='WuT7D'></sub></form><legend id='WuT7D'></legend><bdo id='WuT7D'><pre id='WuT7D'><center id='WuT7D'></center></pre></bdo></b><th id='WuT7D'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WuT7D'><tfoot id='WuT7D'></tfoot><dl id='WuT7D'><fieldset id='WuT7D'></fieldset></dl></div>
            • <tfoot id='WuT7D'></tfoot>

                <tbody id='WuT7D'></tbody>
                • <bdo id='WuT7D'></bdo><ul id='WuT7D'></ul>
                  <legend id='WuT7D'><style id='WuT7D'><dir id='WuT7D'><q id='WuT7D'></q></dir></style></legend>
                  本文介紹了如何在kivy Pong球賽中從另一個類中調用一個類的函數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用教程中提供的 PongGame 代碼練習 Kivy.我想知道如何從新創建的類 - PongSample 調用 PongGame 類中的函數 - serve_ball2().在下面的代碼中,我創建了一個 PongSample 類,以便在第一個球與球拍碰撞時為第二個球發球.

                  I'm practicing Kivy with the PongGame code given in the tutorial. I want to know how to call a function - serve_ball2() in the class PongGame from a newly created class - PongSample. In the below code I created a class PongSample to serve the second ball once the first ball collide with the paddle.

                  更新:我可以從 PongSample 調用 serve_ball2(),但 serve_ball2() 沒有按預期運行,即它沒有發球.

                  Update : I can call the serve_ball2() from PongSample but the serve_ball2() doesn't function as intended i.e it doesn't serve the ball.

                  我在下面分享了完整的代碼.提前致謝

                  I've shared the complete code below. Thanks in advance

                  Pong.py:

                  from kivy.app import App
                  from kivy.uix.widget import Widget
                  from kivy.properties import NumericProperty, ReferenceListProperty,
                      ObjectProperty
                  from kivy.vector import Vector
                  from kivy.clock import Clock, time
                  from threading import Thread
                  
                  class PongPaddle(Widget):
                      score = NumericProperty(0)
                  
                      def bounce_ball(self, ball):
                          if self.collide_widget(ball):
                              vx, vy = ball.velocity
                              offset = (ball.center_y - self.center_y) / (self.height / 2)
                              bounced = Vector(-1 * vx, vy)
                              vel = bounced * 1.1
                              ball.velocity = vel.x, vel.y + offset
                              PongSample().call_game()
                  
                  class PongBall(Widget):
                      velocity_x = NumericProperty(0)
                      velocity_y = NumericProperty(0)
                      velocity = ReferenceListProperty(velocity_x, velocity_y)
                  
                      def move(self):
                          self.pos = Vector(*self.velocity) + self.pos
                  
                  class PongSample(Widget):
                      def call_game(self):
                          print 'PongSample'
                          ponggame=PongGame()
                          ponggame.serve_ball2()
                  
                  class PongGame(Widget):
                      ball = ObjectProperty(None)
                      ball2 = ObjectProperty(None)
                      player1 = ObjectProperty(None)
                      player2 = ObjectProperty(None)
                  
                      def serve_ball(self, vel=(4, 0)):
                          self.ball.center = self.center
                          self.ball.velocity = vel
                  
                      def serve_ball2(self, vel=(3, 0)):  
                          print 'Serve_ball2'
                          self.ball2.center = self.center
                          self.ball2.velocity = vel
                  
                      def serve_down(self):
                          print 'Inside Serve Down'
                          self.ball.center = self.center
                          self.ball.velocity = Vector(4,0).rotate(-90)
                  
                      def update(self, dt):
                          self.ball.move()
                          self.ball2.move()
                  
                          #bounce of paddles
                          self.player1.bounce_ball(self.ball)
                          self.player2.bounce_ball(self.ball)
                  
                          #bounce ball off bottom or top
                          if (self.ball.y < self.y) or (self.ball.top > self.top):
                              self.ball.velocity_y *= -1
                          if (self.ball2.y < self.y) or (self.ball2.top > self.top):
                              self.ball2.velocity_y *= -1
                  
                          #went of to a side to score point?
                          if self.ball.x < self.x:
                              self.player2.score += 1
                              self.serve_ball(vel=(4, 0))
                          if self.ball.x > self.width:
                              self.player1.score += 1
                              self.serve_ball(vel=(-4, 0))
                  
                          if self.ball2.x < self.x:
                              self.player2.score += 1
                              self.serve_ball2(vel=(3, 0))
                          if self.ball2.x > self.width:
                              self.player1.score += 1
                              self.serve_ball2(vel=(-3, 0))
                  
                      def on_touch_move(self, touch):
                          if touch.x < self.width / 3:
                              self.player1.center_y = touch.y
                          if touch.x > self.width - self.width / 3:
                              self.player2.center_y = touch.y
                  
                  class PongApp(App):
                      def build(self):
                          game = PongGame()
                          game.serve_ball()
                          Clock.schedule_interval(game.update, 1.0 / 60.0)
                          return game
                  
                  if __name__ == '__main__':
                      PongApp().run()
                  

                  pong.kv:

                      #:kivy 1.8.0
                  
                  <PongBall>:
                      size: 50, 50 
                      canvas:
                          Ellipse:
                              pos: self.pos
                              size: self.size          
                  
                  <PongPaddle>:
                      size: 25, 200
                      canvas:
                          Rectangle:
                              pos:self.pos
                              size:self.size
                  
                  <PongGame>:
                      ball: pong_ball
                      ball2: pong_ball2
                      player1: player_left
                      player2: player_right
                  
                      canvas:
                          Rectangle:
                              pos: self.center_x-5, 0
                              size: 10, self.height
                  
                      Label:
                          font_size: 70  
                          center_x: root.width / 4
                          top: root.top - 50
                          text: str(root.player1.score)
                  
                      Label:
                          font_size: 70  
                          center_x: root.width * 3 / 4
                          top: root.top - 50
                          text: str(root.player2.score)
                  
                      PongBall:
                          id: pong_ball
                          center: self.parent.center
                  
                      PongBall:
                          id: pong_ball2
                          center: self.parent.center
                  
                      PongPaddle:
                          id: player_left
                          x: root.x
                          center_y: root.center_y
                  
                      PongPaddle:
                          id: player_right
                          x: root.width-self.width
                          center_y: root.center_y
                  

                  推薦答案

                  我強調這似乎沒有必要,而 PongSample 本身似乎根本不需要存在.但是,按照您的要求,我相信以下應該有效.然而,我真正不喜歡的一件事是,在 kv 文件中創建了一個 PongSample 實例,除了為 ball2 服務之外沒有任何其他目的.不過……

                  I emphasize that this seems unnecessary, and that PongSample itself seems like it needn't exist at all. However, to do what you asked, I believe the following should work. One thing I really don't like about this however, is that a PongSample instance is created in the kv file, without any other purpose than to serve ball2. However...

                  為什么不在 PongSample 類中定義 serve_ball2 函數,并將 ball2 傳遞給它?

                  Why not define the serve_ball2 function in the PongSample class instead, and pass ball2 to it?

                  例子:

                  class PongSample(Widget):
                  
                      def serve_ball2(self, ball2, vel=(3,0)):
                          print 'Serve ball 2'
                          ball2.center = self.center
                          ball2.velocity = vel
                  

                  在 PongGame 類中:

                  And in the PongGame class:

                  class PongGame(Widget):
                      ball = ObjectProperty(None)
                      ball2 = ObjectProperty(None)
                      player1 = ObjectProperty(None)
                      player2 = ObjectProperty(None)
                      # add this
                      sample = ObjectProperty(None)
                  

                  然后在kv文件中:

                  # add at the top
                  
                  <PongSample>:
                      size: self.size
                      pos: self.pos
                  
                  # add the below in appropriate places within the PongGame definition
                  
                  PongGame:
                      sample: pong_sample
                  
                      PongSample:
                          id: pong_sample # now it's linked to 'sample' in PongGame
                  

                  所以現在在 PongGame 中,您可以從任何方法調用 self.sample.serve_ball2(ball2).

                  So now in PongGame you can call self.sample.serve_ball2(ball2) from any method.

                  這篇關于如何在kivy Pong球賽中從另一個類中調用一個類的函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)

                  <legend id='ENl61'><style id='ENl61'><dir id='ENl61'><q id='ENl61'></q></dir></style></legend>

                      • <bdo id='ENl61'></bdo><ul id='ENl61'></ul>

                            <tbody id='ENl61'></tbody>

                          <small id='ENl61'></small><noframes id='ENl61'>

                          • <i id='ENl61'><tr id='ENl61'><dt id='ENl61'><q id='ENl61'><span id='ENl61'><b id='ENl61'><form id='ENl61'><ins id='ENl61'></ins><ul id='ENl61'></ul><sub id='ENl61'></sub></form><legend id='ENl61'></legend><bdo id='ENl61'><pre id='ENl61'><center id='ENl61'></center></pre></bdo></b><th id='ENl61'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ENl61'><tfoot id='ENl61'></tfoot><dl id='ENl61'><fieldset id='ENl61'></fieldset></dl></div>
                          • <tfoot id='ENl61'></tfoot>

                          • 主站蜘蛛池模板: 久久人人网 | 91婷婷韩国欧美一区二区 | 国产日韩欧美精品一区二区三区 | 久久国产亚洲 | 日韩精品一区二区三区中文在线 | 欧美久久免费观看 | 中文字幕不卡在线88 | 亚洲狠狠丁香婷婷综合久久久 | 久久国产精品色av免费观看 | 成人影院网站ww555久久精品 | 国产一区二区精 | 一区二区三区日本 | 国产福利91精品 | 成人午夜黄色 | 青青久草 | 午夜精 | 四虎精品在线 | 亚洲 欧美 日韩 在线 | 天天干天天爱天天操 | 一级片片 | 久久网站免费视频 | 日韩视频在线一区 | 中文字幕91av | 成人免费在线小视频 | 久久久精品影院 | 久在线视频播放免费视频 | 天天操夜夜艹 | 在线视频亚洲 | 爱操影视| 欧美精品一区二区三区在线播放 | 成人午夜激情 | 视频一区二区三区中文字幕 | 亚洲欧美一区二区三区国产精品 | 久久精品欧美一区二区三区不卡 | 国产特级毛片 | 午夜免费视频 | 激情综合五月天 | 欧美在线观看一区二区 | 国产免费福利小视频 | 国产精品免费一区二区三区四区 | k8久久久一区二区三区 |