G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 10th, 2020 149 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame, sys, os, random, time
  2.  
  3. pygame.init()
  4. clock = pygame.time.Clock()
  5.  
  6. SCREEN_WIDTH = 414
  7. SCREEN_HEIGHT = 736
  8. WHITE = (255, 255, 255)
  9. RED = (255, 0, 0)
  10. COLORS = [WHITE, RED]
  11. FPS = 60
  12.  
  13. class Timer:
  14.   def __init__(self, countdown, start=True):
  15.     self.countdown = countdown
  16.     if start:
  17.       self.start_timer()
  18.  
  19.   def start_timer(self):
  20.     self.current_time = pygame.time.get_ticks()
  21.     self.last_update = pygame.time.get_ticks()
  22.  
  23.   def check_time(self):
  24.     self.current_time = pygame.time.get_ticks()
  25.     if self.current_time - self.last_update > self.countdown:
  26.       self.last_update = self.current_time
  27.       return True
  28.     else:
  29.       return False
  30.  
  31.   def get_percentage(self):
  32.     return (self.current_time - self.last_update) / self.countdown
  33.  
  34. class Player_Shot:
  35.   def __init__(self, screen, x, y):
  36.     self.screen = screen
  37.     self.x  = x
  38.     self.y = y
  39.     #self.image = pygame.draw.circle(screen, BLACK, (self.x, self.y), 80, 1)
  40.  
  41.   def update(self):
  42.     self.y -= 10
  43.     pygame.draw.circle(self.screen, WHITE, (self.x, self.y), 10, 10)
  44.  
  45.  
  46.   def shoot(self):
  47.     pygame.draw.circle(self.screen, WHITE, (self.x, self.y), 10)
  48.  
  49. class Player:
  50.   def __init__(self, screen):
  51.     self.screen = screen
  52.     self.image = pygame.image.load(os.path.join('graphics', 'player.png'))
  53.     self.x = 300
  54.     self.y = 300
  55.     self.shots = []
  56.     self.shooting_timer = Timer(250)
  57.  
  58.   def create_shot(self):
  59.     if self.shooting_timer.check_time():
  60.       s = Player_Shot(self.screen, self.x, self.y)
  61.       self.shots.append(s)
  62.  
  63.   def update_shots(self):
  64.     for f in self.shots:
  65.       f.update()
  66.  
  67.   def get_input(self):
  68.     key = pygame.key.get_pressed()
  69.     if key[pygame.K_LEFT]:
  70.       self.x -= 5
  71.     if key[pygame.K_RIGHT]:
  72.         self.x += 5
  73.     if key[pygame.K_UP]:
  74.       self.y -= 5
  75.     if key[pygame.K_DOWN]:
  76.         self.y += 5
  77.  
  78.   def run(self):
  79.     self.image = pygame.transform.scale(self.image, (100, 100))
  80.     self.create_shot()
  81.     self.update_shots()
  82.     self.screen.blit(self.image, (self.x, self.y))
  83.  
  84. class Level_1:
  85.   def __init__(self, screen):
  86.     self.screen = screen
  87.     self.p1 = Player(self.screen)
  88.  
  89.   def get_input(self):
  90.     for event in pygame.event.get():
  91.         if event.type == pygame.QUIT:
  92.             pygame.quit()
  93.             sys.exit()
  94.  
  95.   def run(self):
  96.     while True:
  97.       self.get_input()
  98.       self.p1.get_input()
  99.       self.screen.fill((0,0,0))
  100.       self.p1.run()
  101.       pygame.display.update()
  102.       clock.tick(60)
  103.  
  104. class Start_Screen:
  105.   def __init__(self, screen):
  106.     self.screen = screen
  107.     self.loop = 1
  108.     self.faces = []
  109.     self.start_button_size = (200,100)
  110.     self.start_button_pos = (100,300)
  111.     self.start_button_color = (152,24,68)
  112.     self.start_button_rect = pygame.Rect(100, 300, 200, 100)
  113.     self.start_button_sound = pygame.mixer.Sound(os.path.join('sounds', 'start.wav'))
  114.     self.level_1 = Level_1(self.screen)
  115.     self.start_screen_image = pygame.image.load(os.path.join('graphics', 'start_screen.png'))
  116.     self.title_font = pygame.font.Font("fonts/joystix_monospace.ttf", 24)
  117.     self.title_text = self.title_font.render('KAMPUNGAN KRUSHER', True, (255, 255, 255))
  118.     self.title_text_rect = self.title_text.get_rect()
  119.     self.title_text_x = self.screen.get_rect().centerx - (self.title_text.get_width() /2)
  120.     self.title_text_y = 450
  121.     self.start_text_font = pygame.font.Font("fonts/joystix_monospace.ttf", 20)
  122.     self.start_text = self.start_text_font.render('- TAP TO START -', True, (255, 255, 255))
  123.     self.start_text_rect = self.start_text.get_rect()
  124.     self.start_text_x = self.screen.get_rect().centerx - (self.start_text.get_width() /2)
  125.     self.start_text_y = (SCREEN_HEIGHT -  self.start_text.get_height()) - 200
  126.     self.start_text_color = COLORS[0]
  127.     self.start_text_color_timer = 0.05 * FPS
  128.     self.developer_text_font = pygame.font.Font("fonts/joystix_monospace.ttf", 14)
  129.     self.developer_text = self.developer_text_font.render('CREATED BY HOMEMADEPIZZA', True, (255, 255, 255))
  130.     self.developer_text_rect = self.developer_text.get_rect()
  131.     self.developer_text_x = self.screen.get_rect().centerx - (self.developer_text.get_width() /2)
  132.     self.developer_text_y = (SCREEN_HEIGHT -  self.developer_text.get_height()) - 50
  133.  
  134.  
  135.   def get_input(self):
  136.     for event in pygame.event.get():
  137.         if event.type == pygame.QUIT:
  138.             pygame.quit()
  139.             sys.exit()
  140.         if event.type == pygame.MOUSEBUTTONUP:
  141.           mouse_pos = pygame.mouse.get_pos()
  142.           print(mouse_pos)
  143.           self.level_1.run()
  144.           # if self.start_button_rect.collidepoint(mouse_pos):
  145.           #   print("start button tapped")
  146.           #   self.start_button_sound.play()
  147.           #   self.loop = 0
  148.           #   self.level_1.run()
  149.  
  150.   def update_text_color(self):
  151.     if self.start_text_color == COLORS[0]:
  152.       self.start_text_color = COLORS[1]
  153.       self.start_text = self.start_text_font.render('- TAP TO START -', True, self.start_text_color)
  154.     else:
  155.       self.start_text_color = COLORS[0]
  156.       self.start_text = self.start_text_font.render('- TAP TO START -', True, self.start_text_color)
  157.  
  158.   def update_faces(self):
  159.       for f in self.faces:
  160.           if f.y > 600:
  161.               self.faces.remove(f)
  162.           f.update()            
  163.  
  164.   def run(self):
  165.     clock = pygame.time.Clock()
  166.     while self.loop == 1:
  167.       self.get_input()
  168.       self.screen.fill((0,0,0))
  169.       self.start_text_color_timer -= 1
  170.       if self.start_text_color_timer <= 0:
  171.         self.update_text_color()
  172.         self.start_text_color_timer = 0.05 * FPS
  173.       self.screen.blit(self.start_screen_image, (0, 0))
  174.       self.screen.blit(self.title_text, (self.title_text_x, self.title_text_y))
  175.       self.screen.blit(self.start_text, (self.start_text_x, self.start_text_y))
  176.       self.screen.blit(self.developer_text, (self.developer_text_x, self.developer_text_y))
  177.       #pygame.draw.rect(self.screen, self.start_button_color, pygame.Rect(self.start_button_pos, self.start_button_size))
  178.       pygame.display.update()
  179.       clock.tick(60)
  180.  
  181. class Setup:
  182.   def __init__(self):
  183.     self.resolution = (SCREEN_WIDTH, SCREEN_HEIGHT)
  184.     self.screen = pygame.display.set_mode(self.resolution, 0, 32)
  185.     #self.screen = pygame.display.set_mode(self.resolution, pygame.SCALED | pygame.FULLSCREEN)
  186.     self.window_title = pygame.display.set_caption("Kampungan Krusher")
  187.     self.start_screen = Start_Screen(self.screen);
  188.     #self.screen = pygame.display.set_mode(self.resolution, 0, 32)
  189.  
  190.   def run(self):
  191.     self.start_screen.run()
  192.  
  193. game = Setup()
  194. game.run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top