Pages

Showing posts with label Code. Show all posts
Showing posts with label Code. Show all posts

Thursday, July 17, 2014

INVENTORY, EQUIPPING AND STORING PYTHON

#Came up with this for
#storing, and equiping items in python


inventory = []
armor = {"head": "rags",
    "torso":"rags",
    "arms":"rags",
    "legs":"cloth",
    "feet":"sandals",
    "special":"ill-concieved necklace"}
equipment = ["armor_head", "armor_torso", "armor_arms", "armor_legs", "armor_feet", "armor_special"]
item_armor ={
    "armor_head":["rags", "leather hat", "diamond plate helm"],
    "armor_torso":["rags", "leather armor", "diamond plate armor"],
    "armor_arms":["rags", "leather bracers", "diamond bracers"],
    "armor_legs":["cloth", "leather pants", "diamond pants"],
    "armor_feet":["sandals", "leather shoes", "diamond shoes"],
    "armor_special":["ill-concieved necklace", "charming bracelet", "lucky ring"]
}
def store_item(item):
    inventory.append(item)

def equip_item(item1, item2):
   
    if equipment.__contains__(item1):
       
        if "armor_head" == item1:
            old_item = armor["head"]
            store_item(old_item)
            armor["head"] = item2
            inventory.remove(item2)
           
        if "armor_torso" == item1:
            old_item = armor["torso"]
            store_item(old_item)
            armor["torso"] = item2
            inventory.remove(item2)

        if "armor_arms" == item1:
            old_item = armor["arms"]
            store_item(old_item)
            armor["arms"] = item2
            inventory.remove(item2)

        if "armor_legs" == item1:
            old_item = armor["legs"]
            store_item(old_item)
            armor["legs"] = item2
            inventory.remove(item2)
    else:
        print "item is not equipable"

stats = {
    "basedefense": 2,
    "strength": 3,
    "hit": 2,
    "armor": 4}
battlestats = {
    "defense" :   stats["basedefense"] + stats["armor"],
    "attack" : stats["strength"] + stats["hit"]
}
def updatestats():
   

    if armor["head"] == "rags":
        stats["armor"] = stats["armor"] +1
   
    if armor["head"] == "leather hat":
        stats["armor"] =  stats["armor"] +3

def updatebattlestats():
    battlestats["defense"] =   stats["basedefense"] + stats["armor"]
    battlestats["attack"] = stats["strength"] + stats["hit"]
   
    #else:
        #print "Not Working"

   
       
# I can use the 'hashtag' to take out the parts of the test I don't need   
   
def runtest():
    store_item( "leather hat")
    store_item( "leather armor")
    store_item( "leather pants" )
    store_item( "leather bracers" )
   
    #print armor
    #print inventory

    equip_item("armor_head", "leather hat")
    equip_item("armor_torso", "leather armor")
   
    #print armor
    #print inventory

    print stats
    print battlestats
    #print attack
    updatestats()
    updatebattlestats()
    print stats
    print battlestats
   
   

runtest()

Tuesday, June 24, 2014

Rainbows! Also a while loop tuple.

##  My while loop tuple.  Could x y z represent coordinates?


import pygame
from pygame.locals import*
import math
from sys import exit
from random import randint
R = 2
G = 0
B = 0


def run():
    pygame.init()
    screen= pygame.display.set_mode((800, 800))
       
    clock = pygame.time.Clock()
   
    while True:
       
        for event in pygame.event.get():
            if event.type == QUIT:
                exit()
   
       
        x = 2
        R = 0
        G = 0
        B = 0
        y = 0
        z = 0

        while (x > 1):
       
            R = R + 51
            G = 0
            B = 0
            pygame.draw.circle(screen, (R, G, B), (200, 200), 100)
       
            clock.tick(2)

            pygame.display.update()
            if R == 255 :
                y = 2
                x = 0
        while (y > 1):
            R = 0
            G = G + 51
            B = 0
            pygame.draw.circle(screen, (R, G, B), (200, 200), 100)
       
            clock.tick(2)

            pygame.display.update()
            if G == 255:
                z = 2
                y = 0

        while (z > 1):
            R = 0
            G = 0
            B = B + 51
            pygame.draw.circle(screen, (R, G, B), (200, 200), 100)
       
            clock.tick(2)

            pygame.display.update()
            if B == 255:
               
                z = 0



           
run()

Wednesday, May 7, 2014

pygame move formula

It's not working right,  But its a start.


import pygame
from pygame.locals import*

from sys import exit
import math

class MoveObject(object):
    def __init__(self, x1, y1, n, i, w, h, imgw, imgh):
        self.x1 = 0.0
        self.y1 = 0.0
        self.n = n
        self.i = i
        self.w = w
        self.h = h
        self.imgw = imgw
        self.imgh = imgh
       
       

   

    @classmethod
    def object_formula(self, x1, y1, n, i, w, h, imgw, imgh):
        if n * w >1 and n * w < w and i * h > 1 and i * h < h:
           
            return MoveObject(x1 + n * imgw, y1 + i * imgh)
        else:
            return (0 ,0)

def main(MoveObject):
   
    pygame.init()
    screen = pygame.display.set_mode((800, 800), 0, 32)
    UniBrush = pygame.image.load("apoobrush.png")
    unibrush = pygame.transform.scale(UniBrush, (90, 90))
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                exit()
       
       
        pressed_keys = pygame.key.get_pressed()
        if pressed_keys[K_LEFT]:
            n = -1.0
            n = n -1
        elif pressed_keys[K_RIGHT]:
            n = +1.0
            n = n + 1
        if pressed_keys[K_DOWN]:
            i = +1.0
            i = i + 1
        elif pressed_keys[K_UP]:
            i = -1.0
            i = i - 1
        else:
            n = 0
            i = 0
       
        (x, y) = MoveObject.object_formula(0, 0, n, i, 800, 800, 90, 90)
       
       
        screen.blit(unibrush, (x, y))
        pygame.display.flip()
       

main(MoveObject)
   
       
       
       
       
       

Monday, May 5, 2014

More on the rectangles.

