├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── .gitignore ├── Capsian ├── GUI │ ├── __init__.py │ ├── label.py │ └── sprite.py ├── __init__.py ├── audio │ ├── __init__.py │ ├── music.py │ └── sound.py ├── components │ ├── __init__.py │ ├── character_controller.py │ ├── component.py │ ├── light.py │ ├── script.py │ └── transform.py ├── engine.py ├── entities │ ├── __init__.py │ ├── cube.py │ ├── entity.py │ ├── independent_component.py │ ├── particle_system.py │ └── square.py ├── input │ ├── __init__.py │ ├── keyboard.py │ └── mouse.py ├── log.py ├── maths │ ├── __init__.py │ └── math.py ├── services.py ├── texturing │ ├── __init__.py │ ├── material.py │ └── texture.py ├── types │ ├── __init__.py │ ├── flag.py │ ├── flag_list.py │ └── object_array.py ├── values.py ├── video │ ├── __init__.py │ ├── bluefire │ │ ├── __init__.py │ │ └── basic.py │ ├── camera.py │ ├── fog.py │ ├── fps_counter.py │ ├── scene.py │ ├── sky_color.py │ └── window.py └── world │ ├── __init__.py │ ├── clock.py │ └── format.py ├── Capsianline ├── capsianline.py ├── ccerror.py ├── cclexer.py ├── ccparser.py ├── commands │ ├── capget │ │ └── Capsianline.py │ └── command.py ├── design.py └── paths.json ├── LICENSE ├── README.md ├── addons └── __init__.py ├── console.py ├── example ├── __init__.py ├── data.py ├── flashing_light.py ├── main.py ├── map_generator.py ├── movement.py ├── setup.py └── time.py ├── main.py ├── options.cpsn ├── prepare.py └── projects └── __init__.py /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | .vscode 6 | .VSCodeCounter 7 | whiteboard.txt 8 | scripts/*.py 9 | assets/ 10 | *.exe 11 | options.cpsn 12 | addons/ 13 | 14 | 15 | # C extensions 16 | *.so 17 | 18 | # Distribution / packaging 19 | .Python 20 | build/ 21 | develop-eggs/ 22 | dist/ 23 | downloads/ 24 | eggs/ 25 | .eggs/ 26 | lib/ 27 | lib64/ 28 | parts/ 29 | sdist/ 30 | var/ 31 | wheels/ 32 | share/python-wheels/ 33 | *.egg-info/ 34 | .installed.cfg 35 | *.egg 36 | MANIFEST 37 | 38 | # PyInstaller 39 | # Usually these files are written by a python script from a template 40 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 41 | *.manifest 42 | *.spec 43 | 44 | # Installer logs 45 | pip-log.txt 46 | pip-delete-this-directory.txt 47 | 48 | # Unit test / coverage reports 49 | htmlcov/ 50 | .tox/ 51 | .nox/ 52 | .coverage 53 | .coverage.* 54 | .cache 55 | nosetests.xml 56 | coverage.xml 57 | *.cover 58 | *.py,cover 59 | .hypothesis/ 60 | .pytest_cache/ 61 | cover/ 62 | 63 | # Translations 64 | *.mo 65 | *.pot 66 | 67 | # Django stuff: 68 | *.log 69 | local_settings.py 70 | db.sqlite3 71 | db.sqlite3-journal 72 | 73 | # Flask stuff: 74 | instance/ 75 | .webassets-cache 76 | 77 | # Scrapy stuff: 78 | .scrapy 79 | 80 | # Sphinx documentation 81 | docs/_build/ 82 | 83 | # PyBuilder 84 | .pybuilder/ 85 | target/ 86 | 87 | # Jupyter Notebook 88 | .ipynb_checkpoints 89 | 90 | # IPython 91 | profile_default/ 92 | ipython_config.py 93 | 94 | # pyenv 95 | # For a library or package, you might want to ignore these files since the code is 96 | # intended to run in multiple environments; otherwise, check them in: 97 | # .python-version 98 | 99 | # pipenv 100 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 101 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 102 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 103 | # install all needed dependencies. 104 | #Pipfile.lock 105 | 106 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 107 | __pypackages__/ 108 | 109 | # Celery stuff 110 | celerybeat-schedule 111 | celerybeat.pid 112 | 113 | # SageMath parsed files 114 | *.sage.py 115 | 116 | # Environments 117 | .env 118 | .venv 119 | env/ 120 | venv/ 121 | ENV/ 122 | env.bak/ 123 | venv.bak/ 124 | 125 | # Spyder project settings 126 | .spyderproject 127 | .spyproject 128 | 129 | # Rope project settings 130 | .ropeproject 131 | 132 | # mkdocs documentation 133 | /site 134 | 135 | # mypy 136 | .mypy_cache/ 137 | .dmypy.json 138 | dmypy.json 139 | 140 | # Pyre type checker 141 | .pyre/ 142 | 143 | # pytype static type analyzer 144 | .pytype/ 145 | 146 | # Cython debug symbols 147 | cython_debug/ -------------------------------------------------------------------------------- /Capsian/GUI/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.GUI.label import Label2D, Label3D 55 | from Capsian.GUI.sprite import Sprite3D 56 | -------------------------------------------------------------------------------- /Capsian/GUI/label.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.log import Log 55 | from Capsian.values import CPSN_HUD_SCENE 56 | from Capsian.components.transform import Transform 57 | from Capsian.video.scene import PlaceholderScene 58 | import Capsian.engine as engine 59 | import pyglet 60 | 61 | 62 | class Label(pyglet.text.Label): 63 | """ 64 | Fields 65 | ------ 66 | scene | A Capsian Scene Object | Scene2D/OverlayScene 67 | 68 | Methods 69 | ------- 70 | move_to | Moves the label to the specified position 71 | """ 72 | 73 | def __init__(self, font: str, font_size: float, text: str, color, transform=Transform(), scene=PlaceholderScene(), *args, **kwargs): 74 | """ 75 | Parameters 76 | ---------- 77 | font | The font you want to use for the label | str 78 | font-size | The font size you want to use | float 79 | text | The text of the label | str 80 | color | The color of the label | list [R, G, B, A] 81 | scene | The Capsian Scene of which the label is part of | Scene2D 82 | """ 83 | 84 | if not isinstance(scene, CPSN_HUD_SCENE): 85 | Log.critical(f"Invalid scene type for Static HUD Label. This object can only be used in a GUI scene (CPSN_HUD_SCENE)") 86 | return 87 | 88 | self.scene = scene 89 | 90 | super().__init__( 91 | text=text, 92 | font_name=font, 93 | font_size=font_size, 94 | bold=False, 95 | italic=False, 96 | x=transform.x, 97 | y=transform.y, 98 | width=transform.width, 99 | height=transform.height, 100 | color=color, 101 | *args, **kwargs 102 | ) 103 | 104 | 105 | def move_to(self, x: int, y: int) -> None: 106 | """ 107 | Parameters 108 | ---------- 109 | x | The new X position | int 110 | y | The new Y position | int 111 | """ 112 | 113 | self.x = int(x) 114 | self.y = int(y) 115 | 116 | 117 | #################################################################### 118 | 119 | 120 | class Label2D(Label): 121 | """ 122 | Fields 123 | ------ 124 | scene | A Capsian Scene Object | Scene2D/OverlayScene 125 | 126 | Methods 127 | ------- 128 | move_to | Moves the label to the specified position 129 | """ 130 | 131 | def __init__(self, font: str, font_size: float, text: str, color, transform=Transform(), scene=PlaceholderScene, *args, **kwargs): 132 | """ 133 | Parameters 134 | ---------- 135 | font | The font you want to use for the label | str 136 | font-size | The font size you want to use | float 137 | text | The text of the label | str 138 | color | The color of the label | list [R, G, B, A] 139 | scene | The Capsian Scene of which the label is part of | Scene2D 140 | """ 141 | 142 | super().__init__( 143 | font=font, 144 | font_size=font_size, 145 | transform=transform, 146 | text=text, 147 | scene=scene, 148 | color=color, 149 | *args, **kwargs 150 | ) 151 | 152 | self.scene.dynamic_gui.append(self) 153 | 154 | 155 | class Label3D(Label): 156 | """ 157 | Fields 158 | ------ 159 | scene | A Capsian Scene Object | Scene2D/OverlayScene 160 | 161 | Methods 162 | ------- 163 | move_to | Moves the label to the specified position 164 | """ 165 | 166 | def __init__(self, font: str, font_size: float, text: str, color, transform=Transform(), scene=PlaceholderScene, *args, **kwargs): 167 | """ 168 | Parameters 169 | ---------- 170 | font | The font you want to use for the label | str 171 | font-size | The font size you want to use | float 172 | text | The text of the label | str 173 | color | The color of the label | list [R, G, B, A] 174 | scene | The Capsian Scene of which the label is part of | Scene2D 175 | """ 176 | 177 | super().__init__( 178 | font=font, 179 | font_size=font_size, 180 | transform=transform, 181 | text="", 182 | scene=scene, 183 | color=color, 184 | *args, **kwargs 185 | ) 186 | 187 | self.text_pointer = text 188 | scene.dynamic_hud.append(self) 189 | engine.default_clock.Schedule.call_with_interval(self.update_text, 1/10) 190 | 191 | 192 | def update_text(self, dt: float) -> None: 193 | """ 194 | Updates the label's text. This is used for multiple reasons: 195 | 1. Setting the text when the label is created 196 | 2. Updating the text if a pointer (Such as pyglet.clock.get_fps) is specified in the text propriety 197 | 198 | :param delta_time: 199 | :return: None 200 | """ 201 | 202 | try: 203 | self.text = str(self.text_pointer()) 204 | except TypeError: 205 | self.text = str(self.text_pointer) 206 | except: 207 | self.text = "Invalid Pointer!" 208 | -------------------------------------------------------------------------------- /Capsian/GUI/sprite.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.entities.square import TexturedSquare 55 | from Capsian.components.transform import Transform 56 | 57 | 58 | class Sprite3D: 59 | """ 60 | Fields 61 | ------ 62 | texture | The texture fo the Sprite | texture 63 | """ 64 | 65 | 66 | # ------------------------- 67 | # 68 | # DUNDERSCORE 69 | # 70 | # ------------------------- 71 | 72 | def __init__(self, transform=Transform(), scene=None, texture=None): 73 | """ 74 | Parameters 75 | ---------- 76 | transform | A Capsian Tansfom Component | Transfom 77 | scene | A Capsian Scene of which the sprite is part of | Scene3D 78 | texture | A texture | texture 79 | """ 80 | 81 | t = TexturedSquare( 82 | transform, 83 | scene, 84 | texture 85 | ) 86 | 87 | self.texture = texture.get_texture() 88 | scene.dynamic_hud.append(t) 89 | -------------------------------------------------------------------------------- /Capsian/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.audio import * 55 | from Capsian.components import * 56 | from Capsian.entities import * 57 | from Capsian.GUI import * 58 | from Capsian.input import * 59 | from Capsian.texturing import * 60 | from Capsian.types import * 61 | from Capsian.values import * 62 | from Capsian.log import Log, TermColor 63 | from Capsian.video import * 64 | from Capsian.world import * 65 | 66 | import Capsian.engine as engine 67 | from pyglet.window import key as Key 68 | -------------------------------------------------------------------------------- /Capsian/audio/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.audio.music import Track 55 | from Capsian.audio.sound import DirectionalSound 56 | -------------------------------------------------------------------------------- /Capsian/audio/music.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | import pyglet 55 | 56 | 57 | class Track: 58 | """ 59 | A track object is an abstract object which reproduces music or sounds. 60 | A track object has not position in 3D space and does not support directional sound. 61 | It can be used to create background music or play non-directional sounds like a menu button being clicked. 62 | """ 63 | 64 | 65 | # ------------------------- 66 | # 67 | # DUNDERSCORE 68 | # 69 | # ------------------------- 70 | 71 | def __init__(self, file: str, streaming: bool): 72 | """ 73 | Parameters 74 | ---------- 75 | file | The file path of the track | str 76 | """ 77 | 78 | self.file = file 79 | self.streaming = streaming 80 | self.audio = pyglet.resource.media(file, streaming=streaming) 81 | 82 | 83 | # When the object is called 84 | def __call__(self) -> None: 85 | return self.play() 86 | 87 | 88 | # ------------------------- 89 | # 90 | # PUBLIC METHODS 91 | # 92 | # ------------------------- 93 | 94 | # Plays the track 95 | def play(self) -> None: 96 | self.audio.play() 97 | -------------------------------------------------------------------------------- /Capsian/audio/sound.py: -------------------------------------------------------------------------------- 1 | ## ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.components.component import Component 55 | import Capsian.engine as engine 56 | import pyglet 57 | 58 | 59 | class DirectionalSound(Component): 60 | """ 61 | A Directional Sound object is an abstract object that can reproduce sound coming from a direction. 62 | The direction is automatically calculated thanks to pyglet.media.Player(). 63 | CURRENTLY INCOMPLETE! 64 | """ 65 | 66 | 67 | # ------------------------- 68 | # 69 | # DUNDERSCORE 70 | # 71 | # ------------------------- 72 | 73 | def __init__(self, file: str): 74 | """ 75 | Parameters 76 | ---------- 77 | file | The file path to the sound file | str 78 | """ 79 | 80 | self.player = pyglet.media.player.Player() 81 | self.player.position = self.parent.transform.position 82 | self.file = file 83 | 84 | 85 | # Dunderscore method 86 | def __call__(self) -> None: 87 | """ 88 | When the object is called it plays a sound 89 | This method handles the call 90 | """ 91 | 92 | return self.play() 93 | 94 | 95 | # ------------------------- 96 | # 97 | # PUBLIC METHODS 98 | # 99 | # ------------------------- 100 | 101 | # Plays the audio 102 | def play(self) -> None: 103 | self.player.queue(pygletmedia.load(self.file, streaming=False)) 104 | self.player.play() 105 | -------------------------------------------------------------------------------- /Capsian/components/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributioans of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.components.component import Component 55 | from Capsian.components.character_controller import CharacterController 56 | from Capsian.components.transform import Transform 57 | from Capsian.components.light import Light, AmbientLight, DiffusedLight, SpecularLight 58 | from Capsian.components.script import Script 59 | -------------------------------------------------------------------------------- /Capsian/components/character_controller.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributioans of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.components.component import Component 55 | from Capsian.log import Log 56 | from Capsian.values import CPSN_PERSPECTIVE_CAMERA 57 | import Capsian.engine as engine 58 | import Capsian.maths.math as kmath 59 | import math 60 | 61 | 62 | class CharacterController(Component): 63 | """ 64 | A Character Controller surves a very important function: moving and rotating the camera. 65 | It does so via commands sent by your code nad by the engine itself. 66 | 67 | Fields 68 | ------ 69 | multiplier | The sensibility multiplier factor | float 70 | dividend | The movement dividend factor | float 71 | sens | The mouse sensibility | float 72 | speed | The movement speed | float 73 | 74 | Methods 75 | ------- 76 | rotate | Rotates the parent object 77 | move | moves the parent object in the specified direction 78 | """ 79 | 80 | # ------------------------- 81 | # 82 | # DUNDERSCORE 83 | # 84 | # ------------------------- 85 | 86 | def __init__(self): 87 | self.multiplier = 50.00 88 | self.dividend = 10.00 89 | self.sens = 1.000 90 | self.speed = 0.100 91 | self.s = 0.000 92 | 93 | super().__init__() 94 | 95 | 96 | def __repr__(self): 97 | return "character_controller" 98 | 99 | 100 | # ------------------------- 101 | # 102 | # EVENT HANDLERS 103 | # 104 | # ------------------------- 105 | 106 | def on_ready(self, time) -> None: 107 | if not isinstance(self.parent, CPSN_PERSPECTIVE_CAMERA): 108 | Log.critical("You are trying to add a CharacterController Component to an object that is not CPSN_PERSPECTIVE_CAMERA compatible") 109 | return 110 | 111 | 112 | def on_update(self, dt: float, time) -> None: 113 | self.s = dt * self.multiplier * engine.main_window.alive 114 | 115 | self.parent.rotY = -self.parent.components.transform.rotY / 180 * math.pi 116 | 117 | self.parent.dx = self.s * math.sin(self.parent.rotY) 118 | self.parent.dz = self.s * math.cos(self.parent.rotY) 119 | 120 | 121 | def rotate(self) -> None: 122 | self.parent.components.transform.rotX += self.parent.mouse_dy * self.sens 123 | self.parent.components.transform.rotY -= self.parent.mouse_dx * self.sens 124 | 125 | self.parent.components.transform.rotX = kmath.clamp(90, -90, self.parent.components.transform.rotX) 126 | 127 | 128 | def move(self, direction: str) -> None: 129 | if direction == "forwards": 130 | self.parent.components.transform.x += self.parent.dx * self.speed * engine.main_window.alive 131 | self.parent.components.transform.z -= self.parent.dz * self.speed * engine.main_window.alive 132 | 133 | if direction == "backwards": 134 | self.parent.components.transform.x -= self.parent.dx * self.speed * engine.main_window.alive 135 | self.parent.components.transform.z += self.parent.dz * self.speed * engine.main_window.alive 136 | 137 | if direction == "right": 138 | self.parent.components.transform.x += self.parent.dz * self.speed * engine.main_window.alive 139 | self.parent.components.transform.z += self.parent.dx * self.speed * engine.main_window.alive 140 | 141 | if direction == "left": 142 | self.parent.components.transform.x -= self.parent.dz * self.speed * engine.main_window.alive 143 | self.parent.components.transform.z -= self.parent.dx * self.speed * engine.main_window.alive 144 | 145 | if direction == "down": 146 | self.parent.components.transform.y -= self.parent.dz * self.speed * engine.main_window.alive 147 | 148 | if direction == "up": 149 | self.parent.components.transform.y += self.parent.dz * self.speed * engine.main_window.alive 150 | -------------------------------------------------------------------------------- /Capsian/components/light.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.log import Log 55 | from Capsian.components.component import Component 56 | import pyglet 57 | 58 | 59 | class Light(Component): 60 | """ 61 | A Capsian Light Component allows you to add lights to entities. 62 | It currently uses Old OpenGL, so you can't use more than 8 lights in your game! 63 | 64 | Fields 65 | ------ 66 | type | The light's type 67 | intensity | The light's oclor and intensity | list [R, G, B, A] 68 | light | The OpenGL light (Ex: GL_LIGHT0) 69 | 70 | Properties 71 | ---------- 72 | parent | The light component's parent object 73 | 74 | Methods 75 | ------- 76 | draw | Renders the light object 77 | """ 78 | 79 | # ------------------------- 80 | # 81 | # DUNDERSCORE 82 | # 83 | # ------------------------- 84 | 85 | def __init__(self, gl_light, color: list): 86 | """ 87 | Parameters 88 | ---------- 89 | gl_light | The OpenGL Light value | GL_AMBIENT\GL_DIFFUSE\GL_SPECULAR 90 | color | A list of four values describing the color of the light | list [R, G, B, A] 91 | """ 92 | 93 | from Capsian.values import lights 94 | 95 | super().__init__() 96 | 97 | self.type = gl_light 98 | self.intensity = list(color) 99 | 100 | if not len(lights) > 0: 101 | self.light = pyglet.gl.GL_LIGHT0 102 | Log.error("Unable to create light: All 8 light slots available are taken!") 103 | return 104 | 105 | self.light = lights[0] 106 | lights.pop(0) 107 | 108 | 109 | # ------------------------- 110 | # 111 | # EVENT HANDLERS 112 | # 113 | # ------------------------- 114 | 115 | def on_ready(self, time) -> None: 116 | pyglet.gl.glEnable(self.light) 117 | self.parent.scene.lights.append(self) 118 | self.parent.scene.drawable.append(self) 119 | 120 | 121 | # ------------------------- 122 | # 123 | # PUBLIC METHODS 124 | # 125 | # ------------------------- 126 | 127 | # Draw the light 128 | def draw(self) -> None: 129 | """ 130 | Description 131 | ----------- 132 | This method is responsible for rendering the light in the scene. 133 | This method takes no paramters and should not ba called outside of the internal rendering functions 134 | """ 135 | 136 | pyglet.gl.glLightfv( 137 | self.light, 138 | pyglet.gl.GL_POSITION, 139 | (pyglet.gl.GLfloat * 4) ( 140 | self.parent.components.transform.x, 141 | self.parent.components.transform.y, 142 | self.parent.components.transform.z, 143 | 1 144 | ) 145 | ) 146 | 147 | pyglet.gl.glLightfv( 148 | self.light, 149 | self.type, 150 | (pyglet.gl.GLfloat * 3) ( 151 | self.intensity[0], 152 | self.intensity[1], 153 | self.intensity[2] 154 | ) 155 | ) 156 | 157 | pyglet.gl.glLightfv( 158 | self.light, 159 | pyglet.gl.GL_QUADRATIC_ATTENUATION, 160 | (pyglet.gl.GLfloat * 1) (1) 161 | ) 162 | 163 | 164 | ######################################################################################################################## 165 | 166 | 167 | class AmbientLight(Light): 168 | def __init__(self, color: list): 169 | """ 170 | Parameters 171 | ---------- 172 | color | A list of four values describing the color of the light | list [R, G, B, A] 173 | """ 174 | 175 | from Capsian.values import CPSN_AMBIENT_LIGHT 176 | 177 | super().__init__( 178 | CPSN_AMBIENT_LIGHT, 179 | color 180 | ) 181 | 182 | 183 | class DiffusedLight(Light): 184 | def __init__(self, color: list): 185 | """ 186 | Parameters 187 | ---------- 188 | color | A list of four values describing the color of the light | list [R, G, B, A] 189 | """ 190 | 191 | from Capsian.values import CPSN_DIFFUSE_LIGHT 192 | 193 | super().__init__( 194 | CPSN_AMBIENT_LIGHT, 195 | color 196 | ) 197 | 198 | 199 | class SpecularLight(Light): 200 | def __init__(self, color: list): 201 | """ 202 | Parameters 203 | ---------- 204 | color | A list of four values describing the color of the light | list [R, G, B, A] 205 | """ 206 | 207 | from Capsian.values import CPSN_SPECULAR_LIGHT 208 | 209 | super().__init__( 210 | CPSN_SPECULAR_LIGHT, 211 | color 212 | ) 213 | -------------------------------------------------------------------------------- /Capsian/components/script.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributioans of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.components.component import Component 55 | 56 | 57 | class Script(Component): pass 58 | -------------------------------------------------------------------------------- /Capsian/components/transform.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributioans of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.components.component import Component 55 | 56 | 57 | class Transform(Component): 58 | """ 59 | A Transform is a component that holds date about the position, rotation and size of an object. 60 | It is a standalone component in order to allow for the existance of EmptyObjects with no location, useful 61 | for things like KeyboardInputHandler components that don't need any position, but just an entity to update them. 62 | 63 | Fields 64 | ------ 65 | x | The transform's X position | float 66 | y | The transforms's Y position | float 67 | z | The transform's Z position | float 68 | width | The transform's width | float 69 | height | The transform's height | float 70 | depth | The transform's depth | float 71 | rotX | The transofrm's X rotation | float 72 | rotY | The transform's Y rotation | float 73 | rotZ | The transform's Z rotation | float 74 | dx | The transform's X direction | float 75 | dy | The transform's Y direction | float 76 | dz | The transform's Z rotation | float 77 | 78 | Properties 79 | ---------- 80 | position | The transform's position | list [x, y, z] 81 | size | The transform's size | list [width, height, depth] 82 | rotation | The transform's rotation | list [rotX, rotY, rotZ] 83 | direction | The transform's direction | list [dx, dy, dz] 84 | """ 85 | 86 | # ------------------------- 87 | # 88 | # DUNDERSCORE 89 | # 90 | # ------------------------- 91 | 92 | def __init__(self, x=0, y=0, z=0, width=1, height=1, depth=1, rotX=0, rotY=0, rotZ=0, dx=0, dy=0, dz=0): 93 | self.x = float(x) 94 | self.y = float(y) 95 | self.z = float(z) 96 | 97 | self.width = width 98 | self.height = height 99 | self.depth = depth 100 | 101 | self.rotX = float(rotX) 102 | self.rotY = float(rotY) 103 | self.rotZ = float(rotZ) 104 | 105 | self.dx = float(dx) 106 | self.dy = float(dy) 107 | self.dz = float(dz) 108 | 109 | super().__init__() 110 | 111 | 112 | def __repr__(self): 113 | return "transform" 114 | 115 | 116 | # ------------------------- 117 | # 118 | # DUNDERSCORE 119 | # 120 | # ------------------------- 121 | 122 | @property 123 | def position(self) -> list: 124 | return [self.x, self.y, self.z] 125 | 126 | 127 | @property 128 | def size(self) -> list: 129 | return [self.width, self.height, self.depth] 130 | 131 | 132 | @property 133 | def rotation(self) -> list: 134 | return [self.rotX, self.rotY, self.rotZ] 135 | 136 | 137 | @property 138 | def direction(self) -> list: 139 | return [self.dx, self.dy, self.dz] 140 | -------------------------------------------------------------------------------- /Capsian/engine.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.world import Clock 55 | import pyglet 56 | 57 | 58 | # Declare vars 59 | main_window = None 60 | main_camera = None 61 | default_clock = Clock() 62 | 63 | 64 | # Returns a version sting 65 | def version(): 66 | return "Capsian Engine v1.0 #2022.0.1" 67 | 68 | 69 | # Prepares the application 70 | def run(): 71 | from datetime import datetime 72 | import Capsian.services 73 | 74 | if not pyglet.version == "1.5.6": 75 | print("CompatibilityError: Your version of Pyglet is not supported. Please run prepare.py to get the right onw!") 76 | return 77 | 78 | default_clock.entry_points.call(datetime.now()) 79 | pyglet.app.run() 80 | default_clock.exit_points.call(datetime.now()) 81 | pyglet.app.exit() 82 | -------------------------------------------------------------------------------- /Capsian/entities/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | from Capsian.entities.entity import Entity 54 | from Capsian.entities.independent_component import IndependentComponent 55 | from Capsian.entities.cube import Cube 56 | from Capsian.entities.particle_system import Particles3D 57 | from Capsian.entities.square import Square, TexturedSquare, RotatingSquare 58 | -------------------------------------------------------------------------------- /Capsian/entities/cube.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.entities.entity import Entity 55 | from Capsian.components.transform import Transform 56 | import pyglet 57 | 58 | 59 | class Cube(Entity): 60 | """ 61 | A Cube object is 3D Cube. 62 | This object uses Batched rendering for high performance and Capsian materials for texturing. 63 | 64 | Fields 65 | ------ 66 | next_pos | A list of adjacent positions | list 67 | texture | The cube's texture | texture 68 | 69 | Methods 70 | ------- 71 | _add_block | Adds the cube to the scene 72 | """ 73 | 74 | 75 | # ------------------------- 76 | # 77 | # DUNDERSCORE 78 | # 79 | # ------------------------- 80 | 81 | def __init__(self, transform=Transform(), scene=None, material=None): 82 | """ 83 | Parameters 84 | ---------- 85 | transform | A Capsian Transform Component | Transform 86 | scene | A Capsian Scene Object | Scene3D 87 | material | A Capsian Material Object | Material 88 | """ 89 | 90 | super().__init__( 91 | scene=scene, 92 | transform=transform 93 | ) 94 | 95 | self.texture = material.texture 96 | self._add_block( 97 | transform.x, 98 | transform.y, 99 | transform.z 100 | ) 101 | 102 | 103 | # ------------------------- 104 | # 105 | # PRIVATE METHODS 106 | # 107 | # ------------------------- 108 | 109 | # Add faces to batch 110 | def _add_block(self, x: float, y: float, z: float) -> None: 111 | """ 112 | Definition 113 | ---------- 114 | Adds the cube to the scene's world 115 | 116 | Parameters 117 | ---------- 118 | x | The cube's X position | float 119 | y | The cube's Y position | float 120 | z | The cube's Z position | float 121 | """ 122 | 123 | X, Y, Z = x + self.components.transform.width, \ 124 | y + self.components.transform.height, \ 125 | z + self.components.transform.depth 126 | 127 | tex_coords = ('t2f', (0, 0, 1, 0, 1, 1, 0, 1)) 128 | 129 | # Back 130 | self.scene.batch.add( 131 | 4, 132 | pyglet.gl.GL_QUADS, 133 | self.texture, 134 | ( 135 | 'v3f', 136 | ( 137 | X, y, z, 138 | x, y, z, 139 | x, Y, z, 140 | X, Y, z 141 | ) 142 | ), 143 | tex_coords 144 | ) 145 | 146 | # Front 147 | self.scene.batch.add( 148 | 4, 149 | pyglet.gl.GL_QUADS, 150 | self.texture, 151 | ( 152 | 'v3f', 153 | ( 154 | x, y, Z, 155 | X, y, Z, 156 | X, Y, Z, 157 | x, Y, Z 158 | ) 159 | ), 160 | tex_coords 161 | ) 162 | 163 | # Left 164 | self.scene.batch.add( 165 | 4, 166 | pyglet.gl.GL_QUADS, 167 | self.texture, 168 | ( 169 | 'v3f', 170 | ( 171 | x, y, z, 172 | x, y, Z, 173 | x, Y, Z, 174 | x, Y, z 175 | ) 176 | ), 177 | tex_coords 178 | ) 179 | 180 | # Right 181 | self.scene.batch.add( 182 | 4, 183 | pyglet.gl.GL_QUADS, 184 | self.texture, 185 | ( 186 | 'v3f', 187 | ( 188 | X, y, Z, 189 | X, y, z, 190 | X, Y, z, 191 | X, Y, Z 192 | ) 193 | ), 194 | tex_coords 195 | ) 196 | 197 | # Bottom 198 | self.scene.batch.add( 199 | 4, 200 | pyglet.gl.GL_QUADS, 201 | self.texture, 202 | ( 203 | 'v3f', 204 | ( 205 | x, y, z, 206 | X, y, z, 207 | X, y, Z, 208 | x, y, Z 209 | ) 210 | ), 211 | tex_coords 212 | ) 213 | 214 | # Top 215 | self.scene.batch.add( 216 | 4, 217 | pyglet.gl.GL_QUADS, 218 | self.texture, 219 | ( 220 | 'v3f', 221 | ( 222 | x, Y, Z, 223 | X, Y, Z, 224 | X, Y, z, 225 | x, Y, z 226 | ) 227 | ), 228 | tex_coords 229 | ) 230 | -------------------------------------------------------------------------------- /Capsian/entities/independent_component.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.entities.entity import Entity 55 | 56 | 57 | class IndependentComponent(Entity): 58 | """ 59 | An IndependentComponent object allows you to add components to an empty entity more easily. 60 | Where you would normallly have to create an Entity, assign it a transform etc etc... You can just create one of these and go 61 | """ 62 | 63 | # ------------------------- 64 | # 65 | # DUNDERSCORE 66 | # 67 | # ------------------------- 68 | 69 | def __init__(self, component): 70 | super().__init__(active=True) 71 | 72 | self.components.component()(component) 73 | -------------------------------------------------------------------------------- /Capsian/entities/particle_system.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.entities.entity import Entity 55 | from Capsian.components.transform import Transform 56 | from Capsian.entities.square import RotatingSquare 57 | import Capsian.engine as engine 58 | import pyglet 59 | import random 60 | 61 | 62 | class Particle(Entity): 63 | """ 64 | Fields 65 | ------ 66 | dead | The timer for the destruction | int 67 | quads | The lsit of quads that are currently being rendered in the Particle | list [Square] 68 | amount | The amount of quads in the Particle | int 69 | duration | The duration of the effect | float 70 | 71 | Methods 72 | ------- 73 | move | Moves the particles in the designated direction 74 | """ 75 | 76 | # ------------------------- 77 | # 78 | # DUNDERSCORE 79 | # 80 | # ------------------------- 81 | 82 | def __init__(self, transform=Transform(), amount=4, duration=240, scene=None): 83 | """ 84 | Parameters 85 | ---------- 86 | transform | A Capsian Transform Object | Transform 87 | amount | The amount of particles to be generated | int 88 | duration | The duration of the effect | int 89 | scene | The Capsian Scene of which the particles are part of | Scene3D 90 | """ 91 | 92 | super().__init__( 93 | transform, 94 | scene, 95 | False 96 | ) 97 | 98 | self.dead = 0 99 | self.quads = list() 100 | self.amount = int(amount) 101 | self.duration = float(duration) 102 | 103 | self.create( 104 | amount, 105 | self.components.transform.position, 106 | self.components.transform.size 107 | ) 108 | 109 | 110 | # Move the particle 111 | def move(self, dx: float, dy: float, dz: float, dt: float) -> None: 112 | for quad in self.quads: 113 | quad.components.transform.x += dx * dt 114 | quad.components.transform.y += dy * dt 115 | quad.components.transform.z += dz * dt 116 | 117 | 118 | ##################################################################################################################################################################################################################################################################### 119 | 120 | 121 | class Particles3D(Particle): 122 | """ 123 | Methods 124 | ------- 125 | kill | kills all the quds in the particle 126 | check | Checks the state of all a quad in the particle 127 | create | Creates the particles 128 | destroy | Destroyes the object 129 | """ 130 | 131 | 132 | # ------------------------- 133 | # 134 | # PUBLIC METHODS 135 | # 136 | # ------------------------- 137 | 138 | # Kill function 139 | def kill(self) -> None: 140 | self.dead = 0 141 | pyglet.clock.unschedule(self.check) 142 | pyglet.clock.unschedule(self.destroy) 143 | 144 | for quad in self.quads: 145 | quad.delete() 146 | 147 | del self 148 | 149 | 150 | # Check function 151 | def check(self, dt: float) -> None: 152 | if not self.dead < self.duration: 153 | self.kill() 154 | 155 | self.move( 156 | dx=self.components.transform.dx, 157 | dy=self.components.transform.dy, 158 | dz=self.components.transform.dz, 159 | dt=dt 160 | ) 161 | 162 | 163 | # Create particles 164 | def create(self, quantity: int, pos: list, size: list) -> None: 165 | from Capsian import Transform 166 | 167 | for _ in range(quantity): 168 | x = pos[0] + random.uniform(-size[0] * 2, size[2] * 2) 169 | y = pos[1] + random.uniform(-size[0] , size[2] / 2) 170 | z = pos[2] + random.uniform( size[0] * 2, size[2] * 2) 171 | 172 | p = RotatingSquare( 173 | Transform( 174 | x, y, z, 175 | size[0], size[1], size[2] 176 | ), 177 | self.scene, 178 | False 179 | ) 180 | 181 | self.quads.append(p) 182 | 183 | engine.default_clock.Schedule.call_every_tick(self.check) 184 | engine.default_clock.Schedule.call_with_interval(self.destroy, 1) 185 | 186 | 187 | def destroy(self, dt: float) -> None: 188 | if self.dead < self.duration: 189 | self.dead += 1 190 | -------------------------------------------------------------------------------- /Capsian/input/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.input.keyboard import KeyboardInputHandler 55 | from Capsian.input.mouse import MouseInputHandler 56 | -------------------------------------------------------------------------------- /Capsian/input/keyboard.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | 55 | from Capsian.components.component import Component 56 | from pyglet.window import key as Key 57 | import Capsian.engine as engine 58 | 59 | 60 | class KeyboardInputHandler(Component): 61 | """ 62 | Fields 63 | ------ 64 | pressed_key | The currently pressed key (key held) | Pyglet Key State Handler 65 | key_state_handler | The Key State Handler for the object | CapsianKeyStateHandlerObject 66 | 67 | Methods 68 | ------- 69 | on_key_pressed | What happens when a key is pressed 70 | on_key_released | What happens when a key is released 71 | on_key_held | What happens when a key is held down 72 | """ 73 | 74 | 75 | # ------------------------- 76 | # 77 | # DUNDERSCORE 78 | # 79 | # ------------------------- 80 | 81 | def __init__(self): 82 | class CapsianKeyStateHandlerObject(Key.KeyStateHandler): 83 | def __init__(self, parent): 84 | self.parent = parent 85 | super().__init__() 86 | 87 | def on_key_press(self, symbol, modifiers): 88 | self.parent.on_key_pressed(symbol, modifiers) 89 | 90 | def on_key_release(self, symbol, modifiers): 91 | self.parent.on_key_released(symbol, modifiers) 92 | 93 | def __eq__(self, value): 94 | return self.get(value) 95 | 96 | 97 | self.pressed_key = Key.KeyStateHandler() 98 | self.key_state_handler = CapsianKeyStateHandlerObject(self) 99 | 100 | engine.main_window.push_handlers(self.pressed_key) 101 | engine.main_window.push_handlers(self.key_state_handler) 102 | 103 | super().__init__() 104 | 105 | 106 | def __repr__(self): 107 | return "key_listener" 108 | 109 | 110 | # ------------------------- 111 | # 112 | # PUBLIC METHODS 113 | # 114 | # ------------------------- 115 | 116 | def on_key_pressed(self, symbol, modifiers): 117 | """ 118 | Parameters 119 | ---------- 120 | symbol | The key that has been pressed 121 | modifiers | The modifiers that are applied 122 | """ 123 | 124 | pass 125 | 126 | 127 | def on_key_released(self, symbol, modifiers): 128 | """ 129 | Parameters 130 | ---------- 131 | symbol | The key that has been pressed 132 | modifiers | The modifiers that are applied 133 | """ 134 | 135 | pass 136 | 137 | 138 | def on_key_held(self, keys): 139 | """ 140 | Parameters 141 | ---------- 142 | keys | The keys that have been pressed | dict 143 | """ 144 | 145 | pass 146 | 147 | 148 | # ------------------------- 149 | # 150 | # EVENT HANDLERS 151 | # 152 | # ------------------------- 153 | 154 | def on_update(self, dt, time): 155 | self.on_key_held(self.pressed_key) 156 | 157 | -------------------------------------------------------------------------------- /Capsian/input/mouse.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.components.component import Component 55 | import Capsian.engine as engine 56 | 57 | 58 | class MouseInputHandler(Component): 59 | """ 60 | Fields 61 | ------ 62 | pressed_button | The currently pressed button (button held) | Pyglet Mouse State Handler 63 | mouse_state_handler | The Mouse State Handler for the object | CapsianMouseStateHandlerObject 64 | 65 | Methods 66 | ------- 67 | on_button_pressed | What happens when a button is pressed 68 | on_button_released | What happens when a button is released 69 | on_button_held | What happens when a button is held down 70 | """ 71 | 72 | 73 | # ------------------------- 74 | # 75 | # DUNDERSCORE 76 | # 77 | # ------------------------- 78 | 79 | def __init__(self): 80 | from pyglet.window.mouse import MouseStateHandler 81 | 82 | class CapsianMouseStateHandlerObject(MouseStateHandler): 83 | def __init__(self, parent): 84 | self.parent = parent 85 | super().__init__() 86 | 87 | def on_mouse_press(self, x, y, button, modifiers): 88 | self.parent.on_button_pressed(x, y, button, modifiers) 89 | 90 | def on_mouse_release(self, x, y, button, modifiers): 91 | self.parent.on_button_released(x, y, button, modifiers) 92 | 93 | def __eq__(self, value): 94 | return self[value] 95 | 96 | 97 | self.pressed_button = MouseStateHandler() 98 | self.mouse_state_handler = CapsianMouseStateHandlerObject(self) 99 | 100 | engine.main_window.push_handlers(self.pressed_button) 101 | engine.main_window.push_handlers(self.mouse_state_handler) 102 | 103 | super().__init__() 104 | 105 | 106 | def __repr__(self): 107 | return "mouse_listener" 108 | 109 | 110 | # ------------------------- 111 | # 112 | # PUBLIC METHODS 113 | # 114 | # ------------------------- 115 | 116 | def on_button_pressed(self, x: int, y: int, button, modifiers): 117 | """ 118 | Parameters 119 | ---------- 120 | x | The cursor's X position | int 121 | y | The cursor's Y position | int 122 | button | The button that is being pressed 123 | modifiers | The modifiers applied to the stroke 124 | """ 125 | 126 | pass 127 | 128 | 129 | def on_button_released(self, x: int, y: int, button, modifiers): 130 | """ 131 | Parameters 132 | ---------- 133 | x | The cursor's X position | int 134 | y | The cursor's Y position | int 135 | button | The button that is being pressed 136 | modifiers | The modifiers applied to the stroke 137 | """ 138 | 139 | pass 140 | 141 | 142 | def on_button_held(self, buttons): 143 | """ 144 | Parameters 145 | ---------- 146 | buttons | All the buttons | dict 147 | """ 148 | 149 | pass 150 | 151 | 152 | # ------------------------- 153 | # 154 | # EVENT HANDLERS 155 | # 156 | # ------------------------- 157 | 158 | def on_update(self, dt: float, time): 159 | self.on_button_held(self.pressed_button) 160 | -------------------------------------------------------------------------------- /Capsian/log.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from datetime import datetime 55 | from Capsian import * 56 | from os import system 57 | import sys 58 | 59 | 60 | class TermColor: 61 | """ 62 | Gives colors for the Terminal/Command Prompt 63 | """ 64 | 65 | HEADER = '\033[95m' 66 | OK_BLUE = '\033[94m' 67 | OK_GREEN = '\033[92m' 68 | WARNING = '\033[93m' 69 | FAIL = '\033[91m' 70 | END_COLOR = '\033[0m' 71 | BOLD = '\033[1m' 72 | UNDERLINE = '\033[4m' 73 | 74 | 75 | @staticmethod 76 | def begin(color): 77 | print(color, end="") 78 | 79 | 80 | @staticmethod 81 | def end(): 82 | print(TermColor.END_COLOR, end="") 83 | 84 | 85 | # Returns the time and date 86 | def time(): 87 | now = datetime.now() 88 | return now.strftime("%H:%M:%S") 89 | 90 | 91 | class Log: 92 | """ 93 | Logs the engine's activity. 94 | You can also use this in your Capsian applications if you need to 95 | 96 | Methods 97 | ------- 98 | error | Throws an error in the console 99 | critical | Throws an error screen 100 | warning | Throws a warning in the ocnsole 101 | info | Prints information to the console 102 | successful | Prints information to the console, but in green! 103 | """ 104 | 105 | # Print error 106 | @staticmethod 107 | def error(text): 108 | """ 109 | Description 110 | ----------- 111 | Throws an error in the console 112 | 113 | Parameters 114 | ---------- 115 | text | The text you want to display | str 116 | """ 117 | 118 | print( 119 | f"{TermColor.FAIL} [{time()} ERROR] {text} {TermColor.END_COLOR}" 120 | ) 121 | 122 | # Critical function 123 | @staticmethod 124 | def critical(text): 125 | """ 126 | Description 127 | ----------- 128 | This method allows you to throw an error onto the screen. 129 | It is specifically designed to look like an error screen, but not a OS one. 130 | Once called, the method will automatically disable full-screen and resize the window, so not to worry anyone. 131 | 132 | Parameters 133 | ---------- 134 | text | The text you want to display | str 135 | """ 136 | 137 | try: 138 | # Load all necessary libs 139 | from os import system 140 | from Capsian import Scene2D 141 | from Capsian.values import SkyColor 142 | from Capsian import OrthographicCamera 143 | import Capsian.engine as engine 144 | import pyglet 145 | 146 | engine.main_window.set_fullscreen(False) 147 | 148 | # Prepare window 149 | camera = OrthographicCamera() 150 | 151 | # Setup the Window 152 | SkyColor << [0.0, 0.0, 0.0, 1.0] 153 | engine.main_window.set_viewport(camera) 154 | 155 | engine.main_window.set_caption("Capsian 1.0 - UNSTABLE STATE") 156 | 157 | # Print the error to the console 158 | print(f"{TermColor.FAIL} [{time()} FATAL ERROR] {text} {TermColor.END_COLOR}") 159 | 160 | # Draw the message 161 | error_scene = Scene2D(camera) 162 | 163 | error = pyglet.text.Label( 164 | text=f"{text}\n\nPress ENTER or ESCAPE to terminate the execution of the program.\n_", 165 | font_name="MS Gothic", 166 | font_size=24, 167 | bold=True, 168 | italic=False, 169 | width=engine.main_window.width - 25, 170 | x=10, y=engine.main_window.height, 171 | anchor_x="left", 172 | anchor_y="top", 173 | batch=error_scene.batch, 174 | multiline=True, 175 | color=(0, 255, 0, 255) 176 | ) 177 | except: 178 | print(f"{TermColor.FAIL} [{time()} FATAL ERROR] {text} {TermColor.END_COLOR}") 179 | 180 | try: 181 | from Capsian import engine 182 | engine.main_window.alive = 0 183 | except: 184 | pass 185 | 186 | 187 | # Warning function 188 | @staticmethod 189 | def warning(text): 190 | """ 191 | Description 192 | ----------- 193 | Displays a waning in the console 194 | 195 | Parameters 196 | ---------- 197 | text | The text you want to display | str 198 | """ 199 | 200 | print( 201 | f"{TermColor.WARNING} [{time()} WARNING] {text} {TermColor.END_COLOR}" 202 | ) 203 | 204 | 205 | # Information function 206 | @staticmethod 207 | def info(text): 208 | """ 209 | Description 210 | ----------- 211 | Prints information to the console 212 | 213 | Parameters 214 | ---------- 215 | text | The text you want to display | str 216 | """ 217 | 218 | print( 219 | f"{TermColor.BOLD} [{time()} INFO] {text} {TermColor.END_COLOR}" 220 | ) 221 | 222 | 223 | # Successful function 224 | @staticmethod 225 | def successful(text): 226 | """ 227 | Description 228 | ----------- 229 | Prints information to the console 230 | 231 | Parameters 232 | ---------- 233 | text | The text you want to display | str 234 | """ 235 | 236 | print( 237 | f"{TermColor.OK_GREEN} [{time()} SUCCESSFUL] {text} {TermColor.END_COLOR}" 238 | ) 239 | -------------------------------------------------------------------------------- /Capsian/maths/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | -------------------------------------------------------------------------------- /Capsian/maths/math.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | import math 55 | 56 | 57 | def clamp(maximum, minimum, var): 58 | """ 59 | Description 60 | ----------- 61 | This function clamps the value of a given variable 62 | 63 | Parameters 64 | ---------- 65 | maximum | The maximum value the variable can get to | float 66 | minimum | The minimum value that variable cannot fall through | float 67 | """ 68 | 69 | if var > maximum: 70 | return maximum 71 | 72 | if var < minimum: 73 | return minimum 74 | 75 | return var 76 | -------------------------------------------------------------------------------- /Capsian/services.py: -------------------------------------------------------------------------------- 1 | from Capsian.input.keyboard import KeyboardInputHandler 2 | from Capsian.entities.independent_component import IndependentComponent 3 | from pyglet.window import key as Key 4 | import Capsian.engine as engine 5 | import pyglet 6 | 7 | 8 | @IndependentComponent 9 | class CapsianKeyboardHandler(KeyboardInputHandler): 10 | def on_key_pressed(self, symbol, modifiers): 11 | if not engine.main_window.alive > 0: 12 | if symbol == Key.ESCAPE or symbol == Key.ENTER: 13 | engine.main_window.close() 14 | 15 | return 16 | 17 | if symbol == engine.main_window.fullscreen_key: 18 | import os 19 | 20 | if os.name == "nt": 21 | screen = pyglet.canvas.Screen( 22 | display=engine.main_window.display, 23 | width=engine.main_window.screen.width, 24 | height=engine.main_window.screen.height, 25 | handle=None, 26 | x=0, 27 | y=0 28 | ) 29 | 30 | engine.main_window.set_fullscreen( 31 | not engine.main_window.fullscreen, 32 | screen=screen 33 | ) 34 | 35 | elif os.name is not "nt": 36 | engine.main_window.set_fullscreen( 37 | not engine.main_window.fullscreen 38 | ) 39 | 40 | lock = engine.main_window.mouse_lock 41 | engine.main_window.set_mouse_lock(False) 42 | engine.main_window.set_mouse_lock(lock) 43 | -------------------------------------------------------------------------------- /Capsian/texturing/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.texturing.texture import Texture3D, SmartTexture3D, Image2D 55 | from Capsian.texturing.material import Material 56 | -------------------------------------------------------------------------------- /Capsian/texturing/material.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.texturing.texture import Texture 55 | 56 | 57 | class Material: 58 | # ------------------------- 59 | # 60 | # DUNDERSCORE 61 | # 62 | # ------------------------- 63 | 64 | def __init__(self, texture: Texture): 65 | """ 66 | Parameters 67 | ---------- 68 | texture | A Capsian texture object | Texture3D 69 | """ 70 | 71 | self.texture = texture.get_texture() 72 | -------------------------------------------------------------------------------- /Capsian/texturing/texture.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.log import Log 55 | from Capsian.values import CPSN_DEFAULT_TEXTURE_MODE 56 | import Capsian.types as types 57 | import pyglet 58 | 59 | 60 | class Texture: 61 | # ------------------------- 62 | # 63 | # DUNDERSCORE 64 | # 65 | # ------------------------- 66 | 67 | def __init__(self, file, texture_type, flags=types.FlagList([types.Flag("texture mode", CPSN_DEFAULT_TEXTURE_MODE)])): 68 | self.path = file 69 | self.flags = flags 70 | 71 | 72 | ######################################################################################################################## 73 | 74 | 75 | class Texture3D(Texture): 76 | # ------------------------- 77 | # 78 | # DUNDERSCORE 79 | # 80 | # ------------------------- 81 | 82 | def __init__(self, file, flags=types.FlagList([types.Flag("texture mode", CPSN_DEFAULT_TEXTURE_MODE)])): 83 | """ 84 | Parameters 85 | ---------- 86 | file | The path to the texture file | str 87 | flags | The texture flags | FlagList 88 | """ 89 | 90 | super().__init__(file, "texture3D", flags) 91 | 92 | 93 | # ------------------------- 94 | # 95 | # PUBLIC METHODS 96 | # 97 | # ------------------------- 98 | 99 | # Get the texture group 100 | def get_texture(self): 101 | loaded_texture = pyglet.image.load(self.path).get_texture() 102 | 103 | pyglet.gl.glTexParameterf( 104 | pyglet.gl.GL_TEXTURE_2D, 105 | self.flags["texture mode"][0], self.flags["texture mode"][2] 106 | ) 107 | 108 | pyglet.gl.glTexParameterf( 109 | pyglet.gl.GL_TEXTURE_2D, 110 | self.flags["texture mode"][1], self.flags["texture mode"][2] 111 | ) 112 | 113 | Log.successful(f"Successfully loaded texture from file '{self.path}'") 114 | return pyglet.graphics.TextureGroup(loaded_texture) 115 | 116 | 117 | class SmartTexture3D(Texture): 118 | # ------------------------- 119 | # 120 | # DUNDERSCORE 121 | # 122 | # ------------------------- 123 | 124 | def __init__(self, file, transform, flags=types.FlagList([types.Flag("texture mode", CPSN_DEFAULT_TEXTURE_MODE)])): 125 | """ 126 | Parameters 127 | ---------- 128 | file | The path to the texture file | str 129 | flags | The texture flags | FlagList 130 | """ 131 | 132 | super().__init__(file=file, texture_type="smartTexture3D", flags=flags) 133 | self.pos = transform.position 134 | self.size = transform.size 135 | 136 | 137 | # ------------------------- 138 | # 139 | # PUBLIC METHODS 140 | # 141 | # ------------------------- 142 | 143 | def get_texture(self): 144 | loaded_texture = pyglet.image.load(self.path).get_region( 145 | self.pos[0], 146 | self.pos[1], 147 | self.size[0], 148 | self.size[1] 149 | ).get_texture() 150 | 151 | pyglet.gl.glTexParameterf( 152 | pyglet.gl.GL_TEXTURE_2D, 153 | self.flags["texture mode"][0], self.flags["texture mode"][2] 154 | ) 155 | 156 | pyglet.gl.glTexParameterf( 157 | pyglet.gl.GL_TEXTURE_2D, 158 | self.flags["texture mode"][1], self.flags["texture mode"][2] 159 | ) 160 | 161 | Log.successful(f"Successfully loaded texture from file '{self.path}'") 162 | return pyglet.graphics.TextureGroup(loaded_texture) 163 | 164 | 165 | class Image2D: 166 | # ------------------------- 167 | # 168 | # DUNDERSCORE 169 | # 170 | # ------------------------- 171 | 172 | def __init__(self, file): 173 | self.path = file 174 | self.image = self.get_image() 175 | 176 | 177 | # ------------------------- 178 | # 179 | # PUBLIC METHODS 180 | # 181 | # ------------------------- 182 | 183 | def get_image(self): 184 | loaded_image = pyglet.image.load(self.path) 185 | Log.successful(f"Successfully loaded image from file '{path}'") 186 | return loaded_image 187 | 188 | 189 | def get_texture(self): 190 | return self.image.get_texture() 191 | -------------------------------------------------------------------------------- /Capsian/types/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.types.object_array import LimitedLenghtObjectArray 55 | from Capsian.types.flag import Flag 56 | from Capsian.types.flag_list import FlagList 57 | -------------------------------------------------------------------------------- /Capsian/types/flag.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.log import Log 55 | 56 | 57 | class Flag: 58 | # ------------------------- 59 | # 60 | # DUNDERSCORE 61 | # 62 | # ------------------------- 63 | 64 | def __init__(self, name, value): 65 | self.value = value 66 | self.name = name 67 | 68 | 69 | def __repr__(self): 70 | return "flag" 71 | 72 | 73 | # ------------------------- 74 | # 75 | # PUBLIC METHODS 76 | # 77 | # ------------------------- 78 | 79 | def set(self, value): 80 | self.value = value 81 | -------------------------------------------------------------------------------- /Capsian/types/flag_list.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.log import Log 55 | 56 | 57 | class FlagList(dict): 58 | # ------------------------- 59 | # 60 | # DUNDERSCORE 61 | # 62 | # ------------------------- 63 | 64 | def __init__(self, iterable): 65 | self.names = [] 66 | self.values = [] 67 | 68 | for i in iterable: 69 | self.append(i) 70 | 71 | 72 | def __getitem__(self, key): 73 | if key in self.names: 74 | return dict.get(self, key) 75 | 76 | 77 | def __delitem__(self, key): 78 | if key in self.names: 79 | self.names.pop(key) 80 | self.values.remove(self[key]) 81 | 82 | 83 | def __setitem__(self, key, value): 84 | if key not in self.names: 85 | dict.__setitem__(self, key, value) 86 | self.names.append(key) 87 | self.values.append(value) 88 | 89 | 90 | # ------------------------- 91 | # 92 | # PUBLIC METHODS 93 | # 94 | # ------------------------- 95 | 96 | def pop(self, key): 97 | if key in self.names: 98 | self.__delitem__(key) 99 | 100 | 101 | def append(self, flag): 102 | if flag not in self.items(): 103 | self.__setitem__(flag.name, flag.value) 104 | -------------------------------------------------------------------------------- /Capsian/types/object_array.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.log import Log 55 | 56 | 57 | class LimitedLenghtObjectArray(list): 58 | # ------------------------- 59 | # 60 | # DUNDERSCORE 61 | # 62 | # ------------------------- 63 | 64 | def __init__(self, max_size=128, auto_clear=False): 65 | self.max_size = int(max_size) 66 | self.auto_clear = bool(auto_clear) 67 | 68 | 69 | # ------------------------- 70 | # 71 | # PUBLIC METHODS 72 | # 73 | # ------------------------- 74 | 75 | def append(self, object): 76 | if len(self) < self.max_size: 77 | list.append(self, object) 78 | 79 | elif self.auto_clear: 80 | self.clear() 81 | 82 | else: 83 | Log.error(f"Cannot add more than {self.max_size} objects to LimitedLenghtObjectArray") 84 | -------------------------------------------------------------------------------- /Capsian/values.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.video.sky_color import SkyColorClass 55 | from Capsian.video.scene import Scene, Scene3D, Scene2D, OverlayScene, PlaceholderScene 56 | from Capsian.video.camera import PerspectiveCamera, OrthographicCamera, Camera 57 | from Capsian.components.component import Component 58 | import pyglet 59 | 60 | 61 | CPSN_DEFAULT_DELTA_TIME = 1/120 62 | CPSN_DEFAULT_TEXTURE_MODE = [pyglet.gl.GL_TEXTURE_MIN_FILTER, pyglet.gl.GL_TEXTURE_MAG_FILTER, pyglet.gl.GL_NEAREST] 63 | CPSN_SMART_TEXTURE = True 64 | CPSN_NORMAL_TEXTURE = False 65 | CPSN_AUTO_SIZE = None 66 | CPSN_STANDARD_SCENE = Scene 67 | CPSN_3D_SCENE = Scene3D 68 | CPSN_GUI_SCENE = Scene2D 69 | CPSN_HUD_SCENE = OverlayScene 70 | CPSN_USELESS_SCENE = PlaceholderScene 71 | CPSN_AMBIENT_LIGHT = pyglet.gl.GL_AMBIENT 72 | CPSN_DIFFUSE_LIGHT = pyglet.gl.GL_DIFFUSE 73 | CPSN_SPECULAR_LIGHT = pyglet.gl.GL_SPECULAR 74 | CPSN_LIGHTING = "if mode == 'enable':\n\tglEnable(GL_LIGHTING)\n\tself.lighting = True\nelse:\n\tglDisable(GL_LIGHTING)\n\tself.lighting = False" 75 | CPSN_DEFAULT_FOG_COLOR = [0.5, 0.69, 1.0, 1] 76 | CPSN_DEFAULT_CLEAR_COLOR = [0.5, 0.65, 1.0, 1.0] 77 | CPSN_STANDARD_CAMERA = Camera 78 | CPSN_PERSPECTIVE_CAMERA = PerspectiveCamera 79 | CPSN_ORTHOGRAPHIC_CAMERA = OrthographicCamera 80 | CPSN_COMPONENT = Component 81 | CPSN_DEFAULT_FOG_START = 40 82 | CPSN_DEFAULT_FOG_END = 50 83 | CPSN_FLOAT_COLOR = "glf" 84 | CPSN_BYTE_COLOR = "rgb" 85 | 86 | 87 | class Direction: 88 | UP = "up" 89 | DOWN = "down" 90 | FOWARDS = "forwards" 91 | BACKWARDS = "backwards" 92 | LEFT = "left" 93 | RIGHT = "right" 94 | 95 | class Vector: 96 | UP = [ 0.0, 0.1, 0.0 ] 97 | DOWN = [ 0.0, -0.1, 0.0 ] 98 | LEFT = [ 0.1, 0.0, 0.0 ] 99 | RIGHT = [-0.1, 0.0, 0.0 ] 100 | FORWANRDS = [ 0.0, 0.0, 0.1 ] 101 | BACKWARDS = [ 0.0, 0.0, -0.1 ] 102 | 103 | 104 | class MouseButton: 105 | LEFT = 1 << 0 106 | MIDDLE = 1 << 1 107 | RIGHT = 1 << 2 108 | 109 | 110 | lights = [ 111 | pyglet.gl.GL_LIGHT0, 112 | pyglet.gl.GL_LIGHT1, 113 | pyglet.gl.GL_LIGHT2, 114 | pyglet.gl.GL_LIGHT3, 115 | pyglet.gl.GL_LIGHT4, 116 | pyglet.gl.GL_LIGHT5, 117 | pyglet.gl.GL_LIGHT6, 118 | pyglet.gl.GL_LIGHT7, 119 | ] 120 | 121 | SkyColor = SkyColorClass() 122 | -------------------------------------------------------------------------------- /Capsian/video/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.video.camera import PerspectiveCamera, OrthographicCamera 55 | from Capsian.video.fog import Fog 56 | from Capsian.video.fps_counter import FPSCounter 57 | from Capsian.video.scene import Scene2D, Scene3D, PlaceholderScene, OverlayScene 58 | from Capsian.video.sky_color import SkyColorClass 59 | from Capsian.video.window import Window3D 60 | -------------------------------------------------------------------------------- /Capsian/video/bluefire/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | -------------------------------------------------------------------------------- /Capsian/video/bluefire/basic.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | # Oh, why are you here? 55 | # What is BlueFire? 56 | # Well, if you know Capsian, then you probably used it at least once 57 | # So if you used it, then why is this file empty? 58 | # Well, because BlueFire's code currently does not have a single location 59 | # It is defined and declared in many different files and classes, but sonn this will change 60 | # Get ready for the big clean up! 61 | -------------------------------------------------------------------------------- /Capsian/video/fog.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | import pyglet 55 | 56 | 57 | class Fog: 58 | # ------------------------- 59 | # 60 | # DUNDERSCORE 61 | # 62 | # ------------------------- 63 | 64 | def __init__(self, color: list, start: float, end: float): 65 | self.color = color 66 | self.start = float(start) 67 | self.end = float(end) 68 | 69 | self.enable(color, start, end) 70 | 71 | 72 | # ------------------------- 73 | # 74 | # STATIC METHODS 75 | # 76 | # ------------------------- 77 | 78 | @staticmethod 79 | def enable(color: list, start: float, end: float) -> None: 80 | pyglet.gl.glEnable(pyglet.gl.GL_FOG) 81 | 82 | pyglet.gl.glFogfv( 83 | pyglet.gl.GL_FOG_COLOR, 84 | (pyglet.gl.GLfloat * 4) ( 85 | color[0], 86 | color[1], 87 | color[2], 88 | color[3] 89 | ) 90 | ) 91 | 92 | pyglet.gl.glHint( 93 | pyglet.gl.GL_FOG_HINT, 94 | pyglet.gl.GL_NICEST 95 | ) 96 | 97 | pyglet.gl.glFogf( 98 | pyglet.gl.GL_FOG_MODE, 99 | pyglet.gl.GL_LINEAR 100 | ) 101 | 102 | pyglet.gl.glFogf( 103 | pyglet.gl.GL_FOG_START, 104 | float(start) 105 | ) 106 | 107 | pyglet.gl.glFogf( 108 | pyglet.gl.GL_FOG_END, 109 | float(end) 110 | ) 111 | 112 | 113 | @staticmethod 114 | def disable() -> None: 115 | pyglet.gl.glDisable(GL_FOG) 116 | -------------------------------------------------------------------------------- /Capsian/video/fps_counter.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | class FPSCounter: 55 | """ 56 | A self-updating label on the screen that displays the currnt framerate 57 | 58 | Fields 59 | ------ 60 | scene | The scene of which the object is part of | OverlayScene 61 | label | The actual label | Label3D 62 | """ 63 | 64 | # ------------------------- 65 | # 66 | # DUNDERSCORE 67 | # 68 | # ------------------------- 69 | 70 | def __init__(self, scene): 71 | """ 72 | Parameters 73 | ---------- 74 | scene | The scene of which the object is part of | OverlayScene 75 | """ 76 | 77 | from Capsian.components.transform import Transform 78 | from Capsian.GUI.label import Label3D 79 | from Capsian.world.format import Color 80 | 81 | self.scene = scene 82 | self.label = Label3D( 83 | font="Calibri", 84 | font_size=48, 85 | transform=Transform(0, 0, 0, None, None), 86 | text=self.get_pyglet_fps, 87 | color=Color(255, 255, 255).rgba, 88 | scene=scene 89 | ) 90 | 91 | 92 | # ------------------------- 93 | # 94 | # PUBLIC METHODS 95 | # 96 | # ------------------------- 97 | 98 | def get_fps(self): 99 | return float(self.label.text) 100 | 101 | 102 | def get_pyglet_fps(self): 103 | import pyglet 104 | return round(float(pyglet.clock.get_fps())) 105 | -------------------------------------------------------------------------------- /Capsian/video/scene.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.log import Log 55 | import Capsian.types as types 56 | import pyglet 57 | 58 | 59 | class Scene: 60 | # ------------------------- 61 | # 62 | # DUNDERSCORE 63 | # 64 | # ------------------------- 65 | 66 | def __init__(self, camera): 67 | """ 68 | Parameters 69 | ---------- 70 | camera | A Camera Object | Camera\OrthographicCamera\PerspectiveCamera 71 | """ 72 | 73 | self.camera = camera 74 | self.enabled = False 75 | 76 | # Defines lists of objects 77 | self.batch = pyglet.graphics.Batch() 78 | self.lights = types.LimitedLenghtObjectArray(8.00000, False) 79 | self.stack = types.LimitedLenghtObjectArray(1000.00, False) 80 | self.objects2D = list() 81 | self.drawable = list() 82 | 83 | self.stack.append(camera) 84 | 85 | 86 | class Scene3D(Scene): 87 | # ------------------------- 88 | # 89 | # DUNDERSCORE 90 | # 91 | # ------------------------- 92 | 93 | def __init__(self, camera): 94 | from Capsian.values import CPSN_PERSPECTIVE_CAMERA 95 | 96 | super().__init__(camera) 97 | 98 | if not isinstance(camera, CPSN_PERSPECTIVE_CAMERA): 99 | Log.critical(f"{repr(camera)} is not a valid camera for Scene3D!") 100 | return 101 | 102 | if not self.enable(): 103 | Log.error(f"Could not enable scene {self}") 104 | 105 | 106 | # ------------------------- 107 | # 108 | # PUBLIC METHODS 109 | # 110 | # ------------------------- 111 | 112 | def disable(self) -> bool: 113 | if not self.enabled: 114 | Log.error(f"Scene {self} already disabled") 115 | return False 116 | 117 | self.camera.scenes.remove(self) 118 | return True 119 | 120 | 121 | def enable(self) -> bool: 122 | if self.enabled: 123 | Log.error(f"Scene {self} already enabled") 124 | return False 125 | 126 | self.camera.scenes.append(self) 127 | return True 128 | 129 | 130 | class Scene2D(Scene): 131 | # ------------------------- 132 | # 133 | # DUNDERSCORE 134 | # 135 | # ------------------------- 136 | 137 | def __init__(self, camera): 138 | from Capsian.values import CPSN_ORTHOGRAPHIC_CAMERA 139 | 140 | super().__init__(camera) 141 | 142 | self.dynamic_gui = types.LimitedLenghtObjectArray(200.000, False) 143 | 144 | if not isinstance(camera, CPSN_ORTHOGRAPHIC_CAMERA): 145 | Log.critical(f"{repr(camera)} is not a valid camera for Scene2D!") 146 | return 147 | 148 | if not self.enable(): 149 | Log.error(f"Could not enable scene {self}") 150 | 151 | 152 | # ------------------------- 153 | # 154 | # PUBLIC METHODS 155 | # 156 | # ------------------------- 157 | 158 | def disable(self) -> bool: 159 | if not self.enabled: 160 | Log.error(f"Scene {self} already disabled") 161 | return False 162 | 163 | self.camera.scenes.remove(self) 164 | return True 165 | 166 | 167 | def enable(self) -> bool: 168 | if self.enabled: 169 | Log.error(f"Scene {self} already enabled") 170 | return False 171 | 172 | self.camera.scenes.append(self) 173 | return True 174 | 175 | 176 | class OverlayScene(Scene): 177 | # ------------------------- 178 | # 179 | # DUNDERSCORE 180 | # 181 | # ------------------------- 182 | 183 | def __init__(self, camera): 184 | from Capsian.values import CPSN_HUD_SCENE, CPSN_PERSPECTIVE_CAMERA 185 | 186 | super().__init__(camera) 187 | 188 | self.hud_batch = pyglet.graphics.Batch() 189 | self.dynamic_hud = types.LimitedLenghtObjectArray(30.0000, False) 190 | 191 | if not isinstance(camera, CPSN_PERSPECTIVE_CAMERA): 192 | Log.critical(f"{repr(camera)} is not a valid camera for OverlayScene!") 193 | return 194 | 195 | if not self.enable(): 196 | Log.error(f"Could not enable scene {self}") 197 | 198 | 199 | # ------------------------- 200 | # 201 | # PUBLIC METHODS 202 | # 203 | # ------------------------- 204 | 205 | def disable(self) -> bool: 206 | if not self.enabled: 207 | Log.error(f"Scene {self} already disabled") 208 | return False 209 | 210 | self.camera.hud_scenes.remove(self) 211 | return True 212 | 213 | 214 | def enable(self) -> bool: 215 | if self.enabled: 216 | Log.error(f"Scene {self} already enabled") 217 | return False 218 | 219 | self.camera.hud_scenes.append(self) 220 | return True 221 | 222 | 223 | class PlaceholderScene(Scene): 224 | # ------------------------- 225 | # 226 | # DUNDERSCORE 227 | # 228 | # ------------------------- 229 | 230 | def __init__(self): 231 | from Capsian.values import CPSN_STANDARD_SCENE 232 | super().__init__(None) 233 | -------------------------------------------------------------------------------- /Capsian/video/sky_color.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | class SkyColorClass: 55 | # ------------------------- 56 | # 57 | # DUNDERSCORE 58 | # 59 | # ------------------------- 60 | 61 | def __init__(self): 62 | self.color = [0, 0, 0, 0] 63 | 64 | 65 | def __eq__(self, other) -> None: 66 | self.set(other) 67 | 68 | 69 | def __lshift__(self, other) -> None: 70 | self.set(other) 71 | 72 | 73 | # ------------------------- 74 | # 75 | # PUBLIC METHODS 76 | # 77 | # ------------------------- 78 | 79 | def set(self, color: list) -> None: 80 | import pyglet 81 | 82 | pyglet.gl.glClearColor(color[0], color[1], color[2], color[3]) 83 | self.color = color 84 | -------------------------------------------------------------------------------- /Capsian/world/__init__.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian.world.clock import Clock 55 | from Capsian.world.format import TextureMode, Color 56 | -------------------------------------------------------------------------------- /Capsian/world/clock.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | import pyglet 55 | 56 | 57 | class Clock: 58 | """ 59 | A Capsian Clock isn implementation of pyglet.clock.Clock (pyglet.clock.Clock) 60 | """ 61 | 62 | 63 | def __init__(self): 64 | self.Schedule.call_every_tick(self.tick) 65 | 66 | 67 | class _Points: 68 | """ 69 | A class that holds data about all entry points 70 | """ 71 | 72 | 73 | def __init__(self): 74 | self.functions = [] 75 | 76 | 77 | def __add__(self, func) -> None: 78 | self.add(func) 79 | 80 | 81 | def add(self, func) -> None: 82 | if not self.validate(func): 83 | print("Not a callable object") 84 | return 85 | 86 | self.functions.append(func) 87 | 88 | 89 | def validate(self, func) -> bool: 90 | import types 91 | return isinstance(func, (types.FunctionType, types.MethodType)) 92 | 93 | 94 | def call(self, *args, **kwargs) -> None: 95 | for func in self.functions: 96 | func(*args, **kwargs) 97 | 98 | 99 | class Schedule: 100 | """ 101 | A class that takes care of scheduling using the implementation of a pyglet clock 102 | """ 103 | 104 | 105 | @staticmethod 106 | def call_every_tick(func, *args, **kwargs) -> None: 107 | pyglet.clock.schedule(func, *args, **kwargs) 108 | 109 | 110 | @staticmethod 111 | def call_with_interval(func, interval, *args, **kwargs) -> None: 112 | pyglet.clock.schedule_interval(func, interval, *args, **kwargs) 113 | 114 | 115 | @staticmethod 116 | def unschedule(func) -> None: 117 | pyglet.clock.unschedule(func) 118 | 119 | 120 | @staticmethod 121 | def wait(milliseconds) -> None: 122 | pyglet.clock.time.sleep(milliseconds / 1000) 123 | 124 | 125 | @staticmethod 126 | def loop(**kwargs): 127 | if "interval" not in kwargs.keys(): 128 | kwargs.__setitem__("interval", 0) 129 | 130 | def inner(func): 131 | if not kwargs["interval"] == 0: 132 | Clock.Schedule.call_with_interval(func, **kwargs) 133 | return 134 | 135 | kwargs.pop("interval") 136 | Clock.Schedule.call_every_tick(func, **kwargs) 137 | 138 | return inner 139 | 140 | 141 | entry_points = _Points() 142 | exit_points = _Points() 143 | 144 | 145 | def tick(self, dt: float) -> None: 146 | from Capsian import engine 147 | 148 | for scene in engine.main_camera.scenes: 149 | for obj in scene.stack: 150 | obj.update(dt) 151 | -------------------------------------------------------------------------------- /Capsian/world/format.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | def TextureMode(filter1, filter2, algorithm): 55 | """ 56 | Parameters 57 | ---------- 58 | filter1 | The first filter 59 | filter2 | The second filter 60 | algorithm | The OpnGL algorithm used 61 | """ 62 | 63 | return [filter1, filter2, algorithm] 64 | 65 | 66 | class Color: 67 | """ 68 | Fields 69 | ------ 70 | rgba | The color | list [R, G, B, A] 71 | 72 | Methods 73 | ------- 74 | _convert_to_gl_float_color | Converts a given RGBA color from bytes to float 75 | _convert_to_byte_color | Converts a given RGBA color from float to bytes 76 | """ 77 | 78 | def __init__(self, r=255, g=255, b=255, a=255): 79 | """ 80 | Parameters 81 | ---------- 82 | r | Red channel | int > 0 < 256 83 | g | Green channel | int > 0 < 256 84 | b | Blue channel | int > 0 < 256 85 | a | Alpha channel | int > 0 < 256 86 | """ 87 | 88 | self.rgba = [r, g, b, a] 89 | 90 | 91 | def convert_to(self, to: str): 92 | methods = { 93 | "rgb": self._convert_to_byte_color, 94 | "glf": self._convert_to_gl_float_color, 95 | } 96 | 97 | if not to in methods.keys(): 98 | from Capsian import Log 99 | Log.error(f"'{to}' is not a valid color type") 100 | return 101 | 102 | self.rgba = methods[to]() 103 | 104 | 105 | @property 106 | def _convert_to_gl_float_color(self): 107 | gl_colors = [0, 0, 0, 0] 108 | 109 | for i in range(0, len(self.rgba)): 110 | gl_colors[i] = self.rgba[i] / 255 111 | 112 | return gl_colors 113 | 114 | 115 | @property 116 | def _convert_to_byte_color(self): 117 | byte_colors = [0, 0, 0, 0] 118 | 119 | for i in range(0, len(self.rgba)): 120 | byte_colors[i] = self.rgba[i] * 255 121 | 122 | return byte_colors 123 | -------------------------------------------------------------------------------- /Capsianline/capsianline.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Capsianline 3 | # Copyright 2022 Carpal 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ---------------------------------------------------------------------------- 17 | 18 | 19 | from Capsianline.commands import * 20 | from Capsianline.ccparser import * 21 | import Capsianline.design 22 | import Capsian 23 | 24 | 25 | # Draw the design for the header 26 | Capsianline.design.draw() 27 | 28 | def get_package_list(dir: str): 29 | import os 30 | _dirs = os.listdir(dir) 31 | dirs = [] 32 | 33 | for _dir in _dirs: 34 | if os.path.isdir(f"addons/{_dir}") and _dir: 35 | dirs.append(_dir) 36 | 37 | if "__pycache__" in dirs: 38 | dirs.remove("__pycache__") 39 | 40 | return dirs 41 | 42 | 43 | def command_exists(command: str): 44 | import json 45 | global jsfile 46 | 47 | with open("Capsianline/paths.json", "r") as file: 48 | jsfile = json.loads(file.read()) 49 | 50 | paths = jsfile["PATH"] 51 | 52 | for path in paths: 53 | try: 54 | file = open(f"{path}/{command}/Capsianline.py", "r") 55 | file.close() 56 | return f"{path}/{command}/Capsianline.py" 57 | except: 58 | continue 59 | 60 | return False 61 | 62 | 63 | while True: 64 | try: 65 | # parse the command 66 | parser = Parser(input(f"\n{Capsian.TermColor.FAIL}Capsian${Capsian.TermColor.WARNING} ")) 67 | Capsian.TermColor.end() 68 | 69 | # get the tree 70 | tree = parser.parse() 71 | 72 | # organize .. 73 | command = tree[0] # .. the class 74 | sub_command = tree[1] # .. the method 75 | args = tree[2] # .. the function args 76 | 77 | cmd_exists = command_exists(command) 78 | 79 | if cmd_exists == False: 80 | Capsian.Log.error(f"No such command \"{command}\"") 81 | continue 82 | 83 | __linecommand__ = None 84 | cmdcode = open(cmd_exists, "r") 85 | exec(compile(source=cmdcode.read(), filename="command", mode="exec")) 86 | 87 | if not hasattr(__linecommand__, sub_command): 88 | Capsian.Log.error(f"Command \"{command}\" has no subcommand \"{sub_command}\"") 89 | continue 90 | 91 | getattr(__linecommand__, sub_command)(*args) 92 | cmdcode.close() 93 | except KeyboardInterrupt: 94 | # catch ctrl + c 95 | print("\n\nTerminating program....") 96 | Capsian.TermColor.end() 97 | break 98 | 99 | except Exception as e: 100 | # some errors in the process? let's report it 101 | Capsian.Log.error(e) 102 | -------------------------------------------------------------------------------- /Capsianline/ccerror.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Capsianline 3 | # Copyright 2022 Carpal 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ---------------------------------------------------------------------------- 17 | 18 | 19 | class CCError(Exception): 20 | pass 21 | 22 | def error(msg): 23 | raise CCError(msg) 24 | -------------------------------------------------------------------------------- /Capsianline/cclexer.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Capsianline 3 | # Copyright 2022 Carpal 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ---------------------------------------------------------------------------- 17 | 18 | 19 | from Capsianline.ccerror import error 20 | from unicodedata import category 21 | 22 | 23 | # is a control or a white space (chars to skip) ? like \n \t etc.. 24 | def is_control(char): 25 | return category(char) == "Cc" or str(char).isspace() 26 | 27 | 28 | # is a symbol ? like +-@/()[]{} etc.. 29 | def is_symbol(char): 30 | return category(char) == "Po" or category(char) == "Pd" 31 | 32 | 33 | # token kind 34 | class Token: 35 | # token kinds 36 | VALUE = "" 37 | SYMBOL = "" 38 | EOF = "" 39 | BAD = "" 40 | 41 | 42 | # short ways 43 | def value(value): 44 | return (Token.VALUE, value) 45 | 46 | 47 | def eof(): 48 | return (Token.EOF, None) 49 | 50 | 51 | def bad(): 52 | return (Token.BAD, None) 53 | 54 | 55 | # for errors 56 | # returns a pretty version of the passed token 57 | def pretty_idsym(kind, value): 58 | if kind == Token.VALUE or kind == Token.SYMBOL: 59 | return value.replace('\n', '\\n').replace('\t', '\\t') 60 | 61 | if kind == Token.EOF: 62 | return "end of file" 63 | 64 | if kind == Token.BAD: 65 | return "bad token" 66 | 67 | return kind 68 | 69 | 70 | # returns a pretty version of the passed token kind 71 | def pretty_kind(kind): 72 | if kind == Token.EOF: 73 | return "end of file" 74 | 75 | if kind == Token.BAD: 76 | return "bad token" 77 | 78 | if kind == Token.VALUE: 79 | return "value" 80 | 81 | if kind == Token.SYMBOL: 82 | return "symbol" 83 | 84 | return kind 85 | 86 | 87 | # lexer 88 | class Lexer: 89 | # the command to lex 90 | command = None 91 | 92 | # the current index 93 | index = 0 94 | 95 | # set up 96 | def __init__(self, command) -> None: 97 | self.command = command 98 | 99 | 100 | # checks if there is a next char 101 | def next_exists(self): 102 | return self.index + 1 < len(self.command) 103 | 104 | 105 | # checks if the command text if finished 106 | def reachedEOF(self): 107 | return self.index >= len(self.command) 108 | 109 | 110 | # if the eof has not been exceeded returns the current character otherwise an EOF token 111 | def current(self) -> str: 112 | # not over the eof ? 113 | if not self.reachedEOF(): 114 | # then return the current char 115 | return str(self.command[self.index]) 116 | 117 | # else return a eof token 118 | return str(Token.EOF) 119 | 120 | 121 | # the same of current(), but with the next character instead of the current 122 | def next(self) -> str: 123 | # the current is not the last char in the command text ? 124 | if self.next_exists(): 125 | # then return the next, but remain at the current position 126 | return str(self.command[self.index + 1]) 127 | 128 | return str(Token.EOF) 129 | 130 | 131 | # moves the current position of one 132 | def advance(self): 133 | self.index += 1 134 | 135 | # skips all the escaped characters in the text 136 | def eat_controls(self): 137 | # the current is a valid char and this char is a control ? 138 | while (not self.reachedEOF()) and is_control(self.current()): 139 | # then advice while it is that 140 | self.advance() 141 | 142 | 143 | # called if found an identifier char or a number. collects the entire value and returns it 144 | def collect_value(self): 145 | ident = "" 146 | 147 | while True: 148 | # add the current char to the string 149 | ident += self.current() 150 | 151 | # this is the last char or the next char is not a valid char value ? 152 | if self.reachedEOF() or not self.next().isalnum(): 153 | # then break the collecting 154 | break 155 | 156 | # this char has been collected, let's go to the next 157 | self.advance() 158 | 159 | # return the collected value 160 | return Token.value(ident) 161 | 162 | 163 | # converts a char into its escaped version 164 | def next_escaped(self): 165 | # get the char to convert 166 | char = self.current() 167 | 168 | if char == "\"": return "\"" 169 | if char == "n": return '\n' 170 | if char == "t": return '\t' 171 | if char == "\\": return '\\' 172 | 173 | # this is not a valid escaped char, I don't know what to return, so I raise an error 174 | error(f"invalid escaped char \\{char}") 175 | 176 | 177 | # called after found a quote '. collects the string until it finds another quote or the end of the file 178 | def collect_string(self): 179 | string = "" 180 | 181 | # skip first quote ' 182 | self.advance() 183 | 184 | while True: # do while missing in python, shit! 185 | # match escaped chars 186 | if self.current() == "\\": 187 | # skip the \ espace char 188 | self.advance() 189 | # add to the string the next character converted to a real escaped char 190 | string += self.next_escaped() 191 | else: 192 | # not an escaped char ? add it to the string as a normal char 193 | string += self.current() 194 | 195 | # the user opened the string quote, but he never closed it, this is wrong 196 | if self.reachedEOF(): 197 | error("string opened and never closed") 198 | 199 | # after collected the previously char, move to the next 200 | self.advance() 201 | 202 | # the next was a string quote ? 203 | if self.current() == "\"": 204 | # break the string collecting 205 | break 206 | 207 | # return the string as a value 208 | return Token.value(string) 209 | 210 | 211 | # returns eof if the index is at the end of the file, so there is no char to process 212 | def next_token(self) -> Token: 213 | # skip all controls 214 | self.eat_controls() 215 | 216 | token = None 217 | 218 | # there is not char to process ? 219 | if self.reachedEOF(): 220 | return Token.eof() 221 | 222 | # this char is a num or a letter ? 223 | if self.current().isalnum(): 224 | # then collect it 225 | token = self.collect_value() 226 | 227 | elif self.current() == "\"": 228 | # collect the string 229 | token = self.collect_string() 230 | 231 | # a symbol ? 232 | elif is_symbol(self.current()): 233 | token = (Token.SYMBOL, self.current()) 234 | 235 | # none of the priors? 236 | else: 237 | token = Token.bad() 238 | 239 | # next char 240 | self.advance() 241 | return token 242 | -------------------------------------------------------------------------------- /Capsianline/ccparser.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Capsianline 3 | # Copyright 2022 Carpal 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ---------------------------------------------------------------------------- 17 | 18 | 19 | from Capsianline.cclexer import * 20 | from Capsianline.ccerror import * 21 | 22 | 23 | class Parser: 24 | # the lexer 25 | lexer = None 26 | 27 | def __init__(self, command) -> None: 28 | self.lexer = Lexer(command) 29 | 30 | # expects a token kind 31 | def expect(self, kind): 32 | # take the next token from the lexer 33 | token = self.lexer.next_token() 34 | # token_kind != kind 35 | if token[0] != kind: 36 | error(f"expected {Token.pretty_kind(kind)}, found {Token.pretty_idsym(token[0], token[1])}") 37 | 38 | return token 39 | 40 | # expects an identifier (VALUE) with a specific value 41 | def expect_keyword(self, value): 42 | token = self.lexer.next_token() 43 | # token_kind != VALUE token_value != value 44 | if token[0] != Token.VALUE and token[1] != value: 45 | error(f"expected {Token.pretty_idsym(Token.VALUE, value)}, found {Token.pretty_idsym(token[0], token[1])}") 46 | 47 | return token 48 | 49 | # expects a symbol with a specific value 50 | def expect_symbol(self, value): 51 | # take a token from the lexer 52 | token = self.lexer.next_token() 53 | # token_kind != SYMBOL token_value != value 54 | if token[0] != Token.SYMBOL and token[1] != value: 55 | error(f"expected {Token.pretty_idsym(Token.SYMBOL, value)}, found {Token.pretty_idsym(token[0], token[1])}") 56 | 57 | return token 58 | 59 | # expects an arg, if there is other raise an error 60 | def expect_arg(self): 61 | # when pass an arg there must be the -arg flag 62 | # expect - 63 | 64 | # returns the value of the next token 65 | return self.expect(Token.VALUE)[1] # 1 of a tuple with two elements, the first is the token kind, the second the token value 66 | 67 | # collects all the arguments passed until the file ends 68 | def expect_args(self): 69 | args = [] 70 | 71 | # in this way you can also pass no args and it will work because this cycle will never be ran 72 | # the file is not finished yet ? 73 | while not self.lexer.reachedEOF(): 74 | # then collect the next arg and append it to the others 75 | args.append(self.expect_arg()) 76 | 77 | return args 78 | 79 | # organizes the parsing process 80 | def expect_command(self): 81 | command = self.expect(Token.VALUE)[1] # 1 = second term of the tuple = the value 82 | sub_command = self.expect(Token.VALUE)[1] 83 | args = self.expect_args() 84 | 85 | return (command, sub_command, args) 86 | 87 | # returns a tuple containing (class, method, args) 88 | def parse(self): 89 | return self.expect_command() -------------------------------------------------------------------------------- /Capsianline/commands/command.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | class Command: 55 | def __str__(self) -> str: 56 | return "command" 57 | 58 | def __repr__(self) -> str: 59 | return "A Generic Capsianline Command" 60 | 61 | 62 | def help(self): 63 | method_list = [func for func in dir(self)] 64 | 65 | for method in method_list: 66 | if "__" not in method: 67 | print(f"{self} {method}") 68 | 69 | print(f"\n\n{repr(self)}") 70 | -------------------------------------------------------------------------------- /Capsianline/design.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Capsianline 3 | # Copyright 2022 Carpal 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ---------------------------------------------------------------------------- 17 | 18 | 19 | from Capsian import * 20 | 21 | # Init the program 22 | import os 23 | os.system("cls" if os.name == "nt" else "clear") 24 | 25 | 26 | def draw(): 27 | print("============================================================================") 28 | TermColor.begin(TermColor.OK_BLUE) 29 | print(f"Capsianline v2.0 for {engine.version()}") 30 | print("Capsian: https://github.com/tzyvoski/Capsian-Engine") 31 | print("Capsianline: https://github.com/Carpall/Capsianline", end="\n") 32 | TermColor.end() 33 | -------------------------------------------------------------------------------- /Capsianline/paths.json: -------------------------------------------------------------------------------- 1 | { 2 | "PATH": [ 3 | "./addons/", 4 | "./Capsianline/commands" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Contributors][contributors-shield]][contributors-url] 2 | [![Forks][forks-shield]][forks-url] 3 | [![Stargazers][stars-shield]][stars-url] 4 | [![Issues][issues-shield]][issues-url] 5 | [![MIT License][license-shield]][license-url] 6 | ![](https://tokei.rs/b1/github/Alessandro-Salerno/Capsian-Engine) 7 | 8 | 9 | 10 |

11 |

Capsian Engine

12 | 13 |

14 | Capsian is a weird, incomplete and performant Python game engine. The project was initially named "KeyFire Engine" but was later renamed to Capsian due to trademark related issues. 15 |
16 |
17 | Report Bug || 18 | Request Feature 19 |

20 | 21 | 22 | 23 | ## Table of Contents 24 | 25 | - [About the Project](#performance) 26 | - [Built With](#built-with) 27 | - [Scripting](#scripting) 28 | - [Getting Started](#getting-started) 29 | - [Requirements](#requirements) 30 | - [License](#license) 31 | - [Acknowledgements](#acknowledgements) 32 | 33 | ## Performance 34 | 35 |

Capsian performs quite well, especially when you consider Python's notorious performance issues. In terms of framerate, batched scenes tend to hover around 1000 - 4000 FPS depending on the resolution, while more dynamic scenes can be a bit harder on the CPU, leading to poor performance. 36 |
37 |

38 |
39 |
40 |
41 | Snow 42 |

43 | Forest 44 |
45 | 46 | ### Built With 47 | 48 | - [Python](https://www.python.org/) 49 | - [OpenGL](https://www.opengl.org/) 50 | - [Pyglet](http://pyglet.org/) 51 | 52 | ### Scripting 53 | 54 |

Currently, Python is the only option for Capsian scripting. Scripts are organized in an Object-Oriented fashion, with "Script" classes, input handlers and "IndependentComponent" decorators. All Capsian scripts are handled as entity components, as such, they must be attached to an entity, either manually or automatically via the already mentioned "IndependentComponent" decorator. The Capsian Script Manager can help you set up scripts with little to no effort. 55 |
56 |

57 | 58 | 59 | 60 | ### Requirements 61 | 62 | * A Python installation (3.7.3 Recommended) 63 | * An OpenGL-Compatible Graphics Card 64 | 65 | You can install all dependencies using the `prepare.py` script. 66 | 67 | 68 | 69 | 70 | 71 | ## License 72 | 73 | Distributed under the Apache license 2.0. See `LICENSE` for more information. 74 | 75 | 76 | 77 | 78 | 79 | ## Acknowledgements 80 | 81 | - [Carpal](https://github.com/Carpall) ( for [Capsianline](https://github.com/Carpall/Capsianline) ) 82 | - [Liam](https://github.com/Gyro7) ( for the README) 83 | - [lolloberga](https://github.com/lolloberga?tab=overview&from=2022-03-01&to=2022-03-08) 84 | - [Pyglet](http://pyglet.org/) ( for providing the amazing toolkit used to make Capsian possible ) 85 | - [Myself](https://github.com/tzyvoski) 86 | 87 | [contributors-shield]: https://img.shields.io/github/contributors/tzyvoski/Capsian-Engine.svg?style=flat-square 88 | [contributors-url]: https://github.com/tzyvoski/Capsian-Engine/graphs/contributors 89 | [forks-shield]: https://img.shields.io/github/forks/tzyvoski/Capsian-Engine.svg?style=flat-square 90 | [forks-url]: https://github.com/tzyvoski/Capsian-Engine/network/members 91 | [stars-shield]: https://img.shields.io/github/stars/tzyvoski/Capsian-Engine.svg?style=flat-square 92 | [stars-url]: https://github.com/tzyvoski/Capsian-Engine/stargazers 93 | [issues-shield]: https://img.shields.io/github/issues/tzyvoski/Capsian-Engine.svg?style=flat-square 94 | [issues-url]: https://github.com/tzyvoski/Capsian-Engine/issues 95 | [license-shield]: https://img.shields.io/github/license/tzyvoski/Capsian-Engine.svg?style=flat-square 96 | [license-url]: https://github.com/tzyvoski/Capsian-Engine/blob/master/LICENSE.txt 97 | -------------------------------------------------------------------------------- /addons/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alessandro-Salerno/Capsian-Engine/5df7c61433c835e862b670a0bbd65df2aa82f980/addons/__init__.py -------------------------------------------------------------------------------- /console.py: -------------------------------------------------------------------------------- 1 | # This file is completelly useless, but I couldn't care less 2 | # This is the fastest way to fix command prompt directory issues so.... 3 | 4 | import Capsianline.capsianline 5 | -------------------------------------------------------------------------------- /example/__init__.py: -------------------------------------------------------------------------------- 1 | # Import all your scripts from here 2 | 3 | 4 | import scripts.main 5 | import scripts.data 6 | import scripts.setup 7 | import scripts.movement 8 | import scripts.map_generator 9 | import scripts.time 10 | -------------------------------------------------------------------------------- /example/data.py: -------------------------------------------------------------------------------- 1 | from Capsian import * 2 | 3 | 4 | # Scenes 5 | current_scene: Scene3D 6 | 7 | # Textures 8 | log_tex = Texture3D("assets/textures/oak_log.png") 9 | glass_tex = Texture3D("assets/textures/glass.png") 10 | planks_tex = Texture3D("assets/textures/oak_planks.png") 11 | trapdoor_tex = Texture3D("assets/textures/trapdoor.png") 12 | table_tex = Texture3D("assets/textures/table.png") 13 | glow_tex = Texture3D("assets/textures/glowstone.png") 14 | 15 | # Materials 16 | log_mat = Material(log_tex) 17 | glass_mat = Material(glass_tex) 18 | planks_mat = Material(planks_tex) 19 | trapdoor_mat = Material(trapdoor_tex) 20 | table_mat = Material(table_tex) 21 | glow_mat = Material(glow_tex) 22 | -------------------------------------------------------------------------------- /example/flashing_light.py: -------------------------------------------------------------------------------- 1 | from Capsian import * 2 | import random 3 | 4 | 5 | class FlashingLight(AmbientLight): 6 | def flash(self, *args, **kwargs): 7 | offset = random.uniform(-30, 20) 8 | 9 | if not self.intensity[0] > 0: 10 | self.intensity[0] = 50 11 | self.intensity[1] = 50 12 | return 13 | 14 | if self.intensity[0] + offset > 5: 15 | self.intensity[0] += offset 16 | self.intensity[1] += offset 17 | -------------------------------------------------------------------------------- /example/main.py: -------------------------------------------------------------------------------- 1 | from Capsian import * 2 | 3 | 4 | c = PerspectiveCamera(Transform(0.5, 2.5, 2)) 5 | w = Window3D(c, width=1024, height=680, vsync=False) 6 | w.set_mouse_lock(False) 7 | -------------------------------------------------------------------------------- /example/map_generator.py: -------------------------------------------------------------------------------- 1 | from Capsian import * 2 | 3 | 4 | @IndependentComponent 5 | class Generator(Script): 6 | def gen_window(self, pos: list, size: list) -> None: 7 | import scripts.data as data 8 | 9 | for x in range(size[0]): 10 | for y in range(size[1]): 11 | for z in range(size[2]): 12 | Cube( 13 | Transform( 14 | x=pos[0] + x, 15 | y=pos[1] + y, 16 | z=pos[2] + z, 17 | depth=0.25, 18 | ), 19 | 20 | data.current_scene, 21 | data.glass_mat 22 | ) 23 | 24 | 25 | def gen_flash(self, pos: list) -> None: 26 | from scripts.flashing_light import FlashingLight 27 | import scripts.data as data 28 | entt = Entity( 29 | Transform( 30 | x=pos[0], 31 | y=pos[1], 32 | z=pos[2] 33 | ), 34 | 35 | data.current_scene, 36 | False 37 | ) 38 | light = FlashingLight(Color(50, 50, 0, 255).rgba) 39 | entt.components.add(light) 40 | 41 | Cube( 42 | Transform( 43 | 0.35, 44 | 1.7, 45 | 0.35, 46 | width=0.3, 47 | height=0.3, 48 | depth=0.3 49 | ), 50 | 51 | data.current_scene, 52 | data.log_mat 53 | ) 54 | 55 | Cube( 56 | Transform( 57 | 0.375, 58 | 2, 59 | 0.375, 60 | width=0.25, 61 | height=0.25, 62 | depth=0.25 63 | ), 64 | 65 | data.current_scene, 66 | data.glow_mat 67 | ) 68 | 69 | @engine.default_clock.Schedule.loop(interval = 1/3) 70 | def flash(dt): 71 | light.flash() 72 | 73 | 74 | def gen_floor(self, pos: list, size: list) -> None: 75 | import scripts.data as data 76 | 77 | for x in range(size[0]): 78 | for z in range(size[2]): 79 | Cube( 80 | Transform( 81 | x=pos[0] + x, 82 | y=pos[1], 83 | z=pos[2] + z, 84 | height=size[1] 85 | ), 86 | 87 | data.current_scene, 88 | data.planks_mat 89 | ) 90 | 91 | 92 | def gen_table(self, pos: list) -> None: 93 | import scripts.data as data 94 | 95 | Cube( 96 | Transform( 97 | x=pos[0] + 0.375, 98 | y=pos[1], 99 | z=pos[2] + 0.375, 100 | width=0.25, 101 | height=0.15, 102 | depth=0.25 103 | ), 104 | 105 | data.current_scene, 106 | data.table_mat 107 | ) 108 | 109 | Cube( 110 | Transform( 111 | x=pos[0] + 0.4375, 112 | y=pos[1] + 0.15, 113 | z=pos[2] + 0.4375, 114 | width=0.125, 115 | height=0.75, 116 | depth=0.125 117 | ), 118 | 119 | data.current_scene, 120 | data.table_mat 121 | ) 122 | 123 | Cube( 124 | Transform( 125 | 0.375, 126 | 1, 127 | 0.375, 128 | width=0.25, 129 | height=0.25, 130 | depth=0.25 131 | ), 132 | 133 | data.current_scene, 134 | data.log_mat 135 | ) 136 | 137 | Cube( 138 | Transform( 139 | x=pos[0], 140 | y=pos[1] + 0.75 + 0.15, 141 | z=pos[2], 142 | height=0.3 143 | ), 144 | 145 | data.current_scene, 146 | data.table_mat 147 | ) 148 | 149 | 150 | def on_start(self, time) -> None: 151 | import scripts.data as data 152 | self.gen_flash([0.5, 1.5, 0.5]) 153 | self.gen_floor([-1, 0, -1], [3, 0.5, 3]) 154 | self.gen_table([0, 0.5, 0]) 155 | -------------------------------------------------------------------------------- /example/movement.py: -------------------------------------------------------------------------------- 1 | from Capsian import * 2 | 3 | 4 | @engine.main_camera.components.component() 5 | class Movement(KeyboardInputHandler): 6 | 7 | # Create and add character controller when started 8 | def on_start(self, time) -> None: 9 | class CC(CharacterController): 10 | def __init__(self): 11 | super().__init__() 12 | self.speed = 0.005 13 | 14 | global controller 15 | controller = CC() 16 | engine.main_camera.components.add(controller) 17 | 18 | -------------------------------------------------------------------------------- /example/setup.py: -------------------------------------------------------------------------------- 1 | from Capsian import * 2 | 3 | 4 | @IndependentComponent 5 | class Setup(Script): 6 | def on_start(self, time) -> None: 7 | import scripts.data as data 8 | data.current_scene = Scene3D(engine.main_camera) 9 | 10 | overlay = OverlayScene(engine.main_camera) 11 | FPSCounter(overlay) 12 | -------------------------------------------------------------------------------- /example/time.py: -------------------------------------------------------------------------------- 1 | from Capsian import * 2 | 3 | 4 | @IndependentComponent 5 | class Timing(Script): 6 | def on_start(self, time) -> None: 7 | camera = engine.main_camera 8 | controller = camera.components.character_controller 9 | 10 | @engine.default_clock.Schedule.loop() 11 | def move_camera(dt: float) -> None: 12 | controller.move(Direction.FOWARDS) 13 | 14 | if round(camera.components.transform.z, 2) == 0.15: 15 | cm2 = PerspectiveCamera() 16 | window = engine.main_window 17 | window.set_viewport(cm2) 18 | window.set_mouse_lock(False) 19 | overlay = OverlayScene(cm2) 20 | SkyColor << [0, 0, 0, 0] 21 | Label3D( 22 | "MS Gothic", 23 | 50, 24 | "Thanks for checking this out!", 25 | Color(0, 255, 0, 255).rgba, 26 | Transform( 27 | x=25, 28 | y=window.height - 100, 29 | z=0, 30 | width=None, 31 | height=None 32 | ), 33 | overlay, 34 | anchor_x="left", 35 | anchor_y="top" 36 | ) 37 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # pyglet 3 | # Copyright (c) 2006-2008 Alex Holkner 4 | # Copyright (c) 2008-2020 pyglet contributors 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # * Neither the name of pyglet nor the names of its 18 | # contributors may be used to endorse or promote products 19 | # derived from this software without specific prior written 20 | # permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | # POSSIBILITY OF SUCH DAMAGE. 34 | # ---------------------------------------------------------------------------- 35 | 36 | # ---------------------------------------------------------------------------- 37 | # Capsian Engine 38 | # Copyright 2020 - 2022 Alessandro Salerno (Tzyvoski) 39 | # 40 | # Licensed under the Apache License, Version 2.0 (the "License"); 41 | # you may not use this file except in compliance with the License. 42 | # You may obtain a copy of the License at 43 | 44 | # http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | # Unless required by applicable law or agreed to in writing, software 47 | # distributed under the License is distributed on an "AS IS" BASIS, 48 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | # See the License for the specific language governing permissions and 50 | # limitations under the License. 51 | # ---------------------------------------------------------------------------- 52 | 53 | 54 | from Capsian import * 55 | from os import system 56 | import os 57 | 58 | 59 | system("cls") if os.name == "nt" else system("clear") 60 | 61 | 62 | # Eval the contens of the options file 63 | with open("options.cpsn", "r") as preferences: 64 | global options 65 | _options = preferences.read() 66 | options = eval(compile(source=_options, filename="options", mode="eval", optimize=1)) 67 | 68 | 69 | # Compiles and runs scripts 70 | import projects 71 | 72 | 73 | try: 74 | # Enable Capsian Basic Lighting if required 75 | if options["use basic lighting"]: 76 | engine.main_window.enable(CPSN_LIGHTING) 77 | 78 | # Set OpenGL Clear Color 79 | SkyColor << options["clear color"] 80 | 81 | # Set fog settings 82 | if options["enable fog"]: 83 | fog_color = options["fog color"] 84 | fog_start = options["fog start"] 85 | fog_end = options["fog end"] 86 | 87 | Fog(fog_color, fog_start, fog_end) 88 | except: 89 | _errcam = OrthographicCamera() 90 | _errwin = Window3D(camera=_errcam, width=1024, height=680) 91 | Log.critical("Something went wrong while setting up your game. This is usually caused by the absence of a default window and/or camera") 92 | 93 | 94 | # Runs all the code3 95 | engine.run() 96 | 97 | 98 | # Random print() to make the output look cleaner 99 | print() 100 | -------------------------------------------------------------------------------- /options.cpsn: -------------------------------------------------------------------------------- 1 | # This file is not protected by copyright and is designed to modified 2 | # You can add anything you want to this dictionary, but removing things is not racomended 3 | 4 | 5 | { 6 | "use basic lighting" : True, 7 | "enable fog" : False, 8 | "fog color" : CPSN_DEFAULT_FOG_COLOR, 9 | "fog start" : CPSN_DEFAULT_FOG_START, 10 | "fog end" : CPSN_DEFAULT_FOG_END, 11 | "clear color" : [0, 0, 0, 0] 12 | } 13 | -------------------------------------------------------------------------------- /prepare.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | print("Starting Capsian Setup Tool...") 4 | print("This script will install all the dependencies you need") 5 | input("Press enter to continue or close to terminate ") 6 | 7 | _pip_type = "pip" 8 | if os.name == "posix": 9 | _pip_type = "pip3" 10 | 11 | os.system(_pip_type + " install pyglet==1.5.6") 12 | os.system(_pip_type + " install PyOpenGL") 13 | os.system(_pip_type + " install pyinstaller") 14 | 15 | input("Installation complete!\nPress enter to exit ") 16 | -------------------------------------------------------------------------------- /projects/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alessandro-Salerno/Capsian-Engine/5df7c61433c835e862b670a0bbd65df2aa82f980/projects/__init__.py --------------------------------------------------------------------------------