Migration to Codeberg
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import pygame
|
||||
from os import walk
|
||||
from random import choice
|
||||
|
||||
class Car(pygame.sprite.Sprite):
|
||||
def __init__(self, pos, groups):
|
||||
super().__init__(groups)
|
||||
|
||||
self.name = 'car'
|
||||
|
||||
# image
|
||||
for _, _, img_list in walk('../graphics/cars'):
|
||||
car_name = choice(img_list)
|
||||
self.image = pygame.image.load('../graphics/cars/'+car_name).convert_alpha()
|
||||
self.rect = self.image.get_rect(center = pos)
|
||||
|
||||
# float based movement
|
||||
self.pos = pygame.math.Vector2(self.rect.center)
|
||||
|
||||
if pos[0] < 200:
|
||||
self.direction = pygame.math.Vector2(1,0)
|
||||
|
||||
else:
|
||||
self.direction = pygame.math.Vector2(-1,0)
|
||||
self.image = pygame.transform.flip(self.image, True, False)
|
||||
|
||||
self.speed = 300
|
||||
self.hitbox = self.rect.inflate(0, -self.rect.height / 2)
|
||||
|
||||
|
||||
def update(self, dt):
|
||||
self.pos += self.direction * self.speed * dt
|
||||
self.hitbox.center = (round(self.pos.x),round(self.pos.y))
|
||||
self.rect.center = self.hitbox.center
|
||||
|
||||
if not -200 < self.rect.x < 3400:
|
||||
self.kill()
|
||||
@@ -0,0 +1,280 @@
|
||||
{
|
||||
"auto_complete":
|
||||
{
|
||||
"selected_items":
|
||||
[
|
||||
[
|
||||
"s",
|
||||
"ship_rect"
|
||||
],
|
||||
[
|
||||
"te",
|
||||
"text_rect"
|
||||
],
|
||||
[
|
||||
"shi",
|
||||
"ship_rect"
|
||||
],
|
||||
[
|
||||
"sh",
|
||||
"ship_y_pos"
|
||||
],
|
||||
[
|
||||
"ship",
|
||||
"ship_y_pos"
|
||||
],
|
||||
[
|
||||
"w",
|
||||
"WINDOW_WIDTH"
|
||||
],
|
||||
[
|
||||
"dis",
|
||||
"display_surface"
|
||||
],
|
||||
[
|
||||
"sco",
|
||||
"scorpion_health"
|
||||
],
|
||||
[
|
||||
"so",
|
||||
"sorted_comp_num"
|
||||
],
|
||||
[
|
||||
"sorte",
|
||||
"sorted_comp_name"
|
||||
]
|
||||
]
|
||||
},
|
||||
"buffers":
|
||||
[
|
||||
],
|
||||
"build_system": "",
|
||||
"build_system_choices":
|
||||
[
|
||||
[
|
||||
[
|
||||
[
|
||||
"Packages/Python/Python.sublime-build",
|
||||
""
|
||||
],
|
||||
[
|
||||
"Packages/Python/Python.sublime-build",
|
||||
"Syntax Check"
|
||||
]
|
||||
],
|
||||
[
|
||||
"Packages/Python/Python.sublime-build",
|
||||
"Syntax Check"
|
||||
]
|
||||
]
|
||||
],
|
||||
"build_varint": "",
|
||||
"command_palette":
|
||||
{
|
||||
"height": 0.0,
|
||||
"last_filter": "",
|
||||
"selected_items":
|
||||
[
|
||||
[
|
||||
"git",
|
||||
"Git: Init"
|
||||
],
|
||||
[
|
||||
"install",
|
||||
"Package Control: Install Package"
|
||||
],
|
||||
[
|
||||
"python",
|
||||
"Build With: Python"
|
||||
],
|
||||
[
|
||||
"mar",
|
||||
"Markdown Preview: Save to HTML"
|
||||
],
|
||||
[
|
||||
"mark",
|
||||
"Markdown Preview: Save to HTML"
|
||||
],
|
||||
[
|
||||
"markd",
|
||||
"Markdown Preview: Save to HTML"
|
||||
],
|
||||
[
|
||||
"markdown",
|
||||
"Markdown Preview: Save to HTML"
|
||||
],
|
||||
[
|
||||
"Markdown",
|
||||
"Markdown Preview: Preview in Browser"
|
||||
],
|
||||
[
|
||||
"markdwon extende",
|
||||
"Set Syntax: Markdown Extended"
|
||||
],
|
||||
[
|
||||
"package",
|
||||
"Package Control: List Packages"
|
||||
],
|
||||
[
|
||||
"insta",
|
||||
"Package Control: Install Package"
|
||||
],
|
||||
[
|
||||
"markdownpre",
|
||||
"Markdown Preview: Preview in Browser"
|
||||
]
|
||||
],
|
||||
"width": 0.0
|
||||
},
|
||||
"console":
|
||||
{
|
||||
"height": 0.0,
|
||||
"history":
|
||||
[
|
||||
]
|
||||
},
|
||||
"distraction_free":
|
||||
{
|
||||
"menu_visible": true,
|
||||
"show_minimap": false,
|
||||
"show_open_files": false,
|
||||
"show_tabs": false,
|
||||
"side_bar_visible": false,
|
||||
"status_bar_visible": false
|
||||
},
|
||||
"file_history":
|
||||
[
|
||||
"/Users/huaqo/PycharmProjects/Frogger/code/main.py",
|
||||
"/Users/huaqo/Desktop/website.html",
|
||||
"/Users/huaqo/Desktop/Praktikumsbericht",
|
||||
"/Users/huaqo/Library/Mobile Documents/com~apple~CloudDocs/Desktop/preamble.tex",
|
||||
"/Users/huaqo/Library/Mobile Documents/com~apple~CloudDocs/Home/Hobbys/Programmieren/Python/Learn Python by making games/5. Data Handling/test.txt",
|
||||
"/Users/huaqo/Desktop/paper.html"
|
||||
],
|
||||
"find":
|
||||
{
|
||||
"height": 41.0
|
||||
},
|
||||
"find_in_files":
|
||||
{
|
||||
"height": 0.0,
|
||||
"where_history":
|
||||
[
|
||||
]
|
||||
},
|
||||
"find_state":
|
||||
{
|
||||
"case_sensitive": false,
|
||||
"find_history":
|
||||
[
|
||||
],
|
||||
"highlight": true,
|
||||
"in_selection": false,
|
||||
"preserve_case": false,
|
||||
"regex": false,
|
||||
"replace_history":
|
||||
[
|
||||
],
|
||||
"reverse": false,
|
||||
"scrollbar_highlights": true,
|
||||
"show_context": true,
|
||||
"use_buffer2": true,
|
||||
"use_gitignore": true,
|
||||
"whole_word": false,
|
||||
"wrap": true
|
||||
},
|
||||
"groups":
|
||||
[
|
||||
{
|
||||
"sheets":
|
||||
[
|
||||
]
|
||||
}
|
||||
],
|
||||
"incremental_find":
|
||||
{
|
||||
"height": 29.0
|
||||
},
|
||||
"input":
|
||||
{
|
||||
"height": 33.0
|
||||
},
|
||||
"layout":
|
||||
{
|
||||
"cells":
|
||||
[
|
||||
[
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
]
|
||||
],
|
||||
"cols":
|
||||
[
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"rows":
|
||||
[
|
||||
0.0,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
"menu_visible": true,
|
||||
"output.exec":
|
||||
{
|
||||
"height": 243.0
|
||||
},
|
||||
"output.find_results":
|
||||
{
|
||||
"height": 0.0
|
||||
},
|
||||
"pinned_build_system": "",
|
||||
"project": "frogger.sublime-project",
|
||||
"replace":
|
||||
{
|
||||
"height": 54.0
|
||||
},
|
||||
"save_all_on_build": true,
|
||||
"select_file":
|
||||
{
|
||||
"height": 0.0,
|
||||
"last_filter": "",
|
||||
"selected_items":
|
||||
[
|
||||
],
|
||||
"width": 0.0
|
||||
},
|
||||
"select_project":
|
||||
{
|
||||
"height": 0.0,
|
||||
"last_filter": "",
|
||||
"selected_items":
|
||||
[
|
||||
],
|
||||
"width": 0.0
|
||||
},
|
||||
"select_symbol":
|
||||
{
|
||||
"height": 0.0,
|
||||
"last_filter": "",
|
||||
"selected_items":
|
||||
[
|
||||
],
|
||||
"width": 0.0
|
||||
},
|
||||
"selected_group": 0,
|
||||
"settings":
|
||||
{
|
||||
},
|
||||
"show_minimap": false,
|
||||
"show_open_files": true,
|
||||
"show_tabs": true,
|
||||
"side_bar_visible": true,
|
||||
"side_bar_width": 150.0,
|
||||
"status_bar_visible": false,
|
||||
"template_settings":
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import pygame, sys
|
||||
from settings import *
|
||||
from player import Player
|
||||
from car import Car
|
||||
from random import choice, randint
|
||||
from sprite import SimpleSprite, LongSprite
|
||||
|
||||
class AllSprites(pygame.sprite.Group):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.offset = pygame.math.Vector2()
|
||||
self.bg = pygame.image.load('../graphics/main/map.png').convert()
|
||||
self.fg = pygame.image.load('../graphics/main/overlay.png').convert_alpha()
|
||||
|
||||
def customize_draw(self):
|
||||
|
||||
self.offset.x = player.rect.centerx - WINDOW_WIDTH / 2
|
||||
self.offset.y = player.rect.centery - WINDOW_HEIGHT / 2
|
||||
|
||||
display_surface.blit(self.bg,-self.offset)
|
||||
|
||||
for sprite in sorted(self.sprites(), key = lambda sprite: sprite.rect.centery):
|
||||
offset_pos = sprite.rect.topleft - self.offset
|
||||
display_surface.blit(sprite.image, offset_pos)
|
||||
|
||||
display_surface.blit(self.fg,-self.offset)
|
||||
|
||||
|
||||
# basic setup
|
||||
pygame.init()
|
||||
display_surface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
|
||||
pygame.display.set_caption('Frogger')
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
# groups
|
||||
all_sprites = AllSprites()
|
||||
obstacle_sprites = pygame.sprite.Group()
|
||||
|
||||
# sprites
|
||||
player = Player((2062,3274),all_sprites,obstacle_sprites)
|
||||
|
||||
# car timer
|
||||
car_timer = pygame.event.custom_type()
|
||||
pygame.time.set_timer(car_timer,50)
|
||||
pos_list = []
|
||||
|
||||
# font
|
||||
score_text = 'Du hast es geschaft, super!'
|
||||
font = pygame.font.Font(None,50)
|
||||
text_surf = font.render(score_text, True, 'White')
|
||||
text_rect = text_surf.get_rect(center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2))
|
||||
|
||||
# sprite setup
|
||||
for file_name,pos_list in SIMPLE_OBJECTS.items():
|
||||
surf = pygame.image.load(f'../graphics/objects/simple/{file_name}.png').convert_alpha()
|
||||
for pos in pos_list:
|
||||
SimpleSprite(surf, pos, [all_sprites,obstacle_sprites])
|
||||
|
||||
for file_name,pos_list in LONG_OBJECTS.items():
|
||||
surf = pygame.image.load(f'../graphics/objects/long/{file_name}.png').convert_alpha()
|
||||
for pos in pos_list:
|
||||
LongSprite(surf, pos, [all_sprites,obstacle_sprites])
|
||||
|
||||
# game loop
|
||||
while True:
|
||||
|
||||
# event loop
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
if event.type == car_timer:
|
||||
random_pos = choice(CAR_START_POSITIONS)
|
||||
if random_pos not in pos_list:
|
||||
pos_list.append(random_pos)
|
||||
pos = (random_pos[0],random_pos[1] + randint(-8,8))
|
||||
Car(pos,[all_sprites,obstacle_sprites])
|
||||
if len(pos_list) >5:
|
||||
del pos_list[0]
|
||||
|
||||
# delta time
|
||||
dt = clock.tick() / 1000
|
||||
|
||||
|
||||
if player.pos.y >= 1180:
|
||||
# update
|
||||
all_sprites.update(dt)
|
||||
|
||||
# draw
|
||||
all_sprites.customize_draw()
|
||||
else:
|
||||
display_surface.fill('teal')
|
||||
display_surface.blit(text_surf,text_rect)
|
||||
|
||||
# update the display surface -> drawing the frame
|
||||
pygame.display.update()
|
||||
@@ -0,0 +1,259 @@
|
||||
{
|
||||
"auto_complete":
|
||||
{
|
||||
"selected_items":
|
||||
[
|
||||
[
|
||||
"s",
|
||||
"ship_rect"
|
||||
],
|
||||
[
|
||||
"te",
|
||||
"text_rect"
|
||||
],
|
||||
[
|
||||
"shi",
|
||||
"ship_rect"
|
||||
],
|
||||
[
|
||||
"sh",
|
||||
"ship_y_pos"
|
||||
],
|
||||
[
|
||||
"ship",
|
||||
"ship_y_pos"
|
||||
],
|
||||
[
|
||||
"w",
|
||||
"WINDOW_WIDTH"
|
||||
],
|
||||
[
|
||||
"dis",
|
||||
"display_surface"
|
||||
],
|
||||
[
|
||||
"sco",
|
||||
"scorpion_health"
|
||||
],
|
||||
[
|
||||
"so",
|
||||
"sorted_comp_num"
|
||||
],
|
||||
[
|
||||
"sorte",
|
||||
"sorted_comp_name"
|
||||
]
|
||||
]
|
||||
},
|
||||
"buffers":
|
||||
[
|
||||
],
|
||||
"build_system": "",
|
||||
"build_system_choices":
|
||||
[
|
||||
],
|
||||
"build_varint": "",
|
||||
"command_palette":
|
||||
{
|
||||
"height": 0.0,
|
||||
"last_filter": "",
|
||||
"selected_items":
|
||||
[
|
||||
[
|
||||
"git",
|
||||
"Git: Init"
|
||||
],
|
||||
[
|
||||
"install",
|
||||
"Package Control: Install Package"
|
||||
],
|
||||
[
|
||||
"python",
|
||||
"Build With: Python"
|
||||
],
|
||||
[
|
||||
"mar",
|
||||
"Markdown Preview: Save to HTML"
|
||||
],
|
||||
[
|
||||
"mark",
|
||||
"Markdown Preview: Save to HTML"
|
||||
],
|
||||
[
|
||||
"markd",
|
||||
"Markdown Preview: Save to HTML"
|
||||
],
|
||||
[
|
||||
"markdown",
|
||||
"Markdown Preview: Save to HTML"
|
||||
],
|
||||
[
|
||||
"Markdown",
|
||||
"Markdown Preview: Preview in Browser"
|
||||
],
|
||||
[
|
||||
"markdwon extende",
|
||||
"Set Syntax: Markdown Extended"
|
||||
],
|
||||
[
|
||||
"package",
|
||||
"Package Control: List Packages"
|
||||
],
|
||||
[
|
||||
"insta",
|
||||
"Package Control: Install Package"
|
||||
],
|
||||
[
|
||||
"markdownpre",
|
||||
"Markdown Preview: Preview in Browser"
|
||||
]
|
||||
],
|
||||
"width": 0.0
|
||||
},
|
||||
"console":
|
||||
{
|
||||
"height": 0.0,
|
||||
"history":
|
||||
[
|
||||
]
|
||||
},
|
||||
"distraction_free":
|
||||
{
|
||||
"menu_visible": true,
|
||||
"show_minimap": false,
|
||||
"show_open_files": false,
|
||||
"show_tabs": false,
|
||||
"side_bar_visible": false,
|
||||
"status_bar_visible": false
|
||||
},
|
||||
"file_history":
|
||||
[
|
||||
"/Users/huaqo/Desktop/website.html",
|
||||
"/Users/huaqo/Desktop/Praktikumsbericht",
|
||||
"/Users/huaqo/Library/Mobile Documents/com~apple~CloudDocs/Desktop/preamble.tex",
|
||||
"/Users/huaqo/Library/Mobile Documents/com~apple~CloudDocs/Home/Hobbys/Programmieren/Python/Learn Python by making games/5. Data Handling/test.txt",
|
||||
"/Users/huaqo/Desktop/paper.html"
|
||||
],
|
||||
"find":
|
||||
{
|
||||
"height": 41.0
|
||||
},
|
||||
"find_in_files":
|
||||
{
|
||||
"height": 0.0,
|
||||
"where_history":
|
||||
[
|
||||
]
|
||||
},
|
||||
"find_state":
|
||||
{
|
||||
"case_sensitive": false,
|
||||
"find_history":
|
||||
[
|
||||
],
|
||||
"highlight": true,
|
||||
"in_selection": false,
|
||||
"preserve_case": false,
|
||||
"regex": false,
|
||||
"replace_history":
|
||||
[
|
||||
],
|
||||
"reverse": false,
|
||||
"scrollbar_highlights": true,
|
||||
"show_context": true,
|
||||
"use_buffer2": true,
|
||||
"use_gitignore": true,
|
||||
"whole_word": false,
|
||||
"wrap": true
|
||||
},
|
||||
"groups":
|
||||
[
|
||||
{
|
||||
"sheets":
|
||||
[
|
||||
]
|
||||
}
|
||||
],
|
||||
"incremental_find":
|
||||
{
|
||||
"height": 29.0
|
||||
},
|
||||
"input":
|
||||
{
|
||||
"height": 33.0
|
||||
},
|
||||
"layout":
|
||||
{
|
||||
"cells":
|
||||
[
|
||||
[
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
]
|
||||
],
|
||||
"cols":
|
||||
[
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"rows":
|
||||
[
|
||||
0.0,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
"menu_visible": true,
|
||||
"output.find_results":
|
||||
{
|
||||
"height": 0.0
|
||||
},
|
||||
"pinned_build_system": "",
|
||||
"project": "main.sublime-project",
|
||||
"replace":
|
||||
{
|
||||
"height": 54.0
|
||||
},
|
||||
"save_all_on_build": true,
|
||||
"select_file":
|
||||
{
|
||||
"height": 0.0,
|
||||
"last_filter": "",
|
||||
"selected_items":
|
||||
[
|
||||
],
|
||||
"width": 0.0
|
||||
},
|
||||
"select_project":
|
||||
{
|
||||
"height": 0.0,
|
||||
"last_filter": "",
|
||||
"selected_items":
|
||||
[
|
||||
],
|
||||
"width": 0.0
|
||||
},
|
||||
"select_symbol":
|
||||
{
|
||||
"height": 0.0,
|
||||
"last_filter": "",
|
||||
"selected_items":
|
||||
[
|
||||
],
|
||||
"width": 0.0
|
||||
},
|
||||
"selected_group": 0,
|
||||
"settings":
|
||||
{
|
||||
},
|
||||
"show_minimap": false,
|
||||
"show_open_files": true,
|
||||
"show_tabs": true,
|
||||
"side_bar_visible": true,
|
||||
"side_bar_width": 150.0,
|
||||
"status_bar_visible": false,
|
||||
"template_settings":
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
import pygame, sys
|
||||
from os import walk
|
||||
|
||||
class Player(pygame.sprite.Sprite):
|
||||
def __init__(self, pos, groups, collision_sprites):
|
||||
super().__init__(groups)
|
||||
|
||||
# image
|
||||
self.import_assets()
|
||||
self.frame_index = 0
|
||||
self.status = 'up'
|
||||
# self.image = self.animation[self.frame_index]
|
||||
self.image = self.animations[self.status][self.frame_index]
|
||||
self.rect = self.image.get_rect(center = pos)
|
||||
|
||||
# float based movement
|
||||
self.pos = pygame.math.Vector2(self.rect.center)
|
||||
self.direction = pygame.math.Vector2()
|
||||
self.speed = 200
|
||||
|
||||
# collisions
|
||||
self.collision_sprites = collision_sprites
|
||||
self.hitbox = self.rect.inflate(0, -self.rect.height / 2)
|
||||
|
||||
def collision(self,direction):
|
||||
|
||||
if direction == 'horizontal':
|
||||
for sprite in self.collision_sprites.sprites():
|
||||
if sprite.hitbox.colliderect(self.hitbox):
|
||||
if hasattr(sprite,'name') and sprite.name == 'car':
|
||||
pygame.quit
|
||||
sys.exit
|
||||
|
||||
if self.direction.x > 0: #moving right
|
||||
self.hitbox.right = sprite.hitbox.left
|
||||
self.rect.centerx = self.hitbox.centerx
|
||||
self.pos.x = self.hitbox.centerx
|
||||
if self.direction.x < 0: #moving right
|
||||
self.hitbox.left = sprite.hitbox.right
|
||||
self.rect.centerx = self.hitbox.centerx
|
||||
self.pos.x = self.hitbox.centerx
|
||||
|
||||
else:
|
||||
for sprite in self.collision_sprites.sprites():
|
||||
if sprite.hitbox.colliderect(self.hitbox):
|
||||
if hasattr(sprite,'name') and sprite.name == 'car':
|
||||
pygame.quit
|
||||
sys.exit
|
||||
|
||||
if self.direction.y > 0: # moving down
|
||||
self.hitbox.bottom = sprite.hitbox.top
|
||||
self.rect.centery = self.hitbox.centery
|
||||
self.pos.y = self.hitbox.centery
|
||||
if self.direction.y < 0: # moving up
|
||||
self.hitbox.top = sprite.hitbox.bottom
|
||||
self.rect.centery = self.hitbox.centery
|
||||
self.pos.y = self.hitbox.centery
|
||||
|
||||
def import_assets(self):
|
||||
self.animations = {}
|
||||
for index, folder in enumerate(walk('../graphics/player')):
|
||||
if index == 0:
|
||||
for name in folder[1]:
|
||||
self.animations[name] = []
|
||||
else:
|
||||
for file_name in sorted(folder[2]):
|
||||
path = folder[0].replace('\\', '/') + '/' + file_name
|
||||
surf = pygame.image.load(path).convert_alpha()
|
||||
key = folder[0].replace('\\', '/').split('/')[-1]
|
||||
self.animations[key].append(surf)
|
||||
|
||||
def move(self,dt):
|
||||
|
||||
# normalize a vector -> the length of a vector is going to be 1
|
||||
if self.direction.magnitude() != 0:
|
||||
self.direction = self.direction.normalize()
|
||||
|
||||
# vertical movement + collision
|
||||
self.pos.y += self.direction.y * self.speed * dt
|
||||
self.hitbox.centery = round(self.pos.y)
|
||||
self.rect.centery = self.hitbox.centery
|
||||
self.collision('vertical')
|
||||
|
||||
# horizontal movement + collision
|
||||
self.pos.x += self.direction.x * self.speed * dt
|
||||
self.hitbox.centerx = round(self.pos.x)
|
||||
self.rect.centerx = self.hitbox.centerx
|
||||
self.collision('horizontal')
|
||||
|
||||
def input(self):
|
||||
keys = pygame.key.get_pressed()
|
||||
|
||||
# horizontal input
|
||||
if keys[pygame.K_RIGHT]:
|
||||
self.direction.x = 1
|
||||
self.status = 'right'
|
||||
elif keys[pygame.K_LEFT]:
|
||||
self.direction.x = -1
|
||||
self.status = 'left'
|
||||
else:
|
||||
self.direction.x = 0
|
||||
|
||||
# vertical input
|
||||
if keys[pygame.K_UP]:
|
||||
self.direction.y = -1
|
||||
self.status = 'up'
|
||||
elif keys[pygame.K_DOWN]:
|
||||
self.direction.y = 1
|
||||
self.status = 'down'
|
||||
else:
|
||||
self.direction.y = 0
|
||||
|
||||
def animate(self,dt):
|
||||
current_animation = self.animations[self.status]
|
||||
|
||||
if self.direction.magnitude() != 0:
|
||||
self.frame_index += 10 * dt
|
||||
if self.frame_index >= len(current_animation):
|
||||
self.frame_index = 0
|
||||
else:
|
||||
self.frame_index = 0
|
||||
self.image = current_animation[int(self.frame_index)]
|
||||
|
||||
def restrict(self):
|
||||
if self.rect.left < 640:
|
||||
self.pos.x = 640 + self.rect.width / 2
|
||||
self.hitbox.left = 640
|
||||
self.rect.left = 640
|
||||
|
||||
if self.rect.right > 2560:
|
||||
self.pos.x = 2560 - self.rect.width / 2
|
||||
self.hitbox.right = 2560
|
||||
self.rect.right = 2560
|
||||
|
||||
if self.rect.bottom > 3500:
|
||||
self.pos.y = 3500 - self.rect.height / 2
|
||||
self.rect.bottom = 3500
|
||||
self.hitbox.centery = self.rect.centery
|
||||
|
||||
def update(self,dt):
|
||||
self.input()
|
||||
self.move(dt)
|
||||
self.animate(dt)
|
||||
self.restrict()
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
WINDOW_WIDTH, WINDOW_HEIGHT = 1280,720
|
||||
|
||||
CAR_START_POSITIONS = [(-100, 1312), (-100, 1632), (-100,1888),
|
||||
(-100, 2471), (-100,2853), (-100, 3080), (3300, 1400),
|
||||
(3300,1760), (3300, 1970), (3300, 2550), (3300, 2981)]
|
||||
|
||||
SIMPLE_OBJECTS = {
|
||||
'green': [(969.0,3104.17),(986.833,3164.67),(1327.33,3288.67),(1114.67,3084.0),(1468.67,3165.33),(1589.33,3305.33),(1456.67,3298.67),(1659.0,3112.0),
|
||||
(2358.67,3254.67),(2437.33,3315.33),(2470.0,3107.33),(2154.67,3275.33),(1729.33,3210.0),(1747.33,3288.67),(1188.0,3186.67),(1019.67,3262.67),
|
||||
(1552.67,3324.0),(1814.0,3351.33),(2402.0,3366.67),(1047.0,3304.0),(980.5,3327.0),(1050.0,3365.5),(2278.0,2624.0),(2346.0,2560.0),
|
||||
(2209.0,2594.0),(2229.0,2665.0),(834.667,2149.33),(928.0,2209.33),(2473.33,2121.33),(2449.33,2232.67),(877.333,766.667),
|
||||
(648.0,941.3299999999999),(681.333,897.33), (1346.00,1070.00), (1794.00,1070.00)],
|
||||
'green_bush': [(1626.5,3235.67),(1482.67,3264.0),(1520.0,3304.0),(1407.33,3390.67),(1084.67,3172.67),(1003.83,3145.83),(1010.67,3261.0),
|
||||
(1385.0,2627.0),(865.0,2675.0),(941.0,2614.0),(1086.0,2693.0),(1275.0,2723.0),(1407.0,2716.0),(1166.0,2618.0),
|
||||
(826.0,2720.0),(1066.0,2714.0),(1220.0,2726.0),(1244.0,2709.0),(652.0,2198.67),(916.0,2190.67),(2274.0,2218.0),
|
||||
(2280.0,2246.0),(2382.0,2286.0),(2364.0,2213.33),(2413.33,1134.67),(2165.33,1126.67),(2065.33,985.3299999999999),
|
||||
(2361.33,956.0)],
|
||||
'green_mini': [(1140.67,3175.33),(1338.0,3130.67),(1368.67,3236.67),(1108.0,3278.67),(1173.33,3338.0),(1226.0,3216.67),(1272.0,3178.67),
|
||||
(1268.66,3270.0),(2348.67,3417.33),(2456.67,3204.67),(2323.33,3162.0),(2091.33,3372.67),(1776.67,3165.33),(1938.67,3157.33),
|
||||
(1846.0,3279.33),(1081.0,3383.5),(1010.0,2665.0),(1163.0,2690.0),(1344.0,2651.0),(2204.0,2695.0),(2262.0,2729.0),(664.0,2288.0),
|
||||
(858.667,2230.67)],
|
||||
'green_small_potted': [(1504.00, 936.00), (1740.00,936.0)],
|
||||
'barrel_1': [(642.5,3138.0),(663.0,3164.0),(2560.67,2174.0),(2566.0,2116.0),(2616.67,2072.0),(2616.67,2118.0),(2683.33,2160.0),
|
||||
(2677.33,2116.0),(2680.0,2038.0),(664.0,2718.0),(2572.0,1466.0),(678.0,3319.83),(700.667,3334.5)],
|
||||
'barrel_2': [(2579.33,2147.33),(2568.0,2050.0),(2635.33,2150.0),(2607.33,2046.0),(2600.0,2088.0), (2566.00,1576.00), (2546.00,1538.00)],
|
||||
'barrel_3': [(2560.0,2080.0),(2696.0,2106.0),(2657.33,2058.0),(860.667,2289.0)],
|
||||
'hydrant': [(919.333,2093.0),(650.0,3245.83)],
|
||||
'bench_down': [(1235.33,3333.33), (2213.0,3157.0)],
|
||||
'bench_left': [(2522.0,3263.33),(2518.67,2233.33)],
|
||||
'letterbox_down': [(1418.67,928.67)],
|
||||
'yellow_up': [(819.00,3224.50)],
|
||||
'red_right': [(740.00,3315.50)],
|
||||
'red_left': [(550.67,1200.00)],
|
||||
'green_down': [(713.00,3236.50), (510.67,1140.67)],
|
||||
'barrier_1': [(647.0,2633.0)],
|
||||
'barrier_4': [(898.0,3147.5),(694.667,2669.67),(661.333,2745.67),(608.0,1528.0),(588.0,1462.0)],
|
||||
'barrier_5': [(2368.06,3471.44)],
|
||||
'box_4': [(716.0,865.333),(866.667,892.0)],
|
||||
'box_7': [(782.667,942.667),(752.0,888.0),(817.333,845.333)],
|
||||
'box_10': [(730.667,951.33), (865.333,952.67), (805.333,900.667)]}
|
||||
|
||||
LONG_OBJECTS = {
|
||||
'light_both': [(2333.5,2669.0),(2112.67,2669.33),(1087.33,2278.67),(2012.67,2035.33)],
|
||||
'light_green': [(2439.33,2116.0), (911.333,2170.67), (2284.67,3089.33)],
|
||||
'light_wooden': [(795.913,2087.96), (1106.0,1430.0), (2046.0,1428.0), (2202.67,2016.0)],
|
||||
'sign_2': [(1882.00,956.00)]}
|
||||
@@ -0,0 +1,17 @@
|
||||
import pygame
|
||||
|
||||
class SimpleSprite(pygame.sprite.Sprite):
|
||||
def __init__(self,surf,pos,groups):
|
||||
super().__init__(groups)
|
||||
self.image = surf
|
||||
self.rect = self.image.get_rect(topleft = pos)
|
||||
|
||||
self.hitbox = self.rect.inflate(0,-self.rect.height / 2)
|
||||
|
||||
class LongSprite(pygame.sprite.Sprite):
|
||||
def __init__(self,surf,pos,groups):
|
||||
super().__init__(groups)
|
||||
self.image = surf
|
||||
self.rect = self.image.get_rect(topleft = pos)
|
||||
self.hitbox = self.rect.inflate(-self.rect.width * 0.8, -self.rect.height / 2)
|
||||
self.hitbox.bottom = self.rect.bottom -10
|
||||
Reference in New Issue
Block a user