Esempio n. 1
0
    def setup(self) -> None:
        # Set scene.Scene attributes
        self.background_color = "black"

        self.root = scene.Node(parent=self)

        self.new_game()
        if os.path.isfile(SAVE_FILE):
            self.show_resume_menu()
Esempio n. 2
0
    def new_game(self):
        # Create the ground node...
        # Usually, nodes are added to their parent using the 'add_child()' method, but for convenience, you can also pass
        # the node's parent as a keyword argument for the same effect
        self.ground = sc.Node(parent=self)
        ground_x = 0
        tile_width = 64

        # Increment ground_x until the edge of the screen is reached
        while ground_x <= self.size.w + tile_width:
            tile = sc.SpriteNode('plf:Ground_GrassMid', position=(ground_x, 0))
            self.ground.add_child(tile)
            ground_x += tile_width

        # Reset everything to its initial state...
        for item in self.items:
            item.remove_from_parent()
        self.items = []

        for block in self.blocks:
            block.remove_from_parent()
        self.blocks = []

        self.current_blocks = np.array([])

        self.lasers = []

        # Create the first instance of a Block class. This will help with positioning of blocks later in the game
        block = Block(parent=self)
        block.position = (random.uniform(27, self.size.w - 27),
                          random.uniform(100, 200))
        block.z_position = -1
        self.blocks.append(block)

        # Initialise jump counter and the jumped method to determine if the player has performed the first jump
        self.count = -1
        self.jumped = False

        # Set the current score to zero, and the player position to the default starting position
        self.score = 0
        self.score_label.text = '0'
        self.player.position = (self.size.w / 2, 32)
        self.player.texture = jumping_texture

        # Set the difficulty of the game back to its initial state
        self.speed = 1.0

        # The game_over attribute is set to True when the alien dies. We use this to stop player movement and collision checking (the update method simply does nothing when game_over is True).
        self.game_over = False

        # Check if the 'camera view' is moving
        self.moving = False
        self.jump_counter = 0

        # Reset velocity scale and step of the enemies in the game
        self.vel_scale = 1
        self.step = 0
Esempio n. 3
0
	def setup(self):
		center = self.bounds.center()
		sun = scene.SpriteNode('emj:Sun_1', position=center, parent=self)
		earth_anchor = scene.Node(position=center, parent=self)
		earth = scene.SpriteNode('emj:Moon_5', position=(0, 150))
		earth_anchor.add_child(earth)
		A = scene.Action
		self_rotate_action = A.repeat(A.sequence(A.rotate_to(20 * pi, 5),
		A.rotate_to(0, 0), 0), 0)
		earth.run_action(self_rotate_action)
		rotate_action = A.repeat(A.sequence(A.rotate_to(20 * pi, 20),
		A.rotate_to(0, 0), 0), 0)
		earth_anchor.run_action(rotate_action)
Esempio n. 4
0
 def setup(self):
     center = self.bounds.center()
     sun = scene.SpriteNode('plc:Star', position=center, parent=self)
     earth_anchor = scene.Node(position=center, parent=self)
     earth = scene.SpriteNode('plc:Tree_Ugly', position=(0, 150))
     earth_anchor.add_child(earth)
     self_rotate_action = scene.Action.repeat(
         scene.Action.sequence(scene.Action.rotate_to(20 * pi, 5),
                               scene.Action.rotate_to(0, 0), 0), 0)
     earth.run_action(self_rotate_action)
     rotate_action = scene.Action.repeat(
         scene.Action.sequence(scene.Action.rotate_to(20 * pi, 20),
                               scene.Action.rotate_to(0, 0), 0), 0)
     earth_anchor.run_action(rotate_action)
Esempio n. 5
0
 def __init__(self,dofft=False):
    self.v=[scene.SpriteNode() for x in range(int(Np))]
    for i,sp in enumerate(self.v):
       sp.size=(1.5,1.5)
       sp.position=(float(i)/Np*W,H/2)
       sp.color=(1.0*i/Np,(1-1.0*i/Np),(0.5+i/2.0))
       self.add_child(sp)
    # first, start r[0]
    # then, 0.5 sec later, start r[1]
    # then, 0.5 sec later, start r[2], stop r[0]
    # read r[0], then start r[0], stop r[1]
    # basically, each frame we read/start one, and stop i+1
    self.a1=scene.Action.call(self.update_y)
    self.a2=scene.Action.wait(T/(Nr-1))
    self.a3=scene.Action.sequence([self.a1,self.a2])
    self.a4=scene.Action.repeat(self.a3,-1)
    n=scene.Node()
    n.name='n'
    self.add_child(n)
    n.run_action(self.a4)
    self.dofft=dofft
    self.idx=0
 def setup(self):
     #self.label_text = 'ABCDEFGHIJKLMNOPQR'
     self.label_text = 'abcdefghijklmnopqrstuvwxyz'
     length = len(self.label_text)
     center = self.bounds.center()
     self.font_size = 40
     self.pixel_size = .6 * self.font_size
     self.main_node = scene.Node(
         position=(center[0] - length / 2.0 * self.pixel_size, center[1]),
         parent=self)
     self.label_node = [None] * len(self.label_text)
     A = scene.Action
     for i in range(len(self.label_text)):
         self.label_node[i] = scene.LabelNode(self.label_text[i],
                                              font=('Courier',
                                                    self.font_size),
                                              position=(self.pixel_size * i,
                                                        0),
                                              parent=self.main_node)
         custom_action_i = partial(custom_action, i)
         animate_action = A.repeat(A.call(custom_action_i, 5), 0)
         self.label_node[i].run_action(animate_action)
