/usr/lib/games/solarwolf/gamepref.py is in solarwolf 1.5-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | """Game Settings Control for SolarWolf."""
import string, math
import pygame
from pygame.locals import *
import game
import gfx, snd, txt
import input
import score
import gameplay
Prefs = {
"music": ("Off", "Low", "Normal"),
"volume": ("Off", "Low", "Normal"),
"display": ("Window", "Fullscreen"),
"comments": ("None", "Some", "Chatty"),
"help": ("Full Screens", "Quick Comments"),
"thruster": ("Normal", "Inverted"),
}
def load_prefs():
prefs = {}
try:
filename = game.make_dataname('prefs')
for line in open(filename).readlines():
name, val = [s.strip() for s in line.split('=')]
setattr(game, name, int(val))
except (IOError, OSError, KeyError):
#print 'ERROR OPENING PREFS FILE'
pass
def save_prefs():
try:
filename = game.make_dataname('prefs')
f = open(filename, 'w')
for p in Prefs.keys():
val = getattr(game, p)
f.write("%s = %d\n" % (p, int(val)))
f.close()
except (IOError, OSError), msg:
#print 'ERROR SAVING PREFS FILE'
pass
images = []
namefont = None
valuefont = None
def load_game_resources():
global images, namefont, valuefont
img = pygame.transform.rotate(gfx.load('ship-up.png'), -90)
images.append((img, img.get_rect()))
img = gfx.load('menu_setup_on.png')
images.append((img, img.get_rect().move(20, 20)))
namefont = txt.Font(None, 42)
valuefont = txt.Font(None, 36)
snd.preload('select_choose', 'select_move', 'delete')
class GamePref:
def __init__(self, prevhandler):
self.prevhandler = prevhandler
self.images = images
self.prefs = []
for n,v in Prefs.items():
self.prefs.append((n,v))
self.prefs.append(("", ("Return To Menu",)))
self.done = 0
self.aborted = 0
self.linesize = 60
self.gamelist = []
self.buildlabels()
self.buildlist()
self.current = [0, 0]
self.shipmovex = 40
self.shipmovey = 16
step = 0
self.moveto(self.gamelist[0][0][1])
def starting(self):
#snd.playmusic('gamestart.wav')
pass
def moveto(self, pos):
self.shippos = pos[0], pos[1]
def input(self, i):
if self.done:
return
if i.release:
return
if i.translated == input.ABORT:
self.aborted = 1
self.done = 1
self.current[0] = -1
self.clearlist()
self.moveto((2, 2))
snd.play('select_choose')
if i.translated == input.PRESS:
return self.pressed()
if i.translated in (input.DOWN, input.UP, input.LEFT, input.RIGHT):
if i.translated == input.DOWN:
self.current[0] = (self.current[0]+1) % len(self.gamelist)
self.current[1] = min(self.current[1], len(self.gamelist[self.current[0]])-1)
elif i.translated == input.UP:
self.current[0] = (self.current[0]-1) % len(self.gamelist)
self.current[1] = min(self.current[1], len(self.gamelist[self.current[0]])-1)
elif i.translated == input.LEFT:
self.current[1] = (self.current[1]-1) % len(self.gamelist[self.current[0]])
else:
self.current[1] = (self.current[1]+1) % len(self.gamelist[self.current[0]])
snd.play('select_move')
x = self.gamelist[self.current[0]][self.current[1]][1].left
y = self.gamelist[self.current[0]][self.current[1]][1].top
self.moveto((x, y))
def event(self, e):
pass
def run(self):
r = self.background(self.images[0][1])
gfx.dirty(r)
self.moveship()
gfx.updatestars(self.background, gfx)
if not self.done:
self.drawlist()
for img in self.images:
r = gfx.surface.blit(img[0], img[1])
gfx.dirty(r)
else:
game.handler = self.prevhandler
self.clearlist()
for img in self.images[1:]:
r = self.background(img[1])
gfx.dirty(r)
def background(self, area):
return gfx.surface.fill((0, 0, 0), area)
def buildlabels(self):
clr = 160, 200, 250
x, y = 190, 170
for pref, vals in self.prefs:
pref = pref.capitalize()
imgpos = namefont.text(clr, pref, (x,y), "midright")
images.append(imgpos)
y += self.linesize
def buildlist(self):
clr = 220, 230, 240
clr2 = 140, 150, 160
offsetx, offsety = 260, 170
self.clearlist()
self.gamelist = []
for pref, vals in self.prefs:
x = offsetx
y = offsety
if not pref:
y += 30
allvals = []
if pref:
realval = getattr(game, pref)
else:
realval = -1
i = 0
for val in vals:
if i == realval:
c = clr
else:
c = clr2
imgpos = valuefont.text(c, val, (x,y), "midleft")
allvals.append(imgpos)
x = imgpos[1].right + 60
i += 1
self.gamelist.append(allvals)
offsety += self.linesize
def clearlist(self):
for vals in self.gamelist:
for v in vals:
gfx.dirty(self.background(v[1]))
def drawlist(self):
for vals in self.gamelist:
for v in vals:
gfx.dirty(gfx.surface.blit(*v))
def moveship(self):
pos = list(self.images[0][1].topright)
if pos[0] + self.shipmovex < self.shippos[0]:
pos[0] += self.shipmovex
elif pos[0] < self.shippos[0]:
pos[0] = self.shippos[0]
if pos[0] - self.shipmovex > self.shippos[0]:
pos[0] -= self.shipmovex
elif pos[0] > self.shippos[0]:
pos[0] = self.shippos[0]
if pos[1] + self.shipmovey < self.shippos[1]:
pos[1] += self.shipmovey
elif pos[1] < self.shippos[1]:
pos[1] = self.shippos[1]
if pos[1] - self.shipmovey > self.shippos[1]:
pos[1] -= self.shipmovey
elif pos[1] > self.shippos[1]:
pos[1] = self.shippos[1]
self.images[0][1].topright = pos
def pressed(self):
pref, vals = self.prefs[self.current[0]]
if not pref:
snd.play('select_choose')
self.done = 1
else:
val = self.current[1]
oldval = getattr(game, pref)
if oldval == val:
return
setattr(game, pref, val)
self.buildlist()
#some of these need callbacks, music/volume/display
if hasattr(self, "do_" + pref):
getattr(self, "do_" + pref)()
snd.play('select_choose')
def do_music(self):
snd.tweakmusicvolume()
def do_display(self):
gfx.switchfullscreen()
|