当前位置: 首页>>代码示例>>Python>>正文


Python vec2d.vec2d函数代码示例

本文整理汇总了Python中vec2d.vec2d函数的典型用法代码示例。如果您正苦于以下问题:Python vec2d函数的具体用法?Python vec2d怎么用?Python vec2d使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了vec2d函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: move

 def move(self, dt):
     moving = True
     if self.direction[0]: #up
         self.dir = vec2d(0,-5)
         self.dir.length = self.speed
         self.animate.switch("walk", "up")
         self.image = self.animate.update(dt)
     elif self.direction[1]: #left
         self.dir = vec2d(-5,0)
         self.dir.length = self.speed
         self.animate.switch("walk", "left")
         self.image = self.animate.update(dt)
     elif self.direction[2]: #down
         self.dir = vec2d(0,5)
         self.dir.length = self.speed
         self.animate.switch("walk", "down")
         self.image = self.animate.update(dt)
     elif self.direction[3]: #right
         self.dir = vec2d(5,0)
         self.dir.length = self.speed
         self.animate.switch("walk", "right")
         self.image = self.animate.update(dt)
     else:
         moving = False
         self.animate.switch("idle")
         self.animate.new = True
         self.image = self.animate.update(dt)
     if moving:
         self.pos += self.dir
         self.rect.center = self.pos.inttup()
开发者ID:Exodus111,项目名称:Projects,代码行数:30,代码来源:entity.py

示例2: __init__

 def __init__(self, screen, img_filename, init_position,
              init_direction, speed):
     """Skapar ett nytt kryp.
     
     @param screen: Ytan där krypet ska målas. 
     @param image_filname: Image file för krypet.
     @param init_position: Startposition.
     @param init_direction: Startriktning.
     @param speed: Hastighet i pixels/ms
     
     """
     pygame.sprite.Sprite.__init__(self)
     if Creep.explosion_sound is None:
         # Ladda bara ljudet EN gång, en statisk variabel
         Creep.explosion_sound = pygame.mixer.Sound(os.path.join('sound','bomb_explosion.wav'))
     self.explosion_sound = Creep.explosion_sound
     self.explosion_sound.set_volume(0.2)
     self.health = 5
     self.state = Creep.ALIVE
     self.screen = screen
     self.speed = speed
     self.explosion_image = pygame.image.load(os.path.join('images','boom.png')).convert_alpha()
     self.explosion_timer = 0        
     # Originalbilden
     self.base_image = pygame.image.load(img_filename).convert_alpha()
     # Bilden som skall roteras osv
     self.image = self.base_image
     # Rect behövs för den kolissionshanteringen
     self.rect = self.image.get_rect()
     # Start-position. En vektor
     self.pos = vec2d(init_position)
     # Start-riktning. En normaliserad vektor
     self.direction = vec2d(init_direction).normalized()
开发者ID:iingemar,项目名称:fishwarz,代码行数:33,代码来源:creep.py

示例3: __init__

    def __init__(
        self,
        surface,
        pos=vec2d(0, 0),
        size=vec2d(200, 50),
        text="",
        textcolor=(0, 0, 0),
        padding=0,
        bgcolor=(255, 255, 255),
    ):
        print "In textEntry init method"
        self.surface = surface
        self.pos = pos
        self.size = size
        self.text = text
        self.textcolor = textcolor
        self.padding = padding
        self.clicked = False
        self.rect = Rect(self.pos.x, self.pos.y, self.size.x, self.size.y)
        self.lastKey = ""
        self.delay = 1

        # creates a text label to place in the middle of the rectangle
        self.font = pygame.font.SysFont("Times New Roman", 25)
        self.textOverlay = self.font.render(self.text, 1, self.textcolor)
        self.textSize = vec2d(self.font.size(self.text))
        self.textRect = Rect(self.pos.x, self.pos.y, self.textSize.x, self.textSize.y)
开发者ID:tabtab200097,项目名称:game,代码行数:27,代码来源:widgets.py

