Module Credits
[hide private]
[frames] | no frames]

Source Code for Module Credits

  1  ##################################################################### 
  2  # -*- coding: iso-8859-1 -*-                                        # 
  3  #                                                                   # 
  4  # Frets on Fire                                                     # 
  5  # Copyright (C) 2006 Sami Kyöstilä                                  # 
  6  #                                                                   # 
  7  # This program is free software; you can redistribute it and/or     # 
  8  # modify it under the terms of the GNU General Public License       # 
  9  # as published by the Free Software Foundation; either version 2    # 
 10  # of the License, or (at your option) any later version.            # 
 11  #                                                                   # 
 12  # This program is distributed in the hope that it will be useful,   # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of    # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     # 
 15  # GNU General Public License for more details.                      # 
 16  #                                                                   # 
 17  # You should have received a copy of the GNU General Public License # 
 18  # along with this program; if not, write to the Free Software       # 
 19  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,        # 
 20  # MA  02110-1301, USA.                                              # 
 21  ##################################################################### 
 22   
 23  import pygame 
 24  from OpenGL.GL import * 
 25  from OpenGL.GLU import * 
 26  import math 
 27   
 28  from View import Layer 
 29  from Input import KeyListener 
 30  from Language import _ 
 31  import MainMenu 
 32  import Song 
 33  import Version 
 34  import Player 
 35   
36 -class Element:
37 """A basic element in the credits scroller."""
38 - def getHeight(self):
39 """@return: The height of this element in fractions of the screen height""" 40 return 0
41
42 - def render(self, offset):
43 """ 44 Render this element. 45 46 @param offset: Offset in the Y direction in fractions of the screen height 47 """ 48 pass
49
50 -class Text(Element):
51 - def __init__(self, font, scale, color, alignment, text):
52 self.text = text 53 self.font = font 54 self.color = color 55 self.alignment = alignment 56 self.scale = scale 57 self.size = self.font.getStringSize(self.text, scale = scale)
58
59 - def getHeight(self):
60 return self.size[1]
61
62 - def render(self, offset):
63 if self.alignment == "left": 64 x = .1 65 elif self.alignment == "right": 66 x = .9 - self.size[0] 67 elif self.alignment == "center": 68 x = .5 - self.size[0] / 2 69 glColor4f(*self.color) 70 self.font.render(self.text, (x, offset), scale = self.scale)
71
72 -class Picture(Element):
73 - def __init__(self, engine, fileName, height):
74 self.height = height 75 self.engine = engine 76 engine.loadSvgDrawing(self, "drawing", fileName)
77
78 - def getHeight(self):
79 return self.height
80
81 - def render(self, offset):
82 self.drawing.transform.reset() 83 w, h = self.engine.view.geometry[2:4] 84 self.drawing.transform.translate(.5 * w, h - (.5 * self.height + offset) * h * float(w) / float(h)) 85 self.drawing.transform.scale(1, -1) 86 self.drawing.draw()
87
88 -class Credits(Layer, KeyListener):
89 """Credits scroller."""
90 - def __init__(self, engine, songName = None):
91 self.engine = engine 92 self.time = 0.0 93 self.offset = 1.0 94 self.songLoader = self.engine.resource.load(self, "song", lambda: Song.loadSong(self.engine, "defy", playbackOnly = True), 95 onLoad = self.songLoaded) 96 self.engine.loadSvgDrawing(self, "background1", "editor.svg") 97 self.engine.loadSvgDrawing(self, "background2", "keyboard.svg") 98 self.engine.loadSvgDrawing(self, "background3", "cassette.svg") 99 self.engine.boostBackgroundThreads(True) 100 101 nf = self.engine.data.font 102 bf = self.engine.data.bigFont 103 ns = 0.002 104 bs = 0.001 105 hs = 0.003 106 c1 = (1, 1, .5, 1) 107 c2 = (1, .75, 0, 1) 108 109 space = Text(nf, hs, c1, "center", " ") 110 self.credits = [ 111 Text(nf, ns, c2, "center", _("Unreal Voodoo")), 112 Text(nf, ns, c1, "center", _("presents")), 113 Text(nf, bs, c2, "center", " "), 114 Picture(self.engine, "logo.svg", .25), 115 Text(nf, bs, c2, "center", " "), 116 Text(nf, bs, c2, "center", _("Version %s") % Version.version()), 117 space, 118 Text(nf, ns, c1, "left", _("Game Design,")), 119 Text(nf, ns, c1, "left", _("Programming:")), 120 Text(nf, ns, c2, "right", "Sami Kyostila"), 121 space, 122 Text(nf, ns, c1, "left", _("Music,")), 123 Text(nf, ns, c1, "left", _("Sound Effects:")), 124 Text(nf, ns, c2, "right", "Tommi Inkila"), 125 space, 126 Text(nf, ns, c1, "left", _("Graphics:")), 127 Text(nf, ns, c2, "right", "Joonas Kerttula"), 128 space, 129 Text(nf, ns, c1, "left", _("Introducing:")), 130 Text(nf, ns, c2, "right", "Mikko Korkiakoski"), 131 Text(nf, ns, c2, "right", _("as Jurgen, Your New God")), 132 space, 133 Text(nf, ns, c2, "right", "Marjo Hakkinen"), 134 Text(nf, ns, c2, "right", _("as Groupie")), 135 space, 136 Text(nf, ns, c1, "left", _("Song Credits:")), 137 Text(nf, ns, c2, "right", _("Bang Bang, Mystery Man")), 138 Text(nf, bs, c2, "right", _("music by Mary Jo and Tommi Inkila")), 139 Text(nf, bs, c2, "right", _("lyrics by Mary Jo")), 140 space, 141 Text(nf, ns, c2, "right", _("Defy The Machine")), 142 Text(nf, bs, c2, "right", _("music by Tommi Inkila")), 143 space, 144 Text(nf, ns, c2, "right", _("This Week I've Been")), 145 Text(nf, ns, c2, "right", _("Mostly Playing Guitar")), 146 Text(nf, bs, c2, "right", _("composed and performed by Tommi Inkila")), 147 space, 148 Text(nf, ns, c1, "left", _("Testing:")), 149 Text(nf, ns, c2, "right", "Mikko Korkiakoski"), 150 Text(nf, ns, c2, "right", "Tomi Kyostila"), 151 Text(nf, ns, c2, "right", "Jani Vaarala"), 152 Text(nf, ns, c2, "right", "Juho Jamsa"), 153 Text(nf, ns, c2, "right", "Olli Jakola"), 154 space, 155 Text(nf, ns, c1, "left", _("Mac OS X port:")), 156 Text(nf, ns, c2, "right", "Tero Pihlajakoski"), 157 space, 158 Text(nf, ns, c1, "left", _("Special thanks to:")), 159 Text(nf, ns, c2, "right", "Tutorial inspired by adam02"), 160 space, 161 Text(nf, ns, c1, "left", _("Made with:")), 162 Text(nf, ns, c2, "right", "Python"), 163 Text(nf, bs, c2, "right", "http://www.python.org"), 164 space, 165 Text(nf, ns, c2, "right", "PyGame"), 166 Text(nf, bs, c2, "right", "http://www.pygame.org"), 167 space, 168 Text(nf, ns, c2, "right", "PyOpenGL"), 169 Text(nf, bs, c2, "right", "http://pyopengl.sourceforge.net"), 170 space, 171 Text(nf, ns, c2, "right", "Amanith Framework"), 172 Text(nf, bs, c2, "right", "http://www.amanith.org"), 173 space, 174 Text(nf, ns, c2, "right", "Illusoft Collada module 1.4"), 175 Text(nf, bs, c2, "right", "http://colladablender.illusoft.com"), 176 space, 177 Text(nf, ns, c2, "right", "Psyco specializing compiler"), 178 Text(nf, bs, c2, "right", "http://psyco.sourceforge.net"), 179 space, 180 Text(nf, ns, c2, "right", "MXM Python Midi Package 0.1.4"), 181 Text(nf, bs, c2, "right", "http://www.mxm.dk/products/public/pythonmidi"), 182 space, 183 space, 184 Text(nf, bs, c1, "center", _("Source Code available under the GNU General Public License")), 185 Text(nf, bs, c2, "center", "http://www.unrealvoodoo.org"), 186 space, 187 space, 188 space, 189 space, 190 Text(nf, bs, c1, "center", _("Copyright 2006, 2007 by Unreal Voodoo")), 191 ]
192
193 - def songLoaded(self, song):
194 self.engine.boostBackgroundThreads(False) 195 song.play()
196
197 - def shown(self):
198 self.engine.input.addKeyListener(self)
199
200 - def hidden(self):
201 if self.song: 202 self.song.fadeout(1000) 203 self.engine.input.removeKeyListener(self) 204 self.engine.view.pushLayer(MainMenu.MainMenu(self.engine))
205
206 - def quit(self):
207 self.engine.view.popLayer(self)
208
209 - def keyPressed(self, key, unicode):
210 if self.engine.input.controls.getMapping(key) in [Player.CANCEL, Player.KEY1, Player.KEY2] or key == pygame.K_RETURN: 211 self.songLoader.cancel() 212 self.quit() 213 return True
214
215 - def run(self, ticks):
216 self.time += ticks / 50.0 217 if self.song: 218 self.offset -= ticks / 5000.0 219 220 if self.offset < -6.1: 221 self.quit()
222
223 - def render(self, visibility, topMost):
224 v = 1.0 - ((1 - visibility) ** 2) 225 226 # render the background 227 t = self.time / 100 + 34 228 w, h, = self.engine.view.geometry[2:4] 229 r = .5 230 for i, background in [(0, self.background1), (1, self.background2), (2, self.background3)]: 231 background.transform.reset() 232 background.transform.translate((1 - v) * 2 * w + w / 2 + math.cos(t / 2) * w / 2 * r, h / 2 + math.sin(t) * h / 2 * r) 233 background.transform.translate(0, -h * (((self.offset + i * 2) % 6.0) - 3.0)) 234 background.transform.rotate(math.sin(t * 4 + i) / 2) 235 background.transform.scale(math.sin(t / 8) + 3, math.sin(t / 8) + 3) 236 background.draw() 237 238 self.engine.view.setOrthogonalProjection(normalize = True) 239 font = self.engine.data.font 240 241 # render the scroller elements 242 y = self.offset 243 glTranslatef(-(1 - v), 0, 0) 244 try: 245 for element in self.credits: 246 h = element.getHeight() 247 if y + h > 0.0 and y < 1.0: 248 element.render(y) 249 y += h 250 if y > 1.0: 251 break 252 finally: 253 self.engine.view.resetProjection()
254