This commit is contained in:
2021-09-03 16:44:18 +02:00
parent 009e23ea7f
commit 90154e37a8
12 changed files with 98 additions and 26 deletions

View File

@@ -1,7 +1,8 @@
import copy
import math
import pygame
from numpy import array as a
from Objects.Scene import Scene
from UI.Objects.Scene import Scene
class Multiscene(Scene):
@@ -71,6 +72,15 @@ class Multiscene(Scene):
self.resize_subscenes()
def update_mouse_events(self, mouse_pos, clicked):
mouse_pos = a(mouse_pos)
self.mouse_pos = self.inverse_matrix @ mouse_pos
self.clicked = clicked
for subscene in self.subscenes:
subscene.mouse_pos = (subscene.inverse_matrix @ (mouse_pos - (self.matrix @ subscene.position)))
subscene.clicked = clicked
def progress(self):
self.progress_subscenes()
@@ -82,6 +92,14 @@ class Multiscene(Scene):
for subscene in self.subscenes:
subscene.progress()
def get_i_objects(self):
i_objects = copy.copy(self.i_objects)
for subscene in self.subscenes:
i_objects += subscene.get_i_objects()
return i_objects
@staticmethod
def to_ints(iterable):
for i in range(len(iterable)):

View File

@@ -1,5 +1,5 @@
import pygame.transform
from Objects.Screen import Screen
from UI.Objects.Screen import Screen
from numpy import array as a
@@ -14,6 +14,8 @@ class Scene(Screen):
self.nrd_objects = [] # non-rescalable dynamic Objects
self.nrc_objects = [] # non-rescalable controllable Objects
self.i_objects = [] # interactive Objects
self.position = a([0, 0])
self.multiscene = None
@@ -52,3 +54,6 @@ class Scene(Screen):
def progress(self):
pass
def get_i_objects(self):
return self.i_objects

View File

@@ -1,5 +1,5 @@
import math
from numpy import array as a
import math
import pygame

View File

@@ -12,13 +12,13 @@ class RopeInteractiveDot:
self.scene = scene
def blit(self):
pygame.draw.circle(self.scene.s, self.color, self.scene.matrix @ self.position, self.r)
pygame.draw.circle(self.scene.s, self.color, self.scene.matrix @ self.position, self.r * self.scene.pd_)
def input(self, mouse_pos, clicked):
self.position = mouse_pos
if clicked:
for object_ in self.scene.nrd_objects:
for object_ in self.scene.get_i_objects():
if object_.__class__.__name__ == "Rope":
for node in object_.nodes:
if node.locked is False:

View File

@@ -36,7 +36,7 @@ class Rope:
self.a.position = center - connection_vector
def __init__(self, position, length, nodes_n, nodes_r, rope_width, scene, gravity=2, start_angle=1,
balance_amount=20, node_color=(255, 100, 100), rope_color=(255, 160, 160)):
balance_amount=10, node_color=(255, 100, 100), rope_color=(255, 160, 160)):
self.position = position
self.length = length
self.nodes_n = nodes_n
@@ -76,6 +76,8 @@ class Rope:
def blit(self):
if self.pd_ != self.scene.pd_:
self.pd_ = self.scene.pd_
self.rescaled_rope_segment_length = self.rope_segment_length * self.pd_
self.rescaled_nodes_r = self.nodes_r * self.pd_
self.rescaled_rope_width = self.rope_width * self.pd_
@@ -87,10 +89,11 @@ class Rope:
pygame.draw.line(self.scene.s, self.rope_color,
self.scene.matrix @ self.nodes[i].position,
self.scene.matrix @ self.nodes[i + 1].position,
int(self.rescaled_rope_width))
max(1, int(self.rescaled_rope_width)))
for node in self.nodes:
pygame.draw.circle(self.scene.s, self.node_color, self.scene.matrix @ node.position, self.rescaled_nodes_r)
pygame.draw.circle(self.scene.s, self.node_color, self.scene.matrix @ node.position,
max(1, self.rescaled_nodes_r))
@staticmethod
def to_ints(iterable):