示例4: check

 def check(self, player):
     mtop = mleft = mbottom = mright = False
     collided = pygame.sprite.spritecollide(player, self.walls, False)
     if collided != []:
         for brick in collided:
             if not mtop: mtop = brick.rect.collidepoint(player.rect.midtop)
             if not mleft: mleft = brick.rect.collidepoint(player.rect.midleft)
             if not mbottom: mbottom = brick.rect.collidepoint(player.rect.midbottom)
             if not mright: mright = brick.rect.collidepoint(player.rect.midright)
         if mtop:
             if player.direction["up"]:
                 wall_vector = vec2d(10,0)
                 player.dir = player.dir.projection(wall_vector)
         if mleft:
             if player.direction["left"]:
                 wall_vector = vec2d(0,10)
                 player.dir = player.dir.projection(wall_vector)
         if mbottom:
             if player.direction["down"]:
                 wall_vector = vec2d(10,0)
                 player.dir = player.dir.projection(wall_vector)
         if mright:
             if player.direction["right"]:
                 wall_vector = vec2d(0,10)
                 player.dir = player.dir.projection(wall_vector)
开发者ID:Exodus111,项目名称:Projects,代码行数:25,代码来源:load.py

示例5: __init__

    def __init__(self, screen, field, game,
                  image, init_pos, init_direction):
        """
            screen: obrazovka na ktoru sa bude vykraslovat
            
            field: rect v ktorom sa odohrava hra
            
            game: objekt hry
            
            image: ibrazok pre loptu
            
            init_direction = smer lopty na zaciatku
        """
        Sprite.__init__(self)
        
        self.screen = screen
        self.field = field
        self.game = game
        self.image = image
        self.pos = vec2d(init_pos)
        self.direction = vec2d(init_direction).normalized()

        self.speed = 0.35
        self.rect = self.image.get_rect()
        self.rect.center = self.pos
开发者ID:rado-r,项目名称:PygPong,代码行数:25,代码来源:gamedat.py

示例6: __init__

    def __init__(self, screen, field, init_position, init_direction, speed,
                 img_file, dead_img_file):

        Sprite.__init__(self)
        self.name = 'Creep'

        self.base_image = img_file
        self.image = self.base_image
        self.image_dead = dead_img_file

        self.screen = screen
        self.field = field

        self.pos = vec2d(init_position)
        self.direction = vec2d(init_direction).normalized()
        self.speed = speed

        self.state = self.ALIVE

        self.attack_power = 10
        self.deffence_power = 5

        self.life = 100

        self.max_life = 100
        self.image_w, self.image_h = self.image.get_size()
        self.reborn_time = 0
        self._time_moving = 0
        self._time_moving_max = random.randint(5000, 10000)

        self.bullets = []
开发者ID:lepovica,项目名称:Lost-Nero,代码行数:31,代码来源:creep.py

示例7: get_interfaces

 def get_interfaces(self, x,y):
     sides = {}
     sides["left"] = [vec2d(x, y+z) for z in self.interfaces]
     sides["right"] = [vec2d(self.dis+x, y+z) for z in self.interfaces]
     sides["top"] = [vec2d(x+z, y) for z in self.interfaces]
     sides["bottom"] = [vec2d(x+z, y+self.dis) for z in self.interfaces]
     return sides
开发者ID:Marco-Meyer,项目名称:TINF13AIBI-Kinect,代码行数:7,代码来源:electronics.py

示例8: main

