Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea

__pycache__
100 changes: 100 additions & 0 deletions ButtonUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import os
from Widgets import *


def create_buttons(output, painting):
brush_water = MyButton(output, painting, os.path.join("Resources", "brush_water.png"),
25, 33, 50, 60,
ButtonData('normal_button', 15, Colors.water), '水域',
['*PAINT COLORS*', ' ', 'Current Size : '], Colors.coolred)
brush_neighborhood = MyButton(output, painting, os.path.join("Resources", "brush_neighborhood.png"),
80, 33, 50, 60,
ButtonData('normal_button', 15, Colors.neighborhood), '街区',
['*PAINT COLORS*', ' ', 'Current Size : '], Colors.coolred)
brush_culture = MyButton(output, painting, os.path.join("Resources", "brush_culture.png"),
135, 33, 50, 60,
ButtonData('normal_button', 15, Colors.culture), '文化区',
['*PAINT COLORS*', ' ', 'Current Size : '], Colors.coolred)
brush_vegetation = MyButton(output, painting, os.path.join("Resources", "brush_vegetation.png"),
190, 33, 50, 60,
ButtonData('normal_button', 15, Colors.vegetation), '绿化区',
['*PAINT COLORS*', ' ', 'Current Size : '], Colors.coolred)

pencil_road0 = MyButton(output, painting, os.path.join("Resources", "pencil_road0.png"), 25, 95, 50, 60,
ButtonData('normal_button', 2, Colors.road_0), '小道',
['*DRAW*', ' ', 'Current Size : '], Colors.carrot)
pencil_road1 = MyButton(output, painting, os.path.join("Resources", "pencil_road1.png"), 80, 95, 50, 60,
ButtonData('normal_button', 8, Colors.road_1), '公路',
['*DRAW*', ' ', 'Current Size : '], Colors.carrot)
pencil_road2 = MyButton(output, painting, os.path.join("Resources", "pencil_road2.png"), 135, 95, 50, 60,
ButtonData('normal_button', 12, Colors.road_2), '高速公路',
['*DRAW*', ' ', 'Current Size : '], Colors.carrot)
pencil_road3 = MyButton(output, painting, os.path.join("Resources", "pencil_road3.png"), 190, 95, 50, 60,
ButtonData('normal_button', 12, Colors.road_3), '在建道路与其它道路',
['*DRAW*', ' ', 'Current Size : '], Colors.carrot)
# pencil_road1 = MyButton(output, painting, os.path.join("Resources", "pencil_road1.png"), 25, 150, 50, 60,
# ButtonData('normal_button', 2, Colors.road_0), 'Pencil',
# ['*DRAW*', ' ', 'Current Size : '], Colors.carrot)

eraser = MyButton(output, painting, os.path.join("Resources", "eraser.png"), 30, 230, 50, 60,
ButtonData('function_button', None, None), 'Eraser',
['*CLEARS SELECTED*', ' ', 'Current Size : '], Colors.coolblue)
rbin = MyButton(output, painting, os.path.join("Resources", "bin.png"), 135, 230, 50, 60,
ButtonData('function_button', None, None), 'Clear',
['*CLEARS ALL*', ' ', 'Current Size : '], Colors.cloud)
bplus = MyButton(output, painting, os.path.join("Resources", "plus.png"), 31, 510, 35, 45,
ButtonData('function_button', None, None), 'Brush Size +',
['**INCREASE SIZE**', 'Current Size : '], Colors.coolred)
bminus = MyButton(output, painting, os.path.join("Resources", "minus.png"), 200, 510, 35, 50,
ButtonData('function_button', None, None), 'Brush Size -',
['**DECREASE SIZE**', 'Current Size : '], Colors.coolblue)
cplus = MyButton(output, painting, os.path.join("Resources", "plus.png"), 31, 450, 35, 45,
ButtonData('function_button', None, None), 'Darken Brush',
['**INCREASE SIZE**', 'Current Size : '], Colors.coolred)
cminus = MyButton(output, painting, os.path.join("Resources", "minus.png"), 200, 450, 35, 50,
ButtonData('function_button', None, None), 'Lighten Brush',
['**DECREASE SIZE**', 'Current Size : '], Colors.coolblue)

