コード例 #1
0
 def update(self):
     self.pos.add(self.vel)
     self.vel.multiply(0.85)
     self.nextFrame()
     if(self.pos.y<=350):
         self.vel.add(Vector(0,0.45))
     
     if(self.pos.y >= 350):
         self.vel.add(Vector(-0.5,0))
コード例 #2
0
class Bomb:
   
    def __init__ (self, sprite, pos, radius=10): 
        self.k = random.randrange(50,350)
        self.pos = Vector(self.k,50)
        self.vel = Vector()
        self.sprite = simplegui.load_image('http://personal.rhul.ac.uk/zeac/084/Image_bomb.png') 
        self.image = simplegui.load_image('http://personal.rhul.ac.uk/zeac/084/Image_bomb_single.jpeg')
        self.width = 1440 
        self.height = 1400 
        self.rows = 5 
        self.columns = 5 
        self.frameWidth = 589/5 
        self.frameHeight = 589/5
        self.frameCentreX = self.frameWidth/2 
        self.frameCentreY = self.frameHeight/2 
        self.canvasX = self.width/2 
        self.canvasY = self.height/2 
        self.dimX = 100 #Size of image/sprite on the canvas
        self.dimY = 100 
        self.frameIndex = [5, 4] 

    def draw(self, canvas): 
        if(self.pos.y<=350):
            canvas.draw_image(self.image,
                          (218/2,224/2),
                          (218,224),
                          self.pos.getP(),
                          (self.dimX,self.dimY))
            
        if(self.pos.y>=350):
            canvas.draw_image(self.sprite, 
                          (self.frameWidth*self.frameIndex[0]+self.frameCentreX,self.frameHeight*self.frameIndex[1]+self.frameCentreY), 
                          (self.frameWidth, self.frameHeight), 
                          self.pos.getP(), 
                          (self.dimX, self.dimY)) 

       
                    
                    
    def nextFrame(self): 
        self.frameIndex[0]= (self.frameIndex[0]+1)%self.columns 
        if self.frameIndex[0] == 0: 
            self.frameIndex[1]=(self.frameIndex[1]+1)%self.rows 
    def update(self):
        self.pos.add(self.vel)
        self.vel.multiply(0.85)
        self.nextFrame()
        if(self.pos.y<=350):
            self.vel.add(Vector(0,0.45))
        
        if(self.pos.y >= 350):
            self.vel.add(Vector(-0.5,0))
コード例 #3
0
class Wheel:
    def __init__(self, pos, radius=10):
        self.pos = pos
        self.vel = Vector()
        self.radius = max(radius, 10)
        self.colour = 'White'

    def draw(self, canvas):
        canvas.draw_circle(self.pos.getP(), self.radius, 1, self.colour,
                           self.colour)

    def update(self):
        self.pos.add(self.vel)
        self.vel.multiply(0.85)
コード例 #4
0
 def __init__(self, x, border, color):
     self.x = x
     self.border = border
     self.color = color
     self.normal = Vector((1, 0))
     self.edgeR = x + 1 + self.border
     self.edgeL = x - 1 - self.border
コード例 #5
0
 def __init__ (self, sprite, pos, radius=10): 
     self.k = random.randrange(50,350)
     self.pos = Vector(self.k,50)
     self.vel = Vector()
     self.sprite = simplegui.load_image('http://personal.rhul.ac.uk/zeac/084/Image_bomb.png') 
     self.image = simplegui.load_image('http://personal.rhul.ac.uk/zeac/084/Image_bomb_single.jpeg')
     self.width = 1440 
     self.height = 1400 
     self.rows = 5 
     self.columns = 5 
     self.frameWidth = 589/5 
     self.frameHeight = 589/5
     self.frameCentreX = self.frameWidth/2 
     self.frameCentreY = self.frameHeight/2 
     self.canvasX = self.width/2 
     self.canvasY = self.height/2 
     self.dimX = 100 #Size of image/sprite on the canvas
     self.dimY = 100 
     self.frameIndex = [5, 4] 
コード例 #6
0
 def update(self):
     if self.keyboard.right:
         self.wheel.vel.add(Vector(1, 0))
     if self.keyboard.left:
         self.wheel.vel.add(Vector(-1, 0))
コード例 #7
0
 def __init__(self, pos, radius=10):
     self.pos = pos
     self.vel = Vector()
     self.radius = max(radius, 10)
     self.colour = 'White'
コード例 #8
0

class Interaction:
    def __init__(self, wheel, keyboard):
        self.wheel = wheel
        self.keyboard = keyboard

    def update(self):
        if self.keyboard.right:
            self.wheel.vel.add(Vector(1, 0))
        if self.keyboard.left:
            self.wheel.vel.add(Vector(-1, 0))


kbd = Keyboard()
wheel = Wheel(Vector(WIDTH / 2, HEIGHT - 40), 40)
inter = Interaction(wheel, kbd)


def draw(canvas):
    inter.update()
    wheel.update()
    wheel.draw(canvas)


frame = simplegui.create_frame('Interactions', WIDTH, HEIGHT)
frame.set_draw_handler(draw)
frame.set_keydown_handler(kbd.keyDown)
frame.set_keyup_handler(kbd.keyUp)
frame.start()
コード例 #9
0
                    
    def nextFrame(self): 
        self.frameIndex[0]= (self.frameIndex[0]+1)%self.columns 
        if self.frameIndex[0] == 0: 
            self.frameIndex[1]=(self.frameIndex[1]+1)%self.rows 
    def update(self):
        self.pos.add(self.vel)
        self.vel.multiply(0.85)
        self.nextFrame()
        if(self.pos.y<=350):
            self.vel.add(Vector(0,0.45))
        
        if(self.pos.y >= 350):
            self.vel.add(Vector(-0.5,0))
  


  

k = Bomb(Vector(width/2,height/2), 40)

def draw(canvas):
    k.draw(canvas)
    k.update()

frame = simplegui.create_frame('Interactions', width, height)
frame.set_draw_handler(draw)
frame.set_canvas_background('White')
frame.start()