-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Finished HTTP server - New class object - Processing system - Graviation system - Base camere framework
- Loading branch information
1 parent
6b03836
commit ae04995
Showing
9 changed files
with
230 additions
and
103 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
BLACK = (0, 0, 0) | ||
GRAY = (127, 127, 127) | ||
WHITE = (255, 255, 255) | ||
RED = (255, 0, 0) | ||
GREEN = (0, 255, 0) | ||
BLUE = (0, 0, 255) | ||
YELLOW = (255, 255, 0) | ||
CYAN = (0, 255, 255) | ||
MAGENTA = (255, 0, 255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
URL = "http://127.0.0.1" | ||
PORT = 5000 | ||
SCREEN_WIDTH = 600 | ||
SCREEN_HEIGHT = 800 | ||
FPS = 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROCESSING_OBJECTS = list() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,51 @@ | ||
import pygame | ||
from objects.processing import processing | ||
import colors | ||
|
||
class overmap_view (processing): | ||
|
||
def __init__(self, screen, surface, new_x, new_y, width, height) -> None: | ||
super().__init__() | ||
|
||
|
||
self.width = width | ||
self.height = height | ||
|
||
|
||
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})") # Отладочный вывод | ||
|
||
self.camera_view = pygame.Rect(self.x, self.y, self.width, self.height) | ||
print(f"Camera initialized at ({self.x}, {self.y})") | ||
|
||
def __process__(self): | ||
mouse_x, mouse_y = pygame.mouse.get_pos() | ||
mouse_buttons = pygame.mouse.get_pressed() | ||
|
||
if mouse_buttons[0]: | ||
if not self.dragging: | ||
# Начало перетаскивания | ||
self.dragging = True | ||
self.last_mouse_x = mouse_x | ||
self.last_mouse_y = mouse_y | ||
else: | ||
dx = mouse_x - self.last_mouse_x | ||
dy = mouse_y - self.last_mouse_y | ||
|
||
self.camera_view.x -= dx | ||
self.camera_view.y -= dy | ||
|
||
self.last_mouse_x = mouse_x | ||
self.last_mouse_y = mouse_y | ||
else: | ||
self.dragging = False | ||
|
||
def __update__(self): | ||
self.screen.fill((0, 0, 0)) | ||
self.screen.blit(self.render_surface, (0, 0), self.camera_view) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,127 @@ | ||
import pygame | ||
import os | ||
from objects.processing import processing | ||
|
||
class object: | ||
DM_datum = "datum/overmap" | ||
class object (processing): | ||
def __init__(self, name, id, map, x, y, width, height, iconpath = "assets/obj.png"): | ||
super().__init__() | ||
|
||
def __init__(self, x, y, width, height, icon = ""): | ||
self.iconpath = self.texture_path + icon | ||
# Draw parametrs | ||
self.original_texute = pygame.image.load(self.iconpath).convert_alpha() | ||
self.texute = self.original_texute | ||
self.rect = self.image.get_rect(center=(x, y)) | ||
self.rect.width = width | ||
self.rect.height = height | ||
self.name = name | ||
self.id = id | ||
self.DM_datum = "datum/overmap" | ||
self.iconpath = iconpath | ||
# Draw params: | ||
|
||
# Physical parametr | ||
self.rect = pygame.Rect(x, y, width, height) | ||
self.original_texture = any | ||
self.load_texture() | ||
|
||
# Our current velocity | ||
# Positional params: | ||
|
||
self.x = x | ||
self.y = y | ||
self.map = map | ||
|
||
print(f"Created new object {self.name}, with id {self.id}, with icon {self.iconpath}, on {self.x}: {self.y}") | ||
# Physical params: | ||
|
||
# Our current velocity. | ||
self.velocity = pygame.Vector2(0, 0) | ||
# A temporary acceleration that we get | ||
# A temporary acceleration that we get. | ||
self.acceleration = pygame.Vector2(0, 0) | ||
|
||
# A gravitational object that affects us. E.t.c Planet, star, blackhole | ||
self.gsource = None | ||
self.gforce = None | ||
# Our mass, effects on gravity forcess | ||
self.mass = 1 | ||
# Our angle of inclination, relative to it will be set velocity. | ||
self.angle = 0 | ||
# The speed at which we're spinning. Positive values are rotation to the right, negative values are rotation to the left. | ||
self.rotation_speed = 0 | ||
|
||
self.font = pygame.font.SysFont(None, 12) | ||
|
||
def destroy(self): | ||
del self.original_texture | ||
del self.image | ||
del self.rect | ||
del self | ||
|
||
def load_texture(self): | ||
current_directory = os.path.dirname(os.path.abspath(__file__)) | ||
parent = os.path.dirname(current_directory) | ||
|
||
final_path = os.path.join(parent, self.iconpath) | ||
final_path = final_path.replace("\\", "/") | ||
|
||
self.image = pygame.image.load(final_path) | ||
self.original_texture = self.image.copy() | ||
|
||
def set_color(self, color): | ||
self.image.fill(color) | ||
|
||
# Sets new gravitation source | ||
def set_gravity_source(self, gsource, gforce): | ||
self.gsource = gsource | ||
self.gforce = gforce | ||
|
||
|
||
# Applied new temporary acceleration | ||
def apply_force(self, force: pygame.Vector2): | ||
self.acceleration += force | ||
self.acceleration += force / self.mass | ||
|
||
|
||
def apply_thrust(self, thrust): | ||
direction = pygame.Vector2(1, 0).rotate(self.angle) | ||
self.apply_force(direction * thrust) | ||
|
||
|
||
def apply_brake(self, brake_force): | ||
direction = pygame.Vector2(1, 0).rotate(self.angle) | ||
self.apply_force(-direction * brake_force) | ||
|
||
def update(self): | ||
def rotate(self, force): | ||
pass | ||
|
||
def set_rotation(self, force): | ||
pass | ||
|
||
def draw_id(self): | ||
text = f"{self.name}: {self.id} " | ||
text += f"X: {self.x}, Y:{self.y}" | ||
text_surface = self.font.render(text, True, (255, 255, 255)) | ||
text_rect = text_surface.get_rect(center=(self.rect.centerx, self.rect.bottom + 10)) | ||
self.map.blit(text_surface, text_rect) | ||
|
||
def __process__(self): | ||
if self.gsource: | ||
distance = pygame.Vector2(self.gsource.rect.center) - pygame.Vector2(self.rect.center) | ||
distance_length = distance.length() | ||
if distance_length > 0: | ||
gravitational_force = self.gforce * self.mass / (distance_length ** 2) | ||
gravitational_acceleration = gravitational_force * distance.normalize() | ||
self.apply_force(gravitational_acceleration) | ||
|
||
|
||
self.velocity += self.acceleration | ||
self.rect.center += pygame.Vector2(self.velocity.x, self.velocity.y) | ||
self.rect.center += self.velocity | ||
self.acceleration = pygame.Vector2(0, 0) | ||
|
||
self.angle %= 360 | ||
self.image = pygame.transform.rotate(self.original_texute, -self.angle) | ||
self.image = pygame.transform.rotate(self.original_texture, -self.angle) | ||
self.rect = self.image.get_rect(center=self.rect.center) | ||
|
||
def draw(self, screen): | ||
pygame.draw.rect(screen, self.rect) | ||
self.x = self.velocity.x | ||
self.y = self.velocity.y | ||
# Actually move | ||
self.rect.move_ip(self.velocity) | ||
|
||
def __update__(self): | ||
self.draw_id() | ||
self.map.blit(self.image, (self.x, self.y)) | ||
|
||
def spawn_object(name: str, id: int, map: pygame.surface, new_x: int, new_y: int, width: int, height: int, iconpath): | ||
new_obj = object(name, id, map, new_x, new_y, width, height, iconpath) | ||
return new_obj | ||
|
||
def remove_object(obj: object): | ||
obj.destroy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import globals | ||
|
||
class processing: | ||
def __init__(self) -> None: | ||
globals.PROCESSING_OBJECTS.append(self) | ||
|
||
def __del__(self): | ||
globals.PROCESSING_OBJECTS.remove(self) | ||
|
||
# Update physics | ||
def __process__(self): | ||
pass | ||
|
||
# Update visual state | ||
def __update__(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.