I am working on a TF2/Minecraft hybrid and I am stuck on loading blocks as individual types:
main.py:
from direct.showbase.ShowBase import ShowBase
from pandac import *
from direct import *
from panda3d.core import *
from direct.showbase.Loader import *
from Map1 import *
from BlockTypes import *
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# Show fps counter
base.setFrameRateMeter(True)
app = MyApp()
app.run()
Map1.py:
from BlockTypes import BlockTypeTest
BlockTypeTest(0, 0, 0)
BlockTypes.py:
from direct.showbase.ShowBase import ShowBase
from pandac import *
from direct import *
from panda3d.core import *
from direct.showbase.Loader import *
def BlockTypeTest(x, y, z):
block = loader.loadModel("cube.egg")
block.reparentTo(render)
block.setScale(1)
block.setPos(x, y, z)
texture = loader.loadTexture("CubeMapTest2.png")
block.setTexture(texture)
Please help me. I am new to this engine and to python in general.
Your main.py is where your code starts running from. “import” gives python access to that file, but doesn’t actually run it.
I suggest starting with a simpler game or python project. Voxel based games like minecraft are a pain to code and require a bit of experience. I started learning python by writing a chat bot for a chatroom. It was an easy place to start and I got instant results.
I finally figured it out! It turns out all i had to do was skip the traditional code, import the other files and just directly run the code with
run()
The New files:
main.py:
from direct.showbase.ShowBase import ShowBase
from pandac import *
from direct import *
from panda3d.core import *
from direct.showbase.Loader import *
import direct.directbase.DirectStart
from BlockTypes import BlockTypeTest
import Map1
run()
BlockTypes.py:
from direct.showbase.ShowBase import ShowBase
from pandac import *
from direct import *
from panda3d.core import *
from direct.showbase.Loader import *
import direct.directbase.DirectStart
def BlockTypeTest(x, y, z):
block = loader.loadModel("cube.egg")
block.reparentTo(render)
block.setScale(0.1)
block.setPos(x, y, z)
texture = loader.loadTexture("CubeMapTest2.png")
block.setTexture(texture)
Map1.py:
from BlockTypes import BlockTypeTest
BlockTypeTest(0, 0, 0)