Created
May 10, 2013 11:09
-
-
Save bendtherules/5553778 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
class ball(object): | |
global mouse_down | |
#global pygame | |
def __init__(self,x=320,y=240,speed=3): | |
#global pygame | |
self.x=x | |
self.y=y | |
self.speed=speed | |
self.dir=None | |
self.ball=pygame.image.load("gun.png") | |
self.ballrect=self.ball.get_rect() | |
#global mouse_down | |
#mouse_down=False; | |
if not mouse_down: | |
print 5 | |
def mouse_handler(self): | |
global mouse_down | |
if pygame.event.get(pygame.MOUSEBUTTONDOWN) or mouse_down == True: | |
self.x=self.mouse_x | |
self.y=self.mouse_y | |
mouse_down=True | |
print 6 | |
if pygame.event.get(pygame.MOUSEBUTTONUP): | |
mouse_down=False | |
def step(self): | |
self.mouse_x,self.mouse_y=pygame.mouse.get_pos() | |
self.diff_x=self.mouse_x-self.x | |
self.diff_y=self.mouse_y-self.y | |
self.diff_rad=math.atan2(self.diff_y,self.diff_x) | |
self.x+=self.speed*math.cos(self.diff_rad) | |
self.y+=self.speed*math.sin(self.diff_rad) | |
self.ballrect.center=(self.x,self.y) | |
def draw(self): | |
screen.blit(self.ball, self.ballrect) | |
def update(self): | |
self.step() | |
self.mouse_handler() | |
self.draw() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment