forked from JorCademy/JorCademy-Engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Implemented primitive classes for representing draw buffer …
…objects. [FEATURE] Implemented helper functions for drawing primitive shapes.
- Loading branch information
1 parent
ebb0bf1
commit c3fa8e3
Showing
6 changed files
with
104 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
from jorcademy import * | ||
|
||
RED: color = (255, 0, 0) | ||
GREEN: color = (0, 255, 0) | ||
BLUE: color = (0, 0, 255) | ||
|
||
|
||
def setup() -> None: | ||
screen(800, 600) | ||
title("Best game ever") | ||
backdrop(255, 255, 255) | ||
|
||
|
||
def draw() -> None: | ||
pass | ||
ellipse(RED, 400, 300, 100, 200) | ||
rect(GREEN, 400, 300, 100, 100) | ||
text("Hell yeah!", BLUE, 400, 100) |
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,65 @@ | ||
import pygame | ||
|
||
|
||
class DrawableObject: | ||
def __init__(self, x, y, w, h): | ||
self.x = x | ||
self.y = y | ||
self.width = w | ||
self.height = h | ||
self.object_name = "Drawable" | ||
|
||
def get_type(self): | ||
return self.object_name | ||
|
||
def draw(self, context: pygame.display): | ||
pygame.draw.circle(context, self.x, self.y, 100) | ||
|
||
|
||
class Ellipse(DrawableObject): | ||
def __init__(self, color, x, y, w, h): | ||
super().__init__(x, y, w, h) | ||
self.object_name = "Ellipse" | ||
self.color = color | ||
|
||
def draw(self, context: pygame.display): | ||
center = (self.x, self.y) | ||
circle_rect = pygame.Rect(center[0] - self.width / 2, | ||
center[1] - self.height / 2, | ||
self.width, | ||
self.height) | ||
pygame.draw.ellipse(context, | ||
self.color, | ||
circle_rect, | ||
self.width) | ||
|
||
|
||
class Rectangle(DrawableObject): | ||
def __init__(self, color, x, y, w, h): | ||
super().__init__(x, y, w, h) | ||
self.object_name = "Rectangle" | ||
self.color = color | ||
|
||
def draw(self, context: pygame.display): | ||
center = (self.x, self.y) | ||
rectangle_rect = pygame.Rect(center[0] - self.width / 2, | ||
center[1] - self.height / 2, | ||
self.width, | ||
self.height) | ||
pygame.draw.rect(context, self.color, rectangle_rect, self.width) | ||
|
||
|
||
class Text(DrawableObject): | ||
def __init__(self, content, surface, color, x, y, w, h): | ||
super().__init__(x, y, w, h) | ||
self.object_name = "Tex" | ||
self.color = color | ||
self.contents = content | ||
self.surface = surface | ||
|
||
def draw(self, context: pygame.display): | ||
# Set the position of the text | ||
text_position = self.surface.get_rect() | ||
text_position.center = (self.x, self.y) # Centered on the screen | ||
context.blit(self.surface, text_position) | ||
|