Skip to content

Commit 484380a

Browse files
authored
update 0.1.2.1
1 parent 9ca4e1e commit 484380a

20 files changed

+1784
-25
lines changed

core/game/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from core.game.behaviors import *
2+
from core.game.enemy import *
3+
from core.game.projectile import *
4+
from core.game.stage import *
5+
from core.game.player import *
6+
from core.game.pickups import *
7+
from core.game.registries import *
8+
from core.game.menusystem import *
9+
from core.game.triggers import *
10+
from core.game.dialogue import *
11+
from core.game.colliders import *

core/game/behaviors.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import pygame as pg
2+
3+
# A basic skeleton
4+
class Behavior:
5+
def __init__(self, game, target):
6+
self.game = game
7+
self.target = target
8+
self.stop = False
9+
10+
def tick(self):
11+
pass
12+
13+
def update(self):
14+
if not self.stop:
15+
self.tick()
16+
17+
class MoveInDirection(Behavior):
18+
def __init__(self, game, target, args=[[0, 0]]):
19+
super().__init__(game, target)
20+
self.direction = [args[0], args[1]]
21+
self.vel = [args[0], args[1]]
22+
23+
def tick(self):
24+
self.target.pos[0] += self.vel[0]
25+
self.target.pos[1] += self.vel[1]
26+
27+
class MoveByPoints(Behavior):
28+
def __init__(self, game, target, args=()):
29+
super().__init__(game, target)
30+
self.waypoints = args
31+
self.curwaypoint = 0
32+
33+
def tick(self):
34+
try:
35+
if self.target.pos != self.waypoints[self.curwaypoint]:
36+
if self.target.pos[0] < self.waypoints[self.curwaypoint][0]:
37+
self.target.pos[0] += self.target.speed
38+
elif self.target.pos[0] > self.waypoints[self.curwaypoint][0]:
39+
self.target.pos[0] -= self.target.speed
40+
else:
41+
self.target.pos[0] += 0
42+
if self.target.pos[1] < self.waypoints[self.curwaypoint][1]:
43+
self.target.pos[1] += self.target.speed
44+
elif self.target.pos[1] > self.waypoints[self.curwaypoint][1]:
45+
self.target.pos[1] -= self.target.speed
46+
else:
47+
self.target.pos[0] += 0
48+
else:
49+
self.curwaypoint += 1
50+
except IndexError:
51+
self.stop = True
52+
53+

core/game/bulletpatterns.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pygame as pg
2+
import math
3+
import random
4+
5+
def circlepattern(game, speed=1, pos=(0, 0), proj_type="big_ball_white", bullet_count=10):
6+
for i in range(bullet_count):
7+
game.projregistry.shoot(proj_type, pos, 360 - (360 / i), speed)
8+
9+
10+
# don't use
11+
class BulletPattern:
12+
def __init__(self, game):
13+
self.game = game
14+
15+
def shoot(self):
16+
pass
17+
18+
class CirclePattern(BulletPattern):
19+
def __init__(self, game, speed=1, pos=(0, 0), proj_type="big_ball_white", bullet_count=10):
20+
super().__init__(game)
21+
self.speed = speed
22+
self.pos = pos
23+
self.proj_type = proj_type
24+
self.bullet_count = bullet_count
25+
26+
def shoot(self):
27+
for i in range(self.bullet_count):
28+
self.game.projregistry.shoot(self.proj_type, self.pos, 360 - (360 / i), self.speed)

core/game/colliders/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from core.game.colliders.colliders import *
2+
from core.game.colliders.colutils import *

core/game/colliders/colliders.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import math
2+
3+
def dist(a, b):
4+
return math.dist(a, b)
5+
6+
class Collider:
7+
def __init__(self):
8+
pass
9+
10+
class CircleCollider:
11+
def __init__(self, radius=4 , pos=(0, 0)):
12+
self.radius = radius
13+
self.x = pos[0]
14+
self.y = pos[1]
15+
self.position = pos
16+
17+
def colliderect(self, rect):
18+
'''DISCLAIMER:\n
19+
DO NOT USE IF NOT REQUIRED TO,\n
20+
BECAUSE IT ONLY CHECKS FOR THE RECT'S CENTER'''
21+
22+
if dist(rect.center, self.position) <= self.radius:
23+
return True
24+
else:
25+
return False
26+
27+
def collidecircle(self, circle):
28+
if dist(self.position, circle.position) <= self.radius + circle.radius - 1:
29+
return True
30+
else:
31+
return False
32+
33+
def collidepoint(self, point):
34+
if dist(self.position, point) <= self.radius:
35+
return True
36+
else:
37+
return False
38+
39+
def update(self, pos=(0, 0)):
40+
setattr(self, "position", pos)
41+
setattr(self, "x", pos[0])
42+
setattr(self, "y", pos[1])
43+

