让精灵随机出现
我试图让精灵随机出现在屏幕上,而不使用 OOP 原则,
此代码来自 AI
if randint(1, 10) == 1:
leaf = Leaf(world, leaf_image)
leaf.location = Vector2(randint(0, w), randint(0, h))
world.add_entity(leaf)
world.process(time_passed)
world.render(screen)
pygame.display.update()
问题的蚂蚁演示: 如何让精灵随机出现在屏幕上? 我知道要复制它们 但是如果不使用面向对象,
这是我的代码唯一缺少精灵随机出现的方法的部分 这是 antstate.py 的代码,我在其中获取代码: http://www.mediafire.com/?5tjswcyl9xt5huj
I am trying to have sprites randomly appear on the screen with out using OOP principles
this code is from a ants demo for AI
if randint(1, 10) == 1:
leaf = Leaf(world, leaf_image)
leaf.location = Vector2(randint(0, w), randint(0, h))
world.add_entity(leaf)
world.process(time_passed)
world.render(screen)
pygame.display.update()
Question:
How do I get Sprites on the screen randomly?
I know to blit them
but how without using Object-Oriented
this is the only part my code is missing a way for sprites to randomly appear
this the code to the antstate.py where im getting the code:
http://www.mediafire.com/?5tjswcyl9xt5huj
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
精灵是一个对象。所以你需要使用一些 OOP 来处理精灵。这是一个例子:
A sprite is an object. So you need to use some OOP to work with a sprite. Here's an example: