Exemplo n.º 1
0
def think(dt, events, mousepos):
	global mpos, cursor, point
	sound.playmusic("equip")
	if settings.pauseondialog and state.state.playing:
		dialog.think(dt)
		for event in events:
			if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and state.state.tline > 0.5:
				dialog.advance()
		dt = 0
	point = pointat(mousepos)
	for event in events:
		if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
			scene.pop()
			gamescene.makebuttons()
		if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
			handleclick()
		if event.type == pygame.MOUSEBUTTONDOWN and event.button == 2:
			cursor = None
	mpos = mousepos
	dialog.think(dt)
	for b in buttons:
		if b.name.startswith("buy"):
			cname = "conduit-" + b.name[3:]
			b.text = "Buy: $%d\nAvail: %d" % (settings.modulecosts[cname], state.state.unused[cname])
			b.makeimg()
	for q in state.state.quests:
		q.think(dt)
Exemplo n.º 2
0
def think(dt, events, kpress, mpos):
	global alpha, playing
	playing = bool(hud.finaldialoguebox)
	if playing:
		alpha = min(1 * dt + alpha, 1)
	else:
		alpha -= 1 * dt
		if alpha <= 0:
			scene.pop()
			return
	sound.setvolume(alpha)

	if kpress[K_ESCAPE]:
		playing = False

	for event in events:
		if event.type == MOUSEBUTTONDOWN:
			if event.button == 1:
				hud.finaldialoguebox.settext(lines.pop(0) if lines else None)
		if event.type == KEYDOWN and event.key == K_SPACE:
			hud.finaldialoguebox.settext(lines.pop(0) if lines else None)
		if event.type == KEYDOWN and event.key == K_ESCAPE:
			hud.finaldialoguebox.settext()
		if event.type == KEYDOWN and event.key == K_F12:
			graphics.screenshot()

	dx, dy, dr, dA = -0.02 * dt, -0.005 * dt, 0, 0
	camera.move(1 * dx, 1 * dy, 0.7 * dr, 0.7 * dA)
	camera.think(dt)

	hud.think(dt)
Exemplo n.º 3
0
 def use_scene(self, index):
     if scene.current is not None:
         scene.current.closed()
     scene.pop()
     scene.push(self.scenes[index])
     scene.current.loaded()
     scene.current.__class__.__class__.__name__
Exemplo n.º 4
0
def play():
	if state.canload():
		state.load()
		scene.pop()
		scene.push(gamescene)
		scene.push(buildscene)
	else:
		state.reset()
		scene.pop()
		scene.push(gamescene)
		scene.push(cutscene)
Exemplo n.º 5
0
def think(dt, events, mpos):
    sound.playmusic("boss" if state.state.bossmode else "travel")
    if settings.pauseondialog and state.state.playing:
        dialog.think(dt)
        for event in events:
            if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and state.state.tline > 0.5:
                dialog.advance()
        dt = 0

    for event in events:
        if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            handleclick(event.pos)
        if event.type == pygame.KEYDOWN and event.key == pygame.K_F1 and settings.DEBUG:
            scene.push(buildscene)
        if event.type == pygame.KEYDOWN and event.key == pygame.K_F2 and settings.DEBUG:
            state.state.you.x = state.state.mother.x
            state.state.you.y = state.state.mother.y
        if event.type == pygame.KEYDOWN and event.key == pygame.K_F3 and settings.DEBUG:
            state.state.bank += 1
        if event.type == pygame.KEYDOWN and event.key == pygame.K_F4 and settings.DEBUG:
            state.state.bank += 10
        if event.type == pygame.KEYDOWN and event.key == pygame.K_F5 and settings.DEBUG:
            state.state.bank += 100
    global mapmode
    mapmode = any(b.name == "scope" and b.within(mpos) for b in buttons)

    state.state.think(dt)
    vista.think(dt)
    dialog.think(dt)
    for b in buttons:
        b.think(dt)

    if state.state.mother.within((state.state.you.x, state.state.you.y)):
        if apart["mother"]:
            apart["mother"] = False
            scene.push(buildscene)
            state.state.you.x = state.state.mother.x
            state.state.you.y = state.state.mother.y
            state.state.you.allstop()
    else:
        apart["mother"] = True

    global shroud
    if shroud:
        alpha = shroud.get_alpha()
        alpha = int(alpha - 200 * dt)
        if alpha <= 0:
            shroud = None
        else:
            shroud.set_alpha(alpha)
    if not state.state.you.corpse.alive:
        import menuscene
        scene.pop()
        scene.push(menuscene)
Exemplo n.º 6
0
def play():
	if state.canload():
		state.load()
		scene.pop()
		scene.push(gamescene)
		scene.push(buildscene)
	else:
		state.reset()
		scene.pop()
		scene.push(gamescene)
		scene.push(cutscene)
Exemplo n.º 7
0
def think(dt, events, mpos):
	sound.playmusic("boss" if state.state.bossmode else "travel")
	if settings.pauseondialog and state.state.playing:
		dialog.think(dt)
		for event in events:
			if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and state.state.tline > 0.5:
				dialog.advance()
		dt = 0

	for event in events:
		if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
			handleclick(event.pos)
		if event.type == pygame.KEYDOWN and event.key == pygame.K_F1 and settings.DEBUG:
			scene.push(buildscene)
		if event.type == pygame.KEYDOWN and event.key == pygame.K_F2 and settings.DEBUG:
			state.state.you.x = state.state.mother.x
			state.state.you.y = state.state.mother.y
		if event.type == pygame.KEYDOWN and event.key == pygame.K_F3 and settings.DEBUG:
			state.state.bank += 1
		if event.type == pygame.KEYDOWN and event.key == pygame.K_F4 and settings.DEBUG:
			state.state.bank += 10
		if event.type == pygame.KEYDOWN and event.key == pygame.K_F5 and settings.DEBUG:
			state.state.bank += 100
	global mapmode
	mapmode = any(b.name == "scope" and b.within(mpos) for b in buttons)

	state.state.think(dt)
	vista.think(dt)
	dialog.think(dt)
	for b in buttons:
		b.think(dt)

	if state.state.mother.within((state.state.you.x, state.state.you.y)):
		if apart["mother"]:
			apart["mother"] = False
			scene.push(buildscene)
			state.state.you.x = state.state.mother.x
			state.state.you.y = state.state.mother.y
			state.state.you.allstop()
	else:
		apart["mother"] = True

	global shroud
	if shroud:
		alpha = shroud.get_alpha()
		alpha = int(alpha - 200 * dt)
		if alpha <= 0:
			shroud = None
		else:
			shroud.set_alpha(alpha)
	if not state.state.you.corpse.alive:
		import menuscene
		scene.pop()
		scene.push(menuscene)
Exemplo n.º 8
0
def handleclick():
	global cursor
	if isinstance(point, tuple):
		if cursor:
			icon = cursor.nearest(point)
			if state.state.canaddpart(icon):
				state.state.addpart(icon)
				sound.play("build")
				cursor = None
			else:
				sound.play("cantbuild")
		else:
			part = state.state.partat(map(int, point))
			if part:
				state.state.removepart(part)
				sound.play("unbuild")
	elif isinstance(point, basestring):
		if point == "Remove All":
			state.state.removeall()
			sound.play("unbuild")
		elif point == "Depart" and state.state.cango():
			scene.pop()
			gamescene.makebuttons()
		elif point.startswith("buy"):
			cname = "conduit-" + point[3:]
			state.state.buy(cname)
	elif isinstance(point, parts.Conduit):
		if cursor is point:
			for j in range(len(controls)):
				if controls[j] is cursor:
					controls[j] = cursor = cursor.rotate(1)
		elif state.state.unused[point.name]:
			cursor = point
		else:
			sound.play("cantpick")
	elif isinstance(point, parts.Part):
		if cursor is point:
			cursor = None
		elif point.name in state.state.unlocked:
			if state.state.unused[point.name]:
				cursor = point
			else:
				sound.play("cantpick")
		else:
			state.state.unlock(point.name)
	elif point is None:
		cursor = None
	state.save()
Exemplo n.º 9
0
	def think(self, dt, kpressed, kdowns):
		self.t += dt
		if K_ESCAPE in kdowns or K_p in kdowns:
			if settings.DEBUG:
				scene.pop()
			else:
				scene.scenes.append(PauseScene(self))
		dx = int(kpressed[K_RIGHT] or kpressed[K_d] or kpressed[K_e]) - int(kpressed[K_LEFT] or kpressed[K_a])
		jumping = any(k in kdowns for k in (K_UP, K_w, K_COMMA, K_SPACE, K_RETURN, K_DOWN, K_s, K_o))
		shooting = state.mode in ["quest", "boss"]
		#shooting = kpressed[K_SPACE]
		state.player.control(dx, jumping, shooting)
		if settings.DEBUG and K_F2 in kdowns:
			state.player.hurt()
		if settings.DEBUG and K_F3 in kdowns:
			state.player.hp = state.hpmax
		if settings.DEBUG and K_F4 in kdowns:
			state.addboss()
		if settings.DEBUG and K_F5 in kdowns:
			state.beatboss()
		state.think(dt)
