Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from pygame import *
- import random
- # class Collisions:
- # def __init__(self, bullets1_x, bullets1_y, bullets2_x, bullets2_y):
- # self.bullets1_y = bullets1_y
- # self.bullets2_x = bullets2_x
- # self.bullets1_x = bullets1_x
- # self.bullets2_y = bullets2_y
- # def bul(self, col_check_bul):
- # if abs(self.bullets1_x - self.bullets2_x) < 10 :
- # col_check_bul = 1
- class Platform:
- def __init__(self, x, y, w, h):
- self.x = x
- self.y = y
- self.w = w
- self.h = h
- def draw_platform(self):
- pygame.draw.rect(win,(250,2,145), (self.x, self.y, self.w, self.h))
- class Bullet:
- def __init__(self,x,y,radius,color,facing):
- self.x = x
- self.y = y
- self.radius = radius
- self.color = color
- self.facing = facing
- self.vel = 8 * facing
- def draw(self,win):
- pygame.draw.circle(win,self.color,(self.x,self.y),self.radius)
- class Player:
- def __init__(self, x, y, w, h,speed):
- self.x = x
- self.y = y
- self.w = w
- self.h = h
- self.speed = speed
- self.isJump = False
- self.jumpCount = 10
- self.bullets = []
- self.lastMove ="R"
- self.facing = 1
- def draw_player(self):
- pygame.draw.rect(win,(255,255,255), (self.x, self.y, self.h, self.w))
- def shoot(self):
- for bullet in self.bullets:
- if bullet.x < win_w and bullet.x > 0:
- bullet.x += bullet.vel
- else:
- self.bullets.pop(self.bullets.index(bullet))
- def move_player1(self):
- keys = pygame.key.get_pressed()
- if keys[pygame.K_SPACE]:
- if self.lastMove == "R":
- self.facing = 1
- else:
- self.facing = -1
- if len(self.bullets) < 1:
- self.bullets.append(Bullet(round(self.x +self.w // 2),round(self.y +self.h // 2),5,(255,0,0),self.facing))
- if keys[pygame.K_a] and self.x > 5:
- self.x -= self.speed
- self.lastMove = "L"
- if keys[pygame.K_d] and self.x < win_w - self.w - 5:
- self.x += self.speed
- self.lastMove = "R"
- if not(self.isJump):
- if keys[pygame.K_w] and self.y > 5 :
- self.isJump = True
- if keys[pygame.K_s] and self.y < win_h - self.h - 5:
- self.y += self.speed
- else:
- if self.jumpCount >= -10:
- if self.jumpCount < 0:
- self.y += (self.jumpCount ** 2)/2
- else:
- self.y -= (self.jumpCount ** 2)/2
- self.jumpCount -= 1
- else:
- self.isJump = False
- self.jumpCount = 10
- def move_player2(self):
- keys = pygame.key.get_pressed()
- if keys[pygame.K_z]:
- if self.lastMove == "R":
- self.facing = 1
- else:
- self.facing = -1
- if len(self.bullets) < 1:
- self.bullets.append(Bullet(round(self.x +self.w // 2),round(self.y +self.h // 2),5,(255,0,0),self.facing))
- if keys[pygame.K_LEFT] and self.x > 5:
- self.x -= self.speed
- self.lastMove = "L"
- if keys[pygame.K_RIGHT] and self.x < win_w - self.w - 5:
- self.x += self.speed
- self.lastMove = "R"
- if not(self.isJump):
- if keys[pygame.K_UP] and self.y > 5 :
- self.isJump = True
- if keys[pygame.K_DOWN] and self.y < win_h - self.h - 5:
- self.y += self.speed
- else:
- if self.jumpCount >= -10:
- if self.jumpCount < 0:
- self.y += (self.jumpCount ** 2)/2
- else:
- self.y -= (self.jumpCount ** 2)/2
- self.jumpCount -= 1
- else:
- self.isJump = False
- self.jumpCount = 10
- pygame.init()
- pygame.display.set_caption("Dun")
- player1 = Player(50, 445, 50, 50, 5)
- player2 = Player(450,445, 50, 50, 5)
- platform1 = Platform (0,100,50,50)
- platform2 = Platform (250,100,200,50)
- platform3 = Platform (650,100,50,50)
- platform4 = Platform (100,200,150,50)
- platform5 = Platform (450,200,150,50)
- platform6 = Platform (0,300,50,50)
- platform7 = Platform (650,300,50,50)
- platform8 = Platform (100,400,100,100)
- platform9 = Platform (500,400,100,100)
- platform10 = Platform (300,300,100,400)
- win_w = 700
- win_h = 500
- win = pygame.display.set_mode((win_w,win_h))
- col_check_bul = 0
- start = 1
- game = 2
- death = 3
- winner = 4
- buff = 5
- bos = 6
- state = game
- run = True
- while run:
- pygame.time.delay(20)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- if state == game:
- player1.move_player1()
- player1.shoot()
- player2.move_player2()
- player2.shoot()
- if player1.bullets or player2.bullets:
- col_check_bul = 0
- if player1.bullets and player2.bullets:
- if (abs(player1.bullets[0].x - player2.bullets[0].x ) < 10) and (abs(player1.bullets[0].y - player2.bullets[0].y )< 10):
- col_check_bul = 1
- player1.bullets = []
- player2.bullets =[]
- # if player1.bullets :
- # (abs(player1.bullets[0].x - player2.x)) < 30 and (abs(player1.))
- win.fill((0,0,0))
- platform1.draw_platform()
- platform2.draw_platform()
- platform3.draw_platform()
- platform4.draw_platform()
- platform5.draw_platform()
- platform6.draw_platform()
- platform7.draw_platform()
- platform8.draw_platform()
- platform9.draw_platform()
- platform10.draw_platform()
- player1.draw_player()
- if(col_check_bul == 0):
- for bullet in player1.bullets:
- bullet.draw(win)
- player2.draw_player()
- if(col_check_bul == 0):
- for bullet in player2.bullets:
- bullet.draw(win)
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment