def __init__(self, surface, lm, im): self.name = 'lobby' self.surface = surface self.lm = lm self.im = im self.data = None super().__init__(self.name, self.surface, self.lm) self.width, self.height = self.surface.get_size() self.player_x = self.width / 4 self.player_y = 7 * self.height / 15 self.checked_data = False self.background = pygame.transform.scale( pygame.image.load( resource_path(os.path.join('resources', 'lobbybackground.png'))), (self.surface.get_width() * 2, self.surface.get_height())) self.nature = pygame.transform.scale( pygame.image.load( resource_path(os.path.join('resources', '8bitnature.png'))), (self.surface.get_width() * 3, self.surface.get_height())) self.p = Player(x=self.player_x, y=self.player_y) self.p.scale = self.height / 15 * 3 self.floor_height = 7 * self.height / 15 + self.p.get_height() self.background_x = 0 self.doors = [ pygame.image.load( resource_path(os.path.join('resources', 'door.png'))) for x in range(3) ] self.text_rect = pygame.Rect( self.width / 8 + self.p.get_width(), self.floor_height + self.p.get_height(), self.width - self.width / 4 - self.p.get_width() * 2, self.height - self.floor_height + self.p.get_height()) self.sign_text = Text( 'Enter levels by pressing "w" in front of the door. To win the TSA competition, you must beat all levels! Good luck! \n Press ENTER to continue.', self.text_rect) self.tutorial_text = Text( 'Move through the main hallway using "A" and "D" keys \nPress ENTER to continue.', self.text_rect) self.tutorial = True self.sign_prompt = False self.has_prompted = False self.alert_rect = pygame.Rect(self.width / 4, self.height / 4, self.width / 2, self.height / 2) self.alerts = [] self.alert_up = False self.current_alert = None self.incoming_data = False
def __init__(self, surface, lm, im): self.name = 'mainmenu' self.surface = surface self.lm = lm self.im = im super().__init__(self.name, surface, lm) # Required so elements can scale according to size rather than have absolute size self.width, self.height = surface.get_size() self.buttons = [] # To store buttons for easy access in event_update self.p = Player(x=self.width / 4, y=7 * self.height / 15) self.p.scale = self.height / 15 * 3 self.background = pygame.transform.scale( pygame.image.load( resource_path( os.path.join('resources', 'mainmenubackground_0.png'))), (self.width, self.height)) # Crude way to create buttons but works, notice that the dimensions are a portion of height/width self.buttons.append( pygbutton.PygButton((self.width / 3, 7 * self.height / 15, self.width / 3, self.height / 16), 'Play')) self.buttons.append( pygbutton.PygButton((self.width / 3, 8 * self.height / 15, self.width / 3, self.height / 16), 'Options')) self.buttons.append( pygbutton.PygButton((self.width / 3, 9 * self.height / 15, self.width / 6, self.height / 16), 'Credits')) self.buttons.append( pygbutton.PygButton((self.width / 2, 9 * self.height / 15, self.width / 6, self.height / 16), 'Quit'))
def __init__(self, surface, lm): self.name = 'credits' self.surface = surface self.lm = lm super().__init__(self.name, surface, lm) self.width, self.height = surface.get_size() self.background = pygame.transform.scale( pygame.image.load( resource_path( os.path.join('resources', 'mainmenubackground_0.png'))), self.surface.get_size()) self.button_rect = pygame.Rect(0, 0, self.width / 8, self.height / 12) self.back_button = pygbutton.PygButton(self.button_rect, 'Back') self.text_rect = pygame.Rect(self.width / 4, self.height / 4, self.width / 2, self.height / 2) self.creds = Text( ''' This game was made by: Declan O'Mara - Lead Software Engineer Tommy Lasagne - Artistic Director John Kachian - ??? Many thanks to: pygame contributors (github.com/pygame/pygame) Al Sweigart, pygbutton developer (github.com/asweigart/pygbutton) All source code can be found at: github.com/declanomara/tsagame''', self.text_rect)
def __init__(self, x=0, y=0, texture=resource_path(os.path.join('resources', 'car.png'))): self.acceleration = 100 self.velocity = 0 self.x = x self.y = y self.texture = pygame.image.load(texture) self.rect = self.texture.get_rect()
def __init__(self, surface, lm, im): self.name = 'level_0' self.surface = surface self.lm = lm self.im = im self.data = None super().__init__(self.name, self.surface, self.lm) self.width, self.height = self.surface.get_size() self.background = pygame.transform.scale( pygame.image.load( resource_path(os.path.join('resources', 'grid.png'))), self.surface.get_size()) self.lights = [ pygame.Rect(self.width * 3 / 8 - self.width / 40, self.height / 8 - self.width / 40, self.width / 20, self.width / 20), pygame.Rect(self.width * 4 / 8 - self.width / 40, self.height / 8 - self.width / 40, self.width / 20, self.width / 20), pygame.Rect(self.width * 5 / 8 - self.width / 40, self.height / 8 - self.width / 40, self.width / 20, self.width / 20) ] self.colors = [(255, 255, 0), (255, 255, 0), (0, 255, 0)] self.p_car = Car(y=self.height * 4 / 16) self.o_car = Car(y=self.height * 6 / 16) self.p_car.rect = pygame.Rect(self.p_car.x, self.p_car.y, self.width / 4, self.height / 4) self.o_car.rect = pygame.Rect(self.o_car.x, self.o_car.y, self.width / 4, self.height / 4) self.info_rect = pygame.Rect(self.width / 8, self.height * 3 / 4, self.width * 3 / 4, self.height / 4) self.info = Text( 'Tap the space bar as each light changes color. On the green light, the race begins. Good luck! \nPress ENTER to continue.', self.info_rect) self.light = -1 self.has_prompted = False self.is_prompting = False self.last_time = None self.was_down = False self.times = [] self.light_times = [] self.completed = False self.simulating = False self.simulated = False
def __init__(self, texture=os.path.join('resources', 'player.png'), x=0, y=0): self.x = x self.y = y self.texture = pygame.image.load(resource_path(texture)) self.rect = self.texture.get_rect() self.scale = 64 self.base_movement_speed = {'x': 1 / 64, 'y': 1 / 48} self.movement_speed = { 'x': self.base_movement_speed['x'] * self.scale * 1000, 'y': self.base_movement_speed['y'] * self.scale * 1000 } self.ratio = 1 / 2
def __init__(self, surface, lm): self.name = 'options' self.surface = surface self.lm = lm super().__init__(self.name, surface, lm) self.width, self.height = surface.get_size() self.background = pygame.transform.scale( pygame.image.load( resource_path( os.path.join('resources', 'mainmenubackground_0.png'))), self.surface.get_size()) self.button_rect = pygame.Rect(0, 0, self.width / 8, self.height / 12) self.back_button = pygbutton.PygButton(self.button_rect, 'Back') self.text_rect = pygame.Rect(self.width / 4, self.height / 4, self.width / 2, self.height / 2) self.creds = Text( ''' Unfortunately options have not been implemented yet due to time constraints''', self.text_rect)
def __init__(self, surface, lm): self.name = 'trivia' self.surface = surface self.lm = lm super().__init__(self.name, self.surface, self.lm) self.width, self.height = self.surface.get_size() self.button_labels = ['A', 'B', 'C', 'D'] self.buttons_rects = [ pygame.Rect(self.width / 4 + self.width / 8 * i, self.height / 8 * 6, self.width / 8, self.height / 8) for i in range(4) ] self.buttons = [ pygbutton.PygButton(self.buttons_rects[i], self.button_labels[i]) for i in range(4) ] self.p = Player(x=self.width / 8, y=self.height / 4) self.p.scale = self.height / 2 self.o = Player(x=self.width / 8 * 6, y=self.height / 4) self.o.scale = self.height / 2 self.o.texture = pygame.transform.flip( pygame.image.load(os.path.join('resources', 'player.png')), True, False) self.question_rect = pygame.Rect(self.width / 4, 0, self.width / 2, self.height / 2) self.question_num = 0 with open(resource_path(os.path.join('resources', 'q.json'))) as f: self.question_pool = json.loads(f.read()) self.questions = pick_random( self.question_pool, 10 ) # [{'q': 'What is this question?', 'a': ['A1', 'A2', 'A3', 'A4']}] self.num_correct = 0
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Al Sweigart. """ import pygame from run import resource_path from pygame.locals import * pygame.font.init() PYGBUTTON_FONT = pygame.font.Font(resource_path('resources/freesansbold.ttf'), 14) BLACK = (0, 0, 0) WHITE = (255, 255, 255) DARKGRAY = (64, 64, 64) GRAY = (128, 128, 128) LIGHTGRAY = (212, 208, 200) class PygButton(object): def __init__(self, rect=None, caption='', bgcolor=LIGHTGRAY, fgcolor=BLACK,