예제 #1
0
	def _setup(self, i, a, c):
		
		if a != None:
			c['accessory']=scene.SpriteNode(
				texture=a,
				size=(self.size[1]/4, self.size[1]/5*1.5),
				position=scene.Point(-self.size[0]/2+7, self.size[1]/2-10),
				parent=self,
				z_position=4,
				color=self.accessoryColor)
			
		if i != None:
			c['icon']=scene.SpriteNode(
				texture=i,
				size=scene.Size(self.size[1]/2, self.size[1]/2),
				position=scene.Point(self.w/2 - self.size[1]/3 , 0),
				parent=self, 
				z_position=9)
				
		if self.text:
			c['label']=scene.LabelNode(
				text=self.text,
				font=(self.font_family, self.font_size),
				position=scene.Point(0 , 0),
				anchor_point=(0.5, 0.5),
				color=self.text_color,
				parent=self,
				z_position=10)
예제 #2
0
 def addParticle(self):
     pos = scene.Point(0, 0)
     v = scene.Point(random.uniform(0, 5), random.uniform(0, 5))
     a = scene.Point(0, -0.03)
     particle = Particle(pos, v, a)
     self.particles.append(particle)
     particle.setup(self)
예제 #3
0
 def __init__(self, speed=-5):
     texture, size = utils.load_sprite_sheet('ground.png', 1, 1)[0]
     self.ground0 = Ground(texture, size, scene.Point(0, 0))
     self.ground1 = Ground(texture, size, scene.Point(size.x, 0))
     self.add_child(self.ground0)
     self.add_child(self.ground1)
     self.position = scene.Point(0, 0)
     self.velocity = speed
예제 #4
0
 def __init__(self, scene_size_x):
     self.position = scene.Point(0, 0)
     self.velocity = -5
     sprites = utils.load_sprite_sheet('cacti-small.png', 6, 1, 17, 35,
                                       [(0, 1), (0, 2), (3, 1), (2, 2),
                                        (2, 3)])
     position = scene.Point(-100, 0)
     cactuses = [
         Cactus(texture, size, position, scene_size_x)
         for texture, size in sprites
     ]
     for cactus in cactuses:
         self.add_child(cactus)
 def setup(self):
     tile_texture = scene.Texture(ui.Image.named('Snake'))
     self.sprite = scene.SpriteNode(tile_texture,
                                    size=(500, 500),
                                    parent=self)
     self.sprite.shader = scene.Shader(shader_text)
     self.sprite.position = self.size / 2
     self.state = 0.0
     self.record_start = scene.LabelNode('Start_Recording',
                                         position=scene.Point(350, 50),
                                         parent=self)
     self.record_stop = scene.LabelNode('Stop_Recording',
                                        position=scene.Point(650, 50),
                                        parent=self)
