Jump to content
  • Advertisement
Sign in to follow this  
Esys

[pygame] Drawing an Arc

This topic is 3051 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to draw a firing cone to show a ship's weapon's range given the firing arc, weapon range, and ship's facing. I can figure and draw the lines delineating the boundries of the cone, but I can't get the arc drawn right. I think the problem lies in that I can't define the Rect correctly that'll hold the arc. Any suggestions would be appreciated.
import pygame, math

pygame.init()

wRange = 150
wArc = 60
facing = 90

screen = pygame.display.set_mode((640,480))
bg = pygame.Surface(screen.get_size())
bg.fill((0,0,0))

screen.blit(bg, (0,0))

origin = (screen.get_width()/2, screen.get_height()/2)

arcMin = facing-wArc
arcMax = facing+wArc

coordMin = (
    math.cos(math.radians(arcMin))*wRange + origin[0],
    -(math.sin(math.radians(arcMin))*wRange) + origin[1]
    )

coordMax = (
    math.cos(math.radians(arcMax))*wRange + origin[0],
    -(math.sin(math.radians(arcMax))*wRange) + origin[1]
    )

facingRange = (
    origin[0],
    origin[1] + -(math.sin(math.radians(facing))*wRange)
    )

pygame.draw.line(screen, (255,0,0), origin, coordMin)
pygame.draw.line(screen, (255,0,0), origin, coordMax)
pygame.draw.line(screen, (0,255,0), origin, facingRange)

arcLeft = coordMax[0]
arcTop = facingRange[1]
arcW = coordMin[0] - coordMax[0]
arcH = coordMax[1] - facingRange[1]

print arcLeft, arcTop, arcW, arcH

arcRect = pygame.Rect(arcLeft, arcTop, arcW, arcH)
pygame.draw.arc(screen, (255,0,0), arcRect, math.radians(arcMin), math.radians(arcMax))

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
    pygame.display.flip()
  


Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!