buttons = [brush_water, brush_neighborhood, brush_culture, brush_vegetation,
pencil_road0, pencil_road1, pencil_road2, pencil_road3,
eraser, rbin, bplus, bminus, cplus, cminus]

return buttons


def create_color_button(output, painting):
black_b = ColorButton(output, painting, Colors.black, 150, 330, 40, 50,
ButtonData('color_button', None, None), 'Black')
white_b = ColorButton(output, painting, Colors.white, 190, 330, 40, 50,
ButtonData('color_button', None, None), 'White')
red_b = ColorButton(output, painting, Colors.road_1, 50, 330, 20, 25,
ButtonData('color_button', None, None), 'Road_1')
cred_b = ColorButton(output, painting, Colors.coolred, 50, 350, 20, 25,
ButtonData('color_button', None, None), 'Red')
yellow_b = ColorButton(output, painting, Colors.yellow, 70, 330, 20, 25,
ButtonData('color_button', None, None), 'Yellow')
cyellow_b = ColorButton(output, painting, Colors.coolyellow, 70, 350, 20, 25,
ButtonData('color_button', None, None), 'Yellow')
blue_b = ColorButton(output, painting, Colors.blue, 90, 330, 20, 25,
ButtonData('color_button', None, None), 'Blue')
cblue_b = ColorButton(output, painting, Colors.coolblue, 90, 350, 20, 25,
ButtonData('color_button', None, None), 'Blue')
green_b = ColorButton(output, painting, Colors.green, 110, 330, 20, 25,
ButtonData('color_button', None, None), 'Green')
cgreen_b = ColorButton(output, painting, Colors.coolgreen, 110, 350, 20, 25,
ButtonData('color_button', None, None), 'Green')
skin_b = ColorButton(output, painting, (255, 160, 122), 50, 370, 20, 25,
ButtonData('color_button', None, None), 'Skin')
pink_b = ColorButton(output, painting, (255, 105, 180), 70, 370, 20, 25,
ButtonData('color_button', None, None), 'Yellow')
brown_b = ColorButton(output, painting, (139, 69, 19), 90, 370, 20, 25,
ButtonData('color_button', None, None), 'Blue')
grey_b = ColorButton(output, painting, Colors.red, 110, 370, 20, 25,
ButtonData('color_button', None, None), 'Red')

color_buttons = [black_b, white_b, red_b, cred_b,
yellow_b, cyellow_b, blue_b, cblue_b,
green_b, cgreen_b, skin_b, pink_b,
brown_b, grey_b]

return color_buttons
52 changes: 52 additions & 0 deletions Colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class Colors:
coolgrey = (52, 73, 94)
pick = (103, 128, 159)
silver = (189, 195, 199)
spacecol = (70, 70, 70)
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)
blue = (0, 0, 255)
green = (0, 255, 0)
coolred = (231, 76, 60)
darkred = (201, 46, 30)

coolpurple = (142, 68, 173)

coolblue = (52, 152, 219)
darkblue = (22, 122, 189)

coolyellow = (244, 208, 63)
darkyellow = (214, 178, 33)

hyperlapse = (103, 128, 159)
coolgreen = (27, 188, 155)
darkgreen = (16, 68, 40)
carrot = (230, 126, 34)
cloud = (236, 240, 241)
brown = (139, 69, 19)
yellow = (255, 255, 0)

mountain = (244, 244, 244)
water = (178, 206, 254)
neighborhood = (210, 232, 245)
culture = (255, 130, 130)
vegetation = (180, 235, 175)

road_0 = (255, 255, 255)
road_1 = (255, 240, 187)
road_2 = (255, 172, 77)
road_3 = (227, 227, 227)

def __init__(self):
return


def tupadd(tup, howmuch):
listify = list(tup)

for i in range(len(listify)):
if 0 < (listify[i] + howmuch) < 255:
listify[i] += howmuch

return listify
38 changes: 0 additions & 38 deletions Colours.py

This file was deleted.

45 changes: 45 additions & 0 deletions FileSystem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
import pygame


