Initial commit

This commit is contained in:
Bruno Rybársky 2021-03-28 20:09:20 +02:00 committed by GitHub
commit e7da9b7ac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 2050 additions and 0 deletions

17
Sounds.py Normal file

@ -0,0 +1,17 @@
import pygame
from pygame.locals import *
# basic config
pygame.mixer.pre_init(48000, -16, 2, 512)
pygame.init()
pygame.mixer.set_num_channels(16)
def get_sounds():
sounds = {
"click": pygame.mixer.Sound("assets/sounds/click.wav"),
"collision": pygame.mixer.Sound("assets/sounds/collision.wav")
}
return sounds

14
assets/maps/map0 Normal file

@ -0,0 +1,14 @@
000001111111000000
000011000001100000
000110000000110000
001100000000011000
001000000000001000
001000000000001000
001000000000001000
001000000000001000
001000000000001000
001000000000001000
001100000000011000
000110000000110000
000011000001100000
000001111111000000

BIN
assets/sounds/click.wav Normal file

Binary file not shown.

BIN
assets/sounds/collision.wav Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

BIN
assets/textures/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 569 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 568 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

638
epic_sumo1.py Normal file

@ -0,0 +1,638 @@
from s_engine import *
from spark import *
from ingame_funcs import *
import pygame
import sys
import time
import random
import math
from pygame.locals import *
import json
import threading
import asyncio
import websockets
# basic config
work = True
pygame.mixer.pre_init(48000, -16, 2, 512)
pygame.init()
pygame.mixer.set_num_channels(16)
font = pygame.font.SysFont('Comic Sans MS', 80)
small_font = pygame.font.SysFont('Comic Sans MS', 40)
tiny_font = pygame.font.SysFont('Comic Sans MS', 20)
players_defined = 0
connected = 0
global Player1
global Player2
uri = "ws://brn.systems:8765"
global websocket
async def write_players(arrx):
global Player1
global Player2
Player2.all_ids = arrx[0]
Player2.dir_movement = arrx[1]
Player2.direction = arrx[2]
Player2.ids_to_remove = arrx[3]
Player2.memory = arrx[4]
Player2.move.angle_speed = arrx[5]
Player2.move.backwards = arrx[6]
Player2.move.collisions = arrx[7]
Player2.move.degree = arrx[8]
Player2.move.force = arrx[9]
Player2.move.forward = arrx[10]
Player2.move.half_pi = arrx[11]
Player2.move.left = arrx[12]
Player2.move.offset = arrx[13]
Player2.move.pi = arrx[14]
Player2.move.right = arrx[15]
Player2.move.speed = arrx[16]
Player2.move.three_halves_pi = arrx[17]
Player2.move.two_pi = arrx[18]
Player2.move.vectors = arrx[19]
Player2.movement = arrx[20]
Player2.moving = arrx[21]
Player2.object_id = arrx[22]
Player2.object_pos = arrx[23]
Player2.rect.bottom = arrx[24]
Player2.rect.bottomleft = arrx[25]
Player2.rect.bottomright = arrx[26]
Player2.rect.center = arrx[27]
Player2.rect.centerx = arrx[28]
Player2.rect.centery = arrx[29]
Player2.rect.h = arrx[30]
Player2.rect.height = arrx[31]
Player2.rect.left = arrx[32]
Player2.rect.midbottom = arrx[33]
Player2.rect.midleft = arrx[34]
Player2.rect.midright = arrx[35]
Player2.rect.midtop = arrx[36]
Player2.rect.right = arrx[37]
Player2.rect.size = arrx[38]
Player2.rect.top = arrx[39]
Player2.rect.topleft = arrx[40]
Player2.rect.topright = arrx[41]
Player2.rect.w = arrx[42]
Player2.rect.width = arrx[43]
Player2.rect.x = arrx[44]
Player2.rect.y = arrx[45]
Player2.size = arrx[46]
Player2.special = arrx[47]
Player2.specific.attribute = arrx[48]
Player2.specific.attribute_0 = arrx[49]
Player2.specific.attribute_1 = arrx[50]
Player2.specific.attribute_2 = arrx[51]
Player2.specific.boolean_attribute = arrx[52]
Player2.specific.color_r = arrx[53]
Player2.specific.fixed = arrx[54]
Player2.specific.flip = arrx[55]
Player2.specific.height = arrx[56]
Player2.specific.object_id = arrx[57]
Player2.specific.power = arrx[58]
Player2.specific.scroll = arrx[59]
Player2.specific.stage = arrx[60]
Player2.type = arrx[61]
async def hello():
global websocket
global connected
websocket = await websockets.connect(uri)
connected = 1
while True:
greeting = await websocket.recv()
try:
if players_defined == 1:
data = json.loads(greeting)[1]["data"]
if len(data) == 62:
await write_players(data)
except Exception as e:
print(str(e))
loop = asyncio.get_event_loop()
def helloa():
loop.run_until_complete(hello())
loop.run_forever()
t = threading.Thread(target=helloa, args=tuple())
t.start()
while connected == 0:
pass
Window_size = [900, 600]
screen = pygame.display.set_mode(Window_size)
display = pygame.Surface((1350, 900))
pygame.display.set_caption("Epic_sumo")
pygame.display.set_icon(pygame.image.load("assets/textures/icon.png").convert())
clock = pygame.time.Clock()
class Bg:
active = []
timer = 0
bgs = {
"first": pygame.image.load("assets/textures/backround/bg.png").convert(),
"second": pygame.image.load("assets/textures/backround/bg-blue.png").convert()
}
bgs["first"].set_colorkey((255, 255, 255))
bgs["second"].set_colorkey((255, 255, 255))
def __init__(self, pos, speed, typeX):
self.object_pos = pos
self.speed = speed
self.type = typeX
@classmethod
def generate(cls, amount, cord_lim=None):
if cord_lim is None:
cord_lim = [0, 1350]
for i in range(amount):
cls.active.append(Bg([random.randint(cord_lim[0], cord_lim[1]), random.randint(0, 860)],
random.randint(2, 10), random.choice(("first", "second"))))
@classmethod
def blit_them(cls, display):
for circle in cls.active:
display.blit(cls.bgs[circle.type], circle.object_pos)
@classmethod
def remove_circle(cls, which):
cls.active.remove(which)
@classmethod
def central(cls, display):
for circle in cls.active:
circle.move()
cls.blit_them(display)
if cls.timer == 0:
cls.generate(12, [1350, 1500])
cls.timer += 60
else:
cls.timer -= 1
def move(self):
self.object_pos[0] -= self.speed
if self.object_pos[0] < -80:
self.remove_circle(self)
class Solids:
def __init__(self):
self.stage = 0
self.colors = [
(73, 122, 67),
(127, 182, 120),
(181, 230, 29)
]
def draw(self, solid, display, scroll):
cc = (self.stage // 40) % 3
current_stage = self.stage % 40
mid_point = [
solid.object_pos[0] + (solid.size[0] / 2),
solid.object_pos[1] + (solid.size[1] / 2)
]
pygame.draw.rect(display, self.colors[cc], pygame.Rect(mid_point[0] - current_stage - scroll.scroll[0],
mid_point[1] - current_stage - scroll.scroll[1],
current_stage * 2, current_stage * 2))
def draw_solids(self, objects, display, scroll):
for obj in objects.game_objects:
if obj.type == "solid":
self.draw(obj, display, scroll)
self.stage += 1
def menu(screenX, fs):
def mouse_check(mouse_pos, menu_flow):
new_list = [0, 0, menu_flow[2], menu_flow[3], 0, 0]
# settings
if 800 < mouse_pos[0] < 872:
if 500 < mouse_pos[1] < 572:
new_list[0] = 1
# play
if 300 < mouse_pos[0] < 591:
if 300 < mouse_pos[1] < 396:
new_list[1] = 1
# change player 1
if 250 < mouse_pos[0] < 359:
if 500 < mouse_pos[1] < 548:
new_list[4] = 1
# change player 2
if 400 < mouse_pos[0] < 509:
if 500 < mouse_pos[1] < 548:
new_list[5] = 1
return new_list
# preparations
game = Game()
game.game_flow["menu"] = [0, 0, 0, 0, 0, 0]
game.game_flow["sounds"] = get_sounds()
settings_on_top = False
display = pygame.Surface((900, 600))
abilities = {
"1.player": "dash",
"2.player": "dash",
"1.storage": 5,
"2.storage": 5
}
menu_textures = {
"bg": pygame.image.load("assets/textures/menu/main_menu.png").convert(),
"play": pygame.image.load("assets/textures/menu/play_button.png").convert(),
"play_pressed": pygame.image.load("assets/textures/menu/play_button_pressed.png").convert(),
"settings": pygame.image.load("assets/textures/menu/settings_btn.png").convert(),
"settings_pressed": pygame.image.load("assets/textures/menu/settings_btn_pressed.png").convert(),
"change": pygame.image.load("assets/textures/menu/change_btn.png").convert(),
"change_pressed": pygame.image.load("assets/textures/menu/change_btn_pressed.png").convert(),
"dash": pygame.image.load("assets/textures/menu/dash.png").convert(),
"shockwave": pygame.image.load("assets/textures/menu/wave.png").convert(),
"ice": pygame.image.load("assets/textures/menu/ice.png").convert(),
"settings_menu": pygame.image.load("assets/textures/menu/settings.png").convert()
}
# game loop
while game.alive:
display.blit(menu_textures["bg"], [0, 0])
# event loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
mousepos = pygame.mouse.get_pos()
game.game_flow["menu"] = mouse_check(mousepos, game.game_flow["menu"])
# setting actions for buttons
if settings_on_top is False:
if game.game_flow["menu"][1]:
game.game_flow["sounds"]["click"].play(0)
arena(screenX, fs, abilities)
elif game.game_flow["menu"][4]:
game.game_flow["menu"][2] += 1
if game.game_flow["menu"][2] > 2:
game.game_flow["menu"][2] = 0
game.game_flow["sounds"]["click"].play(0)
elif game.game_flow["menu"][5]:
game.game_flow["menu"][3] += 1
if game.game_flow["menu"][3] > 2:
game.game_flow["menu"][3] = 0
game.game_flow["sounds"]["click"].play(0)
# settings menu
if game.game_flow["menu"][0]:
settings_on_top = not settings_on_top
game.game_flow["sounds"]["click"].play(0)
if event.type == pygame.MOUSEMOTION:
# if mouse moving get mouse pos
mousepos = pygame.mouse.get_pos()
# function that checks if mouse is above any button and changes image, color of that image
game.game_flow["menu"] = mouse_check(mousepos, game.game_flow["menu"])
if event.type == KEYDOWN:
if event.key == K_f:
fs = not fs
if fs is False:
screenX = pygame.display.set_mode(Window_size)
else:
screenX = pygame.display.set_mode(Window_size, pygame.FULLSCREEN)
elif event.key == K_ESCAPE:
if settings_on_top is False:
pygame.quit()
sys.exit()
else:
settings_on_top = not settings_on_top
# making menu
if game.game_flow["menu"][1]:
display.blit(menu_textures["play_pressed"], [300, 300])
else:
display.blit(menu_textures["play"], [300, 300])
# showing ability of 1.player
if game.game_flow["menu"][2] == 0:
display.blit(menu_textures["dash"], [100, 400])
abilities["1.player"] = "dash"
abilities["1.storage"] = 10
elif game.game_flow["menu"][2] == 1:
display.blit(menu_textures["shockwave"], [100, 400])
abilities["1.player"] = "wave"
abilities["1.storage"] = 8
elif game.game_flow["menu"][2] == 2:
display.blit(menu_textures["ice"], [100, 400])
abilities["1.player"] = "ice"
abilities["1.storage"] = 10
# showing ability of 2.player
if game.game_flow["menu"][3] == 0:
display.blit(menu_textures["dash"], [500, 400])
abilities["2.player"] = "dash"
abilities["2.storage"] = 10
elif game.game_flow["menu"][3] == 1:
display.blit(menu_textures["shockwave"], [500, 400])
abilities["2.player"] = "wave"
abilities["2.storage"] = 8
elif game.game_flow["menu"][3] == 2:
display.blit(menu_textures["ice"], [500, 400])
abilities["2.player"] = "ice"
abilities["2.storage"] = 10
if game.game_flow["menu"][4] == 0:
display.blit(menu_textures["change"], [250, 500])
elif game.game_flow["menu"][4] == 1:
display.blit(menu_textures["change_pressed"], [250, 500])
if game.game_flow["menu"][5] == 0:
display.blit(menu_textures["change"], [400, 500])
elif game.game_flow["menu"][5] == 1:
display.blit(menu_textures["change_pressed"], [400, 500])
if settings_on_top:
display.blit(menu_textures["settings_menu"], [0, 0])
if game.game_flow["menu"][0]:
display.blit(menu_textures["settings_pressed"], [800, 500])
else:
display.blit(menu_textures["settings"], [800, 500])
# basic loop config
screenX.blit(display, (0, 0))
pygame.display.update()
clock.tick(60)
def arena(screenX, fs, abilities):
global Player1
global Player2
global players_defined
ids = Id()
images_dictionary = {"solid": pygame.image.load("assets/textures/game/solid.png").convert(),
"circle": pygame.image.load("assets/textures/backround/circle_arena.png").convert()}
images_dictionary["circle"].set_colorkey((0, 0, 0))
images_dictionary["solid"].set_colorkey((0, 0, 0))
game = Game()
game.game_flow["collision_timer"] = 0
game.game_flow["boost"] = 0.9
game.game_flow["speed_timer"] = 0
game.game_flow["winner"] = "na"
game.game_flow["inputs"] = True
game.game_flow["sounds"] = get_sounds()
new_parameters = [1350, 900]
display = pygame.Surface((1350, 900))
# background
bg = Bg
bg.generate(100)
# solids
solids = Solids()
# loading map
mapX = load_map("assets/maps/map0")
# loading objects
objects = Objects()
# loading bg circle
midpoint = [816, 672]
circle = Object("circle", game.custom_id_giver, [192, 0], [0, 0], 0, False, [1248, 1344])
sort(circle, objects)
game.custom_id_giver += 1
# loading from map
load_objects(mapX, 96, 96, objects, game)
# players
# never set direction to 0
Player1 = Object("player", game.custom_id_giver, [800, 800], [0, 0],
round(math.tau * 0.75, 2), True, [10, 10], True)
Player1.specific.images.append(pygame.image.load("assets/textures/game/player.png").convert())
Player1.specific.images[0].set_colorkey((0, 0, 0))
Player1.move.collisions = True # enables collisions for player
Player1.move.speed = 0.5 # increasing speed so ur not super slow
Player1.move.angle_speed = 0.1
# simulating movement so u dont start at speed 0
Player1.dir_movement = Player1.move.set_start_dir_movement(Player1.direction, Player1.dir_movement)
# sorts player
sort(Player1, objects)
# moves to next id
game.custom_id_giver += 1
# player 2
# never set direction to 0
Player2 = Object("player", game.custom_id_giver, [800, 400], [0, 0], round(math.pi/2, 2), True, [10, 10], True)
Player2.specific.images.append(pygame.image.load("assets/textures/game/player.png").convert())
Player2.specific.images[0].set_colorkey((0, 0, 0))
Player2.move.collisions = True # enables collisions for player
Player2.move.speed = 0.5 # increasing speed so ur not super slow
Player2.move.angle_speed = 0.1
# simulating movement so u dont start at speed 0
Player2.dir_movement = Player2.move.set_start_dir_movement(Player2.direction, Player2.dir_movement)
# sorts player
sort(Player2, objects)
# moves to next id
game.custom_id_giver += 1
players_defined = 1
# sparks
sparks = Spark
sparks.sparks["a"] = []
sparks.sparks["b"] = []
pointers = [pygame.image.load("assets/textures/game/p1_pointer.png").convert(),
pygame.image.load("assets/textures/game/p2_pointer.png").convert()]
for point in pointers:
point.set_colorkey((0, 0, 0))
# scroll
scroll = Scroll([0, 0])
# ending
winner_text = pygame.image.load("assets/textures/menu/template_for_text.png").convert()
esc = pygame.image.load("assets/textures/menu/esc.png").convert()
# game loop
while game.alive:
# checking if end
check_loser(midpoint, [Player1, Player2], game)
# setting up bg
display.fill((20, 20, 20))
bg.central(display)
# checking for removed objects
objects.destroy_trash(ids)
ids.remove_by_id(objects)
# doing player movement
Player1.movement = Player1.move.move(Player1.dir_movement)
Player1.direction, Player1.dir_movement = Player1.move.change_dir(Player1.direction,
Player1.move.angle_speed)
Player2.movement = Player2.move.move(Player2.dir_movement)
Player2.direction, Player2.dir_movement = Player2.move.change_dir(Player2.direction,
Player2.move.angle_speed)
# second parameter is speed of rotation
# collisions
objects.do_collisions(objects)
players_collisions(Player1, Player2, game)
# new sparks
sparks.scroll = scroll.scroll
sparks.create("a", Player1.object_pos, [3, 5], [[10, 255], [0, 200], [0, 0]], 3, 1)
sparks.create("b", Player2.object_pos, [3, 5], [[0, 0], [0, 200], [10, 255]], 3, 1)
# sounds
# displaying objects
scroll.move_scroll(Player1, [900, 600], "both", 30)
scroll.move_scroll(Player2, [900, 600], "both", 30)
load_textures(objects, images_dictionary, display, scroll)
solids.draw_solids(objects, display, scroll)
display_pointers(display, [Player1, Player2], pointers, scroll)
sparks.central("a", display)
sparks.central("b", display)
# event loop
if game.game_flow["inputs"]:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_f:
fs = not fs
if fs is False:
screenX = pygame.display.set_mode(Window_size)
else:
screenX = pygame.display.set_mode(new_parameters, pygame.FULLSCREEN)
elif event.key == K_ESCAPE:
game.game_flow["sounds"]["click"].play(0)
game.alive = False
elif event.key == K_d:
Player1.move.right = True
elif event.key == K_a:
Player1.move.left = True
elif event.key == K_w:
Player1.move.forward = True
elif event.key == K_e:
if abilities["1.storage"] > 1:
if abilities["1.player"] == "ice":
Player1.move.vectors = []
elif abilities["1.player"] == "dash":
Player1.move.vectors.append([Player1.dir_movement[0] * game.game_flow["boost"],
Player1.dir_movement[1] * game.game_flow["boost"]])
elif abilities["1.player"] == "wave":
Player2.move.vectors.append(
get_shockwave_vector(Player1.object_pos, Player2.object_pos))
abilities["1.storage"] -= 1
# key_up
elif event.type == KEYUP:
if event.key == K_d:
Player1.move.right = False
elif event.key == K_a:
Player1.move.left = False
elif event.key == K_w:
Player1.move.forward = False
else:
stop_inputs([Player1, Player2])
winner = font.render(f"Winner is : {game.game_flow['winner']}",
False, (255, 255, 255))
display.blit(winner_text, [50, 50])
display.blit(winner, [90, 80])
display.blit(esc, [500, 450])
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_f:
fs = not fs
if fs is False:
screenX = pygame.display.set_mode(Window_size)
else:
screenX = pygame.display.set_mode(new_parameters, pygame.FULLSCREEN)
elif event.key == K_ESCAPE:
game.game_flow["sounds"]["click"].play(0)
game.alive = False
# basic loop config
outarr = [Player1.all_ids, Player1.dir_movement, Player1.direction, Player1.ids_to_remove, Player1.memory, Player1.move.angle_speed, Player1.move.backwards, Player1.move.collisions, Player1.move.degree, Player1.move.force, Player1.move.forward, Player1.move.half_pi, Player1.move.left, Player1.move.offset, Player1.move.pi, Player1.move.right, Player1.move.speed, Player1.move.three_halves_pi, Player1.move.two_pi, Player1.move.vectors, Player1.movement, Player1.moving, Player1.object_id, Player1.object_pos, Player1.rect.bottom, Player1.rect.bottomleft, Player1.rect.bottomright, Player1.rect.center, Player1.rect.centerx, Player1.rect.centery, Player1.rect.h, Player1.rect.height, Player1.rect.left, Player1.rect.midbottom, Player1.rect.midleft, Player1.rect.midright, Player1.rect.midtop, Player1.rect.right, Player1.rect.size, Player1.rect.top, Player1.rect.topleft, Player1.rect.topright, Player1.rect.w, Player1.rect.width, Player1.rect.x, Player1.rect.y, Player1.size, Player1.special, Player1.specific.attribute, Player1.specific.attribute_0, Player1.specific.attribute_1, Player1.specific.attribute_2, Player1.specific.boolean_attribute, Player1.specific.color_r, Player1.specific.fixed, Player1.specific.flip, Player1.specific.height, Player1.specific.object_id, Player1.specific.power, Player1.specific.scroll, Player1.specific.stage, Player1.type]
datasend = json.dumps({"player": 1, "data": outarr})
asyncio.run(websocket.send(datasend))
screenX.blit(pygame.transform.scale(display, new_parameters), (0, 0))
pygame.display.update()
clock.tick(60)
menu(screen, False)

640
epic_sumo2.py Normal file

@ -0,0 +1,640 @@
from s_engine import *
from spark import *
from ingame_funcs import *
import pygame
import sys
import time
import random
import math
from pygame.locals import *
import json
import threading
import asyncio
import websockets
# basic config
work = True
pygame.mixer.pre_init(48000, -16, 2, 512)
pygame.init()
pygame.mixer.set_num_channels(16)
font = pygame.font.SysFont('Comic Sans MS', 80)
small_font = pygame.font.SysFont('Comic Sans MS', 40)
tiny_font = pygame.font.SysFont('Comic Sans MS', 20)
players_defined = 0
connected = 0
global Player1
global Player2
uri = "ws://brn.systems:8765"
global websocket
async def write_players(arrx):
global Player1
global Player2
Player1.all_ids = arrx[0]
Player1.dir_movement = arrx[1]
Player1.direction = arrx[2]
Player1.ids_to_remove = arrx[3]
Player1.memory = arrx[4]
Player1.move.angle_speed = arrx[5]
Player1.move.backwards = arrx[6]
Player1.move.collisions = arrx[7]
Player1.move.degree = arrx[8]
Player1.move.force = arrx[9]
Player1.move.forward = arrx[10]
Player1.move.half_pi = arrx[11]
Player1.move.left = arrx[12]
Player1.move.offset = arrx[13]
Player1.move.pi = arrx[14]
Player1.move.right = arrx[15]
Player1.move.speed = arrx[16]
Player1.move.three_halves_pi = arrx[17]
Player1.move.two_pi = arrx[18]
Player1.move.vectors = arrx[19]
Player1.movement = arrx[20]
Player1.moving = arrx[21]
Player1.object_id = arrx[22]
Player1.object_pos = arrx[23]
Player1.rect.bottom = arrx[24]
Player1.rect.bottomleft = arrx[25]
Player1.rect.bottomright = arrx[26]
Player1.rect.center = arrx[27]
Player1.rect.centerx = arrx[28]
Player1.rect.centery = arrx[29]
Player1.rect.h = arrx[30]
Player1.rect.height = arrx[31]
Player1.rect.left = arrx[32]
Player1.rect.midbottom = arrx[33]
Player1.rect.midleft = arrx[34]
Player1.rect.midright = arrx[35]
Player1.rect.midtop = arrx[36]
Player1.rect.right = arrx[37]
Player1.rect.size = arrx[38]
Player1.rect.top = arrx[39]
Player1.rect.topleft = arrx[40]
Player1.rect.topright = arrx[41]
Player1.rect.w = arrx[42]
Player1.rect.width = arrx[43]
Player1.rect.x = arrx[44]
Player1.rect.y = arrx[45]
Player1.size = arrx[46]
Player1.special = arrx[47]
Player1.specific.attribute = arrx[48]
Player1.specific.attribute_0 = arrx[49]
Player1.specific.attribute_1 = arrx[50]
Player1.specific.attribute_2 = arrx[51]
Player1.specific.boolean_attribute = arrx[52]
Player1.specific.color_r = arrx[53]
Player1.specific.fixed = arrx[54]
Player1.specific.flip = arrx[55]
Player1.specific.height = arrx[56]
Player1.specific.object_id = arrx[57]
Player1.specific.power = arrx[58]
Player1.specific.scroll = arrx[59]
Player1.specific.stage = arrx[60]
Player1.type = arrx[61]
async def hello():
global websocket
global connected
websocket = await websockets.connect(uri)
connected = 1
while True:
greeting = await websocket.recv()
try:
if players_defined == 1:
data = json.loads(greeting)[0]["data"]
if len(data) == 62:
await write_players(data)
except Exception as e:
print(str(e))
loop = asyncio.get_event_loop()
def helloa():
loop.run_until_complete(hello())
loop.run_forever()
t = threading.Thread(target=helloa, args=tuple())
t.start()
while connected == 0:
pass
Window_size = [900, 600]
screen = pygame.display.set_mode(Window_size)
display = pygame.Surface((1350, 900))
pygame.display.set_caption("Epic_sumo")
pygame.display.set_icon(pygame.image.load("assets/textures/icon.png").convert())
clock = pygame.time.Clock()
class Bg:
active = []
timer = 0
bgs = {
"first": pygame.image.load("assets/textures/backround/bg.png").convert(),
"second": pygame.image.load("assets/textures/backround/bg-blue.png").convert()
}
bgs["first"].set_colorkey((255, 255, 255))
bgs["second"].set_colorkey((255, 255, 255))
def __init__(self, pos, speed, typeX):
self.object_pos = pos
self.speed = speed
self.type = typeX
@classmethod
def generate(cls, amount, cord_lim=None):
if cord_lim is None:
cord_lim = [0, 1350]
for i in range(amount):
cls.active.append(Bg([random.randint(cord_lim[0], cord_lim[1]), random.randint(0, 860)],
random.randint(2, 10), random.choice(("first", "second"))))
@classmethod
def blit_them(cls, display):
for circle in cls.active:
display.blit(cls.bgs[circle.type], circle.object_pos)
@classmethod
def remove_circle(cls, which):
cls.active.remove(which)
@classmethod
def central(cls, display):
for circle in cls.active:
circle.move()
cls.blit_them(display)
if cls.timer == 0:
cls.generate(12, [1350, 1500])
cls.timer += 60
else:
cls.timer -= 1
def move(self):
self.object_pos[0] -= self.speed
if self.object_pos[0] < -80:
self.remove_circle(self)
class Solids:
def __init__(self):
self.stage = 0
self.colors = [
(73, 122, 67),
(127, 182, 120),
(181, 230, 29)
]
def draw(self, solid, display, scroll):
cc = (self.stage // 40) % 3
current_stage = self.stage % 40
mid_point = [
solid.object_pos[0] + (solid.size[0] / 2),
solid.object_pos[1] + (solid.size[1] / 2)
]
pygame.draw.rect(display, self.colors[cc], pygame.Rect(mid_point[0] - current_stage - scroll.scroll[0],
mid_point[1] - current_stage - scroll.scroll[1],
current_stage * 2, current_stage * 2))
def draw_solids(self, objects, display, scroll):
for obj in objects.game_objects:
if obj.type == "solid":
self.draw(obj, display, scroll)
self.stage += 1
def menu(screenX, fs):
def mouse_check(mouse_pos, menu_flow):
new_list = [0, 0, menu_flow[2], menu_flow[3], 0, 0]
# settings
if 800 < mouse_pos[0] < 872:
if 500 < mouse_pos[1] < 572:
new_list[0] = 1
# play
if 300 < mouse_pos[0] < 591:
if 300 < mouse_pos[1] < 396:
new_list[1] = 1
# change player 1
if 250 < mouse_pos[0] < 359:
if 500 < mouse_pos[1] < 548:
new_list[4] = 1
# change player 2
if 400 < mouse_pos[0] < 509:
if 500 < mouse_pos[1] < 548:
new_list[5] = 1
return new_list
# preparations
game = Game()
game.game_flow["menu"] = [0, 0, 0, 0, 0, 0]
game.game_flow["sounds"] = get_sounds()
settings_on_top = False
display = pygame.Surface((900, 600))
abilities = {
"1.player": "dash",
"2.player": "dash",
"1.storage": 5,
"2.storage": 5
}
menu_textures = {
"bg": pygame.image.load("assets/textures/menu/main_menu.png").convert(),
"play": pygame.image.load("assets/textures/menu/play_button.png").convert(),
"play_pressed": pygame.image.load("assets/textures/menu/play_button_pressed.png").convert(),
"settings": pygame.image.load("assets/textures/menu/settings_btn.png").convert(),
"settings_pressed": pygame.image.load("assets/textures/menu/settings_btn_pressed.png").convert(),
"change": pygame.image.load("assets/textures/menu/change_btn.png").convert(),
"change_pressed": pygame.image.load("assets/textures/menu/change_btn_pressed.png").convert(),
"dash": pygame.image.load("assets/textures/menu/dash.png").convert(),
"shockwave": pygame.image.load("assets/textures/menu/wave.png").convert(),
"ice": pygame.image.load("assets/textures/menu/ice.png").convert(),
"settings_menu": pygame.image.load("assets/textures/menu/settings.png").convert()
}
# game loop
while game.alive:
display.blit(menu_textures["bg"], [0, 0])
# event loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
mousepos = pygame.mouse.get_pos()
game.game_flow["menu"] = mouse_check(mousepos, game.game_flow["menu"])
# setting actions for buttons
if settings_on_top is False:
if game.game_flow["menu"][1]:
game.game_flow["sounds"]["click"].play(0)
arena(screenX, fs, abilities)
elif game.game_flow["menu"][4]:
game.game_flow["menu"][2] += 1
if game.game_flow["menu"][2] > 2:
game.game_flow["menu"][2] = 0
game.game_flow["sounds"]["click"].play(0)
elif game.game_flow["menu"][5]:
game.game_flow["menu"][3] += 1
if game.game_flow["menu"][3] > 2:
game.game_flow["menu"][3] = 0
game.game_flow["sounds"]["click"].play(0)
# settings menu
if game.game_flow["menu"][0]:
settings_on_top = not settings_on_top
game.game_flow["sounds"]["click"].play(0)
if event.type == pygame.MOUSEMOTION:
# if mouse moving get mouse pos
mousepos = pygame.mouse.get_pos()
# function that checks if mouse is above any button and changes image, color of that image
game.game_flow["menu"] = mouse_check(mousepos, game.game_flow["menu"])
if event.type == KEYDOWN:
if event.key == K_f:
fs = not fs
if fs is False:
screenX = pygame.display.set_mode(Window_size)
else:
screenX = pygame.display.set_mode(Window_size, pygame.FULLSCREEN)
elif event.key == K_ESCAPE:
if settings_on_top is False:
pygame.quit()
sys.exit()
else:
settings_on_top = not settings_on_top
# making menu
if game.game_flow["menu"][1]:
display.blit(menu_textures["play_pressed"], [300, 300])
else:
display.blit(menu_textures["play"], [300, 300])
# showing ability of 1.player
if game.game_flow["menu"][2] == 0:
display.blit(menu_textures["dash"], [100, 400])
abilities["1.player"] = "dash"
abilities["1.storage"] = 10
elif game.game_flow["menu"][2] == 1:
display.blit(menu_textures["shockwave"], [100, 400])
abilities["1.player"] = "wave"
abilities["1.storage"] = 8
elif game.game_flow["menu"][2] == 2:
display.blit(menu_textures["ice"], [100, 400])
abilities["1.player"] = "ice"
abilities["1.storage"] = 10
# showing ability of 2.player
if game.game_flow["menu"][3] == 0:
display.blit(menu_textures["dash"], [500, 400])
abilities["2.player"] = "dash"
abilities["2.storage"] = 10
elif game.game_flow["menu"][3] == 1:
display.blit(menu_textures["shockwave"], [500, 400])
abilities["2.player"] = "wave"
abilities["2.storage"] = 8
elif game.game_flow["menu"][3] == 2:
display.blit(menu_textures["ice"], [500, 400])
abilities["2.player"] = "ice"
abilities["2.storage"] = 10
if game.game_flow["menu"][4] == 0:
display.blit(menu_textures["change"], [250, 500])
elif game.game_flow["menu"][4] == 1:
display.blit(menu_textures["change_pressed"], [250, 500])
if game.game_flow["menu"][5] == 0:
display.blit(menu_textures["change"], [400, 500])
elif game.game_flow["menu"][5] == 1:
display.blit(menu_textures["change_pressed"], [400, 500])
if settings_on_top:
display.blit(menu_textures["settings_menu"], [0, 0])
if game.game_flow["menu"][0]:
display.blit(menu_textures["settings_pressed"], [800, 500])
else:
display.blit(menu_textures["settings"], [800, 500])
# basic loop config
screenX.blit(display, (0, 0))
pygame.display.update()
clock.tick(60)
def arena(screenX, fs, abilities):
global Player1
global Player2
global players_defined
ids = Id()
images_dictionary = {"solid": pygame.image.load("assets/textures/game/solid.png").convert(),
"circle": pygame.image.load("assets/textures/backround/circle_arena.png").convert()}
images_dictionary["circle"].set_colorkey((0, 0, 0))
images_dictionary["solid"].set_colorkey((0, 0, 0))
game = Game()
game.game_flow["collision_timer"] = 0
game.game_flow["boost"] = 0.9
game.game_flow["speed_timer"] = 0
game.game_flow["winner"] = "na"
game.game_flow["inputs"] = True
game.game_flow["sounds"] = get_sounds()
new_parameters = [1350, 900]
display = pygame.Surface((1350, 900))
# background
bg = Bg
bg.generate(100)
# solids
solids = Solids()
# loading map
mapX = load_map("assets/maps/map0")
# loading objects
objects = Objects()
# loading bg circle
midpoint = [816, 672]
circle = Object("circle", game.custom_id_giver, [192, 0], [0, 0], 0, False, [1248, 1344])
sort(circle, objects)
game.custom_id_giver += 1
# loading from map
load_objects(mapX, 96, 96, objects, game)
# players
# never set direction to 0
Player1 = Object("player", game.custom_id_giver, [800, 800], [0, 0],
round(math.tau * 0.75, 2), True, [10, 10], True)
Player1.specific.images.append(pygame.image.load("assets/textures/game/player.png").convert())
Player1.specific.images[0].set_colorkey((0, 0, 0))
Player1.move.collisions = True # enables collisions for player
Player1.move.speed = 0.5 # increasing speed so ur not super slow
Player1.move.angle_speed = 0.1
# simulating movement so u dont start at speed 0
Player1.dir_movement = Player1.move.set_start_dir_movement(Player1.direction, Player1.dir_movement)
# sorts player
sort(Player1, objects)
# moves to next id
game.custom_id_giver += 1
# player 2
# never set direction to 0
Player2 = Object("player", game.custom_id_giver, [800, 400], [0, 0], round(math.pi/2, 2), True, [10, 10], True)
Player2.specific.images.append(pygame.image.load("assets/textures/game/player.png").convert())
Player2.specific.images[0].set_colorkey((0, 0, 0))
Player2.move.collisions = True # enables collisions for player
Player2.move.speed = 0.5 # increasing speed so ur not super slow
Player2.move.angle_speed = 0.1
# simulating movement so u dont start at speed 0
Player2.dir_movement = Player2.move.set_start_dir_movement(Player2.direction, Player2.dir_movement)
# sorts player
sort(Player2, objects)
# moves to next id
game.custom_id_giver += 1
players_defined = 1
# sparks
sparks = Spark
sparks.sparks["a"] = []
sparks.sparks["b"] = []
pointers = [pygame.image.load("assets/textures/game/p1_pointer.png").convert(),
pygame.image.load("assets/textures/game/p2_pointer.png").convert()]
for point in pointers:
point.set_colorkey((0, 0, 0))
# scroll
scroll = Scroll([0, 0])
# ending
winner_text = pygame.image.load("assets/textures/menu/template_for_text.png").convert()
esc = pygame.image.load("assets/textures/menu/esc.png").convert()
# game loop
while game.alive:
# checking if end
check_loser(midpoint, [Player1, Player2], game)
# setting up bg
display.fill((20, 20, 20))
bg.central(display)
# checking for removed objects
objects.destroy_trash(ids)
ids.remove_by_id(objects)
# doing player movement
Player1.movement = Player1.move.move(Player1.dir_movement)
Player1.direction, Player1.dir_movement = Player1.move.change_dir(Player1.direction,
Player1.move.angle_speed)
Player2.movement = Player2.move.move(Player2.dir_movement)
Player2.direction, Player2.dir_movement = Player2.move.change_dir(Player2.direction,
Player2.move.angle_speed)
# second parameter is speed of rotation
# collisions
objects.do_collisions(objects)
players_collisions(Player1, Player2, game)
# new sparks
sparks.scroll = scroll.scroll
sparks.create("a", Player1.object_pos, [3, 5], [[10, 255], [0, 200], [0, 0]], 3, 1)
sparks.create("b", Player2.object_pos, [3, 5], [[0, 0], [0, 200], [10, 255]], 3, 1)
# sounds
# displaying objects
scroll.move_scroll(Player1, [900, 600], "both", 30)
scroll.move_scroll(Player2, [900, 600], "both", 30)
load_textures(objects, images_dictionary, display, scroll)
solids.draw_solids(objects, display, scroll)
display_pointers(display, [Player1, Player2], pointers, scroll)
sparks.central("a", display)
sparks.central("b", display)
# event loop
if game.game_flow["inputs"]:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_f:
fs = not fs
if fs is False:
screenX = pygame.display.set_mode(Window_size)
else:
screenX = pygame.display.set_mode(new_parameters, pygame.FULLSCREEN)
elif event.key == K_ESCAPE:
game.game_flow["sounds"]["click"].play(0)
game.alive = False
elif event.key == K_d:
Player2.move.right = True
elif event.key == K_a:
Player2.move.left = True
elif event.key == K_w:
Player2.move.forward = True
elif event.key == K_e:
if abilities["2.storage"] > 0:
if abilities["2.player"] == "ice":
Player2.move.vectors = []
elif abilities["2.player"] == "dash":
Player2.move.vectors.append([Player2.dir_movement[0] * game.game_flow["boost"],
Player2.dir_movement[1] * game.game_flow["boost"]])
elif abilities["2.player"] == "wave":
Player1.move.vectors.append(
get_shockwave_vector(Player2.object_pos, Player1.object_pos))
abilities["2.storage"] -= 1
# key_up
elif event.type == KEYUP:
if event.key == K_d:
Player2.move.right = False
elif event.key == K_a:
Player2.move.left = False
elif event.key == K_w:
Player2.move.forward = False
else:
stop_inputs([Player1, Player2])
winner = font.render(f"Winner is : {game.game_flow['winner']}",
False, (255, 255, 255))
display.blit(winner_text, [50, 50])
display.blit(winner, [90, 80])
display.blit(esc, [500, 450])
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_f:
fs = not fs
if fs is False:
screenX = pygame.display.set_mode(Window_size)
else:
screenX = pygame.display.set_mode(new_parameters, pygame.FULLSCREEN)
elif event.key == K_ESCAPE:
game.game_flow["sounds"]["click"].play(0)
game.alive = False
# basic loop config
outarr = [Player2.all_ids, Player2.dir_movement, Player2.direction, Player2.ids_to_remove, Player2.memory, Player2.move.angle_speed, Player2.move.backwards, Player2.move.collisions, Player2.move.degree, Player2.move.force, Player2.move.forward, Player2.move.half_pi, Player2.move.left, Player2.move.offset, Player2.move.pi, Player2.move.right, Player2.move.speed, Player2.move.three_halves_pi, Player2.move.two_pi, Player2.move.vectors, Player2.movement, Player2.moving, Player2.object_id, Player2.object_pos, Player2.rect.bottom, Player2.rect.bottomleft, Player2.rect.bottomright, Player2.rect.center, Player2.rect.centerx, Player2.rect.centery, Player2.rect.h, Player2.rect.height, Player2.rect.left, Player2.rect.midbottom, Player2.rect.midleft, Player2.rect.midright, Player2.rect.midtop, Player2.rect.right, Player2.rect.size, Player2.rect.top, Player2.rect.topleft, Player2.rect.topright, Player2.rect.w, Player2.rect.width, Player2.rect.x, Player2.rect.y, Player2.size, Player2.special, Player2.specific.attribute, Player2.specific.attribute_0, Player2.specific.attribute_1, Player2.specific.attribute_2, Player2.specific.boolean_attribute, Player2.specific.color_r, Player2.specific.fixed, Player2.specific.flip, Player2.specific.height, Player2.specific.object_id, Player2.specific.power, Player2.specific.scroll, Player2.specific.stage, Player2.type]
datasend = json.dumps({"player": 2, "data": outarr})
asyncio.run(websocket.send(datasend))
screenX.blit(pygame.transform.scale(display, new_parameters), (0, 0))
pygame.display.update()
clock.tick(60)
menu(screen, False)

100
ingame_funcs.py Normal file

@ -0,0 +1,100 @@
import math
from s_engine import *
import pygame
from pygame.locals import *
from Sounds import get_sounds
# basic config
pygame.mixer.pre_init(48000, -16, 2, 512)
pygame.init()
pygame.mixer.set_num_channels(16)
def between_player_collisions(player1, player2, game):
if game.game_flow["collision_timer"] == 0:
dist = distance_indicator(player1.object_pos, player2.object_pos)
if dist < 75:
game.game_flow["sounds"]["collision"].play(0)
player1.move.vectors.append([player2.dir_movement[0] * player2.move.force,
player2.dir_movement[1] * player2.move.force])
player2.move.vectors.append([player1.dir_movement[0] * player1.move.force,
player1.dir_movement[1] * player1.move.force])
game.game_flow["collision_timer"] += 20
else:
game.game_flow["collision_timer"] -= 1
def players_collisions(player1, player2, game):
if game.game_flow["collision_timer"] == 0:
dist = distance_indicator(player1.object_pos, player2.object_pos)
if dist < 75:
game.game_flow["sounds"]["collision"].play(0)
ag1 = find_angle_between_points(player1.object_pos, player2.object_pos)
ag2 = ag1 + math.pi
forces = [average(abs(player1.dir_movement[0]), abs(player1.dir_movement[1])) * player1.move.force,
average(abs(player2.dir_movement[0]), abs(player2.dir_movement[1])) * player2.move.force]
player1.move.vectors.append([math.cos(ag2) * forces[1],
math.sin(ag2) * forces[1]])
player2.move.vectors.append([math.cos(ag1) * forces[0],
math.sin(ag1) * forces[0]])
game.game_flow["collision_timer"] += 20
else:
game.game_flow["collision_timer"] -= 1
def get_shockwave_vector(pos1, pos2, divider=14):
dist = (100 / (distance_indicator(pos1, pos2) + 0.0001))
x_wave = (-(pos1[0] - pos2[0]) / divider) * dist
y_wave = (-(pos1[1] - pos2[1]) / divider) * dist
# divider is there to make the shockwave less powerfull
return [x_wave, y_wave]
def check_loser(midpoint, players, game):
dists = [
distance_indicator(midpoint, players[0].object_pos),
distance_indicator(midpoint, players[1].object_pos)
]
for i in range(2):
if dists[i] > 680:
if game.game_flow["inputs"] is False:
game.game_flow["winner"] = "draw"
game.game_flow["inputs"] = False
if i == 0:
game.game_flow["winner"] = "p2"
else:
game.game_flow["winner"] = "p1"
def stop_inputs(players):
for player in players:
player.move.forward = False
player.move.left = False
player.move.right = False
def display_pointers(display, players, pointers, scroll):
index = 0
for player in players:
angle = find_angle_between_points(player.object_pos, [player.object_pos[0] + math.cos(player.direction),
player.object_pos[1] + math.sin(player.direction)])
if angle is False:
index += 1
continue
display.blit(pygame.transform.rotate(pointers[index], math.degrees(-angle)),
[(player.object_pos[0] + math.cos(angle) * 40) - scroll.scroll[0] - 12,
(player.object_pos[1] + math.sin(angle) * 40) - scroll.scroll[1] - 12])
index += 1

479
s_engine.py Normal file

@ -0,0 +1,479 @@
import pygame
import sys
import time
import random
import math
import copy
from pygame.locals import *
pygame.init()
# has attributes for basic thing in game
class Game:
def __init__(self, game_maps=None):
self.alive = True
# fs = fullscreen
self.fs = False
self.custom_id_giver = 0
self.game_flow = {}
self.game_maps = None
# checks if there are any maps if there are puts them in self.game_maps
if game_maps is not None:
self.game_maps = game_maps
# stores objects in a sorted way
class Objects:
def __init__(self):
self.game_objects = []
self.collision_objects = []
self.moving_objects = []
# dunno if next att will be useful
# u add ids of objects u want to delete there is no func to delete for now
self.objects_to_delete = []
self.values = {
"pos_to_del": []
}
def do_collisions(self, objects):
for obj in self.collision_objects:
collision(obj, objects)
def destroy_trash(self, ids):
for trash in self.objects_to_delete:
ids.ids_to_remove.append(trash)
self.objects_to_delete = []
def take_out_trash(self, ids):
for obj in self.objects_to_delete:
ids.ids_to_remove.append(obj)
self.objects_to_delete = []
# Id class just stores all ids of all objects
class Id:
all_ids = []
ids_to_remove = []
def remove_by_id(self, objects):
for item in self.ids_to_remove:
for obj in objects.game_objects:
if obj.object_id == item:
g_index = objects.game_objects.index(obj)
if obj.moving:
m_index = objects.moving_objects.index(obj)
if obj.move.collisions:
c_index = objects.collision_objects.index(obj)
del objects.collision_objects[c_index]
del objects.moving_objects[m_index]
del objects.game_objects[g_index]
self.ids_to_remove = []
class Scroll:
def __init__(self, scroll):
self.scroll = scroll
self.fade = 20
self.safe_fade = 20
self.in_progress = False
self.save_scroll = self.scroll
def move_scroll(self, player, screen, which, space=20):
if which == "y" or which == "both":
self.scroll[1] += (player.rect.y - self.scroll[1] - (screen[1] / 2) + (player.size[1] / 2)) / space
self.scroll[1] = int(self.scroll[1])
if which == "x" or which == "both":
self.scroll[0] += (player.rect.x - self.scroll[0] - (screen[0] / 2) + (player.size[0] / 2)) / space
self.scroll[0] = int(self.scroll[0])
def add_scroll(self, which, how_much, fade=None):
if fade is not None:
self.safe_fade = fade
if self.in_progress is False:
self.load_safe_fade()
self.save_scroll = self.scroll
self.in_progress = True
how_much[0] /= self.fade
how_much[1] /= self.fade
self.fade += 0.01 * self.fade
if which == "x" or which == "both":
self.scroll[0] += how_much[0]
self.scroll[0] = round(self.scroll[0])
if which == "y" or which == "both":
self.scroll[1] += how_much[1]
self.scroll[1] = round(self.scroll[1])
def load_safe_fade(self):
self.fade = self.safe_fade
self.in_progress = False
class Special:
def __init__(self, object_id):
self.object_id = object_id
self.stage = ""
self.attribute = ""
self.images = []
self.attribute_0 = 0
self.attribute_1 = 0
self.attribute_2 = 0
self.color_r = [0, 0, 0]
self.boolean_attribute = False
self.height = 0
self.power = 0
self.flip = False
self.scroll = False
self.fixed = False
# collisions class take care of collision funcs
# !!!!!!!!!! holds init for Object !!!!!!!!!!!!!!!!!!!
# class purely for inheritance
class Collisions(Id):
def __init__(self, typeX, object_id, x_y, movement, direction, moving, size, special=None):
self.type = typeX
self.object_id = object_id
self.object_pos = x_y
self.movement = movement
self.direction = direction
self.moving = moving
self.size = size
self.dir_movement = [0.0, 0.0]
self.memory = []
self.special = special
if self.object_id != self.all_ids:
self.all_ids.append(self.object_id)
else:
print("duplicate/ linked object")
# giving it bonus classes
if self.moving:
self.move = Moving_Object()
if self.special:
self.specific = Special(self.object_id)
self.rect = pygame.Rect(self.object_pos[0], self.object_pos[1], self.size[0], self.size[1])
# theres a function for every type of collisions
# edit collisions here (I added some basic ones just so u can see)
# self if objects that it hit and obj is the object that hit smt
# always add both side of collisions (ask who collided with whom)
def hit_bottom(self, obj, objects):
if self.type == "solid":
if obj.type == "player":
obj.rect.bottom = self.rect.top
obj.object_pos = [obj.rect.x, obj.rect.y]
self.memory[0] -= 1
if self.memory[0] == 0:
objects.objects_to_delete.append(self.object_id)
opposite = obj.move.get_final_vector()
opp = [-opposite[0] * 0.4, -opposite[1] * 0.8]
obj.move.vectors.append(opp)
def hit_top(self, obj, objects):
if self.type == "solid":
if obj.type == "player":
obj.rect.top = self.rect.bottom
obj.object_pos = [obj.rect.x, obj.rect.y]
self.memory[0] -= 1
if self.memory[0] == 0:
objects.objects_to_delete.append(self.object_id)
opposite = obj.move.get_final_vector()
opp = [-opposite[0] * 0.4, -opposite[1] * 0.8]
obj.move.vectors.append(opp)
def hit_left(self, obj, objects):
if self.type == "solid":
if obj.type == "player":
obj.rect.left = self.rect.right
obj.object_pos = [obj.rect.x, obj.rect.y]
self.memory[0] -= 1
if self.memory[0] == 0:
objects.objects_to_delete.append(self.object_id)
opposite = obj.move.get_final_vector()
opp = [-opposite[0] * 0.4, -opposite[1] * 0.8]
obj.move.vectors.append(opp)
def hit_right(self, obj, objects):
if self.type == "solid":
if obj.type == "player":
obj.rect.right = self.rect.left
obj.object_pos = [obj.rect.x, obj.rect.y]
self.memory[0] -= 1
if self.memory[0] == 0:
objects.objects_to_delete.append(self.object_id)
opposite = obj.move.get_final_vector()
opp = [-opposite[0] * 0.4, -opposite[1] * 0.8]
obj.move.vectors.append(opp)
# next 2 classes are for object class
class Moving_Object:
def __init__(self):
# consts
self.degree = 0.0174533
self.pi = math.pi
self.half_pi = round(math.pi / 2, 6)
self.two_pi = round(math.pi * 2, 6)
self.three_halves_pi = round(3 * (math.pi / 2), 6)
self.speed = 1
self.force = 3
self.offset = 0
self.vectors = []
self.forward = False
self.backwards = False
self.left = False
self.right = False
self.collisions = False
def move(self, dir_movement):
movement = dir_movement
return movement
# dir is the angle the player is facing
def change_dir(self, direction, angle):
new_vector = [0, 0]
if self.left:
direction -= angle
if direction < 0:
direction += self.two_pi
new_vector[0] = round(math.cos(direction) * self.speed, 2)
new_vector[1] = round(math.sin(direction) * self.speed, 2)
self.vectors.append(new_vector)
elif self.right:
direction += angle
if direction > self.two_pi:
direction -= self.two_pi
new_vector[0] = round(math.cos(direction) * self.speed, 2)
new_vector[1] = round(math.sin(direction) * self.speed, 2)
self.vectors.append(new_vector)
elif self.forward:
new_vector[0] = round(math.cos(direction) * self.speed, 2)
new_vector[1] = round(math.sin(direction) * self.speed, 2)
self.vectors.append(new_vector)
return direction, self.get_final_vector()
# used for setting things before game loop
def set_start_dir_movement(self, direction, dir_movement):
dir_movement[0] = round(math.cos(direction + (self.offset * self.degree)) * self.speed, 2)
dir_movement[1] = round(math.sin(direction + (self.offset * self.degree)) * self.speed, 2)
return dir_movement
def get_final_vector(self):
to_remove = []
for i in range(len(self.vectors)-1):
self.vectors[i][0] *= 0.96
self.vectors[i][1] *= 0.96
if abs(self.vectors[i][0]) < 0.2 and abs(self.vectors[i][1]) < 0.2:
to_remove.append(self.vectors[i])
for item in to_remove:
self.vectors.remove(item)
final_vector = [0, 0]
for vector in self.vectors:
final_vector[0] += vector[0]
final_vector[1] += vector[1]
return final_vector
class Object(Collisions):
def __init__(self, typeX, object_id, x_y, movement, direction, moving, size, special=None):
super().__init__(typeX, object_id, x_y, movement, direction, moving, size, special)
def __str__(self):
return self.type
# changes position along with the rect
def change_pos(self, x_y):
self.object_pos = x_y
self.rect = pygame.Rect(self.object_pos[0], self.object_pos[1], self.size[0], self.size[1])
def distance_indicator(coords1, coords2):
x_distance = abs(coords1[0] - coords2[0])
y_distance = abs(coords1[1] - coords2[1])
distance = math.sqrt((x_distance ** 2) + (y_distance ** 2))
return round(distance, 4)
def load_images(path, name, number_of_images, file_type=".png"):
images = []
for i in range(number_of_images):
images.append(pygame.image.load("{}/{}{}{}".format(path, name, i, file_type)).convert())
return images
def load_map(path):
f = open(path, "r")
data = f.read()
f.close()
data = data.split('\n')
product = []
for line in data:
product.append(list(line))
return product
# next func sorts object into objects class so the objects is stored where it should be
def sort(obj, objects):
objects.game_objects.append(obj)
if obj.moving:
objects.moving_objects.append(obj)
if obj.move.collisions:
objects.collision_objects.append(obj)
def find_collisions(obj, objects):
hit_list = []
for element in objects.game_objects:
if element.object_id != obj.object_id:
if element.rect.colliderect(obj.rect):
hit_list.append(element)
return hit_list
def collision(obj, objects):
# collisions for left/right
obj.change_pos([obj.object_pos[0] + obj.movement[0], obj.object_pos[1]])
hit_list = find_collisions(obj, objects)
for item in hit_list:
if obj.movement[0] > 0:
item.hit_right(obj, objects)
elif obj.movement[0] < 0:
item.hit_left(obj, objects)
# collisions for top/bottom
obj.change_pos([obj.object_pos[0], obj.object_pos[1] + obj.movement[1]])
hit_list = find_collisions(obj, objects)
for item in hit_list:
if obj.movement[1] > 0:
item.hit_bottom(obj, objects)
elif obj.movement[1] < 0:
item.hit_top(obj, objects)
# !!!!!!!!!!! config this function for every program !!!!!!!!!!
def load_objects(game_map, width, height, objects, game):
x, y = 0, 0
for line in game_map:
for obj in line:
# this is just to be efficient normaly u can use elif and put another obj to another num
if obj == "1":
obj = Object("solid", game.custom_id_giver, [x, y], [0, 0], 0, False, [width, height])
obj.memory.append(3)
sort(obj, objects)
game.custom_id_giver += 1
x += width
y += height
x = 0
def load_textures(objects, dictionary, display, scroll):
for object in objects.game_objects:
if object.special:
display.blit(object.specific.images[object.specific.attribute_0],
[object.object_pos[0] - scroll.scroll[0], object.object_pos[1] - scroll.scroll[1]])
else:
display.blit(dictionary["{}".format(object.type)],
[object.object_pos[0] - scroll.scroll[0], object.object_pos[1] - scroll.scroll[1]])
def load_sp_texture(objects, type_x, image):
for object in objects.special_objects:
if object.type == type_x:
object.attributes.images.append(image)
def load_bg(image, y_x, width, height, display):
pos = [0, 0]
for i in range(y_x[0]):
for j in range(y_x[1]):
display.blit(image, pos)
pos[0] += width
pos[0] = 0
pos[1] += height
def find_angle_between_points(center, point):
dists = distances(center, point)
try:
angle = math.atan(dists[1] / dists[0])
if point[0] < center[0]:
if point[1] < center[1]:
return angle + math.pi
else:
return (math.pi / 2 - angle) + (math.pi / 2)
else:
if point[1] < center[1]:
return (math.pi / 2 - angle) + 3 * (math.pi / 2)
else:
return angle
except ZeroDivisionError:
return False
def distances(cords1, cords2):
return [abs(cords1[0] - cords2[0]), abs(cords1[1] - cords2[1])]
def average(*args):
sumX = 0
for item in args:
sumX += item
return sumX/len(args)
def area_intersection_of_circles(points, radius_list):
try:
dist = distance_indicator(points[0], points[1])
alpha_cos = (pow(radius_list[1], 2) + pow(dist, 2) - pow(radius_list[0], 2)) / (2 * radius_list[1] * dist)
alpha = math.acos(alpha_cos)
beta_cos = (dist - alpha_cos * radius_list[1]) / radius_list[0]
beta = math.acos(beta_cos)
triangles = (alpha_cos * pow(radius_list[1], 2) * math.sin(alpha)) + (
beta_cos * pow(radius_list[0], 2) * math.sin(beta))
arcs = ((math.pi * pow(radius_list[0], 2) * beta * 2) / math.tau) + (
(math.pi * pow(radius_list[1], 2) * alpha * 2) / math.tau)
return arcs - triangles
except:
return False

54
server.py Normal file

@ -0,0 +1,54 @@
import asyncio
import websockets
import time
import json
import threading
connected = set()
outreg = [{"player": "1", "data": []}, {"player": "2", "data": []}]
async def socket_broadcast(data):
for client in connected:
await client.send(str(data))
async def hello(websocket, path):
global outreg
i = 0
connected.add(websocket)
try:
while i == 0:
try:
await socket_broadcast(json.dumps(outreg))
x = await websocket.recv()
try:
datareg = json.loads(x)
if datareg['player'] == 1:
outreg[0]["data"] = datareg["data"]
elif datareg['player'] == 2:
outreg[1]["data"] = datareg["data"]
#print(json.dumps(datareg)+"\n\n\n"+json.dumps(outreg))
await socket_broadcast(json.dumps(outreg))
except Exception as e:
print(e)
except Exception as e:
print(e)
connected.remove(websocket)
i = 1
finally:
# Unregister.
connected.remove(websocket)
start_server = websockets.serve(hello, "localhost", 8765)
loop = asyncio.get_event_loop()
def loop_in_thread():
loop.run_until_complete(start_server)
loop.run_forever()
t = threading.Thread(target=loop_in_thread, args=tuple())
t.start()
print("hello")

108
spark.py Normal file

@ -0,0 +1,108 @@
import pygame
import random
import math
from pygame.locals import *
pygame.init()
# dt it missing (the epic sumo is fps dependent)
class Spark:
sparks = {}
scroll = [0, 0]
two_pi = round(math.pi * 2) * 100
def __init__(self, pos, angle, speed, colorS, group, scale=1):
self.object_pos = pos
self.angle = angle
self.speed = speed
self.scale = scale
self.scales = [self.scale * 3.5, self.scale * 0.3]
self.color = colorS
self.group = group
# preparing math
self.cosS = math.cos(self.angle) * self.speed
self.L_cosS = math.cos(self.angle + math.pi / 2) * self.speed
self.sinS = math.sin(self.angle) * self.speed
self.L_sinS = math.sin(self.angle + math.pi / 2) * self.speed
def move(self, display):
self.object_pos[0] += self.cosS
self.object_pos[1] += self.sinS
self.draw(display)
self.speed -= 0.2
# im missing the other 2 funcs here didnt really needed them currently
self.angle += 0.1
if self.speed <= 0:
self.delete_self(self)
self.redo_math()
def draw(self, display):
scroll = self.get_scroll()
c1 = self.L_cosS * self.scales[1]
c2 = self.L_sinS * self.scales[1]
p1 = [self.object_pos[0] + self.cosS * self.scale,
self.object_pos[1] + self.sinS * self.scale]
p2 = [self.object_pos[0] + c1,
self.object_pos[1] + c2]
p3 = [self.object_pos[0] - self.cosS * self.scales[0],
self.object_pos[1] - self.sinS * self.scales[0]]
p4 = [self.object_pos[0] - c1,
self.object_pos[1] - c2]
pygame.draw.polygon(display, self.color, [[p1[0] - scroll[0], p1[1] - scroll[1]],
[p2[0] - scroll[0], p2[1] - scroll[1]],
[p3[0] - scroll[0], p3[1] - scroll[1]],
[p4[0] - scroll[0], p4[1] - scroll[1]]])
def redo_math(self):
self.cosS = math.cos(self.angle) * self.speed
self.L_cosS = math.cos(self.angle + math.pi / 2) * self.speed
self.sinS = math.sin(self.angle) * self.speed
self.L_sinS = math.sin(self.angle + math.pi / 2) * self.speed
@classmethod
def delete_self(cls, spark):
cls.sparks[spark.group].remove(spark)
@classmethod
def central(cls, group, display):
for spark in cls.sparks[group]:
spark.move(display)
# math.radians(random.randint(0, 360)),
# random.uniform(0, cls.two_pi)
@classmethod
def generate(cls, group, pos, speed_lim, color_lim, scaler):
cls.sparks[group].append(Spark(pos, random.randint(0, cls.two_pi) / 100,
random.randint(speed_lim[0], speed_lim[1]),
(random.randint(color_lim[0][0], color_lim[0][1]),
random.randint(color_lim[1][0], color_lim[1][1]),
random.randint(color_lim[2][0], color_lim[2][1])), group, scaler))
@classmethod
def create(cls, group, pos, speed_lim, color_lim, scaler, amount):
for i in range(amount):
cls.generate(group, pos.copy(), speed_lim, color_lim, scaler)
@classmethod
def create_3d(cls, group, pos, speed_lim, color_lim, scaler, amount):
for i in range(amount):
cls.generate(group, pos, speed_lim, color_lim, scaler)
@classmethod
def get_scroll(cls):
return cls.scroll