If we take the Cartesian sum of a set  A and B,
Where A is the number of rects in the width
and B is the number of rects in the height...

(H * W)/ W =number of Width Rects (subtract one for A_max)
(H * W)/ H =number of Height Rects (subtract one for B_max)

Lets say it's a 4 x 5 rectangle.

So our two sets would be:
A = range(0, A_max)
B = range(0, B_max)
A = {(0, 1, 2, 3, 4)}
B = {(0, 1, 2, 3)}

the Cartesian set would be:
{(0,0), (0,1), (0,2), (0,3), (0, 4), (1, 0), (1, 1)....(4, 2), (4, 3)}

Each of these sets can represent the C and I in this formula,

(x + CW, y + IH)

Now how do I put it in a computer program, and how do I get it to save the results of each coordinates into a new list for the individual rects.... 

I want the program to be able to distinguish from the cartesian set and the formula, a set of individual rectangles.   That way all the rectangles in a map can be altered, or manipulated.

Kinda like a simple paint, but I don't want it to create them as we go.  I want them already gridded out, and then alterable from there. 

Lets say we can put an image in there like in photoshop, and alter it based on the individual rectanglular spots in the grid.

I don't know if this is how they do it already,  But just thinking that might be how the whole CGI stuff works.    Map a set of points, alter them as we see fit.

Except I just want a simple large-ish grid that can make simple sprites that are easily manipulated and moved, just like the Vector Class does in pygame,  but we can just click the squares and go.... I want these to move up by a vector of 2, 3,  these by 3, 4....  and so on until I've made my own animator without downloading a bunch of rediculously complicated software,  or maybe that's how it all already works and I just don't know it.

Either way, I want to create one myself...  cause I want to make simple sprites that move by with code,  not by image translation.
Are they the same thing?

Thursday, May 1, 2014

RECTANGLES

Been trying to figure out a formula that would allow me to make a loop which creates a screen filled with individual rectangles.


Here's what I come up with so far,  still have to write a program to fit it.

  x  axis,    width   of rectangles = w
  y axis,   hieght of rectangles = h
change in x = 1 =cx

 cx = cx + 1




   ---------------------------------------------------------------------------------------------------------------------------
  | (x, y)               |    (x +cx*w,  y)  |   ( x + cx*w, y)  |   (x + cx*w, y)   |   ( x + cx *w, y) |
  |______________ |________cx = 1__|______cx = 2_____|_______cx = 3____|______cx = 4____|
  |                                                                                                                                                       |
  | (x , y + h)  |   (x + cx*w, y +h) | (x + cx * w, y + h) |(x + cx*w, y + h) ......                  |
  |______________________________________________________________________________________|
  |                                                                                                                                                       |
  | (x, y + 2h)|  (x + cx*w, y + 2h) | ( x + cx *w, y + 2h)  ...........................................|
  |______________________________________________________________________________________|
  |                                                                                                                                                      |
  | (x, y + 3h) |  (x +cx*w, y + 3h) |( x + cx*w, y + 3h) .............................................|
  |______________________________________________________________________________________|

so for the rectangles within the rectangle.....  the origin, for pygame rect coordinates
would be (0, 0)  or (x, y),  
then every rect in the first column would be  (x, y + (i)*h)  where i would increase by one for each additional rect in the column.  
the next column would be (x +w, y+(i)*h)   and next (x + 2w,  y + (i)h)
and next (x + 3w, y +(i)*h)   the width would in crease by one multiple per column for x.

Or if we did rows,   the x would be the ( + (i)*w) and (y + h) only increasing once per row

Determined to get it to work.  Then have it make a list to keep track of each rectangle so it can be altered and changed. 
Maybe a "append.list[]"  for each rectangle created by the change in (i)



Tuesday, April 15, 2014

PsyGame

#the scores aren't working. 
#still trying to figure that out
#and then I'll try to make it into a class, instead of a function
 #need to add better instructions
#hold down your a,b,c  answer to see what the computer
#thinks of your answer.



import sys
import pygame
from pygame.locals import*
import math
from random import randint, choice
from math import*
from sys import exit

pygame.init()


              

one_results = {'a': 'so boringly normal.', 'b': 'At least you have an epi-pen. Right?',

                'c': 'Yea, I step on bees all the time.', 'd': 'Raid? Hell no, we got napalm.',

                'e': 'Sure, yell at it as it dies.', 'f': 'What makes you say that?',

                'g': 'Seriously? It is just a bee.'}

two_results = {'a': 'Kicking is fun. Alch-y.', 'b': 'Maybe if you yell explatives she will notice.',

                'c': 'Eh, you can get booze somewhere else.', 'd': 'throwing pine-sol at her might actually work.',

                'e': 'well maybe she can hear you, but the Captain Morgans is not going to fetch itself!',

                'f': 'but louder right?', 'g': 'That is illegal in 30 states.'}

three_results = {'a': 'again with the normal boring stuff!', 'b': 'At least you did not cry... did you?',

                'c': 'I aknowlege your suffering.', 'd': 'Fart in a can is the best for use in closed spaces. Kids love it.',

                'e': 'Did I mention the kids parent is extremely hot?', 'f': 'It was really good coffee after all.',

                'g': 'Uh-huh, and how long have you had these reactions?'}

four_results = {'a': 'It might work, but to what end?', 'b': 'It stuns them into silence. Good job!',

                'c': 'If they follow you, does the tree still fall in the woods?', 'd': 'Bleach... It might just burn thier throte enough...',

                'e': 'There is no try, only do!', 'f': 'Fine, I will kick them for you.', 'g': 'How are you going to get that into thier mouth?'}

five_results = {'a': 'normal is as normal does.', 'b': 'What because it might be something comming to get you?', 'c': 'My faucet leaks too.',

                'd': 'I love the smell of Lysol in the morning!', 'e': 'That does seem like a logical solution.',

                'f': 'Anything in particular, or the first thing that comes near?', 'g': 'Pretty sure you are not supposed to stick those in your ears.'}

