]> Skullheadx's Git Forge - PygameGUIEngine.git/commitdiff
Rectangle and Color
authorSkullheadx <admonty1@gmail.com>
Thu, 13 Apr 2023 23:42:53 +0000 (19:42 -0400)
committerSkullheadx <admonty1@gmail.com>
Thu, 13 Apr 2023 23:42:53 +0000 (19:42 -0400)
.gitignore
.idea/.gitignore [new file with mode: 0644]
color.py [new file with mode: 0644]
main.py [new file with mode: 0644]
rectangle.py [new file with mode: 0644]

index d9005f2cc7fc4e65f14ed5518276007c08cf2fd0..3eb56cb1b2b440b4f8be065c26fb0972fe724648 100644 (file)
@@ -149,4 +149,4 @@ cython_debug/
 #  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
 #  and can be added to the global gitignore or merged into this file.  For a more nuclear
 #  option (not recommended) you can uncomment the following to ignore the entire idea folder.
-#.idea/
+.idea/
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644 (file)
index 0000000..13566b8
--- /dev/null
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/color.py b/color.py
new file mode 100644 (file)
index 0000000..64b241e
--- /dev/null
+++ b/color.py
@@ -0,0 +1,8 @@
+class Color:
+    BLACK = (0, 0, 0)
+    GRAY = (128, 128, 128)
+    WHITE = (255, 255, 255)
+
+    RED = (255, 0, 0)
+    GREEN = (0, 255, 0)
+    BLUE = (0, 0, 255)
diff --git a/main.py b/main.py
new file mode 100644 (file)
index 0000000..6bd6bd2
--- /dev/null
+++ b/main.py
@@ -0,0 +1,32 @@
+import pygame
+from rectangle import Rectangle
+
+pygame.init()
+
+screen = pygame.display.set_mode((640, 480))
+pygame.display.set_caption("My Game")
+clock = pygame.time.Clock()
+delta = 0
+
+# Testing Rectangle
+r = Rectangle(100, 100, 100, 100, (255, 0, 0))
+r2 = Rectangle(200, 200, 100, 100, (0, 255, 0), (0, 0, 255), 5, 10)
+r3 = Rectangle(300, 300, 100, 100, (0, 0, 255), (255, 0, 0), 5, 10)
+
+is_running = True
+while is_running:
+    for event in pygame.event.get():
+        if event.type == pygame.QUIT:
+            is_running = False
+
+    screen.fill((255, 255, 255))
+
+    r.draw(screen)
+    r2.draw(screen)
+    r3.move(delta * 10, delta * 10)
+    r3.draw(screen)
+
+    pygame.display.update()
+    delta = clock.tick(60) / 1000  # Seconds since last frame
+
+pygame.quit()
diff --git a/rectangle.py b/rectangle.py
new file mode 100644 (file)
index 0000000..5ed959c
--- /dev/null
@@ -0,0 +1,41 @@
+import pygame
+from color import Color
+
+
+class Rectangle:
+
+    def __init__(self, x, y, width, height, background_color, border_color=Color.BLACK, border_width=0,
+                 border_radius=0):
+        self.x = x
+        self.y = y
+        self.width = width
+        self.height = height
+        self.background_color = background_color
+
+        self.border_color = border_color
+        self.border_width = border_width
+        self.border_radius = border_radius
+
+    def set_position(self, x, y):
+        self.x = x
+        self.y = y
+
+    def move(self, dx, dy):
+        self.x += dx
+        self.y += dy
+
+    def set_size(self, width, height):
+        self.width = width
+        self.height = height
+
+    def set_background_color(self, background_color):
+        self.background_color = background_color
+
+    def set_border_color(self, border_color):
+        self.border_color = border_color
+
+    def draw(self, screen):
+        pygame.draw.rect(screen, self.background_color, (self.x, self.y, self.width, self.height),
+                         border_radius=self.border_radius)
+        pygame.draw.rect(screen, self.border_color, (self.x, self.y, self.width, self.height), self.border_width,
+                         border_radius=self.border_radius)