else
This commit is contained in:
parent
bd4c62af18
commit
d9f16c22af
5 changed files with 58 additions and 134 deletions
123
Dots/dots.py
123
Dots/dots.py
|
@ -1,123 +0,0 @@
|
|||
import tkinter
|
||||
import threading
|
||||
import time
|
||||
|
||||
class CanvasGame:
|
||||
def managementthread(self):
|
||||
while True:
|
||||
w = self.pressed_dict.get('w', False)
|
||||
s = self.pressed_dict.get('s', False)
|
||||
a = self.pressed_dict.get('a', False)
|
||||
d = self.pressed_dict.get('d', False)
|
||||
if w:
|
||||
self.velocity_y -= self.velocity_speedup
|
||||
if s:
|
||||
self.velocity_y += self.velocity_speedup
|
||||
|
||||
if a:
|
||||
self.velocity_x -= self.velocity_speedup
|
||||
if d:
|
||||
self.velocity_x += self.velocity_speedup
|
||||
|
||||
if not any(movement for movement in [w,a,s,d]):
|
||||
nondirectional = abs(self.velocity_x) + abs(self.velocity_y)
|
||||
nondirectional /= 2
|
||||
if nondirectional < self.velocity_minimum:
|
||||
self.velocity_x = 0
|
||||
self.velocity_y = 0
|
||||
else:
|
||||
if self.velocity_x != 0:
|
||||
self.velocity_x *= self.velocity_slowdown
|
||||
if self.velocity_y != 0:
|
||||
self.velocity_y *= self.velocity_slowdown
|
||||
|
||||
|
||||
|
||||
self.velocity_x = self.numbercap(self.velocity_x, self.velocity_maximum)
|
||||
self.velocity_y = self.numbercap(self.velocity_y, self.velocity_maximum)
|
||||
|
||||
self.player_x += self.velocity_x
|
||||
self.player_y += self.velocity_y
|
||||
|
||||
x = self.x_camera + self.player_x
|
||||
y = self.y_camera + self.player_y
|
||||
xdiff = x - self.gamewidthcenter
|
||||
ydiff = y - self.gameheightcenter
|
||||
if xdiff > self.camera_distance:
|
||||
self.x_camera -= abs(xdiff / self.camera_distance)
|
||||
elif xdiff < -self.camera_distance:
|
||||
self.x_camera += abs(xdiff / self.camera_distance)
|
||||
|
||||
if ydiff > self.camera_distance:
|
||||
self.y_camera -= abs(ydiff / self.camera_distance)
|
||||
elif ydiff < -self.camera_distance:
|
||||
self.y_camera += abs(ydiff / self.camera_distance)
|
||||
|
||||
#print(self.player_x, x)
|
||||
|
||||
self.canvas.coords(self.player, x-self.player_radius, y-self.player_radius,
|
||||
x+self.player_radius, y+self.player_radius)
|
||||
|
||||
self.label_coordinates.configure(text="%d, %d" % (self.player_x, self.player_y))
|
||||
time.sleep(0.017)
|
||||
|
||||
def numbercap(self, i, cap):
|
||||
if i > cap:
|
||||
i = cap
|
||||
elif i < -cap:
|
||||
i = -cap
|
||||
return i
|
||||
|
||||
def pushkey(self, event):
|
||||
#print(event.char, "Down")
|
||||
self.pressed_dict[event.char] = True
|
||||
def releasekey(self, event):
|
||||
#print(event.char, "Up")
|
||||
self.pressed_dict[event.char] = False
|
||||
|
||||
def __init__(self):
|
||||
self.t = tkinter.Tk()
|
||||
self.pressed_dict = {}
|
||||
|
||||
self.gamewidth = 640
|
||||
self.gameheight = 480
|
||||
self.gamewidthcenter = self.gamewidth / 2
|
||||
self.gameheightcenter = self.gameheight / 2
|
||||
self.canvas = tkinter.Canvas(self.t, width=self.gamewidth, height=self.gameheight)
|
||||
self.x_camera = (self.gamewidth / 2)
|
||||
self.y_camera = (self.gameheight / 2)
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
self.player_x = x
|
||||
self.player_y = y
|
||||
self.player_radius = 3
|
||||
self.player = self.canvas.create_oval(x-self.player_radius, y-self.player_radius,
|
||||
x+self.player_radius, y+self.player_radius,
|
||||
fill="#ff0")
|
||||
self.camera = self.canvas.create_oval(self.x_camera, self.y_camera, self.x_camera, self.y_camera)
|
||||
self.camera_distance = 20
|
||||
self.playerthread = threading.Thread(name="Playerthread", target=self.managementthread)
|
||||
self.playerthread.daemon = True
|
||||
self.velocity_x = 0
|
||||
self.velocity_y = 0
|
||||
self.velocity_maximum = 4
|
||||
self.velocity_minimum = 0.2
|
||||
self.velocity_slowdown = 0.95
|
||||
self.velocity_speedup = 0.6
|
||||
|
||||
self.entities = []
|
||||
self.label_coordinates = tkinter.Label(self.canvas, text="0, 0")
|
||||
self.label_coordinates.place(x=self.gamewidthcenter, y=self.gameheight-10, anchor="c")
|
||||
|
||||
self.canvas.bind("<KeyPress>", self.pushkey)
|
||||
self.canvas.bind("<KeyRelease>", self.releasekey)
|
||||
self.canvas.focus_set()
|
||||
|
||||
self.playerthread.start()
|
||||
|
||||
self.canvas.pack()
|
||||
|
||||
self.t.mainloop()
|
||||
|
||||
c = CanvasGame()
|
|
@ -1,4 +1,10 @@
|
|||
Editor
|
||||
==========
|
||||
|
||||
A neat idea that would make for a fun website. Users read and write text files by choosing the file name. If it exists, the text is returned to them for editing. If it does not, it will be created when they press Save. No logins and no file security. Since it's using a database instead of actual txt files, there are no filename character restrictions, only a maximum title length and a couple self-imposed rules for sanity's sake.
|
||||
A neat idea that would make for a fun website. Users read and write text files by choosing the file name. If it exists, the text is returned to them for editing. If it does not, it will be created when they press Save. No logins and no file security. Since it's using a database instead of actual txt files, there are no filename character restrictions, only a maximum title length and a couple self-imposed rules for sanity's sake.
|
||||
|
||||
`ctrl+s - save file`
|
||||
`ctrl+w - return to menu (does not save)`
|
||||
`ctrl+[ - smaller font`
|
||||
`ctrl+] - larger font`
|
||||
`ctrl+/ - toggle linewrap`
|
|
@ -17,6 +17,8 @@ class Editor:
|
|||
self.font_large = ("Consolas", 16)
|
||||
self.font_med = ("Consolas", 12)
|
||||
self.font_small = ("Consolas", 10)
|
||||
self.font_username = "Consolas"
|
||||
self.font_usersize = 12
|
||||
|
||||
self.kilobyte = 1024
|
||||
self.megabyte = 1048576
|
||||
|
@ -98,18 +100,44 @@ class Editor:
|
|||
self.entities.append(self.label_filesize)
|
||||
#
|
||||
self.scrollbar_editor = tkinter.Scrollbar(self.t)
|
||||
self.scrollbar_horz = tkinter.Scrollbar(self.t, orient='horizontal')
|
||||
self.scrollbar_editor.pack(side='right', fill='y')
|
||||
self.text_editor = tkinter.Text(self.t, wrap='word', font=self.font_med, yscrollcommand=self.scrollbar_editor.set)
|
||||
self.scrollbar_horz.pack(side='bottom', fill='x')
|
||||
self.text_editor = tkinter.Text(self.t, wrap='word', font=self.font_med)
|
||||
self.text_editor.configure(yscrollcommand=self.scrollbar_editor.set)
|
||||
self.text_editor.configure(xscrollcommand=self.scrollbar_horz.set)
|
||||
self.scrollbar_editor.configure(command=self.text_editor.yview)
|
||||
self.scrollbar_horz.configure(command=self.text_editor.xview)
|
||||
self.text_editor.insert('end', filetext)
|
||||
self.text_editor.pack(expand=True, fill='both')
|
||||
self.text_editor.focus_set()
|
||||
self.text_editor.bind('<Control-s>', self.savefile_smart)
|
||||
self.text_editor.bind('<Control-w>', self.gui_build_fileloader)
|
||||
self.text_editor.bind('<Control-[>', lambda s: self.editor_resize_font(-1))
|
||||
self.text_editor.bind('<Control-]>', lambda s: self.editor_resize_font(1))
|
||||
self.text_editor.bind('<Control-/>', self.editor_toggle_wrap)
|
||||
self.entities.append(self.text_editor)
|
||||
self.entities.append(self.scrollbar_editor)
|
||||
self.entities.append(self.scrollbar_horz)
|
||||
###
|
||||
|
||||
def editor_resize_font(self, direction, *b):
|
||||
self.font_usersize += direction
|
||||
if self.font_usersize < 1:
|
||||
self.font_usersize = 1
|
||||
font = [self.font_username, self.font_usersize]
|
||||
self.text_editor.configure(font=font)
|
||||
self.label_filesize.configure(text=str(self.font_usersize))
|
||||
|
||||
def editor_toggle_wrap(self, *b):
|
||||
mode = self.text_editor.cget('wrap')
|
||||
if mode == 'word':
|
||||
self.text_editor.configure(wrap='none')
|
||||
self.label_filesize.configure(text='word wrap disabled')
|
||||
if mode == 'none':
|
||||
self.text_editor.configure(wrap='word')
|
||||
self.label_filesize.configure(text='word wrap enabled')
|
||||
|
||||
def savefile_smart(self, *b):
|
||||
try:
|
||||
filetext = self.text_editor.get('0.0', 'end')
|
||||
|
|
Binary file not shown.
|
@ -40,8 +40,10 @@ class LogoGame:
|
|||
self.cur = self.sql.cursor()
|
||||
self.stats_main = self.stats_load('stats')
|
||||
self.playerstats_load(self.stats_main.playername)
|
||||
self.logos_load()
|
||||
|
||||
self.tkinter_elements = []
|
||||
self.logo_elements = []
|
||||
self.active_tags = set()
|
||||
|
||||
self.w = 1062
|
||||
|
@ -62,19 +64,20 @@ class LogoGame:
|
|||
|
||||
self.t.mainloop()
|
||||
|
||||
def update_wh(self, *b):
|
||||
oldw = self.w
|
||||
oldh = self.h
|
||||
self.w = self.t.winfo_width()
|
||||
self.h = self.t.winfo_height()
|
||||
if oldw != self.w or oldh != self.h:
|
||||
pass
|
||||
#self.uirefresher()
|
||||
def logos_load(self):
|
||||
self.cur.execute('SELECT * FROM logos')
|
||||
self.all_logos = self.cur.fetchall()
|
||||
|
||||
def destroy_all_elements(self):
|
||||
while len(self.tkinter_elements) > 0:
|
||||
self.tkinter_elements[0].destroy()
|
||||
del self.tkinter_elements[0]
|
||||
self.destroy_all_logos()
|
||||
|
||||
def destroy_all_logos(self):
|
||||
while len(self.logo_elements) > 0:
|
||||
self.logo_elements[0].destroy()
|
||||
del self.logo_elements[0]
|
||||
|
||||
def gui_build_main(self, *b):
|
||||
self.destroy_all_elements()
|
||||
|
@ -147,22 +150,32 @@ class LogoGame:
|
|||
self.button_back.grid(row=0, column=0)
|
||||
self.tkinter_elements.append(self.button_back)
|
||||
#
|
||||
#self.frame_gamearea = tkinter.Frame(self.t, bg='#f00')
|
||||
#self.frame_gamearea.pack(expand=True, fill='both', anchor='w')
|
||||
#
|
||||
self.frame_gametaglist = tkinter.Frame(self.t)
|
||||
self.frame_gametaglist.pack(expand=True, fill='y', anchor='e')
|
||||
self.tkinter_elements.append(self.frame_gametaglist)
|
||||
#
|
||||
button_applytag = tkinter.Button(self.frame_gametaglist, text='Apply', command=self.gui_rebuild_game)
|
||||
button_applytag.grid(row=0, column=0, sticky='w')
|
||||
alltags = self.get_all_tags()
|
||||
for tag in alltags:
|
||||
intvar = tkinter.IntVar()
|
||||
intvar.title=tag
|
||||
checkbox = tkinter.Checkbutton(self.frame_gametaglist, text=tag, variable=intvar)
|
||||
checkbox.intvar = intvar
|
||||
checkbox.grid(row=alltags.index(tag), column=0, sticky='w')
|
||||
checkbox.grid(row=alltags.index(tag)+1, column=0, sticky='w')
|
||||
intvar.set(1)
|
||||
self.tkinter_elements.append(checkbox)
|
||||
self.active_tags.add(tag)
|
||||
|
||||
###
|
||||
|
||||
def gui_rebuild_game(self, *b):
|
||||
self.destroy_all_logos()
|
||||
|
||||
|
||||
def gui_build_logo(self, *b):
|
||||
self.destroy_all_elements()
|
||||
###
|
||||
|
|
Loading…
Reference in a new issue