a_falling.collide(other_object):
tmp_set.add(a_falling)
collided = True
if lives == 0:
over = True
started = False
else:
if a_falling.get_id() == 1:
score += 10
elif a_falling.get_id() == 2:
score += 5
elif a_falling.get_id() == 3:
score += 1
elif a_falling.get_id() == 4:
score -= 5
elif a_falling.get_id() == 5:
score -= 10
lives -= 1
wealthgod = Wealthgod([WIDTH/2,HEIGHT - wealthgod_info.get_size()[0]/2], wealthgod_image, wealthgod_info)
group.difference_update(tmp_set)
return collided
#在画布上画一组坠物的辅助函数
def process_falling_group(group, canvas):
tmp_set = set([])
for a_falling in list(group):
a_falling.draw(canvas)
if not over and a_falling.update():
tmp_set.add(a_falling)
group.difference_update(tmp_set)
#主绘制函数
def draw(canvas):
global time, score, lives, over, started,wealthgod,falling_group
if not started and not over:
canvas.draw_image(start_image, start_info.get_center(), start_info.get_size(), [WIDTH / 2, HEIGHT / 2], [WIDTH, HEIGHT])
elif over or time == 0:
timer.stop()
canvas.draw_image(end_image, end_info.get_center(), end_info.get_size(), [WIDTH / 2, HEIGHT / 2], end_info.get_size())
canvas.draw_text('总成绩\n'+" "+ str(score), (20, HEIGHT-100),36, 'Red', 'serif')
gameover()
else:
canvas.draw_image(background_image, background_info.get_center(), background_info.get_size(), [WIDTH / 2, HEIGHT / 2], [WIDTH, HEIGHT])
canvas.draw_text('时间:'+ str(time), (100, 30), 16, 'White', 'serif')
canvas.draw_text('成绩:'+ str(score), (WIDTH/2, 30), 16, 'White', 'serif')
canvas.draw_text('还有:'+ str(lives) + "次机会", (WIDTH - 200, 30), 16, 'White', 'serif')
wealthgod.draw(canvas)
process_falling_group(falling_group, canvas)
if group_collide(falling_group,wealthgod):
if lives>0:
#lives -= 1
wealthgod.draw(canvas)
else:
over = True
# 处理鼠标点击事件的函数
def mouseclick(pos):
#鼠标单击“开始游戏”位置,进入新游戏
global started
if not started and not over:
if 85gamestart()
# 处理键盘按下事件的函数
def keydown(key):
global wealthgod
if key == simplegui.KEY_MAP["left"]: # 向左
wealthgod.moveLeft()
elif key == simplegui.KEY_MAP["right"]: # 向右
wealthgod.moveRight()
# 创建用户界面
frame = simplegui.create_frame("欢天喜地接元宝", WIDTH, HEIGHT)
#