pygame

Python Pygame press two direction key and another key to shoot there's no bullet

时光怂恿深爱的人放手 提交于 2021-02-02 03:48:55
问题 I am trying to make a ship shoot a bullet, and everything it works as expected except when I press both UP , LEFT and then SPACE . Then there's no bullet being fired. There's no bullet being fired for RIGHT + DOWN + SPACE , UP + LEFT + SPACE either. However, when I press both UP , RIGHT and then SPACE , it workes. In fact, every other direction key LEFT + DOWN , UP + RIGHT , UP + DOWN works with SPACE key. Here's the code: #!/usr/bin/python import sys import pygame class Setting: def __init__

Python pygame - bouncing ball (UnboundLocalError: local variable 'move_y' referenced before assignment)

好久不见. 提交于 2021-02-02 03:47:33
问题 I wanted to create a function that is responsible for bouncing ball from the edge of the screen. I know i can do it better with math and Vector2 function but i wonder why i have this error, and why i can run window without this line of code: if ball.y >= HEIGHT - 10: move_y = -vall_vel Code class Ball: def __init__(self, x, y, color): self.x = x self.y = y self.color = color def draw(self, window): pygame.draw.circle(window, self.color, (self.x, self.y), 10) ball = Ball(WIDTH // 2, HEIGHT //

Python Pygame press two direction key and another key to shoot there's no bullet

谁说胖子不能爱 提交于 2021-02-02 03:47:06
问题 I am trying to make a ship shoot a bullet, and everything it works as expected except when I press both UP , LEFT and then SPACE . Then there's no bullet being fired. There's no bullet being fired for RIGHT + DOWN + SPACE , UP + LEFT + SPACE either. However, when I press both UP , RIGHT and then SPACE , it workes. In fact, every other direction key LEFT + DOWN , UP + RIGHT , UP + DOWN works with SPACE key. Here's the code: #!/usr/bin/python import sys import pygame class Setting: def __init__

Pygame rotating cubes around axis

拟墨画扇 提交于 2021-02-02 03:46:32
问题 I have been playing around with the example of a rotating cube here. I have generated 2 cubes that should rotate around the Y-axis. However, it doesn't seem to work as expected and I can't figure out what the problem of it is. Here is a working code example: import sys import math import pygame from pygame.math import Vector3 from enum import Enum class Color(Enum): BLACK = (0, 0, 0) SILVER = (192,192,192) class Cube(): def __init__(self, vectors, screen_width, screen_height, initial_angle=25

Pygame rotating cubes around axis

假装没事ソ 提交于 2021-02-02 03:46:01
问题 I have been playing around with the example of a rotating cube here. I have generated 2 cubes that should rotate around the Y-axis. However, it doesn't seem to work as expected and I can't figure out what the problem of it is. Here is a working code example: import sys import math import pygame from pygame.math import Vector3 from enum import Enum class Color(Enum): BLACK = (0, 0, 0) SILVER = (192,192,192) class Cube(): def __init__(self, vectors, screen_width, screen_height, initial_angle=25

How do you properly implement gravity to a free floating space object and some sort of friction when thrusting in opposite direction

与世无争的帅哥 提交于 2021-02-02 03:45:46
问题 I am trying to program movement that is basically like Asteroids where once UP button is pressed you accelerate to a certain speed and then because in space you don't stop and can only slow down by thrusting in opposite direction. On top of that, I would like gravity to be pulling you towards the bottom of the screen. I have this accomplished for the most part but the issue I have is: When I turn around and thrust opposite direction, it doesn't slow down first going backwards before starting

Pygame rotating cubes around axis

烈酒焚心 提交于 2021-02-02 03:44:51
问题 I have been playing around with the example of a rotating cube here. I have generated 2 cubes that should rotate around the Y-axis. However, it doesn't seem to work as expected and I can't figure out what the problem of it is. Here is a working code example: import sys import math import pygame from pygame.math import Vector3 from enum import Enum class Color(Enum): BLACK = (0, 0, 0) SILVER = (192,192,192) class Cube(): def __init__(self, vectors, screen_width, screen_height, initial_angle=25

How do you properly implement gravity to a free floating space object and some sort of friction when thrusting in opposite direction

房东的猫 提交于 2021-02-02 03:44:50
问题 I am trying to program movement that is basically like Asteroids where once UP button is pressed you accelerate to a certain speed and then because in space you don't stop and can only slow down by thrusting in opposite direction. On top of that, I would like gravity to be pulling you towards the bottom of the screen. I have this accomplished for the most part but the issue I have is: When I turn around and thrust opposite direction, it doesn't slow down first going backwards before starting

Python pygame - bouncing ball (UnboundLocalError: local variable 'move_y' referenced before assignment)

孤人 提交于 2021-02-02 03:44:09
问题 I wanted to create a function that is responsible for bouncing ball from the edge of the screen. I know i can do it better with math and Vector2 function but i wonder why i have this error, and why i can run window without this line of code: if ball.y >= HEIGHT - 10: move_y = -vall_vel Code class Ball: def __init__(self, x, y, color): self.x = x self.y = y self.color = color def draw(self, window): pygame.draw.circle(window, self.color, (self.x, self.y), 10) ball = Ball(WIDTH // 2, HEIGHT //

Python pygame - bouncing ball (UnboundLocalError: local variable 'move_y' referenced before assignment)

隐身守侯 提交于 2021-02-02 03:44:05
问题 I wanted to create a function that is responsible for bouncing ball from the edge of the screen. I know i can do it better with math and Vector2 function but i wonder why i have this error, and why i can run window without this line of code: if ball.y >= HEIGHT - 10: move_y = -vall_vel Code class Ball: def __init__(self, x, y, color): self.x = x self.y = y self.color = color def draw(self, window): pygame.draw.circle(window, self.color, (self.x, self.y), 10) ball = Ball(WIDTH // 2, HEIGHT //