Browse Source
- Updated the Unit base class to include common attributes and methods for all units. - Refactored Bomb, Point, and Rat classes to inherit from the new Unit class structure. - Implemented a consistent die method across units for better cleanup. - Removed redundant code in unit initialization and added specific attributes where necessary. - Deleted obsolete configuration file and added a comprehensive architecture guide for future reference.master
18 changed files with 484 additions and 32497 deletions
@ -1,7 +0,0 @@
|
||||
<html> |
||||
<head><title>404 Not Found</title></head> |
||||
<body> |
||||
<center><h1>404 Not Found</h1></center> |
||||
<hr><center>nginx/1.27.0</center> |
||||
</body> |
||||
</html> |
||||
@ -1,116 +0,0 @@
|
||||
#!/usr/bin/env python |
||||
# -*- coding: utf-8 -*- |
||||
|
||||
from imgui.integrations.sdl2 import SDL2Renderer |
||||
from sdl2 import * |
||||
import OpenGL.GL as gl |
||||
import ctypes |
||||
import imgui |
||||
import sys |
||||
|
||||
|
||||
def main(): |
||||
window, gl_context = impl_pysdl2_init() |
||||
imgui.create_context() |
||||
impl = SDL2Renderer(window) |
||||
|
||||
show_custom_window = True |
||||
|
||||
running = True |
||||
event = SDL_Event() |
||||
while running: |
||||
while SDL_PollEvent(ctypes.byref(event)) != 0: |
||||
if event.type == SDL_QUIT: |
||||
running = False |
||||
break |
||||
impl.process_event(event) |
||||
impl.process_inputs() |
||||
|
||||
imgui.new_frame() |
||||
|
||||
|
||||
#show_test_window() |
||||
#imgui.show_test_window() |
||||
|
||||
if show_custom_window: |
||||
is_expand, show_custom_window = imgui.begin("Custom window", True) |
||||
if is_expand: |
||||
imgui.text("Bars") |
||||
imgui.text_colored("Eggs", 0.2, 1.0, 0.0) |
||||
imgui.end() |
||||
|
||||
gl.glClearColor(1.0, 1.0, 1.0, 1) |
||||
gl.glClear(gl.GL_COLOR_BUFFER_BIT) |
||||
|
||||
|
||||
imgui.render() |
||||
impl.render(imgui.get_draw_data()) |
||||
SDL_GL_SwapWindow(window) |
||||
|
||||
impl.shutdown() |
||||
SDL_GL_DeleteContext(gl_context) |
||||
SDL_DestroyWindow(window) |
||||
SDL_Quit() |
||||
|
||||
|
||||
def impl_pysdl2_init(): |
||||
width, height = 640, 480 |
||||
window_name = "minimal ImGui/SDL2 example" |
||||
|
||||
if SDL_Init(SDL_INIT_EVERYTHING) < 0: |
||||
print( |
||||
"Error: SDL could not initialize! SDL Error: " |
||||
+ SDL_GetError().decode("utf-8") |
||||
) |
||||
sys.exit(1) |
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) |
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24) |
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8) |
||||
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1) |
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) |
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8) |
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG) |
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4) |
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1) |
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE) |
||||
|
||||
SDL_SetHint(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, b"1") |
||||
SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, b"1") |
||||
|
||||
window = SDL_CreateWindow( |
||||
window_name.encode("utf-8"), |
||||
SDL_WINDOWPOS_CENTERED, |
||||
SDL_WINDOWPOS_CENTERED, |
||||
width, |
||||
height, |
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE, |
||||
) |
||||
|
||||
if window is None: |
||||
print( |
||||
"Error: Window could not be created! SDL Error: " |
||||
+ SDL_GetError().decode("utf-8") |
||||
) |
||||
sys.exit(1) |
||||
|
||||
gl_context = SDL_GL_CreateContext(window) |
||||
if gl_context is None: |
||||
print( |
||||
"Error: Cannot create OpenGL Context! SDL Error: " |
||||
+ SDL_GetError().decode("utf-8") |
||||
) |
||||
sys.exit(1) |
||||
|
||||
SDL_GL_MakeCurrent(window, gl_context) |
||||
if SDL_GL_SetSwapInterval(1) < 0: |
||||
print( |
||||
"Warning: Unable to set VSync! SDL Error: " + SDL_GetError().decode("utf-8") |
||||
) |
||||
sys.exit(1) |
||||
|
||||
return window, gl_context |
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -1,25 +0,0 @@
|
||||
[Window][Debug##Default] |
||||
Pos=60,60 |
||||
Size=400,400 |
||||
Collapsed=0 |
||||
|
||||
[Window][Custom window] |
||||
Pos=297,261 |
||||
Size=107,117 |
||||
Collapsed=0 |
||||
|
||||
[Window][Dear ImGui Demo] |
||||
Pos=650,20 |
||||
Size=550,680 |
||||
Collapsed=0 |
||||
|
||||
[Window][Your first window!] |
||||
Pos=60,60 |
||||
Size=100,48 |
||||
Collapsed=0 |
||||
|
||||
[Window][ImGui Demo] |
||||
Pos=236,96 |
||||
Size=550,680 |
||||
Collapsed=0 |
||||
|
||||
@ -1,53 +0,0 @@
|
||||
import ctypes |
||||
import os |
||||
import sdl2 |
||||
import imgui |
||||
from imgui.integrations.sdl2 import SDL2Renderer |
||||
import sdl2.ext |
||||
|
||||
def main(): |
||||
# Initialize SDL2 |
||||
sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) |
||||
|
||||
# Set OpenGL ES version |
||||
sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_MAJOR_VERSION, 2) |
||||
sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_MINOR_VERSION, 0) |
||||
sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_CONTEXT_PROFILE_MASK, sdl2.SDL_GL_CONTEXT_PROFILE_ES) |
||||
|
||||
# Create an SDL window |
||||
window = sdl2.SDL_CreateWindow(b"SDL2 OpenGL ES2", |
||||
sdl2.SDL_WINDOWPOS_UNDEFINED, |
||||
sdl2.SDL_WINDOWPOS_UNDEFINED, |
||||
640, 480, |
||||
sdl2.SDL_WINDOW_OPENGL | sdl2.SDL_WINDOW_SHOWN) |
||||
|
||||
# Create an OpenGL context |
||||
gl_context = sdl2.SDL_GL_CreateContext(window) |
||||
|
||||
# Main loop |
||||
running = True |
||||
event = sdl2.SDL_Event() |
||||
|
||||
# Create an SDL2 renderer for ImGui |
||||
imgui.set_current_context(imgui.create_context()) |
||||
renderer = SDL2Renderer(window) |
||||
while running: |
||||
while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0: |
||||
if event.type == sdl2.SDL_QUIT: |
||||
running = False |
||||
is_expand, show_custom_window = imgui.begin("Custom window", True) |
||||
if is_expand: |
||||
imgui.text("Bars") |
||||
imgui.text_colored("Eggs", 0.2, 1.0, 0.0) |
||||
imgui.end() |
||||
imgui.render() |
||||
renderer.render(imgui.get_draw_data()) |
||||
sdl2.SDL_GL_SwapWindow(window) |
||||
|
||||
# Cleanup |
||||
sdl2.SDL_GL_DeleteContext(gl_context) |
||||
sdl2.SDL_DestroyWindow(window) |
||||
sdl2.SDL_Quit() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
@ -1,77 +0,0 @@
|
||||
from pyglet.libs.egl import egl as libegl |
||||
from pyglet.libs.egl.egl import * |
||||
|
||||
|
||||
_buffer_types = {EGL_SINGLE_BUFFER: "EGL_RENDER_BUFFER", |
||||
EGL_BACK_BUFFER: "EGL_BACK_BUFFER", |
||||
EGL_NONE: "EGL_NONE"} |
||||
|
||||
_api_types = {EGL_OPENGL_API: "EGL_OPENGL_API", |
||||
EGL_OPENGL_ES_API: "EGL_OPENGL_ES_API", |
||||
EGL_NONE: "EGL_NONE"} |
||||
|
||||
# Initialize a display: |
||||
display = libegl.EGLNativeDisplayType() |
||||
display_connection = libegl.eglGetDisplay(display) |
||||
|
||||
majorver = libegl.EGLint() |
||||
minorver = libegl.EGLint() |
||||
result = libegl.eglInitialize(display_connection, majorver, minorver) |
||||
assert result == 1, "EGL Initialization Failed" |
||||
egl_version = majorver.value, minorver.value |
||||
print(f"EGL version: {egl_version}") |
||||
|
||||
# Get the number of configs: |
||||
num_configs = libegl.EGLint() |
||||
config_size = libegl.EGLint() |
||||
result = libegl.eglGetConfigs(display_connection, None, config_size, num_configs) |
||||
assert result == 1, "Failed to query Configs" |
||||
|
||||
print("Number of configs available: ", num_configs.value) |
||||
|
||||
# Choose a config: |
||||
config_attribs = (EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, |
||||
EGL_BLUE_SIZE, 8, |
||||
EGL_GREEN_SIZE, 8, |
||||
EGL_RED_SIZE, 8, |
||||
EGL_DEPTH_SIZE, 8, |
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, |
||||
EGL_NONE) |
||||
config_attrib_array = (libegl.EGLint * len(config_attribs))(*config_attribs) |
||||
egl_config = libegl.EGLConfig() |
||||
result = libegl.eglChooseConfig(display_connection, config_attrib_array, egl_config, 1, num_configs) |
||||
assert result == 1, "Failed to choose Config" |
||||
|
||||
# Create a surface: |
||||
pbufferwidth = 1 |
||||
pbufferheight = 1 |
||||
pbuffer_attribs = (EGL_WIDTH, pbufferwidth, EGL_HEIGHT, pbufferheight, EGL_NONE) |
||||
pbuffer_attrib_array = (libegl.EGLint * len(pbuffer_attribs))(*pbuffer_attribs) |
||||
surface = libegl.eglCreatePbufferSurface(display_connection, egl_config, pbuffer_attrib_array) |
||||
print("Surface: ", surface) |
||||
|
||||
# Bind the API: |
||||
result = libegl.eglBindAPI(libegl.EGL_OPENGL_API) |
||||
assert result == 1, "Failed to bind EGL_OPENGL_API" |
||||
|
||||
# Create a context: |
||||
context_attribs = (EGL_CONTEXT_MAJOR_VERSION, 2, EGL_NONE) |
||||
context_attrib_array = (libegl.EGLint * len(context_attribs))(*context_attribs) |
||||
context = libegl.eglCreateContext(display_connection, egl_config, None, context_attrib_array) |
||||
print("Context: ", context) |
||||
|
||||
# Make context current: |
||||
result = libegl.eglMakeCurrent(display_connection, surface, surface, context) |
||||
assert result == 1, "Failed to make context current" |
||||
|
||||
error_code = libegl.eglGetError() |
||||
assert error_code == EGL_SUCCESS, "EGL Error code {} returned".format(error_code) |
||||
|
||||
# Print some context details: |
||||
buffer_type = libegl.EGLint() |
||||
libegl.eglQueryContext(display_connection, context, EGL_RENDER_BUFFER, buffer_type) |
||||
print("Buffer type: ", _buffer_types.get(buffer_type.value, "Unknown")) |
||||
print("API type: ", _api_types.get(libegl.eglQueryAPI(), "Unknown")) |
||||
|
||||
# Terminate EGL: |
||||
libegl.eglTerminate(display_connection) |
||||
Binary file not shown.
@ -1,78 +0,0 @@
|
||||
import sys |
||||
import sdl2 |
||||
from PIL import Image |
||||
import sdl2.sdlttf |
||||
import sdl2.ext |
||||
|
||||
|
||||
class Main: |
||||
def __init__(self): |
||||
sdl2.ext.init() |
||||
self.size = (800, 600) |
||||
self.window = sdl2.ext.Window("PySDL2 Demo", size=self.size) |
||||
self.window.show() |
||||
self.renderer = sdl2.ext.Renderer(self.window) |
||||
self.factory = sdl2.ext.SpriteFactory(renderer=self.renderer) |
||||
self.fonts = self.generate_fonts("assets/AmaticSC-Regular.ttf") |
||||
self.running = True |
||||
self.assets = self.graphics_load() |
||||
|
||||
def generate_fonts(self,font_file): |
||||
fonts = {} |
||||
for i in range(10, 70, 1): |
||||
fonts.update({i: sdl2.ext.FontManager(font_path=font_file, size=i)}) |
||||
return fonts |
||||
|
||||
def draw_text(self, text, font, position, color): |
||||
sprite = self.factory.from_text(text, fontmanager=font, color=color) |
||||
if position == "center": |
||||
sprite.position = (self.size[0] // 2 - sprite.size[0] // 2, self.size[1] // 2 - sprite.size[1] // 2) |
||||
else: |
||||
sprite.position = position |
||||
self.renderer.copy(sprite, dstrect=sprite.position) |
||||
|
||||
def draw_image(self, sprite, position): |
||||
|
||||
sprite.position = position |
||||
self.renderer.copy(sprite, dstrect=sprite.position) |
||||
|
||||
def load_image(self, path, transparent_color=None): |
||||
image = Image.open(path) |
||||
image = image.resize((image.width * 3, image.height * 3), Image.NEAREST) |
||||
if transparent_color: |
||||
image = image.convert("RGBA") |
||||
datas = image.getdata() |
||||
new_data = [] |
||||
for item in datas: |
||||
if item[:3] == transparent_color: |
||||
new_data.append((255, 255, 255, 0)) |
||||
else: |
||||
new_data.append(item) |
||||
image.putdata(new_data) |
||||
|
||||
return self.factory.from_surface(sdl2.ext.pillow_to_surface(image)) |
||||
|
||||
def run(self): |
||||
while self.running: |
||||
events = sdl2.ext.get_events() |
||||
for event in events: |
||||
if event.type == sdl2.SDL_QUIT: |
||||
self.running = False |
||||
break |
||||
self.renderer.clear() |
||||
self.draw_text("MatGames Corp.", self.fonts[50], (0, 0), sdl2.ext.Color(255, 255, 255)) |
||||
self.draw_image(self.assets["MALE"]["DOWN"], (100, 100)) |
||||
self.renderer.present() |
||||
sdl2.ext.quit() |
||||
return 0 |
||||
|
||||
def graphics_load(self): |
||||
rat_assets = {} |
||||
for sex in ["MALE", "FEMALE", "BABY"]: |
||||
rat_assets[sex] = {} |
||||
for direction in ["UP", "DOWN", "LEFT", "RIGHT"]: |
||||
rat_assets[sex][direction] = self.load_image(f"assets/Rat/BMP_{sex}_{direction}.png", transparent_color=(128, 128, 128)) |
||||
return rat_assets |
||||
|
||||
if __name__ == "__main__": |
||||
sys.exit(Main().run()) |
||||
@ -1,50 +0,0 @@
|
||||
from sdl2 import * |
||||
import tkinter as tk |
||||
from tkinter import * |
||||
import random, ctypes |
||||
|
||||
def draw(): |
||||
global renderer |
||||
x1 = ctypes.c_int(random.randrange(0, 600)) |
||||
y1 = ctypes.c_int(random.randrange(0, 500)) |
||||
x2 = ctypes.c_int(random.randrange(0, 600)) |
||||
y2 = ctypes.c_int(random.randrange(0, 500)) |
||||
r = ctypes.c_ubyte(random.randrange(0, 255)) |
||||
g = ctypes.c_ubyte(random.randrange(0, 255)) |
||||
b = ctypes.c_ubyte(random.randrange(0, 255)) |
||||
SDL_SetRenderDrawColor(renderer, r, g, b, ctypes.c_ubyte(255)) |
||||
SDL_RenderDrawLine(renderer, x1, y1, x2, y2) |
||||
|
||||
def sdl_update(): |
||||
global window, event, renderer |
||||
SDL_RenderPresent(renderer); |
||||
if SDL_PollEvent(ctypes.byref(event)) != 0: |
||||
if event.type == SDL_QUIT: |
||||
SDL_DestroyRenderer(renderer) |
||||
SDL_DestroyWindow(window) |
||||
SDL_Quit() |
||||
|
||||
# tkinter stuff # |
||||
root = tk.Tk() |
||||
embed = tk.Frame(root, width = 500, height = 500) #creates embed frame for pygame window |
||||
embed.grid(columnspan = (600), rowspan = 500) # Adds grid |
||||
embed.pack(side = LEFT) #packs window to the left |
||||
buttonwin = tk.Frame(root, width = 75, height = 500) |
||||
buttonwin.pack(side = LEFT) |
||||
button1 = Button(buttonwin,text = 'Draw', command=draw) |
||||
button1.pack(side=LEFT) |
||||
root.update() |
||||
################################# |
||||
# SDL window stuff # |
||||
SDL_Init(SDL_INIT_VIDEO) |
||||
window = SDL_CreateWindowFrom(embed.winfo_id()) |
||||
renderer = SDL_CreateRenderer(window, -1, 0) |
||||
SDL_SetRenderDrawColor(renderer, ctypes.c_ubyte(255), ctypes.c_ubyte(255), |
||||
ctypes.c_ubyte(255), ctypes.c_ubyte(255)) |
||||
SDL_RenderClear(renderer) |
||||
event = SDL_Event() |
||||
draw() |
||||
|
||||
while True: |
||||
sdl_update() |
||||
root.update() |
||||
@ -1,35 +0,0 @@
|
||||
<!doctype html> |
||||
|
||||
<html> |
||||
|
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>WASM test with XHR</title> |
||||
</head> |
||||
|
||||
<body> |
||||
<script> |
||||
const importObject = { |
||||
my_namespace: { |
||||
imported_func: arg => { |
||||
console.log(arg); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
const request = new XMLHttpRequest(); |
||||
request.open("GET", "rats.wasm"); |
||||
request.responseType = "arraybuffer"; |
||||
request.send(); |
||||
|
||||
request.onload = () => { |
||||
const bytes = request.response; |
||||
WebAssembly.instantiate(bytes, importObject) |
||||
.then(obj => { |
||||
obj.instance.exports.exported_func(); |
||||
}); |
||||
}; |
||||
</script> |
||||
</body> |
||||
|
||||
</html> |
||||
@ -1,13 +0,0 @@
|
||||
const fs = require('fs'); |
||||
const { promisify } = require('util'); |
||||
|
||||
const fileRead = promisify(fs.readFile); |
||||
|
||||
(async function() { |
||||
const wasmBuffer = await fileRead('./rats.wasm'); |
||||
const wasmModule = await WebAssembly.compile(wasmBuffer); |
||||
const wasmInstance = await WebAssembly.instantiate(wasmModule); |
||||
|
||||
// Assuming the WASM module exports a function named 'myFunction'
|
||||
console.log('Result from myFunction:', wasmInstance.instance.exports.myFunction()); |
||||
})(); |
||||
@ -1,27 +1,70 @@
|
||||
class Unit: |
||||
from abc import ABC, abstractmethod |
||||
import uuid |
||||
|
||||
|
||||
class Unit(ABC): |
||||
""" |
||||
A class to represent a unit in the game. |
||||
Abstract base class for all game units. |
||||
|
||||
Attributes |
||||
---------- |
||||
id : UUID |
||||
Unique identifier for the unit. |
||||
game : Game |
||||
Reference to the main game object. |
||||
position : tuple |
||||
The current position of the unit (default is (0, 0)). |
||||
The current position of the unit (x, y). |
||||
position_before : tuple |
||||
The position of the unit before the last update. |
||||
state : int |
||||
The current state of the unit (default is 0). |
||||
age : int |
||||
The age of the unit in game ticks. |
||||
speed : float |
||||
The delay between updates in seconds (default is 0.05). |
||||
partial_move : int |
||||
The partial move value (default is 0). |
||||
Movement speed of the unit. |
||||
partial_move : float |
||||
Partial movement progress for smooth animation. |
||||
bbox : tuple |
||||
Bounding box for collision detection (x1, y1, x2, y2). |
||||
stop : int |
||||
Number of ticks to remain stationary. |
||||
|
||||
Methods |
||||
------- |
||||
__init__(self, position=(0,0)) |
||||
Initializes the unit with a given position. |
||||
move() |
||||
Update unit position and state (must be implemented by subclasses). |
||||
draw() |
||||
Render the unit on screen (must be implemented by subclasses). |
||||
collisions() |
||||
Handle collisions with other units (optional override). |
||||
die() |
||||
Remove unit from game and handle cleanup. |
||||
""" |
||||
def __init__(self, position=(0,0)): |
||||
def __init__(self, game, position=(0, 0), id=None): |
||||
"""Initialize a unit with game reference and position.""" |
||||
self.id = id if id else uuid.uuid4() |
||||
self.game = game |
||||
self.position = position |
||||
self.position_before = self.position |
||||
self.state = 0 |
||||
self.partial_move = 1 |
||||
self.position_before = position |
||||
self.age = 0 |
||||
self.speed = 1.0 |
||||
self.partial_move = 0 |
||||
self.bbox = (0, 0, 0, 0) |
||||
self.stop = 0 |
||||
|
||||
@abstractmethod |
||||
def move(self): |
||||
"""Update unit position and state. Must be implemented by subclasses.""" |
||||
pass |
||||
|
||||
@abstractmethod |
||||
def draw(self): |
||||
"""Render the unit on screen. Must be implemented by subclasses.""" |
||||
pass |
||||
|
||||
def collisions(self): |
||||
"""Handle collisions with other units. Default implementation does nothing.""" |
||||
pass |
||||
|
||||
def die(self): |
||||
"""Remove unit from game and handle basic cleanup.""" |
||||
if self.id in self.game.units: |
||||
self.game.units.pop(self.id) |
||||
|
||||
@ -1,12 +0,0 @@
|
||||
<game> |
||||
<path>/roms/tools/mice/rats</path> |
||||
<name>Mice!</name> |
||||
<desc>Mice! is a strategic game where players must kill rats with bombs before they reproduce and become too numerous. The game is a clone of the classic game Rats! for Windows 95. <image>./drally/cover.png</image> |
||||
<releasedate>20241225T000000</releasedate> |
||||
<developer>Matteo Benedetto</developer> |
||||
<publisher>Check Mate Corp.</publisher> |
||||
<genre>Casual</genre> |
||||
<players>1</players> |
||||
<playcount>1</playcount> |
||||
<lastplayed>20240915T212155</lastplayed> |
||||
</game> |
||||
Loading…
Reference in new issue