I am trying to make that flappybirdAI tutorial, but I can't control my work, as I can't get a preview from it.
I am using this tutorial: https://www.youtube.com/watch?v=ps55secj7iU&list=PLzMcBGfZo4-lwGZWXz5Qgta_YNX3_vLS2&index=2 (this is also my actual status at 16:52, WHERE HE IS OPENING A PREVIEW)
And here is the repository: https://github.com/techwithtim/NEAT-Flappy-Bird
It is complete and working, but I can't find out, how the preview ist started. I already tryed just adding my new trainingfile into that repository (can't get a review from it) And also tryed to create a new one with my own package.json (review does not work)
In every tutorial i find, package.json seems to be necessary, but in that repository is no ".json".
So can anybody help me getting a preview from that running file, please? (I can run it by the way without an ERROR.)
That is my actual code:
import pygame
import neat
import time
import os
import random
WIN_WIDTH = 500
WIN_HEIGHT = 800
#was ist wirklich ein pivotpunkt muss definiert werden. wsl nach prozenten der Laenge der Linie
BIRD_IMGS = [pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bird1.png"))), pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bird2.png"))), pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bird3.png")))] #scale ist für die Vergrößerung des Vogelbildes, load laed ein Bild in die Liste
PIPE_IMG = pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "pipe.png")))
BASE_IMG = pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "base.png")))
BG_IMG = pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bg.png")))
class Bird:
IMGS = BIRD_IMGS
MAX_ROTATION = 25 #max rotationswinkel
ROT_VEL = 20 #rotation per frame
ANIMATION_TIME = 5
def __init__(self, x, y): # initialdaten des Vogels
self.x = x #startposition Vogel
self.y = y
self.tilt = 0 #wie viel ist das Bild gekippt
self.tick_count = 0
self.vel = 0 #geschwindigkeit Bild
self.height = self.y
self.img_count = 0 #welches Vogelbild wird gerade gezeigt? Für die Animation wichtig
self.img = self.IMGS[0] #Bild bird1.png von oben
def jump(self):
self.vel = -10.5 #negativ, weil der Ursprung der Koordinatien links oben ist
self.tick_count = 0 #wann das letzte mal gesprungen? wird zurückgesetzt um das physische Verhalten danach auszurichten (vllt wie lange ist der Einstieg her)
self.height = self.y #von wo aus springt der Vogel (vllt wo Einstiegspunkt)
def move(self): #hier wird jeden Frame gesagt, dass der Vogel bewegt werden soll
self.tick_count += 1
d = self.vel*self.tick_count + 1.5*self.tick_count**2 #macht den Parabelflug bzw die Geschwindigkeitsbewegung die das verursacht
if d >= 16: #Geschwindigkeitsgrenze
d = 16
if d < 0: #Geschwindigkeit über 0, addiere Geschwindigkeit nach oben
d -= 2
self.y = self.y + d #berechnet in welche Richtung der Vogel Geschwindigkeit hat
if d < 0 or self.y < self.height + 50:
if self.tilt < self.MAX_ROTATION:
self.tilt = self.MAX_ROTATION #limitert die Rotation des Bildes
else:
if self.tilt > -90:
self.tilt -= self.ROT_VEL
def draw(self, win):
self.img_count += 1
if self.img_count < self.ANIMATION_TIME: #Animation_Time ist die Anzahl an Frames solange ein Bild bleiben soll. damit ein gleichmäßiges Flattern entsteht, vervielfacht sich diese Zeit ich gleichen Abständen. Beim Fallen schlägt der Vogel mit keinen Flügeln mehr.
self.img = self.IMGS[0]
elif self.img_count < self.ANIMATION_TIME*2:
self.img = self.IMGS[1]
elif self.img_count < self.ANIMATION_TIME*3:
self.img = self.IMGS[2]
elif self.img_count < self.ANIMATION_TIME*4:
self.img = self.IMGS[1]
elif self.img_count == self.ANIMATION_TIME*4 +1:
self.img = self.IMGS[0]
self.img_count = 0
if self.tilt <= -80:
self.img = self.IMGS[1]
self.img_count = self.ANIMATION_TIME*2 #dadurch flattert der Vogel beim Sturzflug nicht
rotated_image = pygame.transform.rotate(self.img, self.tilt)
new_rect = rotated_image.get_rect(center=self.img.get_rect(topleft = (self.x, self.y)).center) #rotiert das Bild von der Mitte aus und nicht von links oben
win.blit(rotated_image, new_rect.topleft) #Bild wird in das win(dow) geladen. blit ist wsl das schnelle kopieren und verschieben von Speicherinhalten
def get_mask(self): #Kollision mit Objekten
return pygame.mask.from_surface(self.img)
def draw_window(win, bird): #zeichnet das Window
win.blit(BG_IMG, (0, 0)) #blit ist die Zeichenfunktion
bird.draw(win)
pygame.display.update() #refresht den Display
def main(): #main loop vom Spiel
bird = Bird(200, 200)
win = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT)) #erstellt das Window
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
draw_window(win, bird)
pygame.quit()
quit()
main()
This is the interface with all it's stuff: the file mytry.py is the only thing I changed in that whole thing. The problems that it shows are also in flappy_bird.py showed as problems, but it works there anyway.