six_results = {'a': 'Owww, oww owwy!', 'b': 'Sure, now you are a suspect.', 'c': 'Ninny ninny two by two, nothing left for you to do.',

                'd': 'Satan loves germs!', 'e': 'Oh, ok, but I really think you should explore this.', 'f': 'Are there three more churches near by?',

                'g': 'Hardly, the thing weighs 800 lbs!'}

seven_results = {'a': 'that seems inappropriate.', 'b': 'I think that is probably appropriate, next to wondering WTF.', 'c': 'LSD normal, or everyday normal?',

                'd': 'Might as well, reality is not working for you.', 'e': 'Louder then the growling Ninny-eater sitting over you?',

                'f': 'Yup, let me just write that down.', 'g': 'Cotton candy does sound delicious.'}

eight_results = {'a': 'Gas pedal or brake?', 'b': 'At least if you startle them, they might move.', 'c': 'or drive away...ninny',

                'd': 'Because they are sweaty gross bicyclist?', 'e': 'In a court of law, "I did not see them" will not fly.',

                'f': 'Honk, honk, honk.', 'g': 'So you are saying that you are not angry?'}

nine_results = {'a': 'Do not worry, I will not write that down...(writing quickly)', 'b': 'So more like panic, or dread?', 'c': 'Sure, it all makes sense now.',

                'd': 'Well as long they do not want you to drink it.', 'e': 'If it works, let me know.', 'f': 'Do the voices know what 51-50 means?',

                'g': 'That is very interesting. (run.... run now.)'}

ten_results = {'a': 'Make sure you wash your shoe afterward.', 'b': 'Bless you might have been better.', 'c': 'Good idea. Spread the plague to everyone.',

                'd': 'Splendid response.', 'e': 'You like that word?', 'f': 'Because blood is awesome.', 'g': 'It is for the good of all mankind.'}

eleven_results = {'a': 'Sure, kicking is always my first reaction.', 'b': 'Did I mention the individual is mute?',

                'c': 'Probably best. Ninny.', 'd': 'Especially if they touch you.',

                'e': 'It is ok not to answer.(ninny)', 'f': 'how about we just touch some lamposts and go watch monk?',

                'g': 'Is it legal for you to have that?'} #even responses.

twelve_results = {'a': 'eh, good thing I did not make it longer.', 'b': 'Results are gauranteed to be unprofessional, uneducated guesses. Ninny.',

                'c': 'Been on that couch a lot have you?', 'd': 'Please refrain from huffing until test is complete.', 'e': 'Ok, ok, I heard you.',

                'f': 'awww, it was not that bad.', 'g': 'I give, here are your results.'}  # odd responses.


   



even_choices = {'a': 'kick something/someone',
                'b': 'yell Shut the F--k up',
                'c': 'walk away',
                'd': 'always disinfect. Or run to nearest medical facility.',
                'e': 'no',
                'f': 'maybe if we do it 3 more times.',
                'g': 'other'}











H = 800
W = 800
screen = pygame.display.set_mode((H, W))
s_font = pygame.font.Font(None, 24)
font = pygame.font.Font(None, 32)
L_font = pygame.font.Font(None, 64)   
clock = pygame.time.Clock()
BLUE = (45, 0, 200)
GREEN = (0, 200, 45)
PURPLE = (200, 95, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 20)
WHITE = (240, 240, 255)   
WHITE1 = (200, 240, 255)



          
       
choicea = font.render("a = low anger", False, GREEN)
choiceb = font.render("b = anxiety", False, GREEN)
choicec = font.render("c = nothing,   this is normal", False, GREEN)
choiced = font.render("d = There is a can of gas that needs some using", False, GREEN)
choicee = font.render("e = Be louder,   that always works", False, GREEN)
choicef = font.render("f = just kill", False, GREEN)
choiceg = font.render("g = other", False, GREEN)

choicea2 = font.render("a = kick something/someone", False, GREEN)
choiceb2 = font.render("b = yell Shut the F--k up", False, GREEN)
choicec2 = font.render("c = walk away", False, GREEN)
choiced2 = font.render("d = always disinfect. Or run to nearest medical facility.", False, GREEN)
choicee2 = font.render("e =  'no'", False, GREEN)
choicef2 = font.render("f = maybe if we do it 3 more times.",False, GREEN)
choiceg2 = font.render("g = 'other'", False, GREEN)