def main():

    # sets up pygame
    pygame.init()
    pygame.display.set_caption("Pysics")
    screen = pygame.display.set_mode((500, 590))
    clock = pygame.time.Clock()
    world = pysicsWorld.world(screen)
    lastdraw = 0

    circle = pysicsObj.object(screen, world, "player", 10, "circle")
    circle.pos = vec2d(320, 240)
    circle.size = 5
    circle.mass = 1

    for i in range(50):
        circle = pysicsObj.object(screen, world, "circle" + str(i), 10, "circle")
        circle.pos = vec2d(random.randint(0, screen.get_width()), random.randint(0, screen.get_height()))
        circle.vel = vec2d(screen.get_size()) / 2 - circle.pos

    circle2 = pysicsObj.object(screen, world, "circle2", 10, "circle")
    circle2.pos = vec2d(320, 0)
    circle2.vel = vec2d(0, 0)
    circle2.size = 5
    circle2.mass = 1

    # game loop
    while 1:

        # cap the framerate at 60 frames per second
        elapsed_time = clock.tick(60)
        lastdraw += elapsed_time
        circle = world.objects[0]

        # handle user input
        for e in pygame.event.get():
            if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
                pygame.quit()
                return

                # move the player with the arrow keys
        key = pygame.key.get_pressed()
        if key[K_LEFT]:
            circle.applyforce(vec2d(-100, 0))
        if key[K_RIGHT]:
            circle.applyforce(vec2d(100, 0))
        if key[K_UP]:
            circle.applyforce(vec2d(0, -200))
        if key[K_DOWN]:
            circle.applyforce(vec2d(0, 100))
        if not key[K_DOWN] and not key[K_LEFT] and not key[K_RIGHT] and not key[K_UP]:
            circle.vel = 0
        circle2.acc = vec2d(0, 10)
        # draw everything

        world.update(elapsed_time)
        if lastdraw > 15:
            world.draw()
            lastdraw = 0
        pygame.display.flip()
开发者ID:zrksyd,项目名称:jusall-programinghw,代码行数:60,代码来源:pysics.py

示例9: on_update

def on_update(dt):
    # going to store the old position, for collision purposes
    old_pos = vec2d(cell.x, cell.y)

    # move the cell towards it's velocity
    cell.x += cell.velocity[0] * dt
    cell.y += cell.velocity[1] * dt

    # check for collisions against wall
    # if one is found, get new position, to allow "sliding"
    # against them
    radius = cell_image.width / 2 * 0.8
    i = 0
    if cell.velocity != (0, 0):
        while i < len(lines):
            p1 = vec2d(lines[i], lines[i + 1])
            p2 = vec2d(lines[i + 2], lines[i + 3])
            line = p2 - p1
            normal = line.perpendicular_normal()
            vec = (cell.x, cell.y) + radius * normal
            intersects = line_intersect(old_pos, vec, p1, p2)
            if not intersects is None:
                new_pos = calc_new_pos(old_pos, vec, p1, p2)
                new_pos -= radius * normal
                cell.x = new_pos.x
                cell.y = new_pos.y
            elif circle_point_intersect(cell.position, radius, p1):
                direction = cell.position - p1
                length = direction.length
                move_by_distance = radius - length
                new_pos = cell.position + direction.normalized() * move_by_distance
                cell.x = new_pos.x
                cell.y = new_pos.y
            i += 4
开发者ID:chris-statzer,项目名称:survivebynine,代码行数:34,代码来源:test_col.py

示例10: __init__

	def __init__(self, screen, game, creep_images, explosion_images,
				field, init_position, init_direction, speed):
		"""Create a new Creep.
			init_position: A vec2d or a pair specifying the initial
			position of the creep on the screen. """

		Sprite.__init__(self)

		self.screen = screen
		self.game = game
		self.speed = speed
		self.field = field


		# base_image holds original image, positioned to angle 0.
		# image will be rotated
		self.base_image_0 = creep_images[0]
		self.base_image_45 = creep_images[1]

		self.image = self.base_image_0
		self.explosion_images = explosion_images

		# vector specifying creep's position on screen
		self.pos = vec2d(init_position)
		self.prev_pos = vec2d(self.pos)

		# the direction is a normalized vector
		self.direction = vec2d(init_direction).normalized()

		self.state = Creep.ALIVE
		self.health = 15
开发者ID:Waveharp,项目名称:Pygame-experiments,代码行数:31,代码来源:main.py

示例11: detectact

 def detectact(self, target, curpos):
     if curpos.get_distance(vec2d(646, 456)) <= 15:
         new_drone = self.buy_drone()
         if new_drone: 
             target.drones.append(new_drone)
     if curpos.get_distance(vec2d(696, 456)) <= 15:
         self.buy_battery()
开发者ID:Lordmordevil,项目名称:BotWars,代码行数:7,代码来源:buildings.py

