/usr/share/games/fretsonfire/game/Player.py is in fretsonfire-game 1.3.110.dfsg2-5.
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 | #####################################################################
# -*- coding: iso-8859-1 -*- #
# #
# Frets on Fire #
# Copyright (C) 2006 Sami Kyöstilä #
# #
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License #
# as published by the Free Software Foundation; either version 2 #
# of the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, #
# MA 02110-1301, USA. #
#####################################################################
import pygame
import Config
import Song
from Language import _
LEFT = 0x1
RIGHT = 0x2
UP = 0x4
DOWN = 0x8
ACTION1 = 0x10
ACTION2 = 0x20
KEY1 = 0x40
KEY2 = 0x80
KEY3 = 0x100
KEY4 = 0x200
KEY5 = 0x400
CANCEL = 0x800
SCORE_MULTIPLIER = [0, 10, 20, 30]
# define configuration keys
Config.define("player", "key_left", str, "K_LEFT", text = _("Move left"))
Config.define("player", "key_right", str, "K_RIGHT", text = _("Move right"))
Config.define("player", "key_up", str, "K_UP", text = _("Move up"))
Config.define("player", "key_down", str, "K_DOWN", text = _("Move down"))
Config.define("player", "key_action1", str, "K_RETURN", text = _("Pick"))
Config.define("player", "key_action2", str, "K_RSHIFT", text = _("Secondary Pick"))
Config.define("player", "key_1", str, "K_F1", text = _("Fret #1"))
Config.define("player", "key_2", str, "K_F2", text = _("Fret #2"))
Config.define("player", "key_3", str, "K_F3", text = _("Fret #3"))
Config.define("player", "key_4", str, "K_F4", text = _("Fret #4"))
Config.define("player", "key_5", str, "K_F5", text = _("Fret #5"))
Config.define("player", "key_cancel", str, "K_ESCAPE", text = _("Cancel"))
Config.define("player", "name", str, "")
Config.define("player", "difficulty", int, Song.EASY_DIFFICULTY)
class Controls:
def __init__(self):
def keycode(name):
k = Config.get("player", name)
try:
return int(k)
except:
return getattr(pygame, k)
self.flags = 0
self.controlMapping = {
keycode("key_left"): LEFT,
keycode("key_right"): RIGHT,
keycode("key_up"): UP,
keycode("key_down"): DOWN,
keycode("key_action1"): ACTION1,
keycode("key_action2"): ACTION2,
keycode("key_1"): KEY1,
keycode("key_2"): KEY2,
keycode("key_3"): KEY3,
keycode("key_4"): KEY4,
keycode("key_5"): KEY5,
keycode("key_cancel"): CANCEL,
}
# Multiple key support
self.heldKeys = {}
def getMapping(self, key):
return self.controlMapping.get(key)
def keyPressed(self, key):
c = self.getMapping(key)
if c:
self.toggle(c, True)
if c in self.heldKeys and not key in self.heldKeys[c]:
self.heldKeys[c].append(key)
return c
return None
def keyReleased(self, key):
c = self.getMapping(key)
if c:
if c in self.heldKeys:
if key in self.heldKeys[c]:
self.heldKeys[c].remove(key)
if not self.heldKeys[c]:
self.toggle(c, False)
return c
return None
self.toggle(c, False)
return c
return None
def toggle(self, control, state):
prevState = self.flags
if state:
self.flags |= control
return not prevState & control
else:
self.flags &= ~control
return prevState & control
def getState(self, control):
return self.flags & control
class Player(object):
def __init__(self, owner, name):
self.owner = owner
self.controls = Controls()
self.reset()
def reset(self):
self.score = 0
self._streak = 0
self.notesHit = 0
self.longestStreak = 0
self.cheating = False
def getName(self):
return Config.get("player", "name")
def setName(self, name):
Config.set("player", "name", name)
name = property(getName, setName)
def getStreak(self):
return self._streak
def setStreak(self, value):
self._streak = value
self.longestStreak = max(self._streak, self.longestStreak)
streak = property(getStreak, setStreak)
def getDifficulty(self):
return Song.difficulties.get(Config.get("player", "difficulty"))
def setDifficulty(self, difficulty):
Config.set("player", "difficulty", difficulty.id)
difficulty = property(getDifficulty, setDifficulty)
def addScore(self, score):
self.score += score * self.getScoreMultiplier()
def getScoreMultiplier(self):
try:
return SCORE_MULTIPLIER.index((self.streak / 10) * 10) + 1
except ValueError:
return len(SCORE_MULTIPLIER)
|