用pygame写游戏 蚂蚁打蜘蛛侠 并升级

这是一个使用pygame库创建的简单游戏,游戏中有蚂蚁在探索世界,当遇到蜘蛛侠时会进行攻击。蚂蚁和蜘蛛侠都有自己的状态机,根据状态执行不同的行为,如探索、追逐和战斗。游戏包含蚂蚁和蜘蛛侠的生成、移动以及状态切换等逻辑。
摘要由CSDN通过智能技术生成
SCREEN_SIZE = (640, 480)
ANT_COUNT=5
import pygame  
from pygame.locals import *  
from random import randint, choice  
from gameobjects.vector2 import Vector2
class World(object):  
    def __init__(self):  
        self.entities = {}  
        self.entity_id = 0  
        '''self.background = pygame.surface.Surface(SCREEN_SIZE).convert() ''' 
        
    def add_entity(self, entity):  
        self.entities[self.entity_id] = entity  
        entity.id = self.entity_id  
        self.entity_id += 1  
  
    def remove_entity(self, entity):  
        del self.entities[entity.id]  
  
    def get(self, entity_id):  
        if entity_id in self.entities:  
            return self.entities[entity_id]  
        else:  
            return None  
  
    def process(self, time_passed):  
        time_passed_seconds = time_passed / 1000.0  
        for entity in self.entities.values():  
            entity.process(time_passed_seconds)  
  
    def render(self, surface):  
        '''surface.blit(self.background, (0, 0))'''
        background_image_filename='grass.jpg'
        background=pygame.image.load(background_image_filename).convert()
        surface.blit(background,(0,0)) 
        for entity in self.entities.itervalues():  
            entity.render(surface)  
  
    def get_close_entity(self, name, location, range=100.):  
        location = Vector2(*location)  
        for entity in self.entities.itervalues():  
            if entity.name == name:  
                distance = location.get_distance_to(entity.location)  
                if distance < range:  
                    return entity  
        return None  

class State(object):  
    def __init__(s
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值