示例12: mouseUp

 def mouseUp(self, button, pos):
     
     if pos[1] < 400:
         if button == 3:
             if type(self.selected) is Drone:
                 self.selected.droneaction(self, pos)
             elif type(self.selected) is MainBase or \
                         type(self.selected) is Outpost:
                 self.selected.target = vec2d(pos[0] + self.hud.pos[0],
                                         pos[1] + self.hud.pos[1])
         elif button == 1:
             found = 0
             for drone in self.drones:
                 if drone.pos.get_distance(vec2d(pos[0] + self.hud.pos[0],
                                         pos[1] + self.hud.pos[1])) < 20:
                     self.selected = drone
                     found = 1;
             if found == 0:
                 for building in self.buildings:
                     if building.pos.get_distance(vec2d(pos[0] + self.hud.pos[0],
                                         pos[1] + self.hud.pos[1])) < building.size:
                         self.selected = building
                  
     # ------------------- Hud control ------------------------
     else:
         curpos = vec2d(pos)
         if button == 1:
             self.selected.detectact(self, curpos)
开发者ID:Lordmordevil,项目名称:BotWars,代码行数:28,代码来源:game.py

示例13: collide

    def collide(creep1, creep2):
        if creep1.id != creep2.id:
            if pygame.sprite.collide_mask(creep1, creep2):
                if creep1.type != creep2.type and creep1.health <= creep2.health:
                    creep1.rotate(-30, 30)
                    creep1.health -= 1
                    creep2.health -= 0.5
                    if creep1.health <= 0:
                        True
                        creep1.kill()
            elif creep1.elapsed_time > randint(100, 500):
                if pygame.sprite.collide_circle_ratio(4)(creep1, creep2):
                    if creep1.type != creep2.type:
                        if creep1.health > creep2.health:
                            creep2.curspeed = uniform(creep2.curspeed * 1.2, creep2.curspeed * 1.3)
                            creep1.curspeed = uniform(creep1.curspeed * 1.1, creep1.curspeed * 1.2)
                            if creep1.curspeed > creep1.speedmax:
                                creep1.curspeed = creep1.speedmax
                            if creep2.curspeed > creep2.speedmax:
                                creep2.curspeed = creep2.speedmax
                        vec = vec2d(creep2.rect.x - creep1.rect.x, creep2.rect.y - creep1.rect.y)
                        if creep1.health > creep2.health:
                            creep1.rotate(creep1.direction.get_angle_between(vec) + randint(-10, 10))
                        else:
                            creep1.rotate(creep1.direction.get_angle_between(vec) - 180 + randint(-10, 10))

            else:
                if (
                    pygame.sprite.collide_circle_ratio(10)(creep1, creep2)
                    and creep1.health >= creep2.health
                    and (creep1.type == creep2.type and creep1.elapsed_time >= 300)
                ):
                    vec = vec2d(creep2.rect.x - creep1.rect.x, creep2.rect.y - creep1.rect.y)
                    creep1.rotate(creep1.direction.get_angle_between(vec) + randint(-20, 20))
开发者ID:peterlenagh,项目名称:creep,代码行数:34,代码来源:Creep.py

示例14: __init__

 def __init__(self, finestra, posicio = 'centre'):
     self.finestra = finestra
     if posicio == 'centre':
         self.posicio = vec2d(finestra.get_rect().center)
     self.direccio = vec2d(0,-1)
     self.cap = self.Cap(self.posicio)
     self.cap.set_direccio(self.direccio)
开发者ID:Paubaquero,项目名称:projecte-RPG,代码行数:7,代码来源:main.py

示例15: draw

 def draw(self, screen, focus, alpha):
     screen_pos = vec2d(int(self.pos[0] * CELL_SIZE + 15 - focus[0]), int(self.pos[1] * CELL_SIZE + 15 - focus[1]))
     sprite_size = self.sprite.get_size()
     screen_iso_pos = vec2d(screen_pos[0] - screen_pos[1], int((screen_pos[0] + screen_pos[1])/2))
     screen.blit(self.sprite,
                 (int(screen_iso_pos[0] - sprite_size[0] // 2),
                  int(screen_iso_pos[1] - sprite_size[1] // 2)),
                 special_flags=pygame.BLEND_MULT)
开发者ID:Lordmordevil,项目名称:Architects_dreem,代码行数:8,代码来源:map.py


注:本文中的vec2d.vec2d函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。