Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- pygame.init()
- #Graphics
- win = pygame.display.set_mode((1800, 700))
- pygame.display.set_caption("Jotaro's revenge")
- bg = pygame.image.load('bg.png')
- char = pygame.image.load('ora.png')
- font = pygame.font.SysFont('comicsans', 40, True)
- #Sound
- music = pygame.mixer.music.load('jotaro.mp3')
- pygame.mixer.music.play(-1)
- pygame.mixer.music.set_volume(0.2)
- #classes and definitions
- class player(object):
- def __init__(self, x, y, width, height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.vel = 15
- self.hitbox = (203, self.y, self.width, self.height)
- def draw(self, win):
- win.blit(char, (self.x,self.y))
- self.hitbox = (203, self.y, self.width, self.height)
- pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
- def hit(self):
- print('hit')
- self.score += 50
- class textbox1(object):
- def __init__(self,x,y,width,height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.vel = 6
- self.hitbox = (self.x, self.y, self.width, self.height)
- def draw(self, win):
- text = font.render('the', 1, (255,255,255))
- win.blit(text, (self.x, self.y))
- self.hitbox = (self.x, self.y, self.width, self.height)
- #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
- class textbox2(object):
- def __init__(self,x,y,width,height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.vel = 6
- self.hitbox = (self.x, self.y, self.width, self.height)
- def draw(self, win):
- text = font.render('an', 1, (255,255,255))
- win.blit(text, (self.x, self.y))
- self.hitbox = (self.x, self.y, self.width, self.height)
- #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
- class textbox3(object):
- def __init__(self,x,y,width,height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.vel = 6
- self.hitbox = (self.x, self.y, self.width, self.height)
- def draw(self, win):
- text = font.render('a', 1, (255,255,255))
- win.blit(text, (self.x, self.y))
- self.hitbox = (self.x, self.y, self.width, self.height)
- #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
- class textbox4(object):
- def __init__(self,x,y,width,height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.vel = 6
- self.hitbox = (self.x, self.y, self.width, self.height)
- def draw(self, win):
- text = font.render('No article', 1, (255,255,255))
- win.blit(text, (self.x, self.y))
- self.hitbox = (self.x, self.y, self.width, self.height)
- #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
- class text1(object):
- def __init__(self,x,y,width,height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.hitbox = (self.x, self.y, self.width, self.height)
- def draw(self, win):
- win.blit(text1, (self.x, self.y))
- self.hitbox = (self.x, self.y, self.width, self.height)
- #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
- def drawgamewindow():
- win.blit(bg,(0,0))
- article1.draw(win)
- article2.draw(win)
- article3.draw(win)
- article4.draw(win)
- man.draw(win)
- text2.draw(win)
- pygame.display.update()
- #k6ik vajalik crap
- the = ['... Second World war ended in 1945.','Do you know ... people who live next door','Have you ever visited ... Tower of London ?']
- an = ['I am not ... honorable person',"I am ... hour away", "John is ... abortionist"]
- a = ['You are ... cruel person', "For his birthday, Steven got ... ballpoint pen","I broke ... glass table"]
- empty = ["John himself doesn't go to ... church.",'After ... work Ann usually goes home.','I hate ... violence.']
- laused = [the, an, a, empty]
- run = True
- article1 = textbox1(2000, 100, 1, 50)
- article2 = textbox2(2000, 250, 1, 50)
- article3 = textbox3(2000, 400, 1, 50)
- article4 = textbox4(2000, 550, 1, 50)
- suvaline = random.choice(laused)
- suvaline2 = random.choice(suvaline)
- text2 = text1(100, 50, 100, 50)
- text1 = font.render(random.choice(suvaline2), 1, (255,255,255))
- man = player(100, 100, 5, 125)
- man.score = 0
- #SEESIIN
- #mainloop
- while run:
- pygame.time.delay(20)
- #player movement
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- #artiklite liikumine
- article1.x -= article1.vel
- article2.x -= article2.vel
- article3.x -= article2.vel
- article4.x -= article2.vel
- if article1.y - article1.height < man.hitbox[1] + man.hitbox[3] and article1.y + article1.height > man.hitbox[1]:
- if article1.x + article1.width > man.hitbox[0] and article1.x < man.hitbox[0] + man.hitbox[2]:
- man.hit()
- print('1')
- if article2.y - article2.height < man.hitbox[1] + man.hitbox[3] and article2.y + article2.height > man.hitbox[1]:
- if article2.x + article2.width > man.hitbox[0] and article2.x < man.hitbox[0] + man.hitbox[2]:
- man.hit()
- print('2')
- if article3.y - article3.height < man.hitbox[1] + man.hitbox[3] and article3.y + article3.height > man.hitbox[1]:
- if article3.x + article3.width > man.hitbox[0] and article3.x < man.hitbox[0] + man.hitbox[2]:
- man.hit()
- print('3')
- if article4.y - article4.height < man.hitbox[1] + man.hitbox[3] and article4.y + article4.height > man.hitbox[1]:
- if article4.x + article4.width > man.hitbox[0] and article4.x < man.hitbox[0] + man.hitbox[2]:
- man.hit()
- print('4')
- #player movement
- keys = pygame.key.get_pressed()
- if keys[pygame.K_w] and man.y > man.vel :
- man.y -= man.vel
- if keys[pygame.K_s] and man.y < 700 - man.height - man.vel:
- man.y += man.vel
- drawgamewindow()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement