Welcome to my basic games!

We have learnt to code with python

Alien fall 1

This is the python code of the first game of alien fall using pygame zero:

  #flower is a sprite, that is,  a moving image in a game
  #Actor is the name of a Class sprite (Abril is an example of the class homosapiens), this means create an object from a class
  #"flower" is a name of an image in the folder images
  flower = Actor('flower')
  #topright means to locate the image in the top right corner
flower.topright = 0, 10
  # coordinates of flower position
  # screen width nased exactly on the width of the flower
WIDTH = 500
# screen height is 400 pixels
HEIGHT = flower.height + 20

def draw():
    screen.fill () 

def update():
    flower.left += 2
    if flower.left > WIDTH:
        flower.right = 0

score = 0

def on_mouse_down(pos):
    global score
    if flower.collidepoint(pos):
        score += 1
        score -= 1
        print("Nothing here")

Alien fall 2

This is a videotutorial showing how to create a basic game named beach

  • Alien fall 3

    This is the python code of the second game of Alien fall's games

      import pgzrun #prepare the laptop for the codes
    cat3 = Actor('cat3') # for the computer to understand the character that will appear on the screen, you must put the character you want to appear in quotation marks.
    cat3.topright = 0,10 #the number corespond to height of the character.
    WIDTH = 500 #means the width of the screen, if you put 100 the screen will be bigger than if you put 50
    HEIGHT = cat3.height + 20 #height of the screen
    def draw():
        screen.fill((248, 170, 234)) #the color of the screen. 
    def update():
        cat3.left += 6 #speed of the cat
        if cat3.left > WIDTH: #the image will moves from the leftto the right until it dissappears of the screen.
            cat3.right = 10
    score = 0
    def on_mouse_down(pos):
        global score
        if cat3.collidepoint(pos):
            sounds.meow1.play() #the sound we want to sound when appeares the image of the cat 
            cat3.image = 'cat2' #secod image of the character
            score += 1
            score -= 1
            print("nothing here")
    pgzrun.go() #means that the codes are finished

    Alien fall 4

    This is the code of the third game of alien fall.

       import pgzrun #prepares the laptop for the codes
     aguila1 = Actor('aguila1') #you have to put the main character between quotes. 
     aguila1.topright = 0,12 #the height you want to put the image.
     WIDTH = 500 #means the width of the screen.
     HEIGHT = aguila1.height + 20 #height of the screen. 
     def draw():
        screen.fill((134, 240, 250 )) #the color we want for the screen, in this case, that numbers means blue.
      def update():
        aguila1.left += 6 #speed of the image.
        if aguila1.left > WIDTH:
            aguila1.right = 10
    score = 0
    def on_mouse_down(pos):
        global score
        if aguila1.collidepoint(pos):
            score += 1
            score -= 1
    def set_aguila1_hit():
        aguila1.image = 'aguila2' #the second image that appears in the screen.
        sounds.cantodeaguila.play() #the sound of the image
        clock.schedule_unique(set_aguila1_normal, 0.5)
    def set_aguila1_normal():
        aguila1.image = "aguila1"
    pgzrun.go() #means that the codes are finished.


    Guess 1

    Here is the videotutorial showing how to create a code about guess a number:

  • Guess 2

    Guess a number I'm thinking about between 5 and 90

        import random # random is a python library to create random numbers
    n = random.randint(5, 90) # d is  an integer number from 5 to 90
    guesses = 0 # guesses is a variable with initial value 0
    while True: # d the following code all the time counting up guesses until break condition
        guesses = guesses + 1 # add a guess every time I try to answer
        print("Can you guess the number I'm thinking about?") # show in the screen this question
        g = int(input()) # g is the number entered by the user (input()
        if g == n: # if the number entered by the user is equal to the random number stop the code
            break # break means stop the code when the previous condition is met
        elif g < n: # if the number entered by the user is less than the random number tell the user "too low"
            print("too low") # elif means else if means if also happens this
        elif g > n: if the number entered by the user is more than the random number tell the user "too high"
            print("too high")
    print("correct! You've tried and find in only", guesses, "attempts.")
    # if the number entered by the user is correct, tell the user "Correct..."
    # tell the user also the number of guesses and the word

    This is the code to guess the number I'm thinking about using python

    Input 1

        print("Enter your sister's name:") #the program will say the phrase betwenn pharenthesis 
    x = input()
    print("hello", x) #the laptop will say the word hello and the name of the person.
    if x == "Estela":
        print("That is a very cool name") #when you put the name, the laptop will say that is a very cool name.

    Input 2

        print("In what countries have you been?:") #the phrase that the program will say
    x = input()
    print("fantastic", x) #if you put whatever number of countries, the laptop will say fantastic
    if x == "In France ":
        print("Oh! I love France, and the Eiffel Tower")
    elif x == "In Germany":
        print("That's great, but I don't too much the cold weather")

    Math 1

    Sum of numbers

        import random #prepares the laptop for do random numbers.
    #crea 2 variables aleatòries senceres (int és integer)
    n = random.randint(5, 8) #5 is the minimum random number, and 8 the maximum
    m = random.randint(2, 6)
    print("What is", n, "plus 3?") #in ths case, 2 is the minimum and 6 the maximum. The program make a sum with random numbers. 
    x = int(input())  #input is keyboard input, int means integers.
    if x == n + 3:                                             
        print("correct") #if the sum is correct
    else:                #else= if the sum is incorrect

    Math 2

        score = 0
    print("What is 5 + 12 ?")
    g = int(input())
    if g == 17:
        print("Very well")
        score = score + 1
    print("What is 50-30 ?")
    g = int(input())
    if g == 20:
        print("Very good")
        print("wrong, try again")
    score = score + 1
    print("Your score:", score)

    Here is a videotutorial explaining how it works

  • Pong game

    # Width means the width of the screen. We can put the number we want the width of the screen. # Height means the height og the screen. If you put 600, the screen will be bigger than if you put 500. # ball = rect + numbers, means the height and width of the ball. The measures you want. If you want the ball taller than wide... # bat = "rect" + numbers, means the measures of the bat of the game # vx = 8, means the speed you want the ball goes, in this case is 8 # vy = 8, means the speed of the bat in the game, in this case is 8 too. # screen.fill + numbers, is the color of the backround of the screen, these numbers means the color blue cian. # screen.draw.filled_rect + numbers means the color you want the ball to be. In this case, that numbers corresponds to the color black. # screen.draw.filled_rect + bat, violet, Means the color of the bat, in this case is violet. # global vx, vy It's a global variable. # ball.x += vx You add in x the speed to the x ball position to move it. # ball.y += vy You add in y the velocity to the y position to move it
      WIDTH = 450
      HEIGHT = 550
    ball = Rect((150, 400), (15, 17))
    bat = Rect((210, 490), (80, 20))
    vx = 8 
    vy = 8
    def draw():
        screen.fill((144, 250, 232)) #color of the screen
        screen.draw.filled_rect(ball, "black") #
        screen.draw.filled_rect(bat, "violet")
    def update():
        global vx, vy
        ball.x += vx
        ball.y += vy
        if ball.right > WIDTH or ball.left < 0:
            vx = -vx
        if ball.colliderect(bat) or ball.top < 0:
            vy = -vy
        if ball.bottom > HEIGHT:
        if (keyboard.right):
            bat.x += 10
            bat.x -= 10

    Here is a video explaining how works the pong game: