cc
This commit is contained in:
Benjamín 2020-12-16 20:40:19 +01:00
parent 14871022ab
commit d61d7a1b1f
12 changed files with 97 additions and 90 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1 +0,0 @@
Yes u found the save file congrats.

1
assets/save.json Normal file

@ -0,0 +1 @@
{}

BIN
assets/textures/load.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

@ -1,3 +1,4 @@
import json
import math import math
import random import random
import pygame import pygame
@ -105,13 +106,13 @@ class Game:
for circle in self.circles: for circle in self.circles:
dist = distance_indicator(circle.center, self.midpoint) dist = distance_indicator(circle.center, self.midpoint)
angle = find_angle_between_points(circle.center, self.midpoint) angle = find_angle_between_points(circle.center, self.midpoint)
final_value[0] += round(math.cos(angle) * dist, 2) * (circle.radius/20) final_value[0] += round(math.cos(angle) * dist, 2) * (circle.radius / 20)
final_value[1] += round(math.sin(angle) * dist, 2) * (circle.radius/20) final_value[1] += round(math.sin(angle) * dist, 2) * (circle.radius / 20)
dist = distance_indicator(self.midpoint, [final_value[0] + self.midpoint[0], final_value[1] + self.midpoint[1]]) dist = distance_indicator(self.midpoint, [final_value[0] + self.midpoint[0], final_value[1] + self.midpoint[1]])
if dist > self.limit: if dist > self.limit:
self.collapse = True self.collapse = True
self.alive =False self.alive = False
elif dist > self.limit * 0.6: elif dist > self.limit * 0.6:
self.black.color_value.r = round((dist - (self.limit * 0.6)) * (255 / (self.limit * 0.4))) self.black.color_value.r = round((dist - (self.limit * 0.6)) * (255 / (self.limit * 0.4)))
@ -160,6 +161,44 @@ class Game:
circle.center = [self.midpoint[0] + (math.cos(angle) * dist), circle.center = [self.midpoint[0] + (math.cos(angle) * dist),
self.midpoint[1] + (math.sin(angle) * dist)] self.midpoint[1] + (math.sin(angle) * dist)]
# saving & loading
def save(self, path, setup):
save = {"gravity": setup["gravity"],
"next_circle": self.c_template,
"limit": self.limit,
"points": self.points,
"circles": []}
for circle in self.circles:
save["circles"].append({"radius": circle.radius,
"center": circle.center,
"color": circle.color,
"color_value": str(circle.color_value)})
del save["circles"][0]
with open(path, "w") as f:
json.dump(save, f, indent=4)
def load(self, path, setup):
with open(path, "r") as f:
save = json.load(f)
setup["gravity"] = save["gravity"]
self.c_template = save["next_circle"]
for circle in save["circles"]:
self.circles.append(Circle(circle["radius"], circle["center"], circle["color"],
pygame.Color(eval(circle["color_value"]))))
self.points = save["points"]
self.limit = save["limit"]
return setup
class Scroll: class Scroll:
def __init__(self, scroll): def __init__(self, scroll):
@ -219,7 +258,7 @@ def get_random_color():
colors = add_to_list("yellow", 18, colors) colors = add_to_list("yellow", 18, colors)
colors = add_to_list("purple", 4, colors) colors = add_to_list("purple", 4, colors)
colors = add_to_list("smaragd", 1, colors) colors = add_to_list("smaragd", 1, colors)
return colors[random.randint(0, len(colors)-1)] return colors[random.randint(0, len(colors) - 1)]
def get_circle_template(): def get_circle_template():
@ -267,7 +306,7 @@ def get_circle(color_value, radius):
def get_gravity_sur(gravity, limit): def get_gravity_sur(gravity, limit):
ratio = limit/40 ratio = limit / 40
sur = pygame.Surface((100, 100)) sur = pygame.Surface((100, 100))
pygame.draw.circle(sur, (200, 200, 200), [50, 50], 40) pygame.draw.circle(sur, (200, 200, 200), [50, 50], 40)
pygame.draw.circle(sur, (217, 24, 114), [50 + (gravity[0] / ratio), 50 + (gravity[1] / ratio)], 10) pygame.draw.circle(sur, (217, 24, 114), [50 + (gravity[0] / ratio), 50 + (gravity[1] / ratio)], 10)

Binary file not shown.

