Reputation: 10913
I've just started to learn pygame, and it pretty much needs some coordinates and points in the code in order to position the object. Do you know of any tool or application that I could use as a reference so that I could see a visual representation of the points.
Maybe a grid with numbers.
And pygame also includes declaring the color by using numbers.
Do you know of any site or application that I can use as reference to those numbers and corresponding color. Like this one: 230, 170, 0
And what do these numbers mean.
I'm using windows operating system.
Upvotes: 1
Views: 1430
Reputation: 2312
I teach students as young as 12 the coordinate system in pygame so it is not too difficult. It is really similar to drawing simple graphs in primary school but upside down.
pygame allows you to create a screen for your game:
import pygame
from pygame.locals import *
#variables for your x,y axis width and height
screen_width = 500
screen height = 300
#variables for rectangle dimensions
rectangle_width = 10
rectangle_height = 20
#R G B
RED = (255, 0 , 0)
#start pygame
pygame.init()
#create a screen
SCREEN = pygame.display.set_mode((screen_width,screen_height))
#tell pygame to execute your pygame code
pygame.display.update()
Using the Coordinate system
Now you have an x,y grid starting at (0,0) in the top, with coordinates of (500,0) in the top right and in the bottom left (0,300) and so on.
To place a shape you must remember pygame chooses the top left of your (object) rectangle as the reference point in the system.
If you wanted a red rectangle in the top left of the screen you would do this:
pygame.draw.rect(SCREEN,RED(0,0,rectangle_width,rectangle_height))
This would place a red rectangle of size 10 wide and 20 height in the top left hand corner (0,0).
From this point changing the position of the rectangle means incrementing or decrementing the (0,0) arguments in the rectangle code above.
For instance to shoot the rectangle down from top left to bottom left just change the (0,0) to (0,300)
This web site has an excellent discussion of pygame coordinates from beginner to advanced:
http://inventwithpython.com/makinggames.pdf
The author Al Sweigart will respond to your emails too.
I get students to move the rectangle to the center,bottom right etc to get the hang of it.
Upvotes: 2
Reputation: 2672
as a late addition, for deciphering RGB.. http://0to255.com/ is an excellent site
Upvotes: 2
Reputation: 7511
You can use human names as well.
import pygame
from pygame.locals import Color
# see pygame.colordict for a full list of human-named colors
player_color = Color("darkred")
# RGB/RGBA values are in the range 0 to 255
enemy_color = Color(129, 129, 129)
# RRGGBB / RRGGBBAA : hex are in the range 00 to ff
bullet_color = Color("#ffaa39")
Full details at : http://www.pygame.org/docs/ref/color.html
Upvotes: 0
Reputation: 1393
just print the (x,y) coordinates in the mouse motion event. i.e. every time mouse moves. for colors you can also use Microsoft Paint.
More generally, you can try to have a look at this series of tutorials on YouTube
for pygame, dealing with positions and colors. He doesn't go into it in great detail, but maybe you can pick it up from the way he is using it. The videos could be instructive in general if you are just starting out.
Upvotes: 0
Reputation: 594
You have to get used to imagine where a point is by is coordinates. It isn't difficult: the (0, 0) point is the top-left corner and the first value represents the horizontal distance in pixel from the left side of the window and the second value represents the distance from the top of the window. And if you make a mistake you can correct it in few seconds.
This is a colors calculator: Color calculator
If you use Notepad++ as editor there is a color picker plug-in: sourceforge.net/projects/npp-plugins/files/
Upvotes: 0
Reputation: 1509
color helper: http://www.pangloss.com/seidel/ClrHlpr/color.html
As for the x,y coordinates. It can get pretty complicated. I recommend doing some eyeballing like the others suggested. However, if you need something more precise, you will need to get your hands dirty. I wrote a level editor for a game design course you can find here: tstechonline.com/edward/tiles/EdwardLevelEditor.html
The basic idea is that the drag and drop interface is converted to a text file which represents the screen as a grid. Each tile is 40x40 pixels and is represented by a letter in the output file. You will need some sort of gui -> text converter tool like this to help you if you need something more precise than eyeballing.
Hope this helps.
Upvotes: 0
Reputation: 476
You don't need a grid to help you, you just need to know the origin point (easy - it is one of the corners). Since it is all interpreted, I say you just hack around displaying stuff on the screen till it clicks in your head.
The other part is easy. It is Red, Blue, Green (each one goes from 0-255, 0 is no-color, 255 is full-color).
Upvotes: 1
Reputation: 59673
In Pygame, co-ordinates work as (x,y) offset from the top left, I believe (where to-the-right is positive on the x-scale, and towards-the-bottom is postive on the y-scale). This is done in number of Pixels. After I had used Pygame for a few days, I was able to guess what the x and y values were that I wanted, and I was always pretty close. It just takes a bit of getting used to.
Those numbers for colour are RGB values. You can find more information about that here. Again, once you get used to using it, you can generally have a pretty good guess at the colour you're after. If you're after a very specific colour, you can open up Microsoft Paint, and select a custom colour by double-clicking on one of the colours in your palette. Then click "Define Custom Colours >>" and pick your colour. It shows you the RGB values there (R is red, G is Green, B is Blue).
If what I've said doesn't make sense to you, please ask for clarification :-)
Upvotes: 2