当前位置:   article > 正文

用Python制作一个简单的球球大作战_python仿球球大作战

python仿球球大作战

大家好,我是查理。今天教大家制作一个简化版球球大作战
话不不多说,上代码

# -*- coding: utf-8 -*-
# @Time    : 2018/7/30 16:19
# @Author  : G.Hope
# @Email   : 1638327522@qq.com
# @File    : 吃球.py
# @Software: PyCharm

import pygame
import random
import math


# 生成随机颜色
def random_color():
    return random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)


# 判断是否碰撞,并使大球吃掉小球(小球消失,大球变大)
def eat(ball1, ball2):
    x1, y1 = ball1['pos']
    x2, y2 = ball2['pos']
    x_distance = x1 - x2
    y_distance = y1 - y2
    distance = math.sqrt(x_distance ** 2 + y_distance ** 2)
    if distance < ball1['r'] + ball2['r']:
        if ball1['r'] > ball2['r']:
            ball1['r'] = ball2['r'] + ball1['r']
            all_balls.remove(ball2)
        else:
            ball2['r'] = ball2['r'] + ball1['r']
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/477837
推荐阅读
相关标签
  

闽ICP备14008679号