def build_background_grid(): parent = Node() # Parameters to pass to the creation of ShapeNode params = { "path": Path.rect(0, 0, GRID_SIZE, GRID_SIZE * ROWS), "fill_color": "clear", "stroke_color": "lightgrey" } anchor = Vector2(0, 0) # Building the columns for i in range(COLUMNS): n = ShapeNode(**params) pos = Vector2(i * GRID_SIZE, 0) n.position = pos n.anchor_point = anchor parent.add_child(n) # Building the rows params["path"] = Path.rect(0, 0, GRID_SIZE * COLUMNS, GRID_SIZE) for i in range(ROWS): n = ShapeNode(**params) pos = Vector2(0, i * GRID_SIZE) n.position = pos n.anchor_point = anchor parent.add_child(n) return parent
def setup(self): self.image = SpriteNode(Texture(image), z_position = -12, position = self.bounds.center(), parent = self) self.background = ShapeNode(path = Path.rect(0,0,self.image.size.w,self.image.size.h), position = self.image.position, z_position = -15, parent = self, fill_color = (1,1,1,.1)) self.offset = Point(-50, 50) self.cursor = Node(parent = self) ShapeNode(path = Path.rect(0,0,1,20), parent = self.cursor, fill_color = (0,0,0)) ShapeNode(path = Path.rect(0,0,20,1), parent = self.cursor, fill_color = (0,0,0)) self.cursorlabel = LabelNode("", parent = self, position = (self.bounds.w/2.0, self.bounds.h*.9)) self.selected = [] self.selected_nodes = [] self.selectbutton = ShapeNode(Path.rect(0,0,150,50), parent = self, position = (self.bounds.w*.2, self.bounds.h*.9), fill_color = (0,0,0), stroke_color = (1,1,1)) LabelNode("Select", parent = self.selectbutton) self.printbutton = ShapeNode(Path.rect(0,0,150,50), parent = self, position = (self.bounds.w*.8, self.bounds.h*.9), fill_color = (0,0,0), stroke_color = (1,1,1)) LabelNode("Print", parent = self.printbutton)
def setup(self): '''Called to initialize the game''' self.center = (self.size.w / 2, self.size.h / 2) self.player = Player(parent=self, speed=PLAYER_SPEED) self.controller = Controller(padding=40, scale=1.2, parent=self) self.firebtn = FireBtn(70, parent=self) self.background_color = '#003f68' self.objects = list() self.lasers = list() self.comets = list() self.pos = (.0, .0) self.firing = False self.player_sequence = Sequence( [Shot(x_offset=40, y_offset=20), Shot(x_offset=-40, y_offset=20)], origin=self.player, delay=0.2) self.spawn_area = ShapeNode(Path.rect(*self.bounds), alpha=0, parent=self, scale=2, position=self.size / 2)
def shoot_rocket(self, x, y): rocket = sk.SpriteNode(TRAIL_TEXTURE) rocket.size = 10, 10 rocket.position = self.size[0] / 2, 0 color = choice(COLORS) rocket.color_blend_factor = 1 rocket.color = color trail = sk.EmitterNode() trail.target_node = self trail.p_texture = TRAIL_TEXTURE trail.p_alpha_speed = -0.5 trail.p_size = 15, 15 trail.p_alpha = 0.4 trail.p_speed = 5 trail.p_birth_rate = 200 path = Path() path.add_quad_curve(x - self.size[0] / 2, y, 0, y / 2) d = abs(rocket.position - (x, y)) duration = max(0.7, d / 500.0) shoot = sk.Action.follow_path(path, duration) self.add_child(rocket) def add_explosion(): rocket.remove_from_parent() num_explosions = randint(1, 3) sound.play_effect('arcade:Explosion_' + str(num_explosions)) for i in range(num_explosions): self.add_random_explosion(x, y, choice(COLORS)) shoot.timing_mode = sk.TIMING_EASE_IN_EASE_OUT trail.position = rocket.position trail.num_particles_to_emit = int(200 * duration) self.add_child(trail) trail.run_action(shoot) trail.run_action( sk.Action.sequence([ sk.Action.wait(duration + 1.0), sk.Action.call(trail.remove_from_parent) ])) explode = sk.Action.call(add_explosion) animation = sk.Action.sequence([shoot, explode]) rocket.run_action(animation) sound.play_effect('game:Woosh_2')
def __init__(self, coords, location, piece, light): self.coords = coords self.location = location self.piece = piece self.light = light square = Path.rect(0, 0, t_lth, t_lth) #Creates lattice effect if sum(coords) % 2 == 0: tile_colour = '#3e3e3e' else: tile_colour = '#d3d3d3' #Creates square ShapeNode.__init__(self, square, tile_colour, '#adadad', position=location) #Below decides whether there is a piece and its info if self.piece["type"] == "p": self.position_chg = -0.05 else: self.position_chg = -0.2 if piece["side"] == "n": pass elif self.piece["side"] == "w": self.marker = LabelNode(piece["type"], ('Academy Engraved LET', t_lth), color='white', position=(0, t_lth * self.position_chg)) self.add_child(self.marker) elif self.piece["side"] == "b": self.marker = LabelNode(piece["type"], ('Academy Engraved LET', t_lth), color='black', position=(0, t_lth * self.position_chg)) self.add_child(self.marker) #Decides whether the square lights up or not (during move selection) if self.light == True: self.light_square = ShapeNode(square, "#2f77ff", "#300cdd", position=(0, 0), alpha=0.3) self.add_child(self.light_square)
def shoot_rocket(self, x, y): rocket = sk.SpriteNode(TRAIL_TEXTURE) rocket.size = 10, 10 rocket.position = self.size[0] / 2, 0 color = choice(COLORS) rocket.color_blend_factor = 1 rocket.color = color trail = sk.EmitterNode() trail.target_node = self trail.p_texture = TRAIL_TEXTURE trail.p_alpha_speed = -0.5 trail.p_size = 15, 15 trail.p_alpha = 0.4 trail.p_speed = 5 trail.p_birth_rate = 200 path = Path() path.add_quad_curve(x - self.size[0]/2, y, 0, y/2) d = abs(rocket.position - (x, y)) duration = max(0.7, d/500.0) shoot = sk.Action.follow_path(path, duration) self.add_child(rocket) def add_explosion(): rocket.remove_from_parent() num_explosions = randint(1, 3) sound.play_effect('arcade:Explosion_' + str(num_explosions)) for i in xrange(num_explosions): self.add_random_explosion(x, y, choice(COLORS)) shoot.timing_mode = sk.TIMING_EASE_IN_EASE_OUT trail.position = rocket.position trail.num_particles_to_emit = int(200 * duration) self.add_child(trail) trail.run_action(shoot) trail.run_action(sk.Action.sequence([sk.Action.wait(duration+1.0), sk.Action.call(trail.remove_from_parent)])) explode = sk.Action.call(add_explosion) animation = sk.Action.sequence([shoot, explode]) rocket.run_action(animation) sound.play_effect('game:Woosh_2')
def touch_began(self, touch): if touch.location in self.selectbutton.bbox: self.selected.append(self.give_position(self.cursor.position)) self.selected_nodes.append(ShapeNode(path = Path.oval(0,0,5,5), parent = self, position = self.cursor.position, z_position = -10, fill_color = (1,1,1), stroke_color = (0,0,0))) if touch.location in self.printbutton.bbox: print self.selected
def __init__(self, i, j, **vargs): self.touched = 0 super().__init__(Path.rect(0, 0, S, S), 'white', position=(i * S, j * S), **vargs)
def make_glyph(glyphs): tempPath = None for paths in glyphs: path = Path() for segment in paths: if len(segment) == 4: start_x = segment[0][0] start_y = segment[0][1] cp1_x = segment[1][0] cp1_y = segment[1][1] cp2_x = segment[2][0] cp2_y = segment[2][1] end_x = segment[3][0] end_y = segment[3][1] if path.bounds.height == 0 and path.bounds.width == 0: path.move_to(start_x, start_y) path.add_curve(end_x, end_y, cp1_x, cp1_y, cp2_x, cp2_y) else: path.add_curve(end_x, end_y, cp1_x, cp1_y, cp2_x, cp2_y) elif len(segment) == 2: start_x = segment[0][0] start_y = segment[0][1] end_x = segment[1][0] end_y = segment[1][1] if path.bounds.height == 0 and path.bounds.width == 0: path.move_to(start_x, start_y) path.line_to(end_x, end_y) else: path.line_to(end_x, end_y) if tempPath: tempPath.append_path(path) else: tempPath = path return tempPath
def setup(self): h = 200 w = 300 p = Path() p.line_to(w / 2, h) p.line_to(-(w / 2), h) p.close() self.s = ShapeNode(p) self.s.anchor_point = (0.5, 0) self.s.position = (self.size.x / 2, self.size.y / 2) self.add_child(self.s) ph = Path() ph.line_to(self.size.x, 0) ph.line_to(self.size.x, 1) ph.line_to(0, 1) ph.close() self.lh = ShapeNode(ph) self.lh.fill_color = 'red' self.lh.position = (self.size.x / 2, self.size.y / 2) self.add_child(self.lh) pv = Path() pv.line_to(0, self.size.y) pv.line_to(1, self.size.y) pv.line_to(1, 0) pv.close() self.lv = ShapeNode(pv) self.lv.fill_color = 'red' self.lv.position = (self.size.x / 2, self.size.y / 2) self.add_child(self.lv)