利用pygame模块开发
项目迭代开发~
github地址:https://github.com/leemamas/pvz
演示视频地址:
https://www.bilibili.com/video/BV1Dz411b7D3/
https://www.bilibili.com/video/BV1mC4y1s7hr/
9.地图的划分
1.定义常量
#地图抵消的值,等左上角的起点坐标(250,90)
X_OFFSET_MAP=250
Y_OFFSET_MAP=90
#网格的长宽
X_GRID_SIZE=80
Y_GRID_SIZE=90
#网格的数目
X_GRID_LEN=9
Y_GRID_LEN=5
2.鼠标到哪,属于哪个区域
def getIndex(self,x,y):
x-=Zone.X_OFFSET_MAP
y-=Zone.Y_OFFSET_MAP
return x//Zone.X_GRID_SIZE,y//Zone.Y_GRID_SIZE
3.区域的地图坐标点
def getGridPos(self,x,y):
return x*Zone.X_GRID_SIZE+Zone.X_OFFSET_MAP,y*Zone.Y_GRID_SIZE+Zone.Y_OFFSET_MAP
4.卡槽区域
def is_card_slot_zone(self,x,y,width,height):
if 250<=x<=250+width and 0<=y<=height:
return True
else:
return False
5种植区域
def is_plant_zone(self,x,y):
if Zone.X_OFFSET_MAP <= x <= Zone.X_OFFSET_MAP + Zone.X_GRID_SIZE*Zone.X_GRID_LEN and Zone.Y_OFFSET_MAP <= y <= Zone.Y_OFFSET_MAP+Zone.Y_GRID_SIZE*Zone.Y_GRID_LEN:
return True
else:
return False