I have tried what other sites said to move things but mine is not working like it should. I am trying to create a Stacker game.
I want all 3 blocks to move once the user presses either the left or right arrow key. I am using python 3.4.3
. I will try to get the boundaries in later once I get it to move first. When I run this it says can't assign to operator.-syntax error
. Here is my code.
import math
import random
import time
import pygame
import sys
import glob
pygame.init()
move=0
fps=60
blue=(0,0,255)
white=(255,255,255)
black=(0,0,0)
green=(0,155,0)
display_width=800
display_height=600
gamedisplay=pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Stacker')
clock=pygame.time.Clock()
speed=0
smallfont=pygame.font.SysFont("Arial",int(display_width/32))
mediumfont=pygame.font.SysFont("Arial",int(display_width/16))
largefont=pygame.font.SysFont("Arial",int(display_width/10))
gamedisplay.fill(green)
block=display_height/12
pygame.display.update()
def quit_game():
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
quit()
def intro_screen():
welcome_message = mediumfont.render(str("Welcome to Stacker!!!"), True,black)
gamedisplay.blit(welcome_message,(display_width/4,display_height/40))
how_to_play_1=smallfont.render(str("Your goal is to get to the major prize bar"),True,black)
gamedisplay.blit(how_to_play_1,(display_width/3.619909502,display_height/2))
how_to_play=smallfont.render(str("Press the space bar to stop the shape"),True,black)
gamedisplay.blit(how_to_play,(display_width/3.48583878,display_height/(12/7)))
pygame.display.update()
def middle_block():
pygame.draw.rect(gamedisplay, blue,(display_width/(32/15),display_height-block,block,block))
pygame.display.update()
def left_block():
pygame.draw.rect(gamedisplay, blue,(display_width/(32/13),display_height-block,block,block))
pygame.display.update()
def right_block():
pygame.draw.rect(gamedisplay, blue,(display_width/(32/17),display_height-block,block,block))
pygame.display.update()
def major_screen():
major_message = mediumfont.render(str("Major Prize Here!"), True,black)
gamedisplay.blit(major_message,(display_width/(10/3),display_height/40))
pygame.display.update()
def main_loop():
leadx=300
leady=300
clock.tick(fps)
intro_screen()
pygame.time.delay(8000)
gamedisplay.fill(green)
major_screen()
pygame.draw.rect(gamedisplay, blue,(display_width-display_width,display_height/8,display_width,display_height/60))
pygame.draw.rect(gamedisplay, blue,(display_width-display_width,display_height/2.4,display_width,display_height/60))
middle_block()
left_block()
right_block()
pygame.display.update()
gameexit=False
while not gameexit:
for event in pygame.event.get():
if event.type==pygame.QUIT:
gameexit=True
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_LEFT:
middle_block() and right_block() and left_block() -= 10
if event.key==pygame.K_RIGHT:
middle_block() and right_block() and left_block() += 10
if event.type==pygame.KEYUP:
if event.key==pygame.K_LEFT:
middle_block() and right_block() and left_block() -= 10
if event.key==pygame.K_RIGHT:
middle_block() and right_block() and left_block() += 10
pygame.display.update()
pygame.display.update()
pygame.display.update()
pygame.quit()
quit()
main_loop()