-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerCharacter.py
75 lines (60 loc) · 2.09 KB
/
ServerCharacter.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
from Ability import *
from ServerGame import *
from InputManager import *
import PacketCommand
import pygame
width = 50.0
height = 50.0
maxHealth = 1
class ServerCharacter:
def __init__(self, uid, pos, name):
# Unique ID associated with character
self.uid = uid
self.pos = pos
self.name = name
self.player = None
self.game = None
self.health = maxHealth
self.vel = [0.0,0.0]
# Velocity delta
self.velDel = [1.5,1.5]
self.velMax = [10,10]
# How much the velocity retains per frame
self.velRed = [0.8,0.8]
self.width = width
self.height = height
self.setRect()
self.mainAbility = Ability(0.5)
self.reallySmallNumber = 0.0001
self.inputManager = InputManager()
def update(self):
self.vel[0] *= self.velRed[0]
self.vel[1] *= self.velRed[1]
if self.inputManager.moveUp:
self.vel[1] -= self.velDel[1]
if self.inputManager.moveLeft:
self.vel[0] -= self.velDel[0]
if self.inputManager.moveDown:
self.vel[1] += self.velDel[1]
if self.inputManager.moveRight:
self.vel[0] += self.velDel[0]
if abs(self.vel[0]) > self.velMax[0]:
if self.vel[0] < 0:
self.vel[0] = -self.velMax[0]
else:
self.vel[0] = self.velMax[0]
if abs(self.vel[1]) > self.velMax[1]:
if self.vel[1] < 0:
self.vel[1] = -self.velMax[1]
else:
self.vel[1] = self.velMax[1]
self.pos[0] += self.vel[0]
self.pos[1] += self.vel[1]
if self.inputManager.mainAbility:
if self.mainAbility.ready():
self.game.spawnProjectile(self, self.inputManager.mousePos)
self.inputManager.clear()
def applyDamage(self, damage):
self.health -= damage
def setRect(self):
self.rect = pygame.Rect(self.pos[0] - self.width / 2.0, self.pos[1] - self.height / 2.0, self.width, self.height)