Stay N Tom

Showing a slice of what it means to be Thomas.

Pages

Sunday, December 11, 2011

Christmas time!!!!

Instead of me going on and on about programing I am going to show you how to make a christmas games that are fun.

Here is a yummy Christmas recipe.

Open your python window, open a new window on python and type this:





import pygame

running=True
screen=pygame.display.set_mode([600,700])
pygame.display.set_caption("Gingerbread Decorator")
help=pygame.image.load("resources/buttons/help.png")
screen.fill([255,255,255])
back=pygame.image.load("resources/buttons/back.png")
bread=pygame.image.load("resources/gingerbread.png")
frostin=pygame.image.load("resources/buttons/frost.png")
map=pygame.image.load("resources/map.png")
bites=[pygame.image.load("resources/buttons/bite_1.png"), pygame.image.load("resources/buttons/bite_2.png"),pygame.image.load("resources/buttons/bite_3.png"), pygame.image.load("resources/buttons/bite_4.png"),pygame.image.load("resources/buttons/bite_5.png"), pygame.image.load("resources/buttons/back.png"),]
candies_im={"red":pygame.image.load("resources/red.png"), "green":pygame.image.load("resources/buttons/gumgreen.png")}
buttons=[pygame.image.load("resources/buttons/clear.png"),pygame.image.load("resources/buttons/icing.png"),pygame.image.load("resources/buttons/red.png"),pygame.image.load("resources/buttons/gum.png"),pygame.image.load("resources/buttons/red_line.png"), pygame.image.load("resources/buttons/mouth.png")]

old_pos=[0,0]

clock=pygame.time.Clock()

temp_line=[]
frosting_dots=[]
lines=[]
candies=[]
#candy_struc=["type", [loc_x, loc_y]]
mouse_down=False
adding=""
state="add"

while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running=False
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_down=True
if pygame.mouse.get_pos()[1]<601: if map.get_at(pygame.mouse.get_pos())==(0,0,0, 255): if adding == "red": candies.append(["red", pygame.mouse.get_pos()]) if adding == "green": candies.append(["green", pygame.mouse.get_pos()]) if event.type == pygame.MOUSEBUTTONUP: mouse_down=False if adding=="line": lines.append(temp_line) temp_line=[] if mouse_down: if pygame.mouse.get_pos()[1]<601: if adding=="frost": #print map.get_at(pygame.mouse.get_pos()) if map.get_at(pygame.mouse.get_pos())==(0,0,0, 255): frosting_dots.append(pygame.mouse.get_pos()) if adding=="line": if map.get_at(pygame.mouse.get_pos())==(0,0,0, 255): temp_line.append(pygame.mouse.get_pos()) #if adding=="red": # candies.append(["red", pygame.mouse.get_pos()]) else: if pygame.mouse.get_pos()[0]>50 and pygame.mouse.get_pos()[0]<125 and pygame.mouse.get_pos()[1]>613 and pygame.mouse.get_pos()[1]<688: #clear frosting_dots=[] candies=[] lines=[] if pygame.mouse.get_pos()[0]>140 and pygame.mouse.get_pos()[0]<215 and pygame.mouse.get_pos()[1]>613 and pygame.mouse.get_pos()[1]<688: adding="frost" print "frost" if pygame.mouse.get_pos()[0]>230 and pygame.mouse.get_pos()[0]<305 and pygame.mouse.get_pos()[1]>613 and pygame.mouse.get_pos()[1]<688: adding="red" print "red" if pygame.mouse.get_pos()[0]>320 and pygame.mouse.get_pos()[0]<395 and pygame.mouse.get_pos()[1]>613 and pygame.mouse.get_pos()[1]<688: adding="green" print "green" if pygame.mouse.get_pos()[0]>410 and pygame.mouse.get_pos()[0]<485 and pygame.mouse.get_pos()[1]>613 and pygame.mouse.get_pos()[1]<688: adding="line" if pygame.mouse.get_pos()[0]>500 and pygame.mouse.get_pos()[0]<575 and pygame.mouse.get_pos()[1]>613 and pygame.mouse.get_pos()[1]<688: state="eat" #screen.fill([255,255,0]) screen.blit(back, [0,0]) screen.blit(bread, [0,0]) for dot in frosting_dots: #screen.blit(frosting, [dot[0]-7, dot[1]-7]) pygame.draw.circle(screen, [240,240,240], dot, 8, 0) #try: # pygame.draw.lines(screen, [240,240,240],False, frosting_dots, 10) #except: # pass for candy in candies: screen.blit(candies_im[candy[0]], [candy[1][0]-25, candy[1][1]-25]) for line in lines: try: pygame.draw.lines(screen, [255,0,0], False, line, 5) except: pass try: pygame.draw.lines(screen, [255,0,0], False, temp_line, 5) except: pass for i in range(0,len(buttons)): screen.blit(buttons[i], [i*90+50, 612]) if adding=="": screen.blit(help, [0,0]) if state=="eat": for bite in bites: screen.blit(bite, [0,0]) for i in range(0,len(buttons)): screen.blit(buttons[i], [i*90+50, 612]) if adding=="": screen.blit(help, [0,0]) pygame.display.flip() pygame.time.delay(500) candies=[] lines=[] frosting_dots=[] state="add" pygame.display.flip() clock.tick(60)



name it gingerbread.py


if you have any trouble running it tell me in the comment box. Happy Holidays everyone!!!!

2 comments: