Pygame Maze game
Ok, so at my school we have to do a Senior project, and I decided that I would try to start programming. For starters, I decided to start taking VEX classes, which taught me a little basic "C" language. I wanted to create a game for my actual project, so I decided to make one of these silly maze games where you don't have to touch the walls with your mouse. I have this to the point where it will load the actual map when I hover over the ready button, but the actual game will not end there. This is my code so far and I am confused because after loading the maze the program will not do what it should when I touch the wall or when I touch the finish line.
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 is probably very rough code, but keep in mind that I am just getting started and that any useful input is appreciated :)
UPDATE: I am sending 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 is not in my code that is actual, just in my python folder. I installed python again (with a new installer) and it works fine. Thanks for the help:)
source to share
on your vague question, it seems that you are not getting enough feedback from your localization and bug fixing program and this may be an actual problem that you might want to solve.
You can benefit a lot from using tools that allow you to run your code line by line and check the state of each variable, so you can easily determine when and why your program is not behaving as you expected. I would recommend fooobar.com/questions/37695 / ... (as well as the links therein) for various approaches to debugging.
Besides using a code debugger, it is a good idea to start using a logger to print debug information at runtime with the required level of specificity. You can get more information on registrars from the link above, or you can just google it - I'm sure you'll find tons of tutorials once you know what to look for.
source to share