用Python、ruby或LUA开发游戏?

2024-06-09 22:35:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我在游戏脚本3和C++的游戏引擎中有游戏开发经验。 但是,我想提高生产率,所以我想用Python、ruby或LUA开发一个新项目。 是个好主意吗?如果是,你建议哪一个?什么是杀手级的游戏开发工具集或引擎?在


Tags: 项目引擎脚本游戏经验建议主意lua
1条回答
网友
1楼 · 发布于 2024-06-09 22:35:44

如果你做得好,那就去Pyglet
它是一个针对OpenGL的跨平台Python版本独立钩子,具有出色的性能。这有点棘手,但它比Python世界中的任何其他东西都做得更好。在

如果你是初学者,我会选择Pygame
这对系统来说有点累,但对于现代计算机来说,这不是问题。。此外,它还为游戏开发提供了预打包的API(因此得名:)

Python游戏/图形引擎的“官方”列表: http://wiki.python.org/moin/PythonGames

一些好的:

  • 潘达3d
  • 皮格勒
  • 游戏
  • 搅拌机3D

Pyglet代码示例:

#!/usr/bin/python
import pyglet
from time import time, sleep

class Window(pyglet.window.Window):
    def __init__(self, refreshrate):
        super(Window, self).__init__(vsync = False)
        self.frames = 0
        self.framerate = pyglet.text.Label(text='Unknown', font_name='Verdana', font_size=8, x=10, y=10, color=(255,255,255,255))
        self.last = time()
        self.alive = 1
        self.refreshrate = refreshrate
        self.click = None
        self.drag = False

    def on_draw(self):
        self.render()

    def on_mouse_press(self, x, y, button, modifiers):
        self.click = x,y

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        if self.click:
            self.drag = True
            print 'Drag offset:',(dx,dy)

    def on_mouse_release(self, x, y, button, modifiers):
        if not self.drag and self.click:
            print 'You clicked here', self.click, 'Relese point:',(x,y)
        else:
            print 'You draged from', self.click, 'to:',(x,y)
        self.click = None
        self.drag = False

    def render(self):
        self.clear()
        if time() - self.last >= 1:
            self.framerate.text = str(self.frames)
            self.frames = 0
            self.last = time()
        else:
            self.frames += 1
        self.framerate.draw()
        self.flip()

    def on_close(self):
        self.alive = 0

    def run(self):
        while self.alive:
            self.render()
            #   > Note: <  
            #  Without self.dispatc_events() the screen will freeze
            #  due to the fact that i don't call pyglet.app.run(),
            #  because i like to have the control when and what locks
            #  the application, since pyglet.app.run() is a locking call.
            event = self.dispatch_events()
            sleep(1.0/self.refreshrate)

win = Window(23) # set the fps
win.run()




关于Pyglet与Python 3.X的说明:

您必须下载1.2alpha1否则它会抱怨您没有安装Python3.X:)

相关问题 更多 >