-2

So I am working on a project that needs a function to be duplicated and not let any space between all the shapes.

Basically, my problem is that I can find the way.

Code:

# importing modules
import pygame
import sys
import random

# colors
white = (255, 255, 255)
blue = (0, 0, 255)
red = (255, 0, 0)
green = (4, 255, 0)
brown=  (165,42,42)
# starting pygame
pygame.init()
# making a screen
(width, height) = (500, 500)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Mincraft')
running = True
# fps counter
clock = pygame.time.Clock()
print(clock)
def grass_block(green,brown):
    pygame.draw.rect(screen, green, (395, 0, 90,50))
    pygame.draw.rect(screen, brown, (395, 10, 90,50))
    pygame.draw.rect(screen, brown, (395, 20, 90,50))
# geting the x button to work
while running:
    grass_block(green,brown)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    pygame.display.update()
    clock.tick(60)

pygame.display.quit()
pygame.quit()
exit()

Side questions id=f someone could transform the rect to a 3d object and make every side with a texture?

Thanks, everyone who responds

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • *"Side questions id=f someone could transform the rect to a 3d object and make every side with a texture?"* - Read [Does PyGame do 3d?](https://stackoverflow.com/questions/4865636/does-pygame-do-3d/65618694#65618694) – Rabbid76 May 31 '21 at 17:47
  • 2
    *"So I am working on a project that needs a function to be duplicated and not let any space between each other"* - I don't think anyone knows what you mean. – Rabbid76 May 31 '21 at 17:49
  • @Rabbid76 how is it now? – YoLo_GR _Alex May 31 '21 at 17:55
  • It is still only just telling us what the task is. We don't know what specific problem you're having or what question you want to ask that you can't find any information about. – takendarkk May 31 '21 at 18:03
  • @takendarkk Very likely the question is: "How do I create a Minecraft clone using Pygame?". The answer is: "You can not". – Rabbid76 May 31 '21 at 18:05

1 Answers1

0

If you are trying to repeat the grass block so that it can be drawn multiple times you need to make quite a few modifications to your code.

First off why are you making colors you parameters

It is completely unnecessary to have

def grass_block(green,brown):

instead put the position of the "block" as the parameters def grass_block(x, y):

Now change your function to reflect these values:

def grass_block(x,y):
    pygame.draw.rect(screen, green, (x, 0 + y, 90,50))
    pygame.draw.rect(screen, brown, (x, 10 + y, 90,50))
    pygame.draw.rect(screen, brown, (x, 20 + y, 90,50))

then in you while loop have an additional loop that repeats the method

while running:
    for i in range("The amount of block you need to make"):
#this should make another block every repetition to the right of the previous
        grass_block(395 + (90 * i), "starting Y value") 

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    pygame.display.update()
    clock.tick(60)
Noah Hall
  • 1
  • 2
  • You really should learn a bit more about some of pythons basics, learn about some classes, and how functions work. Some youTube videos would really help you out – Noah Hall Jun 02 '21 at 17:12