Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame # Import library of functions called 'pygame'
- from pygame.time import Clock
- import random
- import time
- import itertools
- import pygame, os
- os.environ['SDL_VIDEO_CENTERED'] = '1'
- class Digimon(pygame.sprite.Sprite):
- def __init__(self,age,weight,strength,defence,speed,intelligence):
- pygame.sprite.Sprite.__init__(self)
- self.age = age
- self.weight = weight
- self.strength = strength
- self.defence = defence
- self.speed = speed
- self.intelligence = intelligence
- ############################ PLAYER OBJECT ##############################
- Player = Digimon(0,2,0,0,0,0)
- # Player_sprites = itertools.cycle(Player.image) # cycles through the player (in this case - Egg - images)
- ############################ EGG OBJECT #################################
- Egg = Digimon(0,2,0,0,0,0)
- Egg_idle = [pygame.image.load("images/egg_1.png"), pygame.image.load("images/egg_2.png"), pygame.image.load("images/egg_3.png") ]
- Egg_sprites = itertools.cycle(Egg_idle) # cycles through egg images
- ############################ KOROMON OBJECT ##############################
- 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")]
- Koromon_sprites = itertools.cycle(Koromon_idle) # cycles through egg images
- ############################ BEAM OBJECT ##############################
- 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") ]
- Digivolve_sprites = itertools.cycle(Digivolve_beam)
- ############################ INITIALISE GAME ENGINE ##############################
- pygame.init()
- [screen_width, screen_height] = [400,150]
- screen = pygame.display.set_mode([screen_width,screen_height])
- screen.set_colorkey((255, 0 ,255))
- pygame.display.set_caption("Digimon Simulator 1")
- black = ( 0, 0, 0) # defines colours for ease of use
- white = (255,255,255)
- clock = pygame.time.Clock() # controls how fast the game runs
- font = pygame.font.Font(None, 15)
- Digivolve_Koromon = 0
- game_over = 0
- x_pos = 160
- y_pos = 100
- Age_timer = 0
- ############################ FRAME RATE #################################
- update_normal = 5
- update_main = 50.0
- #########################################################################
- done = False # loop control
- t = time.time() # gets the time.
- draw_egg=False
- draw_Koromon=False
- draw_Digivolve=False
- ############################ Main Program Loop #################################
- while not done:
- clock.tick(update_main) # loops game at 50
- ############################ ALL EVENT PROCESSING SHOULD GO BELOW THIS COMMENT #################################
- for event in pygame.event.get(): # User did something
- if event.type == pygame.QUIT: # If user clicked close
- done = True # exits the loop
- if event.type == pygame.MOUSEBUTTONDOWN:
- x,y = event.pos # gets the x, y position of the mouse click
- if ( x in range(150,170)) and ( y in range(10,30)): # if in range, add age +1 to player
- Player.age += 1
- if event.type == pygame.MOUSEBUTTONDOWN:
- x,y = event.pos # gets the x, y position of the mouse click
- if ( x in range(175,195)) and ( y in range(10,30)): # if in range, add age +1 to player
- Player.weight += 1
- if event.type == pygame.MOUSEBUTTONDOWN:
- x,y = event.pos # gets the x, y position of the mouse click
- if ( x in range(200,220)) and ( y in range(10,30)): # if in range, add age +1 to player
- Player.strength += 1
- if event.type == pygame.MOUSEBUTTONDOWN:
- x,y = event.pos # gets the x, y position of the mouse click
- if ( x in range(225,245)) and ( y in range(10,30)): # if in range, add age +1 to player
- Player.defence += 1
- if event.type == pygame.MOUSEBUTTONDOWN:
- x,y = event.pos # gets the x, y position of the mouse click
- if ( x in range(250,275)) and ( y in range(10,30)): # if in range, add age +1 to player
- Player.speed += 1
- if event.type == pygame.MOUSEBUTTONDOWN:
- x,y = event.pos # gets the x, y position of the mouse click
- if ( x in range(275,295)) and ( y in range(10,30)): # if in range, add age +1 to player
- Player.intelligence += 1
- ############################ ALL EVENT PROCESSING SHOULD GO ABOVE THIS COMMENT #################################
- screen.fill((white))
- ############################ ALL HERE IS FRAME RATE 5 #################################
- if time.time() - t >= (1.0 / update_normal): # if new time - old time is more than 0.2 (1/5)
- t = time.time()
- Egg_sprites_next = Egg_sprites.next() # sets it up to cycle through Egg images
- Koromon_sprites_next = Koromon_sprites.next() # sets it up to cycle through Koromon images
- Age_timer += 0.001
- n = random.randint (0,1000)
- if n < 100:
- x_pos -= 1
- print "n is less than 100"
- elif n > 900:
- x_pos += 1
- print "n is more than 950"
- elif x_pos >= 340 or x_pos <= 0:
- x_pos *= -1
- if Player.age == 0 and Player.strength == 0 and Player.defence == 0 and Player.speed == 0 and Player.intelligence == 0:
- draw_egg = True # draws Egg (refer to below for the command)
- draw_Koromon = False
- if Player.age <= 2 and Player.strength == 5:
- # and Player.defence == 5 and Player.speed == 5 and Player.intelligence == 5:
- # draw_egg = False # draws Egg (refer to below for the command)
- Digivolve_sprites_next = Digivolve_sprites.next()
- draw_Digivolve = True # I want this to run faster
- draw_egg = False
- draw_Koromon = False
- if Age_timer == 10:
- Player.age += 1
- Age_timer = 0
- elif Player.age == 12:
- game_over += 1
- if game_over == 1:
- print "Game over"
- else:
- pass
- ############################ ALL HERE IS FRAME RATE 25 (it's in the main loop which is set at 25)#################################
- # Beam_sprites_next = Beam_sprites.next() # sets it up to cycle through Beam images
- #if digivolve == 1: # if Player.age = 1
- # draw_egg = False
- # draw_Koromon = False # draws Koromon (refer to below for the command)
- # draw_beam = True
- ############################ ALL GAME LOGIC SHOULD GO ABOVE THIS COMMENT #################################
- ############################ ALL CODE TO DRAW SHOULD GO BELOW THIS COMMENT #################################
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- if draw_egg:
- screen.blit((Egg_sprites_next), (189, 119))
- if draw_Koromon:
- screen.blit((Koromon_sprites_next), (x_pos,y_pos))
- if draw_Digivolve:
- screen.blit((Digivolve_sprites_next), (x_pos,y_pos))
- else:
- pass
- Player_age_text = font.render("Player Age " + str(Player.age), True, black) # font uses the font fuction above, (what to draw, anti-alias, colour)
- Player_weight_text = font.render("Player Weight " + str(Player.weight), True, black)
- Player_strength_text = font.render("Player Strength " + str(Player.strength), True, black)
- Player_defence_text = font.render("Player Defence " + str(Player.defence), True, black)
- Player_speed_text = font.render("Player Speed " + str(Player.speed), True, black)
- Player_intelligence_text = font.render("Player Intelligence " + str(Player.intelligence), True, black)
- Age_timer_text = font.render("Age_timer " + str(Age_timer), True, black)
- screen.blit(Player_age_text, [10, 10])
- screen.blit(Player_weight_text, [10, 20])
- screen.blit(Player_strength_text, [10, 30])
- screen.blit(Player_defence_text, [10, 40])
- screen.blit(Player_speed_text, [10, 50])
- screen.blit(Player_intelligence_text, [10, 60])
- screen.blit(Age_timer_text, [10, 70])
- pygame.display.flip() # shows screen fill.
- # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement