import pygame
import time

from pygame.locals import*
from time import sleep

class Sprite():
	def __init__(self, model, sprite_type, x, y, w, h):
		self.model = model
		self.sprite_type = sprite_type
		self.x = x
		self.y = y
		self.w = w
		self.h = h
	
	# if sprite_type == "Mario":
	# 	self.vert_vel = 0.0
	# 	self.groundFrames = 0
	# 	self.prev_x = 0
	# 	self.prev_y = 0

	# if sprite_type == "Coin_Block":
	# 	self.coins_reamin = 5

	# if sprite_type == "Coin":
	# 	self.vert_vel = -Math.floor((Math.random() * 60) + 1)
	# 	self.hori_vel = Math.floor((Math.random() * 60) + 1)

class Model():
	def __init__(self):
		self.dest_x = 0
		self.dest_y = 0

	def update(self):
		if self.rect.left < self.dest_x:
			self.rect.left += 1
		if self.rect.left > self.dest_x:
			self.rect.left -= 1
		if self.rect.top < self.dest_y:
			self.rect.top += 1
		if self.rect.top > self.dest_y:
			self.rect.top -= 1

	def set_dest(self, pos):
		self.dest_x = pos[0]
		self.dest_y = pos[1]

class View():
	def __init__(self, model):
		screen_size = (800,600)
		self.screen = pygame.display.set_mode(screen_size, 32)
		self.turtle_image = pygame.image.load("turtle.png")
		self.model = model
		self.model.rect = self.turtle_image.get_rect()

	def update(self):    
		self.screen.fill([0,200,100])
		self.screen.blit(self.turtle_image, self.model.rect)
		pygame.display.flip()

class Controller():
	def __init__(self, model):
		self.model = model
		self.keep_going = True

	def update(self):
		for event in pygame.event.get():
			if event.type == QUIT:
				self.keep_going = False
			elif event.type == KEYDOWN:
				if event.key == K_ESCAPE:
					self.keep_going = False
			elif event.type == pygame.MOUSEBUTTONUP:
				self.model.set_dest(pygame.mouse.get_pos())
		keys = pygame.key.get_pressed()
		if keys[K_LEFT]:
			self.model.dest_x -= 1
		if keys[K_RIGHT]:
			self.model.dest_x += 1
		if keys[K_UP]:
			self.model.dest_y -= 1
		if keys[K_DOWN]:
			self.model.dest_y += 1

print("Use the arrow keys to move. Press Esc to quit.")
pygame.init()
m = Model()
v = View(m)
c = Controller(m)
while c.keep_going:
	c.update()
	m.update()
	v.update()
	sleep(0.04)
print("Goodbye")
import pygame
import time

from pygame.locals import*
from time import sleep

class Sprite():
	def __init__(self, model, sprite_type, x, y, w, h):
		self.model = model
		self.sprite_type = sprite_type
		self.x = x
		self.y = y
		self.w = w
		self.h = h
	
	# if sprite_type == "Mario":
	# 	self.vert_vel = 0.0
	# 	self.groundFrames = 0
	# 	self.prev_x = 0
	# 	self.prev_y = 0

	# if sprite_type == "Coin_Block":
	# 	self.coins_reamin = 5

	# if sprite_type == "Coin":
	# 	self.vert_vel = -Math.floor((Math.random() * 60) + 1)
	# 	self.hori_vel = Math.floor((Math.random() * 60) + 1)

class Model():
	def __init__(self):
		self.dest_x = 0
		self.dest_y = 0

	def update(self):
		if self.rect.left < self.dest_x:
			self.rect.left += 1
		if self.rect.left > self.dest_x:
			self.rect.left -= 1
		if self.rect.top < self.dest_y:
			self.rect.top += 1
		if self.rect.top > self.dest_y:
			self.rect.top -= 1

	def set_dest(self, pos):
		self.dest_x = pos[0]
		self.dest_y = pos[1]

class View():
	def __init__(self, model):
		screen_size = (800,600)
		self.screen = pygame.display.set_mode(screen_size, 32)
		self.turtle_image = pygame.image.load("turtle.png")
		self.model = model
		self.model.rect = self.turtle_image.get_rect()

	def update(self):    
		self.screen.fill([0,200,100])
		self.screen.blit(self.turtle_image, self.model.rect)
		pygame.display.flip()

class Controller():
	def __init__(self, model):
		self.model = model
		self.keep_going = True

	def update(self):
		for event in pygame.event.get():
			if event.type == QUIT:
				self.keep_going = False
			elif event.type == KEYDOWN:
				if event.key == K_ESCAPE:
					self.keep_going = False
			elif event.type == pygame.MOUSEBUTTONUP:
				self.model.set_dest(pygame.mouse.get_pos())
		keys = pygame.key.get_pressed()
		if keys[K_LEFT]:
			self.model.dest_x -= 1
		if keys[K_RIGHT]:
			self.model.dest_x += 1
		if keys[K_UP]:
			self.model.dest_y -= 1
		if keys[K_DOWN]:
			self.model.dest_y += 1

print("Use the arrow keys to move. Press Esc to quit.")
pygame.init()
m = Model()
v = View(m)
c = Controller(m)
while c.keep_going:
	c.update()
	m.update()
	v.update()
	sleep(0.04)
print("Goodbye")
# if sprite_type == "Mario": # 	self.vert_vel = 0.0 # 	self.groundFrames = 0 # 	self.prev_x = 0 # 	self.prev_y = 0 # if sprite_type == "Coin_Block": # 	self.coins_reamin = 5 # if sprite_type == "Coin": # 	self.vert_vel = -Math.floor((Math.random() * 60) + 1) # 	self.hori_vel = Math.floor((Math.random() * 60) + 1)