Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/Sprite2.py56
1 files changed, 4 insertions, 52 deletions
diff --git a/src/api/Sprite2.py b/src/api/Sprite2.py
index d22bef7..b8c9e42 100644
--- a/src/api/Sprite2.py
+++ b/src/api/Sprite2.py
@@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-
import pygame
-import math
import Image
from api.Vector import CVector
+from api.Math import distVec
from Mouse import CMouse
@@ -21,15 +21,10 @@ class CSprite(pygame.sprite.Sprite):
self.mPos = CVector(x, y)
self.mVel = CVector(0, 0)
- # Registration point offset.
self.mOffsetX = 0
self.mOffsetY = 0
-
- # Speed of the sprite.
- self.mSpeed = 0
self.maxSpeed = 50
- self.minSpeed = -3
self.mactive = False
self.mclicked = False
@@ -74,22 +69,6 @@ class CSprite(pygame.sprite.Sprite):
if self.rect.collidepoint(CMouse().getPos()):
self.mclicked = True
- def setSpeed(self, speed):
- """ immediately sets the objects speed to the
- given value.
- """
- self.mSpeed = speed
-
- def speedUp(self, amount):
- """ changes speed by the given amount
- Use a negative value to slow down
- """
- self.mSpeed += amount
- if self.mSpeed < self.minSpeed:
- self.mSpeed = self.minSpeed
- if self.mSpeed > self.maxSpeed:
- self.mSpeed = self.maxSpeed
-
def loadImage(self, aImageFilename, aIsTransparent=True):
self.setImage(Image.loadImage(aImageFilename, aIsTransparent))
@@ -102,35 +81,14 @@ class CSprite(pygame.sprite.Sprite):
""" place the sprite directly at the given position
expects an vector
"""
- self.mPos.setX(position.getX())
- self.mPos.setY(position.getY())
+ self.mPos.setVec(position)
def setPosTuple(self, position):
""" place the sprite directly at the given position
-
expects an (x, y) tuple
"""
self.mPos.setXY(position[0], position[1])
- def setSpeedLimits(self, amax, amin):
- """ determines maximum and minimum
- speeds you will allow through
- speedUp() method. You can still
- directly set any speed you want
- with setSpeed() Default values:
- max: 10
- min: -3
- """
- self.maxSpeed = amax
- self.minSpeed = amin
-
- def dataTrace(self):
- """ utility method for debugging
- print major properties
- extend to add your own properties
- """
- print "x: %d, y: %d, speed: %.2f" % (self.mPos.x, self.mPos.y, self.mSpeed)
-
def mouseDown(self):
""" boolean function. Returns True if the mouse is
clicked over the sprite, False otherwise
@@ -160,10 +118,7 @@ class CSprite(pygame.sprite.Sprite):
""" returns distance to any point in pixels
can be used in circular collision detection
"""
- dx = self.mPos.x - point[0]
- dy = self.mPos.y - point[1]
-
- return math.sqrt((dx * dx) + (dy * dy))
+ return distVec(self.mPos, point)
def destroy(self):
self.image = None
@@ -179,8 +134,5 @@ class CSprite(pygame.sprite.Sprite):
return self.mPos.getY()
def getSize(self):
- if self.image:
- return (self.rect[2], self.rect[3])
- else:
- return (0,0)
+ return (self.rect[2], self.rect[3])