def spawnAsteroids(self): # Control variable for if the ship is alive self.alive = True self.asteroids = [] # List that will contain our asteroids for i in range(10): asteroid = loadObject("asteroid%d.png" % (randint(1, 3)), scale=AST_INIT_SCALE) self.asteroids.append(asteroid) self.setVelocity(self.asteroids[i], LVector3.zero()) self.asteroids[1].setX(15) self.asteroids[1].setZ(11) self.asteroids[2].setX(-1) self.asteroids[2].setZ(-9) self.asteroids[3].setX(0) self.asteroids[3].setZ(12) self.asteroids[4].setX(10) self.asteroids[4].setZ(12) self.asteroids[5].setX(-14) self.asteroids[5].setZ(3) self.asteroids[6].setX(-6) self.asteroids[6].setZ(8) self.asteroids[7].setX(12) self.asteroids[7].setZ(-7) self.asteroids[8].setX(-8) self.asteroids[8].setZ(13) self.asteroids[9].setX(-7) self.asteroids[9].setZ(-4) self.asteroids[0].setX(-8) self.asteroids[0].setZ(-10)
def __init__(self): # Initialize the ShowBase class from which we inherit, which will # create a window and set up everything we need for rendering into it. ShowBase.__init__(self) # This code puts the standard title and instruction text on screen self.title = OnscreenText(text="Panda3D: Tutorial - Tasks", parent=base.a2dBottomRight, scale=.07, align=TextNode.ARight, pos=(-0.1, 0.1), fg=(1, 1, 1, 1), shadow=(0, 0, 0, 0.5)) self.escapeText = genLabelText("ESC: Quit", 0) self.leftkeyText = genLabelText("[Left Arrow]: Turn Left (CCW)", 1) self.rightkeyText = genLabelText("[Right Arrow]: Turn Right (CW)", 2) self.upkeyText = genLabelText("[Up Arrow]: Accelerate", 3) self.spacekeyText = genLabelText("[Space Bar]: Fire", 4) # Disable default mouse-based camera control. This is a method on the # ShowBase class from which we inherit. self.disableMouse() # Load the background starfield. self.setBackgroundColor((0, 0, 0, 1)) self.bg = loadObject("stars.jpg", scale=146, depth=200, transparency=False) # Load the ship and set its initial velocity. self.ship = loadObject("ship.png") self.setVelocity(self.ship, LVector3.zero()) # A dictionary of what keys are currently being pressed # The key events update this list, and our task will query it as input self.keys = {"turnLeft": 0, "turnRight": 0, "accel": 0, "fire": 0} self.accept("escape", sys.exit) # Escape quits # Other keys events set the appropriate value in our key dictionary self.accept("arrow_left", self.setKey, ["turnLeft", 1]) self.accept("arrow_left-up", self.setKey, ["turnLeft", 0]) self.accept("arrow_right", self.setKey, ["turnRight", 1]) self.accept("arrow_right-up", self.setKey, ["turnRight", 0]) self.accept("arrow_up", self.setKey, ["accel", 1]) self.accept("arrow_up-up", self.setKey, ["accel", 0]) self.accept("space", self.setKey, ["fire", 1]) # Now we create the task. taskMgr is the task manager that actually # calls the function each frame. The add method creates a new task. # The first argument is the function to be called, and the second # argument is the name for the task. It returns a task object which # is passed to the function each frame. self.gameTask = base.taskMgr.add(self.gameLoop, "gameLoop") # Stores the time at which the next bullet may be fired. self.nextBullet = 0.0 # This list will stored fired bullets. self.bullets = [] # Complete initialization by spawning the asteroids. self.spawnAsteroids()
def __init__(self): # Initialize the ShowBase class from which we inherit, which will # create a window and set up everything we need for rendering into it. ShowBase.__init__(self) # This code puts the standard title and instruction text on screen self.title = OnscreenText(text="Panda3D: Tutorial - Tasks", parent=base.a2dBottomRight, scale=.07, align=TextNode.ARight, pos=(-0.1, 0.1), fg=(1, 1, 1, 1), shadow=(0, 0, 0, 0.5)) self.escapeText = genLabelText("ESC: Quit", 0) self.leftkeyText = genLabelText("[Left Arrow]: Turn Left (CCW)", 1) self.rightkeyText = genLabelText("[Right Arrow]: Turn Right (CW)", 2) self.upkeyText = genLabelText("[Up Arrow]: Accelerate", 3) self.spacekeyText = genLabelText("[Space Bar]: Fire", 4) # Disable default mouse-based camera control. This is a method on the # ShowBase class from which we inherit. self.disableMouse() # Load the background starfield. self.setBackgroundColor((0, 0, 0, 1)) self.bg = loadObject("stars.jpg", scale=146, depth=200, transparency=False) # Load the ship and set its initial velocity. self.ship = loadObject("ship.png") self.setVelocity(self.ship, LVector3.zero()) # A dictionary of what keys are currently being pressed # The key events update this list, and our task will query it as input self.keys = {"turnLeft": 0, "turnRight": 0, "accel": 0, "fire": 0} self.accept("escape", sys.exit) # Escape quits # Other keys events set the appropriate value in our key dictionary self.accept("arrow_left", self.setKey, ["turnLeft", 1]) self.accept("arrow_left-up", self.setKey, ["turnLeft", 0]) self.accept("arrow_right", self.setKey, ["turnRight", 1]) self.accept("arrow_right-up", self.setKey, ["turnRight", 0]) self.accept("arrow_up", self.setKey, ["accel", 1]) self.accept("arrow_up-up", self.setKey, ["accel", 0]) self.accept("space", self.setKey, ["fire", 1]) # Now we create the task. taskMgr is the task manager that actually # calls the function each frame. The add method creates a new task. # The first argument is the function to be called, and the second # argument is the name for the task. It returns a task object which # is passed to the function each frame. self.gameTask = taskMgr.add(self.gameLoop, "gameLoop") # Stores the time at which the next bullet may be fired. self.nextBullet = 0.0 # This list will stored fired bullets. self.bullets = [] # Complete initialization by spawning the asteroids. self.spawnAsteroids()
def __init__(self): ShowBase.__init__(self) getModelPath().appendDirectory("data") self.AST_INIT_VEL = 0.6 self.score = 0 self.lives = 5 self.BULLET_LIFE = 1.5 self.BULLET_SPEED = 15 self.BULLET_REPEAT = .2 self.AST_VEL_SCALE = 1.2 self.disableMouse() #self.ss = OnscreenText(text="0", parent=base.a2dTopLeft, pos=(0.07, -.06 * 1 - 0.1),fg=(1, 1, 1, 1), align=TextNode.ALeft, shadow=(0, 0, 0, 0.5), scale=.12) self.ss = OnscreenText(text="0", parent=base.a2dTopLeft, pos=(0.2, -0.1), scale=0.08, fg=(1, 1, 1, 1)) # self.ll = OnscreenText(text="5", parent=base.a2dTopLeft, pos=(2.4, -1.76 * 1 - 0.1),fg=(1, 1, 1, 1), align=TextNode.ALeft, shadow=(0, 0, 0, 0.5), scale=.12) self.ll = OnscreenText(text="5", parent=base.a2dTopLeft, pos=(2.5, -1.95), scale=0.08, fg=(1, 1, 1, 1)) self.setBackgroundColor((0, 0, 0, 1)) self.bg = loadObject("stars.png", scale=146, depth=200, transparency=False) self.ship = loadObject("ship.png") self.setVelocity(self.ship, LVector3.zero()) self.ship.hide() self.keys = {"turnLeft": 0, "turnRight": 0, "accel": 0, "fire": 0} self.accept("escape", sys.exit) self.accept("arrow_left", self.setKey, ["turnLeft", 1]) self.accept("arrow_left-up", self.setKey, ["turnLeft", 0]) self.accept("arrow_right", self.setKey, ["turnRight", 1]) self.accept("arrow_right-up", self.setKey, ["turnRight", 0]) self.accept("arrow_up", self.setKey, ["accel", 1]) self.accept("arrow_up-up", self.setKey, ["accel", 0]) self.accept("space", self.setKey, ["fire", 1]) self.gameon = 0 self.gton = 0 self.startgame() mySound = loader.loadSfx("music.wav") myInterval = SoundInterval(mySound, loop=1) myInterval.loop()
def __init__(self, engine): self.eng = engine self.nextBullet = 0.0 # Internal Game State self.bullets_fired = 0 self.bullets_hit = 0 self.bullets_num = BULLET_LIMIT self.ship_firing = 0 # #~ self.life = 10 self.life = SHIP_LIFE self.alive = 1 self.game_score = 0 self.crash = 0 self.ship = self.loadObject("ship2.png", scale=2) self.setVelocity(self.ship, LVector3.zero())
def __init__(self, p3d_proto=None, obs_pixel=0, act_disc=0): # Initialize the ShowBase class from which we inherit, which will # create a window and set up everything we need for rendering into it. ShowBase.__init__(self) self.p3d_proto = p3d_proto self.obs_pixel = obs_pixel self.act_disc = act_disc globalClock.setFrameRate(30) # MNormal:0 MNoneRealTime:1 MForced:2 MLimited:5 #~ globalClock.setMode(0) globalClock.setMode(1) self.exitFunc=on_exit # Internal Game State self.bullets_fired = 0 self.bullets_hit = 0 self.bullets_num = BULLET_LIMIT self.ship_firing = 0 # self.ship_arrow = P3DCreateAxes(length=GUN_RANGE/SCREEN_X) self.ship_arrow1 = P3DCreateAxes(length=AVOID_DIST/SCREEN_X) #~ self.ast_arrow = P3DCreateAxes(length=GUN_RANGE/SCREEN_X) #~ self.ast_arrow1 = P3DCreateAxes(length=AVOID_DIST/SCREEN_X) self.bullets_text = OnscreenText(text="bullets %d"%self.bullets_num, parent=base.a2dBottomRight, scale=.1, align=TextNode.ALeft, pos=(-1.99, 1.9), fg=(0, 1, 0, 1), shadow=(0, 0, 0, 0.5)) # This code puts the standard title and instruction text on screen #~ self.title = OnscreenText(text="Panda3D: Tutorial - Tasks", #~ parent=base.a2dBottomRight, scale=.07, #~ align=TextNode.ARight, pos=(-0.1, 0.1), #~ fg=(1, 1, 1, 1), shadow=(0, 0, 0, 0.5)) #~ self.escapeText = genLabelText("ESC: Quit", 0) #~ self.leftkeyText = genLabelText("[Left Arrow]: Turn Left (CCW)", 1) #~ self.rightkeyText = genLabelText("[Right Arrow]: Turn Right (CW)", 2) #~ self.upkeyText = genLabelText("[Up Arrow]: Accelerate", 3) #~ self.spacekeyText = genLabelText("[Space Bar]: Fire", 4) # Disable default mouse-based camera control. This is a method on the # ShowBase class from which we inherit. self.disableMouse() # Load the background starfield. self.setBackgroundColor((0, 0, 0, 1)) self.bg = loadObject("stars.jpg", scale=146, depth=200, transparency=False) # Load the ship and set its initial velocity. self.ship = loadObject("ship.png", scale=2) self.setVelocity(self.ship, LVector3.zero()) # A dictionary of what keys are currently being pressed # The key events update this list, and our task will query it as input self.keys = {"turnLeft": 0, "turnRight": 0, "accel": 0, "fire": 0} #~ self.accept("escape", sys.exit) # Escape quits self.accept("escape", on_exit) # Escape quits # Other keys events set the appropriate value in our key dictionary self.accept("arrow_left", self.setKey, ["turnLeft", 1]) self.accept("arrow_left-up", self.setKey, ["turnLeft", 0]) self.accept("arrow_right", self.setKey, ["turnRight", 1]) self.accept("arrow_right-up", self.setKey, ["turnRight", 0]) self.accept("arrow_up", self.setKey, ["accel", 1]) self.accept("arrow_up-up", self.setKey, ["accel", 0]) self.accept("space", self.setKey, ["fire", 1]) # Now we create the task. taskMgr is the task manager that actually # calls the function each frame. The add method creates a new task. # The first argument is the function to be called, and the second # argument is the name for the task. It returns a task object which # is passed to the function each frame. self.gameTask = taskMgr.add(self.gameLoop, "gameLoop") # Stores the time at which the next bullet may be fired. self.nextBullet = 0.0 # This list will stored fired bullets. self.bullets = [] # Complete initialization by spawning the asteroids. self.spawnAsteroids()