Welcome to my basic games!

We have learn to code with python.

Game 1

This is the python code using pygame zero:


  

  pol = Actor('pol') 
  pol.topright = 0, 10

  WIDTH = 750
  HEIGHT = pol.height + 10

  def draw():
      screen.clear()
      pol.draw()


  def update():
      pol.left += 5
      if pol.left > WIDTH:
          pol.right = 0

  

This is a videotutorial showing how to create a basic game named "game1"

Game 2

This is the python code using python 3:


    
    import pgzrun

diana = Actor('diana')
diana.topright = 0, 50

WIDHT = 500
HEIGHT = diana.height + 100

def draw():
    screen.clear()
    diana.draw()

def update():
    diana.left += 2
    if diana.left > WIDHT:
        diana.right = 0

score = 0

def on_mouse_down(pos):
    global score
    if diana.collidepoint(pos):
        score += 1
    else:
        score -= 1
        print("Improve your aim")
    print(score)

pgzrun.go()

This is a videotutorial showing how to create a basic game named "game2"

Game 3

This is the python code using python 3:


    
    import pgzrun

monedas1 = Actor('monedas1')
monedas1.topright = 0, 10

WIDTH = 500
HEIGHT = monedas1.height + 20

def draw():
    screen.clear()
    monedas1.draw()

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

score = 0

def on_mouse_down(pos):
    global score
    if monedas1.collidepoint(pos):
        sounds.caja1.play()
        monedas1.image = 'monedas2'
        score += 1
    else:
        score -= 1
        print("Nothing here")
    print(score)

pgzrun.go()

This is a videotutorial showing how to create a basic game named "game3"

Game 4

This is the python code using python 3:


    
    
 import pgzrun
alien = Actor('alien')
alien.topright = 0, 10
WIDTH = 500
HEIGHT = alien.height + 20
def draw():
    screen.clear()
    alien.draw()
def update():
    alien.left += 2
    if alien.left > WIDTH:
        alien.right = 0
score = 0
def on_mouse_down (pos):
    global score
    if alien.collidepoint(pos):
        set_alien_hit()
        score += 1
        print(score)
    else:
        score -= 1
        print(score)
def set_alien_hit():
    alien.image = 'alien_hurt'
    sounds.eep.play()
    clock.schedule_unique(set_alien_normal, 0.5)
def set_alien_normal():
    alien.image = "alien"
pgzrun.go()

This is a videotutorial showing how to create a basic game named "game4"

Game 6

This is the python code using python 3:


    
    from random import randint
tabaco = Actor('tabaco')
def draw():
    screen.clear()
    tabaco.draw()
def shoot_tabaco():
    tabaco.x = randint(10, 300)
    tabaco.y = randint(10, 300)
def on_mouse_down(pos):
    if tabaco.collidepoint(pos):
        print("You should stop smoking")
        shoot_tabaco()
    else:
        print("Congratulations on quitting smoking")
        quit()

shoot_tabaco()

This is a videotutorial showing how to create a basic game named "game6"

Guess 01

This is the python code using python 3:


    
    import random

n = random.randint(0,10)

while True:
    print("I am thinking of a number, can you guess what it is?")
    g = int(input())
    if g == n:
        break
    else:
        print("Wrong")
print("Correct!")

This is a videotutorial showing how to create a basic game named "guess01"

Guess 02

