Jump to content
  • Advertisement
Sign in to follow this  
thedeskgeek

Problem with code

This topic is 1425 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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: 

 

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?

Edited by thedeskgeek

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!