Exemplo n.º 1
0
	def handleiconclick(self, vicon):
		if vicon == "trash":
			if panels.selectedtile is not None:
				panels.claimtile()
				self.clearselections()
		elif vicon == "zoomin":
			vista.zoomin()
		elif vicon == "zoomout":
			vista.zoomout()
		elif vicon == "menu":
			game.save()
			context.push(menu.Menu())
		elif vicon == "music":
			noise.nexttrack()
		elif vicon == "heal":
			game.state.body.core.setbranchstatus()
			if self.healmode:
				self.clearselections()
			else:
				self.clearselections()
				if vista.icons["heal"].active:
					self.healmode = True
		elif vicon == "cut":
			if self.cutmode:
				self.clearselections()
			else:
				self.clearselections()
				if vista.icons["cut"].active:
					self.cutmode = True
Exemplo n.º 2
0
    def think(self, dt, events, keys, mousepos, buttons):

        if self.paused:
            if any(e.type == KEYDOWN or e.type == MOUSEBUTTONDOWN for e in events):
                self.resume()
            return


        if vista.vrect.collidepoint(mousepos):
            edge = vista.grid.nearestedge(vista.screentoworld(mousepos))
            if edge != self.edgepoint:
                if self.panel.selected is not None:
                    appspec = self.panel.tiles[self.panel.selected]
                    self.parttobuild = self.body.canplaceapp(edge, appspec)
                elif self.status.selected is not None:
                    otype = self.status.selected
                    self.parttobuild = self.body.canplaceorgan(edge, otype)
                if self.parttobuild is not None:
                    worldpos = vista.HexGrid.edgeworld(*edge)
                    visible = self.body.mask.isvisible(worldpos)
                    self.canbuild = self.body.canaddpart(self.parttobuild) and visible
                    self.parttobuild.status = "ghost" if self.canbuild else "badghost"
        else:
            edge = None
            self.parttobuild = None
        self.edgepoint = edge

        for event in events:
            if event.type == KEYDOWN and event.key == K_SPACE:
                if settings.debugkeys:
                    self.body.addrandompart()
            if event.type == KEYDOWN and event.key == K_BACKSPACE:
                if settings.debugkeys:
                    self.body.addrandompart(20)
            if event.type == KEYDOWN and event.key == K_v:
                if settings.debugkeys:
                    wpos = vista.screentoworld(mousepos)
                    print "Visibility:", self.body.mask.visibility(wpos)
            if event.type == KEYUP and event.key == K_x:
                if settings.debugkeys:
                    if self.target is not None:
                        self.target.die()
            if event.type == MOUSEBUTTONDOWN and event.button == 1:
                self.clickat = event.pos
            if event.type == MOUSEBUTTONUP and event.button == 1:
                self.handleleftclick(mousepos)
            if event.type == MOUSEBUTTONUP and event.button == 3:
                self.handlerightclick(mousepos)
            if event.type == MOUSEBUTTONUP and event.button == 4 and settings.zoomonscroll:
                vista.zoomin()
            if event.type == MOUSEBUTTONUP and event.button == 5 and settings.zoomonscroll:
                vista.zoomout()
            if event.type == MOUSEMOTION and event.buttons[0]:
                self.handleleftdrag(event.pos, event.rel)

        if settings.showtips:
            tip.settip(self.choosetip(mousepos))

        if keys[K_F5] and settings.debugkeys:
            self.body.addrandompart()

        if (keys[K_x] and settings.debugkeys) or self.cutmode:
            newtarget = self.pointchildbyedge(mousepos)
            if newtarget != self.target:
                if self.target is not None:
                    self.target.setbranchstatus()
                self.target = newtarget
                if self.target is not None:
                    self.target.setbranchstatus("target")
        elif self.healmode:
            self.body.sethealstatus()
            self.target = self.body.nearestorgan(vista.screentoworld(mousepos))
        elif self.target is not None:
            self.target.setbranchstatus()
            self.target = None

        vista.think(dt, mousepos, keys)
        vista.icons["cut"].selected = self.cutmode
        vista.icons["heal"].selected = self.healmode

        self.body.think(dt, self.status.healmeter)
        self.panel.think(dt)
        self.status.think(dt, mousepos)
        self.twinklers += twinkler.newtwinklers(self.body.mask, dt)
        for t in self.twinklers:
            t.think(dt)
        self.twinklers = [t for t in self.twinklers if t.alive()]
        self.body.claimtwinklers(self.twinklers)
        self.body.attackenemies(self.shots)
        if random.random() < dt:
            self.shots += enemy.newshots(self.body)
        for s in self.shots: s.think(dt)
        self.shots = [s for s in self.shots if s.alive()]
        self.status.setheights(self.body.maxmutagen, self.body.maxplaster)
        self.status.mutagenmeter.amount += self.body.checkmutagen()
        self.status.healmeter.amount += self.body.checkplaster()
        tip.think(dt)
        self.twinklers += enemy.spoils
        del enemy.spoils[:]
        self.shots += enemy.spawnedshots
        del enemy.spawnedshots[:]
