![]() pygame documentation |
||
Pygame Home ||
Help Contents ||
Reference Index ||
Cdrom || Color || Cursors || Display || Draw || Event || Font || Image || Joystick || Key || Mask || Mixer || Mouse || Movie || Music || Overlay || Pixelarray || Pygame || Rect || Scrap || Sndarray || Sprite || Surface || Surfarray || Time || Transform |
| pygame.draw.rect - draw a rectangle shape | draw a rectangle shape |
| pygame.draw.polygon - draw a shape with any number of sides | draw a shape with any number of sides |
| pygame.draw.circle - draw a circle around a point | draw a circle around a point |
| pygame.draw.ellipse - draw a round shape inside a rectangle | draw a round shape inside a rectangle |
| pygame.draw.arc - draw a partial section of an ellipse | draw a partial section of an ellipse |
| pygame.draw.line - draw a straight line segment | draw a straight line segment |
| pygame.draw.lines - draw multiple contiguous line segments | draw multiple contiguous line segments |
| pygame.draw.aaline - draw fine antialiased lines | draw fine antialiased lines |
| pygame.draw.aalines - pygame.draw.aalines(Surface, color, closed, pointlist, blend=1): return Rect | pygame.draw.aalines(Surface, color, closed, pointlist, blend=1): return Rect |
Draw several simple shapes to a Surface. These functions will work for rendering to any format of Surface. Rendering to hardware Surfaces will be slower than regular software Surfaces.
Most of the functions take a width argument to represent the size of stroke around the edge of the shape. If a width of 0 is passed the function will actually solid fill the entire shape.
All the drawing functions respect the clip area for the Surface, and will be constrained to that area. The functions return a rectangle representing the bounding area of changed pixels.
Most of the arguments accept a color argument that is an RGB triplet. These can also accept an RGBA quadruplet. The alpha value will be written directly into the Surface if it contains pixel alphas, but the draw function will not draw transparently. The color argument can also be an integer pixel value that is already mapped to the Surface's pixel format.
These functions must temporarily lock the Surface they are operating on. Many sequential drawing calls can be sped up by locking and unlocking the Surface object around the draw calls.
| July 3, 2009 1:28pm - Anonymous |
|---|
missing commands for drawing bezier lines - some gpl sources can be find at http://nitrofurano.linuxkafe.com/sdlbasic - just needed to be recoded to Pygame, but it's not that difficult task at all... |
| February 12, 2008 6:13pm - Anonymous |
Is there a way to produce small line segments that have accurate collision boxes so that one could have two lines that would be parallel to each other with out them colliding? |
| November 7, 2007 5:25pm - Anonymous |
Copy this to your computer and save it as a .py file to run a little trig demo.
#! usr/bin/env python
import pygame, math
from pygame.locals import *
class Ship:
def __init__(self):
self.image=pygame.Surface((40, 40))
self.rect=self.image.get_rect(center=(320,240))
self.x=200
self.y=150
self.x_vel=0
self.y_vel=0
self.angle=0
self.point_list = [(0, -20), (2.25, -20), (3.0, -6), (4.05, -20)]
def update(self):
self.rect.centerx=self.x
self.rect.centery=self.y
self.x+=self.x_vel
self.y+=self.y_vel
key = pygame.key.get_pressed()
if key[K_RIGHT]:
self.angle -= 4
if key[K_LEFT]:
self.angle += 4
if key[K_UP]:
self.accel(0.1)
if key[K_DOWN]:
self.accel(-0.1)
def draw(self, surface):
surface.blit(self.image, self.rect)
self.image.fill((0, 0, 0))
point_list = []
self.angle2 = math.radians(self.angle)
for p in self.point_list:
radian, radius = p
x = int(math.sin(radian+self.angle2)*radius)
y = int(math.cos(radian+self.angle2)*radius)
point_list.append((x+self.image.get_width()/2,y+self.image.get_height()/2))
pygame.draw.polygon(self.image, (255,255,255), point_list, 1)
def accel(self, accel_speed):
self.x_vel += math.sin(self.angle*2*math.pi/360)*-accel_speed
self.y_vel += math.cos(self.angle*2*math.pi/360)*-accel_speed
def wrap(self, surface):
if self.x >= surface.get_width() + self.image.get_width()/2:
self.x = -self.image.get_width()/2
if self.x <= -self.image.get_width()/2 - 1:
self.x = surface.get_width() + self.image.get_width()/2
if self.y >= surface.get_height() + self.image.get_height()/2:
self.y = -self.image.get_height()/2
if self.y <= -self.image.get_height()/2 - 1:
self.y = surface.get_height() + self.image.get_height()/2
def main():
pygame.init()
pygame.display.set_caption('trig demo.py')
screen = pygame.display.set_mode((400, 300))
ship = Ship()
clock = pygame.time.Clock()
while 1:
clock.tick(60)
event = pygame.event.poll()
if event.type == QUIT:
return
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
return
screen.fill((0, 0, 0))
ship.draw(screen)
ship.update()
ship.wrap(screen)
pygame.display.flip()
if __name__ == '__main__':
main()
|
| July 29, 2007 5:05pm - Anonymous |
# Matthew N. Brown copyright 2007
# Here is an example program that
# draws: polygons, circles, and rectangles:
#
# You can copy this program on to
# your own computer and run it.
#
import os, sys
import random
import pygame
from pygame.locals import *
if not pygame.font: print 'Warning, fonts disabled'
if not pygame.mixer: print 'Warning, sound disabled'
import time
import gc
import math
pygame.init()
APPLICATION_w_size = 700
APPLICATION_z_size = 500
screen = pygame.display.set_mode((APPLICATION_w_size, APPLICATION_z_size), RESIZABLE)
#screen = pygame.display.set_mode((APPLICATION_w_size, APPLICATION_z_size), FULLSCREEN)
pygame.display.set_caption("HEHE test draw thingie program Matthew N. Brown copyright 2007")
#pygame.mouse.set_visible(0)
global background
background = pygame.Surface(screen.get_size())
background.fill((0, 0, 0))
screen.blit(background, (0, 0))
pygame.display.flip()
random.seed()
player_w = 3
player_z = 2
x = -1
map_w_size = 10
map_z_size = 10
map = [[x, x, x, x, x, x, x, x, x, x, x],
[x, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1],
[x, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1],
[x, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1],
[x, 1, 1, 0, 0, 1, 0, 0, 4, 0, 0],
[x, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0],
[x, 1, 1, 0, 0, 2, 0, 1, 1, 0, 1],
[x, 1, 1, 1, 0, 2, 0, 1, 0, 0, 1],
[x, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1],
[x, 1, 0, 4, 0, 1, 0, 0, 0, 0, 1],
[x, 1, 0, 2, 2, 2, 2, 2, 2, 2, 1]]
map[player_z][player_w] = 3
## IMAGE STRETCH AND ROTATE: ##
def chilly_font(size):
fonti = pygame.font.Font(None, size)
fonti.set_bold(0)
return fonti
## DRAW TEXT IMAGE: ##
def draw_chilly_text (t, special, size, w, z, colory):
fonty = chilly_font(size)
IMAGEE = fonty.render(t, special, colory)
screen.blit(IMAGEE, (w, z))
### some functions: ###
def in_repeating_boundy (n, b1, b2):
if n < b1: n = b2
if n > b2: n = b1
return n
def in_boundy (n, b1, b2):
if n < b1: n = b1
if n > b2: n = b2
return n
def in_boundy2D ((w, z), (w1, z1, w2, z2)):
if w < w1: w = w1
if w > w2: w = w2
if z < z1: z = z1
if z > z2: z = z2
return w, z
def chilly_distance (w1, z1, w2, z2):
return math.sqrt(math.pow(w1 - w2, 2) + math.pow(z1 - z2, 2))
def chilly_rect_touching_rect(w1, z1, wol1, zol1, w2, z2, wol2, zol2):
w2 -= w1
z2 -= z1
ww1 = -wol2
zz1 = -zol2
return (w2 >= ww1 and w2 <= wol1 and z2 >= zz1 and z2 <= zol1)
## keys and mouse stuff: ##
global ky_held, ky_first_held, ky_time_last_pressed
global mouse_w, mouse_z, mouse_inn, mouse_left_pressed, mouse_right_pressed, mouse_left_held, mouse_right_held
not_mouse_left_or_right_held = 1
mouse_left_held = 0
mouse_right_held = 0
mouse_w = 0
mouse_z = 0
mouse_inn = 0
ky_held = [0]
ky_first_held = [0]
ky_time_last_pressed = [0]
m = -1
while (m < 500):
m += 1
ky_held += [0]
ky_first_held += [0]
ky_time_last_pressed += [0]
## MOUSE AND KEY FUNCTIONS: ##
def clear_kys():
m = -1
while (m < 500):
m += 1
ky_held[m] = 0
ky_first_held[m] = 0
ky_time_last_pressed[m] = 0
def mouse_left_pressed_CEV():
global mouse_left_pressed
if mouse_left_pressed: mouse_left_pressed = 0; return 1
def mouse_right_pressed_CEV():
global mouse_right_pressed
if mouse_right_pressed: mouse_right_pressed = 0; return 1
def old_style_ky(n):
return (ky_first_held_CEV(n) or (ky_held[n] and ky_time_last_pressed[n] < time.time() - .3))
def ky_first_held_CEV(n):
if (ky_first_held[n]):
ky_first_held[n] = 0
return 1
else:
return 0
def mouse_in_rect (w, z, wol, zol):
return (mouse_w >= w and mouse_z >= z and mouse_w <= w + wol and mouse_z <= z + zol)
def mouse_in_circle (w, z, rad):
dia = rad * 2
if mouse_in_rect(w - rad, z - rad, w + dia, z + dia):
return (chilly_distance(mouse_w, mouse_z, w, z) < rad)
else:
return 0
## CHECK FOR: KEYBOARD, MOUSE, JOYSTICK, AND OTHERY INPUTY: ##
def check_for_keys():
global mouse_w, mouse_z, mouse_inn, mouse_left_pressed, mouse_right_pressed, mouse_left_held, mouse_right_held
global loopy, letter_hitty
global not_mouse_left_or_right_held
for e in pygame.event.get():
if e.type == QUIT:
loopy = 0
if e.type == ACTIVEEVENT:
mouse_inn = (e.gain and (e.state == 1 or e.state == 6))
if not mouse_inn:
mouse_w = 0
mouse_z = 0
if e.type == KEYDOWN:
ky_held[e.key] = 1
ky_first_held[e.key] = 1
ky_time_last_pressed[e.key] = time.time()
if (e.key >= 97 and e.key <= 122):
letter_hitty = e.unicode.lower()
if e.type == KEYUP:
ky_held[e.key] = 0
#ky_first_held[e.key] = 0
if e.type == MOUSEMOTION:
mouse_w = e.pos[0]
mouse_z = e.pos[1]
if e.type == MOUSEBUTTONUP:
if e.button == 1: mouse_left_held = 0
if e.button == 3: mouse_right_held = 0
if not mouse_left_held and not mouse_right_held: not_mouse_left_or_right_held = 1
if e.type == MOUSEBUTTONDOWN:
mouse_left_pressed = e.button == 1
mouse_right_pressed = e.button == 3
mouse_left_held = mouse_left_held or e.button == 1
mouse_right_held = mouse_right_held or e.button == 3
if mouse_left_held or mouse_right_held: not_mouse_left_or_right_held = 0
if e.type == JOYAXISMOTION: nnnnnn = 7
if e.type == JOYBALLMOTION: nnnnnn = 8
if e.type == JOYHATMOTION: nnnnnn = 9
if e.type == JOYBUTTONUP: nnnnnn = 10
if e.type == JOYBUTTONDOWN: nnnnnn = 11
if e.type == VIDEORESIZE:
global background, Dimage_editing_screen, screen, APPLICATION_w_size, APPLICATION_z_size
APPLICATION_w_size = e.size[0]
APPLICATION_z_size = e.size[1]
screen = pygame.display.set_mode((APPLICATION_w_size, APPLICATION_z_size), RESIZABLE)
background = pygame.Surface((APPLICATION_w_size, APPLICATION_z_size))
if e.type == VIDEOEXPOSE: nnnnnn = 13
if e.type == USEREVENT: nnnnnn = 14
### MORE STUFF: ###
HE_HE_surfacey = pygame.Surface((40, 40))
color1 = (200, 200, 200)
color2 = (200, 0, 0)
color3 = (0, 200, 0)
color4 = (130, 180, 180)
black_colory = (0, 0, 0)
HE_HE_surfacey.fill(black_colory)
def try_to_push_block(w, z, wo, zo):
if map[z][w] == 1:
w_pushed = w + wo
z_pushed = z + zo
w_pushed, z_pushed = in_boundy2D((w_pushed, z_pushed), (0, 0, map_w_size, map_z_size))
if map[z_pushed][w_pushed] == 0:
map[z][w] = 0
map[z_pushed][w_pushed] = 1
def draw_map():
ww = 0
while ww < map_w_size:
ww += 1
zz = 0
while zz < map_z_size:
zz += 1
n = map[zz][ww]
screen.blit(HE_HE_surfacey, (ww * 40, zz * 40))
if n == 1:
pygame.draw.rect(screen, color1, (ww * 40, zz * 40, 40, 40), 2)
elif n == 2:
#pygame.draw.rect(screen, color2, (ww * 40, zz * 40, 40, 40), 2)
pygame.draw.circle(screen, color2, (ww * 40 + 20, zz * 40 + 20), 17, 2)
elif n == 3:
#pygame.draw.rect(screen, color3, (ww * 40, zz * 40, 40, 40), 2)
locy_w = ww * 40
locy_z = zz * 40
point1 = (20 + locy_w, 10 + locy_z)
point2 = (40 + locy_w, 12 + locy_z)
point3 = (30 + locy_w, 19 + locy_z)
point4 = (30 + locy_w, 30 + locy_z)
point5 = (20 + locy_w, 20 + locy_z)
points = (point1, point2, point3, point4, point5)
pygame.draw.polygon(screen, color3, points, 2)
elif n == 4:
pygame.draw.rect(screen, color4, (ww * 40, zz * 40, 40, 40), 4)
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
# NOTE: w = x
# NOTE: z = y
# -- HE, HE, Bad habit of mine . . .
## MAIN: ##
if __name__ == '__main__':
# THE MAIN, MAIN, MAIN LOOP:
loopy = 1
while (loopy == 1):
mouse_left_pressed = 0
mouse_right_pressed = 0
check_for_keys()
draw_map()
draw_chilly_text('Press the arrow keys to move . . .', 0, 20, 0, 0, (255, 255, 255))
wa = player_w
za = player_z
map[player_z][player_w] = 0
if old_style_ky(276): player_w -= 1
if old_style_ky(273): player_z -= 1
if old_style_ky(275): player_w += 1
if old_style_ky(274): player_z += 1
player_w, player_z = in_boundy2D((player_w, player_z), (0, 0, map_w_size, map_z_size))
try_to_push_block(player_w, player_z, player_w - wa, player_z - za)
if map[player_z][player_w] != 0:
player_w = wa
player_z = za
map[player_z][player_w] = 3
#if ky_first_held[27]: loopy = 0
pygame.display.flip()
|
| April 3, 2007 12:22pm - Anonymous |
just do:
img = pygame.image.load("<<enter file>>").convert()
-harry666t |
| March 17, 2007 1:13pm - Ian Mallett |
see: http://www.pygame.org/docs/tut/newbieguide.html #4 |
| March 5, 2007 12:13am - Ian Mallett |
See tutorials.
After each line
pygame.image.load("<<enter file>>")
Make it
pygame.image.load("<<enter file>>").convert()
No matter what, this will increase your speed by 600%!
Thanks to whoever put in that tutorial!
-P.Z. |
Draws a rectangular shape on the Surface. The given Rect is the area of the rectangle. The width argument is the thickness to draw the outer edge. If width is zero then the rectangle will be filled.
Keep in mind the Surface.fill - fill Surface with a solid color method works just as well for drawing filled rectangles. In fact the Surface.fill - fill Surface with a solid color can be hardware accelerated on some platforms with both software and hardware display modes.
| May 5, 2009 3:48pm - Anonymous |
|---|
Is this the same as pygame.surface.fill(color, rect)? |
| April 22, 2009 2:45pm - Anonymous |
Wouldn't the center simply be X = X2 - X1 Y = Y2 - Y1 ? Bottom right minus top left. That doesn't require any special math functions, yes? |
| November 24, 2008 8:35am - Anonymous |
How to get center of drowed rectangle without math? |
| December 6, 2007 3:43pm - Anonymous |
# This should draw a square with a hight of 20 pixels on a Surface: height = 20 pygame.draw.rect(Surface, (255, 255, 255), (0, 0, height, height)) |
| November 29, 2007 1:19pm - Anonymous |
How do you draw squares in pygame?? |
| October 18, 2007 7:23pm - Anonymous |
# This is an example that uses pygame.draw.rect:
import os, sys
import random
import pygame
from pygame.locals import *
pygame.init()
APPLICATION_x_size = 400
APPLICATION_y_size = 300
screen = pygame.display.set_mode((APPLICATION_x_size, APPLICATION_y_size))
pygame.display.set_caption('Fun Boring Example comes with Source Code too!!')
pygame.mouse.set_visible(True)
#pygame.mouse.set_visible(False)
black_square_that_is_the_size_of_the_screen = pygame.Surface(screen.get_size())
black_square_that_is_the_size_of_the_screen.fill((0, 0, 0))
screen.blit(black_square_that_is_the_size_of_the_screen, (0, 0))
pygame.display.flip()
Weeee = True
while Weeee:
# a color can be: (0 to 255, 0 to 255, 0 to 255)
My_red_color = (255, 0, 0)
My_blue_color = (0, 0, 255)
My_green_color = (0, 255, 0)
My_yellow_color = (255, 255, 0)
WHITE_WHITE_HOORAY = (255, 255, 255)
My_light_red_color = (255, 180, 180)
My_light_blue_color = (190, 190, 255)
# "screen.set_at((x, y), Color)" and "pygame.draw.rect(screen, Color, (x, y, x_size, y_size))" draw colors on to an "in computer memory image" called: "screen"
screen.set_at(( 1, 1), My_yellow_color)
screen.set_at(( 2, 2), My_yellow_color)
screen.set_at(( 3, 3), My_yellow_color)
screen.set_at(( 4, 4), My_yellow_color)
screen.set_at(( 5, 5), My_yellow_color)
screen.set_at(( 6, 6), My_yellow_color)
screen.set_at(( 7, 7), My_yellow_color)
screen.set_at(( 8, 8), My_yellow_color)
screen.set_at(( 9, 9), My_yellow_color)
screen.set_at((10, 10), My_yellow_color)
screen.set_at((11, 11), My_yellow_color)
screen.set_at((12, 12), My_yellow_color)
screen.set_at((13, 13), My_yellow_color)
screen.set_at((14, 14), My_yellow_color)
screen.set_at((15, 15), My_yellow_color)
screen.set_at((16, 16), My_yellow_color)
screen.set_at((17, 17), My_yellow_color)
screen.set_at((18, 18), My_yellow_color)
screen.set_at((19, 19), My_yellow_color)
screen.set_at((20, 20), My_yellow_color)
pygame.draw.rect(screen, My_red_color, (50, 50, 10, 10))
pygame.draw.rect(screen, My_red_color, (50, 120, 20, 20))
pygame.draw.rect(screen, My_blue_color, (50, 150, 30, 30))
pygame.draw.rect(screen, My_blue_color, (50, 1000, 1000, 10))
pygame.draw.rect(screen, My_green_color, (200, 10, 40, 40))
pygame.draw.rect(screen, My_light_red_color, (10, 200, 50, 50))
pygame.draw.rect(screen, My_light_blue_color, (200, 200, 60, 60))
pygame.draw.rect(screen, My_light_blue_color, (100, 200, 10, 2))
pygame.draw.rect(screen, WHITE_WHITE_HOORAY, (0, 100, 50, 52))
# If you delete the below line you should no longer see the vibrant colors.
pygame.display.flip()
# if the 'X' button is pressed the window should close:
Geesh = pygame.event.get()
if len(Geesh) > 0:
if Geesh[0].type == QUIT: Weeee = False
## Once this line is reached the window should close |
| October 17, 2007 4:49pm - Anonymous |
You can use Surface.set_at((x,y), colour) to set a pixel. |
| October 9, 2007 8:01pm - Anonymous |
colors are usually done as a tuple (red light out of 255,green light out of 255, blue light out of 255). |
| October 9, 2007 1:57pm - Anonymous |
There is no explanation of 'color' argument...? |
| September 5, 2007 9:50pm - Anonymous |
This will make one single pixel a Color at coordanates x, y on a Surface: pygame.draw.rect(Surface, Color, (x, y, 1, 1)) |
| August 1, 2007 5:48pm - Ian Mallett |
Right. Unfortunately, That's the way it is. A width or height of 0 should also be allowed, for rectangles of changing sizes (think progressbar at 0%) |
| July 16, 2007 9:15pm - Anonymous |
Can I draw just one pixel with this? Apparantly the smallest rect one can draw is 2 pixels big, I guess? |
| June 2, 2007 10:44am - Anonymous |
you can't "delete" something you have drawn, you have to draw something over it instead. you can make classes that wrap the different draw function and have both a "show" and a "hide" function and the hide function has to draw the background over the shape you created in "hide", but this can have weird results if shapes overlap and are not correctly redrawn. cheers |
| May 4, 2007 12:39am - Anonymous |
Once you draw something, how do you delete it?? |
| March 11, 2007 8:32pm - Anonymous |
the forth numer is the height of the rect |
| March 3, 2007 4:39pm - Anonymous |
first number = top left rectangle x coordinate second number = top left rectangle y coordinate third number = width of rectangle fourth number = length of rectangle |
Draws a polygonal shape on the Surface. The pointlist argument is the vertices of the polygon. The width argument is the thickness to draw the outer edge. If width is zero then the polygon will be filled.
For aapolygon, use aalines with the 'closed' parameter.
| April 16, 2009 1:34pm - Anonymous |
|---|
LOL |
| September 18, 2008 12:41am - Anonymous |
"For aapolygon use aalines" why not use lines for non aa polygon? |
Draws a circular shape on the Surface. The pos argument is the center of the circle, and radius is the size. The width argument is the thickness to draw the outer edge. If width is zero then the circle will be filled.
| June 12, 2009 7:37pm - Anonymous |
|---|
lY83IX <a href="http://tejfmdaeythv.com/">tejfmdaeythv</a>, [url=http://yuencgyjbppc.com/]yuencgyjbppc[/url], [link=http://ixugzkhpxezh.com/]ixugzkhpxezh[/link], http://dohmyqxyaxff.com/ |
| April 16, 2009 1:36pm - Anonymous |
what the fuck? |
| March 14, 2009 5:06pm - Anonymous |
If you want a 'cheap' antialiased circle, calculate all the points on a circle using sin/cos, then plot each point as an antialiased polygon. You should iterate through every n degrees or so such that you get the desired precision. 10 degrees is good enough for small circles. |
| December 16, 2008 7:37am - Anonymous |
Thanks for the full program listings in the comments section guys. Very, very useful, and not at all annoying. Well done! Just a note to say that using circle() to draw single pixels isn't very efficient. Try Pixelarray for fast pixel drawing. |
| February 25, 2008 11:09pm - Ian Mallett |
Should have an Anti-alias option... |
| January 10, 2008 10:20am - Miroslav Cika |
# Circle example: # When border=0 circle is filled # (screen, (rgb colour), (Xpos,Ypos),Diameter,border width) pygame.draw.circle(screen, (0, 127, 255), (300, 140), 50, 4) |
| December 23, 2007 3:46pm - Anonymous |
# Matthew N. Brown copyright 2007
# Here is an example program in wich
# balls hit walls and other balls:
#
# This program draws circles using: pygame.draw.circle
#
# You can copy this program on to
# your own computer and run it.
#
import os, sys
## INIT STUFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#########################################################################################
def HE_HE_init():
global screen, big_black_rect, APPLICATION_w_size, APPLICATION_z_size
global WOW_pi_divided_by_180, WOW_180_divided_by_pi
pygame.init()
random.seed()
APPLICATION_w_size = 700
APPLICATION_z_size = 500
##### To close window while in fullscreen, press Esc while holding shift. #######
screen = pygame.display.set_mode((APPLICATION_w_size, APPLICATION_z_size))
#screen = pygame.display.set_mode((APPLICATION_w_size, APPLICATION_z_size), FULLSCREEN)
pygame.display.set_caption("They bwounce off bwalls? Matthew N. Brown copyright 2007")
pygame.mouse.set_visible(1)
big_black_rect = pygame.Surface(screen.get_size())
big_black_rect = big_black_rect.convert()
big_black_rect.fill((0, 0, 0))
screen.blit(big_black_rect, (0, 0))
#fonty = pygame.font.Font(None, 36)
fonty = pygame.font.SysFont("Times New Roman", 25)
fonty.set_bold(0)
IMAGEE = fonty.render('Loading . . .', 1, (0, 250, 10))
screen.blit(IMAGEE, (100, 200)); del IMAGEE
pygame.display.flip()
pygame.mixer.init(22050, -16, True, 1024)
WOW_pi_divided_by_180 = math.pi / 180.0
WOW_180_divided_by_pi = 180.0 / math.pi
set_up_key_variables()
Lets_ROLL()
## INIT STUFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#########################################################################################
## SAVE LEVEL?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#########################################################################################
def write_to_file_WEEE_STRANGE(file_namey, data):
noq = '\n'
filey = open(file_namey, 'w')
for d in data:
filey.write( str(d) + noq)
## SAVE LEVEL?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#########################################################################################
## SMALL FUNCTIONS STUFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#########################################################################################
### some functions: ###
def distance_2D (w1, z1, w2, z2):
return math.sqrt(math.pow(float(w1) - float(w2), 2) + math.pow(float(z1) - float(z2), 2))
def rect_touching_rect(w1, z1, wol1, zol1, w2, z2, wol2, zol2):
w2 -= w1
z2 -= z1
ww1 = -wol2
zz1 = -zol2
return (w2 > ww1 and w2 < wol1 and z2 > zz1 and z2 < zol1)
def rect_touching_rect2(w1, z1, wol1, zol1, w2, z2, wol2, zol2):
w2 -= w1
z2 -= z1
ww1 = -wol2
zz1 = -zol2
return (w2 >= ww1 and w2 <= wol1 and z2 >= zz1 and z2 <= zol1)
def positive(n):
if n < 0: n = -n; return n
def int_randy(range, add):
return int((random.random() * range) + add)
def randy(range, add):
return (random.random() * range) + add
def freaky_rect_switcharoo_2D(pw, pz, pwol, pzol, buffy_the_fat):
buffy_the_fat2 = buffy_the_fat * 2
if pwol > 0:
gw = pw; gwol = pwol
else:
gw = pwol + pw; gwol = pw - gw
if pzol > 0:
gz = pz; gzol = pzol
else:
gz = pzol + pz; gzol = pz - gz
return [gw - buffy_the_fat, gz - buffy_the_fat, gwol + buffy_the_fat2, gzol + buffy_the_fat2]
def points_rotated_by_angle_2D(points_wz, axis_w, axis_z, angle):
rotated_points_wz = []
angle = -angle -90
angle_times_WOW_pi_divided_by_180 = angle * WOW_pi_divided_by_180
c1 = math.cos(angle_times_WOW_pi_divided_by_180)
s1 = math.sin(angle_times_WOW_pi_divided_by_180)
for pointy in points_wz:
xt = pointy[0] - axis_w
yt = pointy[1] - axis_z
rotated_points_wz += [(-xt * s1) + (yt * c1) + axis_w, (-xt * c1) - (yt * s1) + axis_z]
return rotated_points_wz
def point_rotated_by_angle_2D(point_w, point_z, axis_w, axis_z, angle):
angle = -angle -90
angle_times_WOW_pi_divided_by_180 = angle * WOW_pi_divided_by_180
c1 = math.cos(angle_times_WOW_pi_divided_by_180)
s1 = math.sin(angle_times_WOW_pi_divided_by_180)
xt = point_w - axis_w
yt = point_z - axis_z
return (-xt * s1) + (yt * c1) + axis_w, (-xt * c1) - (yt * s1) + axis_z
def arc_tangent_2D(point_w, point_z):
return math.atan2(point_w, point_z) * WOW_180_divided_by_pi + 180
def arc_tangent_2D_2(point_w, point_z):
return -math.atan2(point_w, point_z) * WOW_180_divided_by_pi + 180
def ball_to_ball_wzkol_bounce(V1, m1, V2, m2, ball1_is_to_the_left):
if (ball1_is_to_the_left and V1 >= V2) or (not ball1_is_to_the_left and V1 <= V2):
Rv1 = V1 - V2
Rv2 = 0 #V2 - V2
NewV1 = ((m1 - m2) / float(m1 + m2)) * float(Rv1) + V2
NewV2 = (( 2 * m1) / float(m1 + m2)) * float(Rv1) + V2
return NewV1, NewV2
else:
return V1, V2
def Find_where_ball_stops_on_line_w(ball_w, ball_z, ball_wol, ball_zol, ball_rad, line_w, line_rad):
did_collide = False
totally = ball_rad + line_rad
b1 = line_w + totally
b2 = line_w - totally
New_ball_w = ball_w + ball_wol
New_ball_z = ball_z + ball_zol
if ball_w >= b1 and ball_wol < 0 and New_ball_w < b1: New_ball_w = b1; did_collide = True
elif ball_w <= b2 and ball_wol > 0 and New_ball_w > b2: New_ball_w = b2; did_collide = True
else:
if ball_w > b2 and ball_w < b1:
if ball_w > line_w and ball_wol < 0:
New_ball_w = ball_w; New_ball_z = ball_z
did_collide = True
elif ball_w < line_w and ball_wol > 0:
New_ball_w = ball_w; New_ball_z = ball_z
did_collide = True
return New_ball_w, New_ball_z, did_collide
New_ball_z = (float(ball_zol) / float(ball_wol) * float(New_ball_w - ball_w)) + float(ball_z)
return New_ball_w, New_ball_z, did_collide
def find_where_ball_collides_on_a_wall(
ball_w, ball_z,
ball_wol, ball_zol,
ball_rad,
wall_type,
wall_w1, wall_z1,
wall_w2, wall_z2,
wall_rad):
toetoadly = ball_rad + wall_rad
did_collide = False
New_ball_w = ball_w + ball_wol
New_ball_z = ball_z + ball_zol
angle_hit_at = None
Relate_ball_w = ball_w - wall_w1
Relate_ball_z = ball_z - wall_z1
Relate_wall_w2 = wall_w2 - wall_w1
Relate_wall_z2 = wall_z2 - wall_z1
arc_tangeriney = arc_tangent_2D(Relate_wall_w2, Relate_wall_z2)
Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_Relate_wall_w2, Rotate_Relate_wall_z2 = points_rotated_by_angle_2D(((Relate_ball_w, Relate_ball_z), (Relate_wall_w2, Relate_wall_z2)), 0, 0, arc_tangeriney)
Rotate_ball_wol, Rotate_ball_zol = point_rotated_by_angle_2D(ball_wol, ball_zol, 0, 0, arc_tangeriney)
Rotate_Relate_ball_collide_w, Rotate_Relate_ball_collide_z, did_hit_weird_line = Find_where_ball_stops_on_line_w(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, ball_rad, 0, wall_rad)
if Rotate_Relate_ball_w > -toetoadly and Rotate_Relate_ball_w < toetoadly:
HE_HE_strange_popper_z = Rotate_Relate_ball_z
else:
HE_HE_strange_popper_z = Rotate_Relate_ball_collide_z
Rotate_angle_hit_at = None
if HE_HE_strange_popper_z < Rotate_Relate_wall_z2:
if ball_is_going_towards_point(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, 0, Rotate_Relate_wall_z2):
p1_touched, p1_collide_w, p1_collide_z, p1_angle_hit_at = find_where_ball_collides_on_another_ball(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, ball_rad, 0, Rotate_Relate_wall_z2, wall_rad)
if p1_touched:
Rotate_Relate_ball_collide_w = p1_collide_w
Rotate_Relate_ball_collide_z = p1_collide_z
Rotate_angle_hit_at = p1_angle_hit_at
did_collide = True
elif HE_HE_strange_popper_z > 0:
if ball_is_going_towards_point(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, 0, 0):
p2_touched, p2_collide_w, p2_collide_z, p2_angle_hit_at = find_where_ball_collides_on_another_ball(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, ball_rad, 0, 0, wall_rad)
if p2_touched:
Rotate_Relate_ball_collide_w = p2_collide_w
Rotate_Relate_ball_collide_z = p2_collide_z
Rotate_angle_hit_at = p2_angle_hit_at
did_collide = True
else:
if did_hit_weird_line:
did_collide = True
if Rotate_Relate_ball_collide_w < 0: Rotate_angle_hit_at = 90
else: Rotate_angle_hit_at = 270
if did_collide:
arc_tangeriney_2 = -arc_tangeriney
angle_hit_at = Rotate_angle_hit_at + arc_tangeriney
New_ball_w, New_ball_z = point_rotated_by_angle_2D(Rotate_Relate_ball_collide_w, Rotate_Relate_ball_collide_z, 0, 0, arc_tangeriney_2)
New_ball_w += wall_w1
New_ball_z += wall_z1
return did_collide, New_ball_w, New_ball_z, angle_hit_at #, is_moving_towards
def zol_at_angle(wol, zol, angle):
rotated_wol, rotated_zol = point_rotated_by_angle_2D(wol, zol, 0, 0, angle)
return rotated_zol
def wzol_bounce_at_angle(wol, zol, angle, multi):
rotated_wol, rotated_zol = point_rotated_by_angle_2D(wol, zol, 0, 0, angle)
if rotated_zol > 0: rotated_zol = -rotated_zol * multi
return point_rotated_by_angle_2D(rotated_wol, rotated_zol, 0, 0, -angle)
def ball_is_going_towards_point(ball_w, ball_z, ball_wol, ball_zol, point_w, point_z):
angley = arc_tangent_2D(ball_w - point_w, ball_z - point_z)
rotated_wol, rotated_zol = point_rotated_by_angle_2D(ball_wol, ball_zol, 0, 0, angley)
return rotated_zol > 0
def find_where_ball_collides_on_another_ball (
ball1_w, ball1_z,
ball1_wol, ball1_zol,
ball1_rad,
ball2_w, ball2_z,
ball2_rad
):
totally = ball1_rad + ball2_rad
dis_from_each_other = math.sqrt(math.pow(float(ball1_w) - float(ball2_w), 2) + math.pow(float(ball1_z) - float(ball2_z), 2))
if dis_from_each_other < totally:
angley = arc_tangent_2D(ball1_w - ball2_w, ball1_z - ball2_z)
return True, ball1_w, ball1_z, angley
else:
they_did_touch = False
New_ball1_w = ball1_w + ball1_wol
New_ball1_z = ball1_z + ball1_zol
angle_hit_at = None
Relate_ball1_w = ball1_w - ball2_w
Relate_ball1_z = ball1_z - ball2_z
Relate_ball2_w = 0
Relate_ball2_z = 0
arcy_tangeriney = arc_tangent_2D(ball1_wol, ball1_zol)
Rotated_Relate_ball1_w, Rotated_Relate_ball1_z, Rotated_ball1_wol, Rotated_ball1_zol = points_rotated_by_angle_2D(((Relate_ball1_w, Relate_ball1_z), (ball1_wol, ball1_zol)), 0, 0, arcy_tangeriney)
did_collidey = False
if Rotated_Relate_ball1_z > 0 and (Rotated_Relate_ball1_w > -totally and Rotated_Relate_ball1_w < totally):
Rotated_Relate_ball1_collide_w = Rotated_Relate_ball1_w # + Rotated_ball1_wol
HE_HE = math.pow(Rotated_Relate_ball1_w, 2) - math.pow(totally, 2)
if HE_HE < 0: HE_HE = -HE_HE
Rotated_Relate_ball1_collide_z = math.sqrt(HE_HE)
Rotated_Relate_ball1_z__PLUS__Rotated_ball1_zol = Rotated_Relate_ball1_z + Rotated_ball1_zol
if Rotated_Relate_ball1_collide_z < Rotated_Relate_ball1_z__PLUS__Rotated_ball1_zol:
collision_wol = Rotated_ball1_wol
collision_zol = Rotated_ball1_zol
Rotated_Relate_ball1_collide_z = Rotated_Relate_ball1_z__PLUS__Rotated_ball1_zol
angley_to_hit = None
else:
did_collidey = True
they_did_touch = True
angley_to_hit = arc_tangent_2D(Rotated_Relate_ball1_collide_w, Rotated_Relate_ball1_collide_z)
else:
angley_to_hit = None
collision_wol = Rotated_ball1_wol
collision_zol = Rotated_ball1_zol
Rotated_Relate_ball1_collide_w = Rotated_Relate_ball1_w + Rotated_ball1_wol
Rotated_Relate_ball1_collide_z = Rotated_Relate_ball1_z + Rotated_ball1_zol
if did_collidey:
arcy_tangeriney_2 = -arcy_tangeriney
angle_hit_at = angley_to_hit + arcy_tangeriney
New_ball1_w, New_ball1_z = point_rotated_by_angle_2D(Rotated_Relate_ball1_collide_w, Rotated_Relate_ball1_collide_z, 0, 0, arcy_tangeriney_2)
New_ball1_w += ball2_w
New_ball1_z += ball2_z
return they_did_touch, New_ball1_w, New_ball1_z, angle_hit_at #, New_ball1_wol, New_ball1_zol
### some functions: ###
## GRAPHICS STUFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#########################################################################################
def chilly_font(size):
fonti = pygame.font.SysFont("Times New Roman", size)
return fonti
def chilly_font_Italicy(size):
fonti = pygame.font.SysFont("Times New Roman", size)
fonti.set_italic(1)
return fonti
def draw_loading_messagey(stringy): # Draw loading message
pygame.mouse.set_visible(1)
fonty = chilly_font(26)
IMAGEE = fonty.render(stringy, 0, (0, 255, 0), (0, 0, 0))
screen.blit(IMAGEE, (200, 250))
del IMAGEE
pygame.display.flip()
## GRAPHICS STUFF: ##
#########################################################################################
## KEYS AND MOUSE STUFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#########################################################################################
def set_up_key_variables():
global ky_held, ky_first_held, ky_time_last_pressed
global mowse_w, mowse_z, mowse_inn
global mowse_left_pressed, mowse_right_pressed, mowse_left_held, mowse_right_held
mowse_left_held = False
mowse_right_held = False
mowse_left_pressed = False
mowse_right_pressed = False
mowse_w = 0
mowse_z = 0
mowse_inn = 0
ky_held = []
ky_first_held = []
ky_time_last_pressed = []
m = -1
while m < 500:
m += 1
ky_held += [0]
ky_first_held += [0]
ky_time_last_pressed += [0]
def clear_all_kys():
global mowse_left_pressed, mowse_right_pressed, mowse_left_held, mowse_right_held
mowse_left_held = False
mowse_right_held = False
mowse_left_pressed = False
mowse_right_pressed = False
m = -1
while (m < 500):
m += 1; ky_held[m] = 0; ky_first_held[m] = 0; ky_time_last_pressed[m] = 0
def clear_these_ky_first_held(list_keys_numbers):
for k in list_keys_numbers:
ky_first_held[k] = 0
def clear_first_held_kys():
m = -1
while (m < 500):
m += 1; ky_first_held[m] = 0
def old_style_ky(n):
return (ky_first_held_CEV(n) or (ky_held[n] and ky_time_last_pressed[n] < time.time() - .3))
def ky_first_held_CEV(n):
if (ky_first_held[n]):
ky_first_held[n] = 0; return 1
else:
return 0
def mowse_in_rect (w, z, wol, zol):
return (mowse_w >= w and mowse_z >= z and mowse_w <= w + wol and mowse_z <= z + zol)
def mowse_in_circle (w, z, rad):
dia = rad * 2
if mowse_in_rect(w - rad, z - rad, w + dia, z + dia):
return (distance_2D(mowse_w, mowse_z, w, z) < rad)
else:
return 0
## CHECK FOR: KEYBOARD, MOUSE, JOYSTICK, AND OTHERY INPUTY: ##
def check_for_keys():
global mowse_w, mowse_z, mowse_inn, mowse_left_pressed, mowse_right_pressed, mowse_left_held, mowse_right_held, APPLICATION_w_size, APPLICATION_z_size
global loopy
global unicodey
mowse_left_pressed = False
mowse_right_pressed = False
unicodey = ''
for e in pygame.event.get():
if e.type == QUIT:
loopy = 0
elif e.type == ACTIVEEVENT:
mowse_inn = (e.gain and (e.state == 1 or e.state == 6))
elif e.type == KEYDOWN:
ky_held[e.key] = 1
ky_first_held[e.key] = 1
ky_time_last_pressed[e.key] = time.time()
unicodey = e.unicode
elif e.type == KEYUP:
ky_held[e.key] = 0
elif e.type == MOUSEMOTION:
mowse_w = e.pos[0]
mowse_z = e.pos[1]
if mowse_w >= 0 and mowse_w <= APPLICATION_w_size and mowse_z >= 0 and mowse_z <= APPLICATION_z_size:
mowse_inn = 1
else:
mowse_inn = 0
elif e.type == MOUSEBUTTONUP:
if e.button == 1: mowse_left_held = 0
if e.button == 3: mowse_right_held = 0
elif e.type == MOUSEBUTTONDOWN:
mowse_left_pressed = (e.button == 1)
mowse_right_pressed = (e.button == 3)
mowse_left_held = mowse_left_held or e.button == 1
mowse_right_held = mowse_right_held or e.button == 3
elif e.type == JOYAXISMOTION:
pass
elif e.type == JOYBALLMOTION:
pass
elif e.type == JOYHATMOTION:
pass
elif e.type == JOYBUTTONUP:
pass
elif e.type == JOYBUTTONDOWN:
pass
elif e.type == VIDEORESIZE:
print e
print "What happened!?"
#global big_black_rect, screen
#APPLICATION_w_size = e.size[0]
#APPLICATION_z_size = e.size[1]
#screen = pygame.display.set_mode((APPLICATION_w_size, APPLICATION_z_size))#, RESIZABLE)
#big_black_rect = pygame.Surface(screen.get_size())
#big_black_rect = big_black_rect.convert()
#big_black_rect.fill((0, 100, 200))
elif e.type == VIDEOEXPOSE:
pass
elif e.type == USEREVENT:
pass
if ky_held[27] and (ky_held[303] or ky_held[304]): loopy = 0
## CHECK FOR: KEYBOARD, MOUSE, JOYSTICK, AND OTHERY INPUTY: ##
## KEYS AND MOUSE STUFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#########################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
## MAIN LOOPY STUFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#########################################################################################
def ball_is_going_towards_ball(Bn1, Bn2):
global ball_max, ball_w, ball_z, ball_wol, ball_zol, ball_rad, ball_color, ball_mass, ball_RECT
arc_tangerine = arc_tangent_2D(ball_w[Bn1] - ball_w[Bn2], ball_z[Bn1] - ball_z[Bn2])
woly1, zoly1 = point_rotated_by_angle_2D(ball_wol[Bn1], ball_zol[Bn1], 0, 0, arc_tangerine)
return zoly1 > 0
def ball_is_relatively_going_towards_ball(Bn1, Bn2):
global ball_max, ball_w, ball_z, ball_wol, ball_zol, ball_rad, ball_color, ball_mass, ball_RECT
arc_tangerine = arc_tangent_2D(ball_w[Bn1] - ball_w[Bn2], ball_z[Bn1] - ball_z[Bn2])
woly1, zoly1, woly2, zoly2 = points_rotated_by_angle_2D(((ball_wol[Bn1], ball_zol[Bn1]), (ball_wol[Bn2], ball_zol[Bn2])), 0, 0, arc_tangerine)
return zoly1 > 0 and zoly1 > zoly2 # zoly2 < zoly1 or zoly2 > zoly1 # zoly1 + zoly2 > 0
#return zoly1 > 0 or zoly1 > zoly2
def Make_two_balls_hit_at_angle(Bn1, Bn2, angle):
global bounce_friction
#print angle
global ball_max, ball_w, ball_z, ball_wol, ball_zol, ball_rad, ball_color, ball_mass, ball_RECT
woly1, zoly1, woly2, zoly2 = points_rotated_by_angle_2D(((ball_wol[Bn1], ball_zol[Bn1]), (ball_wol[Bn2], ball_zol[Bn2])), 0, 0, angle)
V1 = zoly1 * bounce_friction
V2 = zoly2 * bounce_friction
zoly1, zoly2 = ball_to_ball_wzkol_bounce(V1, ball_mass[Bn1], V2, ball_mass[Bn2], True)
ball_wol[Bn1], ball_zol[Bn1], ball_wol[Bn2], ball_zol[Bn2] = points_rotated_by_angle_2D(((woly1, zoly1), (woly2, zoly2)), 0, 0, -angle)
updatey_ball_quick_rect(Bn1)
updatey_ball_quick_rect(Bn2)
def updatey_ball_quick_rect(B):
dia = ball_rad[B] * 2 + 4
ball_squar[B] = [ball_w[B] - ball_rad[B] - 2, ball_z[B] - ball_rad[B] - 2, dia, dia]
ball_RECT[B] = freaky_rect_switcharoo_2D(ball_w[B], ball_z[B], ball_wol[B], ball_zol[B], ball_rad[B] + 4)
def minus_ball_thing(n):
global ball_max, ball_w, ball_z, ball_wol, ball_zol, ball_rad, ball_color, ball_angle, ball_angleol, ball_squar, ball_mass, ball_RECT
if ball_max >= 0:
del ball_w [n]
del ball_z [n]
del ball_wol [n]
del ball_zol [n]
del ball_rad [n]
del ball_color [n]
del ball_squar [n]
del ball_angle [n]
del ball_angleol[n]
del ball_mass [n]
del ball_RECT [n]
ball_max -= 1
def add_ball_thing(w, z, wol, zol, rad, color, angle, angleol, mass_thing, rect_thing):
global ball_max, ball_w, ball_z, ball_wol, ball_zol, ball_rad, ball_color, ball_squar, ball_angle, ball_angleol, ball_mass, ball_RECT
ball_max += 1
ball_w += [w]
ball_z += [z]
ball_wol += [wol]
ball_zol += [zol]
ball_rad += [rad]
ball_color += [color]
ball_angle += [angle]
ball_angleol += [angleol]
dia = rad * 2
ball_squar += [[w - rad, z - rad, dia, dia]]
if mass_thing == True:
ball_mass += [4 / 3 * math.pi * rad * rad * rad]
else:
ball_mass += [mass_thing]
if rect_thing == True:
ball_RECT += [None]
updatey_ball_quick_rect(ball_max)
#ball_RECT += [freaky_rect_switcharoo_2D(w, z, wol, zol, rad)]
else:
ball_RECT += [rect_thing]
def minus_wall_thing(WAL):
global wall_max, wall_type, wall_w1, wall_z1, wall_w2, wall_z2, wall_rad, wall_color, wall_RECT
if wall_max >= 0:
del wall_type [WAL]
del wall_w1 [WAL]
del wall_z1 [WAL]
del wall_w2 [WAL]
del wall_z2 [WAL]
del wall_rad [WAL]
del wall_color [WAL]
del wall_RECT [WAL]
wall_max -= 1
def add_wall_thing(type, w1, z1, w2, z2, rad, color_thing, rect_thing):
global wall_max, wall_type, wall_w1, wall_z1, wall_w2, wall_z2, wall_rad, wall_color, wall_RECT
wall_max += 1
wall_type += [type]
wall_w1 += [w1]
wall_z1 += [z1]
wall_w2 += [w2]
wall_z2 += [z2]
wall_rad += [rad]
if color_thing == True:
if type == 1: color_thing = (220, 220, 220)
elif type == 2: color_thing = (240, 140, 130)
elif type == 3: color_thing = (100, 255, 100)
elif type == 4: color_thing = (255, 100, 100)
elif type == 5: color_thing = (100, 100, 255)
wall_color += [color_thing]
if rect_thing == True:
wall_RECT += [freaky_rect_switcharoo_2D(w1 - 2, z1 - 2, w2 - w1 + 4, z2 - z1 + 4, rad)]
else:
wall_RECT += [rect_thing]
def reset_stuff():
global ball_max, ball_w, ball_z, ball_wol, ball_zol, ball_rad, ball_color, ball_angle, ball_angleol, ball_squar, ball_mass, ball_RECT
global wall_max, wall_type, wall_w1, wall_z1, wall_w2, wall_z2, wall_rad, wall_color, wall_RECT
global levely
if levely == 1:
ball_max = -1
ball_w = []
ball_z = []
ball_wol = []
ball_zol = []
ball_rad = []
ball_color = []
ball_angle = []
ball_angleol = []
ball_squar = []
ball_mass = []
ball_RECT = []
#add_ball_thing(350, 300, 0, 0, 18, (230, 230, 250), 0, 0, True, True)
#add_ball_thing(150, 400, 0, 0, 40, (220, 210, 255), 0, 0, True, True)
#add_ball_thing(300, 150, 0, 0, 62, (110, 106, 255), 0, 0, True, True)
add_ball_thing(220, 200, 0, 0, 50, (180, 226, 255), 180, 0, True, True)
wall_max = -1
wall_type = []
wall_w1 = []
wall_z1 = []
wall_w2 = []
wall_z2 = []
wall_rad = []
wall_color = []
wall_RECT = []
add_wall_thing(1, 160, 250, 300, 270, 1, True, True)
add_wall_thing(1, 500, 270, 600, 310, 1, True, True)
add_wall_thing(1, 200, 450, 600, 450, 10, True, True)
add_wall_thing(1, 300, 350, 400, 370, 5, True, True)
add_wall_thing(1, 300, 100, 400, 100, 20, True, True)
add_wall_thing(1, 650, 140, 700, 200, 6, True, True)
add_wall_thing(1, 650, 140, 600, 40, 6, True, True)
add_wall_thing(1, 150, 340, 150, 340, 30, True, True)
add_wall_thing(1, 40, 200, 40, 200, 30, True, True)
add_wall_thing(1, 30, 30, 30, 30, 10, True, True)
add_wall_thing(1, 30, 30, 30, 30, 10, True, True)
add_wall_thing(1, 30, 30, 30, 30, 10, True, True)
add_wall_thing(1, 30, 30, 30, 30, 10, True, True)
add_wall_thing(1, 30, 30, 30, 30, 10, True, True)
add_wall_thing(1, 0, 0, APPLICATION_w_size, 0, 5, True, True)
add_wall_thing(1, 0, 0, 0, APPLICATION_z_size, 5, True, True)
add_wall_thing(1, 0, APPLICATION_z_size, APPLICATION_w_size, APPLICATION_z_size, 5, True, True)
add_wall_thing(1, APPLICATION_w_size, 0, APPLICATION_w_size, APPLICATION_z_size, 5, True, True)
elif levely == 2:
ball_max = 1
ball_w = [323.62638473709342, 384.72135876760257]
ball_z = [298.67896746658624, 109.24043981044279]
ball_wol = [-0.27396932987421913, 7.133321987715842]
ball_zol = [-0.38420912894762504, 1.6564147490246901]
ball_rad = [15, 28]
ball_color = [(137, 244, 234), (138, 221, 217)]
ball_angle = [51.908780125668613, 294.77431504891717]
ball_angleol = [-1.2400074168431123, 17.698615258690229]
ball_squar = [[306.62638473709342, 281.67896746658624, 34, 34], [354.72135876760257, 79.240439810442794, 60, 60]]
ball_mass = [10602.875205865552, 68964.24193160313]
ball_RECT = [[304.35241540721921, 279.2947583376386, 38.273969329874205, 38.384209128947646], [352.72135876760257, 77.240439810442794, 71.133321987715846, 65.656414749024691]]
wall_max = 17
wall_type = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
wall_w1 = [189, 290, 166, 14, 697, 562, 643, 3, 0, 223, 117, 695, 497, 497, 0, 0, 0, 700]
wall_z1 = [284, 316, 436, 499, 446, 0, 128, 225, 106, 310, 155, 210, 159, 159, 0, 0, 500, 0]
wall_w2 = [222, 446, 697, 157, 377, 681, 679, 49, 383, 287, 5, 448, 376, 546, 700, 0, 700, 700]
wall_z2 = [301, 314, 478, 432, 487, 99, 98, 416, 171, 324, 225, 323, 147, 179, 0, 500, 500, 500]
wall_rad = [1, 1, 10, 5, 20, 6, 6, 30, 30, 10, 10, 10, 10, 10, 5, 5, 5, 5]
wall_color = [(220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220)]
wall_RECT = [[186, 281, 39, 23], [287, 313, 162, 4], [154, 424, 555, 66], [7, 429, 157, 73], [359, 424, 356, 85], [554, -8, 135, 115], [635, 94, 52, 38], [-29, 193, 110, 255], [-32, 74, 447, 129], [211, 298, 88, 38], [-3, 143, 128, 94], [440, 198, 263, 137], [368, 139, 137, 28], [485, 147, 73, 44], [-7, -7, 714, 14], [-7, -7, 14, 514], [-7, 493, 714, 14], [693, -7, 14, 514]]
elif levely == 3:
ball_max = 2
ball_w = [425.0, 492.31837629165733, 98.512856261065167]
ball_z = [126.0, 422.24553778829392, 430.4902396760661]
ball_wol = [-12.0, 2.6816237083426699, 6.487143738934833]
ball_zol = [-3.0, -1.245537788293916, -21.490239676066096]
ball_rad = [15, 28, 21]
ball_color = [(137, 244, 234), (138, 221, 217), (136, 235, 236)]
ball_angle = [93.833857527468922, 75.681742520058592, 323.2915629772819]
ball_angleol = [-0.87655530207419896, 0.30220691772972269, 1.1825329351046094]
ball_squar = [[408.0, 109.0, 34, 34], [462.31837629165733, 392.24553778829392, 60, 60], [75.512856261065167, 407.4902396760661, 46, 46]]
ball_mass = [10602.875205865552, 68964.24193160313, 29094.28956489508]
ball_RECT = [[394.0, 104.0, 50.0, 41.0], [460.31837629165733, 389.0, 66.68162370834267, 65.245537788293916], [73.512856261065167, 384.0, 56.487143738934833, 71.490239676066096]]
wall_max = 17
wall_type = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
wall_w1 = [189, 290, 166, 14, 697, 562, 643, 3, 0, 223, 117, 695, 497, 497, 0, 0, 0, 700]
wall_z1 = [284, 316, 436, 499, 446, 0, 128, 225, 106, 310, 155, 210, 159, 159, 0, 0, 500, 0]
wall_w2 = [222, 446, 697, 157, 377, 681, 679, 49, 383, 287, 5, 480, 376, 546, 700, 0, 700, 700]
wall_z2 = [301, 314, 478, 432, 487, 99, 98, 416, 171, 324, 225, 325, 147, 179, 0, 500, 500, 500]
wall_rad = [1, 1, 10, 5, 20, 6, 6, 30, 30, 10, 10, 10, 10, 10, 5, 5, 5, 5]
wall_color = [(220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220)]
wall_RECT = [[186, 281, 39, 23], [287, 313, 162, 4], [154, 424, 555, 66], [7, 429, 157, 73], [359, 424, 356, 85], [554, -8, 135, 115], [635, 94, 52, 38], [-29, 193, 110, 255], [-32, 74, 447, 129], [211, 298, 88, 38], [-3, 143, 128, 94], [472, 198, 231, 139], [368, 139, 137, 28], [485, 147, 73, 44], [-7, -7, 714, 14], [-7, -7, 14, 514], [-7, 493, 714, 14], [693, -7, 14, 514]]
elif levely == 4:
ball_max = 15
ball_w = [60.722554805471077, 452.1573538490178, 80.244575784959252, 38.90004863123329, 526.62934623960155, 561.76077439217966, 51.00641675327735, 476.21179724447387, 74.019911348330012, 104.13986580489509, 77.672785567417591, 97.908669417930454, 492.31309851379422, 107.55531577343871, 25.677250467589708, 408.28461679522843]
ball_z = [123.53309256655999, 426.85562864865636, 446.98025958602022, 145.55077237791539, 432.36880616921724, 419.52605372165829, 185.76812996010321, 398.60172712183214, 227.90675893521163, 330.14246403509031, 280.7917430301959, 382.77488932204739, 431.7008452670733, 426.72875393133694, 108.86075181750218, 420.07030113046562]
ball_wol = [0.58974898201312453, 0.29357826379544644, -0.7453458908661944, -0.26977452024547638, -0.13077525550683244, 0.35703289164546842, 0.25581836770201244, -0.16968524576896582, -0.96858759109981474, 0.020541831638986374, 0.21623640500730243, 0.16869582232640204, -0.32778500262837312, -1.0423733543425631, 0.078384075232750969, 0.070169924397188832]
ball_zol = [2.5202528491916918, -0.067935899483811957, 1.0209651395893582, 1.5519551597452736, 0.37674466231734333, 0.7179102343171756, 1.2098558443319702, -0.21937811619009639, 1.6292902773669935, 0.95366629391114355, 0.99836183708718151, 0.65985328138026611, 0.72997687518744558, -0.33325230167901332, 1.8584237502130836, 1.1180771215980612]
ball_rad = [12, 20, 14, 19, 14, 23, 23, 13, 25, 28, 28, 25, 20, 20, 20, 24]
ball_color = [(132, 202, 208), (130, 220, 228), (133, 230, 241), (133, 200, 224), (138, 244, 248), (134, 176, 212), (132, 246, 206), (136, 191, 201), (130, 247, 204), (135, 190, 248), (136, 196, 244), (137, 246, 211), (132, 176, 232), (139, 200, 204), (135, 204, 206), (137, 234, 248)]
ball_angle = [250.64218161257492, 228.50285566079282, 169.93029421257162, 93.92451866434908, 160.53385135173758, 101.81391124171368, 58.682544988047297, 42.833392250734839, 278.96920717602609, 157.52451729820555, 104.82808146227505, 319.29094377305643, 8.3988066326588289, 61.303383965779759, 262.01723832271352, 187.75853100116501]
ball_angleol = [-11.145052526574146, 0.73910476098485844, -1.916370769365741, 7.8109934129380036, 1.2564621818214414, -0.21633250902344123, 0.96094866236460608, 18.696614939999161, -2.7765510174821686, -0.46915418861267033, 1.3615127061730832, 0.55215997018655683, 0.83188571652892485, -2.1096665563746759, 4.3536534603644128, 0.77565328887569629]
ball_squar = [[46.722554805471077, 109.53309256655999, 28, 28], [430.1573538490178, 404.85562864865636, 44, 44], [64.244575784959252, 430.98025958602022, 32, 32], [17.90004863123329, 124.55077237791539, 42, 42], [510.62934623960155, 416.36880616921724, 32, 32], [536.76077439217966, 394.52605372165829, 50, 50], [26.00641675327735, 160.76812996010321, 50, 50], [461.21179724447387, 383.60172712183214, 30, 30], [47.019911348330012, 200.90675893521163, 54, 54], [74.139865804895095, 300.14246403509031, 60, 60], [47.672785567417591, 250.7917430301959, 60, 60], [70.908669417930454, 355.77488932204739, 54, 54], [470.31309851379422, 409.7008452670733, 44, 44], [85.555315773438707, 404.72875393133694, 44, 44], [3.6772504675897082, 86.860751817502177, 44, 44], [382.28461679522843, 394.07030113046562, 52, 52]]
ball_mass = [5428.6721054031623, 25132.741228718347, 8620.5302414503913, 21548.184010972389, 8620.5302414503913, 38223.757816227015, 38223.757816227015, 6902.0790599367756, 49087.385212340516, 68964.24193160313, 68964.24193160313, 49087.385212340516, 25132.741228718347, 25132.741228718347, 25132.741228718347, 43429.376843225298]
tempy = [[24.00641675327735, 158.76812996010321, 54.255818367702012, 55.209855844331969], [459.04211199870491, 381.38234900564203, 34.16968524576896, 34.219378116190114], [44.051323757230193, 198.90675893521163, 58.968587591099819, 59.629290277366991], [72.139865804895095, 298.14246403509031, 64.02054183163898, 64.953666293911141], [45.672785567417591, 248.7917430301959, 64.216236405007308, 64.998361837087188], [68.908669417930454, 353.77488932204739, 58.168695822326399, 58.659853281380265], [467.98531351116583, 407.7008452670733, 48.327785002628389, 48.729976875187447], [82.512942419096149, 402.39550162965793, 49.042373354342558, 48.333252301679011], [1.6772504675897082, 84.860751817502177, 48.078384075232748, 49.858423750213085], [380.28461679522843, 392.07030113046562, 56.070169924397192, 57.118077121598063]]
ball_RECT = [[44.722554805471077, 107.53309256655999, 32.589748982013127, 34.520252849191692], [428.1573538490178, 402.78769274917255, 48.293578263795446, 48.067935899483814], [61.499229894093062, 428.98025958602022, 36.74534589086619, 37.020965139589357], [15.630274110987813, 122.55077237791539, 46.269774520245477, 47.551955159745276], [508.49857098409473, 414.36880616921724, 36.130775255506819, 36.376744662317343], [534.76077439217966, 392.52605372165829, 54.357032891645467, 54.717910234317173]] + tempy
del tempy
wall_max = 17
wall_type = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
wall_w1 = [189, 196, 166, 14, 697, 562, 643, 0, 326, 51, 18, 695, 497, 497, 0, 0, 0, 700]
wall_z1 = [284, 221, 436, 499, 446, 0, 128, 201, 62, 9, 182, 210, 159, 159, 0, 0, 500, 0]
wall_w2 = [220, 297, 697, 157, 377, 681, 679, 49, 304, 139, 0, 480, 376, 524, 700, 0, 700, 700]
wall_z2 = [244, 218, 478, 432, 487, 99, 98, 416, 161, 315, 126, 325, 147, 176, 0, 500, 500, 500]
wall_rad = [1, 1, 10, 5, 20, 6, 6, 30, 30, 10, 10, 10, 10, 10, 5, 5, 5, 5]
wall_color = [(220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220)]
wall_RECT = [[186, 245, 37, 38], [193, 218, 107, 3], [154, 424, 555, 66], [7, 429, 157, 73], [359, 424, 356, 85], [554, -8, 135, 115], [635, 94, 52, 38], [-32, 169, 113, 279], [276, 30, 78, 163], [39, -3, 112, 330], [-8, 118, 34, 72], [472, 198, 231, 139], [368, 139, 137, 28], [485, 147, 51, 41], [-7, -7, 714, 14], [-7, -7, 14, 514], [-7, 493, 714, 14], [693, -7, 14, 514]]
elif levely == 5:
ball_max = 15
ball_w = [563.2380017184845, 135.5091931534665, 435.09697027584525, 132.51126304855137, 158.80356877160969, 486.49890666361813, 28.0454597909272, 469.94449157610796, 253.77058846375945, 33.311743878553251, 651.08671805489632, 467.4560139814393, 420.90145867058521, 248.83956419449743, 98.267666685148598, 670.85536291962285]
ball_z = [340.3499477728684, 192.53572614832325, 274.00276170743837, 474.72360924550071, 248.04392629767023, 199.66234253741388, 291.77486188629132, 98.828156873677884, 261.79870802935454, 452.90721309179793, 434.31611085503482, 422.84067516142846, 143.71750465032488, 474.55563009909457, 63.407930077910926, 97.5392796541895]
ball_wol = [-0.12736934788998625, -0.34670289908297647, -0.62730956112551528, -0.01316352118701539, -0.36875760413492498, 0.3253705975573648, -0.43186646985168864, 0.029829055857965088, -0.051399766840351885, 0.31143213467472303, 0.91261705660387604, -0.39289683694945782, 0.6973192899270082, -0.026739395385515136, 0.47773812365404217, -0.14449244329674141]
ball_zol = [0.2651067487506561, 0.33747092449158278, -0.20330004911815291, 0.11263669365628809, 0.62183969591811039, 0.220324713577495, 0.12382039798193512, -0.062689280803922554, 0.13756798955280808, 0.8702172500111478, -0.031277763984301599, 0.28378328194527458, 0.1666190295210413, 0.056074468995401638, 0.75422143538357722, 0.14790083350095956]
ball_rad = [12, 20, 14, 19, 14, 23, 23, 13, 25, 28, 28, 25, 20, 20, 20, 24]
ball_color = [(132, 202, 208), (130, 220, 228), (133, 230, 241), (133, 200, 224), (138, 244, 248), (134, 176, 212), (132, 246, 206), (136, 191, 201), (130, 247, 204), (135, 190, 248), (136, 196, 244), (137, 246, 211), (132, 176, 232), (139, 200, 204), (135, 204, 206), (137, 234, 248)]
ball_angle = [103.32400188884675, 316.71158855283181, 66.797426175129175, 35.509394217326573, 15.886531654813545, 0.61656478963343941, 195.33151301725019, 152.08747184390086, 199.80989069184068, 131.62120808048311, 339.38767654500623, 158.21789358507957, 322.31233400906359, 97.437869538449633, 179.6312883714439, 134.41162557033078]
ball_angleol = [0.54118695268280415, -1.0009948706990461, -0.42583251039327935, -0.049119552546591096, -1.7234897593393199, 0.1278122582140804, -0.33925087348758332, 0.98916269599321738, 0.054177225060088277, 0.93648329222661952, 2.0855948904138386, -1.2792816321392795, 1.9343475351789952, -0.094694117658838645, 1.3328174529019678, 1.0390947956294083]
ball_squar = [[549.2380017184845, 326.3499477728684, 28, 28], [113.5091931534665, 170.53572614832325, 44, 44], [419.09697027584525, 258.00276170743837, 32, 32], [111.51126304855137, 453.72360924550071, 42, 42], [142.80356877160969, 232.04392629767023, 32, 32], [461.49890666361813, 174.66234253741388, 50, 50], [3.0454597909272003, 266.77486188629132, 50, 50], [454.94449157610796, 83.828156873677884, 30, 30], [226.77058846375945, 234.79870802935454, 54, 54], [3.3117438785532514, 422.90721309179793, 60, 60], [621.08671805489632, 404.31611085503482, 60, 60], [440.4560139814393, 395.84067516142846, 54, 54], [398.90145867058521, 121.71750465032488, 44, 44], [226.83956419449743, 452.55563009909457, 44, 44], [76.267666685148598, 41.407930077910926, 44, 44], [644.85536291962285, 71.5392796541895, 52, 52]]
ball_mass = [5428.6721054031623, 25132.741228718347, 8620.5302414503913, 21548.184010972389, 8620.5302414503913, 38223.757816227015, 38223.757816227015, 6902.0790599367756, 49087.385212340516, 68964.24193160313, 68964.24193160313, 49087.385212340516, 25132.741228718347, 25132.741228718347, 25132.741228718347, 43429.376843225298]
tempy = [[140.43481116747478, 230.04392629767023, 36.368757604134913, 36.621839695918112], [459.49890666361813, 172.66234253741388, 54.325370597557367, 54.220324713577497], [0.61359332107551268, 264.77486188629132, 54.431866469851684, 54.123820397981937], [452.94449157610796, 81.765467592873961, 34.029829055857967, 34.062689280803923], [224.7191886969191, 232.79870802935454, 58.051399766840348, 58.137567989552807], [1.3117438785532514, 420.90721309179793, 64.311432134674718, 64.870217250011152], [619.08671805489632, 402.28483309105053, 64.912617056603878, 64.031277763984292], [438.06311714448987, 393.84067516142846, 58.392896836949433, 58.283783281945276], [396.90145867058521, 119.71750465032488, 48.697319289927009, 48.166619029521044], [224.81282479911192, 450.55563009909457, 48.026739395385505, 48.056074468995405], [74.267666685148598, 39.407930077910926, 48.477738123654042, 48.754221435383577], [642.71087047632614, 69.5392796541895, 56.144492443296713, 56.147900833500962]]
ball_RECT = [[547.11063237059454, 324.3499477728684, 32.127369347889953, 32.265106748750654], [111.16249025438353, 168.53572614832325, 48.34670289908297, 48.337470924491583], [416.46966071471974, 255.79946165832024, 36.627309561125514, 36.203300049118127], [109.49809952736436, 451.72360924550071, 46.01316352118701, 46.112636693656285]] + tempy
del tempy
wall_max = 17
wall_type = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
wall_w1 = [135, 120, 230, 14, 531, 562, 441, 128, 403, 51, 504, 518, 377, 447, 0, 0, 0, 700]
wall_z1 = [265, 216, 439, 499, 339, 0, 217, 104, 306, 9, 441, 210, 168, 127, 0, 0, 500, 0]
wall_w2 = [227, 288, 697, 157, 456, 665, 476, 432, 61, 139, 633, 547, 435, 537, 700, 0, 700, 700]
wall_z2 = [262, 200, 478, 432, 302, 141, 228, 77, 334, 315, 295, 193, 178, 114, 0, 500, 500, 500]
wall_rad = [1, 1, 10, 5, 20, 6, 6, 30, 30, 10, 10, 10, 10, 10, 5, 5, 5, 5]
wall_color = [(220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220), (220, 220, 220)]
wall_RECT = [[132, 262, 98, 3], [117, 201, 174, 14], [218, 427, 491, 63], [7, 429, 157, 73], [438, 284, 111, 73], [554, -8, 119, 157], [433, 209, 51, 27], [96, 49, 368, 83], [33, 274, 398, 92], [39, -3, 112, 330], [492, 287, 153, 162], [506, 185, 53, 33], [365, 156, 82, 34], [435, 106, 114, 29], [-7, -7, 714, 14], [-7, -7, 14, 514], [-7, 493, 714, 14], [693, -7, 14, 514]]
def draw_walls_on_big_black_rect():
global wall_max, wall_type, wall_w1, wall_z1, wall_w2, wall_z2, wall_rad, wall_color, wall_RECT
global big_black_rect
global LIN_selected, CLICKER, CLICKER2
if CLICKER:
if LIN_selected != -1:
nnn = LIN_selected[0]
if LIN_selected[1] == 1:
wall_w1[nnn] = mowse_w
wall_z1[nnn] = mowse_z
else:
wall_w2[nnn] = mowse_w
wall_z2[nnn] = mowse_z
w1 = wall_w1[nnn]
z1 = wall_z1[nnn]
w2 = wall_w2[nnn]
z2 = wall_z2[nnn]
rad = wall_rad[nnn]
wall_RECT[nnn] = freaky_rect_switcharoo_2D(w1 - 2, z1 - 2, w2 - w1 + 4, z2 - z1 + 4, rad)
wl = -1
while wl < wall_max:
wl += 1
w1 = wall_w1[wl]
z1 = wall_z1[wl]
w2 = wall_w2[wl]
z2 = wall_z2[wl]
rad = wall_rad[wl]
collyu = wall_color[wl]
pygame.draw.line(big_black_rect, collyu, (w1, z1), (w2, z2), rad * 2)
pygame.draw.circle(big_black_rect, collyu, (w1, z1), rad)
pygame.draw.circle(big_black_rect, collyu, (w2, z2), rad)
#pygame.draw.rect(big_black_rect, (200, 200, 200), wall_RECT[wl], 1)
if CLICKER2:
if mowse_in_rect(wall_RECT[wl][0], wall_RECT[wl][1], wall_RECT[wl][2], wall_RECT[wl][3]):
if mowse_in_circle(w1, z1, rad+3): selected = -1; LIN_selected = [wl, 1]
elif mowse_in_circle(w2, z2, rad+3): selected = -1; LIN_selected = [wl, 2]
def Lets_ROLL():
global loopy
global ball_max, ball_w, ball_z, ball_wol, ball_zol, ball_rad, ball_color, ball_angle, ball_angleol, ball_squar, ball_mass, ball_RECT
global wall_max, wall_type, wall_w1, wall_z1, wall_w2, wall_z2, wall_rad, wall_color, wall_RECT
global bounce_friction, air_friction, gravity, rock_and_ROLLY
global LIN_selected, CLICKER, CLICKER2
global levely
levely = 3
bounce_friction = 0.8
#bounce_friction = 1.0
air_friction = 0.999
#air_friction = 1.0
gravity = 0.5
rock_and_ROLLY = math.pi / 8 * 180 #24
reset_stuff()
fontyyy = chilly_font_Italicy(24)
PRESS_SPACE_BAR_TO_MOVE_immy = fontyyy.render('Press SPACE BAR to start motion.', 0, (100, 200, 100))
PRESS_SPACE_BAR_TO_STOP_immy = fontyyy.render('Press SPACE BAR to stop motion.', 0, (200, 100, 100))
PRESS_ENTER_TO_RESET_immy = fontyyy.render('Press ENTER to reset.', 0, (150, 150, 150))
PRESS_MINUS_TO_MINUS_immy = fontyyy.render('Press - to delete a ball.', 0, (150, 150, 150))
PRESS_ADD_TO_ADD_immy = fontyyy.render('Press + to add a ball.', 0, (150, 150, 150))
LEFT_CLICK_TO_immy = fontyyy.render('Left click on a "ghost ball" to change its speed.', 0, (150, 150, 150))
RIGHT_CLICK_TO_immy = fontyyy.render('Right click on a ball to stop its motion.', 0, (150, 150, 150))
PRESS_S_TO_immy = fontyyy.render('Press S to stop all balls.', 0, (150, 150, 150))
PRESS_PAGE_UP_TO_immy = fontyyy.render('Press Page Up to change the level.', 0, (150, 150, 150))
#message_1_immy
del fontyyy
#calculate_for_sure = True
selected = -1
LIN_selected = -1
move_stuff = True
t = time.time() + .01
CLICKER = False
CLICKER2 = False
loopy = 1
while loopy:
big_black_rect.fill((0, 0, 0))
draw_walls_on_big_black_rect()
screen.blit(big_black_rect, (0, 0))
check_for_keys()
CLICKER = mowse_left_held
CLICKER2 = mowse_left_pressed
CLICKER_2 = mowse_right_held
CLICKER2_2 = mowse_right_pressed
if ky_first_held_CEV(32): move_stuff = not move_stuff
if ky_first_held_CEV(13): reset_stuff()
if ky_first_held_CEV(280):
levely += 1
if levely > 5: levely = 1
reset_stuff()
if ky_first_held_CEV(115): # S
M = -1
while M < ball_max:
M += 1
ball_wol[M] = 0
ball_zol[M] = 0
updatey_ball_quick_rect(M)
if ky_first_held_CEV(45) or ky_first_held_CEV(269): # -
minus_ball_thing(0)
if ky_first_held_CEV(61) or ky_first_held_CEV(270): # +
add_ball_thing(350 + randy(40, -20), 400 + randy(40, -20), randy(40, -20), randy(40, -20), int_randy(20, 10), (int_randy(10, 130), int_randy(80, 170), int_randy(50, 200)), 0, 0, True, True)
if ky_first_held_CEV(49):
listy = ['Level_save']
listy += ['ball_max = ' + str(ball_max)]
listy += ['ball_w = ' + str(ball_w)]
listy += ['ball_z = ' + str(ball_z)]
listy += ['ball_wol = ' + str(ball_wol)]
listy += ['ball_zol = ' + str(ball_zol)]
listy += ['ball_rad = ' + str(ball_rad)]
listy += ['ball_color = ' + str(ball_color)]
listy += ['ball_angle = ' + str(ball_angle)]
listy += ['ball_angleol = ' + str(ball_angleol)]
listy += ['ball_squar = ' + str(ball_squar)]
listy += ['ball_mass = ' + str(ball_mass)]
listy += ['ball_RECT = ' + str(ball_RECT)]
listy += ['wall_max = ' + str(wall_max)]
listy += ['wall_type = ' + str(wall_type)]
listy += ['wall_w1 = ' + str(wall_w1)]
listy += ['wall_z1 = ' + str(wall_z1)]
listy += ['wall_w2 = ' + str(wall_w2)]
listy += ['wall_z2 = ' + str(wall_z2)]
listy += ['wall_rad = ' + str(wall_rad)]
listy += ['wall_color = ' + str(wall_color)]
listy += ['wall_RECT = ' + str(wall_RECT)]
##write_to_file_WEEE_STRANGE("Level_Save.dat", listy)
del listy
if CLICKER2:
allow_selectey_thing = True
else:
allow_selectey_thing = False
if not CLICKER:
selected = -1
LIN_selected = -1
to_be_selected = selected
M = -1
while M < ball_max:
M += 1
if move_stuff:
move_ball(M)
wwol = int(ball_w[M] + ball_wol[M])
zzol = int(ball_z[M] + ball_zol[M])
pygame.draw.circle(screen, ball_color[M], (int(ball_w[M]), int(ball_z[M])), ball_rad[M])
blpw, blpz = point_rotated_by_angle_2D(0, -ball_rad[M], 0, 0, ball_angle[M])
pygame.draw.line(screen, (100, 100, 100), (int(ball_w[M] + blpw), int(ball_z[M] + blpz)), (int(ball_w[M]), int(ball_z[M])))
if not move_stuff:
pygame.draw.circle(screen, (100, 100, 250), (wwol, zzol), ball_rad[M], 1)
pygame.draw.circle(screen, (100, 100, 150), (wwol, zzol), int(ball_rad[M] * 1.0), 1)
pygame.draw.circle(screen, (150, 150, 200), (wwol, zzol), int(ball_rad[M] * 0.8), 1)
pygame.draw.circle(screen, (200, 200, 250), (wwol, zzol), int(ball_rad[M] * 0.5), 1)
pygame.draw.line(screen, (100, 160, 250), (int(ball_w[M]), int(ball_z[M])), (wwol, zzol))
pygame.draw.rect(screen, (130, 130, 130), ball_RECT[M], 1)
pygame.draw.rect(screen, (140, 140, 140), ball_squar[M], 1)
if allow_selectey_thing:
if mowse_in_rect(ball_RECT[M][0], ball_RECT[M][1], ball_RECT[M][2], ball_RECT[M][3]):
if mowse_in_circle(wwol, zzol, ball_rad[M]):
to_be_selected = M
LIN_selected = -1
if CLICKER_2:
if mowse_in_rect(ball_squar[M][0], ball_squar[M][1], ball_squar[M][2], ball_squar[M][3]):
if mowse_in_circle(ball_w[M], ball_z[M], ball_rad[M]):
ball_wol[M] = 0
ball_zol[M] = 0
ball_angleol[M] = 0
updatey_ball_quick_rect(M)
if CLICKER:
if selected == M:
if move_stuff:
mowseyy_w = mowse_w
mowseyy_z = mowse_z
bw1 = ball_rad[M]
bz1 = ball_rad[M]
bw2 = APPLICATION_w_size - ball_rad[M]
bz2 = APPLICATION_z_size - ball_rad[M]
if mowseyy_w < bw1: mowseyy_w = bw1
if mowseyy_w > bw2: mowseyy_w = bw2
if mowseyy_z < bz1: mowseyy_z = bz1
if mowseyy_z > bz2: mowseyy_z = bz2
ww = mowseyy_w - ball_w[M]
zz = mowseyy_z - ball_z[M]
#dissy = distance_2D(0, 0, ww, zz)
ball_wol[M] = ww # / 2.0 # / dissy
ball_zol[M] = zz # / 2.0 # / dissy
else:
ball_wol[M] = mowse_w - ball_w[M]
ball_zol[M] = mowse_z - ball_z[M]
updatey_ball_quick_rect(M)
selected = to_be_selected
if not move_stuff:
screen.blit(PRESS_SPACE_BAR_TO_MOVE_immy, (10, 10))
else:
screen.blit(PRESS_SPACE_BAR_TO_STOP_immy, (10, 10))
screen.blit(PRESS_MINUS_TO_MINUS_immy, (10, 30))
screen.blit(PRESS_ADD_TO_ADD_immy, (10, 50))
screen.blit(PRESS_ENTER_TO_RESET_immy, (10, 70))
screen.blit(LEFT_CLICK_TO_immy, (10, 90))
screen.blit(RIGHT_CLICK_TO_immy, (10, 110))
screen.blit(PRESS_S_TO_immy, (10, 130))
screen.blit(PRESS_PAGE_UP_TO_immy, (10, 150))
pygame.display.flip()
while t > time.time(): pass
t = time.time() + .01
# Try_Again_HE_HE Is weird!! maybe It should be deleted!!
def move_ball(M):
ball_angle[M] += ball_angleol[M]
if ball_angle[M] > 359: ball_angle[M] -= 360
elif ball_angle[M] < 0: ball_angle[M] += 361
#movey_bally_speciality(M, ball_wol[M], ball_zol[M], 10)
movey_bally_speciality(M, ball_wol[M], ball_zol[M], 10)
ball_zol[M] += gravity
updatey_ball_quick_rect(M)
def movey_bally_speciality(M, wol_special, zol_special, Try_Again_HE_HE):
global loopy
global ball_max, ball_w, ball_z, ball_wol, ball_zol, ball_rad, ball_color, ball_angle, ball_angleol, ball_squar, ball_mass, ball_RECT
global wall_max, wall_type, wall_w1, wall_z1, wall_w2, wall_z2, wall_rad, wall_color, wall_RECT
global bounce_friction, air_friction, gravity, rock_and_ROLLY
distance_is_supposed_to_be_at = distance_2D(0, 0, wol_special, zol_special)
wa = ball_w[M]
za = ball_z[M]
#will_be_w = wa + ball_wol[M]
#will_be_z = za + ball_zol[M]
will_be_w = wa + wol_special
will_be_z = za + zol_special
LIN_collide_max = -1
LIN_collide_w = []
LIN_collide_z = []
LIN_collide_ang = []
LIN_collide_dis = []
LL = -1
while LL < wall_max:
LL += 1
if rect_touching_rect2(ball_RECT[M][0], ball_RECT[M][1], ball_RECT[M][2], ball_RECT[M][3], wall_RECT[LL][0], wall_RECT[LL][1], wall_RECT[LL][2], wall_RECT[LL][3]):
#print 'weee'
did_collide, New_ball_w, New_ball_z, angle_hit_at = find_where_ball_collides_on_a_wall(wa, za, wol_special, zol_special, ball_rad[M], wall_type[LL], wall_w1[LL], wall_z1[LL], wall_w2[LL], wall_z2[LL], wall_rad[LL])
if did_collide:
#print 'collide'
#print str(New_ball_w), str(New_ball_z)
LIN_collide_max += 1
LIN_collide_w += [New_ball_w]
LIN_collide_z += [New_ball_z]
LIN_collide_ang += [angle_hit_at]
LIN_collide_dis += [distance_2D(wa, za, New_ball_w, New_ball_z)]
HEH_collide_max = -1
HEH_collide_w = []
HEH_collide_z = []
HEH_collide_ang = []
HEH_collide_dis = []
HEH_collide_ball_hit = []
M2 = -1
while M2 < ball_max:
M2 += 1
if M2 != M:
if rect_touching_rect2(ball_RECT[M][0], ball_RECT[M][1], ball_RECT[M][2], ball_RECT[M][3], ball_squar[M2][0], ball_squar[M2][1], ball_squar[M2][2], ball_squar[M2][3]):
#they_did_touch, New_ball1_w, New_ball1_z, angle_hit_at = find_where_ball_collides_on_another_ball(wa, za, ball_wol[M], ball_zol[M], ball_rad[M], ball_w[M2], ball_z[M2], ball_rad[M2])
they_did_touch, New_ball1_w, New_ball1_z, angle_hit_at = find_where_ball_collides_on_another_ball(wa, za, wol_special, zol_special, ball_rad[M], ball_w[M2], ball_z[M2], ball_rad[M2])
if they_did_touch:
HEH_collide_max += 1
HEH_collide_w += [New_ball1_w]
HEH_collide_z += [New_ball1_z]
HEH_collide_ang += [angle_hit_at]
HEH_collide_dis += [distance_2D(wa, za, New_ball1_w, New_ball1_z)]
HEH_collide_ball_hit += [M2]
current_dis = distance_is_supposed_to_be_at
Wall_to_hit_at_angley = None
Grr = -1
while Grr < LIN_collide_max:
Grr += 1
#print LIN_collide_dis[Grr], current_dis
if LIN_collide_dis[Grr] < current_dis:
#print 'weee!'
Wall_to_hit_at_angley = LIN_collide_ang[Grr]
current_dis = LIN_collide_dis[Grr]
will_be_w = LIN_collide_w[Grr]
will_be_z = LIN_collide_z[Grr]
Ball_to_hit = None
Ball_to_hit_at_angley = None
Heh = -1
while Heh < HEH_collide_max:
Heh += 1
if HEH_collide_dis[Heh] < current_dis:
if ball_is_going_towards_ball(M, HEH_collide_ball_hit[Heh]):
if ball_is_relatively_going_towards_ball(M, HEH_collide_ball_hit[Heh]):
Ball_to_hit = HEH_collide_ball_hit[Heh]
Ball_to_hit_at_angley = HEH_collide_ang[Heh]
else:
Ball_to_hit = None
Ball_to_hit_at_angley = None
current_dis = HEH_collide_dis[Heh]
will_be_w = HEH_collide_w[Heh]
will_be_z = HEH_collide_z[Heh]
if Ball_to_hit != None:
Make_two_balls_hit_at_angle(M, Ball_to_hit, Ball_to_hit_at_angley)
else:
#if bouncey == 1: ball_wol[M] = -ball_wol[M] * bounce_friction
#elif bouncey == 2: ball_zol[M] = -ball_zol[M] * bounce_friction
if Wall_to_hit_at_angley != None:
ball_wol[M], ball_zol[M] = wzol_bounce_at_angle(ball_wol[M], ball_zol[M], Wall_to_hit_at_angley, bounce_friction)
ball_angleol[M] = zol_at_angle(ball_wol[M], ball_zol[M], Wall_to_hit_at_angley + 90) / ball_rad[M] * rock_and_ROLLY
ball_w[M] = will_be_w
ball_z[M] = will_be_z
if ball_w[M] < 0 or ball_w[M] > APPLICATION_w_size or ball_z[M] < 0 or ball_z[M] > APPLICATION_z_size:
#print str(M) + " ", str(wa), str(za)
print str(M) + " ", str(ball_w[M]), str(ball_z[M]), str(ball_rad[M])
ball_wol[M] *= air_friction
ball_zol[M] *= air_friction
updatey_ball_quick_rect(M)
if current_dis < distance_is_supposed_to_be_at:
if Try_Again_HE_HE > 0:
distance_to_travel_next = distance_is_supposed_to_be_at - current_dis
disy_HE_HE = distance_2D(0, 0, ball_wol[M], ball_zol[M])
next_wol = ball_wol[M]
next_zol = ball_zol[M]
movey_bally_speciality(M, next_wol, next_zol, Try_Again_HE_HE - 1)
## Woah... Finally! Were near the end of the program! ##
if __name__ == '__main__':
import math
import pygame
import random
import time
import gc
import copy
from pygame.locals import *
if not pygame.font: print 'Warning, fonts disabled?'
if not pygame.mixer: print 'Warning, sound disabled?'
HE_HE_init()
## THE END! ## |
| September 23, 2007 8:07am - Victor Blomqvist |
Instead of drawing a circle with zero radius, you can use the method set_at on the surface to set the color of a single pixel: http://www.pygame.org/docs/ref/surface.html#Surface.set_at |
| September 8, 2007 2:17am - Anonymous |
How to draw a single pixel: draw a circle with radius zero! Took me a while to find this. circle( ..., 0 ) will give you a single pixel |
| July 29, 2007 7:02pm - Anonymous |
# Matthew N. Brown copyright 2007
# Here is an example program that
# draws a bouncing ball using: pygame.draw.circle
#
# You can copy this program on to
# your own computer and run it.
#
import os, sys
import random
import pygame
from pygame.locals import *
if not pygame.font: print 'Warning, fonts disabled'
if not pygame.mixer: print 'Warning, sound disabled'
import time
import gc
import math
pygame.init()
APPLICATION_w_size = 700
APPLICATION_z_size = 500
screen = pygame.display.set_mode((APPLICATION_w_size, APPLICATION_z_size), RESIZABLE)
#screen = pygame.display.set_mode((APPLICATION_w_size, APPLICATION_z_size), FULLSCREEN)
pygame.display.set_caption("HEHE test circle thingie program Matthew N. Brown copyright 2007")
#pygame.mouse.set_visible(0)
global background
background = pygame.Surface(screen.get_size())
background.fill((0, 0, 0))
screen.blit(background, (0, 0))
pygame.display.flip()
random.seed()
## IMAGE STRETCH AND ROTATE: ##
def HEHEHE_font(size):
fonti = pygame.font.Font(None, size)
fonti.set_bold(0)
return fonti
## DRAW TEXT IMAGE: ##
def draw_HEHEHE_text (t, special, size, w, z, colory):
fonty = HEHEHE_font(size)
IMAGEE = fonty.render(t, special, colory)
screen.blit(IMAGEE, (w, z))
### some functions: ###
def in_repeating_boundy (n, b1, b2):
if n < b1: n = b2
if n > b2: n = b1
return n
def in_boundy (n, b1, b2):
if n < b1: n = b1
if n > b2: n = b2
return n
def in_boundy2D ((w, z), (w1, z1, w2, z2)):
if w < w1: w = w1
if w > w2: w = w2
if z < z1: z = z1
if z > z2: z = z2
return w, z
def HEHEHE_distance (w1, z1, w2, z2):
return math.sqrt(math.pow(w1 - w2, 2) + math.pow(z1 - z2, 2))
def HEHEHE_rect_touching_rect(w1, z1, wol1, zol1, w2, z2, wol2, zol2):
w2 -= w1
z2 -= z1
ww1 = -wol2
zz1 = -zol2
return (w2 >= ww1 and w2 <= wol1 and z2 >= zz1 and z2 <= zol1)
## keys and mouse stuff: ##
global ky_held, ky_first_held, ky_time_last_pressed
global mouse_w, mouse_z, mouse_inn, mouse_left_pressed, mouse_right_pressed, mouse_left_held, mouse_right_held
not_mouse_left_or_right_held = 1
mouse_left_held = 0
mouse_right_held = 0
mouse_w = 0
mouse_z = 0
mouse_inn = 0
ky_held = [0]
ky_first_held = [0]
ky_time_last_pressed = [0]
m = -1
while (m < 500):
m += 1
ky_held += [0]
ky_first_held += [0]
ky_time_last_pressed += [0]
## MOUSE AND KEY FUNCTIONS: ##
def clear_kys():
m = -1
while (m < 500):
m += 1
ky_held[m] = 0
ky_first_held[m] = 0
ky_time_last_pressed[m] = 0
def mouse_left_pressed_CEV():
global mouse_left_pressed
if mouse_left_pressed: mouse_left_pressed = 0; return 1
def mouse_right_pressed_CEV():
global mouse_right_pressed
if mouse_right_pressed: mouse_right_pressed = 0; return 1
def old_style_ky(n):
return (ky_first_held_CEV(n) or (ky_held[n] and ky_time_last_pressed[n] < time.time() - .3))
def ky_first_held_CEV(n):
if (ky_first_held[n]):
ky_first_held[n] = 0
return 1
else:
return 0
def mouse_in_rect (w, z, wol, zol):
return (mouse_w >= w and mouse_z >= z and mouse_w <= w + wol and mouse_z <= z + zol)
def mouse_in_circle (w, z, rad):
dia = rad * 2
if mouse_in_rect(w - rad, z - rad, w + dia, z + dia):
return (HEHEHE_distance(mouse_w, mouse_z, w, z) < rad)
else:
return 0
## CHECK FOR: KEYBOARD, MOUSE, JOYSTICK, AND OTHERY INPUTY: ##
def check_for_keys():
global mouse_w, mouse_z, mouse_inn, mouse_left_pressed, mouse_right_pressed, mouse_left_held, mouse_right_held
global loopy, letter_hitty
global not_mouse_left_or_right_held
for e in pygame.event.get():
if e.type == QUIT:
loopy = 0
if e.type == ACTIVEEVENT:
mouse_inn = (e.gain and (e.state == 1 or e.state == 6))
if not mouse_inn:
mouse_w = 0
mouse_z = 0
if e.type == KEYDOWN:
ky_held[e.key] = 1
ky_first_held[e.key] = 1
ky_time_last_pressed[e.key] = time.time()
if (e.key >= 97 and e.key <= 122):
letter_hitty = e.unicode.lower()
if e.type == KEYUP:
ky_held[e.key] = 0
#ky_first_held[e.key] = 0
if e.type == MOUSEMOTION:
mouse_w = e.pos[0]
mouse_z = e.pos[1]
if e.type == MOUSEBUTTONUP:
if e.button == 1: mouse_left_held = 0
if e.button == 3: mouse_right_held = 0
if not mouse_left_held and not mouse_right_held: not_mouse_left_or_right_held = 1
if e.type == MOUSEBUTTONDOWN:
mouse_left_pressed = e.button == 1
mouse_right_pressed = e.button == 3
mouse_left_held = mouse_left_held or e.button == 1
mouse_right_held = mouse_right_held or e.button == 3
if mouse_left_held or mouse_right_held: not_mouse_left_or_right_held = 0
if e.type == JOYAXISMOTION: nnnnnn = 7
if e.type == JOYBALLMOTION: nnnnnn = 8
if e.type == JOYHATMOTION: nnnnnn = 9
if e.type == JOYBUTTONUP: nnnnnn = 10
if e.type == JOYBUTTONDOWN: nnnnnn = 11
if e.type == VIDEORESIZE:
global background, Dimage_editing_screen, screen, APPLICATION_w_size, APPLICATION_z_size
APPLICATION_w_size = e.size[0]
APPLICATION_z_size = e.size[1]
screen = pygame.display.set_mode((APPLICATION_w_size, APPLICATION_z_size), RESIZABLE)
background = pygame.Surface((APPLICATION_w_size, APPLICATION_z_size))
if e.type == VIDEOEXPOSE: nnnnnn = 13
if e.type == USEREVENT: nnnnnn = 14
### MORE STUFF: ###
ball_w = 30.0
ball_z = 20.0
ball_wol = 4.0
ball_zol = -1.0
gravity_w = 0.0
gravity_z = 1.0
radius = 11.0
makes_ball_slower_per_bounce = 1.2
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
#######################################################################################
# NOTE: w = x
# NOTE: z = y
# -- HE, HE, Bad habit of mine . . .
## MAIN: ##
if __name__ == '__main__':
# THE MAIN, MAIN, MAIN LOOP:
loopy = 1
while (loopy == 1):
t = time.time()
while t > time.time() - .03:
pass
mouse_left_pressed = 0
mouse_right_pressed = 0
check_for_keys()
ball_wol += gravity_w
ball_zol += gravity_z
if old_style_ky(276): ball_wol -= 12
if old_style_ky(273): ball_zol -= 22
if old_style_ky(275): ball_wol += 12
if old_style_ky(274): ball_zol += 22
if ky_held[115]: ball_wol = 0; ball_zol = 0
if ky_held[99]: ball_wol = (random.random() * 400) - 200; ball_zol = (random.random() * 400) - 200
ball_w += ball_wol
ball_z += ball_zol
if ball_w < radius: ball_w = radius; ball_wol = -(ball_wol / makes_ball_slower_per_bounce)
if ball_z < radius: ball_z = radius; ball_zol = -(ball_zol / makes_ball_slower_per_bounce)
if ball_w > APPLICATION_w_size - radius: ball_w = APPLICATION_w_size - radius; ball_wol = -(ball_wol / makes_ball_slower_per_bounce)
if ball_z > APPLICATION_z_size - radius: ball_z = APPLICATION_z_size - radius; ball_zol = -(ball_zol / makes_ball_slower_per_bounce)
screen.fill((0, 0, 0))
draw_HEHEHE_text('Press the arrow keys to move ball.', 0, 25, 0, 0, (255, 255, 255))
draw_HEHEHE_text('Hold S to stop ball.', 0, 25, 0, 30, (255, 255, 255))
draw_HEHEHE_text('press C to make ball go crazy.', 0, 25, 0, 70, (255, 255, 255))
pygame.draw.circle(screen, (200, 200, 200), (int(ball_w), int(ball_z)), int(radius))
#if ky_first_held[27]: loopy = 0
pygame.display.flip() |
Draws an elliptical shape on the Surface. The given rectangle is the area that the circle will fill. The width argument is the thickness to draw the outer edge. If width is zero then the ellipse will be filled.
| January 10, 2008 10:08am - Miroslav Cika |
|---|
# Ellipse example: # When border=0 ellipse is filled # (screen, (rgb colour) (Xpos,Ypos,width,height),border width) pygame.draw.ellipse(screen, (0, 127, 0), (300, 150, 80, 40), 0) |
| November 27, 2005 10:45pm - Anonymous |
if your rect contains a negative width or height you need to rect.normalize() your rect before passing it to this function |
Draws an elliptical arc on the Surface. The rect argument is the area that the ellipse will fill. The two angle arguments are the initial and final angle in radians, with the zero on the right. The width argument is the thickness to draw the outer edge.
| April 3, 2009 11:52am - Anonymous |
|---|
I was getting odd results with the default syntax of: pygame.draw.arc(screen, color, rect, angle1, angle2) Where angle1 < angle2. Not sure if I was doing something wrong with the regular python "x = sin(angle); y=cos(angle)" commands. But I found that reversing the angles worked well, like this: pygame.draw.arc(screen, color, rect, (math.pi * 2.0) - angle2, (math.pi * 2.0) - angle1) |
| February 24, 2009 10:22pm - Anonymous |
#Dibujar Arco/ Draw Arc, claro hay que importar la libreria math pygame.draw.arc(background, (0, 0, 0), ((5, 150), (100, 100)), 0, math.pi/2, 5) |
| February 16, 2008 3:39pm - Anonymous |
While thick arcs do get filled, they also get moire holes - at least on Debian's 1.7.1release-4.1. For now, I've been using a rather ugly workaround where one draws the arc several times with the start angle offset by 0.01 to cut the moires back. |
| February 26, 2007 6:27pm - Anonymous |
Just use the same line width as your radius. This of course dosn't solve your problem if you want a border on your arc, but then you can just paint twice. |
| November 19, 2006 2:38pm - Anonymous |
no fill? |
Draw a straight line segment on a Surface. There are no endcaps, the ends are squared off for thick lines.
| December 3, 2008 5:58pm - Anonymous |
|---|
d |
| February 12, 2008 6:09pm - Anonymous |
Is there a way to make the collision box of the line accurate to the line itself? |
| March 1, 2007 11:28am - Anonymous |
It looks like width is not a keyword argument, but a required/positional/whatever one instead. >>> pygame.draw.line(surf, color, (x1, y1), (x2, y2), width=width) Traceback (most recent call last): File "<console>", line 1, in ? TypeError: line() takes no keyword arguments >>> pygame.draw.line(surf, color, (x1, y1), (x2, y2)) <rect(0, 0, 11, 11)> >>> pygame.draw.line(surf, color, (x1, y1), (x2, y2), 1) <rect(0, 0, 11, 11)> |
| November 22, 2005 10:22pm - Anonymous |
This code fixes the bad rect given by the line function. temprect=(pygame.draw.line(screen,color,firstpos,newpos,thick)) temprect.inflate_ip(thick*2, thick*2) dirty.append(temprect) |
Draw a sequence of lines on a Surface. The pointlist argument is a series of points that are connected by a line. If the closed argument is true an additional line segment is drawn between the first and last points.
This does not draw any endcaps or miter joints. Lines with sharp corners and wide line widths can have improper looking corners.
Draws an anti-aliased line on a surface. This will respect the clipping rectangle. A bounding box of the affected area is returned returned as a rectangle. If blend is true, the shades will be be blended with existing pixel shades instead of overwriting them. This function accepts floating point values for the end points.
| June 12, 2009 7:27pm - Anonymous |
|---|
enymm7 <a href="http://yquqnezxrtdj.com/">yquqnezxrtdj</a>, [url=http://gxrthlbeewso.com/]gxrthlbeewso[/url], [link=http://kbbfxszmxwce.com/]kbbfxszmxwce[/link], http://vgsgeuljdksn.com/ |
| December 27, 2008 6:40am - Anonymous |
That fix doesn't allow for diagonal lines! I have the same issue. |
| May 29, 2008 7:54am - Anonymous |
You could use draw.rect() instead of draw.aaline() |
| March 28, 2008 2:12pm - Anonymous |
Is there a way to draw an anti aliased line with a thickness? |
Draws a sequence on a surface. You must pass at least two points in the sequence of points. The closed argument is a simple boolean and if true, a line will be draw between the first and last points. The boolean blend argument set to true will blend the shades with existing shades instead of overwriting them. This function accepts floating point values for the end points.
| June 18, 2008 2:46am - Jordan Trudgett |
|---|
return bezierLis -> return bezierList (line 65) |
| February 6, 2008 10:50am - Jeiel Aranal |
Use the following class to generate a bezier curve that can be drawn with aalines:
## Class begins here
class Bezier:
class SmoothnessError(Exception): pass
class CurveError(Exception): pass
def __init__(self):
"""
A Python class for generating bezier curves
An implementation of an algorithm presented by Nils Pipenbrinck
http://www.cubic.org/docs/bezier.htm
"""
def __lerp(self, ptA, ptB, t):
"""
Returns the linear interp between two points as a list
ptA and ptB are a list of xy coords, t is the point on the curve
"""
dest = []
dest.append(ptA[0]+float(ptB[0]-ptA[0])*t)
dest.append(ptA[1]+float(ptB[1]-ptA[1])*t)
return dest
def bezierPt(self, ctrlPts, t):
"""A recursive function for finding point t along a bezier curve"""
if len(ctrlPts) == 1:
#print "Len is 1", ctrlPts
return ctrlPts[0]
lerpList = []
for i in xrange(len(ctrlPts)-1):
ptA = [ctrlPts[i][0],ctrlPts[i][1]]
ptB = [ctrlPts[i+1][0],ctrlPts[i+1][1]]
lerpList.append(self.__lerp(ptA,ptB,t))
#print len(lerpList)
return self.bezierPt(lerpList, t)
def makeBezier(self, ctrlPts, smoothness):
"""
Returns a list of points on a bezier curve
ctrlPts is a list of 2d Points that define the curve, in most cases these
consist of control point locations and their handles, except in a 3 point
curve where it's just defined by the three control points.
smoothness is the number of points on the curve that should be generated.
This should always be more than two points or generating the bezier curve is
pointless and the script dies in a fire (or throws an exception)
"""
if len(ctrlPts) < 2:
raise self.CurverError("Curve list must contain more than one point")
if smoothness < 3:
raise self.SmoothnessError("Smoothness must be more than two")
iteration = smoothness
bezierList = []
subtract=1.0/smoothness
for i in xrange(0,iteration):
t = 1.0-(subtract*i)
if t < subtract:
t = 0
bPt = self.bezierPt(ctrlPts,t)
#print bPt
bezierList.append(bPt)
return bezierLis
## Class ends
###################
# An example of how to use the class with pygame
## Pygame Example
import math, pygame
from pygame.locals import *
import bezier
def main():
pygame.init()
screen = pygame.display.set_mode((640,480))
clock = pygame.time.Clock()
b = bezier.Bezier()
"""
A bezier curve definition, a list of 2d poins, simple innit
It's basically control points with control handle locations before or
after the control point.
Read http://www.cubic.org/docs/bezier.htm for more info
"""
bezierPts = [[40,100],[80,20],[150,180],[260,100]]
bLine = b.makeBezier(bezierPts, 10)
screen.fill((255,255,255))
pygame.draw.aalines(screen, (1,1,1), False, bLine, 1)
pygame.display.flip()
bounce = False
while True:
clock.tick(60)
pygame.event.pump()
event = pygame.event.poll()
if event.type == QUIT:
return
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
return
setTo = pygame.time.get_ticks()/20
bezierPts[1][1] = setTo
bLine = b.makeBezier(bezierPts,20)
screen.fill((255,255,255))
pygame.draw.aalines(screen, (1,1,1), False, bLine, 1)
pygame.display.flip()
if __name__ == "__main__":
m = main()
## End example |
| August 27, 2007 12:19pm - Anonymous |
If you try to use the alpha in [Color] its not applied, but Draw.lines applies alpha in [Color] |
