So my professor gave us an assignment and I cannot figure out at all how to get it to work, he apparently gave us a hint yesterday but I was deathly ill. He doesn't really help and the book doesn't tell you either. So I know I'm new to this forum but can someone help? Here's the assignment:
This is all I have right now and I'm so lost, I can't even get the thing to draw a single rectangle!:
Okay I figured out how I get it to do the columns and rows correctly. I can't seem to figure out how to make the checkerboard effect like in the picture. And on top of that I need to make another image that is inside the rectangles D: I am now officially stuck.
Well I know nothing of Python, but as far as a 'general' (java/javascript/actionscript) approach, I'd probably do something like the following pseudocode. I'm assuming draw.rect's 0,0 means starting at x,y - so here goes:
for h in range (0, num_column) : for w in range (0, num_row) : color = color1 if((h + w) % 2 == 1) color = color2
pygame.draw.rect(screen, color, (w * rect_Width, h * rect_Height, rect_Width, rect_Height)) else: else:
As I said before, this is pseudocode and I know nothing about Python *I had to look up the for code, and there's a big chance I'm not using it 100% correct* - but it should give you some pointers. Here's a generic breakdown of what it does: - The double for-loop makes sure you call the code for each rectangle - the if statement leaves the color either at color1 or sets it to color2, by checking if h + w is uneven (1) - this is some pretty heavy pseudocode, beware! - you then use the draw.rect with the width and height params you created in the for loops.
Hmm, the above code is wrong (according to Python):
Traceback (most recent call last): File "something.py", line 10, in chkrboard = pygame.Surface(win_width, win_height) ValueError: size needs to be (int width, int height)
Hmm, the above code is wrong (according to Python):
Traceback (most recent call last): File "something.py", line 10, in chkrboard = pygame.Surface(win_width, win_height) ValueError: size needs to be (int width, int height)