def __init__(self): self.z_position = 2 self.is_jumping = False self.is_ducking = False self.is_blinking = False self.is_dead = False self.counter = 0 list_running_dinos = utils.load_sprite_sheet('dino.png', 5, 1, 44, 47) list_ducking_dinos = utils.load_sprite_sheet('dino_ducking.png', 2, 1, 59, 47) self.list_dinos = list_running_dinos + list_ducking_dinos self.index = 0 self.left_buttom_coord = scene.Point(10, 10) self.update_img() self.velocity = [0, 0]
def __init__(self,screen,speed=5,sizex=-1,sizey=-1): pg.sprite.Sprite.__init__(self,self.containers) self.screen = screen self.images,self.rect = ut.load_sprite_sheet('cacti-small.png',3,1,sizex,sizey,-1) self.rect.bottom = int(0.98*ct.height) self.rect.left = ct.width + self.rect.width self.image = self.images[random.randrange(0,3)] self.movement = [-1*speed,0]
def __init__(self, speed=-5): texture, size = utils.load_sprite_sheet('ground.png', 1, 1)[0] self.ground0 = Ground(texture, size, scene.Point(0, 0)) self.ground1 = Ground(texture, size, scene.Point(size.x, 0)) self.add_child(self.ground0) self.add_child(self.ground1) self.position = scene.Point(0, 0) self.velocity = speed
def __init__(self,screen,speed=5,sizex=-1,sizey=-1): pg.sprite.Sprite.__init__(self,self.containers) self.screen = screen self.images,self.rect = ut.load_sprite_sheet('ptera.png',2,1,sizex,sizey,-1) self.ptera_height = [ct.height*0.82,ct.height*0.75,ct.height*0.60] self.rect.centery = self.ptera_height[random.randrange(0,3)] self.rect.left = ct.width + self.rect.width self.image = self.images[0] self.movement = [-1*speed,0] self.index = 0 self.counter = 0
def __init__(self,screen,sizex=-1,sizey=-1): self.screen = screen self.checkPoint_sound = pg.mixer.Sound('sprites/checkPoint.wav') self.images,self.rect = ut.load_sprite_sheet('dino.png',5,1,sizex,sizey,-1) self.images1,self.rect1 = ut.load_sprite_sheet('dino_ducking.png',2,1,59,sizey,-1) self.rect.bottom = int(0.98*ct.height) self.rect.left = ct.width/15 self.image = self.images[0] self.index = 0 self.counter = 0 self.score = 0 self.isJumping = False self.isDead = False self.isDucking = False self.isBlinking = False self.movement = [0,0] self.jumpSpeed = 11.5 self.stand_pos_width = self.rect.width self.duck_pos_width = self.rect1.width
def __init__(self, scene_size_x): self.position = scene.Point(0, 0) self.velocity = -5 sprites = utils.load_sprite_sheet('cacti-small.png', 6, 1, 17, 35, [(0, 1), (0, 2), (3, 1), (2, 2), (2, 3)]) position = scene.Point(-100, 0) cactuses = [ Cactus(texture, size, position, scene_size_x) for texture, size in sprites ] for cactus in cactuses: self.add_child(cactus)
def __init__(self,screen,x=-1,y=-1): self.screen = screen self.score = 0 self.tempimages,self.temprect = ut.load_sprite_sheet('numbers.png',12,1,11,int(11*6/5),-1) self.image = pg.Surface((55,int(11*6/5))) self.rect = self.image.get_rect() if x == -1: self.rect.left = ct.width*0.89 else: self.rect.left = x if y == -1: self.rect.top = ct.height*0.1 else: self.rect.top = y
def __init__(self, speed, scene_size_x): self.position = scene.Point(0, 0) self.velocity = -2 texture, size = utils.load_sprite_sheet('cloud.png', 1, 1, int(90 * 30 / 42), 30)[0] position = scene.Point(-200, random.randrange(90, 150)) cloud0 = Cloud(texture, size, position, scene_size_x) cloud1 = Cloud(texture, size, position, scene_size_x) cloud2 = Cloud(texture, size, position, scene_size_x) cloud3 = Cloud(texture, size, position, scene_size_x) self.add_child(cloud0) self.add_child(cloud1) self.add_child(cloud2) self.add_child(cloud3)
def introscreen(self): temp_dino = Dino(self.screen, 47, 47) temp_dino.isBlinking = True gameStart = False callout, callout_rect = ut.load_image('call_out.png', 196, 45, -1) callout_rect.left = ct.width * 0.05 callout_rect.top = ct.height * 0.4 temp_ground, temp_ground_rect = ut.load_sprite_sheet( 'ground.png', 15, 1, -1, -1, -1) temp_ground_rect.left = ct.width / 20 temp_ground_rect.bottom = ct.height logo, logo_rect = ut.load_image('logo.png', 240, 40, -1) logo_rect.centerx = ct.width * 0.6 logo_rect.centery = ct.height * 0.6 while not gameStart: if pg.display.get_surface() == None: print("Couldn't load display surface") return (True) else: for event in pg.event.get(): if event.type == pg.QUIT: return (True) if event.type == pg.KEYDOWN: if event.key == pg.K_SPACE or event.key == pg.K_UP: temp_dino.isJumping = True temp_dino.isBlinking = False temp_dino.movement[1] = -1 * temp_dino.jumpSpeed temp_dino.update() if pg.display.get_surface() != None: self.screen.fill(ct.background_col) self.screen.blit(temp_ground[0], temp_ground_rect) if temp_dino.isBlinking: self.screen.blit(logo, logo_rect) self.screen.blit(callout, callout_rect) temp_dino.draw() pg.display.update() self.clock.tick(ct.FPS) if temp_dino.isJumping == False and temp_dino.isBlinking == False: gameStart = True
def __init__(self,x,y): super().__init__("WaffleMaker",image=utils.load_sprite_sheet("wafflemaker",constants.WAFFLE_MAKER_SIZE,constants.WAFFLE_MAKER_SIZE), x=x,y=y,width=constants.WAFFLE_MAKER_SIZE,height=constants.WAFFLE_MAKER_SIZE) self.waffle = None self.cook_meter = CookMeter(x=self.x - constants.COOK_METER_WIDTH - 10, y=self.y,height=self.height) self.batter_selector = BatterSelector(x=self.x+self.width+10, y=self.y, height=self.height) self.selected_batter = constants.DUMP_BATTER
def __init__(self,x,y,height): super().__init__("BatterSelector",x=x,y=y,width=constants.BATTER_ICON_SIZE,height=height,color=colors.red) self.batters = list() for i in range(len(BATTER_NAMES)): batter = BATTER_NAMES[i] self.batters.append(BatterIcon(name=batter,image=utils.load_sprite_sheet(batter,constants.BATTER_ICON_SIZE,constants.BATTER_ICON_SIZE),x=self.x,y=self.y+i*constants.BATTER_ICON_SIZE))
def gameplay(self): gamespeed = 4 startMenu = False gameOver = False gameQuit = False playerDino = Dino(self.screen, 44, 47) new_ground = Ground(self.screen, -1 * gamespeed) scb = Scoreboard(self.screen) highsc = Scoreboard(self.screen, ct.width * 0.78) counter = 0 cacti = pg.sprite.Group() pteras = pg.sprite.Group() clouds = pg.sprite.Group() last_obstacle = pg.sprite.Group() Cactus.containers = cacti Ptera.containers = pteras Cloud.containers = clouds retbutton_image, retbutton_rect = ut.load_image( 'replay_button.png', 35, 31, -1) gameover_image, gameover_rect = ut.load_image('game_over.png', 190, 11, -1) temp_images, temp_rect = ut.load_sprite_sheet('numbers.png', 12, 1, 11, int(11 * 6 / 5), -1) HI_image = pg.Surface((22, int(11 * 6 / 5))) HI_rect = HI_image.get_rect() HI_image.fill(ct.background_col) HI_image.blit(temp_images[10], temp_rect) temp_rect.left += temp_rect.width HI_image.blit(temp_images[11], temp_rect) HI_rect.top = ct.height * 0.1 HI_rect.left = ct.width * 0.73 while not gameQuit: while startMenu: pass while not gameOver: if pg.display.get_surface() == None: print("Couldn't load display surface") gameQuit = True gameOver = True else: ########## frame = self.cam.get_frame() frame = cv2.resize(frame, self.im_shape) frame = np.reshape( frame, (1, self.im_shape[0], self.im_shape[1], 3)) out = self.model.predict(frame) CLS = {0: 'Center', 1: 'Top', 2: 'Bottom'} print(CLS[int(out[0])], ) if True: for event in pg.event.get(): if event.type == pg.QUIT: gameQuit = True gameOver = True if out[0] == 1: if playerDino.rect.bottom == int(0.98 * ct.height): playerDino.isJumping = True if pg.mixer.get_init() != None: self.jump_sound.play() playerDino.movement[ 1] = -1 * playerDino.jumpSpeed elif out[0] == 0: playerDino.isDucking = False elif out[0] == 2: if not (playerDino.isJumping and playerDino.isDead): playerDino.isDucking = True if False: for event in pg.event.get(): if event.type == pg.QUIT: gameQuit = True gameOver = True if event.type == pg.KEYDOWN: if event.key == pg.K_SPACE: if playerDino.rect.bottom == int( 0.98 * ct.height): playerDino.isJumping = True if pg.mixer.get_init() != None: self.jump_sound.play() playerDino.movement[ 1] = -1 * playerDino.jumpSpeed if event.key == pg.K_DOWN: if not (playerDino.isJumping and playerDino.isDead): playerDino.isDucking = True if event.type == pg.KEYUP: if event.key == pg.K_DOWN: playerDino.isDucking = False ########## for c in cacti: c.movement[0] = -1 * gamespeed if pg.sprite.collide_mask(playerDino, c): playerDino.isDead = True if pg.mixer.get_init() != None: self.die_sound.play() for p in pteras: p.movement[0] = -1 * gamespeed if pg.sprite.collide_mask(playerDino, p): playerDino.isDead = True if pg.mixer.get_init() != None: self.die_sound.play() if len(cacti) < 2: if len(cacti) == 0: last_obstacle.empty() last_obstacle.add( Cactus(self.screen, gamespeed, 40, 40)) else: for l in last_obstacle: if l.rect.right < ct.width * 0.7 and random.randrange( 0, 50) == 10: last_obstacle.empty() last_obstacle.add( Cactus(self.screen, gamespeed, 40, 40)) if len(pteras) == 0 and random.randrange( 0, 200) == 10 and counter > 500: for l in last_obstacle: if l.rect.right < ct.width * 0.8: last_obstacle.empty() last_obstacle.add( Ptera(self.screen, gamespeed, 46, 40)) if len(clouds) < 5 and random.randrange(0, 300) == 10: Cloud(self.screen, ct.width, random.randrange(ct.height / 5, ct.height / 2)) playerDino.update() cacti.update() pteras.update() clouds.update() new_ground.update() scb.update(playerDino.score) highsc.update(self.high_score) if pg.display.get_surface() != None: self.screen.fill(ct.background_col) new_ground.draw() clouds.draw(self.screen) scb.draw() if self.high_score != 0: highsc.draw() self.screen.blit(HI_image, HI_rect) cacti.draw(self.screen) pteras.draw(self.screen) playerDino.draw() pg.display.update() self.clock.tick(ct.FPS) if playerDino.isDead: gameOver = True if playerDino.score > self.high_score: self.high_score = playerDino.score if counter % 700 == 699: new_ground.speed -= 1 gamespeed += 1 counter = (counter + 1) if gameQuit: break while gameOver: if pg.display.get_surface() == None: print("Couldn't load display surface") gameQuit = True gameOver = False else: for event in pg.event.get(): if event.type == pg.QUIT: gameQuit = True gameOver = False if event.type == pg.KEYDOWN: if event.key == pg.K_ESCAPE: gameQuit = True gameOver = False if event.key == pg.K_RETURN or event.key == pg.K_SPACE: gameOver = False self.gameplay() highsc.update(self.high_score) if pg.display.get_surface() != None: self.disp_gameOver_msg(retbutton_image, gameover_image) if self.high_score != 0: highsc.draw() self.screen.blit(HI_image, HI_rect) pg.display.update() self.clock.tick(ct.FPS) pg.quit() self.cam.stop() quit()
import pygame import utils import game_data import level import menu ################## # initialisation # ################## pygame.init() pygame.event.set_allowed( [pygame.QUIT, pygame.MOUSEMOTION, pygame.MOUSEBUTTONUP]) pygame.display.set_caption("Attack on the cemetery") screen = pygame.display.set_mode((1, 1)) game_data.buildings_images = utils.load_sprite_sheet("assets/buildings.png", (75, 75)) game_data.monsters_images = utils.load_sprite_sheet("assets/monsters.png", (50, 50)) game_data.projectile_images = utils.load_sprite_sheet("assets/projectiles.png", (32, 9)) game_data.effects = utils.load_sprite_sheet("assets/effects.png", (50, 50)) game_data.new_building_image = pygame.image.load( "assets/building_0.png").convert_alpha() game_data.buttons = utils.load_sprite_sheet("assets/buttons.png", (50, 50)) game_data.scores_image = utils.load_sprite_sheet("assets/scores.png", (85, 50)) pygame.mixer_music.load("assets/Wintergatan - Ondophone .mp3") next_ui = "menu" while True: if next_ui == "exit": break