プレイヤーの画像がマウスに続く十字線に向くようにしたかったので、画像を回転させる機能を使用し、多くの問題(角度が正しくない、機能を適切に使用していないなど)を解決した後、イメージャーを回転させましたが、プレーヤーの画像で使用すると機能しません。まず、プレーヤーの画像が画面に表示されません。次に、ゲームが信じられないほど遅くなります。次に、呪いをしばらく動かした後、エラーが返されます。
これは私のスクリプトです:
#set up
import pygame, sys, random, time, math
from pygame.locals import *
from math import atan2, degrees, pi
pygame.init()
#variables end----------------------------------------------------------------
#imagers
grass = "grass_shit.png" #grass image
player_img = "shithead.png" #player name
ali_img = "shit_head2.png" #alien image
dead_screen = "dead_shit.png"
cross_hair = "crosshair.png"
#screen
screen = pygame.display.set_mode((850, 640),0,32) #set screen
background = pygame.image.load(grass).convert() #load image to screen
#character variables
char = pygame.image.load(player_img).convert_alpha() #covert player image
player_x, player_y = 0, 0 #character position
move_player_x, move_player_y = 0, 0 #how far the character will move, #x is left and right, y is up and down
#alien variables
ali = pygame.image.load(ali_img).convert_alpha() #covert alien image
ali_x, ali_y = random.randint(10, 480), random.randint(10, 500)
move_ali_x, move_ali_y = 0, 0
#mouse things
crosshair = pygame.image.load(cross_hair).convert_alpha()
#other
blit_everything = True
dead = False
#variables end----------------------------------------------------------------
while True:
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
if event.type==KEYDOWN:
if event.key==K_a:
move_player_x=-3
elif event.key==K_d:
move_player_x=+3
elif event.key==K_w:
move_player_y=-3
elif event.key==K_s:
move_player_y=+3
if event.type==KEYUP:
if event.key==K_a:
move_player_x=0
elif event.key==K_d:
move_player_x=0
elif event.key==K_w:
move_player_y=0
elif event.key==K_s:
move_player_y=0
if event.type==KEYDOWN:
if event.key== K_LEFT:
move_player_x=-3
elif event.key== K_RIGHT:
move_player_x=+3
elif event.key==K_UP:
move_player_y=-3
elif event.key== K_DOWN:
move_player_y=+3
if event.type==KEYUP:
if event.key==K_LEFT:
move_player_x=0
elif event.key==K_RIGHT:
move_player_x=0
elif event.key==K_UP:
move_player_y=0
elif event.key==K_DOWN:
move_player_y=0
if ali_x < player_x:
move_ali_x =+ 0.5
elif ali_x > player_x:
move_ali_x =- 0.5
if ali_y < player_y:
move_ali_y =+ 0.5
elif ali_y > player_y:
move_ali_y =- 0.5
ali_y += move_ali_y
ali_x += move_ali_x
ali_rect = pygame.Rect(ali_x, ali_y, 35, 35)
player_x += move_player_x
player_y += move_player_y
char_rect = pygame.Rect(player_x, player_y, 35, 35)
if char_rect.colliderect(ali_rect):
background = pygame.image.load(dead_screen).convert()
blit_everything = False
dead = True
mouse_x, mouse_y = pygame.mouse.get_pos()
mouse_x -= crosshair.get_width() / 2
mouse_y -= crosshair.get_height() / 2
dx = player_x - mouse_x
dy = player_y - mouse_y
player_atan = atan2(-dy, dx)
player_atan %= 2 * pi
player_angle = degrees(player_atan)
char = pygame.transform.rotate(char, player_angle)
print player_angle
screen.blit(background,(0,0))
#blit everything
if blit_everything == True:
screen.blit(char,(player_x,player_y))
screen.blit(ali,(ali_x, ali_y))
screen.blit(crosshair,(mouse_x, mouse_y))
pygame.display.update()
エラーは次のとおりです。
Traceback (most recent call last):
File "/home/claude/Dropbox/BigKahunaBurger/BigKahunaBurger LOOP.py", line 160, in <module>
char = pygame.transform.rotate(char, player_angle)
error: Width or height is too large
>>>
161行目で、プログラムに角度を出力させて、角度であることを確認しました。これが得られます。
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
162.829790545
159.757500243
149.225963899
126.609372987
152.009531506
114.018423659
すべての数値が角度であることがわかるように、角度を四捨五入してみましたが、効果はありませんでした。
どんな助けでも大歓迎です
ありがとうございました