Exemple #1
0
    def __init__(self, display, roomName=ROOM.TEST_ROOM):

        super(Game, self).__init__(display) #@TODO: fix me!
        self.controls = Controller()
        self.status = StatusBox()
        self.status.capture()

        # add the status bar sprites. the status
        # box is an event handler so they'll just
        # change on their own, but we have to add
        # them to the sprite group so they show up
        # on screen...        
        self.sprites = SpriteGear(self.display)
        for bar in self.status.bars.values():
            self.sprites.sprites.add(bar)

        if roomName == ROOM.TEST_ROOM:
            self.room = makeTestRoom()
            # a block to play with:
            self.sprites.sprites.add(
                BlockSprite(
                self.room.addBlock((SCREEN.WIDTH/2+150,SCREEN.HEIGHT-100), 32, 32),
                pygame.image.load(IMAGE.SOCCER)))
        
        else:
            self.room = loader.roomFromFile(open(ROOM.DIRECTORY+roomName+"-geom.svg"))

            
        self.sprites.fromRoom(self.room, roomName)
        # finally, note the hero:
        self.hero = self.room.hero
Exemple #2
0
    def __init__(self, display):

        super(LevelList, self).__init__(display) #@TODO: fix me!
        self.controls = Controller()
        self.status = StatusBox()
        self.status.capture()
	self.display = display

	roomList = os.listdir (ROOM.DIRECTORY)

	display.addFont (self.FONTSIZE)

	self.roomList = []
	self.selected = 0

	for x in roomList:
		if len(x) > 4:
			if x[len(x)-4:] == ".svg":
				self.roomList.append (x)
				
        self.roomList = ["outside","joe1"]
	self.levelCount = len(self.roomList)
Exemple #3
0
    def __init__(self, **kwargs):
        super(Diagnostics, self).__init__(**kwargs)

        self.status = StatusBox(pos_hint={
            "x": 0.75,
            "y": 0.02
        },
                                size_hint=(0.25, 0.9))
        self.add_widget(self.status)

        self.rv = RV(pos_hint={"x": 0.02, "y": 0.02}, size_hint=(0.7, 0.2))
        self.add_widget(self.rv)

        self.tabs = Datatabs(pos_hint={
            "x": 0.02,
            "y": 0.25
        },
                             size_hint=(0.7, 0.65))
        self.add_widget(self.tabs)

        self.bind(errors=self.streamline_errors)
        #self.bind(data=self.update_data)
        self.bind(errors=self.update_errors)
Exemple #4
0
class Game(State):

    def __init__(self, display, roomName=ROOM.TEST_ROOM):

        super(Game, self).__init__(display) #@TODO: fix me!
        self.controls = Controller()
        self.status = StatusBox()
        self.status.capture()

        # add the status bar sprites. the status
        # box is an event handler so they'll just
        # change on their own, but we have to add
        # them to the sprite group so they show up
        # on screen...        
        self.sprites = SpriteGear(self.display)
        for bar in self.status.bars.values():
            self.sprites.sprites.add(bar)

        if roomName == ROOM.TEST_ROOM:
            self.room = makeTestRoom()
            # a block to play with:
            self.sprites.sprites.add(
                BlockSprite(
                self.room.addBlock((SCREEN.WIDTH/2+150,SCREEN.HEIGHT-100), 32, 32),
                pygame.image.load(IMAGE.SOCCER)))
        
        else:
            self.room = loader.roomFromFile(open(ROOM.DIRECTORY+roomName+"-geom.svg"))

            
        self.sprites.fromRoom(self.room, roomName)
        # finally, note the hero:
        self.hero = self.room.hero
        


    def EVT_GAME_RIGHT(self, event):
        """
        when the player tells us to go right, we
        should move the hero to the right in our world.
        """
        self.hero.run(RIGHT)

    def EVT_GAME_LEFT(self, event):
        self.hero.run(LEFT)

    def EVT_GAME_JUMP(self, event):
        self.hero.jump()

    def EVT_GAME_QUIT(self, event):
        self.done = True
        
    def heroPosition(self):
        """
        Get the position of our intrepid kiwi.
        """
        return self.hero.getPosition()

    def tick(self):
        self.room.physics.step()
        self.room.hero.step()
        self.room.hero.metabolism.eat(Food(5,5, self.room, (0,0))) # hack to lower metabolism
        self.controls.tick()
        self.sprites.tick()
        
    def kick(self):
        super(Game, self).kick()
        self.sprites.refresh()
Exemple #5
0
class LevelList(State):
    FONTSIZE = 30

    def __init__(self, display):

        super(LevelList, self).__init__(display) #@TODO: fix me!
        self.controls = Controller()
        self.status = StatusBox()
        self.status.capture()
	self.display = display

	roomList = os.listdir (ROOM.DIRECTORY)

	display.addFont (self.FONTSIZE)

	self.roomList = []
	self.selected = 0

	for x in roomList:
		if len(x) > 4:
			if x[len(x)-4:] == ".svg":
				self.roomList.append (x)
				
        self.roomList = ["outside","joe1"]
	self.levelCount = len(self.roomList)


    def EVT_LEVELLIST_DOWN(self, event):
        """
        when the player tells us to go right, we
        should move the hero to the right in our world.
        """
        #self.hero.run(RIGHT)
	#self.moveDown();
	print "DOWN"
	self.selected += 1

	if self.selected >= len(self.roomList):
		self.selected = len(self.roomList)-1

    def EVT_LEVELLIST_UP(self, event):
        #self.hero.run(LEFT)
	self.selected-=1
	if self.selected < 0:
		self.selected = 0

    def EVT_LEVELLIST_ENTER(self, event):
        self.done = True
        print "SELECTED %s" % self.roomList[self.selected]        
        self.next = Game(self.display,
                         roomName=self.roomList[self.selected])
        
    def EVT_KeyDown(self, event):
        if not self.done:
            if event.key == pg.K_UP:
                eventnet.driver.post(LEVELLIST.UP)
            elif event.key == pg.K_DOWN:
                eventnet.driver.post(LEVELLIST.DOWN)
            elif event.key == pg.K_RETURN:
                eventnet.driver.post(LEVELLIST.ENTER)
            

    def tick(self):
	self.display.clear()

	i = 0

        for x in self.roomList:
		if i == self.selected:
			color = (255,255,255,255)
		else:
			color = (200,200,200,255)

		self.display.text (x[:len(x)], self.FONTSIZE, [320, 240-len(self.roomList)*self.FONTSIZE/1.3+i*self.FONTSIZE/1.3], color, Display.CENTER)
		i+=1

	self.display.flip()
        
    def kick(self):
        super(LevelList, self).kick()
        self.selected = 0
        self.tick()