Problem with code

Started by
-1 comments, last by thedeskgeek 9 years, 8 months ago

So I am learning how to code with pygame, and I am having a small TypeError. the error is "Integer Argument expected, got float" I think it means that where an integer argument is, a float is given instead. But I am still learning so I am asking you guys for some help. Here is the code:

SOLVED!

it was the "/" symbol. For Python 3 it is supposed to be "//"

  1. 
    #! /usr/bin/env python
    
    # Move a single pixel around the screen without scrashing against the borders. 
    
    import pygame
    
    # Window dimensions
    width = 640
    height = 400
    
    # Position of the pixel
    x = width / 2
    y = height / 2
    
    # Direction of the pixel
    dir_x = 0
    dir_y = -1
    
    screen = pygame.display.set_mode((width, height))
    clock = pygame.time.Clock()
    running = True 
    
    while running:
    	x += dir_x
    	y += dir_y
    
    	if x <= 0 or x >= width or y <= 0 or y >= height:
    		print ("Crash!")
    		running = False
    
    	for event in pygame.event.get():
    		if event.type == pygame.QUIT:
    			running = False
    
    		elif event.type == pygame.KEYDOWN:
    			if event.key == pygame.K_UP:
    				dir_x = 0
    				dir_y = -1
    
    			elif event.key == pygame.K_DOWN:
    				dir_x = 0
    				dir_y = 1
    
    			elif event.key == pygame.K_LEFT:
    				dir_x = -1
    				dir_y = 0 
    
    			elif event.key == pygame.K_RIGHT:
    				dir_x = 1 
    				dir_y = 0
    
    	screen.fill((0,0,0))
    	screen.set_at((x, y), (255,255,255))
    
    	pygame.display.flip()
    	clock.tick(120)
    
    

Think you guys can help me?

This topic is closed to new replies.

Advertisement