Programmieren – die besten Beiträge

Wie kann ich mehrere Münzen in PyGame einsammeln?

Hallo,

ich habe eine Frage zu meinem Programm.

Nachdem ich die dritte Münze in meinem Spiel eingesammelt habe, wird komischerweise die zweite Münze anstatt der Dritten gespawnt. Wie kann ich das ändern? Bzw. hat jemand eine Idee, wie sich das beheben lässt?

Hier ist mein Code:

from random import randint

WIDTH = 600
HEIGHT = 600
score = 0
game_over = False

mario = Actor("mario.png")
mario.pos = 100, 100

coin = Actor("money.png")
coin.pos = 0, 0

def draw():
  screen.fill("green")
  mario.draw()
  coin.draw()
  screen.draw.text("Punkte: " + str(score), color="black", topleft=(10, 10))

  if game_over:
    screen.fill("pink")
    screen.draw.text("Endstand:" + str(score), topleft=(10, 10), fontsize = 60)

def place_coin():
  coin.x = 100
  coin.y = 200

def place_coin2():
  coin.x = 100
  coin.y = 300

def place_coin3():
  coin.x = 100
  coin.y = 400

def place_coin4():
  coin.x = 100
  coin.y = 500

def place_coin5():
  coin.x = 300
  coin.y = 100

def place_coin6():
  coin.x = 300
  coin.y = 300

def place_coin7():
  coin.x = 500
  coin.y = 200

def place_coin8():
  coin.x = 500
  coin.y = 300

def place_coin9():
  coin.x = 500
  coin.y = 400

def place_coin10():
  coin.x = 500
  coin.y = 500

def place_coin11():
  coin.x = 700
  coin.y = 100

def place_coin12():
  coin.x = 700
  coin.y = 300

def time_up():
  global game_over
  game_over = True

def update():
  global score

  if keyboard.left:
    mario.x = mario.x - 4
  elif keyboard.right:
    mario.x = mario.x + 4
  elif keyboard.up:
    mario.y = mario.y - 4
  elif keyboard.down:
    mario.y = mario.y + 4

  coin_collectet = mario.colliderect(coin)

  if coin_collectet:
    score = score + 10
    place_coin2()

  coin_collectet = mario.colliderect(coin)

  if coin_collectet:
    score = score + 10
    place_coin10()

  coin_collectet = mario.colliderect(coin)

  if coin_collectet:
    score = score + 10
    place_coin4()

  coin_collectet = mario.colliderect(coin)

  if coin_collectet:
    score = score + 10
    place_coin8()

clock.schedule(time_up, 20.0)
place_coin()
programmieren, Pygame

Symfony authentication funktioniert nicht?

Guten Tag,

für mein Symfony-Projekt habe ich beschlossen, das von Symfony miglieferter Security Bundle für die User-Authentifikation zu verwenden.

Ich habe mich nach folgenden Dokuemntationen durchgearbeitet:
https://symfony.com/doc/current/security.html
https://symfony.com/doc/current/security/form_login_setup.html
https://symfony.com/doc/current/testing.html#doctrine-fixtures

Hier meine Dateien:

SecurityController: https://hastebin.com/tiruyoteco.php

LoginAuth. https://hastebin.com/abewapanod.php

Dummy User: https://hastebin.com/epemuqihoz.php

Ich habe nun einen SecurityController, einen LoginFormAuthenticator, eine login.html.twig und eine security.yaml.

All diese Sachen sind auto_generiert und wurden von mir nicht verändert. Ferner habe ich einen dummy User angelegt, welcher den Benutzernamen "Test" und das Passwort "Test" hat.

Möchte ich mich jetzt testweise einloggen, lädt die Seite einfach neu, ohne dass ich einen Error oder einen Success bekomme.

Hier der Code der login.html.twig [2]

{% extends 'base.html.twig' %}

{% block title %}Log in!{% endblock %}
  {% block home %}active{% endblock %}
{% block stylesheets %}
    <link href="{{ asset("css/login.css") }}" rel="stylesheet">
{% endblock %}

{% block body %}

    <div class="container">
        <form class="text-light" method="post">
            {% if error %}
                <div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
            {% endif %}

            {% if app.user %}
                <div class="mb-3">
                    You are logged in as {{ app.user.username }}, <a href="{{ path('app_logout') }}">Logout</a>
                </div>
            {% endif %}
            <h2 class="text-center mb-5">Login</h2>
            <div class="mb-3">
                <input type="text" class="form-control text-light form-control-lg " placeholder="Username" id="exampleInputEmail1" value="{{ last_username }}" name="username" aria-describedby="emailHelp" required>
            </div>
            <div class="mb-3">
                <input type="password" name="password" placeholder="Password" class="form-control text-light form-control-lg " id="exampleInputPassword1" required>
            </div>
            <div class="d-flex justify-content-between">
                <button type="submit" class="btn btn-outline-success">Einloggen</button>
                <a href="./register" class="btn btn-outline-primary">Registrieren</a>
            </div>
            <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
        </form>
    </div>
{% endblock %}

meine Frage ist nun, an welchen Stellen ich nach dem fehler suchen soll oder ob ihr schon eine erkennt.

Vielen Dank.

mfg. Anton

Computer, Technik, programmieren, Framework, PHP, Webentwicklung, Laravel, Backend-Developer

AttributeError: 'PhotoImage' object has no attribute 'shape'?

Ich bin derzeit dabei mit tkinter, opencv und mit Media Pipe Framework zu arbeiten. Dabei möchte ich Bilder Hochladen können und die hochgeladenen Bilder soll mithilfe von Mediapipe die Hand Landmarks erfassen. Mit Hand Landmarks meine ich alle 21 Positionen eines Hand zu erkennen (Hier findet ihr mehr Infos dazu: https://google.github.io/mediapipe/solutions/hands.html ). Leider bekomme ich mit meiner erstellten Implementierung folgende Fehlermeldung:

INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:/Users/bj/projects/pro1/pictureMp.py", line 31, in imageLandmarks
    height, width, _ = image.shape
AttributeError: 'PhotoImage' object has no attribute 'shape'

Was kann ich dagegen machen? Hier ist mein aktueller Code:

def imageLandmarks():
    global panelA
    with mpHands.Hands(static_image_mode=True, max_num_hands=2, min_detection_confidence=0.5) as hands:
        select_image.path = filedialog.askopenfilename()
        filename = os.path.basename(select_image.path)

        if len(select_image.path) > 0:
            image = cv2.imread(select_image.path)
            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            image = Image.fromarray(image)
            image = ImageTk.PhotoImage(image)

            height, width, _ = image.shape
            results = hands.process(image)

            num_cords = 21
            landmarks = ['class']
            for val in range(1, num_cords + 1):
                landmarks += ['x{}'.format(val), 'y{}'.format(val), 'z{}'.format(val)]

                if results.multi_hand_landmarks:
                    for num, hand in enumerate(results.multi_hand_landmarks):
                        mpDraw.draw_landmarks(image, hand, mpHands.HAND_CONNECTIONS)
programmieren, Python, opencv, Tkinter

Meistgelesene Beiträge zum Thema Programmieren