def update(self, entity): #self.timer+=1 #if self.timePassed >= 100: self.ang += 2 * math.pi / 100 if self.ang >= round(2 * math.pi): return False entity.x += math.cos(self.ang) * self.radius entity.y += math.sin(self.ang) * self.radius return True
def drawSelf(self, surface, coords=[0, 0], width=16, color=(50, 50, 50)): # Detects if there is any change in variable. if so, then change the internal variable, so that it's not done every frame. for node in self.connectedNodes: if self.connectedNodes[node][4] != width or self.connectedNodes[node][5] != color: self.changeColorWidth(node, color, width) for connectedNodes in list(self.connectedNodes.values()): # connectedNodes is the values inside the actual connectedNodes addition = ( -math.cos(connectedNodes[1] * math.pi/180) * 16 , math.sin(connectedNodes[1] * math.pi/180) * 16 ) newCoords = [ a + b + c + d if b < 0 else a + c for a, b, c, d in zip(self.coords, connectedNodes[0], coords, addition) ] surface.blit(connectedNodes[3], newCoords ) # Draw arrow that signifies in which direction the car in the road is going to go. GMfun.drawArrow(surface, [ a + b + 8 + ( c / 2 ) for a, b, c in zip(coords, self.coords, connectedNodes[0]) ], 10, 60, 360 - connectedNodes[1], (120, 120, 120), 3)
def updateMovement(self): self.prevRadius = self.radius self.radialVelocity += Physics.G self.angularVelocity = -ORBITING_OBJECT_SPEED if (self.radialVelocity < PLAYER_MIN_SPEED): self.radialVelocity = PLAYER_MIN_SPEED self.radius += self.radialVelocity self.radius = planetRadius + 200 self.angle += self.angularVelocity * planetRadius / self.radius # print("angle ", self.angle) self.position.x = planetCenter.x + self.radius * math.sin(self.angle) self.position.y = planetCenter.y + self.radius * -math.cos(self.angle)
def updateMovement(self, step): angle = self.angle self.prevAngle = angle # print("prevAngle ", math.degrees(self.prevAngle)) position = self.position self.prevPosition = position # print("PREV position = ", self.prevPosition) dx = self.position.x - planetCenter.x dy = self.position.y - planetCenter.y r = math.sqrt(dx ** 2 + dy ** 2) g = Physics.G * self.mass * planetMass / r ** 2 self.radialVelocity += g if (self.radialVelocity < PLAYER_MIN_SPEED): self.radialVelocity = PLAYER_MIN_SPEED self.radius += self.radialVelocity # print("radius ", self.radius) bottom = self.radius - self.halfHeight self.onGround = False if (bottom <= planetRadius): self.onGround = True self.radius = planetRadius + self.halfHeight self.radialVelocity = 0 if self.onGround == True and self.direction == 'none': self.angularVelocity = 0 self.angle += self.angularVelocity * planetRadius / self.radius # print("angle ", self.angle) # print("angle ", math.degrees(self.angle)) if (math.degrees(self.angle) >= 360.0): self.angle = 0.0 # self.position.x = planetCenter.x + self.radius * math.sin(self.angle) # self.position.y = planetCenter.y + self.radius * -math.cos(self.angle) newPosition = Vector2() newPosition.x = planetCenter.x + self.radius * math.sin(self.angle) newPosition.y = planetCenter.y + self.radius * -math.cos(self.angle) positionChange = newPosition - position # print("positionChange = ", positionChange) self.position.x += positionChange.x * step self.position.y += positionChange.y * step
def __init__(self): super().__init__() self.image = pygame.image.load('character.png').convert_alpha() # okreslenie wielkosci i masy bohatera self.width = 25 self.halfWidth = self.width / 2 self.height = 25 self.halfHeight = self.height / 2 self.size = (self.width, self.height) self.image = pygame.transform.scale(self.image, self.size) self.rect = self.image.get_rect() self.mass = Physics.characterMass self.angle = 0 self.prevAngle = 0 self.angularVelocity = 0 self.radius = planetRadius + self.halfHeight self.radialVelocity = 0 self.onGround = False self.direction = 'right' # okreslenie pozycji bohatera self.position = Vector2() self.position.x = planetCenter.x + self.radius * math.sin(self.angle) self.position.y = planetCenter.y - 20 + self.radius * -math.cos(self.angle) self.prevPosition = Vector2() self.nextPosition = Vector2() self.acceleration = Vector2(0, 0) # okreslenie predkosci poruszania sie bohatera self.velocity = Vector2(0, 0) self.nextVelocity = Vector2() # zmienna opisujaca czy gracz chce wykonac skok self.isGoingToJump = False