Guest User

Untitled

a guest
Apr 3rd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. from pygame.time import Clock
  2. import random
  3. import time
  4. import itertools
  5. import pygame
  6. import os, sys
  7. os.environ['SDL_VIDEO_CENTERED'] = '1'
  8. # os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (1000,100)
  9. import glob
  10. from ctypes import windll, Structure, c_long, byref #windows only
  11.  
  12.  
  13. class RECT(Structure):
  14. _fields_ = [
  15. ('left', c_long),
  16. ('top', c_long),
  17. ('right', c_long),
  18. ('bottom', c_long),
  19. ]
  20. def width(self): return self.right - self.left
  21. def height(self): return self.bottom - self.top
  22.  
  23.  
  24. def onTop(window):
  25. SetWindowPos = windll.user32.SetWindowPos
  26. GetWindowRect = windll.user32.GetWindowRect
  27. rc = RECT()
  28. GetWindowRect(window, byref(rc))
  29. SetWindowPos(window, -1, rc.left, rc.top, 0, 0, 0x0001)
  30.  
  31.  
  32.  
  33. ## CLASSES ----------------------------------------------
  34.  
  35. class Digimon(object):
  36. def __init__(self,age ,weight,strength,defence,speed,intelligence):
  37. self.age = age
  38. self.weight = weight
  39. self.strength = strength
  40. self.defence = defence
  41. self.speed = speed
  42. self.intelligence = intelligence
  43.  
  44. Player = Digimon(0,0,0,0,0,0)
  45.  
  46. ## Egg -----------------------------------------------
  47.  
  48. Egg = Digimon(0,0,0,0,0,0)
  49.  
  50. ## In training I -----------------------------------------------
  51. Botamon = Digimon(0,2,1,0,0,0)
  52. Ketomon = Digimon(0,2,1,0,0,0)
  53. Kuamon = Digimon(0,2,0,1,0,0)
  54. Poyomon = Digimon(0,2,0,0,0,1)
  55. Punimon = Digimon(0,2,0,0,1,0)
  56.  
  57. ## In training II ----------------------------------------------
  58.  
  59. ## Rookie ------------------------------------------------------
  60. #Agumon
  61. #Gabumon
  62. Elecmon = Digimon(4,5,5,3,4,4)
  63. #Patamon
  64. #Wormmon
  65. #Veemon
  66. Terriermon = Digimon(4,4,3,3,5,4)
  67. Keramon = Digimon(4,3,6,2,2,6)
  68.  
  69.  
  70. ## Ultimate ----------------------------------------------------
  71. Pumpkinmon = Digimon(12,8,12,8,6,8)
  72.  
  73. #Agumon = Digimon(5,2,2,2,1,1)
  74. #Terriermon = Digimon(5,2,1,1,3,2)
  75.  
  76. Egg_idle = []
  77. for image in glob.glob("image/Egg/?.png"):
  78. Egg_idle.append(pygame.image.load(image))
  79. Eggcycle = itertools.cycle(Egg_idle)
  80.  
  81. Botamon_idle = []
  82. for image in glob.glob("image/In training_II/Gigimon_idle/?.png"):
  83. Botamon_idle.append(pygame.image.load(image))
  84. Botamoncycle = itertools.cycle(Botamon_idle)
  85.  
  86.  
  87. ## INIT -------------------------------------------------
  88.  
  89. pygame.init()
  90. screen = pygame.display.set_mode([300, 100])
  91. pygame.display.set_caption('Digimon Simulator')
  92. onTop(pygame.display.get_wm_info()['window'])
  93. font = pygame.font.Font("Digimonbasic.ttf", 15)
  94. black = ( 0, 0, 0) # defines colours for ease of use
  95. background_image = pygame.image.load("background3.png").convert()
  96. bar_full = pygame.image.load("bar_background.png").convert()
  97. bar = pygame.image.load("bar.png").convert()
  98. bar_length_x, bar_length_y = (50, 2)
  99. Digimon_x_pos, Digimon_y_pos = 150, 59
  100.  
  101. # TIME -------------------------------------------------
  102. clock = pygame.time.Clock()
  103. fps = 60
  104. dt = 0
  105. clock.tick()
  106.  
  107. Digimon_timer, Digimon_delay, Digimon_change = 0, 40, False
  108. Age_timer, Age_delay, Age_change = 0, 600, False
  109. Hunger_timer, Hunger_delay, Hunger_change = 0,6,False
  110. Sleep_timer, Sleep_delay, Sleep_change = 0,6,False
  111.  
  112.  
  113.  
  114. done = False # loop control
  115.  
  116. while not done:
  117. for event in pygame.event.get(): # User did something
  118. if event.type == pygame.QUIT:
  119. done = True # ends loop. game exit
  120. if event.type == pygame.MOUSEBUTTONDOWN:
  121. x,y = event.pos # gets the x, y position of the mouse click
  122. # if x >= Digimon_x_pos:
  123. # Player.__dict__ = Egg.__dict__
  124. if x >= Digimon_x_pos:
  125. #if ( x in range(10,100)) and ( y in range(10,100)): # if in range, add age +1 to player
  126. difference = (50 - bar_length_x)
  127. bar_length_x += difference
  128.  
  129. Digimon_timer += dt
  130. Age_timer += dt
  131. Hunger_timer += dt
  132. Sleep_timer += dt
  133. dt = clock.tick(fps)
  134. screen.blit(background_image, [0, 0])
  135. bar_transform = pygame.transform.scale(bar, (bar_length_x, bar_length_y)) # transforms the bar to 50 x, 2 y. can be changed now
  136. screen.blit(bar_full, [6,10])
  137. screen.blit(bar_transform ,[24,15])
  138. #Player.__dict__ = Egg.__dict__
  139. age_text = font.render("AGE: " + str(Player.age), True, black)
  140. screen.blit(age_text, [200, 10])
  141.  
  142. Eggcycle_next = Eggcycle.next()
  143. Botamoncycle_next = Botamoncycle.next()
  144.  
  145. #for the age. increases incrementally
  146. if Age_timer >= Age_delay:
  147. Age_timer -= Age_delay
  148. Age_change = not Age_change
  149. if Age_change:
  150. Player.age += 1
  151. #for the digimon sprites#
  152. # for the digimon sprite change
  153. if Digimon_timer >= Digimon_delay:
  154. Digimon_timer -= Digimon_delay
  155. Digimon_change = not Digimon_change
  156. if Digimon_change:
  157. if Player.age >= 2:
  158. screen.blit((Botamoncycle_next), (Digimon_x_pos, Digimon_y_pos))
  159. pygame.display.flip() # shows screen fill.
  160. else:
  161. Player.__dict__ == Egg.__dict__
  162. screen.blit((Eggcycle_next), (Digimon_x_pos, Digimon_y_pos))
  163. pygame.display.flip() # shows screen fill.
  164.  
  165.  
  166. #for the happiness bar
  167. if Hunger_timer >= Hunger_delay:
  168. Hunger_timer -= Hunger_delay
  169. Hunger_change = not Hunger_change
  170. if Hunger_change:
  171. if bar_length_x == 0:
  172. bar_length_x == 0
  173. else:
  174. bar_length_x -= 1
  175.  
  176. if Sleep_timer >= Sleep_delay:
  177. Sleep_timer -= Sleep_delay
  178. Sleep_change = not Sleep_change
  179. if Sleep_change:
  180. print "hi"
  181. # if bar_length_x == 0:
  182. # bar_length_x == 0
  183. # else:
  184. # bar_length_x -= 1
  185. clock.tick(fps) # Limit to 60 frames per second
  186. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment