NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#Kütüphane
import pygame,random
#Pygame yükleme
pygame.init()
#Pencere Ayarları
genislik,yukseklik=1280,720
pencere=pygame.display.set_mode((genislik,yukseklik))
pygame.display.set_caption('Tenis Beta')
icon1=pygame.image.load("images/tennis1.png")
pygame.display.set_icon(icon1)
#FPS işlemleri
fps=30
saat=pygame.time.Clock()
#Sınıflar
class Oyun():
def __init__(self,oyuncu1,oyuncu2,top_grup):
#Parametre Değişkenleri
self.oyuncu1=oyuncu1
self.oyuncu2=oyuncu2
self.top_grup=top_grup
#Resimler
self.arka_plan=pygame.image.load("images/back.jpg")
self.oyun_bitti=pygame.image.load("images/oyunbitti.png")
#Oyun Değişkenleri
self.oyuncu1_puan=0
self.oyuncu2_puan=0
self.puan=1
self.sayac=30
self.fps_sayac=0
#Yazı Tipi
self.oyun_font=pygame.font.Font("images/comic.ttf",40)
#Sesler
self.kenar_ses=pygame.mixer.Sound("sounds/tick.wav")
self.carpisma_sesi=pygame.mixer.Sound("sounds/pong.wav")
self.tepealt_ses=pygame.mixer.Sound("sounds/tick2.wav")
pygame.mixer.music.load("sounds/back1.mp3")
pygame.mixer.music.play(-1)

def update(self):
self.fps_sayac+=1
if self.fps_sayac==fps:
self.sayac-=1
self.fps_sayac=0
if self.sayac==0:
self.bitir()
self.temas()
self.oyun_durum()
def cizdir(self):
pencere.blit(self.arka_plan,(0,0))

puan1=self.oyun_font.render("1.Oyuncu:"+str(self.oyuncu1_puan),True,(0,0,255))
puan1_konum=puan1.get_rect()
puan1_konum.topleft=(20,1)

puan2=self.oyun_font.render("2.Oyuncu:"+str(self.oyuncu2_puan),True,(0,255,0))
puan2_konum=puan2.get_rect()
puan2_konum.topleft=(genislik-260,1)

