Bug When Jumping Tkinter Python 3












0














When the player jumps onto the box i want them to jump again but a big happens where only 1 iteration of the jump loop happens



My Code:



import tkinter
from tkinter import *
import time

root = Tk()
frame = Frame(root)
canvas = Canvas(frame, width=800, height=500, bg='Black')
frame.pack()
canvas.pack()
canvas.focus_set()


class Player:
def __init__(self, canvas):
self.canvas = canvas
self.id = self.canvas.create_rectangle(200, 440, 250, 490, fill='Black', outline='White', width=5)
self.isJump = False
self.canvas.bind('<space>', self.jump)
self.x = 0
self.coords = self.canvas.coords(self.id)
self.fall = False

def jump(self, event):
self.isJump = True


def update(self):
self.coords = self.canvas.coords(self.id)
if self.fall != True:
if self.isJump == True:
if self.x <= 15:
self.canvas.move(self.id, 0, -10)
self.x += 1
elif self.x <= 31:
self.canvas.move(self.id, 0, 10)
self.x += 1
else:
self.isJump = False
self.x = 0

class Box:
def __init__(self, canvas, x, y, width, height):
self.canvas = canvas
self.id = self.canvas.create_rectangle(x, y, x+width, y+height, fill='White', width=0)
self.height = height
self.coords = self.canvas.coords(self.id)
self.passed = False

def update(self):
self.coords = self.canvas.coords(self.id)
self.canvas.move(self.id, -5, 0)

l =
l.append(Box(canvas, 1900, 390, 500, 100))
l.append(Box(canvas, 2800, 390, 300, 100))

p1 = Player(canvas)
co = [p1.coords[0], 440.0, p1.coords[2], 490.0]

g = False

while 1:
root.update()
root.update_idletasks()

p1.update()

for i in range(len(l)):
l[i].update()
if p1.coords[2] >= l[i].coords[0]:
if p1.coords[0] < l[i].coords[2]:

if p1.coords[3] > l[i].coords[1]:
print('cool')
canvas.delete(ALL)
elif p1.coords[3] < l[i].coords[1]:
p1.isJump = False
p1.x = 0
if g == False:
print('gogofdoaof')
canvas.coords(p1.id, p1.coords[0], l[i].coords[1]-55, p1.coords[2], l[i].coords[1]-5)
g = True
p1.x = 0



else:
if p1.coords != co and l[i].passed == False:
p1.fall = True
g = False
canvas.move(p1.id, 0, 5)
else:
p1.fall = False
l[i].passed = True


time.sleep(0.015)









share|improve this question







New contributor