예제 #6
0
    def __init__(self, speed, scene_size_x):
        self.position = scene.Point(0, 0)
        self.velocity = -2

        texture, size = utils.load_sprite_sheet('cloud.png', 1, 1,
                                                int(90 * 30 / 42), 30)[0]
        position = scene.Point(-200, random.randrange(90, 150))
        cloud0 = Cloud(texture, size, position, scene_size_x)
        cloud1 = Cloud(texture, size, position, scene_size_x)
        cloud2 = Cloud(texture, size, position, scene_size_x)
        cloud3 = Cloud(texture, size, position, scene_size_x)
        self.add_child(cloud0)
        self.add_child(cloud1)
        self.add_child(cloud2)
        self.add_child(cloud3)
    def action(self, touch, touchState):
        p = scene.Point(*touch.location)
        for pixel in self.pixels:
            if p in pixel.rect:
                # Auto-save image
                saveDelta = int(time()) - self.lastSave
                if saveDelta > Settings.autoSaveTime:
                    self.superview['debugtext'].text = "Autosaving..."
                    currentTime = str(datetime.now().day) + "_" + str(datetime.now().hour)
                    self.fastsave(self.imageName + "_worksave_" + currentTime)
                    self.lastSave = int(time())
                if self.toolMode == 'dots':
                    self.drawpixel(pixel)
                    if self.toolMode == 'lines' or self.toolMode == 'dots':
                        self.superview['debugtext'].text = "index:" + str(pixel.index) + ", pos:" + str(pixel.position) + ", autosave:" + str(Settings.autoSaveTime-saveDelta)
                elif self.toolMode == 'lines':
                    if touchState == 'began':
                        self.prevPixel == []
                    self.drawline(self.prevPixel, pixel, touchState)
                    self.prevPixel = pixel
                    if touchState == "ended":
                        #self.preview_update()
                        self.prevPixel = []
                    if self.toolMode == 'lines' or self.toolMode == 'dots':
                        self.superview['debugtext'].text = "index:" + str(pixel.index) + ", pos:" + str(pixel.position) + ", autosave:" + str(Settings.autoSaveTime-saveDelta)
                elif self.toolMode == 'zoom':
                    self.set_zoom_center(touch.location)

                    # Calculate the bounds of the zoom area
                    zoomCenter = self.zoom_frame.center
                    halfWidth = 319 * 0.5 / self.zoomLevels[self.zoomCurrent]
                    halfHeight = 199 * 0.5 / self.zoomLevels[self.zoomCurrent]
                    zoomFrom = (int((zoomCenter[0]/3-halfWidth)*0.5), int(zoomCenter[1]/3-halfHeight))
                    zoomTo = (int((zoomCenter[0]/3+halfWidth)*0.5), int(zoomCenter[1]/3+halfHeight))

                    # Debug text for zoom mode
                    self.superview['debugtext'].text = "Zoom location: [" + str(zoomFrom) + "," + str(zoomTo) + "], zoom level:" + str(self.zoomLevels[self.zoomCurrent])

                    # When the finger is released, we draw the zoomed view
                    if touchState == "ended":
                        self.superview['debugtext'].text = "Zooming in"
                        self.zoomState = True
                        self.redraw_canvas()
                        self.zoom_frame.hidden = True
                        if self.color_check.hidden == False:
                            self.character_colorcheck()

                        # Return to previous tool mode
                        self.toolMode = self.prevMode
                        self.superview['debugtext'].text = "Mode set back to " + self.toolMode
                        ## Todo: Sometimes, random dots get drawn after this command
                        ## Investigate why
                # Update preview image
                undoDelta = int(time()) - self.lastUndo
                if undoDelta > Settings.previewTime:
                    self.preview_update()
                    self.lastUndo = int(time())
예제 #8
0
    def setup(self):
        #print(self.bounds, self.size)
        #print(type(self.bounds))
        #sys.exit(type(self.bounds))
        self.square_size = min(*self.size) / 8  # normally 96.0 on an iPad

        if self.size.w > self.size.h:
            self.offset = scene.Point((self.size.w - self.size.h) / 2, 0)
        else:  # normally Point(x=128.0, y=0) on an iPad in landscape mode
            self.offset = scene.Point(0, (self.size.h - self.size.w) / 2)

        #self.offset =
        #print(self.square_size)
        cfg = self.game_view.game.board.cfg
        self.coord_disp_mode = {
            'onoff': cfg.disp_coords,
            'mode': cfg.coord_mode
        }
        self.render_mode = {
            'sqrs': cfg.disp_sqrs,
            'pieces': cfg.disp_pieces,
            'valid': cfg.highlight,
            'coords': cfg.disp_coords,
            'turn_color': cfg.disp_turn,
            'timers': cfg.disp_timers
        }
        self.is_selected = False
        self.selected = ''  # Coord(None, None)  self.selected --> a fen_pos
        self.target = self.selected
        self.err = None
        self.err_pos = ''  # Coord(None, None)
        self.valid_cache = []
        self.img_names = self.game_view.load_images()
        #print(self.img_names)
        self.turn_indicator_img = 'White_Square'
        self.pos_score = None
        self.disp_score = False
        #min = Coord(0, 0).as_screen
        #max = Coord(8, 8).as_screen
        #self.bounds = scene.Rect(min.x, min.y, max.x-min.x, max.y-min.y)
        #print(screen_size)
        #self.size = screen_size
        #print(self.bounds) # --> Rect(x=128, y=0, w=768, h=768)
        self.won = self.game_view.game.is_won()