Exemplo n.º 3
0
    def handleleftclick(self, mousepos):

        if self.clickat is None:  # It's a drag
            return
        (x0, y0), (x1, y1) = self.clickat, mousepos
        if abs(x0-x1) + abs(y0-y1) > 25:
            return
    
        bicon = self.status.iconpoint(mousepos)  # Any build icons pointed to
        vicon = vista.iconhit(mousepos)  # Any vista icons pointed to
        if vicon == "trash":
            if self.panel.selected is not None:
                self.panel.claimtile()
                noise.play("trash")
            self.clearselections()
        elif vicon == "zoomin":
            vista.zoomin()
        elif vicon == "zoomout":
            vista.zoomout()
        elif vicon == "pause":
            self.pause()
        elif vicon == "music":
            noise.nexttrack()
        elif vicon == "heal":
            self.body.core.setbranchstatus()
            if self.healmode:
                self.clearselections()
            else:
                self.clearselections()
                if vista.icons["heal"].active:
                    self.healmode = True
        elif vicon == "cut":
            if self.cutmode:
                self.clearselections()
            else:
                self.clearselections()
                if vista.icons["cut"].active:
                    self.cutmode = True
        elif vista.prect.collidepoint(mousepos):  # Click on panel
            self.clearselections(clearpanel = False)
            jtile = self.panel.iconp(mousepos)
            if jtile in (None, 0, 1, 2, 3, 4, 5):
                self.panel.selecttile(jtile)
        elif bicon is not None:
            self.clearselections(clearstatus = False)
            self.status.select(bicon.name)
        elif vista.vrect.collidepoint(mousepos):
            if self.cutmode and self.target is not None:
                self.target.die()
                self.clearselections()
            elif self.healmode and self.target is not None:
                self.target.autoheal = not self.target.autoheal
            elif self.parttobuild is not None and self.canbuild and self.body.canaddpart(self.parttobuild):
                if self.panel.selected is not None:
                    self.panel.claimtile()
                if self.status.selected is not None:
                    self.status.build()
                self.body.addpart(self.parttobuild)
                self.clearselections()
            else:
                worldpos = vista.screentoworld(mousepos)
                if vista.HexGrid.nearesttile(worldpos) == (0,0):
                    settings.showtips = not settings.showtips
                    noise.play("addpart")
