forked from ganzsz/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball.py
More file actions
55 lines (44 loc) · 1.21 KB
/
ball.py
File metadata and controls
55 lines (44 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys, time, math, os, random
from pyglet.gl import *
window = pyglet.window.Window()
keyboard = pyglet.window.key.KeyStateHandler()
window.push_handlers(keyboard)
class ball:
def __init__(self, x, y, Xsize, Ysize):
self.x=x
self.y=y
self.Xsize = Xsize
self.Ysize = Ysize
self.dy = 2
self.dx = 2
def draw(self):
pyglet.graphics.draw(4, pyglet.gl.GL_QUADS, ('v2f',
[self.x, self.y, self.x-self.Xsize, self.y, self.x-self.Xsize, self.y-self.Ysize, self.x, self.y-self.Ysize]))
def update(self):
global window
if(self.x==window.width):
self.dx=-2
if(self.x==self.Xsize):
self.dx=2
if(self.y==window.height):
self.dy=-2
if(self.y==self.Ysize):
self.dy=2
self.y+=self.dy
self.x+=self.dx
@window.event
def on_draw():
global ball
glClearColor(0, 0.2, 0.2, 0)
glClear(GL_COLOR_BUFFER_BIT)
ball.draw()
def update(tm):
global ball
ball.update()
@window.event
def on_key_press(symbol, modifiers):
global ball
ball.update()
ball=ball(100,200,50,50)
pyglet.clock.schedule_interval(update, 0.005)
pyglet.app.run()