I've started programming python but Education videos didn't help me for learning and remembering python command. That's why my friend gave a piece of advice about developing a Mario game.
I can learn easier like that and I can understand programming dialectic easier than my old method. My plan is creating an automatic self-play Mario than I will show this program with a led screen. Maybe I will use raspberry pi or Arduino. I don't know yet. I will create barriers and Mario is going to pass automatically all barriers.
import pygame, sys import maryolib pygame.init() # Ekranimizi olusturuyoruzDISPLAY_X = 1000
DISPLAY_Y = 800
main_display = pygame.display.set_mode((DISPLAY_X, DISPLAY_Y), 0, 32) pygame.display.set_caption("Project-Maryo") # Oyunun kac fps'de calisacagini ayarlayacagizclock = pygame.time.Clock() FPS = 60 # RGB renk tanimlamalarimizBLACK = (0, 0, 0) GREEN = (0, 255, 0) WHITE = (255, 255, 255) BLUE = (0, 0, 255) RED = (255, 0, 0) #Jump enter codejumpCount = 10# Beyaz rengi arka plana uygula
main_display.fill(WHITE) # Ekranda gorulecek grafiksel objeleri bu listede tutacagiz
graph_list = pygame.sprite.Group() # Yeni bir grafik olusturuyoruz
maryo = maryolib.MaryoImageObject(35, 50, "maryo.png")maryo.move_to(50, 100)# Grafigin konumunu degistir
graph_list.add(maryo)# yeni grafigimizi listeye ekliyoruz # Duvar olusturuyoruzwall = maryolib.MaryoImageObject(DISPLAY_Y-50, 50, "wall.png")wall.move_to(0, DISPLAY_Y-50)# Grafigin konumunu degistir
graph_list.add(wall)
# yeni grafigimizi listeye ekliyoruz # Programin ana dongusu burasiwhile True: # Event demek bir tusa basilmasi vs. demek. Eventler pygame.event.get()# fonksiyonunun dondurdugu listede birikiyor. Bunlari tek tek isliyoruz.for event in pygame.event.get():# Eger pencere kapatilmissa asagiyi calistirif event.type == pygame.QUIT: pygame.quit() sys.exit() # Bir tusa basilirsa asagiyi caltirif event.type == pygame.KEYDOWN: # Eger basilan tus esc ise bunu yapif event.key == pygame.K_ESCAPE: pygame.quit() sys.exit() # Eger basilan tus "space" tusu ise bunu yapelif event.key == pygame.K_SPACE: print("Space tusuna basildi.") # Event'taki kisim, butona bastiginiz an 1 kere calisir. Asagidaki kisim# butona basili tuttugunuz surece calisir. keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: print("Sol ok tusuna basili tutuluyor.") maryo.move_left(5) # 5 pixel saga hareket et if keys[pygame.K_RIGHT]: print("Sag ok tusuna basili tutuluyor.") # Temas algilama kismini burada yapiyoruz. Eger maryo ve wall temas etmiyorsa# saga gitmeye izin ver. Yoksa saga gitme.maryo.move_right(5)
# 5 pixel saga hareket et if keys[pygame.K_UP]: print("Yukarı yonde calistirildi.") if not pygame.sprite.collide_rect(maryo, wall): maryo.move_up(5) if keys[pygame.K_DOWN]: print("Asagi yonde calistirildi.") if not pygame.sprite.collide_rect(maryo, wall): maryo.move_down(5) if keys[pygame.K_SPACE]: print("Zıplama.") maryo.down_speed = -20 maryo.move_down(maryo.down_speed) maryo.down_speed += 5 if not pygame.sprite.collide_rect(maryo, wall): maryo.down_speed = 0 if not pygame.sprite.collide_rect(maryo, wall): maryo.move_down(10) # Onceki ekrani tamamen temizle main_display.fill(WHITE) # Yukaridaki degisiklikleri ekrana yansitmak icin asagidaki kodlari girmeliyizgraph_list.draw(main_display) pygame.display.update() # Belli bir sure bekleyecegiz clock.tick(FPS)
REFERENCE => FURKAN TOKAÇ https://furkantokac.com/project-maryo-rehber-v01/