Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import time
- import os
- X_SCREEN = 600
- Y_SCREEN = 600
- SPEED = 30
- WHITE = (255, 255, 255)
- def prints(text):
- print time.time(), text
- class Window:
- def __init__(self, title="AI game"):
- prints("incoming reckt")
- self.frame = None
- self.clock = pygame.time.Clock()
- self.is_run = True
- self.objects = []
- self.show()
- self.set_title(title)
- self.create("ball.bmp")
- self.game_hendle()
- def create(self, place):
- obj = Object(place)
- self.objects.append(obj)
- prints("object appended to list")
- def show_object(self, obj):
- self.frame.blit(obj.face, obj.position)
- def show(self):
- prints("show the frame")
- self.frame = pygame.display.set_mode((X_SCREEN, Y_SCREEN))
- @staticmethod
- def set_title(title):
- prints(str("the title is " + title))
- pygame.display.set_caption(str(title))
- def game_hendle(self):
- self.frame.fill(WHITE)
- prints("don't warry, i got this")
- print
- while self.is_run:
- for event in pygame.event.get():
- self.events_hendle(event)
- for thing_to_show in self.objects:
- if thing_to_show.is_show:
- self.show_object(thing_to_show)
- pygame.display.update()
- self.clock.tick(30)
- pygame.quit()
- quit()
- def events_hendle(self, event):
- if event.type == pygame.QUIT:
- self.is_run = False
- prints("bby")
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_UP:
- prints("up")
- new_position = self.objects[0].x + SPEED
- print "the new position is " + str(new_position)
- print "the y is " + str(self.objects[0].y)
- self.objects[0].set_position(self.objects[0].y, new_position)
- if event.key == pygame.K_DOWN:
- prints("down")
- new_position = self.objects[0].x - SPEED
- print "the new position is " + str(new_position)
- print "the y is " + str( self.objects[0].y)
- self.objects[0].set_position(self.objects[0].y, new_position)
- class Object:
- def __init__(self, face):
- prints("object was created")
- self.x = X_SCREEN / 2
- self.y = Y_SCREEN / 2
- print "RESET OBJECT PARAMS"
- self.reset_position(self.x, self.y)
- self.face = pygame.image.load(os.path.join(face))
- self.is_show = True
- def reset_position(self, x, y):
- self.position = (x, y)
- def set_position(self, x, y):
- self.x = x
- self.y = y
- prints(str("position resetes to " + str(x) + "," + str(y)))
- self.reset_position(x, y)
- if __name__ == "__main__":
- prints("game starts")
- off = False
- window_frame = Window()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement