-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.py
139 lines (123 loc) · 5.58 KB
/
Player.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#William Wallace himself
import pygame
import os
from Vector import *
from math import sqrt
class Player(pygame.sprite.Sprite):
bottom = 630
left = 0
right = 720
def __init__(self):
self.image = 17
self.framenumber = 0
self.swinging = 4;
self.gunmode = False;
pygame.sprite.Sprite.__init__(self)
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(),
pygame.image.load(os.path.join(os.curdir, 'spriter1.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter2.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter3.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter4.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter5.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter6.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter7.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'spriter8.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'jump.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'start.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'bowl.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'bowr.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'hurt.png')).convert_alpha(),
pygame.image.load(os.path.join(os.curdir, 'dead.png')).convert_alpha()
]
self.rect = self.images[self.image].get_rect()
self.rect = self.rect.move(300,600)
self.vel = 0
self.x = 300
self.y = 600
self.dir = 1 # 1: Right -1: Left
self.vector = Vector(self.x,self.y)
self.Arrows = 20
self.ArrowsMax = 20
self.ArrowsRepl = 0.0
self.ArrowsReplRate = 0.1
self.Gravity = 100
self.GravityRepl = 0.0
self.RapidFire = False
self.MultiShot = False
self.MultiShot2 = False
self.Lives = 5
self.Repel = 8
self.DecoyNum = 5
self.DecoyCounter = 0
self.DecoyX = 0
self.DecoyY = 0
def updateVector(self,x,y):
diffX = x - self.x
diffY = y - self.y
if diffX != 0 and diffY!= 0:
newX = diffX / (sqrt((diffX*diffX)+(diffY*diffY)))
newY = diffY / (sqrt((diffX*diffX)+(diffY*diffY)))
else:
newX = 0
newY = 0
temp = Vector(newX,newY)
self.vector.add(temp)
if self.vector.x != 0 and self.vector.y != 0:
self.vector.x = self.vector.x / (sqrt((self.vector.x*self.vector.x)+(self.vector.y*self.vector.y)))
self.vector.y = self.vector.y / (sqrt((self.vector.x*self.vector.x)+(self.vector.y*self.vector.y)))
def updatePlayerPos(self,x,y):
#self.image = (self.image + 1) % 8
x = int(x)
y = int(y)
#if(x == 0):
# if(self.image != 19 and self.image != 18):
# self.updatePlayerSprite(17, 1)
if(self.gunmode):
self.images[18] = pygame.image.load(os.path.join(os.curdir, 'gunl.png')).convert_alpha()
self.images[19] = pygame.image.load(os.path.join(os.curdir, 'gunr.png')).convert_alpha()
if self.x + x < 1252 and self.x + x > -5:
self.x += x
self.rect = self.rect.move(x,0)
if self.y + y < 600 and self.y + y > 0:
self.y += y
self.rect = self.rect.move(0,y)
self.updatePlayerSprite(16,1)
if self.y + y > 600:
self.rect = self.rect.move(0,600-self.y)
#self.updatePlayerSprite(17,1)
self.y = 600
if(x < 0):
self.updatePlayerSprite(0, 8)
if(x > 0):
self.updatePlayerSprite(8,8)
def updatePlayerSprite(self, framestart, totalframes):
self.framenumber += 0.33
if(self.framenumber > framestart + totalframes or self.framenumber < framestart):
self.framenumber = framestart
self.image = (int(self.framenumber)) % totalframes + framestart
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)
def jet(self):
if self.vel <= 0:
self.vel = 3
else:
self.vel *= 1.1
if self.vel > 10:
self.vel = 10
self.updatePlayerPos(0,-self.vel)
def fall(self):
self.vel -= 1
self.updatePlayerPos(0,-self.vel)
def Decoy(self,x,y):
self.DecoyX = x
self.DecoyY = y
self.DecoyCounter = 1000