omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. Karina

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    • Profile
    • Following 0
    • Followers 1
    • Topics 3
    • Posts 122
    • Best 4
    • Controversial 0
    • Groups 0

    Karina

    @Karina

    4
    Reputation
    1331
    Profile views
    122
    Posts
    1
    Followers
    0
    Following
    Joined Last Online

    Karina Unfollow Follow

    Best posts made by Karina

    • RE: [SPACE ESCAPE]-Game example to help with Game dev

      @cvp with enumerate doesn’t work cause with this for i, icon in enumerate(icons) you get keys of icons and nums 0, 1, 2. So i is the number and icon picture
      I did the same but without enumerate

      self.arrows = [Arrow(i, position=icons[i], parent=self) for i in icons] 
      

      Looks better than it was before👍

      posted in Pythonista
      Karina
      Karina
    • RE: [SPACE ESCAPE]-Game example to help with Game dev

      ShapeNode is a subclass of SpriteNode!

      Yeah, they say it in docs, I just forgot🤦‍♀️. Then it's more clever to make ShapeNode base class

      posted in Pythonista
      Karina
      Karina
    • RE: Flappy bird
      from scene import *
      import random
      
      
      class Column(SpriteNode):
      	def __init__(self, **kwargs):
      		SpriteNode.__init__(self, 'plf:Tile_BoxCrate_double', **kwargs)
      		
      		
      class Game(Scene):
      	def setup(self):
      		self.background_color = '#99d7ff'
      		x = 0
      		ground = Node(parent=self)
      		while x < self.size.w:
      			lower_tile = SpriteNode('plf:Ground_Stone', (x, 30))
      			higher_tile = SpriteNode('plf:Ground_Stone', (x, 738))
      
      			x += 60
      			ground.add_child(lower_tile)
      			ground.add_child(higher_tile)
      			self.add_column()
      			
      			
      	def add_column(self):
      		lower = random.randint(0, 360) // 64
      		higher = random.randint(0, 360) // 64
      		y = 45
      		for i in range(lower):
      			column = Column(parent=self)
      			column.anchor_point = (0.5, 0)
      			column.position = (self.size.w, y)
      			y += 64
      		y = 738
      		for i in range(higher):
      			column = Column(parent=self)
      			column.anchor_point = (0.5, column.size.h)
      			column.position = (self.size.w, y)
      			y -= 64
      
      
      run(Game())
      

      This only makes ground and two columns at the end of the screen. The problem is that whenever I run this, the columns always at the same size. But I use random here, so they should get different each time. I can't get why is it so

      posted in Pythonista
      Karina
      Karina
    • Flappy bird

      Hello everyone! I'm writing the game and at the beginning now

      posted in Pythonista
      Karina
      Karina

    Latest posts made by Karina

    • RE: Game on scene, ball not moving

      @mikael thanks) why have I overlooked that

      posted in Pythonista
      Karina
      Karina
    • Game on scene, ball not moving

      Hey everyone
      I’ve begun to write smth like air hockey and for now stuck cause the ball stays on its place but prints that the position is changing. I can’t figure why, seems i’ve written it just like the paddles that can move

      Here’s the code, about a 100 lines

      
      from scene import *
      import math
      import random
      
      
      sw, sh = get_screen_size()[0], get_screen_size()[1]
      
      
      class Ball(SpriteNode):
      	def __init__(self, r=11, v=(1, 1), parent=None, *args, **kwargs):
      		self.size = (r*2, r*2)
      		self.v = Vector2(*v)
      		self.r = r
      		self.ball_speed = 10
      		self.angle = random.uniform(0, 2*math.pi)
      		SpriteNode('pzl:BallGray', color='purple', parent=parent, *args, **kwargs)
      
      
      
      class Game(Scene):
      	def setup(self):
      		self.background_color = 'black'
      		board_shape = ui.Path.rounded_rect(0, 0, sw-30, sh-30, 15)
      		board_shape.line_width = 4
      		self.board = ShapeNode(board_shape, position=(sw/2, sh/2), 
      						  stroke_color='#723d04', fill_color='#acacac',
      						  z_position=-1, parent=self)
      						  
      		self.left_player = SpriteNode('pzl:PaddleBlue', position=(-420, 0),
      									  parent=self.board)
      		self.left_player.rotation = math.pi/2
      		
      		self.right_player = SpriteNode('pzl:PaddleRed', position=(420, 0),
      									   parent=self.board)
      		self.right_player.rotation = math.pi/2
      		
      		self.right_touch, self.left_touch = (0, 0), (0, 0)
      		
      		self.spawn_ball()
      		
      		
      	def update(self):
      		print(self.ball.position)
      		x, y = self.ball.position + self.ball.v
      		self.ball.position = Point(x, y)
      			
      		
      	def touch_began(self, touch):
      		touch_loc = self.board.point_from_scene(touch.location)
      		if touch_loc in self.left_player.frame:
      			self.left_touch = touch.touch_id
      		elif touch_loc in self.right_player.frame:
      			self.right_touch = touch.touch_id
      		
      		
      	def touch_moved(self, touch):
      		if self.right_touch != (0, 0) or self.left_touch != (0, 0):
      			self.move_paddle(touch)
      				
      	
      	def touch_ended(self, touch):
      		touch_id = touch.touch_id
      		if touch_id == self.right_touch:
      			self.right_touch = (0, 0)
      		elif touch_id == self.left_touch:
      			self.left_touch = (0, 0)
      			
      			
      	def move_paddle(self, user_touch):
      		paddle = None
      		touch_id = user_touch.touch_id
      		delta_y = user_touch.location.y - user_touch.prev_location.y
      		if touch_id in self.left_touch:
      			paddle = self.left_player
      		elif touch_id in self.right_touch:
      			paddle = self.right_player
      			
      		if paddle:	
      			x, y = paddle.position
      			if delta_y > 0:
      				paddle.position = x, min(y + delta_y, sh/2 - 70)
      			elif delta_y < 0:
      				paddle.position = x, max(y + delta_y, -sh/2 + 70)
      				
      				
      	def spawn_ball(self):
      		self.ball = Ball(position=(0, 0), parent=self.board)
      		self.ball.v = (math.cos(self.ball.angle), math.sin(self.ball.angle))
      		
      
      	
      run(Game())
      
      
      posted in Pythonista
      Karina
      Karina
    • RE: Frame for tetris
      from scene import *
      import random, sound
      from arrows import *
      
      sw, sh = get_screen_size()
      rect_w = sw/3  #343.33
      rect_h = 612 #668
      side = int(rect_w/10)
      colors = ['red']
      
      x = side/2
      y = rect_h/2 - side/2
      dot =  [[
      		 [x, y]
      		 		]]
      		 		
      line = [
      		 [[x, y], [x+side, y]],
      		 [[x, y], [x, y-side]]
      							   ]
      							 
      shapes = [dot, line]
      
      
      class Board(ShapeNode):
      	def __init__(self, stroke_color='lightgrey', line_width=1, parent=None, *args, **kwargs):
      			path = ui.Path.rect(0, 0, rect_w, rect_h)
      			path.line_width = line_width
      			
      			if stroke_color == 'lightgrey':
      				d = int(rect_w/10)
      				for l in range(int(rect_w/d)):
      					x = l*d
      					path.move_to(x, 0)
      					path.line_to(x, rect_h)
      			
      			super().__init__(path,
      							 fill_color='white',
      							 stroke_color=stroke_color,
      							 parent=parent,
      							 *args, **kwargs)
      		
      
      
      class Game(Scene):
      	def setup(self):
      		self.background_color = 'white'
      		self.grey_rect = Board(line_width=2, parent=self, position=(sw/3, sh/2), z_position=0)
      		self.board = Board(stroke_color='purple', line_width=15, parent=self, position=(sw/3, sh/2), 	z_position=-1)
      		
      		self.seconds = 0
      		self.figure = {}
      		self.add_buttons()
      		self.add_figure()
      		
      	
      	def update(self):
      		self.seconds += self.dt
      		if self.seconds > 0.2:
      			for f in self.figure:
      				self.figure[f][1] -= side/2
      				f.position = self.figure[f]
      				self.seconds = 0
      				if f.position.y == - rect_h/2 + side/2:
      					self.figure.pop(f)
      					self.add_figure()
      					break
      					
      					
      	def touch_began(self, touch):
      		tapped = True
      		for arw in self.arrows:
      			if touch.location in arw.frame:
      				sound.play_effect('rpg:Chop')
      				arw.fill_color = '#969696'
      				
      				for f in self.figure:
      					if -rect_w/2 < self.figure[f][0] + side < rect_w/2:
      						if 'right' in arw.picture:
      							self.figure[f][0] += side
      					
      					if -rect_w/2 < self.figure[f][0] - side < rect_w/2:
      						if 'left' in arw.picture:
      							self.figure[f][0] -= side
      							
      	def touch_ended(self, touch):
      		for arw in self.arrows:
      			if arw.fill_color == '#969696':
      				arw.fill_color = 'white'
      				right = left = down = up = None;
      				
      
      	def add_buttons(self):
      		self.arrows = [Arrow(i, position=icons[i], parent=self) for i in icons] 
      
      			
      	def add_figure(self):
      		figure = random.choice(shapes)
      		#for example, var=0 for horizontal line, 1 - for vertical
      		var = random.choice(range(len(figure)))
      		print(figure[var])
      		global x 
      		global y
      		x = random.choice(range(10)) * side - rect_w/2 + side/2
      		y = rect_h/2 - side/2
      		for pos in figure[var]:
      			print(pos)
      			block = SpriteNode('pzl:Gray3', pos,            color=colors[shapes.index(figure)] , size=(side, side), parent=self.grey_rect)
      			self.figure[block] = pos
      
      
      run(Game())  
      

      There are a lot of bugs cause I move the blocks one by one. And I added colors but they mix with the original color

      posted in Pythonista
      Karina
      Karina
    • RE: Frame for tetris

      @cvp I did also moving blocks down, in cycle for, one by one each block. Is there a way think of a figure as a single block?

      posted in Pythonista
      Karina
      Karina
    • RE: Frame for tetris

      @cvp I thought to write how to move blocks right and left in the touch_began of arrows. But no matter, you did it easier👍

      posted in Pythonista
      Karina
      Karina
    • RE: Frame for tetris

      @cvp So the Tetris didn’t receive touches?
      I thought to put the moving ➡️⬅️ into arrows, but it would be much more confusing

      posted in Pythonista
      Karina
      Karina
    • RE: Frame for tetris

      And if with arrows? Maybe it looks on that touch_began

      from scene import *
      import sound
      
      
      def sw(): return get_screen_size()[0]
      def sh(): return get_screen_size()[1]
      def bw(): return 100
      def bh(): return 100
      
      right = left = down = up = None
      
      icons = {
      	     'iob:arrow_down_b_256' : (sw()/4*3, 60),
      	     'iob:arrow_up_b_256' : (sw()/4*3, bh() + 60),
      	     'iob:arrow_left_b_256' : (sw()/4*3 - 95, bh()),
      	     'iob:arrow_right_b_256' : (sw()/4*3 + 95, bh())
      	      }
      
      
      class Arrow(ShapeNode):
      	def __init__(self,
      				 picture,
      				 path=None,
      	             size=Size(120, 120),
      	             corner_radius=8,
      	             border_size=20,
      	             borderColor='#3f0917',
      	             position=(0,0),
      	             parent=None,
      	             *args, **kwargs):
      	             	
      	             	#for border
      	             	self.picture = picture
      	             	self.corner_radius = corner_radius
      	             	self.border_size = border_size
      	             	self.borderColor = borderColor
      	             	
      	             	self.position = position
      	             	self.size = size
      	             	
      	             	#for super()
      	             	self.x, self.y = position
      	             	self.w, self.h = size
      	             	
      	             	super().__init__(fill_color='white',
      	             					path=ui.Path.rounded_rect(self.x, 
      	             											   self.y,
      	             											   self.w/1.5, 
      	             											   self.h/1.5,
      	             											   self.corner_radius),
      	             					stroke_color=borderColor,
      	             					parent=parent,
      	             					*args, **kwargs)
      	             					
      	             	self._setup(self.picture)
      	             	                 
      	def _setup(self, pict):
      		if self.picture:
      			arrow = SpriteNode(self.picture,
      							   position=Point(0, 0), 
      							   size=(100, 100),
      							   parent=self)
      							   
      	             	                 
      
      class Main(Scene):            	                 
      	def setup(self):
      		fill_color = self.background_color
      		self.background_color = 'white'
      		self.arrows = [Arrow(i, position=icons[i], parent=self) for i in icons] 
      			
      			
      	def touch_began(self, touch):
      		tapped = True
      		for arw in self.arrows:
      			if touch.location in arw.frame:
      				sound.play_effect('rpg:Chop')
      				arw.fill_color = '#969696'
      				if 'right' in arw.picture:
      					global right
      					right = True
      				
      			
      	def touch_ended(self, touch):
      		for arw in self.arrows:
      			if arw.fill_color == '#969696':
      				arw.fill_color = 'white'
      				right = left = down = up = None
      				
      		
      				
      if __name__ == '__main__':				
      	run(Main(), PORTRAIT) 
      
      posted in Pythonista
      Karina
      Karina
    • RE: Frame for tetris

      You’re talking about that position in the beginnig, when I couldn’t move the purple rect from the corner?)

      posted in Pythonista
      Karina
      Karina
    • RE: Frame for tetris
      from scene import *
      import random
      import arrows
      
      sw, sh = get_screen_size()
      rect_w = sw/3  #343.33
      rect_h = 612 #668
      side = int(rect_w/10)
      colors = ['red']
      
      
      class Board(ShapeNode):
      	def __init__(self, stroke_color='lightgrey', line_width=1, parent=None, *args, **kwargs):
      			path = ui.Path.rect(0, 0, rect_w, rect_h)
      			path.line_width = line_width
      			
      			if stroke_color == 'lightgrey':
      				d = int(rect_w/10)
      				for l in range(int(rect_w/d)):
      					x = l*d
      					path.move_to(x, 0)
      					path.line_to(x, rect_h)
      			
      			super().__init__(path,
      							 fill_color='white',
      							 stroke_color=stroke_color,
      							 parent=parent,
      							 *args, **kwargs)
      		
      
      
      class Game(Scene):
      	def setup(self):
      		self.background_color = 'white'
      		self.grey_rect = Board(line_width=2, parent=self, position=(sw/3, sh/2), z_position=0)
      		self.board = Board(stroke_color='purple', line_width=15, parent=self, position=(sw/3, sh/2), 	z_position=-1)
      		
      		self.seconds = 0
      		self.figures = {}
      		self.add_buttons()
      		self.add_figure()
      		
      	
      	def update(self):
      		self.seconds += self.dt
      		if self.seconds > 0.5:
      			for f in self.figures:
      				self.figures[f][1] -= side/2
      				f.position = self.figures[f]
      				self.seconds = 0
      				if f.position.y == - rect_h/2 + side/2:
      					self.add_figure()
      					self.figures.pop(f)
      					
      					
      	def touch_began(self, touch):
      		print('touch_began')
      
      
      	def add_buttons(self):
      		ars = arrows.Main()
      		self.present_modal_scene(ars)
      
      				
      	def add_figure(self):
      		x = random.choice(range(10)) * side - rect_w/2 + side/2
      		y = rect_h/2 - side/2
      		block = SpriteNode('pzl:Yellow7', (x, y), z_position=1, size=Size(side, side), parent=self.grey_rect)
      		self.figures[block] = [x, y]
      
      
      run(Game())  
      

      Maybe you’ll check if it works?

      posted in Pythonista
      Karina
      Karina
    • RE: Frame for tetris

      @cvp it’s in the game class that inherited scene. And update in the class he sees

      posted in Pythonista
      Karina
      Karina