This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
So i'm fairly new to Pygame and python in general and so i'm trying to make my first game from purely my own code, not fallowing a tutorial or anything and I'm encountering an issue that I just can't find the solution to, I'm using a placeholder ducky png as the 'obstacle' for the player to jump over and all the sprite needs to do is spawn just out of screen an travel from the right to the left side, which I actually have working. but when ever a new sprite is spawned in while another is on the screen is just disappears (I'll try and include a clip of the game running as an example). help please
example: https://www.loom.com/share/ceef743ee6104ca8ac9ec94e00809547
\/\/\/\/\/\/ #---code
#Dinosaur Game Cloneimport pygameimport randompygame.init()
screen = pygame.display.set_mode((800, 600))pygame.display.set_caption("Dinosaur game")
#----------------------Setup----------------------##
object current co-ordinates
x = 200
y = 300
# dimensions of the object
width = 40
height = 80
isjump = False
score = 0
# Force (v) up and mass m.
v = 7.5m = 1min = 1max = 3
# Indicates pygame is running
run = True#----------------------Class Setup----------------------#
def Your_score(score):
value = font_style.render("Your Score: " str(score), True, (213, 50, 80))
screen.blit(value, [10, 10])
font_style = pygame.font.SysFont("bahnschrift", 25)
class Object(pygame.sprite.Sprite):
def __init__(self, picture_path, pos_x, pos_y)
:super().__init__()
self.image = pygame.image.load(picture_path)
self.rect = self.image.get_rect()
self.pos_x = pos_x
self.pos_y = pos_y
self.rect.center = [pos_x, pos_y]
self.image = pygame.transform.scale(self.image, (50, 50))
def Move(self, pos_vel):
if run == True:
self.pos_x -= pos_vel
def Draw(self, surface):
surface.blit(self.image, (self.pos_x, self.pos_y))
def die(self):
pygame.sprite.spritecollide(player, object_group, True)
object_group = pygame.sprite.Group()new_object = Object("duck_back.png", 800, 270)
#----------------------Game Loop----------------------#
while run == True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.MOUSEBUTTONDOWN:
Object.die()
keys = pygame.key.get_pressed()
# if up arrow key is pressed
if isjump == False:
if keys[pygame.K_UP] and y == 300:
isjump = True
if isjump:
# calculate force (F). F = 1 / 2 * mass * velocity ^ 2.
F = (1 / 2) * m * (v ** 2)
y -= F
v = v-0.5
if v < 0:
m = -1
if v == -8:
isjump = False
v = 7.5
m = 1
screen.fill((0, 0, 0))
if y == 300 and keys[pygame.K_DOWN]:
player = pygame.draw.rect(screen, (255, 255, 255), (x, y-15, width, height-40))
else:
player = pygame.draw.rect(screen, (255, 255, 255), (x, y-50, width,height))
pygame.draw.rect(screen, (120, 120, 120), (0, 320, 800, 50))
chance = random.randint(1,200)
if chance == 1:
object_draw = True
print("spawn")
else:
object_draw = False
if object_draw == True:
new_object = Object("duck_back.png", 800, 270)
object_group.add(new_object)
score = 1
new_object.Draw(screen)
new_object.Move(5)
object_group.update(screen)
Your_score(score)
pygame.time.wait(15)
pygame.display.update()
pygame.quit()
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/pygame/comm...