Einsteigerfrage

Startseite Foren Deutsches LiveCode-Forum Einsteigerfrage

Ansicht von 1 Antwort-Thema
  • Autor
    Beiträge
    • #2229
      duiJM
      Teilnehmer

        Hallo zusammen,
        ich befasse mich erst seit kurzem mit LC und zum Einstieg habe ich mir eine Art PacMan vorgenommen.
        Ich habe ein Labyrinth (Lab03.png), eine Spielfigur (grun.png) die ich steuern kann, die nicht gegen die Wände laufen darf usw und einen Gegner (rot.png), der auf die Spielfigur zuläuft, in Abhängigkeit, wo diese sich befindet und auch nicht gegen die Wand laufen soll. Klappt allerdings nur solange, bis rot die vertikale Position von grun erreicht hat. Dann bleibt rot stehen.
        Ich weiß im moment nicht, ob das ein LC Problem ist, oder ein Denkfehler in meiner Programmierung?! 😉
        Vielleicht kann mit jemand nen Tip geben?!

        Hier der Code:
        (movered wird übrigens über einen screenupdater aufgerufen)

        on movered –bewegt rot eigenständig
        if the left of the image “grun.png” < the left of the image “rot.png” then
        set the left of image “rot.png” to the left of image “rot.png” -1
        if intersect( image “rot.png” , image “Lab03.png” , 150) then –prüft ob rot gegen Wand
        set the left of image “rot.png” to the left of image “rot.png” +1
        end if
        end if
        if the left of the image “grun.png” > the left of the image “rot.png” then
        set the left of image “rot.png” to the left of image “rot.png” +1
        if intersect( image “rot.png” , image “Lab03.png” , 150) then
        set the left of image “rot.png” to the left of image “rot.png” -1
        end if
        end if
        if the top of the image “grun.png” > the top of the image “rot.png” then
        set the top of image “rot.png” to the top of image “rot.png” +1
        if intersect( image “rot.png” , image “Lab03.png” , 150) then
        set the top of image “rot.png” to the top of image “rot.png” -1
        end if
        end if
        if the top of the image “grun.png” < the top of the image “rot.png” then
        set the top of image “rot.png” to the top of image “rot.png” -1
        if intersect( image “rot.png” , image “Lab03.png” , 150) then
        set the top of image “rot.png” to the top of image “rot.png” +1
        end if
        end if
        –detectCollisions
        send movered to this stack in 1 seconds
        end movered

      • #2248
        Klaus Major
        Administrator

          Hallo duijM,

          willkommen im Forum! 🙂

          Hinweis: Wnn du LC Objekte ansprichst, bitte nicht THE benutzen -> the left of THE image xyz.
          Also OHNE THE -> the left of img xyz…

          THE wird verwendet, wenn Du Custom Properties ansprichst.

          OK, zu Deinem Problem, ich denke es fehlt die Kodition =, die lässt du in Deinem Skript aus.
          Du fragst nur ab, ob the left of img “rot” GROESSER oder KLEINER als the left of img “gruen” ist.
          Deshalb bleibt ROT stehen, es gibt keine Anweisung, was passieren soll, wenn die beiden Bilder die SELBE Position haben!

          Mach es so:

          if the left of image “grun.png” >= the left of the image “rot.png” then

          Selbiges für TOP.

          Gruß

          Klaus

      Ansicht von 1 Antwort-Thema
      • Du musst angemeldet sein, um auf dieses Thema antworten zu können.