def display_box():
    scorea = 0
    scoreb = 0
    scorec = 0
    scored = 0
    scoree = 0
    scoref = 0
    scoreg = 0
    scoreh = 0   
   
    pygame.draw.rect(screen, (200, 195, 100), (20, 20, 760, 760))
    pygame.draw.rect(screen, (BLUE), (30, 30, 740, 740), 10)
    intro = font.render("For instructions, press Space bar", False, BLUE)
    title1 = font.render("For entertainment only", False, GREEN)
    title2 = L_font.render("Personality", False, BLUE)
    title3 = L_font.render("Test", False, BLUE)
    title4 = s_font.render("illegitimate results will vary.",False, BLACK)
    author = font.render("Nellie Tobey, 2014", False, BLACK)
    clock.tick(30)
    instructionNext =font.render("to move on, push enter", False, BLUE)
       
    screen.blit(intro, (40, 40))
    screen.blit(title1, (60, 60))
    screen.blit(title2, (290, 300))
    screen.blit(title3, (340, 340))
    screen.blit(title4, (290, 380))
    screen.blit(author, (40, 640))
    pygame.display.flip()
   
   
   
   
           
    done = False   
   
    next = 0
    next_next = 0
    x = 1
    question_list = [" 1. You have stepped on a bee, and it died stinging you.",
                " 2. An elderly lady is blocking the way at the liquor store",
        " 3. A strangers child has knocked over your morning coffee.",
        " 4. Someone is trying to dramatically tell you a story.",
                " 5. A clicking noise is getting louder as you try to rest.",
                " 6. Someone has defiled a church and placed thier cross upside down.",
                " 7. You have awakened in a field of cotton candy neon blossoms.",
                " 8. The bicyclist in front of you refuses to get off the road even as you honk.",
                " 9. The voices say what?",
                " 10. A woman has sneezed and blood splatters on the floor in front of you.",
                " 11. A mysterious and dangerous looking individual is approaching you rapidly.",
                " 12. Are you tierd of questions?"]

   

    Results = font.render("Your scores. If you score higher then 20 any one catagorie..", False, BLACK)
    Results2 = font.render("... wow. And quit cheating my game!", False, BLACK)

    ResultsA = font.render( "Anger index = %r" % scorea, False, BLUE)

    ResultsB = font.render("Passive aggressive 'or just an angry asshole' index = %r" % scoreb, False, BLUE)

    ResultsC = font.render( "Normal, normal Ninny = %r" % scorec, False, BLUE)

    ResultsD = font.render( "Issues? Nothing prozac can't fix = %r" % scored, False, BLUE)

    ResultsE = font.render("Get your ears checked and/or Narcasism = %r" % scoree, False, BLUE)

    ResultsF = font.render( "OCD or Friggen nuts =  %r" % scoref, False, BLUE)

    ResultsG = font.render("Indecisive and/or Friggen Nuts = %r" % scoreg, False, BLUE)

    ResultsH = font.render( "Bat shit. = %r" % scoreh, False, BLUE)

   
    while done==False:
       
       
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
                exit()
       
        if next ==0:
            screen.blit(intro, (40, 40))
            screen.blit(title1, (60, 60))
            screen.blit(title2, (290, 300))
            screen.blit(title3, (340, 340))
            screen.blit(author, (40, 640))
            pygame.display.flip()
        keys = pygame.key.get_pressed()
        if (keys[K_SPACE]) and next == 0:
            next = +1
        if next == 1:           
            text = L_font.render("INSTRUCTIONS", False, (0, 35, 0))
            text_1 = font.render("push ENTER to begin your test!", False, (BLACK))

            pygame.draw.rect(screen, (200, 255, 255), (20, 20, 760, 760))
            screen.blit(text, (W/2 - 170, H/2 - 200))
            screen.blit(text_1, (W/2 - 100, H/2 - 150))

            pygame.display.flip()
            if (keys[K_RETURN]) and next ==1:
                next = 2
               
        elif next == 2:
            screen.fill(WHITE)
            pygame.draw.rect(screen, (BLUE), (30, 30, 740, 740), 10)
            question1 = font.render(question_list[0], False, RED)
            screen.blit(question1, (100, 50))
            screen.blit(choicea, (100, 120))
            screen.blit(choiceb, (100, 140))
            screen.blit(choicec, (100, 160))
            screen.blit(choiced, (100, 180))
            screen.blit(choicee, (100, 200))
            screen.blit(choicef, (100, 220))
            screen.blit(choiceg, (100, 240))
           
            instruction = font.render("choose your first response and press SPACE.", False, BLACK)
            screen.blit(instruction, (100, 300))
           
           
           
            pygame.display.flip()
           
       
            answer = ""
            if (keys[K_a]):
                answer = one_results['a']
                scorea = +1
            if (keys[K_b]):
                answer = one_results['b']
               
            if (keys[K_c]):
                answer = one_results['c']
               
            if (keys[K_d]):
                answer = one_results['d']
               
            if (keys[K_e]):
                answer = one_results['e']
               
            if (keys[K_f]):
                answer = one_results['f']
               
            if (keys[K_g]):
                answer = one_results['g']
               

            choices1 = font.render(answer, False, RED)
            screen.blit(choices1, (100, 390))
           
           
           
            if (keys[K_SPACE]) and (next ==2):
                next = 3
           
        elif next == 3:
            screen.fill(WHITE)
            pygame.draw.rect(screen, (BLACK), (30, 30, 740, 740), 10)
            question2 = font.render(question_list[1], False, RED)
            screen.blit(question2, (20, 50))
            screen.blit(choicea2, (100, 120))
            screen.blit(choiceb2, (100, 140))
            screen.blit(choicec2, (100, 160))
            screen.blit(choiced2, (100, 180))
            screen.blit(choicee2, (100, 200))
            screen.blit(choicef2, (100, 220))
            screen.blit(choiceg2, (100, 240))
            instruction = font.render("choose your first response and press ENTER.", False, BLACK)
            screen.blit(instruction, (100, 300))

       
            answer = ""
            if (keys[K_a]):
                answer = two_results['a']
               
            if (keys[K_b]):
                answer = two_results['b']
               
            if (keys[K_c]):
                answer = two_results['c']
               
            if (keys[K_d]):
                answer = two_results['d']
               
            if (keys[K_e]):
                answer = two_results['e']
               
            if (keys[K_f]):
                answer = two_results['f']
               
            if (keys[K_g]):
                answer = two_results['g']
               

            choices1 = font.render(answer, False, RED)
            screen.blit(choices1, (100, 390))
           
            pygame.display.flip()
            if (keys[K_RETURN]) and next ==3:
                next = 4
           
        elif next == 4:
            screen.fill(WHITE)
            pygame.draw.rect(screen, (BLUE), (30, 30, 740, 740), 10)
            question3 = font.render(question_list[2], False, RED)
            screen.blit(question3, (20, 50))
            screen.blit(choicea, (100, 120))
            screen.blit(choiceb, (100, 140))
            screen.blit(choicec, (100, 160))
            screen.blit(choiced, (100, 180))
            screen.blit(choicee, (100, 200))
            screen.blit(choicef, (100, 220))
            screen.blit(choiceg, (100, 240))
            instruction = font.render("choose your first response and press SPACE.", False, BLACK)
            screen.blit(instruction, (100, 300))

       
            answer = ""
            if (keys[K_a]):
                answer = three_results['a']
               
            if (keys[K_b]):
                answer = three_results['b']
               
            if (keys[K_c]):
                answer = three_results['c']
               
            if (keys[K_d]):
                answer = three_results['d']
               
            if (keys[K_e]):
                answer = three_results['e']
               
            if (keys[K_f]):
                answer = three_results['f']
               
            if (keys[K_g]):
                answer = three_results['g']
               

            choices1 = font.render(answer, False, RED)
            screen.blit(choices1, (100, 390))
           
            pygame.display.flip()
            if (keys[K_SPACE]) and next ==4:
                next = 5
       
       
        elif next == 5:
            screen.fill(WHITE)
            pygame.draw.rect(screen, (BLUE), (30, 30, 740, 740), 10)
            question4 = font.render(question_list[3], False, RED)
            screen.blit(question4, (20, 50))
            screen.blit(choicea2, (100, 120))
            screen.blit(choiceb2, (100, 140))
            screen.blit(choicec2, (100, 160))
            screen.blit(choiced2, (100, 180))
            screen.blit(choicee2, (100, 200))
            screen.blit(choicef2, (100, 220))
            screen.blit(choiceg2, (100, 240))
            instruction = font.render("choose your first response and press ENTER.", False, BLACK)
            screen.blit(instruction, (100, 300))
           
            answer = ""
           
            if (keys[K_a]):
                answer = four_results['a']
               
            if (keys[K_b]):
                answer = four_results['b']
               
            if (keys[K_c]):
                answer = four_results['c']
               
            if (keys[K_d]):
                answer = four_results['d']
               
            if (keys[K_e]):
                answer = four_results['e']
               
            if (keys[K_f]):
                answer = four_results['f']
               
            if (keys[K_g]):
                answer = four_results['g']
               

            choices1 = font.render(answer, False, RED)
            screen.blit(choices1, (100, 390))
            if (keys[K_RETURN]) and next ==5:
                next = 6
       
            pygame.display.flip()
       
        elif next == 6:
            screen.fill(WHITE1)
            pygame.draw.rect(screen, (BLUE), (30, 30, 740, 740), 10)
            question5 = font.render(question_list[4], False, RED)
            screen.blit(question5, (20, 50))
            screen.blit(choicea, (100, 120))
            screen.blit(choiceb, (100, 140))
            screen.blit(choicec, (100, 160))
            screen.blit(choiced, (100, 180))
            screen.blit(choicee, (100, 200))
            screen.blit(choicef, (100, 220))
            screen.blit(choiceg, (100, 240))
            instruction = font.render("choose your first response and press SPACE.", False, BLACK)
            screen.blit(instruction, (100, 300))

       
            answer = ""
            if (keys[K_a]):
                answer = five_results['a']
               
            if (keys[K_b]):
                answer = five_results['b']
               
            if (keys[K_c]):
                answer = five_results['c']
               
            if (keys[K_d]):
                answer = five_results['d']
               
            if (keys[K_e]):
                answer = five_results['e']
               
            if (keys[K_f]):
                answer = five_results['f']
               
            if (keys[K_g]):
                answer = five_results['g']
               

            choices1 = font.render(answer, False, RED)
            screen.blit(choices1, (100, 390))
            if (keys[K_SPACE]) and next ==6:
                next = 7
            pygame.display.flip()

       
       
        elif next == 7:
            screen.fill(WHITE1)
            pygame.draw.rect(screen, (BLUE), (30, 30, 740, 740), 10)
            question6 = font.render(question_list[5], False, RED)
            screen.blit(question6, (20, 50))
            screen.blit(choicea2, (100, 120))
            screen.blit(choiceb2, (100, 140))
            screen.blit(choicec2, (100, 160))
            screen.blit(choiced2, (100, 180))
            screen.blit(choicee2, (100, 200))
            screen.blit(choicef2, (100, 220))
            screen.blit(choiceg2, (100, 240))
            instruction = font.render("choose your first response and press ENTER.", False, BLACK)
            screen.blit(instruction, (100, 300))

       
            answer = ""
            if (keys[K_a]):
                answer = six_results['a']
               
            if (keys[K_b]):
                answer = six_results['b']
               
            if (keys[K_c]):
                answer = six_results['c']
               
            if (keys[K_d]):
                answer =six_results['d']
               
            if (keys[K_e]):
                answer = six_results['e']
               
            if (keys[K_f]):
                answer = six_results['f']
               
            if (keys[K_g]):
                answer = six_results['g']
               

            choices1 = font.render(answer, False, RED)
            screen.blit(choices1, (100, 390))
            if (keys[K_RETURN]) and next ==7:
                next = 8
            pygame.display.flip()

           
           
       
        elif next == 8:
           
            screen.fill(WHITE1)
            pygame.draw.rect(screen, (BLUE), (30, 30, 740, 740), 10)
            color = font.render("Did the screen change color?", False, GREEN)
            screen.blit(color, ( 135, 200 ))
            colorblind = font.render("y for yes, n for no", False, GREEN)
            screen.blit(colorblind, (135, 240))
            instruction = font.render("choose your first response and press SPACE.", False, BLACK)
            screen.blit(instruction, (100, 300))
           

            answer = ""
            if (keys[K_y]):
                answer = "you can answer something honestly!"
                choices1 = font.render(answer, False, RED)
                screen.blit(choices1, (100, 390))
            if (keys[K_n]):
                answer = "This is no fun if you aren't paying attention."
                choices2 = font.render(answer, False, RED)
                screen.blit(choices2, (100, 390))
           
           

                scorea = +10
                scoreb = +10
                scorec = +1
                scored = +5
                scoree = +10
                scoref = +2
                scoreg = +5
                scoreh = +1

             
           
            if (keys[K_SPACE]) and next ==8:
                next = 9
           
            pygame.display.flip()

       
        elif next == 9:
       


            screen.fill(WHITE1)
            pygame.draw.rect(screen, (BLUE), (30, 30, 740, 740), 10)

            screen.blit(Results, (100, 180))
            screen.blit(Results2, (100, 210))
            screen.blit(ResultsA, (120, 230))
            screen.blit(ResultsB, (120, 250))
            screen.blit(ResultsC, (120, 270))
            screen.blit(ResultsD, (120, 290))
            screen.blit(ResultsE, (120, 310))
            screen.blit(ResultsF, (120, 330))
            screen.blit(ResultsG, (120, 350))
            screen.blit(ResultsH, (120, 370))
            pygame.display.flip()