class FileSystem:
def __init__(self, start_name, input_dir, output_dir, output_name, blank=False):
self.start_name = start_name
self.input_dir = input_dir
self.output_dir = output_dir
self.output_name = output_name
self.blank = blank

if self.blank:
self.file_names = [self.output_name]
self.idx = 0
self.cur_img = None
else:
self.file_names = os.listdir(input_dir)
self.idx = self.file_names.index(start_name)
self.cur_img = None
self.read_cur()
return

def read_cur(self):
if self.blank:
return self.cur_img
file_name = os.path.join(self.input_dir, self.file_names[self.idx])
self.cur_img = pygame.image.load(file_name)
return

def get_cur(self):
return self.cur_img

def get_next(self):
if self.idx + 1 >= len(self.file_names):
return None
else:
self.idx += 1
self.read_cur()
return self.get_cur()

def save_img(self, canvas):
file_name = os.path.join(self.output_dir, self.file_names[self.idx])
pygame.image.save(canvas, file_name)
return
29 changes: 17 additions & 12 deletions Functions.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
from Colours import *
import pygame
import math
from Colors import *

w_width = 1000
w_height = 800

def fullquit():
def full_quit():
pygame.quit()
quit()

def message_to_screen(window,msg,colour=cloud,x=0,y=0,fontsize=25,bold=False,italic = False ):
message_font = pygame.font.SysFont("Century Gothic",fontsize,bold,italic)
screen_text = message_font.render(msg,True,colour)
window.blit(screen_text,[x,y])

def message_to_screen(window, msg, color=Colors.cloud, x=0, y=0, fontsize=20, bold=False, italic=False):
message_font = pygame.font.SysFont("SimHei", fontsize, bold, italic)
screen_text = message_font.render(msg, True, color)
window.blit(screen_text, [x, y])
return



def mouse_pos_distance(vec_a, vec_b):
return math.sqrt(math.pow(vec_a[0] - vec_b[0], 2) + math.pow(vec_a[1] - vec_b[1], 2))





def forward_a_step(vec_a, vec_b, v_size):
vec_diff = [vec_b[0] - vec_a[0], vec_b[1] - vec_a[1]]
vec_diff_m = math.sqrt(math.pow(vec_diff[0], 2) + math.pow(vec_diff[1], 2)) + 1e-20
vec_diff_n = [vec_diff[0] / vec_diff_m, vec_diff[1] / vec_diff_m]
ret = [vec_a[0] + vec_diff_n[0] * v_size, vec_a[1] + vec_diff_n[1] * v_size]
return ret
43 changes: 35 additions & 8 deletions GameData.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
import pygame
import math
from Colours import *
from Colors import *
from Functions import *


class BaseGame:
def __init__(self):
pygame.init()

pygame.init()
# Window
self.window_width = 960
self.window_height = 700
self.window_size = (self.window_width, self.window_height)
self.window = pygame.display.set_mode(self.window_size) # pygame.NOFRAME

window_size = window_width , window_height = 1000,800
window = pygame.display.set_mode(window_size)#, pygame.NOFRAME )
# Game info
pygame.display.set_caption("Map Painter")

pygame.display.set_caption("Project MAN")
self.clock = pygame.time.Clock()
self.FPS = 1000
self.font = pygame.font.SysFont("Century Gothic", 25)

clock = pygame.time.Clock()
FPS = 1000
# Border
self.border_width = 10

font = pygame.font.SysFont( "Century Gothic" , 25 )
# Toolbar
self.toolbar_x = self.border_width
self.toolbar_y = self.border_width
self.toolbar_w = 250
self.toolbar_h = self.window_height - 2 * self.border_width

# Canvas
self.canvas_x = self.border_width + self.toolbar_w + self.border_width
self.canvas_y = self.border_width
self.canvas_w = self.window_width - self.canvas_x - self.border_width
self.canvas_h = self.window_height - 2 * self.border_width

# Info box
self.infobox_w = self.toolbar_w - 2 * self.border_width
self.infobox_h = 50
self.infobox_x = 2 * self.border_width
self.infobox_y = self.window_height - 2 * self.border_width - self.infobox_h

return
Loading