Advertisement
Guest User

Untitled

a guest
Mar 6th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.40 KB | None | 0 0
  1. import pygame # Import library of functions called 'pygame'
  2. from pygame.time import Clock
  3. import random
  4. import time
  5. import itertools
  6. import pygame, os
  7. os.environ['SDL_VIDEO_CENTERED'] = '1'
  8.  
  9. class Digimon(pygame.sprite.Sprite):
  10.     def __init__(self,age,weight,strength,defence,speed,intelligence):
  11.         pygame.sprite.Sprite.__init__(self)
  12.         self.age = age  
  13.         self.weight = weight    
  14.         self.strength = strength
  15.         self.defence = defence  
  16.         self.speed = speed  
  17.         self.intelligence = intelligence
  18.        
  19. ############################ PLAYER OBJECT ##############################
  20. Player = Digimon(0,2,0,0,0,0)
  21.  
  22. # Player_sprites = itertools.cycle(Player.image) # cycles through the player (in this case - Egg - images)
  23.  
  24. ############################ EGG OBJECT #################################
  25. Egg = Digimon(0,2,0,0,0,0)
  26. Egg_idle = [pygame.image.load("images/egg_1.png"), pygame.image.load("images/egg_2.png"), pygame.image.load("images/egg_3.png") ]
  27.  
  28. Egg_sprites = itertools.cycle(Egg_idle) # cycles through egg images
  29.  
  30. ############################ KOROMON OBJECT ##############################
  31.  
  32. Koromon_idle = [pygame.image.load("images/koro_1.png"), pygame.image.load("images/koro_2.png"), pygame.image.load("images/koro_3.png"), pygame.image.load("images/koro_4.png"), pygame.image.load("images/koro_5.png"), pygame.image.load("images/koro_6.png"), pygame.image.load("images/koro_7.png"), pygame.image.load("images/koro_8.png"), pygame.image.load("images/koro_9.png"), pygame.image.load("images/koro_10.png")]
  33.  
  34. Koromon_sprites = itertools.cycle(Koromon_idle) # cycles through egg images
  35.  
  36. ############################ BEAM OBJECT ##############################
  37.  
  38. Digivolve_beam =[ pygame.image.load("images/beam.png"), pygame.image.load("images/beam-1.png"), pygame.image.load("images/beam-2.png"), pygame.image.load("images/beam-3.png"), pygame.image.load("images/beam-4.png"), pygame.image.load("images/beam-5.png"), pygame.image.load("images/beam-6.png"), pygame.image.load("images/beam-7.png"), pygame.image.load("images/beam-8.png"), pygame.image.load("images/beam-9.png"), pygame.image.load("images/beam-10.png"), pygame.image.load("images/beam-11.png"), pygame.image.load("images/beam-12.png"), pygame.image.load("images/beam-13.png"), pygame.image.load("images/beam-14.png") ]
  39.  
  40. Digivolve_sprites = itertools.cycle(Digivolve_beam)
  41.  
  42. ############################ INITIALISE GAME ENGINE ##############################
  43. pygame.init()
  44.  
  45. [screen_width, screen_height] = [400,150]
  46. screen = pygame.display.set_mode([screen_width,screen_height])
  47. screen.set_colorkey((255, 0 ,255))
  48.  
  49. pygame.display.set_caption("Digimon Simulator 1")
  50.  
  51. black = (  0,  0,  0) # defines colours for ease of use
  52. white = (255,255,255)
  53.  
  54. clock = pygame.time.Clock() # controls how fast the game runs
  55.  
  56. font = pygame.font.Font(None, 15)
  57.  
  58. Digivolve_Koromon = 0
  59.  
  60. game_over = 0
  61.  
  62. x_pos = 160
  63. y_pos = 100
  64.  
  65. Age_timer = 0
  66.  
  67. ############################ FRAME RATE #################################
  68. update_normal = 5
  69. update_main = 50.0
  70. #########################################################################
  71.  
  72. done = False # loop control
  73. t = time.time() # gets the time.
  74.  
  75. draw_egg=False
  76. draw_Koromon=False
  77. draw_Digivolve=False
  78.  
  79. ############################ Main Program Loop #################################
  80. while not done:
  81.     clock.tick(update_main) # loops game at 50
  82.    
  83. ############################ ALL EVENT PROCESSING SHOULD GO BELOW THIS COMMENT #################################
  84.     for event in pygame.event.get():    # User did something
  85.         if event.type == pygame.QUIT: # If user clicked close
  86.             done = True # exits the loop
  87.         if event.type == pygame.MOUSEBUTTONDOWN:
  88.             x,y = event.pos # gets the x, y position of the mouse click
  89.             if ( x  in range(150,170)) and ( y in range(10,30)): # if in range, add age +1 to player
  90.                 Player.age += 1
  91.         if event.type == pygame.MOUSEBUTTONDOWN:
  92.             x,y = event.pos # gets the x, y position of the mouse click
  93.             if ( x  in range(175,195)) and ( y in range(10,30)): # if in range, add age +1 to player
  94.                 Player.weight += 1
  95.         if event.type == pygame.MOUSEBUTTONDOWN:
  96.             x,y = event.pos # gets the x, y position of the mouse click
  97.             if ( x  in range(200,220)) and ( y in range(10,30)): # if in range, add age +1 to player
  98.                 Player.strength += 1
  99.         if event.type == pygame.MOUSEBUTTONDOWN:
  100.             x,y = event.pos # gets the x, y position of the mouse click
  101.             if ( x  in range(225,245)) and ( y in range(10,30)): # if in range, add age +1 to player
  102.                 Player.defence += 1
  103.         if event.type == pygame.MOUSEBUTTONDOWN:
  104.             x,y = event.pos # gets the x, y position of the mouse click
  105.             if ( x  in range(250,275)) and ( y in range(10,30)): # if in range, add age +1 to player
  106.                 Player.speed += 1
  107.         if event.type == pygame.MOUSEBUTTONDOWN:
  108.             x,y = event.pos # gets the x, y position of the mouse click
  109.             if ( x  in range(275,295)) and ( y in range(10,30)): # if in range, add age +1 to player
  110.                 Player.intelligence += 1
  111.  
  112. ############################ ALL EVENT PROCESSING SHOULD GO ABOVE THIS COMMENT #################################
  113.     screen.fill((white))
  114.  
  115. ############################ ALL HERE IS FRAME RATE 5 #################################
  116.  
  117.     if time.time() - t >= (1.0 / update_normal): # if new time - old time is more than 0.2 (1/5)
  118.         t = time.time()
  119.         Egg_sprites_next = Egg_sprites.next() # sets it up to cycle through Egg images
  120.         Koromon_sprites_next = Koromon_sprites.next() # sets it up to cycle through Koromon images
  121.         Age_timer += 0.001
  122.    
  123.         n = random.randint (0,1000)
  124.        
  125.         if n < 100:
  126.             x_pos -= 1
  127.        
  128.             print "n is less than 100"
  129.            
  130.         elif n > 900:
  131.             x_pos += 1
  132.             print "n is more than 950"
  133.        
  134.    
  135.         elif x_pos >= 340 or x_pos <= 0:
  136.             x_pos *= -1
  137.        
  138.         if Player.age == 0 and Player.strength == 0 and Player.defence == 0 and Player.speed == 0 and Player.intelligence == 0:
  139.             draw_egg = True # draws Egg (refer to below for the command)
  140.             draw_Koromon = False  
  141.  
  142.         if Player.age <= 2 and Player.strength == 5:
  143.         # and Player.defence == 5 and Player.speed == 5 and Player.intelligence == 5:
  144.             # draw_egg = False # draws Egg (refer to below for the command)    
  145.             Digivolve_sprites_next = Digivolve_sprites.next()
  146.             draw_Digivolve = True # I want this to run faster
  147.                
  148.             draw_egg = False
  149.            
  150.             draw_Koromon = False
  151.  
  152.         if Age_timer == 10:
  153.             Player.age += 1
  154.             Age_timer = 0      
  155.            
  156.         elif Player.age == 12:
  157.             game_over += 1
  158.             if game_over == 1:
  159.                 print "Game over"
  160.         else:
  161.             pass
  162.            
  163. ############################ ALL HERE IS FRAME RATE 25 (it's in the main loop which is set at 25)#################################
  164.  
  165.        
  166.  
  167.    
  168.     # Beam_sprites_next = Beam_sprites.next() # sets it up to cycle through Beam images
  169.     #if digivolve == 1: # if Player.age = 1
  170.     #   draw_egg = False
  171.     #   draw_Koromon = False # draws Koromon (refer to below for the command)
  172.     #   draw_beam = True
  173.        
  174. ############################ ALL GAME LOGIC SHOULD GO ABOVE THIS COMMENT #################################
  175.  
  176. ############################ ALL CODE TO DRAW SHOULD GO BELOW THIS COMMENT #################################
  177.     Age_button = pygame.draw.rect(screen, black, [150,10, 20,20], 0) # [x,y top left point, width, height], how wide the line around the rectangle is. If 0, rect is filled.
  178.    
  179.     Weight_button = pygame.draw.rect(screen, black, [175,10, 20,20], 0) # [x,y top left point, width, height], how wide the line around the rectangle is. If 0, rect is filled.
  180.    
  181.     Strength_button = pygame.draw.rect(screen, black, [200,10, 20,20], 0) # [x,y top left point, width, height], how wide the line around the rectangle is. If 0, rect is filled.
  182.    
  183.     Defence_button = pygame.draw.rect(screen, black, [225,10, 20,20], 0) # [x,y top left point, width, height], how wide the line around the rectangle is. If 0, rect is filled.
  184.    
  185.     Speed_button = pygame.draw.rect(screen, black, [250,10, 20,20], 0) # [x,y top left point, width, height], how wide the line around the rectangle is. If 0, rect is filled.
  186.    
  187.     Intelligence_button = pygame.draw.rect(screen, black, [275,10, 20,20], 0) # [x,y top left point, width, height], how wide the line around the rectangle is. If 0, rect is filled.
  188.    
  189.     if draw_egg:
  190.         screen.blit((Egg_sprites_next), (189, 119))
  191.    
  192.     if draw_Koromon:
  193.         screen.blit((Koromon_sprites_next), (x_pos,y_pos))
  194.        
  195.     if draw_Digivolve:
  196.         screen.blit((Digivolve_sprites_next), (x_pos,y_pos))
  197.    
  198.     else:
  199.         pass
  200.        
  201.     Player_age_text    = font.render("Player Age " + str(Player.age), True, black) # font uses the font fuction above, (what to draw, anti-alias, colour)
  202.     Player_weight_text = font.render("Player Weight " + str(Player.weight), True, black)
  203.     Player_strength_text = font.render("Player Strength " + str(Player.strength), True, black)
  204.     Player_defence_text = font.render("Player Defence " + str(Player.defence), True, black)
  205.     Player_speed_text = font.render("Player Speed " + str(Player.speed), True, black)
  206.     Player_intelligence_text = font.render("Player Intelligence " + str(Player.intelligence), True, black)
  207.     Age_timer_text = font.render("Age_timer " + str(Age_timer), True, black)
  208.    
  209.     screen.blit(Player_age_text, [10, 10])
  210.     screen.blit(Player_weight_text, [10, 20])
  211.     screen.blit(Player_strength_text, [10, 30])
  212.     screen.blit(Player_defence_text, [10, 40])
  213.     screen.blit(Player_speed_text, [10, 50])
  214.     screen.blit(Player_intelligence_text, [10, 60])
  215.     screen.blit(Age_timer_text, [10, 70])
  216.    
  217.     pygame.display.flip() # shows screen fill.
  218.    
  219.     # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT
  220.      
  221. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement