pygame big fish eat small fish大鱼吃小鱼游戏界面
以下是部分代码预览:
"""pygame大鱼吃小鱼,这是本人曾经制作的一个小练习,现在翻出来以飨读者,以前为了方便学生理解程序,用了些中文变量。"""
import pygame
from pygame.locals import *
import math
from random import randint
pygame.init()
screen = pygame.display.set_mode((480,360))
pygame.display.set_caption("pygame大鱼吃小鱼_作者:李兴球")
class Bigfish():
def __init__(self,rightImageList,leftImageList,x,y):
self.imageindex = 0 # 相当于造型编号
self.direction=0 # 0表示右,1左
self.imageList = [rightImageList,leftImageList]
self.image = self.imageList[self.direction][self.imageindex]
pass
def move(self,mx,my): # mx是鼠标指针的x坐标
dx = self.rect.centerx - mx # dx大于0,表示鱼在鼠标指针右边,这时它的方向为左.
if dx!=0: self.direction= (dx//abs(dx) + 1)//2