Exemplo n.º 4
0
    def think(self, dt, events, keys, mousepos, buttons):

        if self.paused:
            if any(e.type == KEYDOWN or e.type == MOUSEBUTTONDOWN
                   for e in events):
                self.resume()
            return

        if vista.vrect.collidepoint(mousepos):
            edge = vista.grid.nearestedge(vista.screentoworld(mousepos))
            if edge != self.edgepoint:
                if self.panel.selected is not None:
                    appspec = self.panel.tiles[self.panel.selected]
                    self.parttobuild = self.body.canplaceapp(edge, appspec)
                elif self.status.selected is not None:
                    otype = self.status.selected
                    self.parttobuild = self.body.canplaceorgan(edge, otype)
                if self.parttobuild is not None:
                    worldpos = vista.HexGrid.edgeworld(*edge)
                    visible = self.body.mask.isvisible(worldpos)
                    self.canbuild = self.body.canaddpart(
                        self.parttobuild) and visible
                    self.parttobuild.status = "ghost" if self.canbuild else "badghost"
        else:
            edge = None
            self.parttobuild = None
        self.edgepoint = edge

        for event in events:
            if event.type == KEYDOWN and event.key == K_SPACE:
                if settings.debugkeys:
                    self.body.addrandompart()
            if event.type == KEYDOWN and event.key == K_BACKSPACE:
                if settings.debugkeys:
                    self.body.addrandompart(20)
            if event.type == KEYDOWN and event.key == K_v:
                if settings.debugkeys:
                    wpos = vista.screentoworld(mousepos)
                    print "Visibility:", self.body.mask.visibility(wpos)
            if event.type == KEYUP and event.key == K_x:
                if settings.debugkeys:
                    if self.target is not None:
                        self.target.die()
            if event.type == MOUSEBUTTONDOWN and event.button == 1:
                self.clickat = event.pos
            if event.type == MOUSEBUTTONUP and event.button == 1:
                self.handleleftclick(mousepos)
            if event.type == MOUSEBUTTONUP and event.button == 3:
                self.handlerightclick(mousepos)
            if event.type == MOUSEBUTTONUP and event.button == 4 and settings.zoomonscroll:
                vista.zoomin()
            if event.type == MOUSEBUTTONUP and event.button == 5 and settings.zoomonscroll:
                vista.zoomout()
            if event.type == MOUSEMOTION and event.buttons[0]:
                self.handleleftdrag(event.pos, event.rel)

        if settings.showtips:
            tip.settip(self.choosetip(mousepos))

        if keys[K_F5] and settings.debugkeys:
            self.body.addrandompart()

        if (keys[K_x] and settings.debugkeys) or self.cutmode:
            newtarget = self.pointchildbyedge(mousepos)
            if newtarget != self.target:
                if self.target is not None:
                    self.target.setbranchstatus()
                self.target = newtarget
                if self.target is not None:
                    self.target.setbranchstatus("target")
        elif self.healmode:
            self.body.sethealstatus()
            self.target = self.body.nearestorgan(vista.screentoworld(mousepos))
        elif self.target is not None:
            self.target.setbranchstatus()
            self.target = None

        vista.think(dt, mousepos, keys)
        vista.icons["cut"].selected = self.cutmode
        vista.icons["heal"].selected = self.healmode

        self.body.think(dt, self.status.healmeter)
        self.panel.think(dt)
        self.status.think(dt, mousepos)
        self.twinklers += twinkler.newtwinklers(self.body.mask, dt)
        for t in self.twinklers:
            t.think(dt)
        self.twinklers = [t for t in self.twinklers if t.alive()]
        self.body.claimtwinklers(self.twinklers)
        self.body.attackenemies(self.shots)
        if random.random() < dt:
            self.shots += enemy.newshots(self.body)
        for s in self.shots:
            s.think(dt)
        self.shots = [s for s in self.shots if s.alive()]
        self.status.setheights(self.body.maxmutagen, self.body.maxplaster)
        self.status.mutagenmeter.amount += self.body.checkmutagen()
        self.status.healmeter.amount += self.body.checkplaster()
        tip.think(dt)
        self.twinklers += enemy.spoils
        del enemy.spoils[:]
        self.shots += enemy.spawnedshots
        del enemy.spawnedshots[:]
Exemplo n.º 5
0
    def handleleftclick(self, mousepos):

        if self.clickat is None:  # It's a drag
            return
        (x0, y0), (x1, y1) = self.clickat, mousepos
        if abs(x0 - x1) + abs(y0 - y1) > 25:
            return

        bicon = self.status.iconpoint(mousepos)  # Any build icons pointed to
        vicon = vista.iconhit(mousepos)  # Any vista icons pointed to
        if vicon == "trash":
            if self.panel.selected is not None:
                self.panel.claimtile()
                noise.play("trash")
            self.clearselections()
        elif vicon == "zoomin":
            vista.zoomin()
        elif vicon == "zoomout":
            vista.zoomout()
        elif vicon == "pause":
            self.pause()
        elif vicon == "music":
            noise.nexttrack()
        elif vicon == "heal":
            self.body.core.setbranchstatus()
            if self.healmode:
                self.clearselections()
            else:
                self.clearselections()
                if vista.icons["heal"].active:
                    self.healmode = True
        elif vicon == "cut":
            if self.cutmode:
                self.clearselections()
            else:
                self.clearselections()
                if vista.icons["cut"].active:
                    self.cutmode = True
        elif vista.prect.collidepoint(mousepos):  # Click on panel
            self.clearselections(clearpanel=False)
            jtile = self.panel.iconp(mousepos)
            if jtile in (None, 0, 1, 2, 3, 4, 5):
                self.panel.selecttile(jtile)
        elif bicon is not None:
            self.clearselections(clearstatus=False)
            self.status.select(bicon.name)
        elif vista.vrect.collidepoint(mousepos):
            if self.cutmode and self.target is not None:
                self.target.die()
                self.clearselections()
            elif self.healmode and self.target is not None:
                self.target.autoheal = not self.target.autoheal
            elif self.parttobuild is not None and self.canbuild and self.body.canaddpart(
                    self.parttobuild):
                if self.panel.selected is not None:
                    self.panel.claimtile()
                if self.status.selected is not None:
                    self.status.build()
                self.body.addpart(self.parttobuild)
                self.clearselections()
            else:
                worldpos = vista.screentoworld(mousepos)
                if vista.HexGrid.nearesttile(worldpos) == (0, 0):
                    settings.showtips = not settings.showtips
                    noise.play("addpart")
