Ok, so at my school we are required to do a Senior project, and I decided I would try and pick up on programing. To start out, I decided to start taking VEX classes, which taught me a bit of basic "C" language. I wanted to make a game for my actual project, so I decided to make one of those stupid maze games where you have to avoid touching the walls with your mouse. I have it to the point where it will load the actual map when I hover over the ready button, but the actual game won't finish beyond there. This is my code so far, and I am confused because after loading the maze, the program won't do what it's supposed to when I touch the wall or when I touch the finish point.
import pygame
from pygame import *
pygame.init()
done = False
getready = image.load('ready.png')
backdrop = image.load('map.png')
goon = image.load('continue.png')
maze2 = image.load('map2.png')
loose = image.load('loose.png')
screen = display.set_mode((700, 500))
display.set_caption('Maze Game')
event.set_grab(1)
while done == False:
screen.blit(getready, (0, 0))
display.update()
for e in event.get():
if e.type == KEYUP:
if e.key == K_ESCAPE:
done = True
if screen.get_at((mouse.get_pos())) == (0, 0, 0):
while done == False:
screen.blit(backdrop, (0, 0))
display.update()
if screen.get_at((mouse.get_pos())) == (0, 0, 0):
print("You touched the wall!")
done = True
elif screen.get_at((mouse.get_pos())) == (0, 255, 0):
screen.blit(goon, (0, 0))
display.update()
if e in event.get():
if e.type == KEYUP:
if e.key == K_y:
screen.blit(maze2, (0, 0))
display.update()
if e in event.get():
if e.type == KEYUP:
if e.key == K_y:
done = True
if screen.get_at((mouse.get_pos())) == (0, 0, 0):
screen.blit(victory, (0, 0))
display.update()
time.sleep(3)
for e in event.get():
if e.type == KEYUP:
if e.key == K_ESCAPE:
done = True
pygame.quit()
I know this probably is really crude code, but keep in mind I'm just starting, and that any helpful input is appreciated :)
UPDATE: I send my cousin the code, and he changed it to this:
import pygame
from pygame import *
pygame.init()
done = False
done2 = False
ref = image.load('ready.png')
loose = image.load('loose.png')
cntnu = image.load('continue.png')
goon = 0
screen = display.set_mode((700, 500))
display.set_caption('Maze Game')
event.set_grab(1)
while done == False:
screen.blit(ref, (0, 0))
display.update()
done2 = False
for e in event.get():
if e.type == KEYUP:
if e.key == K_ESCAPE:
done = True
if screen.get_at((mouse.get_pos())) == (0, 0, 0):
ref = image.load('map.png')
done2 = True
if screen.get_at((mouse.get_pos())) == (1, 0, 0):
screen.blit(loose, (0, 0))
display.update()
done2 = True
time.wait(2000)
done = True
if screen.get_at((mouse.get_pos())) == (0, 255, 0):
screen.blit(cntnu, (0, 0))
display.update()
time.wait(3000)
pygame.quit()
The problem was not in my code actualy, just in my python folder. I re-installed python (with a new installer) and it works fine. Thanks for every ones help :)
Update: I fixed the problem. It turns out that my code was working fine the whole time. The problem was actually with my python library. I re installed everything and it worked fine.