display_box()         

           
               

Saturday, March 15, 2014

simple introduction screen pygame

###  An intro screen.  Trying to make my personality test, ###
### will post it when it's ready so you can try it out! ###

import pygame
from pygame.locals import*
import math
from random import randint, choice
from math import*
from sys import exit

pygame.init()




H = 800
W = 800
screen = pygame.display.set_mode((H, W))

font = pygame.font.Font(None, 32)
L_font = pygame.font.Font(None, 64)   
clock = pygame.time.Clock()
BLUE = (45, 0, 200)
GREEN = (0, 200, 45)
PURPLE = (200, 95, 255)
BLACK = (0, 0, 0)   

def display_box():
       
    # the needed variables
    pygame.draw.rect(screen, (200, 195, 100), (20, 20, 760, 760))
    pygame.draw.rect(screen, (BLUE), (30, 30, 740, 740), 10)
    intro = font.render("For instructions, press Space bar", False, BLUE)
    title1 = font.render("For entertainment only", False, GREEN)
    title2 = L_font.render("Personality", False, BLUE)
    title3 = L_font.render("Test", False, BLUE)
    author = font.render("Nellie Tobey, 2014", False, BLACK)
    clock.tick(30)
   
     # the first screen you want them to see. #
     # the function draws it,   the loop will change it# 
    screen.blit(intro, (40, 40))
    screen.blit(title1, (60, 60))
    screen.blit(title2, (290, 300))
    screen.blit(title3, (340, 340))
    screen.blit(author, (40, 640))
    pygame.display.flip()
   
    # these three variables will help us change the
    # state of the function
      
    done = False   
    instruction_screen = 1
    display_instructions = 1
    # main LOOP. This changes the screen as the state of function changes #
 
  while done==False:       
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
                exit()

        if instruction_screen ==1:
            screen.blit(intro, (40, 40))
            screen.blit(title1, (60, 60))
            screen.blit(title2, (290, 300))
            screen.blit(title3, (340, 340))
            screen.blit(author, (40, 640))
            pygame.display.flip()
        keys = pygame.key.get_pressed()

           # if you push space, things change

        if (keys[K_SPACE]): 
            instruction_screen = 2  #we could create more, and more screens
            display_instructions = 0
        if display_instructions == 0:           
            text = L_font.render("INSTRUCTIONS", False, (0, 35, 0))
            pygame.draw.rect(screen, (200, 255, 255), (20, 20, 760, 760))
            screen.blit(text, (H/2 - 170, W/2 - 200))
            pygame.display.flip()
       
   
       