Charlie Mort is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0














    When the player jumps onto the box i want them to jump again but a big happens where only 1 iteration of the jump loop happens



    My Code:



    import tkinter
    from tkinter import *
    import time

    root = Tk()
    frame = Frame(root)
    canvas = Canvas(frame, width=800, height=500, bg='Black')
    frame.pack()
    canvas.pack()
    canvas.focus_set()


    class Player:
    def __init__(self, canvas):
    self.canvas = canvas
    self.id = self.canvas.create_rectangle(200, 440, 250, 490, fill='Black', outline='White', width=5)
    self.isJump = False
    self.canvas.bind('<space>', self.jump)
    self.x = 0
    self.coords = self.canvas.coords(self.id)
    self.fall = False

    def jump(self, event):
    self.isJump = True


    def update(self):
    self.coords = self.canvas.coords(self.id)
    if self.fall != True:
    if self.isJump == True:
    if self.x <= 15:
    self.canvas.move(self.id, 0, -10)
    self.x += 1
    elif self.x <= 31:
    self.canvas.move(self.id, 0, 10)
    self.x += 1
    else:
    self.isJump = False
    self.x = 0

    class Box:
    def __init__(self, canvas, x, y, width, height):
    self.canvas = canvas
    self.id = self.canvas.create_rectangle(x, y, x+width, y+height, fill='White', width=0)
    self.height = height
    self.coords = self.canvas.coords(self.id)
    self.passed = False

    def update(self):
    self.coords = self.canvas.coords(self.id)
    self.canvas.move(self.id, -5, 0)

    l =
    l.append(Box(canvas, 1900, 390, 500, 100))
    l.append(Box(canvas, 2800, 390, 300, 100))

    p1 = Player(canvas)
    co = [p1.coords[0], 440.0, p1.coords[2], 490.0]

    g = False

    while 1:
    root.update()
    root.update_idletasks()

    p1.update()

    for i in range(len(l)):
    l[i].update()
    if p1.coords[2] >= l[i].coords[0]:
    if p1.coords[0] < l[i].coords[2]:

    if p1.coords[3] > l[i].coords[1]:
    print('cool')
    canvas.delete(ALL)
    elif p1.coords[3] < l[i].coords[1]:
    p1.isJump = False
    p1.x = 0
    if g == False:
    print('gogofdoaof')
    canvas.coords(p1.id, p1.coords[0], l[i].coords[1]-55, p1.coords[2], l[i].coords[1]-5)
    g = True
    p1.x = 0



    else:
    if p1.coords != co and l[i].passed == False:
    p1.fall = True
    g = False
    canvas.move(p1.id, 0, 5)
    else:
    p1.fall = False
    l[i].passed = True


    time.sleep(0.015)









    share|improve this question







    New contributor




    Charlie Mort is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0







      When the player jumps onto the box i want them to jump again but a big happens where only 1 iteration of the jump loop happens



      My Code:



      import tkinter
      from tkinter import *
      import time

      root = Tk()
      frame = Frame(root)
      canvas = Canvas(frame, width=800, height=500, bg='Black')
      frame.pack()
      canvas.pack()
      canvas.focus_set()


      class Player:
      def __init__(self, canvas):
      self.canvas = canvas
      self.id = self.canvas.create_rectangle(200, 440, 250, 490, fill='Black', outline='White', width=5)
      self.isJump = False
      self.canvas.bind('<space>', self.jump)
      self.x = 0
      self.coords = self.canvas.coords(self.id)
      self.fall = False

      def jump(self, event):
      self.isJump = True


      def update(self):
      self.coords = self.canvas.coords(self.id)
      if self.fall != True:
      if self.isJump == True:
      if self.x <= 15:
      self.canvas.move(self.id, 0, -10)
      self.x += 1
      elif self.x <= 31:
      self.canvas.move(self.id, 0, 10)
      self.x += 1
      else:
      self.isJump = False
      self.x = 0

      class Box:
      def __init__(self, canvas, x, y, width, height):
      self.canvas = canvas
      self.id = self.canvas.create_rectangle(x, y, x+width, y+height, fill='White', width=0)
      self.height = height
      self.coords = self.canvas.coords(self.id)
      self.passed = False

      def update(self):
      self.coords = self.canvas.coords(self.id)
      self.canvas.move(self.id, -5, 0)

      l =
      l.append(Box(canvas, 1900, 390, 500, 100))
      l.append(Box(canvas, 2800, 390, 300, 100))

      p1 = Player(canvas)
      co = [p1.coords[0], 440.0, p1.coords[2], 490.0]

      g = False

      while 1:
      root.update()
      root.update_idletasks()

      p1.update()

      for i in range(len(l)):
      l[i].update()
      if p1.coords[2] >= l[i].coords[0]:
      if p1.coords[0] < l[i].coords[2]:

      if p1.coords[3] > l[i].coords[1]:
      print('cool')
      canvas.delete(ALL)
      elif p1.coords[3] < l[i].coords[1]:
      p1.isJump = False
      p1.x = 0
      if g == False:
      print('gogofdoaof')
      canvas.coords(p1.id, p1.coords[0], l[i].coords[1]-55, p1.coords[2], l[i].coords[1]-5)
      g = True
      p1.x = 0



      else:
      if p1.coords != co and l[i].passed == False:
      p1.fall = True
      g = False
      canvas.move(p1.id, 0, 5)
      else:
      p1.fall = False
      l[i].passed = True


      time.sleep(0.015)









      share|improve this question







      New contributor




      Charlie Mort is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      When the player jumps onto the box i want them to jump again but a big happens where only 1 iteration of the jump loop happens



      My Code:



      import tkinter
      from tkinter import *
      import time

      root = Tk()
      frame = Frame(root)
      canvas = Canvas(frame, width=800, height=500, bg='Black')
      frame.pack()
      canvas.pack()
      canvas.focus_set()


      class Player:
      def __init__(self, canvas):
      self.canvas = canvas
      self.id = self.canvas.create_rectangle(200, 440, 250, 490, fill='Black', outline='White', width=5)
      self.isJump = False
      self.canvas.bind('<space>', self.jump)
      self.x = 0
      self.coords = self.canvas.coords(self.id)
      self.fall = False

      def jump(self, event):
      self.isJump = True


      def update(self):
      self.coords = self.canvas.coords(self.id)
      if self.fall != True:
      if self.isJump == True:
      if self.x <= 15:
      self.canvas.move(self.id, 0, -10)
      self.x += 1
      elif self.x <= 31:
      self.canvas.move(self.id, 0, 10)
      self.x += 1
      else:
      self.isJump = False
      self.x = 0

      class Box:
      def __init__(self, canvas, x, y, width, height):
      self.canvas = canvas
      self.id = self.canvas.create_rectangle(x, y, x+width, y+height, fill='White', width=0)
      self.height = height
      self.coords = self.canvas.coords(self.id)
      self.passed = False

      def update(self):
      self.coords = self.canvas.coords(self.id)
      self.canvas.move(self.id, -5, 0)

      l =
      l.append(Box(canvas, 1900, 390, 500, 100))
      l.append(Box(canvas, 2800, 390, 300, 100))

      p1 = Player(canvas)
      co = [p1.coords[0], 440.0, p1.coords[2], 490.0]

      g = False

      while 1:
      root.update()
      root.update_idletasks()

      p1.update()

      for i in range(len(l)):
      l[i].update()
      if p1.coords[2] >= l[i].coords[0]:
      if p1.coords[0] < l[i].coords[2]:

      if p1.coords[3] > l[i].coords[1]:
      print('cool')
      canvas.delete(ALL)
      elif p1.coords[3] < l[i].coords[1]:
      p1.isJump = False
      p1.x = 0
      if g == False:
      print('gogofdoaof')
      canvas.coords(p1.id, p1.coords[0], l[i].coords[1]-55, p1.coords[2], l[i].coords[1]-5)
      g = True
      p1.x = 0



      else:
      if p1.coords != co and l[i].passed == False:
      p1.fall = True
      g = False
      canvas.move(p1.id, 0, 5)
      else:
      p1.fall = False
      l[i].passed = True


      time.sleep(0.015)






      python python-3.x tkinter






      share|improve this question







      New contributor




      Charlie Mort is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Charlie Mort is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Charlie Mort is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 hour ago









      Charlie Mort

      1




      1




      New contributor




      Charlie Mort is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Charlie Mort is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Charlie Mort is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Charlie Mort is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210555%2fbug-when-jumping-tkinter-python-3%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Charlie Mort is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Charlie Mort is a new contributor. Be nice, and check out our Code of Conduct.













          Charlie Mort is a new contributor. Be nice, and check out our Code of Conduct.












          Charlie Mort is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210555%2fbug-when-jumping-tkinter-python-3%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre