Skip to content

Commit

Permalink
Abstract map continue
Browse files Browse the repository at this point in the history
  • Loading branch information
TeshariEnjoer committed Aug 9, 2024
1 parent b8017d8 commit 8dce8f9
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 26 deletions.
2 changes: 1 addition & 1 deletion code/__DEFINES/laplas_defines/abstract_map.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define MAP_SERVER_STATUS_DISABLED 0
#define MAP_SERVER_STATUS_BOOTING 1
#define MAP_SERVER_STATUS_INGAME 2
#define DEFAULT_ABSTRACT_MAP_URL "http://localhost:5000/"
#define DEFAULT_ABSTRACT_MAP_URL "http://127.0.0.1:5000/"


//
Expand Down
3 changes: 2 additions & 1 deletion laplas/code/modules/abstract_overmap/SSabstract_overmap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SUBSYSTEM_DEF(abstract_overmap)
CRASH("[name] failed to install new secure key!")
init_map()


/datum/controller/subsystem/abstract_overmap/proc/init_map()
. = ""
. += "key = [http_key],"
Expand All @@ -43,10 +44,10 @@ SUBSYSTEM_DEF(abstract_overmap)
. += "generation_type [generation_type],"
. += "max_planets [max_planets],"
. += "max_outposts [max_outposts],"

var/response = ABSTRACT_MAP_REQUEST(ABSTRACT_MAP_INIT, args)



/datum/controller/subsystem/abstract_overmap/proc/reset_key()
var/response = ABSTRACT_MAP_REQUEST(ABSTRACT_MAP_RESET_KEY, http_key)
if(response == AM_RESPONSE_SUCESS)
Expand Down
40 changes: 40 additions & 0 deletions laplas/tools/abstract_map/camera.py
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()
14 changes: 11 additions & 3 deletions laplas/tools/abstract_map/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

acess_key = None
map = None
process = False

if __name__ == '__main__':
app.run(debug=True, port= 5000)

def check_acess(key):
if(key == acess_key):
Expand All @@ -29,8 +33,9 @@ def unpack_data(args):
return result

# Sets up a new acess key for map args = new_key
@app.route('/set_key', methods=['GET'])
@app.route('/set_key', methods=['GET', 'POST'])
def set_key(args):
print(f"Request method: {args}")
if(acess_key):
return "ABSTRACT MAP ERROR: ATTEMPT REPLACE EXISTED ACESS KEY"

Expand Down Expand Up @@ -69,8 +74,11 @@ def init_map(args):
if(not check_acess(key)):
return ACESS_DANIED

global map
map = overmap(map_size_x, map_size_x)

global process
process = True

@app.route('/create_obj', methods=['GET'])
def create_obj(id: str, args):
Expand All @@ -80,5 +88,5 @@ def create_obj(id: str, args):
def move_obj(id, new_position):
pass

if __name__ == '__main__':
app.run(debug=True)
while(process):
map.process()
48 changes: 48 additions & 0 deletions laplas/tools/abstract_map/objects/object.py
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)
50 changes: 29 additions & 21 deletions laplas/tools/abstract_map/overmap.py
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()

0 comments on commit 8dce8f9

Please sign in to comment.