From 1dd7a53e5f3442d78e1db6d8142445f8185c817b Mon Sep 17 00:00:00 2001 From: David Sharpe Date: Sun, 18 May 2014 01:15:18 +0200 Subject: [PATCH] Tuts for noobs. --- data/tutorial/tutorial_screen_1.json | 1 + naja/scenes/introduction.py | 104 ++++++++++++++++++++++++--- naja/widgets/image_box.py | 2 +- 3 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 data/tutorial/tutorial_screen_1.json diff --git a/data/tutorial/tutorial_screen_1.json b/data/tutorial/tutorial_screen_1.json new file mode 100644 index 0000000..d9b41e1 --- /dev/null +++ b/data/tutorial/tutorial_screen_1.json @@ -0,0 +1 @@ +{"timestamp": "Sat May 17 23:51:34 2014", "data": {"wins_required": 4, "puzzle": false, "player_mode": 2, "locations": [{"card_name": "win1", "max_number": 1, "actions": [{"required_bits": [], "action_class": "LoseHealthOrMSB"}, {"required_bits": ["RED", "GREEN", "BLUE"], "action_class": "AcquireWinToken"}]}, {"card_name": "win2", "max_number": 2, "actions": [{"required_bits": [], "action_class": "LoseHealthOrMSB"}, {"required_bits": ["RED", "GREEN", "BLUE"], "action_class": "AcquireWinTokenAndLoseHealth"}]}, {"card_name": "win3", "max_number": 1, "actions": [{"required_bits": [], "action_class": "LoseHealthOrMSBAndSetBits"}, {"required_bits": ["RED", "GREEN", "BLUE"], "action_class": "AcquireWinToken"}]}, {"card_name": "knight_set", "actions": [{"required_bits": [], "action_class": "GainMSB"}, {"required_bits": ["BLUE"], "action_class": "SetBits"}, {"required_bits": ["RED", "GREEN"], "data": {"chesspiece": "KNIGHT"}, "action_class": "AllowChessMove"}]}, {"card_name": "castle_set", "actions": [{"required_bits": [], "action_class": "GainMSB"}, {"required_bits": ["GREEN"], "action_class": "SetBits"}, {"required_bits": ["RED", "BLUE"], "data": {"chesspiece": "CASTLE"}, "action_class": "AllowChessMove"}]}, {"card_name": "bishop_set", "actions": [{"required_bits": [], "action_class": "GainMSB"}, {"required_bits": ["RED"], "action_class": "SetBits"}, {"required_bits": ["GREEN", "BLUE"], "data": {"chesspiece": "BISHOP"}, "action_class": "AllowChessMove"}]}, {"card_name": "bishop_set_knight", "actions": [{"required_bits": [], "data": {"chesspiece": "BISHOP"}, "action_class": "AllowChessMoveIfMSB"}, {"required_bits": ["BLUE"], "action_class": "SetBits"}, {"required_bits": ["RED", "GREEN"], "data": {"chesspiece": "KNIGHT"}, "action_class": "AllowChessMove"}]}, {"card_name": "knight_set_castle", "actions": [{"required_bits": [], "data": {"chesspiece": "KNIGHT"}, "action_class": "AllowChessMoveIfMSB"}, {"required_bits": ["GREEN"], "action_class": "SetBits"}, {"required_bits": ["RED", "BLUE"], "data": {"chesspiece": "CASTLE"}, "action_class": "AllowChessMove"}]}, {"card_name": "castle_set_bishop", "actions": [{"required_bits": [], "data": {"chesspiece": "CASTLE"}, "action_class": "AllowChessMoveIfMSB"}, {"required_bits": ["RED"], "action_class": "SetBits"}, {"required_bits": ["GREEN", "BLUE"], "data": {"chesspiece": "BISHOP"}, "action_class": "AllowChessMove"}]}, {"card_name": "toggle-rg-r", "bits": ["RED", "GREEN"], "actions": [{"required_bits": [], "action_class": "GainHealthAndClearBitsOrMSB"}, {"required_bits": ["RED"], "action_class": "ToggleBits"}, {"required_bits": ["GREEN", "BLUE"], "action_class": "SetBits"}]}, {"card_name": "toggle-rg-g", "bits": ["RED", "GREEN"], "actions": [{"required_bits": [], "action_class": "GainHealthAndClearBitsOrMSB"}, {"required_bits": ["GREEN"], "action_class": "ToggleBits"}, {"required_bits": ["RED", "BLUE"], "action_class": "SetBits"}]}, {"card_name": "shift-n-heal", "actions": [{"required_bits": [], "action_class": "ToggleBits"}, {"required_bits": ["BLUE"], "data": {"direction": "NORTH"}, "action_class": "ShiftLocations"}, {"required_bits": ["RED", "GREEN"], "action_class": "GainHealth"}]}, {"card_name": "shift-s-heal", "actions": [{"required_bits": [], "action_class": "ToggleBits"}, {"required_bits": ["BLUE"], "data": {"direction": "SOUTH"}, "action_class": "ShiftLocations"}, {"required_bits": ["RED", "GREEN"], "action_class": "GainHealth"}]}, {"card_name": "shift-e-heal", "actions": [{"required_bits": [], "action_class": "ToggleBits"}, {"required_bits": ["GREEN"], "data": {"direction": "EAST"}, "action_class": "ShiftLocations"}, {"required_bits": ["RED", "BLUE"], "action_class": "GainHealth"}]}, {"card_name": "shift-w-heal", "actions": [{"required_bits": [], "action_class": "ToggleBits"}, {"required_bits": ["GREEN"], "data": {"direction": "WEST"}, "action_class": "ShiftLocations"}, {"required_bits": ["RED", "BLUE"], "action_class": "GainHealth"}]}, {"card_name": "shift-n-harm", "actions": [{"required_bits": [], "action_class": "ToggleBitsAndHarm"}, {"required_bits": ["BLUE"], "data": {"direction": "NORTH"}, "action_class": "ShiftLocations"}, {"required_bits": ["RED", "GREEN"], "action_class": "GainHealth"}]}, {"card_name": "shift-s-harm", "actions": [{"required_bits": [], "action_class": "ToggleBitsAndHarm"}, {"required_bits": ["BLUE"], "data": {"direction": "SOUTH"}, "action_class": "ShiftLocations"}, {"required_bits": ["RED", "GREEN"], "action_class": "GainHealth"}]}, {"card_name": "shift-e-harm", "actions": [{"required_bits": [], "action_class": "ToggleBitsAndHarm"}, {"required_bits": ["GREEN"], "data": {"direction": "EAST"}, "action_class": "ShiftLocations"}, {"required_bits": ["RED", "BLUE"], "action_class": "GainHealth"}]}, {"card_name": "shift-w-harm", "actions": [{"required_bits": [], "action_class": "ToggleBitsAndHarm"}, {"required_bits": ["GREEN"], "data": {"direction": "WEST"}, "action_class": "ShiftLocations"}, {"required_bits": ["RED", "BLUE"], "action_class": "GainHealth"}]}, {"card_name": "shift-e-bitshift", "actions": [{"required_bits": ["GREEN"], "data": {"direction": "EAST"}, "action_class": "ShiftLocations"}, {"required_bits": ["GREEN", "BLUE"], "data": {"shift": 1, "direction": "right"}, "action_class": "ShiftBits"}]}, {"card_name": "shift-w-bitshift", "actions": [{"required_bits": ["GREEN"], "data": {"direction": "WEST"}, "action_class": "ShiftLocations"}, {"required_bits": ["RED", "BLUE"], "data": {"shift": 1, "direction": "left"}, "action_class": "ShiftBits"}]}, {"card_name": "rot-cw-set", "actions": [{"required_bits": [], "action_class": "ToggleBits"}, {"required_bits": ["RED"], "data": {"rot_direction": "CLOCKWISE"}, "action_class": "RotateLocations"}, {"required_bits": ["BLUE"], "action_class": "SetBits"}]}, {"card_name": "rot-ccw-set", "actions": [{"required_bits": [], "action_class": "ToggleBits"}, {"required_bits": ["RED"], "data": {"rot_direction": "ANTICLOCKWISE"}, "action_class": "RotateLocations"}, {"required_bits": ["GREEN"], "action_class": "SetBits"}]}, {"card_name": "mean-card", "actions": [{"required_bits": [], "action_class": "LoseHealthOrMSB"}]}, {"card_name": "mean-card", "actions": [{"required_bits": [], "action_class": "ClearBitsAndHealth"}, {"required_bits": ["RED"], "action_class": "LoseHealthOrMSB"}]}], "player": {"position": [0, 3], "movement_mode": 0, "bits": 184}, "max_health": 4, "clock_count": 5, "replacement_params": {"max": 8, "chance": 0.2, "min": 4}, "wins": 0, "board_locations": [[[0, 0], {"replacement_time": null, "max_number": 25, "bitwise_operand": [3, 4], "actions": [{"required_bits": [], "data": {}, "action_class": "ToggleBitsAndHarm"}, {"required_bits": [4], "data": {"direction": "SOUTH"}, "action_class": "ShiftLocations"}, {"required_bits": [5, 6], "data": {}, "action_class": "GainHealth"}], "card_name": "shift-s-harm"}], [[0, 1], {"replacement_time": null, "max_number": 25, "bitwise_operand": [0, 5], "actions": [{"required_bits": [], "data": {}, "action_class": "ClearBitsAndHealth"}, {"required_bits": [6], "data": {}, "action_class": "LoseHealthOrMSB"}], "card_name": "mean-card"}], [[0, 2], {"replacement_time": null, "max_number": 25, "bitwise_operand": [5, 6], "actions": [{"required_bits": [], "data": {}, "action_class": "GainHealthAndClearBitsOrMSB"}, {"required_bits": [5], "data": {}, "action_class": "ToggleBits"}, {"required_bits": [4, 6], "data": {}, "action_class": "SetBits"}], "card_name": "toggle-rg-g"}], [[0, 3], {"replacement_time": null, "max_number": 25, "bitwise_operand": [0, 3, 5], "actions": [{"required_bits": [], "data": {}, "action_class": "ToggleBits"}, {"required_bits": [5], "data": {"direction": "EAST"}, "action_class": "ShiftLocations"}, {"required_bits": [4, 6], "data": {}, "action_class": "GainHealth"}], "card_name": "shift-e-heal"}], [[0, 4], {"replacement_time": null, "max_number": 25, "bitwise_operand": [1, 5], "actions": [{"required_bits": [], "data": {}, "action_class": "ToggleBitsAndHarm"}, {"required_bits": [4], "data": {"direction": "SOUTH"}, "action_class": "ShiftLocations"}, {"required_bits": [5, 6], "data": {}, "action_class": "GainHealth"}], "card_name": "shift-s-harm"}], [[1, 0], {"replacement_time": null, "max_number": 25, "bitwise_operand": [3, 5], "actions": [{"required_bits": [], "data": {}, "action_class": "ToggleBitsAndHarm"}, {"required_bits": [5], "data": {"direction": "EAST"}, "action_class": "ShiftLocations"}, {"required_bits": [4, 6], "data": {}, "action_class": "GainHealth"}], "card_name": "shift-e-harm"}], [[1, 1], {"replacement_time": 2, "max_number": 25, "bitwise_operand": [0, 5], "actions": [{"required_bits": [], "data": {"chesspiece": "BISHOP"}, "action_class": "AllowChessMoveIfMSB"}, {"required_bits": [4], "data": {}, "action_class": "SetBits"}, {"required_bits": [5, 6], "data": {"chesspiece": "KNIGHT"}, "action_class": "AllowChessMove"}], "card_name": "bishop_set_knight"}], [[1, 2], {"replacement_time": null, "max_number": 25, "bitwise_operand": [2, 6], "actions": [{"required_bits": [], "data": {}, "action_class": "GainMSB"}, {"required_bits": [4], "data": {}, "action_class": "SetBits"}, {"required_bits": [5, 6], "data": {"chesspiece": "KNIGHT"}, "action_class": "AllowChessMove"}], "card_name": "knight_set"}], [[1, 3], {"replacement_time": null, "max_number": 25, "bitwise_operand": [2, 6], "actions": [{"required_bits": [], "data": {}, "action_class": "ClearBitsAndHealth"}, {"required_bits": [6], "data": {}, "action_class": "LoseHealthOrMSB"}], "card_name": "mean-card"}], [[1, 4], {"replacement_time": 2, "max_number": 25, "bitwise_operand": [1, 4, 6], "actions": [{"required_bits": [], "data": {}, "action_class": "DoNothing"}, {"required_bits": [5], "data": {"direction": "WEST"}, "action_class": "ShiftLocations"}, {"required_bits": [4, 6], "data": {"shift": 1, "direction": "left"}, "action_class": "ShiftBits"}], "card_name": "shift-w-bitshift"}], [[2, 0], {"replacement_time": null, "max_number": 25, "bitwise_operand": [3, 5], "actions": [{"required_bits": [], "data": {}, "action_class": "ToggleBitsAndHarm"}, {"required_bits": [4], "data": {"direction": "NORTH"}, "action_class": "ShiftLocations"}, {"required_bits": [5, 6], "data": {}, "action_class": "GainHealth"}], "card_name": "shift-n-harm"}], [[2, 1], {"replacement_time": null, "max_number": 25, "bitwise_operand": [3, 7], "actions": [{"required_bits": [], "data": {}, "action_class": "ToggleBitsAndHarm"}, {"required_bits": [5], "data": {"direction": "EAST"}, "action_class": "ShiftLocations"}, {"required_bits": [4, 6], "data": {}, "action_class": "GainHealth"}], "card_name": "shift-e-harm"}], [[2, 2], {"replacement_time": null, "max_number": 25, "bitwise_operand": [1, 4, 5], "actions": [{"required_bits": [], "data": {}, "action_class": "GainMSB"}, {"required_bits": [5], "data": {}, "action_class": "SetBits"}, {"required_bits": [4, 6], "data": {"chesspiece": "CASTLE"}, "action_class": "AllowChessMove"}], "card_name": "castle_set"}], [[2, 3], {"replacement_time": 2, "max_number": 25, "bitwise_operand": [3, 4], "actions": [{"required_bits": [], "data": {}, "action_class": "GainMSB"}, {"required_bits": [4], "data": {}, "action_class": "SetBits"}, {"required_bits": [5, 6], "data": {"chesspiece": "KNIGHT"}, "action_class": "AllowChessMove"}], "card_name": "knight_set"}], [[2, 4], {"replacement_time": null, "max_number": 25, "bitwise_operand": [2, 5], "actions": [{"required_bits": [], "data": {}, "action_class": "ToggleBits"}, {"required_bits": [5], "data": {"direction": "EAST"}, "action_class": "ShiftLocations"}, {"required_bits": [4, 6], "data": {}, "action_class": "GainHealth"}], "card_name": "shift-e-heal"}], [[3, 0], {"replacement_time": null, "max_number": 25, "bitwise_operand": [2, 3, 6], "actions": [{"required_bits": [], "data": {}, "action_class": "ToggleBitsAndHarm"}, {"required_bits": [4], "data": {"direction": "NORTH"}, "action_class": "ShiftLocations"}, {"required_bits": [5, 6], "data": {}, "action_class": "GainHealth"}], "card_name": "shift-n-harm"}], [[3, 1], {"replacement_time": null, "max_number": 25, "bitwise_operand": [5, 6], "actions": [{"required_bits": [], "data": {}, "action_class": "GainHealthAndClearBitsOrMSB"}, {"required_bits": [6], "data": {}, "action_class": "ToggleBits"}, {"required_bits": [4, 5], "data": {}, "action_class": "SetBits"}], "card_name": "toggle-rg-r"}], [[3, 2], {"replacement_time": null, "max_number": 25, "bitwise_operand": [1, 4], "actions": [{"required_bits": [], "data": {}, "action_class": "DoNothing"}, {"required_bits": [5], "data": {"direction": "EAST"}, "action_class": "ShiftLocations"}, {"required_bits": [4, 5], "data": {"shift": 1, "direction": "right"}, "action_class": "ShiftBits"}], "card_name": "shift-e-bitshift"}], [[3, 3], {"replacement_time": null, "max_number": 25, "bitwise_operand": [1, 6], "actions": [{"required_bits": [], "data": {"chesspiece": "CASTLE"}, "action_class": "AllowChessMoveIfMSB"}, {"required_bits": [6], "data": {}, "action_class": "SetBits"}, {"required_bits": [4, 5], "data": {"chesspiece": "BISHOP"}, "action_class": "AllowChessMove"}], "card_name": "castle_set_bishop"}], [[3, 4], {"replacement_time": null, "max_number": 25, "bitwise_operand": [0, 5], "actions": [{"required_bits": [], "data": {}, "action_class": "ClearBitsAndHealth"}, {"required_bits": [6], "data": {}, "action_class": "LoseHealthOrMSB"}], "card_name": "mean-card"}], [[4, 0], {"replacement_time": null, "max_number": 25, "bitwise_operand": [0, 7], "actions": [{"required_bits": [], "data": {}, "action_class": "ToggleBits"}, {"required_bits": [6], "data": {"rot_direction": "CLOCKWISE"}, "action_class": "RotateLocations"}, {"required_bits": [4], "data": {}, "action_class": "SetBits"}], "card_name": "rot-cw-set"}], [[4, 1], {"replacement_time": null, "max_number": 25, "bitwise_operand": [1, 7], "actions": [{"required_bits": [], "data": {}, "action_class": "ToggleBitsAndHarm"}, {"required_bits": [4], "data": {"direction": "SOUTH"}, "action_class": "ShiftLocations"}, {"required_bits": [5, 6], "data": {}, "action_class": "GainHealth"}], "card_name": "shift-s-harm"}], [[4, 2], {"replacement_time": null, "max_number": 1, "bitwise_operand": [1, 2, 6], "actions": [{"required_bits": [], "data": {}, "action_class": "LoseHealthOrMSBAndSetBits"}, {"required_bits": [4, 5, 6], "data": {}, "action_class": "AcquireWinToken"}], "card_name": "win3"}], [[4, 3], {"replacement_time": null, "max_number": 25, "bitwise_operand": [3, 4], "actions": [{"required_bits": [], "data": {"chesspiece": "BISHOP"}, "action_class": "AllowChessMoveIfMSB"}, {"required_bits": [4], "data": {}, "action_class": "SetBits"}, {"required_bits": [5, 6], "data": {"chesspiece": "KNIGHT"}, "action_class": "AllowChessMove"}], "card_name": "bishop_set_knight"}], [[4, 4], {"replacement_time": null, "max_number": 25, "bitwise_operand": [1, 5, 6], "actions": [{"required_bits": [], "data": {"chesspiece": "CASTLE"}, "action_class": "AllowChessMoveIfMSB"}, {"required_bits": [6], "data": {}, "action_class": "SetBits"}, {"required_bits": [4, 5], "data": {"chesspiece": "BISHOP"}, "action_class": "AllowChessMove"}], "card_name": "castle_set_bishop"}]], "cheater": true, "health": 3}} \ No newline at end of file diff --git a/naja/scenes/introduction.py b/naja/scenes/introduction.py index a8e001f..ddaab48 100644 --- a/naja/scenes/introduction.py +++ b/naja/scenes/introduction.py @@ -5,7 +5,8 @@ Load and save scenes. import pygame.locals as pgl import pygame -from naja.constants import KEYS, SCREEN +from naja import constants +from naja.constants import KEYS, SCREEN, PALETTE from naja.events import SceneChangeEvent, LoadGameEvent from naja.gamestate import GameState from naja.scenes.scene import Scene @@ -26,6 +27,8 @@ class IntroductionScene(Scene): (0, 0), "screens/splash.png") self.add(background) + self.intro = 0 + selector = SelectorWidget() self.add(selector) @@ -48,7 +51,7 @@ class IntroductionScene(Scene): intro = TextWidget( (x_offset, y_offset), 'Introductory Level', colour='white', centre=True) - intro.add_callback('click', self.introduction_level) + intro.add_callback('click', self.introduction_to_screen_1) selector.add(intro) y_offset += 2*y_diff @@ -65,23 +68,93 @@ class IntroductionScene(Scene): LoadGameEvent.post(state=GameState.new(deck='introduction')) SceneChangeEvent.post(GameScene) - def introduction_to_screen_1(self, event): + def make_game_surface(self): self.container.widgets = [] state = resources.get_json('tutorial/tutorial_screen_1.json') dummy_game = DummyGameScene(state) game_surface = pygame.surface.Surface(SCREEN) dummy_game.render(game_surface) self.add(PreRenderedImageBox((0, 0), game_surface)) + return game_surface + + def introduction_to_screen_1(self, event): + game_surface = self.make_game_surface() + self.intro = 1 self.add(TextBoxWidget( - (10, 50), '\n'.join([ - "You are a robot, frantically trying to set the correct " - "bits to gain points for reasons that are unlikely ever " - "to become clear.", + (24, 72), '\n'.join([ + "These are your robot's status bits. On the left we have " + "the Most Signiticant Bit (MSB, currently set), then Red, " + "Green (set) and Blue (set) key bits, and finally the four " + "bits which control movement options, of which only left is " + "set. You can only move in directions which are set. \n" + "Enter to continue.", ]), fontsize=32, - colour='white', padding=1, border=1, - bg_colour='black', border_colour='black', - box_width=740, view_port=(780, 540))) + colour=PALETTE.GREEN, padding=12, border=8, + bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN, + box_width=400, view_port=(500, 800))) + + pygame.draw.rect(game_surface, PALETTE.GREEN, (0, 0, 480, 60), 8) + + def introduction_to_screen_2(self, event): + game_surface = self.make_game_surface() + self.intro = 2 + + self.add(TextBoxWidget( + (24, 172), '\n'.join([ + "These are your health and score. On the left we have four " + "health bits. The robot has taken one damage, so only three " + "are lit. The stars are points you have scored. Once you have " + "all of them you win the game! Total health and required " + "points vary according to the game. \n" + "Enter to continue.", + ]), fontsize=32, + colour=PALETTE.GREEN, padding=12, border=8, + bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN, + box_width=400, view_port=(500, 800))) + + pygame.draw.rect(game_surface, PALETTE.GREEN, (0, 540, 480, 60), 8) + + def introduction_to_screen_3(self, event): + game_surface = self.make_game_surface() + self.intro = 3 + + self.add(TextBoxWidget( + (24, 132), '\n'.join([ + "This text box describes the current game mode. The game is " + "divided into movements and actions, and each mode has " + "different options, shown here.\n" + "During movement, you can examine the entire board, but you " + "can only move to hi-lighted tiles (including the one you are " + "on. Actions come next... \n" + "Enter to continue.", + ]), fontsize=32, + colour=PALETTE.GREEN, padding=12, border=8, + bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN, + box_width=400, view_port=(500, 800))) + + pygame.draw.rect(game_surface, PALETTE.GREEN, (488, 416, 304, 132), 8) + + def introduction_to_screen_4(self, event): + game_surface = self.make_game_surface() + self.intro = 4 + + self.add(TextBoxWidget( + (24, 72), '\n'.join([ + "This text box shows actions available on the tile. " + "Some actions have requirements and are only selectable if " + "you have the correct bits set (unavailable actions are " + "greyed out). Actions usually change the bits set on " + "your robot. This is often not beneficial.\n" + "Some actions have additional effects if the MSB is " + "set.\n" + "Enter to continue.", + ]), fontsize=32, + colour=PALETTE.GREEN, padding=12, border=8, + bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN, + box_width=400, view_port=(500, 800))) + + pygame.draw.rect(game_surface, PALETTE.GREEN, (488, 52, 304, 240), 8) def handle_scene_event(self, ev): @@ -89,3 +162,14 @@ class IntroductionScene(Scene): from naja.scenes.menu import MenuScene SceneChangeEvent.post(MenuScene) return + if ev.type == pgl.KEYDOWN and ev.key in KEYS.SELECT: + if 0 < self.intro < 5: + if self.intro == 1: + self.introduction_to_screen_2(ev) + elif self.intro == 2: + self.introduction_to_screen_3(ev) + elif self.intro == 3: + self.introduction_to_screen_4(ev) + else: + self.introduction_level(ev) + return diff --git a/naja/widgets/image_box.py b/naja/widgets/image_box.py index e9b4bf3..45c4a8c 100644 --- a/naja/widgets/image_box.py +++ b/naja/widgets/image_box.py @@ -29,7 +29,7 @@ class PreRenderedImageBox(Widget): def __init__(self, pos, image): super(PreRenderedImageBox, self).__init__(pos) - self.surface = image.copy() + self.surface = image def prepare(self): self.size = self.surface.get_rect().size -- 2.34.1