def __init__(self, skin_red, skin_green, skin_blue, clothes_red, clothes_green, clothes_blue): super(CharacterBody, self).__init__() from cocos.layer.util_layers import ColorLayer #red, green, blue = self.config['player']['color'] body_width = 48 body_height = 16 body = ColorLayer(clothes_red, clothes_green, clothes_blue, 255, body_width, body_height) half_body_width = body_width / 2 half_body_height = body_height / 2 body.position = -half_body_width, -half_body_height self.add(body) head_size = 18 half_head_size = head_size / 2 head = ColorLayer(skin_red, skin_green, skin_blue, 255, head_size, head_size) head.position = -half_head_size, -half_head_size self.body_width = body_width self.body_height = body_height self.head_size = head_size self.skin_red = skin_red self.skin_green = skin_green self.skin_blue = skin_blue self.clothes_red = clothes_red self.clothes_green = clothes_green self.clothes_blue = clothes_blue self.add(head) self.anchor = 0, 0
def __init__(self, *args): from cocos.layer.util_layers import ColorLayer super(Zombie, self).__init__(0, 255, 0, *args) arm_width = 10 arm_height = 2 * arm_width left_arm = ColorLayer(self.skin_red, self.skin_green, self.skin_blue, 255, arm_width, arm_height) left_arm.position = -self.body_width/2, self.head_size/2 right_arm = ColorLayer(self.skin_red, self.skin_green, self.skin_blue, 255, arm_width, arm_height) right_arm.position = self.body_width/2 - arm_width, self.head_size/2 self.add(left_arm) self.add(right_arm)
def __init__(self, *args): from cocos.layer.util_layers import ColorLayer super(Player, self).__init__(*args) hand_size = 10 half_hand_size = hand_size / 2 left_hand = ColorLayer(self.skin_red, self.skin_green, self.skin_blue, 255, hand_size, hand_size) left_hand.position = -self.body_width/2, self.head_size/2 right_hand = ColorLayer(self.skin_red, self.skin_green, self.skin_blue, 255, hand_size, hand_size) right_hand.position = self.body_width/2 - hand_size, self.head_size/2 self.add(left_hand) self.add(right_hand)
def __init__(self): # Always call super in the constructor: super( ChessBoard, self ).__init__() the_board = [6, 4, 2, 0, 5, 7, 1, 3] # 8x8 board colors = [(255,0,0), (0,0,0)] n = len(the_board) # This is an NxN chess board. sq_sz = windowWidth // n # sq_sz is length of a square. # Build layers for board squares for row in range(n): # Draw each row of the board. c_indx = row % 2 # Alternate starting color for col in range(n): # Run through cols drawing squares l = ColorLayer( colors[c_indx][0], colors[c_indx][1], colors[c_indx][2], 255, width=sq_sz, height=sq_sz) l.position = (col*sq_sz, row*sq_sz) self.add( l ) # Now flip the color index for the next square c_indx = (c_indx + 1) % 2
def __init__(self, player, width, height): Layer.__init__(self) self.width = width self.height = height self.player = player.domain msg = Label( 'health %s, sticks: %s' % (self.player.health, self.player._inventory.get('sticks')), font_name='somebitch', anchor_x='left', anchor_y='bottom', # really - it's top of screen width=width, height=25, x=5, y=-3, ) color = (73, 106, 44, 255) hudBackground = ColorLayer(*color, width=self.width, height=25) hudBackground.position = (0, 0) self.add(hudBackground) self.add(msg, name='msg') self.schedule(self.update)