sayac_yazi=self.oyun_font.render("Süre:"+str(self.sayac),True,(255,0,0))
sayac_yazi_konum=sayac_yazi.get_rect()
sayac_yazi_konum.topleft=(genislik//2-110,1)

pencere.blit(puan1,puan1_konum)
pencere.blit(puan2,puan2_konum)
pencere.blit(sayac_yazi,sayac_yazi_konum)
def temas(self):
if pygame.sprite.spritecollide(self.oyuncu1,self.top_grup,False):
self.carpisma_sesi.play()
for top in self.top_grup.sprites():
top.yonx*=-1
if top.hiz<=15:
top.hiz+=1

if pygame.sprite.spritecollide(self.oyuncu2,self.top_grup,False):
self.carpisma_sesi.play()
for top in self.top_grup.sprites():
top.yonx*=-1
if top.hiz<=15:
top.hiz+=1

def oyun_durum(self):
for top in self.top_grup.sprites():
if top.rect.left<=0:
self.kenar_ses.play()
self.oyuncu2_puan+=self.puan

if top.rect.right>=genislik:
self.kenar_ses.play()
self.oyuncu1_puan+=self.puan

if top.rect.top<=50:
self.tepealt_ses.play()

if top.rect.bottom>=yukseklik:
self.tepealt_ses.play()
def bitir(self):
bittimi=True
global durum
pencere.blit(self.oyun_bitti,(0,0))
a="1.Oyuncu Kazandı!"
b="2.Oyuncu Kazandı!"
c="Dostluk Kazandı!"
if self.oyuncu1_puan>self.oyuncu2_puan:
kazanan=self.oyun_font.render(a,True,(0,50,100))
kazanan_konum=kazanan.get_rect()
kazanan_konum.topleft=(genislik//2-150,yukseklik//2)
if self.oyuncu2_puan>self.oyuncu1_puan:
kazanan=self.oyun_font.render(b,True,(0,50,100))
kazanan_konum=kazanan.get_rect()
kazanan_konum.topleft=(genislik//2-150,yukseklik//2)
if self.oyuncu1_puan==self.oyuncu2_puan:
kazanan=self.oyun_font.render(c,True,(0,50,100))
kazanan_konum=kazanan.get_rect()
kazanan_konum.topleft=(genislik//2-150,yukseklik//2)
pencere.blit(kazanan,kazanan_konum)
pygame.display.update()
while bittimi:
for etkinlik in pygame.event.get():
if etkinlik.type==pygame.KEYDOWN:
if etkinlik.key==pygame.K_RETURN:
self.oyun_reset()
bittimi=False
if etkinlik.type==pygame.QUIT:
bittimi=False
durum=False
def oyun_reset(self):
self.oyuncu1_puan=0
self.oyuncu2_puan=0
self.sayac=30

class Oyuncu1(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image=pygame.image.load("images/bar1.png")
self.rect=self.image.get_rect()
self.rect.x=32
self.rect.y=50
#Oyuncu Değişken
self.hiz=10

def update(self):
tus=pygame.key.get_pressed()
if tus[pygame.K_w] and self.rect.top>=50:
self.rect.y-=self.hiz
elif tus[pygame.K_s] and self.rect.bottom<=yukseklik:
self.rect.y+=self.hiz

class Oyuncu2(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image=pygame.image.load("images/bar2.png")
self.rect=self.image.get_rect()
self.rect.x=genislik-64
self.rect.y=50

#Oyuncu Değişken
self.hiz=10
def update(self):
tus=pygame.key.get_pressed()
if tus[pygame.K_UP] and self.rect.top>=50:
self.rect.y-=self.hiz
elif tus[pygame.K_DOWN] and self.rect.bottom<=yukseklik:
self.rect.y+=self.hiz
class Top(pygame.sprite.Sprite):
def __init__(self,x,y):
super().__init__()
self.image=pygame.image.load("images/tennis1.png")
self.rect=self.image.get_rect()
self.rect.centerx=x
self.rect.centery=y
#Top Değişkenleri
self.yonx=1
self.yony=1
self.hiz=12
def update(self):
self.rect.centerx+=self.hiz*self.yonx
self.rect.centery+=self.hiz*self.yony
if self.rect.left<=0 or self.rect.right>=genislik:
self.yonx*=-1
if self.rect.top<=50 or self.rect.bottom>=yukseklik:
self.yony*=-1

#1. Oyuncu İşlemleri
oyuncu1_grup=pygame.sprite.Group()
oyuncu1=Oyuncu1()
oyuncu1_grup.add(oyuncu1)
#2. Oyuncu İşlemleri
oyuncu2_grup=pygame.sprite.Group()
oyuncu2=Oyuncu2()
oyuncu2_grup.add(oyuncu2)
#Top İşlemleri
top_grup=pygame.sprite.Group()
top=Top(random.randint(200,1000),random.randint(300,yukseklik-32))
top_grup.add(top)

#Oyun Sınıfı
oyun=Oyun(oyuncu1,oyuncu2,top_grup)
#Oyun Döngüsü
durum=True
while durum:
for etkinlik in pygame.event.get():
if etkinlik.type==pygame.QUIT:
durum=False
#Oyun İşlem
oyun.update()
oyun.cizdir()
#1.Oyuncu İşlem
oyuncu1_grup.update()
oyuncu1_grup.draw(pencere)
#2.Oyuncu İşlem
oyuncu2_grup.update()
oyuncu2_grup.draw(pencere)
#Top İşlem
top_grup.update()
top_grup.draw(pencere)
pygame.display.update()
saat.tick(fps)
pygame.quit()
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.