예제 #9
0
 def getImageNameAndSize(self):
     for fontSize in xrange(256, 31, -32):
         (imageName, imageSize) = scene.render_text(clipText,
                                                    font_size=fontSize)
         print(fontSize),
         print(imageSize),
         print(self.bounds)
         if scene.Point(*imageSize) in self.bounds:
             return (imageName, imageSize)
         scene.unload_image(imageName)
     return scene.render_text(clipText, font_size=12)
예제 #10
0
	def setup(self):
		# this method is called, when user moves to this scene
		self.left_button_down = False
		self.right_button_down = False
		self.ship_move_speed = 40.0
		self.missiles = []
		# self.aliens = []
		# self.alien_attack_rate = 1
		# self.alien_attack_speed = 20.0
		
		# add blue background color
		scene.SpriteNode(position=self.size / 2,
		color=(0.61, 0.78, 0.87),
		parent=self,
		size=self.size)
		
		position = scene.Point(self.size.x / 2, 100)
		self.spaceship = scene.SpriteNode('spc:PlayerShip1Orange',
		parent=self,
		position=position)
		
		self.left_button = scene.SpriteNode('iob:arrow_left_a_256',
		parent=self,
		scale=0.5,
		position=scene.Point(75, 75),
		alpha=0.5)
		
		self.right_button = scene.SpriteNode('iob:arrow_right_a_256',
		parent=self,
		scale=0.5,
		position=scene.Point(200, 75),
		alpha=0.5)
		
		position = scene.Point(self.size.x - 75, 75)
		self.fire_button = scene.SpriteNode('iob:disc_256',
		parent=self,
		scale=0.5,
		position=position,
		alpha=0.5)
예제 #11
0
	def setup(self):
		self.background_color='#f2f2f2'
		self.my_button_up=ButtonNode(
					text='', 
					parent=self,
					position=scene.Point(self.size[0]/2, self.size[1]/2+100),
					action=my_button_action)
		self.my_button_right=ButtonNode(
					text='right', 
					parent=self,
					position=scene.Point(self.size[0]/2+100, self.size[1]/2),
					action=my_button_action)
		self.my_button_down=ButtonNode(
					text='down', 
					parent=self,
					position=scene.Point(self.size[0]/2, self.size[1]/2-100),
					action=my_button_action)
		self.my_button_left=ButtonNode(
					text='left', 
					parent=self,
					position=scene.Point(self.size[0]/2-100, self.size[1]/2),
					action=my_button_action)
예제 #12
0
 def setup(self):
     self.center = self.bounds.center()
     pad = 4  # pixels between buttons
     loc = scene.Point(pad, pad)
     keyboard = make_keyboards()[0]
     for keyrow in keyboard:
         button_height = loc.x = pad
         for key in keyrow:
             width = 740 if key == 'space' else 89
             key_button = TextButton(self, scene.Rect(loc[0], loc[1], width, 40), key)
             loc.x += key_button.frame.w + pad
             button_height = max(button_height, key_button.frame.h)
         loc.y += button_height + pad
     self.center.y += loc.y / 2  # move center up to compensate for keyboard
예제 #13
0
	def setup(self):
		#centerOfScreen = self.bounds.center()
		thePoint = scene.Point(10 + sizeInPixels / 2, 10 + sizeInPixels / 2)
		images = 'Rabbit_Face Mouse_Face Cat_Face Dog_Face Octopus Bear_Face Chicken Cow_Face'
		images = images.split()
		for image in images:
			scene.load_image(image)
		images *= 2 # go from 8 images to 16
		random.shuffle(images)
		for image in images:
			self.add_layer(ImageLayer(thePoint, image))
			thePoint.x += 10 + sizeInPixels / 3
			thePoint.y = thePoint.x
		self.touchedLayer = None