This is the python code using python 3:


    
    
  import random # random is a python library to create random numbers

  n = random.randint(0, 150) # d is a integer number from ten to twenty
  guesses = 0 # guesses is a variiable with initical value 0

  while True: # do the following code all the timecounting up guesses
      guesses = guesses + 1 # add a guess every time I try to answer
      print("Can you guess the number I think of?") # show int the screen this question
      g = int(input()) # g is a number entered by the user (inut()
      if g == n: # if the number entered by the user is equal to the random number stop the code
          break
      elif g < n: # if the number entered by the user is minor than the random number tell the user "You have fallen short, think big"
          print("You have fallen short, think big")
      elif g > n: # if the number entered by the user is more than the random number tell the user "Oh...you have passed, try something minor"
          print("Oh...you have passed, try something minor")
  print("Correct! Amazing!", 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 attempts
    

This is a videotutorial showing how to create a basic game named "guess02"

Input 02

This is the python code using python 3:


    
    print("What's the capital of France?")
x = input()
print("You think it's", x)
if x == "Madrid":
    print("Wrong, try again")
elif x == "Roma":
    print("Wrong, try again")
elif x == "Paris":
    print("You are rigth, congratulations!")

else:
    print("Correct, congratulations!")

This is a videotutorial showing how to create a basic game named "input02"

Math 01

This is the python code using python 3:


    
    import random #prepare the computer to understand and generate "random numbers"
#create 2 integer random variables (int = integer) below
n = round (random.uniform (10, 150), 2) # 10 is the minimum random number and 150 is the maximum

m = round (random.uniform (1, 9), 2)

print ("What is", n, "-", m, "/", m, "?") #output in quotation marks and variable
g = float (input ()) #float would be decimals
if g == n + m / m:
    print ("You need to study a little more ...")
else: # Otherwise write incorrect
    print ("Correct, you are the best")

This is a videotutorial showing how to create a basic game named "math01"

Math 02

This is the python code using python 3:


    
   import random

n = random.randint(0, 150)
guesses = 0

while True:
    guesses = guesses + 1
    print("Can you guess the number I think of?")
    g = int(input())
    if g == n:
        break
    elif g < n:
        print("You have fallen short, think big")
    elif g > n:
        print("Oh...you have passed, try something minor")
print("Correct! Amazing!", guesses, "guesses.")

This is a videotutorial showing how to create a basic game named "math02"

Pong

This is the python code using python 3:


WIDTH = 900
HEIGHT = 600

ball = Rect((150, 400), (10, 9))
bat = Rect((240, 480), (150, 20))
vx = 8
vy = 8

def draw():
    screen.clear()
    screen.draw.filled_rect(ball, "violet")
    screen.draw.filled_rect(bat, "white")

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:
        exit()
    if(keyboard.right):
        bat.x += 10
    elif(keyboard.left):
        bat.x -= 10

This is a videotutorial showing how to create a basic game named "pong"

Shoot The Fruit

This is the python code using python 3:


from random import randint
import pgzrun
import pygame

background = Actor("fondocomida1")
apple = Actor("apple")
orange = Actor("orange")
pineapple = Actor("pineapple")
score = 0
time_left = 10
WIDTH  = 1350
HEIGHT = 700
game_over = False

def draw():
    screen.surface = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN)
    screen.clear()
    screen.blit("fondocomida1", (0, 0))
    apple.draw()
    orange.draw()
    pineapple.draw()
    screen.draw.text("Score: " + str(score), color="white", topleft=(10, 10))

    if game_over:
        screen.fill(color="black")
        screen.draw.text("Final Score: "+ str(score), topleft=(10, 10), color="white", fontsize=60)

def place_fruits():
    apple.x = randint(50,1200)
    apple.y = randint(50,600)
    orange.x = randint(50,1200)
    orange.y = randint(50,600)
    pineapple.x = randint(50,1200)
    pineapple.y = randint(50,600)

def time_up():
    global game_over
    game_over = True

def on_mouse_down(pos):
    global score
    if apple.collidepoint(pos):
        print("Good shot!")
        place_fruits()
        score = score + 1
    if orange.collidepoint(pos):
        print("No! Oranges no")
        place_fruits()
        score = score - 1
    if pineapple.collidepoint(pos):
        print("PARTY! +5")
        place_fruits()
        score = score + 5

clock.schedule(time_up, 10)
place_fruits
pgzrun.go()

This is a videotutorial showing how to create a basic game named "shootthefruit"

  • That is a website about videogames for an Erasmus + project for my school: Institut Pompeu Fabra using Javascript and p5.js