Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.94 KB | None | 0 0
  1. import pygame
  2. import time
  3. import os
  4. X_SCREEN = 600
  5. Y_SCREEN = 600
  6. SPEED = 30
  7. WHITE = (255, 255, 255)
  8.  
  9.  
  10. def prints(text):
  11.     print time.time(), text
  12.  
  13.  
  14. class Window:
  15.     def __init__(self, title="AI game"):
  16.         prints("incoming reckt")
  17.         self.frame = None
  18.         self.clock = pygame.time.Clock()
  19.         self.is_run = True
  20.         self.objects = []
  21.  
  22.         self.show()
  23.         self.set_title(title)
  24.         self.create("ball.bmp")
  25.         self.game_hendle()
  26.  
  27.     def create(self, place):
  28.         obj = Object(place)
  29.         self.objects.append(obj)
  30.         prints("object appended to list")
  31.  
  32.     def show_object(self, obj):
  33.         self.frame.blit(obj.face, obj.position)
  34.  
  35.     def show(self):
  36.         prints("show the frame")
  37.         self.frame = pygame.display.set_mode((X_SCREEN, Y_SCREEN))
  38.  
  39.     @staticmethod
  40.     def set_title(title):
  41.         prints(str("the title is " + title))
  42.         pygame.display.set_caption(str(title))
  43.  
  44.     def game_hendle(self):
  45.         self.frame.fill(WHITE)
  46.         prints("don't warry, i got this")
  47.         print
  48.         while self.is_run:
  49.             for event in pygame.event.get():
  50.                 self.events_hendle(event)
  51.             for thing_to_show in self.objects:
  52.                 if thing_to_show.is_show:
  53.                     self.show_object(thing_to_show)
  54.             pygame.display.update()
  55.             self.clock.tick(30)
  56.         pygame.quit()
  57.         quit()
  58.  
  59.     def events_hendle(self, event):
  60.         if event.type == pygame.QUIT:
  61.             self.is_run = False
  62.             prints("bby")
  63.         if event.type == pygame.KEYDOWN:
  64.             if event.key == pygame.K_UP:
  65.                 prints("up")
  66.                 new_position = self.objects[0].x + SPEED
  67.                 print "the new position is " + str(new_position)
  68.                 print "the y is " + str(self.objects[0].y)
  69.  
  70.                 self.objects[0].set_position(self.objects[0].y, new_position)
  71.             if event.key == pygame.K_DOWN:
  72.                 prints("down")
  73.                 new_position = self.objects[0].x - SPEED
  74.                 print "the new position is " + str(new_position)
  75.                 print "the y is " + str( self.objects[0].y)
  76.                 self.objects[0].set_position(self.objects[0].y, new_position)
  77.  
  78.  
  79. class Object:
  80.     def __init__(self, face):
  81.         prints("object was created")
  82.         self.x = X_SCREEN / 2
  83.         self.y = Y_SCREEN / 2
  84.         print "RESET OBJECT PARAMS"
  85.         self.reset_position(self.x, self.y)
  86.         self.face = pygame.image.load(os.path.join(face))
  87.  
  88.         self.is_show = True
  89.  
  90.     def reset_position(self, x, y):
  91.         self.position = (x, y)
  92.  
  93.     def set_position(self, x, y):
  94.         self.x = x
  95.         self.y = y
  96.         prints(str("position resetes to " + str(x) + "," + str(y)))
  97.         self.reset_position(x, y)
  98.  
  99.  
  100. if __name__ == "__main__":
  101.     prints("game starts")
  102.     off = False
  103.     window_frame = Window()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement