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 random
import pygame
@ -105,13 +106,13 @@ class Game:
for circle in self.circles:
dist = distance_indicator(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[1] += round(math.sin(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)
dist = distance_indicator(self.midpoint, [final_value[0] + self.midpoint[0], final_value[1] + self.midpoint[1]])
if dist > self.limit:
self.collapse = True
self.alive =False
self.alive = False
elif dist > self.limit * 0.6:
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),
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:
def __init__(self, scroll):
@ -203,11 +242,11 @@ class Scroll:
def get_colors():
colors = {"red": pygame.Color(255, 0, 0, 125), # weight 16
"blue": pygame.Color(0, 0, 220, 125), # weight 20
"green": pygame.Color(0, 220, 0, 125), # weight 20
"yellow": pygame.Color(252, 239, 56, 125), # weight 22
"purple": pygame.Color(105, 0, 158, 125), # weight 4
"smaragd": pygame.Color(0, 214, 168, 125)} # weight 1
"blue": pygame.Color(0, 0, 220, 125), # weight 20
"green": pygame.Color(0, 220, 0, 125), # weight 20
"yellow": pygame.Color(252, 239, 56, 125), # weight 22
"purple": pygame.Color(105, 0, 158, 125), # weight 4
"smaragd": pygame.Color(0, 214, 168, 125)} # weight 1
return colors
@ -219,7 +258,7 @@ def get_random_color():
colors = add_to_list("yellow", 18, colors)
colors = add_to_list("purple", 4, 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():
@ -267,7 +306,7 @@ def get_circle(color_value, radius):
def get_gravity_sur(gravity, limit):
ratio = limit/40
ratio = limit / 40
sur = pygame.Surface((100, 100))
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)

Binary file not shown.

@ -1,4 +1,3 @@
from fast_and_trash import *
from Sounds import *
from mouse_engine import *
import pygame
@ -16,6 +15,7 @@ tiny_font = pygame.font.SysFont('Comic Sans MS', 20)
Window_size = [900, 600]
Default_size = Window_size
monitor_size = [pygame.display.Info().current_w, pygame.display.Info().current_h]
screen = pygame.display.set_mode(Window_size)
display = pygame.Surface((900, 600))
pygame.display.set_caption("Planetio")
@ -44,11 +44,18 @@ def menu(screenX, fs, Win_size):
sheets[3].set_colorkey((0, 0, 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
setup = {"rotate": True,
"gravity": False,
"cheatsheet": True}
"cheatsheet": True,
"load": False}
# mouse
@ -57,17 +64,6 @@ def menu(screenX, fs, Win_size):
rotate_color = (0, 0, 0)
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
while alive:
display.fill((255, 255, 255))
@ -83,10 +79,20 @@ def menu(screenX, fs, Win_size):
mouse.update(Win_size, Default_size)
# 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):
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):
sounds["click"].play(0)
@ -130,6 +136,11 @@ def menu(screenX, fs, Win_size):
else:
s_index = 0
if mouse.in_circle([200, 120], 50):
l_index = 1
else:
l_index = 0
if event.type == KEYDOWN:
if event.key == K_f:
fs = not fs
@ -137,9 +148,9 @@ def menu(screenX, fs, Win_size):
Win_size = Default_size
screenX = pygame.display.set_mode(Win_size)
else:
screenX = pygame.display.set_mode(Win_size, pygame.FULLSCREEN)
screenX = pygame.display.set_mode(monitor_size, pygame.FULLSCREEN)
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:
pygame.quit()
@ -164,6 +175,10 @@ def menu(screenX, fs, Win_size):
else:
display.blit(sheets[0 + (s_index * 2)], [700, 100])
# load
display.blit(load[l_index], [140, 60])
# basic loop config
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_alpha(180)
# if loading
if setup["load"]:
setup = game.load("assets/save.json", setup)
while game.alive:
display.fill((255, 255, 255))
@ -260,6 +279,7 @@ def run_game(screenX, fs, setup, Win_size):
for event in pygame.event.get():
if event.type == QUIT:
game.save("assets/save.json", setup)
pygame.quit()
sys.exit()
@ -304,14 +324,17 @@ def run_game(screenX, fs, setup, Win_size):
Win_size = Default_size
screenX = pygame.display.set_mode(Win_size)
else:
screenX = pygame.display.set_mode(Win_size, pygame.FULLSCREEN)
screenX = pygame.display.set_mode(monitor_size, pygame.FULLSCREEN)
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:
game.save("assets/save.json", setup)
return screenX, fs, Win_size
elif event.key == K_r:
with open("assets/save.json", "w") as f:
json.dump({}, f, indent=4)
return screenX, fs, Win_size
# managing scroll
@ -352,6 +375,10 @@ def run_game(screenX, fs, setup, Win_size):
screenX.blit(pygame.transform.scale(display, Win_size), (0, 0))
pygame.display.update()
# todo save
with open("assets/save.json", "w") as f:
json.dump({}, f, indent=4)
# ending
if 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
screenX = pygame.display.set_mode(Win_size)
else:
screenX = pygame.display.set_mode(Win_size, pygame.FULLSCREEN)
screenX = pygame.display.set_mode(monitor_size, pygame.FULLSCREEN)
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:
return screenX, fs, Win_size
@ -441,64 +468,5 @@ def end(screenX, fs, Win_size, game, reason):
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)
# pip install pygame==2.0.0.dev16