Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
Conflicts:
	Vector.pyc
  • Loading branch information
Zcr1 committed Nov 6, 2011
2 parents ca9ecbd + 1f4c8f7 commit 9693657
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
@@ -1,8 +1,11 @@

Player.pyc

wallacetemp.png

Vector.pyc

Vector.pyc

Enemy.pyc

Arrow.pyc
54 changes: 54 additions & 0 deletions Arrow.py
@@ -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

45 changes: 45 additions & 0 deletions Enemy.py
@@ -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)
Binary file added Enemy.pyc
Binary file not shown.
17 changes: 15 additions & 2 deletions Main.py
Expand Up @@ -4,6 +4,7 @@
from Player import *
from Vector import *
from Enemy import *
from Arrow import *


def main():
Expand All @@ -22,6 +23,10 @@ def main():
maxEnemies = 10
enemyList = []

#Enemy variables
maxEnemies = 10
enemyList = []

if menu == True:
Menu(menu, windowSurfaceObj, fpsClock, desertBackground)
#Main Loop
Expand All @@ -44,10 +49,11 @@ def main():
sys.exit()
elif event.type == MOUSEMOTION:
mousex, mousey = event.pos
#player.updateVector(mousex,mousey)
elif event.type == MOUSEBUTTONUP:
if event.button in (1,2,3):
blah = "blah"
mousex, mousey = event.pos
arrow = Arrow(player.x,player.y,mousex,mousey)
ArrowList.append(arrow)
#left, middle, right button
elif event.button in (4,5):
blah = "blah"
Expand Down Expand Up @@ -94,6 +100,13 @@ def main():
#player.updatePos()
if not skipFall:
player.fall()

for i in range(len(ArrowList)):
chk = ArrowList[i].updateArrowPos()
if chk:
ArrowObj = ArrowList[i].ArrowObj
windowSurfaceObj.blit(ArrowObj, ArrowList[i].rect)

windowSurfaceObj.blit(player.images[player.image],player.rect)
#pygame.display.update()
pygame.display.flip()
Expand Down

0 comments on commit 9693657

Please sign in to comment.