I am making a snake game in pygame. However, I ran into a TypeError
problem inside my Snake
class object. To be specific it threw an error inside the draw()
(class) and blit()
(non-class) functions, telling me that "an integer is required" (got type tuple).
import pygame
import random
pygame.init()
screen = pygame.display.set_mode((640, 480))
class Snake(object):
def __init__(self, x, y, height, width, color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.vel = 3
def draw(self): # The problem happened here
pygame.draw.rect(screen, self.color, (self.x, self.y), (self.height, self.width))
def auto_move(self):
pass
def blit(): # The problem also happened here
snake.draw()
snake = Snake(300, 300, 64, 64, (0, 255, 0))
run = True
while run:
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
blit()
pygame.display.update()
The game is far from finish as I quickly ran to said error. Thanks in advance.