Übung 9: Sprites und Wände

Ziel: Erstelle eine Landschaft aus Wandobjekten, in der der Benutzer navigieren muss, um Münzen zu sammeln. Dies hilft beim Üben der Verwendung von for-Schleifen, um mehrere Elemente zu erstellen und zu positionieren.

../../_images/lab9.gif
  • Step 1: Start with one these examples:

  • Schritt 2: Wenn du mit den Beispielen beginnst, lösche den aktuellen Programmcode zum Platzieren der Wände. Du sollst deine eigenen Wände erstellen.

  • Step 3: Create a more complex arrangement of walls. Make sure the walls don’t allow the user to go off-screen. This is worth 6 points, based on how complex the arrangement. See Individually Placing Walls, Placing Walls With A Loop, and Placing Walls With A List for ideas. Just DON’T do the same thing as examples. Make it your own. Specifically, do NOT just copy the random wall-gap algorithm in the scrolling screen example.

  • Step 4: Update the graphics. Use multiple types of blocks for the walls. (See note below.) Change the character. This is worth 4 points, one point for each graphic used that wasn’t part of the base example. Remember to put a quick citation in your program just before you load graphics or sounds.

Bemerkung

If you have more than one type of wall block, that’s great. But you don’t need more than one wall list. The physics engine requires all walls be kept in the same list.

  • Step 5: Add coins (or something) for the user to collect. 4 points, based on the complexity of the coin layout. Remember, you can place coins like we placed wall blocks. If you randomly place coins, you might end up with coins on top of walls. See the „Important Part“ around line 83 or so of the example sprite_no_coins_on_walls.py for how to avoid this.

  • Schritt 6: Zähle mit, wie viele Münzen gesammelt wurden, und zeige den Wert auf dem Bildschirm an. Maximal 4 Punkte.

  • Schritt 7: Gib jedes Mal einen Sound aus, wenn der Benutzer eine Münze einsammelt. 2 Punkte.

Warnung

Bewege die Spielfigur nicht doppelt!

Die Anweisung self.physics_engine.update() bewegt die Spielfigur, während sie auf Wände überprüft. Die Anweisung self.all_sprites_list.update() bewegt die Spielfigur, ohne auf Wände zu überprüfen. Verwende nicht beide Anweisungen. Du würdest am Ende „durch Wände gehen“. Wenn du andere zu aktualisierende Sprites hast, aktualisiere nur diese Sprites. Zum Beispiel: self.coin_list.update().

Zusätzliche Herausforderungen

Diese werden für diese Übung nicht benötigt, aber ich wurde in vergangenen Jahren von Studierenden gefragt, wie das geht:

  • This is a great project to use the Move Better example, as you’ll find player movement is a lot more predictable.

  • If you are interested in having the player be able to face left or right, see the Sprite Face Left or Right example.

  • Want to animate walking? Look at the Animate your sprites. example.