Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 50 additions & 65 deletions character.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from common_class import Position
from weapons import RPG7


class Team:
def __init__(self, id, nb_viking):
self.id = id
Expand All @@ -11,25 +12,32 @@ def __init__(self, id, nb_viking):


class Viking:
def __init__(self, id, name="", health=100, image_path="", flipped=False):
self.falling = False
def __init__(self, id, name="", health=100, image_path="", flipped=False, speed_x=10):
self.id = id
self.name = name
self.health = health
self.position = Position(0, 0)

self.position = Position(0, 0, speed_x=speed_x)
self.flipped = flipped
self.jumping = False
self.isMoving = False
self.falling = False
self.there_was_ground = False
self.jump_height = 100
self.jump_velocity = 0
self.initialY = 0
self.initial_y = 0

self.gravity = GRAVITY
self.initial_time = 0

self.rpg7 = RPG7(self.position.x - 10, self.position.y - 30)
self.rpg7_visible = False
self.raw_image = pygame.image.load(image_path)
self.image = pygame.transform.scale(self.raw_image, (int(self.raw_image.get_width() * SCALE_VIKING), int(self.raw_image.get_height() * SCALE_VIKING)))

self.original_image = pygame.image.load(image_path)
self.image = pygame.transform.scale(self.original_image,
(int(self.original_image.get_width() * SCALE_VIKING), int(self.original_image.get_height() * SCALE_VIKING)))
self.image = pygame.transform.flip(self.image, True, False) if self.flipped else self.image
self.rect = self.image.get_rect()


def draw(self):
screen.blit(self.image, (self.position.x, self.position.y - self.rect.height))

Expand All @@ -50,15 +58,15 @@ def capXandY(self):
self.position.y = 1
self.health = 0
#
def doMath(self, map): # not meth

def doMath(self, map): # not meth
self.capXandY()
# falling calculations
if map[int(self.position.x + int(self.rect.width/2))][int(self.position.y+1)] == 0 and not self.jumping:
if map[int(self.position.x + int(self.rect.width / 2))][int(self.position.y + 1)] == 0 and not self.jumping:
if not self.falling:
print('start falling')
self.setupFalling(self.position.y)
time = (pygame.time.get_ticks() - self.initialTime) / 1000
self.position.y = int((-0.5 * self.gravity) * (time * time) + (self.position.y * time) + self.initialY)
time = (pygame.time.get_ticks() - self.initial_time) / 1000
self.position.y = int((-0.5 * self.gravity) * (time * time) + (self.position.y * time) + self.initial_y)
#
self.capXandY()
# go above the ground
Expand All @@ -67,88 +75,65 @@ def doMath(self, map): # not meth
#
self.capXandY()
# stop the fall
if map[int(self.position.x + int(self.rect.width / 2))][int(self.position.y + 1)] == 1 and self.falling and not self.jumping:
if map[int(self.position.x + int(self.rect.width / 2))][
int(self.position.y + 1)] == 1 and self.falling and not self.jumping:
self.falling = False
print('stop falling')


def setupFalling(self, initialY):
def setupFalling(self, initial_y):
self.falling = True
self.gravity = GRAVITY
self.initialY = initialY
self.initialTime = pygame.time.get_ticks()

# def shoot(self):
# if self.stock_rocket > 0:
# self.stock_rocket -= 1
# else:
# print(f"{self.name} has no rocket")

# def takeDamage(self, damage):
# self.health -= damage
# if self.health <= 0:
# print(f"{self.name} died")
# else:
# print(f"{self.name} has lost {damage} health")

# def reload(self):
# self.stock_rocket = 5
self.initial_y = initial_y
self.initial_time = pygame.time.get_ticks()

def getFlipped(self, flipped):
self.flipped = flipped
self.image = pygame.transform.flip(self.image, True, False)

def move(self, key, delta_time, timer, bitMap, rocketSelected):
def move(self, key, delta_time, timer, bit_map, rocket_selected):
left_movement = key[pygame.K_q]
right_movement = key[pygame.K_d]
take_rpg = key[pygame.K_UP]

self.isMoving = False
speed_x = self.position.speed_x

if not timer <= 0:
if left_movement:
self.position.x -= speed_x * delta_time
self.isMoving: True
self.position.x -= self.position.speed_x * delta_time
if self.flipped:
self.getFlipped(False)
self.rpg7.getFlipped(False)
if right_movement:
self.position.x += speed_x * delta_time
self.isMoving: True
self.position.x += self.position.speed_x * delta_time
if not self.flipped:
self.getFlipped(True)
self.rpg7.getFlipped(True)

if key[pygame.K_SPACE] and not self.jumping and not self.falling:
self.isMoving: True
print(self.falling)
print('start jumping')
self.setupJump(self.position.y, -50)

if self.jumping:
self.isMoving: True
time = (pygame.time.get_ticks() - self.initialTime)/100
self.position.y = int((-0.5 * self.gravity) * (time * time) + (self.jump_velocity * time) + self.initialY)
if not int(self.position.x + self.image.get_width()/2) >= int(SCREEN_WIDTH/TILE_SIZE)-1 and not int(self.position.x + self.image.get_width()/2) < 0 and not int(self.position.y+2) >= int(SCREEN_HEIGHT/TILE_SIZE)-1 and not bitMap[int(self.position.x + self.image.get_width()/2)][int(self.position.y+2)] == 1:
self.thereWasGround = False


if not self.position.y > int(SCREEN_HEIGHT/TILE_SIZE) and not self.position.y < 0 and not self.thereWasGround:
if bitMap[int(self.position.x + self.image.get_width()/2)][int(self.position.y+2)] == 1:
print('stop jumping')
time = (pygame.time.get_ticks() - self.initial_time) / 100
self.position.y = int((-0.5 * self.gravity) * (time * time) + (self.jump_velocity * time) + self.initial_y)
if not int(self.position.x + self.image.get_width() / 2) >= int(SCREEN_WIDTH / TILE_SIZE) - 1 and not int(
self.position.x + self.image.get_width() / 2) < 0 and not int(self.position.y + 2) >= int(
SCREEN_HEIGHT / TILE_SIZE) - 1 and not bit_map[int(self.position.x + self.image.get_width() / 2)][
int(self.position.y + 2)] == 1:
self.there_was_ground = False

if not self.position.y > int(
SCREEN_HEIGHT / TILE_SIZE) and not self.position.y < 0 and not self.there_was_ground:
if bit_map[int(self.position.x + self.image.get_width() / 2)][int(self.position.y + 2)] == 1:
self.jumping = False

if rocketSelected:
if rocket_selected:
self.draw_RPG7()

def draw_RPG7(self):
LaunchRPG7 = RPG7(self.position.x, self.position.y-40)
LaunchRPG7.draw()
self.rpg7.position.x = self.position.x - 10
self.rpg7.position.y = self.position.y - 30
self.rpg7.draw()

def setupJump(self, initialY, jump_velocity):
self.thereWasGround = True
def setupJump(self, initial_y, jump_velocity):
self.there_was_ground = True
self.jumping = True
self.initialY = initialY
self.initialTime = pygame.time.get_ticks()
self.initial_y = initial_y
self.initial_time = pygame.time.get_ticks()
self.gravity = GRAVITY
self.jump_velocity = jump_velocity

Binary file added images/asset/sky_win.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/asset/title_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading