Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
Conflicts: Vector.pyc
- Loading branch information
Showing
5 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
|
||
Player.pyc | ||
|
||
wallacetemp.png | ||
|
||
Vector.pyc | ||
|
||
Vector.pyc | ||
|
||
Enemy.pyc | ||
|
||
Arrow.pyc |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import pygame | ||
import os | ||
from Vector import * | ||
from math import sqrt | ||
|
||
def direction(x, y): | ||
"""Return the direction component of a vector (in radians), given | ||
cartesian coordinates. | ||
""" | ||
if x > 0: | ||
if y >= 0: | ||
return atan(y / x) | ||
else: | ||
return atan(y / x) + TwoPI | ||
elif x == 0: | ||
if y > 0: | ||
return HalfPI | ||
elif y == 0: | ||
return 0 | ||
else: | ||
return OneAndHalfPI | ||
else: | ||
return (atan(y / x) + PI) * 57.2957795 | ||
|
||
|
||
class Arrow(pygame.sprite.Sprite): | ||
def __init__(self,playerX,playerY,mouseX,mouseY): | ||
pygame.sprite.Sprite.__init__(self) | ||
self.image = pygame.image.load(os.path.join(os.curdir, 'arrow.png')).convert_alpha() | ||
self.rect = self.image.get_rect() | ||
self.rect = self.rect.move(playerX,playerY) | ||
self.x = playerX | ||
self.y = playerY | ||
diffX = mouseX - playerX | ||
diffY = mouseY - playerY | ||
if diffX != 0 and diffY!= 0: | ||
self.vector = Vector((diffX / sqrt(diffX*diffX + diffY*diffY)), (diffY / sqrt(diffX*diffX + diffY*diffY))) | ||
self.valid = True | ||
self.vel = 25 | ||
if self.vector.x > 0: | ||
self.ArrowObj = pygame.transform.rotate(self.image, 180 + direction(-self.vector.x,self.vector.y)) | ||
else: | ||
self.ArrowObj = pygame.transform.rotate(self.image, -direction(self.vector.x,self.vector.y)) | ||
|
||
def updateArrowPos(self): | ||
self.x += self.vector.x * self.vel | ||
self.y += self.vector.y * self.vel | ||
self.rect = self.rect.move(self.vector.x * self.vel, self.vector.y * self.vel) | ||
if self.x > 1280 or self.x < 0 or self.y > 720 or self.y < 0: | ||
return -1 | ||
self.valid = False | ||
else: | ||
return 1 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#A villianous enemy | ||
import pygame | ||
import os | ||
|
||
|
||
class Enemy(pygame.sprite.Sprite): | ||
|
||
def __init__(self, right, speed): | ||
pygame.sprite.Sprite.__init__(self) | ||
self.HP = 5 | ||
self.image = 0 | ||
self.images = [pygame.image.load(os.path.join(os.curdir, 'spritel1.png')).convert_alpha(), | ||
pygame.image.load(os.path.join(os.curdir, 'spritel2.png')).convert_alpha(), | ||
pygame.image.load(os.path.join(os.curdir, 'spritel3.png')).convert_alpha(), | ||
pygame.image.load(os.path.join(os.curdir, 'spritel4.png')).convert_alpha(), | ||
pygame.image.load(os.path.join(os.curdir, 'spritel5.png')).convert_alpha(), | ||
pygame.image.load(os.path.join(os.curdir, 'spritel6.png')).convert_alpha(), | ||
pygame.image.load(os.path.join(os.curdir, 'spritel7.png')).convert_alpha(), | ||
pygame.image.load(os.path.join(os.curdir, 'spritel8.png')).convert_alpha()] | ||
self.rect = self.images[self.image].get_rect() | ||
if right == True: | ||
self.x = 1280 | ||
self.y = 600 | ||
self.speed = -speed | ||
else: | ||
self.x = 0 | ||
self.y = 600 | ||
self.speed = speed | ||
self.rect = self.rect.move(self.x, self.y) | ||
|
||
|
||
def updateEnemyPos(self): | ||
self.image = (self.image + 1) % 8 | ||
if self.x + self.speed < 513 or self.x + self.speed > 745: | ||
self.x += self.speed | ||
self.rect = self.rect.move(self.speed,0) | ||
|
||
def swordHit(self, enemyList, index): | ||
self.HP = slef.HP - 5 | ||
if self.HP < 1: | ||
enemyList.pop(index) | ||
def arrowHit(self, enemyList, index): | ||
self.HP = slef.HP - 2.5 | ||
if self.HP < 1: | ||
enemyList.pop(index) |
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