simgame 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simgame-0.2.0/PKG-INFO +35 -0
- simgame-0.2.0/README.md +28 -0
- simgame-0.2.0/pyproject.toml +13 -0
- simgame-0.2.0/setup.cfg +4 -0
- simgame-0.2.0/simgame/__init__.py +75 -0
- simgame-0.2.0/simgame.egg-info/PKG-INFO +35 -0
- simgame-0.2.0/simgame.egg-info/SOURCES.txt +7 -0
- simgame-0.2.0/simgame.egg-info/dependency_links.txt +1 -0
- simgame-0.2.0/simgame.egg-info/top_level.txt +1 -0
simgame-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simgame
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A lightweight 2D game engine based on SDL2.
|
|
5
|
+
License: MIT
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
# SimGame
|
|
9
|
+
> - **一个基于SDL2的轻量化 2D 游戏引擎 🎮**
|
|
10
|
+
> - **新增 2D 绘图功能**
|
|
11
|
+
> - **可绘制方形,圆形,线**
|
|
12
|
+
## 安装:
|
|
13
|
+
```bash
|
|
14
|
+
pip install simgame
|
|
15
|
+
```
|
|
16
|
+
## 快速上手:
|
|
17
|
+
```python
|
|
18
|
+
import simgame #导入simgame
|
|
19
|
+
ctx = simgame.create_window(title="SimGame",size=(800,600)) #创建上下文对象
|
|
20
|
+
running = True #设置游戏是否运行
|
|
21
|
+
while running: #开启游戏主循环
|
|
22
|
+
for event in ctx.input.get_events(): #检测所有事件
|
|
23
|
+
if event == ctx.input.QUIT: #检测到退出事件
|
|
24
|
+
running = False #退出窗口
|
|
25
|
+
ctx.screen.clear() #清空窗口
|
|
26
|
+
ctx.screen.fill((255,28,0)) #将窗口涂成红色
|
|
27
|
+
ctx.draw.rect((0,0,100,100),(0,255,100)) #画一个绿色的空心方块
|
|
28
|
+
ctx.draw.circle((400,300),50,(100,100,100),filled=True) #画一个灰色的实心圆
|
|
29
|
+
ctx.draw.line((0,0),(400,300),(0,0,0)) #画一个连接(0,0)和(400,300)的线
|
|
30
|
+
ctx.quit() #清理内存
|
|
31
|
+
```
|
|
32
|
+
## 关于作者(About):
|
|
33
|
+
> - **SimGame是一个轻量化的 2D 游戏引擎**
|
|
34
|
+
> - **制作人:钴蓝工作室🔵**
|
|
35
|
+
> - **版本:0.2.0**
|
simgame-0.2.0/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# SimGame
|
|
2
|
+
> - **一个基于SDL2的轻量化 2D 游戏引擎 🎮**
|
|
3
|
+
> - **新增 2D 绘图功能**
|
|
4
|
+
> - **可绘制方形,圆形,线**
|
|
5
|
+
## 安装:
|
|
6
|
+
```bash
|
|
7
|
+
pip install simgame
|
|
8
|
+
```
|
|
9
|
+
## 快速上手:
|
|
10
|
+
```python
|
|
11
|
+
import simgame #导入simgame
|
|
12
|
+
ctx = simgame.create_window(title="SimGame",size=(800,600)) #创建上下文对象
|
|
13
|
+
running = True #设置游戏是否运行
|
|
14
|
+
while running: #开启游戏主循环
|
|
15
|
+
for event in ctx.input.get_events(): #检测所有事件
|
|
16
|
+
if event == ctx.input.QUIT: #检测到退出事件
|
|
17
|
+
running = False #退出窗口
|
|
18
|
+
ctx.screen.clear() #清空窗口
|
|
19
|
+
ctx.screen.fill((255,28,0)) #将窗口涂成红色
|
|
20
|
+
ctx.draw.rect((0,0,100,100),(0,255,100)) #画一个绿色的空心方块
|
|
21
|
+
ctx.draw.circle((400,300),50,(100,100,100),filled=True) #画一个灰色的实心圆
|
|
22
|
+
ctx.draw.line((0,0),(400,300),(0,0,0)) #画一个连接(0,0)和(400,300)的线
|
|
23
|
+
ctx.quit() #清理内存
|
|
24
|
+
```
|
|
25
|
+
## 关于作者(About):
|
|
26
|
+
> - **SimGame是一个轻量化的 2D 游戏引擎**
|
|
27
|
+
> - **制作人:钴蓝工作室🔵**
|
|
28
|
+
> - **版本:0.2.0**
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "simgame"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "A lightweight 2D game engine based on SDL2."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
|
|
12
|
+
[tool.setuptools.packages.find]
|
|
13
|
+
include = ["simgame*"]
|
simgame-0.2.0/setup.cfg
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import sdl2
|
|
2
|
+
import sdl2.ext
|
|
3
|
+
import ctypes
|
|
4
|
+
class _Screen:
|
|
5
|
+
def __init__(self, renderer):
|
|
6
|
+
self.renderer = renderer
|
|
7
|
+
def fill(self, color):
|
|
8
|
+
r, g, b = color
|
|
9
|
+
sdl2.SDL_SetRenderDrawColor(self.renderer, r, g, b, 255)
|
|
10
|
+
sdl2.SDL_RenderClear(self.renderer)
|
|
11
|
+
def clear(self):
|
|
12
|
+
self.fill((0, 0, 0))
|
|
13
|
+
def update(self):
|
|
14
|
+
sdl2.SDL_RenderPresent(self.renderer)
|
|
15
|
+
class _Draw:
|
|
16
|
+
def __init__(self,renderer):
|
|
17
|
+
self.renderer = renderer
|
|
18
|
+
def rect(self,geo,color,filled=False):
|
|
19
|
+
x,y,w,h = geo
|
|
20
|
+
r,g,b = color
|
|
21
|
+
sdl2.SDL_SetRenderDrawColor(self.renderer,r,g,b,255)
|
|
22
|
+
sdl_rect = sdl2.SDL_Rect(int(x),int(y),int(w),int(h))
|
|
23
|
+
if filled:
|
|
24
|
+
sdl2.SDL_RenderFillRect(sdl_rect)
|
|
25
|
+
else:
|
|
26
|
+
sdl2.SDL_RenderDrawRect(sdl_rect)
|
|
27
|
+
def line(self,start,end,color):
|
|
28
|
+
x1,y1 = start
|
|
29
|
+
x2,y2 = end
|
|
30
|
+
r,g,b = color
|
|
31
|
+
sdl2.SDL_SetRenderDrawColor(self.renderer,r,g,b,255)
|
|
32
|
+
sdl2.SDL_RenderDrawLine(self.renderer,int(x1),int(y1),int(x2),int(y2))
|
|
33
|
+
def circle(self,center,radius,color,filled=False):
|
|
34
|
+
x,y = center
|
|
35
|
+
r,g,b = color
|
|
36
|
+
rgba_color = (r,g,b,255)
|
|
37
|
+
sdl2.ext.circle(self.renderer,rgba_color,int(x),int(y),int(radius),filled)
|
|
38
|
+
class _Input:
|
|
39
|
+
def __init__(self):
|
|
40
|
+
self.QUIT = sdl2.SDL_QUIT
|
|
41
|
+
|
|
42
|
+
def get_events(self):
|
|
43
|
+
events = []
|
|
44
|
+
while True:
|
|
45
|
+
event = sdl2.SDL_Event()
|
|
46
|
+
if sdl2.SDL_PollEvent(ctypes.byref(event)) == 0:
|
|
47
|
+
break
|
|
48
|
+
events.append(event.type)
|
|
49
|
+
return events
|
|
50
|
+
class _Context:
|
|
51
|
+
def __init__(self, title="SimGame", size=(800, 600)):
|
|
52
|
+
if isinstance(title, str):
|
|
53
|
+
title = title.encode("utf-8")
|
|
54
|
+
sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)
|
|
55
|
+
self.window = sdl2.SDL_CreateWindow(
|
|
56
|
+
title,
|
|
57
|
+
sdl2.SDL_WINDOWPOS_CENTERED,
|
|
58
|
+
sdl2.SDL_WINDOWPOS_CENTERED,
|
|
59
|
+
size[0], size[1],
|
|
60
|
+
sdl2.SDL_WINDOW_SHOWN
|
|
61
|
+
)
|
|
62
|
+
icon = sdl2.SDL_CreateRGBSurfaceWithFormat(0, 32, 32, 32, sdl2.SDL_PIXELFORMAT_RGBA32)
|
|
63
|
+
sdl2.ext.fill(icon.contents, (0, 0, 0, 0))
|
|
64
|
+
sdl2.SDL_SetWindowIcon(self.window, icon)
|
|
65
|
+
sdl2.SDL_FreeSurface(icon)
|
|
66
|
+
self.renderer = sdl2.SDL_CreateRenderer(self.window, -1, sdl2.SDL_RENDERER_ACCELERATED)
|
|
67
|
+
self.screen = _Screen(self.renderer)
|
|
68
|
+
self.input = _Input()
|
|
69
|
+
self.draw = _Draw(self.renderer)
|
|
70
|
+
def quit(self):
|
|
71
|
+
sdl2.SDL_DestroyRenderer(self.renderer)
|
|
72
|
+
sdl2.SDL_DestroyWindow(self.window)
|
|
73
|
+
sdl2.SDL_Quit()
|
|
74
|
+
def create_window(title="SimGame", size=(800, 600)):
|
|
75
|
+
return _Context(title, size)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simgame
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A lightweight 2D game engine based on SDL2.
|
|
5
|
+
License: MIT
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
# SimGame
|
|
9
|
+
> - **一个基于SDL2的轻量化 2D 游戏引擎 🎮**
|
|
10
|
+
> - **新增 2D 绘图功能**
|
|
11
|
+
> - **可绘制方形,圆形,线**
|
|
12
|
+
## 安装:
|
|
13
|
+
```bash
|
|
14
|
+
pip install simgame
|
|
15
|
+
```
|
|
16
|
+
## 快速上手:
|
|
17
|
+
```python
|
|
18
|
+
import simgame #导入simgame
|
|
19
|
+
ctx = simgame.create_window(title="SimGame",size=(800,600)) #创建上下文对象
|
|
20
|
+
running = True #设置游戏是否运行
|
|
21
|
+
while running: #开启游戏主循环
|
|
22
|
+
for event in ctx.input.get_events(): #检测所有事件
|
|
23
|
+
if event == ctx.input.QUIT: #检测到退出事件
|
|
24
|
+
running = False #退出窗口
|
|
25
|
+
ctx.screen.clear() #清空窗口
|
|
26
|
+
ctx.screen.fill((255,28,0)) #将窗口涂成红色
|
|
27
|
+
ctx.draw.rect((0,0,100,100),(0,255,100)) #画一个绿色的空心方块
|
|
28
|
+
ctx.draw.circle((400,300),50,(100,100,100),filled=True) #画一个灰色的实心圆
|
|
29
|
+
ctx.draw.line((0,0),(400,300),(0,0,0)) #画一个连接(0,0)和(400,300)的线
|
|
30
|
+
ctx.quit() #清理内存
|
|
31
|
+
```
|
|
32
|
+
## 关于作者(About):
|
|
33
|
+
> - **SimGame是一个轻量化的 2D 游戏引擎**
|
|
34
|
+
> - **制作人:钴蓝工作室🔵**
|
|
35
|
+
> - **版本:0.2.0**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
simgame
|