Pygame罪,cos,tan计算圆形运动路径

时间:2017-05-21 14:43:30

标签: pygame

我已经挣扎了几天知道如何弄清楚如何使图像在圆形路径中移动。我在这里看过其他帖子,但我无法得到它。

那么我如何在圆形路径中移动图像。我的代码只将我的图像移动45度然后停止。我需要它完整的循环并继续这样做。

当前代码:

[u8]

1 个答案:

答案 0 :(得分:1)

你可以使用public class Student { public int xh { get; set; } public string xm { get; set; } public string xb { get; set; } public string csrq { get; set; } public string jg { get; set; } public string sjhm { get; set; } public string yxh { get; set; } public string mm { get; set; } } public class StudentDBContext : DbContext { public StudentDBContext() : base("schoolDB") { } public DbSet<Student> Students { get; set; } } <add name="schoolDB" connectionString="Data Source=DESKTOP-*****;Initial Catalog=school;Persist Security Info=True;User ID=***;Password=***" providerName="System.Data.SqlClient" /> 并在每一帧中旋转它,按半径缩放它并将其添加到pygame.math.Vector2位置以获得小圆圈的当前中心。

CENTER

编辑:如果您希望红球跟随鼠标,那么如果您将x和y设置为鼠标位置import sys import pygame pygame.init() screen = pygame.display.set_mode((400, 400)) clock = pygame.time.Clock() CENTER = (200, 200) RADIUS = 100 # A unit vector pointing to the right. direction = pygame.math.Vector2(1, 0) run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False pygame.quit() sys.exit() direction.rotate_ip(4) # By 4 degrees. # Normalize it, so that the length doesn't change because # of floating point inaccuracies. direction.normalize_ip() # Scale direction vector, add it to CENTER and convert to ints. ball_pos = [int(i) for i in CENTER+direction*RADIUS] screen.fill((255,255,255)) pygame.draw.circle(screen, (71,153,192), CENTER, RADIUS) pygame.draw.circle(screen, (243,79,79), ball_pos, 16) pygame.display.update() clock.tick(30) ,则您的示例实际上有效。

x, y = pygame.mouse.get_pos()