Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- 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')
- 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 = (137, self.y, self.width, self.height)
- def draw(self, win):
- win.blit(char, (self.x,self.y))
- self.hitbox = (137, self.y, self.width, self.height)
- pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
- def hit(self):
- print('hit')
- class textbox(object):
- def __init__(self,x,y,width,height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.vel = 10
- self.hitbox = (self.x, self.y, self.width, self.height)
- def draw(self, win):
- 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)
- pygame.display.update()
- #mainloop
- run = True
- article1 = textbox(2000, 100, 100, 50)
- article2 = textbox(2000, 250, 100, 50)
- article3 = textbox(2000, 400, 100, 50)
- article4 = textbox(2000, 550, 100, 50)
- man = player(100, 100, 70, 125)
- 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')
- 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