def __init__(self, cave_rect, min_gap, section_size=10): super().__init__("Cave", cave_rect, cdkk.stylesheet.style("Invisible")) self.cave_height = cave_rect.height self.cave_min_gap = min_gap self.cave_section_size = section_size self.cave_sections = (cave_rect.width // self.cave_section_size) + 1 self.update_reqd = False self.walls = cdkk.SpriteGroup("Cave Shapes") top_style = {"fillcolour":"blue", "outlinecolour":None, "shape":"Polygon"} self.cave_top = cdkk.Sprite_Shape("Cave Top", cave_rect, top_style) self.walls.add(self.cave_top) bottom_style = {"fillcolour":"red3", "outlinecolour":None, "shape":"Polygon"} self.cave_bottom = cdkk.Sprite_Shape("Cave Bottom", cave_rect, bottom_style) self.walls.add(self.cave_bottom)
def __init__(self, cave_rect, spaceship_height, name = "Cave Manager"): super().__init__(name) self._cave_rect = cave_rect self.cave_background = cdkk.Sprite_Shape("Cave background", cave_rect, style={"fillcolour":"green", "outlinecolour":None}) self.add(self.cave_background) self.cave = Sprite_Cave(cave_rect, spaceship_height*5) self.add(self.cave) self.rockets = cdkk.SpriteGroup("Rockets") self.rocket_launch_at = random.randint(15, 30) self.rocket_loop = 0 self.fuel_tanks = cdkk.SpriteGroup("Fuel Tanks")
def __init__(self, limits, name="Test PyGame App Manager"): super().__init__(name) image_sprite = cdkk.Sprite() image_sprite.load_image_from_file("beachball.png") image_sprite.rect.topleft = (10, 10) self.add(image_sprite) anim_sprite = cdkk.Sprite_Animation() anim_sprite.load_spritesheet("Explode", "ExplosionCount.png", 4, 4, set_anim=True) anim_sprite.rect.topleft = (200, 10) self.add(anim_sprite) rect_sprite = cdkk.Sprite_Shape("Shape:Rectangle", cdkk.cdkkRect(300, 10, 60, 30), {"fillcolour": "blue"}) self.add(rect_sprite) ellipse_sprite = cdkk.Sprite_Shape("Shape:Ellipse", cdkk.cdkkRect(400, 10, 60, 50), { "fillcolour": "green3", "outlinecolour": "red4", "shape": "Ellipse" }) self.add(ellipse_sprite) polygon_sprite = cdkk.Sprite_Shape("Shape:Polygon", cdkk.cdkkRect(500, 10, 101, 101), { "fillcolour": None, "shape": "Polygon" }) polygon_sprite.setup_polygon([(0, 50), (50, 0), (100, 50), (50, 100)]) self.add(polygon_sprite) image_from_ss = cdkk.Sprite() image_from_ss._image.set_spritesheet("ExplosionCount.png", 4, 4) image_from_ss._image.spritesheet_image(6) image_from_ss._image_size_to_rect() image_from_ss.rect.topleft = (650, 10) self.add(image_from_ss) tb_default = cdkk.Sprite_TextBox("TextBox: Default", cdkk.cdkkRect(10, 150, 300, 60)) self.add(tb_default) tb_style = { "textcolour": "blue", "fillcolour": None, "outlinecolour": "blue" } tb_style1 = cdkk.Sprite_TextBox("Blue/None/Blue", cdkk.cdkkRect(320, 150, 300, 60), style=tb_style) self.add(tb_style1) tb_style["fillcolour"] = "yellow1" tb_style["textsize"] = 20 tb_style["shape"] = "Ellipse" tb_style2 = cdkk.Sprite_TextBox("Blue/Yellow/Blue, O, 20", cdkk.cdkkRect(640, 150, 300, 60), style=tb_style) self.add(tb_style2) tb_topleft = cdkk.Sprite_TextBox("TextBox: Top Left", cdkk.cdkkRect(10, 220, 300, 60), style={ "align_horiz": "L", "align_vert": "T" }) self.add(tb_topleft) tb_bottomright = cdkk.Sprite_TextBox("TextBox: Bottom Right", cdkk.cdkkRect(320, 220, 300, 60), style={ "align_horiz": "R", "align_vert": "B" }) self.add(tb_bottomright) tb_click_me = cdkk.Sprite_TextBox("Click Me", cdkk.cdkkRect(640, 220, 300, 60)) ev_Clicked = cdkk.EventManager.gc_event("Clicked") ev_Unclicked = cdkk.EventManager.gc_event("Unclicked") tb_click_me.setup_mouse_events(ev_Clicked, ev_Unclicked) self.add(tb_click_me) self.game_over = cdkk.Sprite_GameOver(cdkk.cdkkRect(320, 300, 300, 60)) ev_Clicked = cdkk.EventManager.gc_event("ToggleGameOver") self._click_game_over = cdkk.Sprite_Button( "End Game", cdkk.cdkkRect(10, 300, 300, 60), ev_Clicked) self.add(self._click_game_over) self.start_game() self._fps = cdkk.Sprite_DynamicText("FPS", cdkk.cdkkRect(640, 300, 120, 40), style={ "fillcolour": None, "align_horiz": "L", "textformat": "FPS: {0:4.1f}" }) self.add(self._fps) self._fps_units = cdkk.Sprite_Label("frames/sec", cdkk.cdkkRect(770, 300, 150, 40)) self._fps_units.rect.centery = 320 self.add(self._fps_units) tb_auto_size = cdkk.Sprite_TextBox("AutoSize", cdkk.cdkkRect(10, 400, 0, 0), auto_size=True) ev_Auto_Clicked = cdkk.EventManager.gc_event("AutoSize") tb_auto_size.setup_mouse_events(ev_Auto_Clicked, None) self.add(tb_auto_size)
def __init__(self, limits): super().__init__("Court") court_style = {"fillcolour": "cadetblue3", "outlinecolour": "black"} court = cdkk.Sprite_Shape("Court", limits, court_style) self.add(court)
def __init__(self, limits, name="Board Manager"): super().__init__(name) self._mm_game = BoardGame_Mastermind(MM_HOLES, MM_TURNS, MM_OPTIONS) # --- Set up the board self.cp_hole_size = int( min((limits.height * 0.9) / MM_TURNS, (limits.width * 0.9) / MM_HOLES)) self._board_rect = cdkk.cdkkRect( 0, 0, (self.cp_hole_size + self.sp_hole_size) * MM_HOLES + 10, self.cp_hole_size * MM_TURNS + 10) self._board_rect.center = limits.center self.add( cdkk.Sprite_Shape("Board Background", self._board_rect, { "fillcolour": "tan4", "outlinecolour": None })) # --- Set up each turn for i in range(MM_TURNS): evl_click = [] for j in range(MM_HOLES): evl_click.append( cdkk.EventManager.gc_event("PlaceCodePeg", guess=(i, j))) self.add( Sprite_CodePeg_Set(i, self.code_peg_rect(i), MM_HOLES, evl_click=evl_click)) self.add( Sprite_ScorePeg_Set(i, self.score_pegs_rect(i), int((MM_HOLES + 1) / 2), 2)) # --- Code peg options and picker options = [i for i in range(MM_OPTIONS)] evl_click = [ cdkk.EventManager.gc_event("SelectCodePeg", guess=i) for i in range(MM_OPTIONS) ] options_rect = cdkk.cdkkRect( limits.left + limits.width * 0.2, limits.top + limits.height / 2 - self.cp_hole_size * MM_OPTIONS / 2, self.cp_hole_size - 10, self.cp_hole_size * MM_OPTIONS) cp = Sprite_CodePeg_Set(999, options_rect, 1, MM_OPTIONS, evl_click, "CodePegOptions") cp.update(options) self.add(cp) self._peg_picker = Sprite_CodePeg(self.code_peg_rect(0, 0)) self.add(self._peg_picker) # --- Set up controls button_height = 35 rect = cdkk.cdkkRect(self._board_rect.right + 100, limits.height / 2, 120, button_height) ev_Guess = cdkk.EventManager.gc_event("GuessCode") rect.bottom = limits.height / 2 - button_height * 2 self.add(cdkk.Sprite_Button("Guess", rect, ev_Guess)) ev_Restart = cdkk.EventManager.gc_event("StartGame") rect.centery = limits.height / 2 self.add(cdkk.Sprite_Button("Restart", rect, ev_Restart)) ev_Quit = cdkk.EventManager.gc_event("Quit") rect.top = limits.height / 2 + button_height * 2 self.add(cdkk.Sprite_Button("Quit", rect, ev_Quit)) self._winner = cdkk.Sprite_GameOver(limits) self.start_game()