#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "Kjetil Liestøl Nielsen"

import pygame
pygame.init()

width = 600
height = 400

win = pygame.display.set_mode((width, height))
pygame.display.set_caption("My first game")

x = 50
y = 50
size = 20

GRAVITY = 400
vy = 0
vx = 200

clock = pygame.time.Clock()

run = True
while run:
	# Handle events
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			run = False

	# Update the game
	dt = clock.tick(60)/1000.0

	vy += GRAVITY * dt
	y += vy * dt

	x += vx * dt

	if y >= height-size:
		y = height-size
		vy = -0.7*vy

	if x >= width-size:
		x = width-size
		vx = -vx
	elif x <= 0:
		x = 0
		vx = -vx

	# Draw the game
	win.fill((255,255,255));
	pygame.draw.rect(win, (255,0,0), (x,y,size,size))
	pygame.display.update()

pygame.quit()