Exemplo n.º 6
0
	def think(self, dt, events, keys, mousepos, buttons):
		if vista.vrect.collidepoint(mousepos):
			edge = vista.grid.nearestedge(vista.screentoworld(mousepos))
			if edge != self.edgepoint:
				if panels.selectedtile is not None:
					appspec = status.state.tiles[panels.selectedtile]
					self.parttobuild = game.state.body.canplaceapp(edge, appspec)
				elif panels.selectedorgan is not None:
					otype = panels.selectedorgan
					self.parttobuild = game.state.body.canplaceorgan(edge, otype)
				if self.parttobuild is not None:
					worldpos = vista.HexGrid.edgeworld(*edge)
					visible = game.state.body.mask.isvisible(worldpos)
					self.canbuild = game.state.body.canaddpart(self.parttobuild) and visible
					self.parttobuild.status = "ghost" if self.canbuild else "badghost"
		else:
			edge = None
			self.parttobuild = None
		self.edgepoint = edge
		
		for event in events:
			if event.type == KEYDOWN and event.key == K_SPACE:
				if settings.debugkeys:
					game.state.body.addrandompart()
			if event.type == KEYDOWN and event.key == K_BACKSPACE:
				if settings.debugkeys:
					game.state.body.addrandompart(20)
			if event.type == KEYDOWN and event.key == K_v:
				if settings.debugkeys:
					wpos = vista.screentoworld(mousepos)
					print("Visibility:", game.state.body.mask.visibility(wpos))
			if event.type == KEYUP and event.key == K_x:
				if settings.debugkeys:
					if self.target is not None:
						self.target.die()
			if event.type == KEYUP and event.key == K_F11:
				context.push(makemap.MakeMap())
			if event.type == KEYUP and event.key == K_F9:
				context.push(restart.Restart())
			if event.type == MOUSEBUTTONDOWN and event.button == 1:
				self.clickat = event.pos
			if event.type == MOUSEBUTTONUP and event.button == 1:
				self.handleleftclick(mousepos)
			if event.type == MOUSEBUTTONUP and event.button == 3:
				self.handlerightclick(mousepos)
			if event.type == MOUSEBUTTONUP and event.button == 4 and settings.zoomonscroll:
				vista.zoomin()
			if event.type == MOUSEBUTTONUP and event.button == 5 and settings.zoomonscroll:
				vista.zoomout()
			if event.type == MOUSEMOTION and event.buttons[0]:
				self.handleleftdrag(event.pos, event.rel)
		
		if settings.showtips:
			tip.settip(self.choosetip(mousepos))
		
		if keys[K_F5] and settings.debugkeys:
			game.state.body.addrandompart()
		
		if (keys[K_x] and settings.debugkeys) or self.cutmode:
			newtarget = self.pointchildbyedge(mousepos)
			if newtarget != self.target:
				if self.target is not None:
					self.target.setbranchstatus()
				self.target = newtarget
				if self.target is not None:
					self.target.setbranchstatus("target")
		elif self.healmode:
			game.state.body.sethealstatus()
			self.target = game.state.body.nearestorgan(vista.screentoworld(mousepos))
		elif self.target is not None:
			self.target.setbranchstatus()
			self.target = None
		
		vista.think(dt, mousepos, keys)
		vista.icons["cut"].selected = self.cutmode
		vista.icons["heal"].selected = self.healmode
		
		game.state.think(dt)
		status.state.think(dt)
		tip.think(dt)