Game Programming Tutorial 4 in Python: Control with mouse

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
4,239
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Jul 22, 2010

We implement a program in which we can send a character around the screen by clicking on different positions. In process of doing so, we will learn about how to use vectors and how to do simple arithmetic with them. I'll also show you some drawing tricks.

All supplementary material can be found on
http://karpathy.ca/phyces/tutorial4.php

I messed up a tiny bit in this tutorial in mouseUp() method. The line should be
self.target= vec2d(pos) instead of
self.target= pos
I go into full story in the link if you are interested, but I will also go over this issue in more depth in later videos.

Category:

Education

Tags:

License:

Standard YouTube License

  • likes, 1 dislikes

Link to this comment:

Share to:

Top Comments

  • Hi. Great tutorials.

    However, I got a TypeError: Integer argument expected, got float. (line 37)

    Draw is expecting an Integer, but Vec2d is returning a float. How do you get it to work?

    (for the record I'm using Python 3.1, and Pygame 1.9.1)

  • To fix the error, i recommend just assigning another variable in draw, for example self.posint = (int(self.pos[0]), int(self.pos[1])) and then use self.posint in the draw, or whatever you want to call it. since redefining self.pos to int would screw other things up

see all

All Comments (24)

Sign In or Sign Up now to post a comment!
  • ok so this is a out of date or something tut- everyone is getting the same error - im gonna say i understand how it should work and mostly why- but im gonna move on cuz obviously its not working for me.

    im sure versions are different - but they do not offer the 2.5.6 for windows anymore - just for linux

    - python 2.7.2

    -pygame 1.9.1

  • for some reason when I try to execute startcode.py, I just started getting an error saying s=Starter() is invalid

    it wasn't happening before, and it's also happening with your final code version

  • @Dragonno96 Thanks for the tip, that fixed the TypeError problem.

  • @faithfulnathan I keep getting the same problem. DX

  • What are the parameters for the key input? Is it the arrow keys alone? Cause I've been at this for some time now, but I don't know the right integers for using the 'KeyUp' function. I don't think I ever saw a tutorial for it anywhere.

  • @xFelicianoX that's a fair complaint, I should have been a bit more clear on this. When you do dir.length = 3, behind the scenes Python does something like dir.setLength(3) . And that function does a few things: it computes the length of the dir vector, and then it divides each component by this length, and then multiplies each component by the 3. The result being that dir.x and dir.y are pointing along the same direction, but dir is now a length of 3. Bit of vector math

  • Nice tutorial but I don't get how dir.length works

  • @Hobben93

    @faithfulnathan

    self.pos.inttup() converts the vec2d item into a integer tuple

    Found this when i was exploring the vec2d module

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more