core/game/colliders/colutils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# unused

core/game/dialogue.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import pygame as pg
2+
from core.visuals.ui import *
3+
from ursina import Entity
4+
5+
class Dialogue:
6+
'''Values:
7+
is_skippable: bool
8+
maxtime: int
9+
text: str
10+
11+
Errors:
12+
...
13+
'''
14+
default_values = {
15+
'maxshowtime': 400, 'is_skippable': True, 'text': "Test"
16+
}
17+
def __init__(self, game, dialoguemanager, **kwargs):
18+
self.game = game
19+
self.dialogmanage = dialoguemanager
20+
self.text = "Test\nMultiline"
21+
self.is_skippable = True
22+
self.on_scr_time = 0
23+
self.maxtime = 400
24+
for key, value in kwargs.items():
25+
setattr(self, key, value)
26+
27+
def todict(self): # method for saving an enemy object to a stage file
28+
return {"game": None,
29+
"text": self.text,
30+
"is_skippable": self.is_skippable,
31+
"maxshowtime": self.maxtime
32+
}
33+
34+
@classmethod
35+
def fromdict(cls, asset, game=None, dialogmanager=None): # method for loading an enemy object from a stage file
36+
return cls(game, dialogmanager, text=asset["text"], is_skippable=asset["is_skippable"], maxtime=asset["maxshowtime"])
37+
38+
def update(self):
39+
self.on_scr_time += 1
40+
if self.on_scr_time >= self.maxtime:
41+
return True
42+
else:
43+
return False
44+
45+
def skip(self):
46+
self.on_scr_time = self.maxtime
47+
48+
class DialogueCollection:
49+
def __init__(self, game, dialoguemanager, dialogue=[]):
50+
self.game = game
51+
self.active = True
52+
self.dialog_index = 0
53+
self.dialogmanager = dialoguemanager
54+
self.dialogue = dialogue
55+
56+
def todict(self): # method for saving an enemy object to a stage file
57+
return {"game": None,
58+
"dialogue": self.dialogue
59+
}
60+
61+
@classmethod
62+
def fromdict(cls, asset, game=None, dialogmanager=None): # method for loading an enemy object from a stage file
63+
return cls(game, dialogmanager, dialogue=asset["dialogue"])
64+
65+
def update(self):
66+
if self.active == False:
67+
for dialog in self.dialogue:
68+
dialog.on_scr_time = 0
69+
if len(self.dialogue) >= 1:
70+
try:
71+
line_height = self.dialogmanager.font.get_linesize()
72+
lines = self.dialogue[self.dialog_index].text.split('\n')
73+
if self.dialogue[self.dialog_index].update() == True:
74+
self.dialog_index += 1
75+
for line in lines:
76+
text_surface = self.dialogmanager.font.render(line, True, (255, 255, 255))
77+
self.game.fight_area.blit(text_surface, (self.dialogmanager.dialoguerect.left, self.dialogmanager.dialoguerect.top + self.dialogmanager.y_offset))
78+
self.dialogmanager.y_offset += line_height
79+
self.dialogmanager.y_offset = self.dialogmanager.default_offset
80+
except IndexError:
81+
self.active = False
82+
83+
class DialogueSystem:
84+
def __init__(self, game):
85+
self.game = game
86+
self.active = False
87+
self.active_collection = 0
88+
self.dialogue_collection_dict = {0 : DialogueCollection(self.game, self, [Dialogue(self.game, self, maxshowtime=400, is_skippable=True, text="Test\nMultiline"), Dialogue(self.game, self, maxshowtime=400, is_skippable=True, text="Test NAH")])}
89+
self.skip_dialogue = False
90+
self.dialoguerect = pg.Rect(16, 300, 354, 130)
91+
self.font = pg.font.SysFont('Comic Sans MS', 18)
92+
93+
self.default_offset = 0
94+
self.y_offset = 0
95+
96+
def update(self):
97+
if self.active:
98+
if len(self.dialogue_collection_dict) >= 1 and self.dialogue_collection_dict[self.active_collection].active == True:
99+
pg.draw.rect(self.game.fight_area, (40, 40, 40, 150), self.dialoguerect)
100+
self.dialogue_collection_dict[self.active_collection].update()
101+
102+
def skip(self):
103+
if len(self.dialogue_collection_dict) >= 1 and self.dialogue_collection_dict[self.active_collection].active == True:
104+
self.dialogue_collection_dict[self.active_collection].dialogue[self.dialogue_collection_dict[self.active_collection].dialog_index].skip()

0 commit comments

Comments
 (0)