PYTHON
Welcome to my basic games!
we have learnt to code with python
Alien fall
This is the python code using pygame zero:
# alien is a sprite,that is, a moving images in a game
# Actor is the name of a Class sprite (Nayara is an example of the class Homo sapiens), this means create an object from a class
# oscarcasas is a name of a image in the folder images
alien = Actor ('oscarcasas')
# topright means to locate the image in the top right corner
alien.topright = 0, 10
# screen sice in pixels
WIDTH = 500
HEIGHT = alien.height + 20
def draw():
screen.clear()
alien.draw()
def update():
alien.left += 2
if alien.left > WIDTH:
alien.right = 0
This is a videotutorial showing how to create a basic game named Alien Fall:
Flappy bird
import pgzrun
import random
TITLE = 'Flappy Bird'
WIDTH = 400
HEIGHT = 708
# These constant control the difficulty of the game
GAP = 130
GRAVITY = 0.3
FLAP_STRENGTH = 6.5
SPEED = 3
bird = Actor('bird1', (75, 200))
bird.dead = False
bird.score = 0
bird.vy = 0
#storage.setdefault('highscore', 0)
def reset_pipes():
pipe_gap_y = random.randint(200, HEIGHT -200)
pipe_top.pos = (WIDTH, pipe_gap_y - GAP // 2)
pipe_bottom.pos = (WIDTH, pipe_gap_y + GAP // 2)
pipe_top = Actor('top', anchor=('left', 'bottom'))
pipe_bottom = Actor('bottom', anchor=('left', 'top'))
reset_pipes() # Set initial pipe positions.
def update_pipes():
pipe_top.left -= SPEED
pipe_bottom.left -= SPEED
if pipe_top.right < 0:
reset_pipes()
if not bird.dead:
bird.score += 1
def update_bird():
uy = bird.vy
bird.vy += GRAVITY
bird.y += (uy + bird.vy) / 2
bird.x = 75
if not bird.dead:
if bird.vy < -3:
bird.image = 'bird2'
else:
bird.image = 'bird1'
if bird.colliderect(pipe_top) or bird.colliderect(pipe_bottom):
bird.dead = True
bird.image = 'birddead'
if not 0 < bird.y < 720:
bird.y = 200
bird.dead = False
bird.score = 0
bird.vy = 0
reset_pipes()
def update():
update_pipes()
update_bird()
def on_key_down():
if not bird.dead:
bird.vy = -FLAP_STRENGTH
def draw():
screen.blit('background', (0, 0))
pipe_top.draw()
pipe_bottom.draw()
bird.draw()
pgzrun.go()
This is a videotutorial showing how to create a basic game named Flappy bird:
I am Nayara, in this website you will find my work a school project where our school is participating during the school year 2020-2021. Our Erasmus+ partner schools are from Greece, Italy, Czech Republic and Spain Visit school website here Pompeu Fabra de Martorell.
Some of the project objectives are:
- To learn how to create a website about videogames for an Erasmus + project for my school: Institut Pompeu Fabra using Javascript and p5.js
- To learn how to build a mobile App using MIT App Inventor for this project
- To create original videogames based on traditions
- Our first game is a T-rex like videogame using traditional big-head from Martorell ("capgrossos" in Catalan language) and the Devil's bridge (Pont del diable in Catalan)
- To create a T-Rex like videogame you will follow the less than 200 code lines from this Youtube video tutorial, in the following steps:
- Look carefully the following videotutorial:
- Every student will use differnt images related to local traditions in their own neocities websites and mobile apps creations
- To create in your neocities a folder named trex and inside that folder a file named "index.htlm" and another named "trex.js" in order to make the game work.
- You can copy the code from the video above in the files index.htlm and trex.js. Remember code does not allow mistakes and typos. In case of doubt copy the code from http://github.com/drfperez/erasmusvideogame
- Edit the big-head images, Devil's bridge images and all images involved in the game using GIMP editor and substitute the images in the game.
- To learn more about HTML, CSS and Javascript, check out these tutorials and www.w3schools.com!