pygame鼠闯迷宫闯关小游戏

pygame鼠闯迷宫闯关小游戏

pygame mouse maze game 鼠闯迷宫pygame鼠标牵引游戏

```"""鼠闯迷宫闯关小游戏.一只老鼠在一个巨大的迷宫中,它要出去才不致于被饿死,用鼠标牵引它移动即可。

__author__ = "李兴球"
__date__ = "2018年12月左右"

import os,math,sys
import pygame
from pygame.locals import *

class Maze(pygame.sprite.Sprite):
def __init__(self,image,scale,screen):
pygame.sprite.Sprite.__init__(self)
self.screen = screen
pass

def update(self,dx,dy):
"""迷宫朝相反的dx和dy移动"""
self.rect.move_ip(dx*0.05,dy*0.05)

def draw(self):
self.screen.blit(self.image,self.rect)

class Mouse(pygame.sprite.Sprite):
def __init__(self,image,position,screen,maze=None):
pygame.sprite.Sprite.__init__(self)
self.position = position                                  # 原始坐标
self.screen = screen
self.maze = maze                                          # 引用当前的迷宫对象
pass

def distance(self,mousexy):
"""到鼠标指针的距离"""
dy = mousexy[1] - self.rect.centery
dx = mousexy[0] - self.rect.centerx
return math.sqrt(dx * dx  + dy * dy)

def update(self,mousexy,logic):
"""根据方向角度更新图像"""
if self.distance(mousexy) > 50 :
self.image = pygame.transform.rotate(self.raw_image,self.angle).convert_alpha()
self.image.set_colorkey((0,0,0))
pass

def bump_check(self):
，再侦测像素值就知道是碰到门还是碰到绿色"""
level_end = False
pass
def draw(self):
self.screen.blit(self.image,self.rect)

def display_shell(screensize,shell_image,begin_button_images):
width,height = screensize
index = 0
button_image = begin_button_images[index]

button_rect = button_image.get_rect()
button_width = button_rect.width
button_height = button_rect.height
button_rect.center = (width//2,100+height//2)
clock = pygame.time.Clock()
running = True
continue_game = True
while running:
for event in pygame.event.get():
if event.type == QUIT:
running = False
pass
pygame.display.update()
clock.tick(30)

return continue_game

def display_end(end_image):
clock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == QUIT:
running = False
break
mousekeys = pygame.mouse.get_pressed()
if mousekeys[0] : running = False

screen.blit(end_image,(0,0))
pygame.display.update()
clock.tick(30)

if __name__ == "__main__":

pass

```

(会员专属：能浏览所有文章，下载所有带链接的Python资源。)