@ -1,4 +1,3 @@
from fast_and_trash import *
from Sounds import * from Sounds import *
from mouse_engine import * from mouse_engine import *
import pygame import pygame
@ -16,6 +15,7 @@ tiny_font = pygame.font.SysFont('Comic Sans MS', 20)
Window_size = [900, 600] Window_size = [900, 600]
Default_size = Window_size Default_size = Window_size
monitor_size = [pygame.display.Info().current_w, pygame.display.Info().current_h]
screen = pygame.display.set_mode(Window_size) screen = pygame.display.set_mode(Window_size)
display = pygame.Surface((900, 600)) display = pygame.Surface((900, 600))
pygame.display.set_caption("Planetio") pygame.display.set_caption("Planetio")
@ -44,11 +44,18 @@ def menu(screenX, fs, Win_size):
sheets[3].set_colorkey((0, 0, 0)) sheets[3].set_colorkey((0, 0, 0))
s_index = 0 s_index = 0
load = [pygame.image.load("assets/textures/load.png").convert(),
pygame.image.load("assets/textures/load_hover.png").convert()]
for item in load:
item.set_colorkey((0, 0, 0))
l_index = 0
# values to pass # values to pass
setup = {"rotate": True, setup = {"rotate": True,
"gravity": False, "gravity": False,
"cheatsheet": True} "cheatsheet": True,
"load": False}
# mouse # mouse
@ -57,17 +64,6 @@ def menu(screenX, fs, Win_size):
rotate_color = (0, 0, 0) rotate_color = (0, 0, 0)
r_circle_cords = [730, 500] r_circle_cords = [730, 500]
# checking if tutorial
file = open("assets/save", "r")
place = file.read()
file.close()
if place == "tutorial":
screenX, fs, Win_size = tutorial(screenX, fs, Win_size)
file = open("assets/save", "w")
file.write("Yes u found the save file congrats.")
file.close()
# game loop # game loop
while alive: while alive:
display.fill((255, 255, 255)) display.fill((255, 255, 255))
@ -83,10 +79,20 @@ def menu(screenX, fs, Win_size):
mouse.update(Win_size, Default_size) mouse.update(Win_size, Default_size)
# setting actions for buttons # setting actions for buttons
if mouse.in_circle([200, 120], 50):
with open("assets/save.json", "r") as f:
file = json.load(f)
if file != {}:
setup["load"] = True
sounds["click"].play(0)
screenX, fs, Win_size = run_game(screenX, fs, setup, Win_size)
setup["load"] = False
if mouse.in_circle([450, 300], 50): if mouse.in_circle([450, 300], 50):
sounds["click"].play(0) sounds["click"].play(0)
run_game(screenX, fs, setup, Win_size) screenX, fs, Win_size = run_game(screenX, fs, setup, Win_size)
if mouse.in_circle([700, 500], 20): if mouse.in_circle([700, 500], 20):
sounds["click"].play(0) sounds["click"].play(0)
@ -130,6 +136,11 @@ def menu(screenX, fs, Win_size):
else: else:
s_index = 0 s_index = 0
if mouse.in_circle([200, 120], 50):
l_index = 1
else:
l_index = 0
if event.type == KEYDOWN: if event.type == KEYDOWN:
if event.key == K_f: if event.key == K_f:
fs = not fs fs = not fs
@ -137,9 +148,9 @@ def menu(screenX, fs, Win_size):
Win_size = Default_size Win_size = Default_size
screenX = pygame.display.set_mode(Win_size) screenX = pygame.display.set_mode(Win_size)
else: else:
screenX = pygame.display.set_mode(Win_size, pygame.FULLSCREEN) screenX = pygame.display.set_mode(monitor_size, pygame.FULLSCREEN)
d = pygame.display.get_surface() d = pygame.display.get_surface()
Win_size = [d.get_width(), int((d.get_width()*2)/3)] Win_size = [int((d.get_height() / 2) * 3), d.get_height()]
elif event.key == K_ESCAPE: elif event.key == K_ESCAPE:
pygame.quit() pygame.quit()
@ -164,6 +175,10 @@ def menu(screenX, fs, Win_size):
else: else:
display.blit(sheets[0 + (s_index * 2)], [700, 100]) display.blit(sheets[0 + (s_index * 2)], [700, 100])
# load
display.blit(load[l_index], [140, 60])
# basic loop config # basic loop config
screenX.blit(pygame.transform.scale(display, Win_size), (0, 0)) screenX.blit(pygame.transform.scale(display, Win_size), (0, 0))
@ -200,6 +215,10 @@ def run_game(screenX, fs, setup, Win_size):
cheatsheet.set_colorkey((0, 0, 0)) cheatsheet.set_colorkey((0, 0, 0))
cheatsheet.set_alpha(180) cheatsheet.set_alpha(180)
# if loading
if setup["load"]:
setup = game.load("assets/save.json", setup)
while game.alive: while game.alive:
display.fill((255, 255, 255)) display.fill((255, 255, 255))
@ -260,6 +279,7 @@ def run_game(screenX, fs, setup, Win_size):
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == QUIT: if event.type == QUIT:
game.save("assets/save.json", setup)
pygame.quit() pygame.quit()
sys.exit() sys.exit()
@ -304,14 +324,17 @@ def run_game(screenX, fs, setup, Win_size):
Win_size = Default_size Win_size = Default_size
screenX = pygame.display.set_mode(Win_size) screenX = pygame.display.set_mode(Win_size)
else: else:
screenX = pygame.display.set_mode(Win_size, pygame.FULLSCREEN) screenX = pygame.display.set_mode(monitor_size, pygame.FULLSCREEN)
d = pygame.display.get_surface() d = pygame.display.get_surface()
Win_size = [d.get_width(), int((d.get_width() * 2) / 3)] Win_size = [int((d.get_height() / 2) * 3), d.get_height()]
elif event.key == K_ESCAPE: elif event.key == K_ESCAPE:
game.save("assets/save.json", setup)
return screenX, fs, Win_size return screenX, fs, Win_size
elif event.key == K_r: elif event.key == K_r:
with open("assets/save.json", "w") as f:
json.dump({}, f, indent=4)
return screenX, fs, Win_size return screenX, fs, Win_size
# managing scroll # managing scroll
@ -352,6 +375,10 @@ def run_game(screenX, fs, setup, Win_size):
screenX.blit(pygame.transform.scale(display, Win_size), (0, 0)) screenX.blit(pygame.transform.scale(display, Win_size), (0, 0))
pygame.display.update() pygame.display.update()
# todo save
with open("assets/save.json", "w") as f:
json.dump({}, f, indent=4)
# ending # ending
if game.collapse: if game.collapse:
screenX, fs, Win_size = end(screenX, fs, Win_size, game, "collapse") screenX, fs, Win_size = end(screenX, fs, Win_size, game, "collapse")
@ -416,9 +443,9 @@ def end(screenX, fs, Win_size, game, reason):
Win_size = Default_size Win_size = Default_size
screenX = pygame.display.set_mode(Win_size) screenX = pygame.display.set_mode(Win_size)
else: else:
screenX = pygame.display.set_mode(Win_size, pygame.FULLSCREEN) screenX = pygame.display.set_mode(monitor_size, pygame.FULLSCREEN)
d = pygame.display.get_surface() d = pygame.display.get_surface()
Win_size = [d.get_width(), int((d.get_width() * 2) / 3)] Win_size = [int((d.get_height() / 2) * 3), d.get_height()]
elif event.key == K_ESCAPE: elif event.key == K_ESCAPE:
return screenX, fs, Win_size return screenX, fs, Win_size
@ -441,64 +468,5 @@ def end(screenX, fs, Win_size, game, reason):
clock.tick(60) clock.tick(60)
def tutorial(screenX, fs, Win_size):
menu_buttons = pygame.transform.scale(pygame.image.load("assets/textures/tutorial/menu_buttons.png").convert(),
[400, 400])
full_s = small_font.render("F = FULLSCREEN", False, (0, 0, 0))
colorX = (10, 10, 10)
mouse = Mouse([0, 0])
mouse.update(Win_size, Default_size)
alive = True
while alive:
mouse.update(Win_size, Default_size)
# drawing things
display.fill((255, 255, 255))
display.blit(menu_buttons, [50, 40])
display.blit(full_s, [50, 470])
pygame.draw.circle(display, colorX, [700, 300], 40)
# event loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key == K_f:
fs = not fs
if fs is False:
Win_size = Default_size
screenX = pygame.display.set_mode(Win_size)
else:
screenX = pygame.display.set_mode(Win_size, pygame.FULLSCREEN)
d = pygame.display.get_surface()
Win_size = [d.get_width(), int((d.get_width()*2)/3)]
elif event.key == K_ESCAPE:
return screenX, fs, Win_size
elif event.type == MOUSEMOTION:
if mouse.in_circle([700, 300], 40):
colorX = (80, 80, 80)
else:
colorX = (10, 10, 10)
elif event.type == MOUSEBUTTONDOWN:
if mouse.in_circle([700, 300], 40):
return screenX, fs, Win_size
# basic loop config
screenX.blit(pygame.transform.scale(display, Win_size), (0, 0))
pygame.display.update()
clock.tick(60)
menu(screen, False, Window_size) menu(screen, False, Window_size)
# pip install pygame==2.0.0.dev16 # pip install pygame==2.0.0.dev16