Exemplo n.º 10
0
def think(dt, events, kpress, mpos):

	global alpha
	if playing:
		alpha = min(2 * dt + alpha, 1)
	else:
		alpha -= 2 * dt
		if alpha <= 0:
			if selected is None:
				scene.pop()
			else:
				scene.push(scenes.dialogue)
			return
	sound.setvolume(alpha)

	if kpress[K_ESCAPE]:
		scene.pop()

	for event in events:
		if event.type == MOUSEBUTTONDOWN and event.button == 1:
			px, py = mpos
			if hud.click((px, settings.sy - py)):
				continue
		if event.type == KEYDOWN and event.key == K_CAPSLOCK:
			settings.swaparrows = not settings.swaparrows
		if event.type == KEYDOWN and event.key == K_F12:
			graphics.screenshot()

	dx, dy, dr, dA = -0.02 * dt, -0.005 * dt, 0, 0
	camera.move(1 * dx, 1 * dy, 0.7 * dr, 0.7 * dA)
	camera.think(dt)

	px, py = mpos
	hud.point((px, settings.sy - py))

	hud.think(dt)
Exemplo n.º 11
0
def draw():
	vista.screen.fill((255, 255, 255))
	dialog.draw()
	if len(state.state.playing) < 5:
		scene.pop()
Exemplo n.º 12
0
def think(dt):
	global yc, zc, ships, hazards, effects, projectiles, bosses, modetime, tstage, substages
	modetime += dt
	tstage += dt
	yc += dt * vyc
#	zc += (2 - zc) * 0.4 * dt
	adddecoration(dt)
	if mode == "boss":
		addrock = random() * [None, 99999999, 1, 1, 1][stage] < dt
		if addrock:
			x = uniform(-settings.lwidth - 5, settings.lwidth + 5)
			size = choice([1, 1.5, 2, 2.5]), choice([1, 1.2, 1.4, 1.6])
			hazards.append(thing.Rock((x, yc + settings.yrange[1], 0), size))
	while hq and hq[0].y < yc + settings.yrange[1]:
		hazards.append(hq.pop(0))
	while sq and sq[0].y < yc + settings.yrange[1]:
		ships.append(sq.pop(0))
	while eq and eq[0][0] < yc:
		eq.pop(0)[1]()
	oships = [s for s in ships if s is not player]
	if player.alive:
		player.hitany(hazards + oships)
		player.think(dt)
	for h in hazards:
		h.hitany(projectiles)
		h.think(dt)
	for s in oships:
		s.hitany(projectiles)
		s.think(dt)
	for e in effects:
		e.think(dt)
	for p in projectiles:
		p.think(dt)
	ships = [s for s in ships if s.alive]
	hazards = [h for h in hazards if h.alive]
	effects = [e for e in effects if e.alive]
	projectiles = [p for p in projectiles if p.alive]
	if mode == "boss":
		if not any(b.alive for b in bosses):
			beatboss()
	if mode == "reset":
		if not any(t.alive for t in texts):
			if quitting:
				scene.pop()
				return
			setmode("quest")
			start()
			player.x = 0
			player.falling = False
			player.jump(1.4)
	if mode == "gameover":
		if not any(t.alive for t in texts):
			start()
	if mode == "boss":
		if stage == 4:
			img.setshroud((255, 255, 0, 20))
		else:
			img.setshroud((0, 0, 20, 40))
	elif mode == "quest":
		img.setshroud((20, 20, 60, 50))
	elif mode == "reset":
		img.setshroud((100, 100, 140, 50))
	elif mode == "gameover":
		img.setshroud((140, 0, 0, 80))
Exemplo n.º 13
0
def draw():
    vista.screen.fill((255, 255, 255))
    dialog.draw()
    if len(state.state.playing) < 5:
        scene.pop()
Exemplo n.º 14
0
def quit():
	scene.pop()
Exemplo n.º 15
0
def quit():
	scene.pop()
