• BurntRice

    Have any of you actually tested the code or not?
    I’ve got two half done codes for each scenario, so can you just quickly test it @ccc? I’m quite slow, and very busy with other work (got a deadline in the next 3 days, and I’m only half-way). If you get back to me then I can just focus on one strong effort.

    posted in Pythonista read more
  • BurntRice

    Um, who is correct out of you two?
    Your two comments kinda contradict each other.

    posted in Pythonista read more
  • BurntRice

    Why won’t this work?

    from scene import *
    import turtle 
    import ui 
    import math
    import random
    A = Action()
    direction = 1
    #Setting up background colour for the entire scene
    class Game(Scene):
        def setup(self):
            self.bg = SpriteNode('spc:BackgroundBlack')
            self.lasers = []
            
            #Creating the player
            self.Player = SpriteNode('shp:RoundRect')
            self.Player.color = ("cyan")
            self.Player.anchor_point = (0.5, 0)
            self.Player.position = (512, 400)
            self.add_child(self.Player)
            
            #Controlling the player
            self.UpCrtl = SpriteNode('iow:arrow_up_b_32')
            self.UpCrtl.x_scale = 3.5/1.0
            self.UpCrtl.y_scale = 3.5/1.0
            self.UpCrtl.alpha = 0.5
            self.UpCrtl.position = (175, 295)
            self.add_child(self.UpCrtl)
            
            self.DownCrtl = SpriteNode('iow:arrow_down_b_32')
            self.DownCrtl.x_scale = 3.5/1.0
            self.DownCrtl.y_scale = 3.5/1.0
            self.DownCrtl.alpha = 0.5
            self.DownCrtl.position = (175, 130)
            self.add_child(self.DownCrtl)
            
            self.RightCrtl = SpriteNode('iow:arrow_right_b_32')
            self.RightCrtl.x_scale = 3.5/1.0
            self.RightCrtl.y_scale = 3.5/1.0
            self.RightCrtl.alpha = 0.5
            self.RightCrtl.position = (250, 212.5)
            self.add_child(self.RightCrtl)
            
            self.LeftCrtl = SpriteNode('iow:arrow_left_b_32')
            self.LeftCrtl.x_scale = 3.5/1.0
            self.LeftCrtl.y_scale = 3.5/1.0
            self.LeftCrtl.alpha = 0.5
            self.LeftCrtl.position = (100, 212.5)
            self.add_child(self.LeftCrtl)
            
            #The button for shooting
            self.laserButton = SpriteNode('shp:Circle')
            self.laserButton.color = ('gray')
            self.laserButton.x_scale = 3/1
            self.laserButton.y_scale = 3/1
            self.add_child(self.laserButton)
            self.laserButton.position = (1000, 212.5)
    
        def update(self):
            for touch in self.touches.values():
                if touch.location in self.LeftCrtl.bbox:
                    #left button pressed
                    direction = 4
                    new_x = self.Player.position.x - 5
                    if new_x >= 0 and new_x <= 1100:
                        self.Player.position = (new_x, self.Player.position.y)
                        
                if touch.location in self.RightCrtl.bbox:
                    #right button pressed
                    direction = 2
                    new_x = self.Player.position.x + 5
                    if new_x >= 0 and new_x <= 1100:
                        self.Player.position = (new_x, self.Player.position.y)
                
                if touch.location in self.UpCrtl.bbox:
                    direction = 1
                    new_y = self.Player.position.y + 5
                    if new_y >= 0 and new_y <= 800:
                        self.Player.position = (self.Player.position.x, new_y)
                    
                if touch.location in self.DownCrtl.bbox:
                    direction = 3
                    new_y = self.Player.position.y - 5
                    if new_y >= 0 and new_y <= 800:
                        self.Player.position = (self.Player.position.x, new_y)
                        
                if touch.location in self.laserButton.bbox:
                    new_laser = SpriteNode('spc:LaserBlue6')
                    new_laser.position=(self.Player.position.x,self.Player.position.y + 6)
                    self.add_child(new_laser)
                    self.lasers.append(new_laser)
    
                for l in self.lasers:
                    if direction() = 1:
                    l.position = (l.position.x, l.position.y + 75)
                    if direction() = 2:
                        l.position = (l.position.x + 75, l.position.y)
                        if.direction() = 3:
                            l.position = (l.position.x, l.position.y - 75)
                            if direction() = 4:
                                l.position = (l.position.x + 75, l.position.y)
    
    if __name__ == '__main__':
        run(Game(), LANDSCAPE, show_fps=True)
    

    posted in Pythonista read more
  • BurntRice

    Also, if you can add code for creating a scrolling background, that would be pretty good to (or adding a link to a previous forum).

    posted in Pythonista read more
  • BurntRice

    I need the type of code so that depending on which direction button was pressed last, the lasers fires in that direction. My code so far only shoots in a positive x axis. I need it to shoot in negative x axis, and positive and negative y axis as well.
    Here is my code so far:

    from scene import *
    import turtle 
    import ui 
    import math
    import random
    A = Action()
    #Setting up background colour for the entire scene
    class Game(Scene):
        
        def setup(self):
            self.bg = SpriteNode('spc:BackgroundBlack')
            self.lasers = []
            
            #Creating the player
            self.Player = SpriteNode('shp:RoundRect')
            self.Player.color = ("cyan")
            self.Player.anchor_point = (0.5, 0)
            self.Player.position = (512, 400)
            self.add_child(self.Player)
            
            #Controlling the player
            self.UpCrtl = SpriteNode('iow:arrow_up_b_32')
            self.UpCrtl.x_scale = 3.5/1.0
            self.UpCrtl.y_scale = 3.5/1.0
            self.UpCrtl.alpha = 0.5
            self.UpCrtl.position = (175, 295)
            self.add_child(self.UpCrtl)
            
            self.DownCrtl = SpriteNode('iow:arrow_down_b_32')
            self.DownCrtl.x_scale = 3.5/1.0
            self.DownCrtl.y_scale = 3.5/1.0
            self.DownCrtl.alpha = 0.5
            self.DownCrtl.position = (175, 130)
            self.add_child(self.DownCrtl)
            
            self.RightCrtl = SpriteNode('iow:arrow_right_b_32')
            self.RightCrtl.x_scale = 3.5/1.0
            self.RightCrtl.y_scale = 3.5/1.0
            self.RightCrtl.alpha = 0.5
            self.RightCrtl.position = (250, 212.5)
            self.add_child(self.RightCrtl)
            
            self.LeftCrtl = SpriteNode('iow:arrow_left_b_32')
            self.LeftCrtl.x_scale = 3.5/1.0
            self.LeftCrtl.y_scale = 3.5/1.0
            self.LeftCrtl.alpha = 0.5
            self.LeftCrtl.position = (100, 212.5)
            self.add_child(self.LeftCrtl)
            
            #The button for shooting
            self.laserButton = SpriteNode('shp:Circle')
            self.laserButton.color = ('gray')
            self.laserButton.x_scale = 3/1
            self.laserButton.y_scale = 3/1
            self.add_child(self.laserButton)
            self.laserButton.position = (1000, 212.5)
            
        def update(self):
            for touch in self.touches.values():
                if touch.location in self.LeftCrtl.bbox:
                    #left button pressed
                    new_x = self.Player.position.x - 5
                    if new_x >= 0 and new_x <= 1100:
                        self.Player.position = (new_x, self.Player.position.y)
                        
                if touch.location in self.RightCrtl.bbox:
                        #right button pressed
                    new_x = self.Player.position.x + 5
                    if new_x >= 0 and new_x <= 1100:
                        self.Player.position = (new_x, self.Player.position.y)
                
                if touch.location in self.UpCrtl.bbox:
                    new_y = self.Player.position.y + 5
                    if new_y >= 0 and new_y <= 800:
                        self.Player.position = (self.Player.position.x, new_y)
                    
                if touch.location in self.DownCrtl.bbox:
                    new_y = self.Player.position.y - 5
                    if new_y >= 0 and new_y <= 800:
                        self.Player.position = (self.Player.position.x, new_y)
    
                if touch.location in self.laserButton.bbox:
                    new_laser = SpriteNode('spc:LaserBlue6')
                    new_laser.position = (self.Player.position.x, self.Player.position.y + 60)
                    self.add_child(new_laser)
                    self.lasers.append(new_laser)
    
            for l in self.lasers:
                l.position = (l.position.x, l.position.y + 7.5)
                if l.position.y > 800:
                    l.remove_from_parent()
                    self.lasers.remove(l)
    
    
    if __name__ == '__main__':
        run(Game(), LANDSCAPE, show_fps=True)
    

    posted in Pythonista read more
  • BurntRice

    I have another problem, with the up and down buttons (I haven’t implemented your code yet but I will soon.)
    Here is my code.

    from scene import *
    import turtle 
    import ui 
    import math
    import random
    A = Action()
    #Setting up background colour for the entire scene
    class Game(Scene):
        
        def setup(self):
            self.bg = SpriteNode('spc:BackgroundBlack')
                    
            #Creating the player
            self.Player = SpriteNode('shp:RoundRect')
            self.Player.color = ("cyan")
            self.Player.anchor_point = (0.5, 0)
            self.Player.position = (600, 400)
            self.add_child(self.Player)
            
            #Controlling the player
            self.UpCrtl = SpriteNode('iow:arrow_up_b_32')
            self.UpCrtl.x_scale = 3.5/1.0
            self.UpCrtl.y_scale = 3.5/1.0
            self.UpCrtl.alpha = 0.5
            self.UpCrtl.position = (175, 295)
            self.add_child(self.UpCrtl)
            
            self.DownCrtl = SpriteNode('iow:arrow_down_b_32')
            self.DownCrtl.x_scale = 3.5/1.0
            self.DownCrtl.y_scale = 3.5/1.0
            self.DownCrtl.alpha = 0.5
            self.DownCrtl.position = (175, 130)
            self.add_child(self.DownCrtl)
            
            self.RightCrtl = SpriteNode('iow:arrow_right_b_32')
            self.RightCrtl.x_scale = 3.5/1.0
            self.RightCrtl.y_scale = 3.5/1.0
            self.RightCrtl.alpha = 0.5
            self.RightCrtl.position = (250, 212.5)
            self.add_child(self.RightCrtl)
            
            self.LeftCrtl = SpriteNode('iow:arrow_left_b_32')
            self.LeftCrtl.x_scale = 3.5/1.0
            self.LeftCrtl.y_scale = 3.5/1.0
            self.LeftCrtl.alpha = 0.5
            self.LeftCrtl.position = (100, 212.5)
            self.add_child(self.LeftCrtl)
            
            #The button for shooting
            self.laserButton = SpriteNode('shp:Circle')
            self.laserButton.color = ('gray')
            self.laserButton.x_scale = 3/1
            self.laserButton.y_scale = 3/1
            self.add_child(self.laserButton)
            self.laserButton.position = (1000, 212.5)
            
        def update(self):
            for touch in self.touches.values():
                if touch.location in self.LeftCrtl.bbox:
                    #left button pressed
                    new_x = self.Player.position.x - 5
                    if new_x >= 0 and new_x <= 1024:
                        self.Player.position = (new_x, self.Player.position.y)
                        
                if touch.location in self.RightCrtl.bbox:
                        #right button pressed
                        new_x = self.Player.position.x + 5
                        if new_x >= 0 and new_x <= 1024:
                            self.Player.position = (new_x, self.Player.position.y)
                
                if touch.location in self.UpCrtl.bbox:
                        new_y = self.Player.position.y + 5
                        if new_y >= 0 and new_y <= 1024:
                            self.Player.position = (new_y, self.Player.position.x)
                        
                if touch.location in self.DownCrtl.bbox:
                        new_y = self.Player.position.y - 5
                        if new_y >= 0 and new_y <= 1024:
                            self.Player.position = (new_y, self.Player.position.x)
    
    
    if __name__ == '__main__':
        run(Game(), LANDSCAPE, show_fps=True)
    

    posted in Pythonista read more
  • BurntRice

    Thank you. I’m a beginner so learning to simplify code will be really good.

    posted in Pythonista read more
  • BurntRice

    Thank you so much.

    posted in Pythonista read more
  • BurntRice

    I don’t know my code isn’t working, (I’m pretty new to this), and I need to fix this soon as this is a school project. Please help.
    Here is my code so far:

    from scene import *
    import turtle 
    import ui 
    import math
    import random
    A = Action()
    #Setting up background colour for the entire scene
    class Game(Scene):
        
        def setup(self):
            self.bg = SpriteNode('spc:BackgroundBlack')
                    
            #Creating the player
            self.Player = SpriteNode('shp:RoundRect')
            self.Player.color = ("cyan")
            self.Player.anchor_point = (0.5, 0)
            self.Player.position = (600, 400)
            self.add_child(self.Player)
            
            #Controlling the player
            self.UpCrtl = SpriteNode('iow:arrow_up_b_32')
            self.UpCrtl.x_scale = 3.5/1.0
            self.UpCrtl.y_scale = 3.5/1.0
            self.UpCrtl.alpha = 0.5
            self.UpCrtl.position = (175, 295)
            self.add_child(self.UpCrtl)
            
            self.DownCrtl = SpriteNode('iow:arrow_down_b_32')
            self.DownCrtl.x_scale = 3.5/1.0
            self.DownCrtl.y_scale = 3.5/1.0
            self.DownCrtl.alpha = 0.5
            self.DownCrtl.position = (175, 130)
            self.add_child(self.DownCrtl)
            
            self.RightCrtl = SpriteNode('iow:arrow_right_b_32')
            self.RightCrtl.x_scale = 3.5/1.0
            self.RightCrtl.y_scale = 3.5/1.0
            self.RightCrtl.alpha = 0.5
            self.RightCrtl.position = (250, 212.5)
            self.add_child(self.RightCrtl)
            
            self.LeftCrtl = SpriteNode('iow:arrow_left_b_32')
            self.LeftCrtl.x_scale = 3.5/1.0
            self.LeftCrtl.y_scale = 3.5/1.0
            self.LeftCrtl.alpha = 0.5
            self.LeftCrtl.position = (100, 212.5)
            self.add_child(self.LeftCrtl)
            
            
            #The button for shooting
            self.laserButton = SpriteNode('shp:Circle')
            self.laserButton.color = ('gray')
            self.laserButton.x_scale = 3/1
            self.laserButton.y_scale = 3/1
            self.add_child(self.laserButton)
            self.laserButton.position = (1000, 212.5)
            
            def update(self):
                for touch in self.touches.values():
                    if touch.location in self.LeftCrtl.bbox:
                        #left button pressed
                        new_x = self.Player.position.x - 5
                        if new_x >= 0 and new_x <= 1024:
                            self.Player.position = (new_x, self.Player.position.y)
                            
                    if touch.location in self.RightCrtl.bbox:
                            #right button pressed
                            new_x = self.Player.position.x + 5
                            if new_x >= 0 and new_x <= 1024:
                                self.Player.position = (new_x, self.Player.position.y)
                                
                            
                
                        
    if __name__ == '__main__':
        run(Game(), LANDSCAPE, show_fps=True)
    

    posted in Pythonista read more
  • BurntRice

    @BurntRice Touch mechanism

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!