예제 #14
0
    def __init__(self):
        self.z_position = 2
        self.is_jumping = False
        self.is_ducking = False
        self.is_blinking = False
        self.is_dead = False
        self.counter = 0
        list_running_dinos = utils.load_sprite_sheet('dino.png', 5, 1, 44, 47)
        list_ducking_dinos = utils.load_sprite_sheet('dino_ducking.png', 2, 1,
                                                     59, 47)
        self.list_dinos = list_running_dinos + list_ducking_dinos

        self.index = 0
        self.left_buttom_coord = scene.Point(10, 10)
        self.update_img()

        self.velocity = [0, 0]
예제 #15
0
 def as_screen(self, piece):
     return scene.Point(piece.x * self.square_size + self.offset.x,
                        piece.y * self.square_size + self.offset.y)
# coding: utf-8

# https://forum.omz-software.com/topic/2518/tip-useful-objects-like-rect-obj-in-scene-module-others-also


from scene import Rect

#==============================

import scene, ui
assert dir(scene.Point())   == dir(ui.Point())
assert dir(scene.Rect())    == dir(ui.Rect())
assert dir(scene.Vector2()) == dir(ui.Vector2())
print('Success!')

#==============================

>>> ui.Rect(1,1,5,5) in ui.Rect(0,0,10,10)
True
>>> ui.Rect(1,1,15,15) in ui.Rect(0,0,10,10)
False
>>> ui.Point(1,1) in ui.Rect(0,0,10,10)
True
>>> ui.Point(-1,1) in ui.Rect(0,0,10,10)
False

#==============================

assert(ui.Rect is scene.Rect)

#==============================
 def action(self, touch):
     p = scene.Point(*touch.location)
     for pixel in self.pixels:
         if p in pixel:
             eval('self.{}(pixel)'.format(self.mode))
예제 #18
0
 def __init__(self, frame=None, velocity=None, color=None):
     self.frame = frame or scene.Rect(0, 0, 25, 25)
     self.velocity = velocity or scene.Point(0, 0)
     self.color = color or random_color()
예제 #19
0
 def position(self, value):
     self._position = scene.Point(*value)
예제 #20
0
def random_particle():
    def random_velocity():
        return random.randint(-g_speed, g_speed) or random_velocity()

    return Particle(velocity=scene.Point(random_velocity(), random_velocity()))
 def add_lines(self):
     self.lines = []
     point = self.size / 2 + scene.Point(100, 0)
     self.add_child(scene.LabelNode('x', position=point))
     for angle in range(0, 360, 10):
         self.add_line(angle)
예제 #22
0
 def reset(self, position_x):
     x = self.scene_size_x - position_x + random.randrange(0, 500, 80)
     y = random.randrange(90, 150)
     self.left_buttom_coord = scene.Point(x, y)
     self.update_img()
예제 #23
0
 def hit_test(self, x, y):
     return scene.Point(x, y) in self.bounds
예제 #24
0
    r = self.radians
    self.polar(r, m)

  @property
  def radians(self):
    return math.atan2(self.y, self.x)

  @radians.setter
  def radians(self, r):
    m = self.magnitude
    self.polar(r, m)

  def polar(self, r, m):
    self.y = math.sin(r) * m
    self.x = math.cos(r) * m
    
  @property
  def degrees(self):
    return math.degrees(self.radians)

  @degrees.setter
  def degrees(self, d):
    self.radians = math.radians(d)

if __name__ == '__main__':
  v = V(scene.Point(1,2))
  print(type(v))
  print(v.magnitude)
  v.magnitude *= 2
  print(v)
 def setup(self):
     self.rect2 = scene.Point(150,50)