Exemplo n.º 16
0
def think(dt):
    global yc, zc, ships, hazards, effects, projectiles, bosses, modetime, tstage, substages
    modetime += dt
    tstage += dt
    yc += dt * vyc
    #	zc += (2 - zc) * 0.4 * dt
    adddecoration(dt)
    if mode == "boss":
        addrock = random() * [None, 99999999, 1, 1, 1][stage] < dt
        if addrock:
            x = uniform(-settings.lwidth - 5, settings.lwidth + 5)
            size = choice([1, 1.5, 2, 2.5]), choice([1, 1.2, 1.4, 1.6])
            hazards.append(thing.Rock((x, yc + settings.yrange[1], 0), size))
    while hq and hq[0].y < yc + settings.yrange[1]:
        hazards.append(hq.pop(0))
    while sq and sq[0].y < yc + settings.yrange[1]:
        ships.append(sq.pop(0))
    while eq and eq[0][0] < yc:
        eq.pop(0)[1]()
    oships = [s for s in ships if s is not player]
    if player.alive:
        player.hitany(hazards + oships)
        player.think(dt)
    for h in hazards:
        h.hitany(projectiles)
        h.think(dt)
    for s in oships:
        s.hitany(projectiles)
        s.think(dt)
    for e in effects:
        e.think(dt)
    for p in projectiles:
        p.think(dt)
    ships = [s for s in ships if s.alive]
    hazards = [h for h in hazards if h.alive]
    effects = [e for e in effects if e.alive]
    projectiles = [p for p in projectiles if p.alive]
    if mode == "boss":
        if not any(b.alive for b in bosses):
            beatboss()
    if mode == "reset":
        if not any(t.alive for t in texts):
            if quitting:
                scene.pop()
                return
            setmode("quest")
            start()
            player.x = 0
            player.falling = False
            player.jump(1.4)
    if mode == "gameover":
        if not any(t.alive for t in texts):
            start()
    if mode == "boss":
        if stage == 4:
            img.setshroud((255, 255, 0, 20))
        else:
            img.setshroud((0, 0, 20, 40))
    elif mode == "quest":
        img.setshroud((20, 20, 60, 50))
    elif mode == "reset":
        img.setshroud((100, 100, 140, 50))
    elif mode == "gameover":
        img.setshroud((140, 0, 0, 80))
Exemplo n.º 17
0
	def think(self, dt, kpressed, kdowns):
		if K_ESCAPE in kdowns or K_p in kdowns:
			scene.pop()
		if K_q in kdowns:
			scene.pop()
			scene.pop()
Exemplo n.º 18
0
def think(dt, events, kpress, mpos):

	global alpha, playing, ending, lastsave
	if playing and not ending:
		alpha = min(2 * dt + alpha, 1)
	elif ending:
		alpha -= 2 * dt
		if alpha <= -6:
			hud.endtitle.settext()
			if not hud.endtitle:
				state.removesave()
				scene.pop()
				return
	else:
		alpha -= 2 * dt
		if alpha <= 0:
			scene.pop()
			return
	sound.setvolume(alpha)

	lastsave += dt
	if settings.savetime is not None and lastsave > settings.savetime:
		lastsave = 0
		state.save()

	if kpress[K_ESCAPE]:
		state.save()
		scene.pop()
		scene.pop()
		playing = False

	dx = ((kpress[K_RIGHT]) - (kpress[K_LEFT])) * dt
	dy = ((kpress[K_UP]) - (kpress[K_DOWN])) * dt
	dr = ((kpress[K_e] or kpress[K_d]) - (kpress[K_a])) * dt
	dA = ((kpress[K_COMMA] or kpress[K_w]) - (kpress[K_o] or kpress[K_s])) * dt

	for event in events:
		if event.type == QUIT:
			state.save()
			scene.pop()
			scene.pop()
			playing = False
		if event.type == MOUSEBUTTONDOWN:
			if event.button == 4:
				camera.zoom /= 1.08
			elif event.button == 5:
				camera.zoom *= 1.08
			else:
				px, py = mpos
				if hud.click((px, settings.sy - py)):
					continue
				p = camera.screentoworld((settings.sx - px, settings.sy - py))
				if p and cursor.tobuild:
					phat = p.norm()
					if state.canbuild(cursor.tobuild, phat) and not state.builderror(cursor.tobuild):
						f = camera.eye().rej(phat).norm()
						state.build(cursor.tobuild(p.norm(), f))
						cursor.tobuild = None
					else:
						sound.play("error")
				elif cursor.pointingto:
					if cursor.unbuild:
						state.unbuild(cursor.pointingto)
					elif cursor.disable:
						state.toggleenable(cursor.pointingto)
				else:
					cursor.dragging = True
		if event.type == MOUSEBUTTONUP:
			cursor.dragging = False
		if event.type == MOUSEMOTION:
			relx, rely = event.rel
			if event.buttons[0]:
				dx -= relx * settings.dragfactor / settings.sy
				dy += rely * settings.dragfactor / settings.sy
			if event.buttons[2]:
				dr -= relx * settings.dragfactor / settings.sy
				dA += rely * settings.dragfactor / settings.sy
