当我尝试使用变量创建一个形状时,我不断收到此错误消息:
"TypeError:期望整数参数,浮点数"
import pygame._view
import pygame, sys
from pygame.locals import *
import random
pygame.init()
Run Code Online (Sandbox Code Playgroud)
...
barrel = pygame.image.load("images\Barrel.gif")
barrel_create = 0
barrelx = screen.get_height()- barrel.get_height()
barrely = screen.get_width()/2 - barrel.get_width()/2
barrel_exist = 0
explosion_delay = 0
Run Code Online (Sandbox Code Playgroud)
...
while running:
if barrel_exist == 0:
if barrel_create == 500:
barrely = 200
barrelx = random.randint(0,400)
barrel_exist = 1
if barrel_exist == 1:
barrely = barrely + 0.1
if barrely > 400:
barrel_exist = 0
if explosion_delay > 0:
pygame.draw.circle(screen, (0,255,0), (barrelx, barrely), …Run Code Online (Sandbox Code Playgroud) 当我使用math.cos()和math.sin()函数时,我的python解释器表现得很时髦.例如,如果我在计算器上执行此操作:
cos(35)*15+9 = 21.28728066
sin(35)*15+9 = 17.60364655
Run Code Online (Sandbox Code Playgroud)
但是当我在python上执行此操作时(3.2和2.7)
>>> import math
>>> math.cos(35)*15+9
-4.5553830763726015
>>> import math
>>> math.sin(35)*15+9
2.577259957557734
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
编辑:为了以防万一,你如何将Python中的Radian更改为度?
我试图将SDL_mixer,SDL_ttf和SDL_image链接到我的项目,但由于某种原因,在编译我的代码时会弹出这些错误.我包含的头文件取决于它上面的库.我按此顺序链接到我的库:
MinGW32 OpenGL32 SDLmain SDL SDL_image SDL_ttf SDL_mixer
#include <map>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <GL/gl.h>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_ttf.h>
using namespace std;
#include "include_file.h"
#include "structure.h"
#include "player.h"
#include "healthclass.h"
#include "items.h"
#include "loadfiles.h"
#include "init_game.h"
#include "missions.h"
Run Code Online (Sandbox Code Playgroud)
那么错误:
obj\Release\main.o:main.cpp:(.text+0x16e): undefined reference to `Mix_LoadMUS'
obj\Release\main.o:main.cpp:(.text+0x197): undefined reference to `Mix_LoadWAV_RW'
obj\Release\main.o:main.cpp:(.text+0x1c0): undefined reference to `Mix_LoadWAV_RW'
obj\Release\main.o:main.cpp:(.text+0x1e9): undefined reference to `Mix_LoadWAV_RW'
obj\Release\main.o:main.cpp:(.text+0x7cd): undefined reference to `IMG_Load'
obj\Release\main.o:main.cpp:(.text+0x996): undefined reference to `TTF_RenderUTF8_Shaded' …Run Code Online (Sandbox Code Playgroud) python ×2
c++ ×1
codeblocks ×1
draw ×1
math ×1
mingw ×1
pygame ×1
sdl ×1
trigonometry ×1
variables ×1