Sign in to follow this  

Problem with code

Recommended Posts

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: 



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.set_at((x, y), (255,255,255))

Think you guys can help me?

Edited by thedeskgeek

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this