#			camera.seek((0, 0, 1))
		if event.type == KEYDOWN and event.key == K_CAPSLOCK:
			settings.swaparrows = not settings.swaparrows
		if event.type == KEYDOWN and event.key == K_F3 and settings.unlocked >= 99:
			if settings.level == 3:
				scene.pushunder(scenes.final)
			ending = True
			hud.endtitle.settext("Mission Complete")
		if event.type == KEYDOWN and event.key == K_F12:
			graphics.screenshot()
		if event.type == KEYDOWN and event.key == K_INSERT:
			camera.zoom /= 1.2
		if event.type == KEYDOWN and event.key == K_DELETE:
			camera.zoom *= 1.2
		if event.type == KEYDOWN and event.key == K_SPACE:
			things.Asteroid(100)

	camera.zoom = min(max(camera.zoom, 30), 200)


	if bool(kpress[K_LSHIFT]) != bool(settings.swaparrows):
		dx, dy, dr, dA = dr, dA, dx, dy
	
	camera.move(40. * dx / state.R, 40. * dy / state.R, 2.5 * dr, 0.7 * dA)
	camera.think(dt)
			

	px, py = mpos
	hud.point((px, settings.sy - py))

	dtobj = dt * settings.speedup

	for obj in state.thinkers():
		obj.think(dtobj)

	hud.think(dt)
	state.think(dtobj)
	
	hud.setstatus()

	if not ending:
		if state.checklose():
			ending = True
			hud.endtitle.settext("Mission Failed")
		elif state.checkwin(dt):
			if settings.level == 3:
				scene.pushunder(scenes.final)
			sound.play("success")
			ending = True
			hud.endtitle.settext("Mission Complete")
			settings.unlocked = max(settings.unlocked, settings.level + 1)
			settings.save()
Exemplo n.º 19
0
    def think(self, dt, events):
        if settings.doubletime:
            dt *= 2
        self.t += dt
        vista.think(dt)
        for event in events:
            if event.type == pygame.KEYDOWN and event.key == pygame.K_TAB:
                vista.swapmode()
            if event.type == pygame.MOUSEBUTTONUP and vista.minirect.collidepoint(event.pos):
                vista.swapmode()
            if event.type == pygame.KEYDOWN and event.key == pygame.K_F11:
                self.won = True
            if event.type == pygame.KEYDOWN and event.key == pygame.K_F10:
                gamestate.hp = 0
            if event.type == pygame.KEYDOWN and event.key == pygame.K_F1:
                gamestate.level = 0
                scene.pop()
                scene.push(GameScene())
            if event.type == pygame.KEYDOWN and event.key == pygame.K_F2:
                gamestate.level = 1
                scene.pop()
                scene.push(GameScene())
            if event.type == pygame.KEYDOWN and event.key == pygame.K_F3:
                gamestate.level = 2
                scene.pop()
                scene.push(GameScene())
            if event.type == pygame.KEYDOWN and event.key == pygame.K_F4:
                gamestate.level = 3
                scene.pop()
                scene.push(GameScene())
            if event.type == pygame.KEYDOWN and event.key == pygame.K_F5:
                gamestate.level = 4
                scene.pop()
                scene.push(GameScene())
                
        if not vista.ftrans and self.losetitle:  # not transitioning
            if vista.mode:
                gamemap.think(dt, events)
            else:
                tech.think(dt, events)

        if self.foequeue and self.t > self.foequeue[0][0]:
            t, cls, path = self.foequeue.pop(0)
            gamestate.foes.append(cls(path))
        
        if gamestate.hp > 0 and not self.foequeue and not gamestate.foes:
            self.won = True
        
        for t in gamestate.towers:
            t.think(dt)
        for f in gamestate.foes:
            f.think(dt)
        for f in gamestate.effects:
            f.think(dt)
        if self.won:
            self.wintitle.think(dt)
            if not self.wintitle:
                gamestate.level += 1
                scene.pop()
                scene.push(GameScene())
        elif gamestate.hp > 0:
            self.title.think(dt)
        else:
            self.losetitle.think(dt)
            gamestate.foes = []
            self.foequeue = []
            if not self.losetitle and gamestate.level < 4:
                scene.pop()
                scene.push(GameScene())