display_box()


def instructions():
    pass
def test():
    pass
def answers():                         #these are where my app will go. 
    pass
def questions():
    pass
def results():
    pass

Saturday, March 8, 2014

Class and inheritance in Python

# my example to show a shell for class's for a game in Python
# I'm sure there is a better way, but this will kinda show you how to make the inheritance, and class thing
# work together. You can switch the modules around to any class, as long as the class is defined before you #use them. 

##  Meggamuffins is my name!  Eating mushrooms is NOT my game!

#When you run this in terminal, it should show you how the order is written backwards,

# but the computer processes it bottom up.  Same as the other shell, but in all classes.

## ALL props to Zed Shaw and his amazing learning tools.  http://learnpythonthehardway.org

class State(object):
    #could store global variables here, instead of making them global
    def __init__(self, name):
        self.name = name
       
       
class Wingame(object):
    def __init__(self, chicken_dinner):
        self.chicken_dinner = chicken_dinner
    def winner(self):
        print "winner winner , chicken dinner! %s"

class Endgame(Wingame):
    def __init__(self, wawa):
        self.wawa = wawa
    def end_credits(self):  #game over
        print " You LOSE - Nellie Tobey - shell designer"
        Wingame(object).winner()
       
class Battle(Endgame):
    def __init__(self, charge):
        self.charge = charge
    def fight(self):
        print "Lets get ready to wooooop azz."
        Endgame(object).end_credits()

class Level_up(Battle):
    def __init__(self, woot):
        self.woot = woot
    def stats(self):
        print " congrats, you are level -impotent-"
        Battle(object).fight()
       
class Enemy_pos(Level_up):
    def __init__(self, pos_badguy):
        self.pos_badguy = pos_badguy
    def point_enemy(self):
        print "There he goes!  Gettim!"
        Level_up(object).stats()
       
class Enemy(Enemy_pos):
    def __init__(self, badguy):
        self.badguy = badguy
    def Rawwwr(self):
        print " we need more chose to be the badguy games!"
        Enemy_pos(object).point_enemy()
       
class Hero_pos(Enemy):
    def __init__(self, sexy_pos):
        self.sexy_pos = sexy_pos
    def point_hero(self):
        print " There he goes with that swaaard again!"
        Enemy(object).Rawwwr()
       
class Hero(Hero_pos):
    def __init__(self, sexy):
        self.sexy = sexy
    def mighty(self):
        print "FF is better at female lead roles then American cinema"
        Hero_pos(object).point_hero()
       
class Npc_pos(Hero):
    def __init__(self, poser):
        self.poser = poser
    def point_npc(self):
        print "character is at point (2, 3)"
        Hero(object).mighty()

class Npc(Npc_pos):
    def __init__(self, cpu):
        self.cpu = cpu
    def char_dialog(self):
        print "You have a quest, let me give you arbitrary things to do!"
        Npc_pos(object).point_npc()
       
class Inventory(Npc):
    def __init__(self, stuffing):
        self.stuffing = stuffing
    def stuff(self):
        print "inventory = this, that, the other thing"
        Npc(object).char_dialog()

class Images(Inventory):
    def __init__(self, image):
        self.image = image
    def show_image(self):
        print " ******************* "
        print " **     INTRO     ** "
        print " ******************* "
       
        Inventory(object).stuff()

class Storyline(Images):
    def __init__(self, story):
        self.story = story
    def storyintro(self):
        print "story introduction"
        Images(object).show_image()

class Start(Storyline):
    def __init__(self, heregoes):
        self.heregoes = heregoes
    def game_instructions(self):
        print "start, game instructions"
        Storyline(object).storyintro()


Gamestart = Start(object).game_instructions()

       

