Skip to content

Commit

Permalink
Abstract map:
Browse files Browse the repository at this point in the history
- Self-madet HTTP server
- Multi-threding pygame execution
  • Loading branch information
TeshariEnjoer committed Aug 9, 2024
1 parent e91be45 commit 6b03836
Show file tree
Hide file tree
Showing 242 changed files with 54,687 additions and 8,672 deletions.
46 changes: 46 additions & 0 deletions laplas/abstract_map/objects/camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pygame

class camera:
def __init__(self, screen, surface, new_x, new_y) -> None:
self.width = 800
self.height = 600
self.dragging = False
self.last_mouse_x = 0
self.last_mouse_y = 0

self.x = new_x
self.y = new_y

self.screen = screen
self.render_surface = surface
self.camera_rect = pygame.Rect(self.x, self.y, self.width, self.height)

print(f"Camera initialized at ({self.x}, {self.y})") # Отладочный вывод

def process(self):
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
self.dragging = True
self.last_mouse_x, self.last_mouse_y = event.pos
print(f"Started dragging at ({self.last_mouse_x}, {self.last_mouse_y})")

if event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
self.dragging = False
print("Stopped dragging")

if event.type == pygame.MOUSEMOTION:
if self.dragging:
mouse_x, mouse_y = event.pos
dx = mouse_x - self.last_mouse_x
dy = mouse_y - self.last_mouse_y
self.x -= dx
self.y -= dy
self.last_mouse_x, self.last_mouse_y = mouse_x, mouse_y

print(f"Dragging to ({self.x}, {self.y})")

self.camera_rect.topleft = (self.x, self.y)
self.screen.blit(self.render_surface, (0, 0), self.camera_rect)
print(f"Camera rect top-left at ({self.camera_rect.x}, {self.camera_rect.y})") # Отладочный вывод
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import pygame
from objects import object
import camera
from objects import camera


camera_width, camera_height = 800, 600

class overmap:
pygame.init()

def __init__(self, size_x: int, size_y: int, visual: bool) -> None:
# A map full size
self.size_x = size_x
Expand All @@ -23,19 +21,22 @@ def __init__(self, size_x: int, size_y: int, visual: bool) -> None:
self.screen = pygame.display.set_mode((camera_width, camera_height))
self.create_map()
self.create_camera()

self.clock = pygame.time.Clock()
pygame.display.set_caption("Large Map with Coordinate System")
self.camera = camera

## Overmap functions

# Actually creates a non physical map, ans setups a cordinates system
def create_map(self):
self.map_holder = pygame.Surface((self.size_x, self.size_y))
self.level_surface.fill((25, 25, 25))
self.map_holder.fill((25, 25, 25))


def create_camera(self):
camera_x, camera_y = 0, 0
self.camera = camera(self.map_holder, self.screen, camera_x, camera_y)
camera_x, camera_y = 1, 1
# self.camera = camera(self.map_holder, self.screen, camera_x, camera_y)

## Function for manipulate with objects
def create_object(self, obj, args):
Expand All @@ -48,9 +49,15 @@ def adjust_speed(self):
pass

def process(self):
self.camera.process()
# self.camera.process(self.camera)
self.clock.tick(60)

if(not self.all_object.__len__()):
return
for obj in self.all_object:
obj.process()


def process_map(state: bool):
while(state):
overmap.process()
1 change: 1 addition & 0 deletions laplas/abstract_map/pygame-2.6.0.dist-info/INSTALLER
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
Loading

0 comments on commit 6b03836

Please sign in to comment.