-
-
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.
- Loading branch information
1 parent
b8017d8
commit 8dce8f9
Showing
6 changed files
with
131 additions
and
26 deletions.
There are no files selected for viewing
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
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
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,40 @@ | ||
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) | ||
|
||
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 | ||
|
||
if(event.type == pygame.MOUSEBUTTONUP): | ||
if(event.button == 1): # Левая кнопка мыши | ||
self.dragging = False | ||
|
||
if(event.type == pygame.MOUSEMOTION): | ||
if(self.dragging): | ||
mouse_x, mouse_y = event.pos | ||
dx = self.last_mouse_x - mouse_x | ||
dy = self.last_mouse_y - mouse_y | ||
self.x += dx | ||
self.y += dy | ||
self.last_mouse_x, self.last_mouse_y = self.x, self.y | ||
|
||
self.camera_rect.topleft = (self.x, self.y) | ||
self.screen.blit(self.render_surface, (0, 0), self.camera_rect) | ||
pygame.display.flip() |
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
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,48 @@ | ||
import pygame | ||
|
||
class object: | ||
DM_datum = "datum/overmap" | ||
|
||
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 | ||
|
||
# Physical parametr | ||
|
||
# Our current velocity | ||
self.velocity = pygame.Vector2(0, 0) | ||
# A temporary acceleration that we get | ||
self.acceleration = pygame.Vector2(0, 0) | ||
|
||
self.angle = 0 | ||
self.rotation_speed = 0 | ||
|
||
|
||
# Applied new temporary acceleration | ||
def apply_force(self, force: pygame.Vector2): | ||
self.acceleration += force | ||
|
||
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): | ||
self.velocity += self.acceleration | ||
self.rect.center += pygame.Vector2(self.velocity.x, self.velocity.y) | ||
self.acceleration = pygame.Vector2(0, 0) | ||
|
||
self.angle %= 360 | ||
self.image = pygame.transform.rotate(self.original_texute, -self.angle) | ||
self.rect = self.image.get_rect(center=self.rect.center) | ||
|
||
def draw(self, screen): | ||
pygame.draw.rect(screen, self.rect) |
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,56 @@ | ||
import pygame | ||
from objects import object | ||
import camera | ||
|
||
|
||
camera_width, camera_height = 800, 600 | ||
|
||
class overmap: | ||
process = False | ||
pygame.init() | ||
|
||
def __init__(self, size_x: int, size_y: int, visual: bool) -> None: | ||
# A map full size | ||
self.size_x = size_x | ||
self.size_y = size_y | ||
|
||
|
||
self.all_object = list() | ||
# Format "id" = obj | ||
self.all_object = dict() | ||
self.all_ships = dict() | ||
# Format "id" = obj | ||
self.all_planets = dict() | ||
|
||
|
||
if(visual): | ||
self.init_window() | ||
|
||
self.screen = pygame.display.set_mode((camera_width, camera_height)) | ||
self.create_map() | ||
self.create_camera() | ||
pygame.display.set_caption("Large Map with Coordinate System") | ||
|
||
## Overmap functions | ||
def init_window(): | ||
pygame.init() | ||
|
||
# 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)) | ||
|
||
width, height = 800, 600 | ||
screen = pygame.Surface((width, height)) | ||
screen.fill(1, 1, 1) | ||
|
||
pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(100, 100, 200, 200), 1) | ||
pygame.draw.circle(screen, (255, 0, 0), (400, 300), 50) | ||
|
||
def create_camera(): | ||
pass | ||
def create_camera(self): | ||
camera_x, camera_y = 0, 0 | ||
self.camera = camera(self.map_holder, self.screen, camera_x, camera_y) | ||
|
||
## Function for manipulate with objects | ||
def create_object(): | ||
def create_object(self, obj, args): | ||
pass | ||
|
||
def remove_object(): | ||
def remove_object(self): | ||
pass | ||
|
||
def adjust_speed(): | ||
def adjust_speed(self): | ||
pass | ||
|
||
while process: | ||
pass | ||
def process(self): | ||
self.camera.process() | ||
|
||
if(not self.all_object.__len__()): | ||
return | ||
for obj in self.all_object: | ||
obj.process() |