Thursday, March 6, 2014

simple bounce pygame python code

## I'm always looking for examples, so if I can provide one that I had a hard time
## finding ,  I will.    Remember to put your own images in.  mine only work for me.

##  diagonal bounce from chapter 5, Beggining Game Development with Pygame,
## python: Will McGugan


background_image = ("UnicornPoop/CRSwall.jpg")
sprite_image_Right = ("UnicornPoop/brushRight.png")  #your images here  ###################("filename/imagename.png") or just('filename.ext')
sprite_image_Left = ("UnicornPoop/brushLeft.png")

import pygame
from pygame.locals import*
from sys import exit
from vectorMagnitude import Vector2

pygame.init()

screen = pygame.display.set_mode((600, 800), 0, 32)

background= pygame.image.load(background_image).convert()

sprite = pygame.image.load(sprite_image_Right)
sprite_left = pygame.image.load(sprite_image_Left)

clock = pygame.time.Clock()

x, y = 100., 100.
speed_x, speed_y = 133., 170.


while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()

       

    screen.blit(background, (-5, -5))
    screen.blit(sprite, (x, y))
   
    time_passed = clock.tick(30)
    time_passed_seconds = time_passed / 1000.

    x += speed_x * time_passed_seconds
    y += speed_y * time_passed_seconds

    if x > 600 - sprite.get_width():
        speed_x = -speed_x
        x = 600 - sprite.get_width()
    elif x < 0:
        speed_x = -speed_x
        x = 0

    if y > 800 - sprite.get_height():
        speed_y = -speed_y
        y = 800 - sprite.get_height()
    elif y < 0:
        speed_y = -speed_y
        y = 0

    pygame.display.update()

   

pygame vector image bounce with Vector class

##### mostly this code is re-written, but if I had to look for it, maybe you did too
##  if you cut and paste (which you should type yourself to learn)  just the
## import  math, and vector class , and the stuff that's
## edited out at the bottom, you can see what the vector class does
## I looked forever for a code to make the object bounce, or follow.
## nobody really says, "you have to have a vector class, or module to do it"
## apparently you do.   If not, let me know in comments, I'd love to learn how


import pygame
from pygame.locals import*
from sys import exit
import math
#from book by Will McGugan Beginning Game Development with Python and Pygame
#and modification from stackoverflow.com,  Dominic Kexel
class Vector2(tuple):
   
    def __new__(typ, x = 1.0, y = 1.0):
        n = tuple.__new__(typ, (int(x), int(y)))
        n.x = x
        n.y = y
        return n
    def __str__(self):
        return "(%s, %s)"%(self.x, self.y)
    def __add__(self, other): 
        return self.__new__(type(self), self.x + other.x, self.y + other.y)
   
    def __sub__(self, other):
        return self.__new__(type(self), self.x - other.x, self.y - other.y)
   
    def __neg__(self, other):
        return self.__new__(type(self), -self.x, -self.y)

    def __mul__(self, scalar):
        return self.__new__(type(self), self.x * scalar, self.y * scalar)
   
    def __div__(self, scalar):
        return self.__new__(type(self), self.x / scalar, self.y / scalar)

    @staticmethod
    def from_points(P1, P2):
        return Vector2( P2[0] - P1[0], P2[1] - P1[1] )

    def get_magnitude(self):
        return math.sqrt( self.x**2 + self.y**2 )

    def normalize(self):
        magnitude = self.get_magnitude()
        self.x /= magnitude
        self.y /= magnitude

   
   
class main(Vector2):

    background_image = ("UnicornPoop/CRSwall.jpg") # for the images, you'll have to put your own in
    sprite_image_Right = ("UnicornPoop/brushRight.png") #filename / your image
    sprite_image_Left = ("UnicornPoop/brushLeft.png")   #filename / your image

    pygame.init()

    screen = pygame.display.set_mode((600, 800), 0, 32)

    background= pygame.image.load(background_image).convert()

    sprite = pygame.image.load(sprite_image_Right)
    spriteLeft = pygame.image.load(sprite_image_Left)

    clock = pygame.time.Clock()

    position = Vector2(100.0, 100.0)
    speed = 250
    heading = Vector2()
    sprite_pos = pygame.mouse.get_pos()
    while True:

       


        for event in pygame.event.get():
            if event.type == QUIT:
                exit()
        if event.type == MOUSEBUTTONDOWN:
           
           
            destination = Vector2(*event.pos) - Vector2(*sprite.get_size())/2
            heading = Vector2.from_points(position, destination)
            heading.normalize()
           
           
        screen.blit(background, (-5, -5))
        screen.blit(sprite, position)

   
        time_passed = clock.tick()
        time_passed_seconds = time_passed / 1000.

        distance_moved = time_passed_seconds * speed
        position += heading * distance_moved
   
        pygame.display.update()

main()

#A = (10.0, 20.0)
#B = (30.0, 35.0)
#AB = Vector2.from_points(A, B)
#step = AB * .1
#position = Vector2(10, 20)  #the book says to put (A.x, A.y) but I get error, has no attribute x
#for n in range(10):
    #position += step
    #print position
#A = (10.0, 20.0)
#B = (30.0, 35.0)
#C = (15.0, 45.0)
#AB = Vector2.from_points(A, B)
#BC = Vector2.from_points(B, C)

#AC = Vector2.from_points(A, C)
#print "Vector AC is",AC

#AC = AB + BC

#print "AB + BC is", AC


#print "Vector AB is", AB
#print "Magnitude of Vector AB is ", AB.get_magnitude()
#AB.normalize()
#print "Vector AB normalized is", AB
#print AB.get_magnitude()

Wednesday, February 26, 2014

pygame grid

#Trying to make a sprite drawing program... click on the squares/rects
#make a sprite, save image.  Haven't figured out it all yet. Just a grid.
 # the actual GRID is only 4 lines of code plus the variables.  I'll mark em.


import pygame
from pygame.locals import*
from pygame import time
import random
import sys