Exemplo n.º 20
0
 def use_scene(self, index):
     scene.pop()
     scene.push(self.scenes[index])
     scene.current.__class__.__class__.__name__
Exemplo n.º 21
0
def clickon(bname):
	soundname = buttons[bname].soundname
	if bname == "buildw":
		if mode == "main":
			buildwmode()
		elif mode == "buildw":
			soundname = "back"
			mainmode()
	elif bname == "buildb":
		if mode == "main":
			buildbmode()
		elif mode == "buildb":
			soundname = "back"
			mainmode()
	elif bname == "buildr":
		if mode == "main":
			buildrmode()
		elif mode == "buildr":
			soundname = "back"
			mainmode()
	elif bname.startswith("build"):
		cursor.tobuild = buttons[bname].btype
	if bname == "launch":
		if mode == "main":
			launchmode()
		elif mode == "launch":
			soundname = "back"
			mainmode()
	elif bname.startswith("launch"):
		if state.launcherror(buttons[bname].ltype):
			soundname = "error"
		else:
			state.launch(buttons[bname].ltype)
			soundname = "launch"

	if bname == "help":
		if mode == "main":
			soundname = "back"
			helpmode()
		elif mode == "help":
			mainmode()
	elif bname == "helpmission":
		labels["helppage"].settext(info.missionhelp[settings.level])
	elif bname.startswith("help"):
		labels["helppage"].settext(info.help[buttons[bname].helpname])

	if bname == "unbuild":
		if mode == "main":
			unbuildmode()
		elif mode == "unbuild":
			soundname = "back"
			mainmode()

	if bname == "unlaunch":
		if mode == "main":
			unlaunchmode()
		elif mode == "unlaunch":
			soundname = "back"
			mainmode()
	elif bname.startswith("unlaunch"):
		state.unlaunch(buttons[bname].ltype)

	if bname == "disable":
		if mode == "main":
			disablemode()
		elif mode == "disable":
			soundname = "back"
			mainmode()

	if bname == "back":
		soundname = "back"
		cursor.tobuild = None
		mainmode()
	
	if bname == "bcancel":
		soundname = "back"
		cursor.tobuild = None

	if bname == "quit":
		soundname = "back"
		quitmode()

	if bname == "abandonquit":
		soundname = "back"
		state.removesave()
		scene.top().playing = False

	if bname == "savequit":
		soundname = "back"
		state.save()
		scene.pop()
		scene.pop()

	if bname == "quitgame":
		scene.top().playing = False


	if bname.startswith("level"):
		scene.top().playing = False
		scene.top().selected = buttons[bname].n

	if bname == "selectlevel":
		if mode == "level":
			soundname = "back"
			menumode()
		else:
			levelmode()
	if bname == "options":
		if mode == "options":
			soundname = "back"
			menumode()
		else:
			optionsmode()
	if bname == "credits":
		if mode == "credits":
			soundname = "back"
			menumode()
		else:
			creditsmode()

	if bname == "soundtoggle":
		settings.sound = not settings.sound
		settings.save()
		sound.setvolume()
	if bname == "musictoggle":
		settings.music = not settings.music
		settings.save()
		sound.setvolume()
	if bname == "fullscreentoggle":
		settings.fullscreen = not settings.fullscreen
		settings.save()
	if bname == "wsizesmall":
		settings.wsize = 640, 360
		settings.save()
	if bname == "wsizemedium":
		settings.wsize = 854, 480
		settings.save()
	if bname == "wsizelarge":
		settings.wsize = 1280, 720
		settings.save()
	if bname == "wsizevlarge":
		settings.wsize = 1920, 1080
		settings.save()
	if mode == "options":
		buttons["soundtoggle"].words = "SOUND: %s" % ("ON" if settings.sound else "OFF")
		buttons["musictoggle"].words = "MUSIC: %s" % ("ON" if settings.music else "OFF")
		buttons["fullscreentoggle"].words = "FULLSCREEN: %s" % ("ON" if settings.fullscreen else "OFF")
		for sname in "small medium large vlarge".split():
			b = buttons["wsize" + sname]
			size = map(int, b.words.split()[-1].split("x"))
			b.color = (180, 255, 180) if tuple(size) == tuple(settings.wsize) else (180, 180, 180)

	sound.play(soundname)