Skip to content
Snippets Groups Projects
Commit db0835b4 authored by Choukroun Theo's avatar Choukroun Theo
Browse files

Programmes de draw commentés

parent d46dfcca
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ from src.graphics import animation
from src.menu.config import config
from src.graphics import spritestheme
def set_sprites_theme(skin, theme):
"""imports the right images for the choice of the skin and of the theme"""
spritestheme.images_background = [pygame.image.load(f"src/static/{theme}/{i}.png") for i in range(0, 10)]
......@@ -32,15 +33,15 @@ def set_sprites_theme(skin, theme):
spritestheme.images_skin[key][i] = pygame.transform.scale(
spritestheme.images_skin[key][i], (80, 80))
def draw_lines(player, current_roads, screen, index_animation_coin):
"""draws lines of texture on screen"""
for road_num in range(len(current_roads)):
current_road = current_roads[road_num]
# print(type(current_road))
objects.Line.lilypads_generated = False
if current_road.road_type == "grass":
if current_road.road_type == "grass": # we draw the line with trees, rocks and coins
screen.blit(spritestheme.images_background[0],
(0, - player.y + current_road.y + 350))
for tree_pos in current_road.trees:
......@@ -59,56 +60,62 @@ def draw_lines(player, current_roads, screen, index_animation_coin):
coin_y = -player.y + current_road.y + coins[0][1] + 400
screen.blit(spritestheme.coin_img[index_animation_coin], (coin_x-45, coin_y-45))
if current_road.road_type == "road":
if current_road.road_type == "road": # we draw the line with cars
if road_num != 0:
if road_num != len(current_roads)-1:
# if this road is in the middle of other roads
if current_roads[road_num-1].road_type == "road" and current_roads[road_num+1].road_type == "road":
screen.blit(spritestheme.road_mid_img, (0, - player.y +
current_roads[road_num].y + 350))
# if there is only another road under it
elif current_roads[road_num-1].road_type == "road":
screen.blit(spritestheme.road_up_img, (0, - player.y +
current_roads[road_num].y + 350))
# if there is only another road above it
elif current_roads[road_num+1].road_type == "road":
screen.blit(spritestheme.road_down_img, (0, - player.y +
current_roads[road_num].y + 350))
# if the road is alone
else:
screen.blit(spritestheme.road_solo_img, (0, - player.y +
current_roads[road_num].y + 350))
else:
if current_roads[road_num-1].road_type == "road":
if current_roads[road_num-1].road_type == "road": # only roads under
screen.blit(spritestheme.road_up_img, (0, - player.y +
current_roads[road_num].y + 350))
else:
else: # road alone
screen.blit(spritestheme.road_solo_img, (0, - player.y +
current_roads[road_num].y + 350))
else:
if current_roads[road_num+1].road_type == "road":
if current_roads[road_num+1].road_type == "road": # only roads above
screen.blit(spritestheme.road_down_img, (0, - player.y +
current_roads[road_num].y + 350))
else:
else: # road alone
screen.blit(spritestheme.road_solo_img, (0, - player.y +
current_roads[road_num].y + 350))
coins = current_road.coin
if len(coins) > 0:
coin_x = coins[0][0]
coin_y = -player.y + current_road.y + coins[0][1] + 400
screen.blit(spritestheme.coin_img[index_animation_coin], (coin_x-45, coin_y-45))
if current_road.road_type == "water":
if current_road.road_type == "water": # we draw the line and eventually lilypads
# we check if the lilypads positions are correct
if road_num != 0:
generation.verify_lilypads(
current_roads[road_num - 1], current_road)
if road_num != len(current_roads)-1:
generation.verify_lilypads(
current_roads[road_num + 1], current_road)
# screen.blit(images_background[4], (0, - player.y + current_roads[road_num].y + 350))
for lilypad_pos in current_road.lilypads:
lilypad_x = lilypad_pos[0]
lilypad_y = - player.y + \
current_roads[road_num].y + lilypad_pos[1] + 400
screen.blit(spritestheme.lilypad_img, (lilypad_x - 50, lilypad_y - 50))
if current_road.road_type == "rail":
if current_road.road_type == "rail": # we draw the line and coins
screen.blit(spritestheme.images_background[1], (0, - player.y +
current_roads[road_num].y + 350))
coins = current_road.coin
......@@ -119,20 +126,19 @@ def draw_lines(player, current_roads, screen, index_animation_coin):
def draw_moving(player, current_roads, screen):
"""draws every moving object : car, wood, train"""
"""draws every moving object : car, wood and train"""
for road in current_roads:
if road.road_type == "road":
for car in road.list_cars:
# pygame.draw.rect(screen, car.color, [car.x-car.length/2, - player.y + road.y + 350, car.length, 100])
if road.speed < 0:
screen.blit(spritestheme.car_img[car.type], (car.x-car.length/2, - player.y + road.y + 350 - 10)) # Affichage
else:
screen.blit(spritestheme.car_img[car.type], (car.x-car.length/2, - player.y + road.y + 350 - 10))
else: # we must flip the design of the car
screen.blit(pygame.transform.flip(spritestheme.car_img[car.type], True, False),(car.x-car.length/2, - player.y + road.y + 350 - 10))
if road.road_type == "water":
for raft in road.list_cars:
screen.blit(spritestheme.raft_img[raft.length], (raft.x-raft.length/2, - player.y + road.y + 350))
#pygame.draw.rect(screen, (165, 42, 42), [
# wood.x-wood.length/2, - player.y + road.y + 350, wood.length, 100])
if road.road_type == "rail":
for train in road.list_cars:
if road.speed > 0:
......@@ -146,8 +152,9 @@ def draw_moving(player, current_roads, screen):
screen.blit(spritestheme.traffic_red, (600 - 550*road.speed /
abs(road.speed), - player.y + road.y + 350))
def movement_character(moving, move_direction, index_animation, x, y, screen):
"""draws the player when moving, creating an animation"""
"""draws the player, creating an animation if he is moving"""
if moving:
image_actuelle = spritestheme.images_skin[move_direction][index_animation]
else:
......@@ -162,6 +169,7 @@ def animation_water(index_animation, y, screen):
def death_animation(x,y,screen, death_type):
"""The player can get hit by a vehicle or drown in the water"""
if death_type == "road":
screen.blit(spritestheme.blood_img, (x,y))
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment