I have made a simple game but I want to learn how to make a coin system for example
This is my code right any help I would appreciate Thanks! my game so fare
I want to learn how to make a simple coin system where coins spawn on my platforms and if I touch them I gain points and the coins would disappear Another Example but I am not there with imaging right now I am focusing with the basics right now like the first exampled I showed Thanks!!!!
import pygame
import random
import time
pygame.init()
# screen
window = pygame.display.set_mode((500,500))
pygame.display.set_caption("hyeo")
playerx = 350
playery = 250
# player
class player:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.isJump = False
self.JumpCount = 10
self.fall = 0
self.speed = 5
self.color = color
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
pygame.draw.rect(window, self.color, self.rect)
# enemy class
class enemys:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
pygame.draw.rect(window, self.color, self.rect)
# FPS
FPS = 60
clock = pygame.time.Clock()
# Colors
NiceBlue = (46, 196, 187)
NiceGreen = (48, 196, 46)
# define players by name
playerman = player(40,390,30,30, NiceBlue)
enemy1 = enemys(150,390,150,10, NiceGreen)
enemy2 = enemys(350,300,150,10, NiceGreen)
enemy3 = enemys(70,250,150,10, NiceGreen)
enemy4 = enemys(-1000,480,1900,60, NiceGreen)
# put them in a list so we can call all of them at the same time
enemies = [enemy1,enemy2,enemy3,enemy4]
# Coins my g
# main Loop
runninggame = True
while runninggame:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
runninggame = False
keys = pygame.key.get_pressed()
# Right and Left
if playerman.y < 250:
playerman.y += 1
for enemy in enemies:
enemy.y += playerman.speed
# FOR DOWN AND UP
if playerman.y > 450: #somewhere close to the bottom of the screen
playerman.y -= playerman.fall #reverse direction
for enemy in enemies:
enemy.y -= playerman.fall
if keys[pygame.K_LEFT]:
playerman.x -= playerman.speed
if playerman.x < 100:
playerman.x += playerman.speed
for enemy in enemies:
enemy.x += playerman.speed
if keys[pygame.K_RIGHT]:
playerman.x += playerman.speed
if playerman.x > 400:
playerman.x -= playerman.speed
for enemy in enemies:
enemy.x -= playerman.speed
if not playerman.isJump:
playerman.y += playerman.fall
playerman.fall += 1
collide = False
for enemy in enemies:
if playerman.rect.colliderect(enemy.rect):
collide = True
playerman.y = enemy.rect.top - playerman.height +1
if playerman.rect.right > enemy.rect.left and playerman.rect.left < enemy.rect.left - playerman.width:
playerman.x = enemy.rect.left - player.width
if playerman.rect.left < enemy.rect.right and playerman.rect.right > enemy.rect.right + playerman.width:
playerman.x = enemy.rect.right
break
if playerman.rect.bottom >= 500:
collide = True
playerman.isJump = False
playerman.JumpCount = 10
playerman.y = 500 - playerman.height
if collide:
if keys[pygame.K_SPACE]:
playerman.isJump = True
playerman.fall = 0
else:
if playerman.JumpCount > 0:
playerman.y -= (playerman.JumpCount*abs(playerman.JumpCount))*0.4
playerman.JumpCount -= 1
else:
playerman.isJump = False
playerman.JumpCount = 10
window.fill((0,0,0))
playerman.draw()
enemy1.draw()
enemy2.draw()
enemy3.draw()
enemy4.draw()
pygame.display.update()
pygame.quit()