Esempio n. 7
0
 def setup(self):
     #self.label_text = 'ABCDEFGHIJKLMNOPQR'
     self.label_text = 'abcdefghijklmnopqrstuvwxyz'
     length = len(self.label_text)
     center = self.bounds.center()
     self.font_size = 60
     self.pixel_size = .6*self.font_size
     self.main_node = scene.Node(position=(center[0]-length/2.0*self.pixel_size,
         center[1]), parent=self)
     self.label_node = [None]*len(self.label_text)
     self.pos1 = [None]*len(self.label_text)
     self.pos2 = [None]*len(self.label_text)
     for i in range(len(self.label_text)):
         self.pos1[i] = (800*random.random()+100, 600*random.random()-300)
         self.pos2[i] = (self.pixel_size*i*1.0, 0.0)
     A = scene.Action
     for i in range(len(self.label_text)):
         self.label_node[i] = scene.LabelNode(self.label_text[i],
                 font=('Courier', self.font_size),
                 position=self.pos1[i], parent=self.main_node)
         animate_action = A.repeat(A.sequence(
                                     A.move_to(self.pos2[i][0], self.pos2[i][1], 8),
                                     A.move_to(self.pos1[i][0], self.pos1[i][1], 8)), 0)
         self.label_node[i].run_action(animate_action)
Esempio n. 8
0
 def setup(self):
     self.background_color='red'
     self.xoff = 0
     self.root = scene.Node(parent=self)
     self.p = Plot(parent=self.root, xsize=0.35, ysize=0.2, position=(0.5, 0.1), nticks=3, goal=.0)
     self.p.position = (0.05, 0.5)
Esempio n. 9
0
    def setup(self):
        color_gps = "#2299ff"
        self.background_color = "#161616"

        self.scrw = numpy.min([440, self.size.w])
        self.scrh = self.size.h / self.size.w * self.scrw
        self.scale = self.size.h / self.scrh

        self.adiCenter = [self.scrw / 2.0, self.scrh - 155]
        self.pxPerDeg = 10

        self.hdg_mode = True
        self.dtk = 0.0
        self.yaw_history = list()

        ADI = scene.Node(parent=self)
        ADI.position = self.adiCenter

        # Attitude pitch marks
        #self.pitchMarks=scene.SpriteNode("IMG_2130.JPG")

        self.pitchMarks = sg.adi_pitchBars(self.pxPerDeg)
        ADI.add_child(self.pitchMarks)
        self.rollPointer = sg.adi_rollPointer(150)
        ADI.add_child(self.rollPointer)
        self.yawPointer = sg.adi_yawPointer(150)
        ADI.add_child(self.yawPointer)

        ADI.add_child(sg.adi_ac())
        ADI.add_child(sg.adi_rollMarks(150))

        # Location labels
        locationNode = scene.ShapeNode(scene.ui.Path.rect(0, 0, 200, 48))
        locationNode.anchor_point = [0.0, 0.99]
        locationNode.position = [0.0, self.scrh]
        locationNode.fill_color = "#000000"

        h = 24
        self.lbl_lat = scene.LabelNode("%3.3f" % 0)
        self.lbl_lat.position = [0, 0]
        self.lbl_lat.anchor_point = [0, 1.0]
        self.lbl_lat.color = color_gps
        locationNode.add_child(self.lbl_lat)
        self.lbl_lon = scene.LabelNode("%3.3f" % 0)
        self.lbl_lon.position = [0, -h]
        self.lbl_lon.anchor_point = [0, 1.0]
        self.lbl_lon.color = color_gps
        locationNode.add_child(self.lbl_lon)

        adi_height = 280
        hsi_height = self.scrh - adi_height
        altNode = scene.ShapeNode(scene.ui.Path.rect(0, 0, self.scrw + 1,
                                                     self.scrh - adi_height),
                                  "#000000",
                                  parent=self)
        altNode.anchor_point = (0.0, 0.0)
        altNode.position = [-1.0, -1.0]

        # Alt label
        [alt_symbol, self.txt_alth, self.txt_altd] = sg.alt_display(ADI)
        alt_symbol.position = [self.scrw / 2, 0.0]

        # GS label
        [gs_symbol, self.txt_spd] = sg.gs_display(ADI)
        gs_symbol.position = [-self.scrw / 2, 0.0]

        # HSI
        self.cdi_r = 180.0
        [self.rose] = sg.compass_rose(altNode, self.cdi_r)
        self.rose.position = [
            self.scrw / 2, self.scrh - adi_height - self.cdi_r - 32
        ]

        [self.cdi_needle, self.cdi_track] = sg.cdi(self.cdi_r)

        [ac] = sg.ac_symbol(altNode)
        ac.position = [self.scrw / 2, self.scrh - adi_height - self.cdi_r - 32]

        # Heading label
        h = 30
        [self.hdg_symbol, self.txt_hdg] = sg.hdg_display(altNode, h)
        self.hdg_symbol.position = [self.scrw / 2, hsi_height + 10]

        # Waypoint info display
        [self.wpt_dsp, self.wpt_name, self.wpt_dtk,
         self.wpt_dist] = sg.wpt_display(altNode)
        self.wpt_dsp.position = [0, hsi_height]

        self.wpt = ""
        self.scratchpad = sg.scratchpad(self, self.scrw, 128)

        # G meter
        [g_symbol, self.txt_g] = sg.g_display(ADI)
        g_symbol.position = [self.scrw / 2, -adi_height / 3]

        location.start_updates()
        motion.start_updates()

        self.isInit = True
        print(self.pitchMarks)
        print("PFD initialized")
Esempio n. 10
0
 def __init__(self):
     scene.Scene.__init__(self)
     self.background_color = 'midnightblue'
     self.add_child(scene.Node())  # Dummy node as a bugfix
     pass