pygame.init()
#############  GRID VARIABLES ########
WINDOWWIDTH = 800
WINDOWHEIGHT = 800
CELLSIZE = 10
CELLWIDTH = int(WINDOWWIDTH/CELLSIZE)
CELLHEIGHT = int(WINDOWHEIGHT/CELLSIZE)
#####################################
#always rainbows.    
x1 = random.randint(0, 255)
y1 = random.randint(10, 245)
z1 = random.randint(15, 200)
   
RAINBOW1 = (x1, y1, z1)
GREY = (200, 200, 200)
BLUE = (0, 0, 255)
BLUE1 = (0, 0, 230)
BLUE2 = (50, 0, 250)
RED = (210, 0, 0)
RED2 = (255, 20, 50)
WHITE = (255, 250, 250)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)



pygame.init()
   


SCREEN = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))   
SCREEN.fill((255, 255, 255))

pygame.display.update()
clock = pygame.time.Clock

z = 0

FONT = pygame.font.Font('freesansbold.ttf', 18)
pygame.display.set_caption("Make a Sprite")   
######################GRID ###########################
     
for x in range(0, WINDOWWIDTH, CELLSIZE):
    pygame.draw.line(SCREEN, BLACK, (x, 0), (x, WINDOWHEIGHT))
for y in range(0, WINDOWHEIGHT, CELLSIZE):
    pygame.draw.line(SCREEN, BLACK, (0, y), (WINDOWWIDTH, y))   

#######################GRID##########################

while True:
   
    (a,b) = pygame.mouse.get_pos()

    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()
       
   

silly one.

#brain fried.  Need to sleep. 
#Here's my pooping unicorn as of now.... but the unicorn is invisible. 

import pygame
import random
import sys

from pygame.locals import*

background_image_file = 'CRSwall.jpg'
mouse_image_file = 'brush.png'
   


def main():   
    pygame.init()
   
    SCREEN = pygame.display.set_mode((600,800))
    pygame.display.set_caption('Nellie wants to be a Geek!')
   
    BACKGROUND = pygame.image.load(background_image_file).convert()
    mouse_cursor = pygame.image.load(mouse_image_file).convert()
   
   
    SCREEN.blit(BACKGROUND,(-10, -10))
   
    x1 = random.randint(0, 255)
    y1 = random.randint(10, 245)
    z1 = random.randint(15, 200)
   
    RAINBOW1 = (x1, y1, z1)

    BLACK = (0, 0, 0)
    WHITE = (255, 255, 255)
    PURPLE = (255, 0, 220)
    BLUE = (74, 74, 250)

    font = pygame.font.Font(None, 49)
    text = font.render("Pooping Unicorn! Clicky clicky!", False, RAINBOW1)
    textPos = text.get_rect()
    textPos.centerx = BACKGROUND.get_rect().centerx
   
    pygame.draw.rect(BACKGROUND, (100, 255, 255), (0, 0, 600, 60))
    pygame.draw.rect(SCREEN, (255, 200, 50), (800, 0, 600, 60))
   
   
    (mouseX, mouseY) = pygame.mouse.get_pos()
    pygame.draw.circle(BACKGROUND, (RAINBOW1), (mouseX, mouseY), 20, 20)
    x1 = random.randint(0, 255)
    y1 = random.randint(10, 245)
    z1 = random.randint(15, 200)
    RAINBOW1 = (x1, y1, z1)

    pygame.display.update()
    #screen.blit(ball.image, ball.rect)
    BACKGROUND.blit(text, textPos)   
        SCREEN.blit(BACKGROUND, (0,0))       
    pygame.display.flip()

    while 1:   
       
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()   
            if event.type == MOUSEBUTTONDOWN :
                main()
               
                BACKGROUND.blit(text, textPos)
                SCREEN.blit(mouse_cursor.image, mouse_cursor.rect)

if __name__ == '__main__': main()

   

Sunday, February 23, 2014

example of Python Class order of operations

##  Meggamuffins is my name!  Eating mushrooms is NOT my game!
#When you run this in terminal, it should show you how the order is written backwards,
# but the computer processes it bottom up.
## ALL props to Zed Shaw and his amazing learning tools.  http://learnpythonthehardway.org
class Meggamuffins(object):

    def __init__(self, gamedata):
       
        self.gamedata = gamedata
        def wingame(self):
            print "wingame = self"
            print "that is the entire list, if it all printed off, then it worked!"
        def endgame(self):
            print "endgame =  endgame"
            wingame(self)
        def battle(storyline, enemy, hero, level_up, npc):
            print "battle = storyline, enemy, hero, level_up, npc"
            endgame(self)
        def level_up(self, hero, inventory, storyline):
            print "self, hero, inventory, storyline"
            battle(storyline, enemy, hero, level_up, npc)
        def enemy_position(self, storyline, areamap, hero):
            print "enemy_position = self, storyline, areamap, hero"
            level_up(self, hero, inventory, storyline)
        def enemy(self, inventory):
            print "enemy = self, inventory)"
            enemy_position(self, storyline, areamap, hero)
        def hero_position(self, storyline, areamap, hero):
            print "hero_position = self, storyline, areamap, hero"
            enemy(self, inventory)
        def hero(self, storyline, areamap, inventory):
            print " Hero = self, storyline, areamap, inventory"
            hero_position(self, storyline, areamap, hero)
        def npc_position(self, storyline, areamap):
            print "npc_position = self, storyline, areamap)"
            hero(self, storyline, areamap, inventory)
        def npc(self, storyline, areamap, inventory):
            print "npc = self, storyline, areamap"
            npc_position(self, storyline, areamap)
        def inventory(self):
            print "inventory =  self"
            npc(self, storyline, areamap, inventory)
        def areamap(self, storyline):
            print "areamap = self, storyline"
            inventory(self)
        def storyline(self, areamap):
            print "storyline"
            areamap(self, storyline)
               
        def start(self):
            print "start"
            storyline(self, areamap)
       
        start(self)
   
   
   
           
           
## I have NO IDEA why we have to rename this object to call it.
## why can't I just type, Meggamuffins.gamedata(object)???
redundantnaming = Meggamuffins(object)
redundantnaming.gamedata()