Compare commits

...

52 Commits

Author SHA1 Message Date
dfdf3ef610 Some test with threading in qt-test.py 2024-02-24 15:39:12 +01:00
86a6c6280a Added pyinstaller cli commands documentation 2024-02-24 14:53:54 +01:00
d7d0db970e Updated .gitignore 2024-02-24 14:25:29 +01:00
0d0786d412 Uploaded qt-test.py for test with qt 2024-02-23 23:06:45 +01:00
9748e4f7da Added text_input_handler (prototype) 2024-02-14 22:14:37 +01:00
3589bd49ee Update Labels class 2024-02-14 21:04:05 +01:00
2e9bbc7d19 SOme changes on Labelclass 2024-02-13 19:59:14 +01:00
187803d3f7 Builded prototype of labels class 2024-02-09 21:39:35 +01:00
907da56d23 Added some codecomments 2024-02-08 11:01:08 +01:00
b229ca3da0 Added new concept images for menu 2024-02-07 20:20:26 +01:00
2a60195960 Removed pygame-menu and code cleanup
Added game class
2024-02-06 22:28:14 +01:00
caad5c9dbc Added snake sprite 2024-02-04 22:31:59 +01:00
d312fa3308 Update Fruit class
Added multiplie fruitcolors and spawn them random
2024-02-04 18:33:16 +01:00
cbcf1e6bbd Update imageobj for tests 2024-02-04 17:28:04 +01:00
4b48e17cea Uploading Fruit-icons 2024-02-04 17:22:41 +01:00
d55aac72a6 Added image for fruits
TODO: Optimize GameObjects class for images and sprites
2024-02-02 13:38:06 +01:00
cd6a884ac9 Add new Surface / movementarea for Snake 2024-02-02 12:33:28 +01:00
3284f3d0ac Update of GameObjects module
Code cleanup
2024-02-01 14:36:30 +01:00
65ac13612d Code cleanup
Added Gameover mechanics...
2024-02-01 09:16:07 +01:00
d0bbdfd6f1 Code cleanup
Repositioning Scoreboard to center of top
2024-01-30 21:18:27 +01:00
92fd4a4cb2 Rewrite Gameobjects
Added new movementfunction
Code cleanup

Todo: Remove old class and update code for new one
2024-01-29 21:47:43 +01:00
a3269826bf Code cleanup
Added some todo's
2024-01-28 21:50:11 +01:00
a824390566 Code cleanup 2024-01-20 09:39:22 +01:00
55c060559d Added colorattribute to GameObjects class 2024-01-20 09:36:15 +01:00
e595d085c6 Some chagens on GameOjects class
Code cleanup
Some stability tests
2024-01-18 21:31:23 +01:00
410ce9f72b Dummyclass for Gameobjects 2024-01-16 21:26:36 +01:00
e01d187ea5 Code cleanup
Added testmodel bitmap
Added Prototype for imagemodels
2024-01-15 22:01:13 +01:00
3e56abba63 Some cleanup
Todo: Change controlstructure for user who logged in the first time
2024-01-07 22:12:56 +01:00
40839589f0 Added Player class that handle playerobject 2024-01-07 22:02:08 +01:00
f77433d5f4 Fixed typo 2024-01-07 21:38:00 +01:00
c146a58904 Code cleanup
Update GameObject class
Added some functions to User class
Updated gameending highscore upload to database
2024-01-07 21:33:13 +01:00
17e258f408 Switched GameObjects class and Follower childclass to modules directory 2024-01-07 15:21:10 +01:00
900cee34e5 Updated .gitignore and added Userlogin (SQLLITE) 2024-01-07 11:51:08 +01:00
9b8fe57c17 Changed location of pygame-test to main directory 2024-01-07 11:02:07 +01:00
6221fd49a4 Pygame-test changed import User class to modules folder 2024-01-07 10:54:35 +01:00
45c730a174 Changed Projectstructure + Some changes on pygame-test
Added Username function
Added Gameobjectposition lastframe
Added prototype function  stepping_movement
Code cleanup
2024-01-07 10:42:15 +01:00
28670e7609 Some changes in subclass of Gameobject 2024-01-01 18:37:18 +01:00
040a226c2e Debuged change of rectsize on collision with player rect 2024-01-01 15:30:51 +01:00
a2d56d74e8 TODO Hardcopy der Gameobjects calss
Funktion manipuliert aktive Gameobjekte, welche mit vererbter Klasse instanziert werden
Grund hierfür, konnte noch nicht ausfindig gemacht werden!
2024-01-01 13:07:56 +01:00
e3193695c3 Some changes in class Follower and code cleanup 2024-01-01 12:11:05 +01:00
e3fc96bff8 New class for Follower added
Masterclass copy seems not working correctly
2023-12-31 18:08:26 +01:00
594b4a4b33 Some changes on followers function 2023-12-31 15:08:09 +01:00
73cfbbbce4 Added followers function
Actually want draw all followers on Playerobject :(
2023-12-31 14:11:37 +01:00
da23babe68 Codeupdate gamemenu 2023-12-31 09:58:19 +01:00
3e2b906279 Spawnkollisionsprüfung in work 2023-12-30 15:25:55 +01:00
06de20158f Some changes on mechanics 2023-12-30 12:37:07 +01:00
1736feb94b Some changes on movement system 2023-12-28 19:59:17 +01:00
ed384cfcba FIxed typo 2023-12-27 22:01:21 +01:00
3cd688c3e2 Spawn entities with ID-Tag + Code cleanup 2023-12-27 21:57:57 +01:00
3f9c38d172 Recommit 2023-12-27 19:36:55 +01:00
dc14d8a91d Merge branch 'master' of https://git.r6-gaming.de/administrator/python-tests 2023-12-27 19:26:44 +01:00
a1ee99e713 Added collision control
TODO: Add playerfollower after collide
2023-12-27 19:24:35 +01:00
32 changed files with 1252 additions and 170 deletions

4
.gitignore vendored
View File

@@ -11,3 +11,7 @@
/.idea
/SnakeTest.spec
python-tests.code-workspace
modules/__pycache__c
modules/__pycache__
modules/__pycache__
qt-test.spec

View File

@@ -1,5 +1,5 @@
import Game
import User
import modules.Game as Game
import modules.User as User
import Controls
import subprocess

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -0,0 +1,234 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="1024"
height="768"
viewBox="0 0 270.93333 203.2"
version="1.1"
id="svg1"
inkscape:version="1.3.2 (091e20ef0f, 2023-11-25, custom)"
sodipodi:docname="MAINVIEW.svg"
inkscape:export-filename="MAINVIEW.webp"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="1.4513545"
inkscape:cx="466.1163"
inkscape:cy="325.90245"
inkscape:window-width="2560"
inkscape:window-height="1356"
inkscape:window-x="2560"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="layer1"
showguides="true">
<inkscape:grid
id="grid1"
units="mm"
originx="0"
originy="0"
spacingx="0.99999998"
spacingy="1"
empcolor="#0099e5"
empopacity="0.30196078"
color="#0099e5"
opacity="0.14901961"
empspacing="5"
dotted="false"
gridanglex="30"
gridanglez="30"
visible="false" />
</sodipodi:namedview>
<defs
id="defs1">
<linearGradient
id="linearGradient18"
inkscape:swatch="gradient">
<stop
style="stop-color:#293c4b;stop-opacity:1;"
offset="0"
id="stop18" />
<stop
style="stop-color:#293c4b;stop-opacity:0;"
offset="1"
id="stop19" />
</linearGradient>
</defs>
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1"
style="display:inline">
<rect
style="fill:#379426;fill-opacity:1;stroke-width:1.654;stroke-linejoin:bevel;paint-order:markers stroke fill"
id="rect1"
width="270.93332"
height="203.2"
x="-4.8062439e-08"
y="0"
inkscape:label="MAINSCREEN" />
<rect
style="fill:#293c4b;fill-opacity:1;stroke-width:1.654;stroke-linejoin:bevel;paint-order:markers stroke fill"
id="rect2"
width="270.93332"
height="192.61667"
x="2.7435373e-08"
y="10.583333"
inkscape:label="PLAYGROUNG" />
<text
xml:space="preserve"
style="font-size:5.29166667px;line-height:0;font-family:'DejaVu Sans Mono';-inkscape-font-specification:'DejaVu Sans Mono';fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.654;stroke-linejoin:bevel;stroke-opacity:0.587196;paint-order:markers stroke fill"
x="117.58411"
y="7.6566405"
id="text6"><tspan
sodipodi:role="line"
id="tspan6"
style="stroke-width:1.654;font-size:5.29166667px"
x="117.58411"
y="7.6566405"><tspan
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Inconsolata;-inkscape-font-specification:Inconsolata;font-size:5.29166667px"
id="tspan17">SCORE</tspan>: </tspan></text>
<text
xml:space="preserve"
style="font-size:5.29167px;line-height:0;font-family:'DejaVu Sans Mono';-inkscape-font-specification:'DejaVu Sans Mono';fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.654;stroke-linejoin:bevel;stroke-opacity:0.587196;paint-order:markers stroke fill"
x="4.9488788"
y="7.2679081"
id="text6-5"><tspan
sodipodi:role="line"
id="tspan6-3"
style="font-size:5.29167px;stroke-width:1.654"
x="4.9488788"
y="7.2679081"><tspan
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.29167px;font-family:Inconsolata;-inkscape-font-specification:Inconsolata"
id="tspan16">PLAYER</tspan>: </tspan></text>
<rect
style="fill:#293c4b;fill-opacity:1;stroke:#000000;stroke-width:1.62159;stroke-linecap:round;stroke-linejoin:bevel;stroke-dasharray:none;stroke-opacity:0.558499;paint-order:fill markers stroke"
id="rect18"
width="269.56253"
height="190.07933"
x="0.57719308"
y="11.879853" />
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="LABEL_NAME_ENTRY"
style="display:none"
sodipodi:insensitive="true">
<rect
style="fill:#379426;fill-opacity:0.604856;stroke:#000000;stroke-width:1.654;stroke-linejoin:bevel;stroke-opacity:0.430464;paint-order:markers stroke fill"
id="rect3"
width="126.33456"
height="32.996475"
x="74.561096"
y="75.107994" />
<text
xml:space="preserve"
style="font-size:4.7625px;line-height:0;font-family:'DejaVu Sans Mono';-inkscape-font-specification:'DejaVu Sans Mono';fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.654;stroke-linejoin:bevel;stroke-opacity:0.430464;paint-order:markers stroke fill"
x="80.39473"
y="83.676147"
id="text3"><tspan
sodipodi:role="line"
id="tspan3"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.7625px;font-family:Inconsolata;-inkscape-font-specification:Inconsolata;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.654;stroke-opacity:0.587196"
x="80.39473"
y="83.676147">Bitte gib einen Namen ein:</tspan></text>
<rect
style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.654;stroke-linejoin:bevel;stroke-opacity:0.587196;paint-order:markers stroke fill"
id="rect4"
width="84.952248"
height="8.3858442"
x="80.212425"
y="87.322159" />
<text
xml:space="preserve"
style="font-size:4.7625px;line-height:0;font-family:'DejaVu Sans Mono';-inkscape-font-specification:'DejaVu Sans Mono';fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.654;stroke-linejoin:bevel;stroke-opacity:0.587196;paint-order:markers stroke fill"
x="80.577026"
y="103.36465"
id="text5"><tspan
sodipodi:role="line"
id="tspan5"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Inconsolata;-inkscape-font-specification:Inconsolata;stroke-width:1.654"
x="80.577026"
y="103.36465">Mit ENTER bestätigen</tspan></text>
<text
xml:space="preserve"
style="font-size:4.23333px;line-height:0;font-family:'DejaVu Sans Mono';-inkscape-font-specification:'DejaVu Sans Mono';fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:1.642;stroke-linejoin:bevel;stroke-dasharray:none;stroke-opacity:1;paint-order:markers stroke fill"
x="81.488533"
y="93.338089"
id="text11"><tspan
sodipodi:role="line"
id="tspan11"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.23333px;font-family:Inconsolata;-inkscape-font-specification:Inconsolata;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.642"
x="81.488533"
y="93.338089">Mein Name</tspan></text>
</g>
<g
inkscape:groupmode="layer"
id="g21"
inkscape:label="LABEL_SELECT_PLAYER"
style="display:inline">
<rect
style="fill:#379426;fill-opacity:0.604856;stroke:#000000;stroke-width:2.47263;stroke-linejoin:bevel;stroke-opacity:0.430464;paint-order:markers stroke fill"
id="rect19"
width="90.131538"
height="103.3607"
x="79.710228"
y="41.791622" />
<text
xml:space="preserve"
style="font-size:5.82083px;line-height:0;font-family:'DejaVu Sans Mono';-inkscape-font-specification:'DejaVu Sans Mono';fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.654;stroke-linejoin:bevel;stroke-opacity:0.430464;paint-order:markers stroke fill"
x="90.785881"
y="50.132771"
id="text19"><tspan
sodipodi:role="line"
id="tspan19"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:ultra-expanded;font-size:5.82083px;font-family:Inconsolata;-inkscape-font-specification:'Inconsolata Ultra-Expanded';fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.654;stroke-opacity:0.587196"
x="90.785881"
y="50.132771">Wähle einen Spieler aus:</tspan></text>
<rect
style="fill:#ffffff;fill-opacity:0;stroke:#ffffff;stroke-width:0.661458;stroke-linecap:round;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke"
id="rect21"
width="78.207115"
height="8.3858442"
x="87.139854"
y="65.081451" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:ultra-expanded;font-size:5.82083px;line-height:0;font-family:Inconsolata;-inkscape-font-specification:'Inconsolata Ultra-Expanded';fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.661458;stroke-linecap:round;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke"
x="91.515083"
y="60.888523"
id="text21"><tspan
sodipodi:role="line"
id="tspan21"
style="stroke-width:0.661458;stroke:none;fill:#ffffff;fill-opacity:1"
x="91.515083"
y="60.888523">Chris</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:ultra-expanded;font-size:5.82083px;line-height:0;font-family:Inconsolata;-inkscape-font-specification:'Inconsolata Ultra-Expanded';fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.661458;stroke-linecap:round;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke"
x="92.061981"
y="70.915077"
id="text22"><tspan
sodipodi:role="line"
id="tspan22"
style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.661458"
x="92.061981"
y="70.915077">Chris_selected</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

BIN
data/models/fruit1.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

82
data/models/fruit_1.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 135 KiB

89
data/models/fruit_1_1.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 705 B

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1019 B

BIN
data/models/player_test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

View File

@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg1"
sodipodi:docname="snake_head.svg"
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
inkscape:zoom="1.4485269"
inkscape:cx="314.11221"
inkscape:cy="493.95008"
inkscape:window-width="1920"
inkscape:window-height="1009"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs1">
<inkscape:path-effect
effect="spiro"
id="path-effect7"
is_visible="true"
lpeversion="1" />
<inkscape:path-effect
effect="spiro"
id="path-effect1"
is_visible="true"
lpeversion="1" />
</defs>
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:#ff9955;stroke-width:0.264583"
d="m 110.14207,106.30627 c 0.97733,-3.74444 1.10317,-7.708487 0.36531,-11.507378 -0.66809,-3.43968 -2.03122,-6.741683 -2.37454,-10.228783 -0.29,-2.945551 0.16205,-5.923884 0.93766,-8.780245 0.77562,-2.856361 1.87099,-5.613644 2.89813,-8.389496 0.73104,-1.975626 1.43062,-3.968708 2.36111,-5.858603 0.93048,-1.889896 2.10529,-3.68662 3.66657,-5.100807 1.40917,-1.276411 3.12732,-2.222108 4.97729,-2.660958 1.84998,-0.43885 3.82935,-0.361656 5.6168,0.286421 2.02972,0.735918 3.77162,2.197605 4.93174,4.018449 1.15498,1.812771 1.73416,3.927534 2.19188,6.027677 0.72732,3.337131 1.18861,6.730702 2.00923,10.046123 0.74801,3.022072 1.79996,6.019687 1.82656,9.132842 0.0251,2.940419 -0.8684,5.804829 -1.82656,8.584869 -1.32171,3.834844 -2.79483,7.663889 -3.28783,11.690039 -0.1187,0.96941 -0.17973,1.94587 -0.18265,2.92251"
id="path7"
inkscape:path-effect="#path-effect7"
inkscape:original-d="m 110.14207,106.30627 c -9.19373,4.56642 0.36531,-7.6107 0.36531,-11.507378 0,-3.89668 -1.64391,-6.94096 -2.37454,-10.228783 -0.73063,-3.287821 2.43543,-11.50738 3.83579,-17.169741 1.40037,-5.662361 4.14022,-7.123616 6.02768,-10.95941 1.88745,-3.835794 6.88007,-1.826567 10.59409,-2.374537 3.71403,-0.547971 3.4096,2.73985 4.93174,4.018449 1.52214,1.278599 1.46125,4.201107 2.19188,6.027677 0.73063,1.826567 1.33948,6.575644 2.00923,10.046123 0.66974,3.470481 1.21771,6.027676 1.82656,9.132842 0.60886,3.105166 -1.21771,5.784133 -1.82656,8.584869 -0.60886,2.800739 -2.131,7.854244 -3.28783,11.690039 -1.15682,3.83579 -0.18265,1.88745 -0.18265,2.92251"
transform="translate(-30.914667,30.458026)"
inkscape:export-filename="snake_head_1.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96" />
<circle
id="path8"
style="fill:#000000;stroke:none;stroke-width:0.264583"
cx="110.69003"
cy="103.74908"
r="0.39687499" />
<path
style="fill:#ff9955;stroke-width:0.266018"
d="m 79.273061,136.13284 v 46.76014 H 103.27676 V 136.49815 H 79.273061 Z"
id="path9"
inkscape:export-filename="snake_body_1.png"
inkscape:export-xdpi="32.247917"
inkscape:export-ydpi="32.247917" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
data/models/testmodel.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -4,15 +4,13 @@ import time
import threading
import tkinter
from turtle import left, width
import User
import modules.User as User
import sys
import tkinter as tk
from direct import task
from tkinter import Scale, StringVar
from random import random
#TODO Klassen erstellten
def button_event_close():
print("Programm wird geschlossen")

View File

@@ -1,5 +1,5 @@
import User
import Statics
import modules.User as User
import modules.Statics as Statics
import Controls
from math import pi, sin, cos

341
modules/GameObject.py Normal file
View File

@@ -0,0 +1,341 @@
import pygame
import random as rand
class GameObject():
"""TODO Install a body array with positions of mainbody and adders"""
_size_rect_x:int
_size_rect_y:int
__movespeed = int()
_rectobjekt:pygame.Rect
_surface:pygame.Surface
_mainscreensize:tuple
__hide = False
__collided = False
__is_player = False
__is_rect = False
__has_follower = False
__score:int
count = 0
def __init__(self, name:str, surface, mainscreensize:tuple, posx_init:int=0, posy_init:int=0, move_speed:int=0, is_player:bool = False, is_rect:bool = True, color:tuple = (0,0,0), rect_size:tuple = (10,10), image = str()) -> None:
self.__name = name
self._pos_x = posx_init
self._pos_y = posy_init
self.pos_array = (posx_init,posy_init)
self.__inital_pos_x = posx_init
self.__initial_pos_y = posx_init
self.__movespeed = move_speed
self.__is_player = is_player
self.__is_rect = is_rect
self._size_rect_x = rect_size[0]
self._size_rect_y = rect_size[1]
self.count += 1
self.__pos_lf_x = 0
self.__pos_lf_y = 0
self._surface = surface
self._mainscreensize = mainscreensize
self.__score = 0
self.__imagepath = image
self.__imageloaded = 0
self.__color = color
def draw(self):
#font = pygame.font.SysFont(None, 70)
#text = font.render("TEST", True, (0,0,0) )
if(not self.__hide):
self._rectobjekt = pygame.draw.rect(self._surface, self.__color, [self._pos_x, self._pos_y,self._size_rect_x,self._size_rect_y])
def get_name(self, debug=False):
if(debug):
print(self.__name)
return self.__name
def get_position(self, debug=False):
if(debug):
print((self._pos_x, self._pos_y))
return (self._pos_x, self._pos_y)
def get_rect(self):
return self._rectobjekt
def get_rect_size(self):
return (self._size_rect_x, self._size_rect_y)
def get_movespeed(self):
return self.__movespeed
def get_playermovedirection(self):
return self.__movedirection
def get_player_score(self) -> int:
return self.__score
def get_surface(self) -> pygame.Surface:
return self._surface
def has_follower(self):
return self.__has_follower
def set_follower(self):
self.__has_follower = True
def is_collided(self) -> bool:
return self.__collided
def set_collided(self):
self.__collided = True
def set_position(self, pos:tuple):
self._pos_x = pos[0]
self._pos_y = pos[1]
def update_pos_lastframe(self,x,y,debug=False):
if (debug):
print("Letzte Position: " + str((x,y)))
self.__pos_lf_x = x
self.__pos_lf_y = y
def update_player_score(self, score_from_entity):
if(score_from_entity > 0):
self.__score += score_from_entity
def collide(self, GameObject) -> bool:
#print(GameObject)
#print(GameObject.get_rect())
"""TODO: Hitbox with Objectsize"""
if(pygame.rect.Rect.colliderect(self._rectobjekt, GameObject.get_rect()) and not self.is_collided()):
print("Kollision\n") #Funktioniert für das erste!
self.set_collided()
return True
#self.hide() #Löscht das Objekt nach einem Zusammenstoß mit Playerobject
return False
def hide(self):
if(self.__hide != True):
print("Gameoject mit der ID " + self.__name + " gelöscht!")
self.__hide = True
"""TODO: Delete obeject function"""
class GameObject_new():
def __init__(self, name:str, surface:pygame.surface.Surface, surface_size:tuple, init_pos_x, init_pos_y, visibility:bool = True) -> None:
self._name = name
self._surface = surface
self._surface_size = surface_size
self._position = [init_pos_x, init_pos_y]
self._visibility = visibility
def printall_attributes(self):
print(self._name)
print(self._surface)
print(self._surface_size)
print(self._position)
print(self._visibility)
def get_position(self) -> tuple:
return self._position
class Block(GameObject):
__score = int()
def __init__(self, name: str, surface, mainscreensize: tuple, posx_init: int = 0, posy_init: int = 0, move_speed: int = 0, is_player: bool = False, is_rect: bool = True, color: tuple = (0, 0, 0), rect_size: tuple = (10, 10), image=str()) -> None:
super().__init__(name, surface, mainscreensize, posx_init, posy_init, move_speed, is_player, is_rect, color, rect_size, image)
self.__score = rand.randint(5, 50)
def set_position_player(self, pos:tuple, playermovedirection:list, debug=False):
if(playermovedirection["up"]):
super().set_position((pos[0],pos[1]+super().get_rect_size()[1]))
print(pos)
if(playermovedirection["down"]):
super().set_position((pos[0],pos[1]-super().get_rect_size()[1]))
print(pos)
if(playermovedirection["left"]):
super().set_position((pos[0]+super().get_rect_size()[0],pos[1]))
print(pos)
if(playermovedirection["right"]):
super().set_position((pos[0]-super().get_rect_size()[0],pos[1]))
print(pos)
def test(self):
print(super().get_position())
def get_score(self) -> int:
return self.__score
class Player(GameObject_new):
#Later handles the Player-Gameobject
def __init__(self, name: str, surface: pygame.Surface, surface_size: tuple, init_pos_x, init_pos_y, visibility: bool = True,
size:int = 10
) -> None:
self._size = size
self._score = 0
self._rect:pygame.Rect
self.__snake_body = [[100,100+size], [100,100+size*2], [100,100+size*3], [100,size*5]]
super().__init__(name, surface, surface_size, init_pos_x, init_pos_y, visibility)
self.__snake = {"head":"data/models/snake_head_1.png", "body":"data/models/snake_body_1.png", "tail":""}
self._startmoving = False
__movedirection = {"up":False, "down":False, "left":False, "right":False}
__test_counter = 0
__player_rect:pygame.Rect
def user_test_func(self):
pass
def change_direction(self, direction:dict):
if(direction):
for key in self.__movedirection.keys():
self.__movedirection[key] = False
self.__movedirection[direction] = True
#print(direction) for debug purposes
def move(self, *speed:int):
MOVE_SPEED = 1
if(self.__test_counter == 10):
self.__test_counter = 0
if(self.__movedirection['up']):
if(not speed): self._position[1] -= MOVE_SPEED
else: self._position[1] -= speed[0]
if(self._position[1] <= -self._size):
self._position[1] = self._surface_size[1]
elif(self.__movedirection['down']):
if(not speed): self._position[1] += MOVE_SPEED
else: self._position[1] += speed[0]
if(self._position[1] >= self._surface_size[1]):
self._position[1] = -self._size
elif(self.__movedirection['left']):
if(not speed): self._position[0] -= MOVE_SPEED
else: self._position[0] -= speed[0]
if(self._position[0] <= -self._size):
self._position[0] = self._surface_size[0]
elif(self.__movedirection['right']):
if(not speed): self._position[0] += MOVE_SPEED
else: self._position[0] += speed[0]
if(self._position[0] >= self._surface_size[0]):
self._position[0] = -self._size
self.__test_counter+=1
def draw(self):
if(self.__test_counter == 10):
self.__snake_body.insert(0, list(self._position))
counter = 0
for pos in self.__snake_body:
if(counter == 0): #Only for the first part of the Snkae, this meens the head
#self.__player_rect = pygame.draw.rect(self._surface, (0,0,0), pygame.Rect(pos[0], pos[1], self._size, self._size))
surface = pygame.Surface((40,120))
surface.fill((255,255,255))
image = pygame.image.load(self.__snake["head"])
image = pygame.transform.scale(image, (40, 60))
if(self.__movedirection["right"]):
image = pygame.transform.rotate(image, 270) #Rotates the Snakehead on directionchange
surface = pygame.transform.rotate(surface, 270)
if(self.__movedirection["left"]):
image = pygame.transform.rotate(image, 90)
surface = pygame.transform.rotate(surface, 90)
if(self.__movedirection["up"]):
image = pygame.transform.rotate(image, 0)
surface = pygame.transform.rotate(surface, 0)
if(self.__movedirection["down"]):
image = pygame.transform.rotate(image, 180)
surface = pygame.transform.rotate(surface, 180)
surface.blit(image, (0,0))
self.__player_rect = self._surface.blit(surface, (pos[0], pos[1]))
else:
#pygame.draw.rect(self._surface, (0,0,0), pygame.Rect(pos[0], pos[1], self._size, self._size))
surface = pygame.Surface((40,40))
surface.fill((255,255,255))
image = pygame.image.load(self.__snake["body"])
image = pygame.transform.scale(image, (30,40))
image = pygame.transform.rotate(image, 270)
surface.blit(image, (0,5))
self._surface.blit(surface, (pos[0], pos[1]))
#print((pos[0], pos[1]))
counter += 1
#TODO Insert elif for the last position of the array, this meens the tail
counter = 0
#print(pos)
if(self.__test_counter == 10):
self.__snake_body.pop()
def collide_fruit(self, rect:pygame.Rect):
if(pygame.Rect.colliderect(self.get_player_rect(), rect)):
return True
else:
return False
def collide_self(self):
count = len(self.__snake_body)
for elements in range(1, count):
if(self.get_position() == self.__snake_body[elements]):
print(F"Colidepositions Player: {self.get_position()} Object{self.__snake_body[elements]}") #For DEBUG only
return True
return False
def add_body(self):
self.__snake_body.append(list(self._position))
def get_position(self) -> tuple:
return self.__snake_body[0]
def get_player_score(self) -> int:
return self._score
def get_positions_snake_body(self) -> list:
return self.__snake_body
def get_player_rect(self):
return self.__player_rect
def get_playermovedirection(self):
return self.__movedirection
def inc_score(self, points:int):
self._score += points
class Fruit(GameObject_new):
def __init__(self, name: str, surface: pygame.Surface, surface_size: tuple, init_pos_x, init_pos_y, visibility: bool = True, rect_size:int = 10, color:tuple = (0,0,0), score_points = 0, sprite=str()) -> None:
super().__init__(name, surface, surface_size, init_pos_x, init_pos_y, visibility)
self.__score_points = score_points
self.__rect:pygame.Rect
self.__rect_size = rect_size
self.__color = color
self.__image = pygame.image.load(sprite)
def draw(self):
#self.__rect = pygame.draw.rect(self._surface, self.__color, (self._position[0], self._position[1], self.__rect_size, self.__rect_size))
self.__rect = self._surface.blit(self.__image, self.get_position())
def get_rect(self) -> pygame.Rect:
return self.__rect
def get_score_points(self) -> int:
return self.__score_points
class GOIMAGE(GameObject):
def __init__(self, name: str, surface, mainscreensize: tuple, posx_init: int = 0, posy_init: int = 0, move_speed: int = 0, is_player: bool = False, is_rect: bool = True, color: tuple = (0, 0, 0), rect_size: tuple = (10, 10), image=str()) -> None:
super().__init__(name, surface, mainscreensize, posx_init, posy_init, move_speed, is_player, is_rect, color, rect_size, image)
self.__image = pygame.image.load(image).convert()
#self.__image = pygame.transform.scale(self.__image, (20, 20)) Scale the selected image
def move(self):
pass
def draw(self):
surface = self.get_surface()
surface.blit(self.__image, self.get_position())

30
modules/Game_new.py Normal file
View File

@@ -0,0 +1,30 @@
#Behandelt später die Hauptschleife und Klassenobjekte
class Game():
def __init__(self) -> None:
self.__state = {
"started":False,
"playermove":False,
"win":False,
"lose":False,
"paused":False,
"menu":False
}
def get_state(self, state):
return self.__state[state]
def change_state(self, state):
"""Toggles the selected game state"""
if(not self.__state[state]):
self.__state[state] = True
else:
self.__state[state] = False
def scoreboard(self):
pass
def spawn_fruit(self):
pass
def spawn_player(self):
pass

25
modules/Labels.py Normal file
View File

@@ -0,0 +1,25 @@
import pygame
class Label:
def __init__(self, is_rect=False, pos=tuple, size=tuple, mainsurface=pygame.Surface) -> None:
self._surface = pygame.Surface(size)
self._mainsurface = mainsurface
self._is_rect = is_rect
self._pos = pos
self._size = size
def get_surface(self):
return self._surface
def draw(self):
if(self._is_rect):
rect = pygame.draw.rect(self._mainsurface, (0,0,0), (self._pos[0],self._pos[1], self._size[0], self._size[1]), 1)
else:
print("Zeichne Surface!")
pass
class Input_Label(Label):
def __init__(self, is_rect=False, pos=tuple, size=tuple, mainsurface=pygame.Surface) -> None:
super().__init__(is_rect, pos, size, mainsurface)

View File

@@ -77,7 +77,6 @@ class User:
row = c.execute(sql)
res = row.fetchone()
c.execute(sql_update_login_date)
self.__sqlhandle.commit()
self.__uid = res[0]
self.__username = res[1]
@@ -90,6 +89,26 @@ class User:
return True
def update_user_highscore(self, score:int):
"""Updates users highscore"""
sql = "SELECT * FROM user WHERE username ='"+self.getusername()+"'"
sql_update_highscore = "UPDATE user SET highscore = "+str(score)+" WHERE username = '"+self.getusername()+"'"
try:
c = self.__sqlhandle.cursor()
row = c.execute(sql)
res = row.fetchone()
c.execute(sql_update_highscore)
self.__sqlhandle.commit()
self.__uid = res[0]
self.__username = res[1]
self.__highscore = res[2]
self.__lastlogin = res[3]
except:
print("Fehler beim Update des Highscores")
return False
return True
def getplayed_time(self):
return self.__played_time
@@ -97,7 +116,7 @@ class User:
return self.__lastlogin
def getusername(self):
return self.__username
return str(self.__username)
def gethighscore(self):
@@ -120,6 +139,7 @@ class User:
return self.__all_listed_users
def checkuserdb(self):
"""Checks for existing user, else return false"""
cursor = self.__sqlhandle.cursor()
rows=cursor.execute("SELECT * FROM user")
rows_count =len(list(rows))

View File

@@ -1,202 +1,209 @@
import pygame
import pygame_menu
import random as rnd
import random as rand
import modules.User as User
import modules.Game_new as Game
import modules.Labels as Label
from modules.GameObject import *
pygame.init()
MAINSCREEN_SIZE = (1024,768)
MAINSCREEN = pygame.display.set_mode(MAINSCREEN_SIZE)
pygame.display.set_caption("Testgame")
PLAYGROUND = pygame.Surface((1024,728))
pygame.display.set_caption("Snake_v1")
WEISS = (255,255,255)
SCHWARZ = (0,0,0)
GRUEN = (0,255,0)
ROT = (255,0,0)
### FONTS ###
fonts = {
"font1" : pygame.font.SysFont("times new roman", 18),
"font2" : pygame.font.SysFont("times new roman", 26),
"font3" : pygame.font.SysFont("times new roman", 32),
"font4" : pygame.font.SysFont("times new roman", 48)
}
my_font = pygame.font.SysFont('times new roman', 26)
my_font2 = pygame.font.SysFont('times new roman', 32)
my_font3 = pygame.font.SysFont('times new roman', 46)
### TEXTLABELS ###
surface_text_noplayer = fonts["font2"].render("Es existiert noch kein Spieler", True, SCHWARZ)
surface_text_inputplayername = fonts["font1"].render("Bitte gib einen Namen ein: ", True, SCHWARZ)
labels = []
WEISS = ( 255, 255, 255)
active = True
clock = pygame.time.Clock()
# Definieren der Variablen
ballpos_x = 10
ballpos_y = 10
#Handles all collided objects an adds it as playerfollower
class GameObject():
__name = str()
__pos_x = int()
__pos_y = int()
__color = (0,0,0)
__size_rect = {"x":50, "y":50}
__movespeed = int()
__rectobjekt = pygame.Rect
__surface = MAINSCREEN
__removed = False
def apply_name(input):
print(input)
if(len(input) <= 0):
print("Kein Name eingegeben!")
else:
if(User.select(input) == False):
User.createuser(input)
elif(User.select(input) == True):
print("Es existiert bereits ein Spieler mit diesem Namen!")
__movedirection = {"up":False, "down":False, "left":False, "right":False}
print(F"Hallo {User.getusername()}, dein letztes Spiel war am: {User.getlastlogin()} mit einem Highscore von: {User.gethighscore()}")
def __init__(self, name:str, posx_init:int=0, posy_init:int=0, move_speed:int=0) -> None:
self.__name = name
self.__pos_x = posx_init
self.__pos_y = posy_init
self.__movespeed = move_speed
#self.__rectobjekt = rect
def __del__(self):
#print("\nKlasse gelöscht", end="\n")
pass
def change_direction(self, direction:dict):
if(direction):
for key in self.__movedirection.keys():
self.__movedirection[key] = False
self.__movedirection[direction] = True
print(direction)
pass
def move(self, *speed:int):
MOVE_SPEED = 1 #Defaultspeed
if(self.__movedirection['up']):
if(not speed): self.__pos_y -= MOVE_SPEED
else: self.__pos_y -= speed[0]
if(self.__pos_y <= -self.__size_rect["y"]):
self.__pos_y = MAINSCREEN_SIZE[1]
elif(self.__movedirection['down']):
if(not speed): self.__pos_y += MOVE_SPEED
else: self.__pos_y += speed[0]
if(self.__pos_y >= MAINSCREEN_SIZE[1]):
self.__pos_y = -self.__size_rect["y"]
elif(self.__movedirection['left']):
if(not speed): self.__pos_x -= MOVE_SPEED
else: self.__pos_x -= speed[0]
if(self.__pos_x <= -self.__size_rect["x"]):
self.__pos_x = MAINSCREEN_SIZE[0]
elif(self.__movedirection['right']):
if(not speed): self.__pos_x += MOVE_SPEED
else: self.__pos_x += speed[0]
if(self.__pos_x >= MAINSCREEN_SIZE[0]):
self.__pos_x = -self.__size_rect["x"]
def get_text_input(dest=str):
return dest
print("Objekt-Koordinaten "+self.__name+"= X: "+str(self.__rectobjekt.x)+" Y: "+str(self.__rectobjekt.y), end="\r")
def draw(self):
#font = pygame.font.SysFont(None, 70)
#text = font.render("TEST", True, (0,0,0) )
if(self.__removed == False):
self.__rectobjekt = pygame.draw.rect(self.__surface, self.__color, [self.__pos_x, self.__pos_y,self.__size_rect["x"],self.__size_rect["y"]])
def get_rect(self):
return self.__rectobjekt
def get_movespeed(self):
return self.__movespeed
def collide(self, GameObject):
#print(GameObject)
#print(GameObject.get_rect())
if(self.get_rect().x == GameObject.get_rect().x and self.get_rect().y == GameObject.get_rect().y):
"""TODO: Hitbox with Objectsize"""
if(pygame.rect.Rect.colliderect(self.__rectobjekt, GameObject.get_rect())):
print("Kollision")
pass
def remove(self):
print("Gameoject mit der ID " + self.__name + " gelöscht!")
self.__removed = True
"""TODO: Delete obeject function"""
surface_menu = pygame.Surface((400, 500))
surface_menu.fill((244,244,244))
surface_menu_rect = surface_menu.get_rect()
def spawn_entities(x:int):
Objects = list()
def percent_from_screen(base:int, percent:int) -> int:
perc_hundred = base/100
return int(perc_hundred*percent)
game = Game.Game()
User = User.User()
input_label1 = Label.Input_Label(True, (50,50), (100,25), PLAYGROUND)
labels.append(input_label1)
player = Player("Player", PLAYGROUND, PLAYGROUND.get_size(), 100, 100, size=40)
def spawn_entities(x:int, list_of_objects:list):
count = 0
for y in range(x):
Objects.append(GameObject("TEST", rnd.randint(1,MAINSCREEN_SIZE[0]), rnd.randint(1,MAINSCREEN_SIZE[1]), rnd.randint(1,15)))
rect_size = 80
Entity = Block("Entitiy-"+str(count), MAINSCREEN, MAINSCREEN_SIZE, rand.randint(1,MAINSCREEN_SIZE[0]), rand.randint(1,MAINSCREEN_SIZE[1]), rand.randint(1,15), is_rect=True, rect_size=(rect_size,rect_size))
Entity.get_name(True)
list_of_objects.append(Entity)
count += 1
for x in Objects:
print(x)
return tuple(Objects)
object1 = GameObject("Testobject", 50, 50)
object2 = GameObject("Testobject2", 100, 100)
fruits = [
"data/models/fruit_1_1_scaled_2_red.png",
"data/models/fruit_1_1_scaled_2_green.png",
"data/models/fruit_1_1_scaled_2_yellow.png",
"data/models/fruit_1_1_scaled_2_orange.png"
]
background = pygame.surface.Surface((640,480))
x = 3600
invert = False
spawned_enteties = spawn_entities(50)
counter = 0
#Fenster-Hauptschleife
spawn_fruit = True
game_started = False
text_input_activate = True
text_input_buffer = str()
game.change_state("menu")
while active == True:
MAINSCREEN.fill((255,255,255))
MAINSCREEN.fill((55,148,38))
PLAYGROUND.fill((244,244,244))
for event in pygame.event.get():
#print(event)
if (event.type == pygame.QUIT):
print("Programm wird geschlossen!")
#print(spawned_entities, end="\n")
active = False
elif (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_UP):
print("Keydown")
object1.change_direction("up")
if(game.get_state("started")):
if (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_UP):
game_started = True
if(player.get_playermovedirection()["down"] != True):
player.change_direction("up")
elif (event.key == pygame.K_DOWN):
game_started = True
if(player.get_playermovedirection()["up"] != True):
player.change_direction("down")
elif (event.key == pygame.K_RIGHT):
game_started = True
if(player.get_playermovedirection()["left"] != True):
player.change_direction("right")
elif (event.key == pygame.K_LEFT):
game_started = True
if(player.get_playermovedirection()["right"] != True):
player.change_direction("left")
elif (event.key == pygame.K_DOWN):
print("Keydown")
object1.change_direction("down")
#rect1.move(ballpos_x, ballpos_y)
if(text_input_activate == True):
if(event.type == pygame.KEYDOWN):
text_input_buffer += event.unicode
if(event.key == pygame.K_BACKSPACE):
text_input_buffer = text_input_buffer[:-2]
elif (event.key == pygame.K_RIGHT):
print("Keydown")
object1.change_direction("right")
#rect1.move(ballpos_x, ballpos_y)
ballpos_x += 10
elif (event.key == pygame.K_LEFT):
print("Keydown")
object1.change_direction("left")
#rect1.move(ballpos_x, ballpos_y)
ballpos_x -= 10
print(text_input_buffer)
for y in spawned_enteties:
y.draw()
y.move(y.get_movespeed())
if(game.get_state("menu")):
pass
object1.draw()
object1.move(0.5)
text_surface_score = my_font.render('Score: '+str(player.get_player_score()), True, (0, 0, 0))
text_surface_player = my_font.render("Player: " + User.getusername(), True, SCHWARZ, None)
text_test = my_font.render("Test", True, SCHWARZ, None)
if(x == 0):
for y in spawned_enteties:
y.remove()
pass
x -= 1
text_out = my_font.render(text_input_buffer, True, SCHWARZ, None)
"""
rect1 = pygame.draw.rect(MAINSCREEN, (0,0,0), [ballpos_x,ballpos_y,100,100])
if(not invert):
#if ballpos_x <= (MAINSCREEN.get_size()[0]): ballpos_x += 1
if ballpos_y <= (MAINSCREEN.get_size()[1]): ballpos_y += 1
#if(ballpos_x >= MAINSCREEN.get_size()[0]): ballpos_x = int(-100)
if(ballpos_y >= MAINSCREEN.get_size()[1]): ballpos_y = int(-100)
"""
#input_label1.draw()
pygame.draw.line(MAINSCREEN, SCHWARZ, (0,38), (MAINSCREEN_SIZE[0], 38), 2)
"""
Lässt das Rechteck diagonal auf- und ablaufen
if(not invert):
if ballpos_x < (MAINSCREEN.get_size()[0]-100): ballpos_x += 1
if ballpos_y < (MAINSCREEN.get_size()[1]-100): ballpos_y += 1
else:
if ballpos_x != 0: ballpos_x -= 1
if ballpos_y != 0: ballpos_y -= 1
PLAYGROUND.blit(text_out, (MAINSCREEN_SIZE[0]/2, MAINSCREEN_SIZE[1]/2))
#pygame.draw.rect(surface_menu, (0,0,0), (0,0,400,500), 1, 7)
#PLAYGROUND.blit(surface_menu, (20,20))
if(ballpos_x == (MAINSCREEN.get_size()[0]-100) and ballpos_y == (MAINSCREEN.get_size()[1]-100)):
invert = True
if(ballpos_x == 0 and ballpos_y == 0):
invert = False
"""
#print("Objekt-Koordinaten= X: "+str(rect1.x)+" Y: "+str(rect1.y)+"", end="\r")
if(User.checkuserdb() == False):
PLAYGROUND.blit(surface_text_noplayer, (MAINSCREEN_SIZE[0]/2 - surface_text_noplayer.get_width()/2, 10))
PLAYGROUND.blit(surface_text_inputplayername, (MAINSCREEN_SIZE[0]/2 - surface_text_inputplayername.get_width()/2, 40))
#Displayflip sorgt dafür, dass das Fenster entsprechend der Tickrate aktualisiert wird
#pygame.display.flip()
if(game.get_state("started")):
MAINSCREEN.blit(text_surface_score, (MAINSCREEN_SIZE[0]/2-text_surface_score.get_size()[0]/2,0)) #Paints the Scoreboard in Top/Center
MAINSCREEN.blit(text_surface_player, (10, 0))
#If spawn_fruit is True then create a fruitobject and set spawn_fruit=false
if(spawn_fruit == True):
fruit = Fruit("Fruit", PLAYGROUND, PLAYGROUND.get_size(), init_pos_x=rand.randint(0, PLAYGROUND.get_size()[0]-40), init_pos_y=rand.randint(0, PLAYGROUND.get_size()[1]-40), color=ROT, rect_size=40, score_points=10, sprite=fruits[rand.randint(0, len(fruits)-1)])
spawn_fruit = False
#Draws a fruit if a fruitobject is instanced
if(fruit):
fruit.draw()
player.draw()
if(game_started == True and player.collide_self() == False):
player.move(40)
if(player.collide_self()):
game_started == False
gameovertext = my_font2.render("Game Over!", True, SCHWARZ)
if(player.get_player_score() > User.gethighscore()):
User.update_user_highscore(player.get_player_score())
PLAYGROUND.blit(gameovertext, (MAINSCREEN_SIZE[0]/2-gameovertext.get_size()[0]/2, MAINSCREEN_SIZE[1]/2-gameovertext.get_size()[1]/2))
if(player.collide_fruit(fruit.get_rect()) == True and fruit):
player.add_body()
player.inc_score(fruit.get_score_points())
del fruit
spawn_fruit=True
MAINSCREEN.blit(PLAYGROUND, (0,40))
pygame.display.flip()
clock.tick(60)
pygame.quit()

View File

@@ -0,0 +1,2 @@
pyinstaller qt-test.py --noconsole --upx-dir=c:\upx-packer\upx.exe #Upacked
pyinstaller qt-test.py --onefile --noconsole --upx-dir=c:\upx-packer\upx.exe #Packed in onefile

63
qt-test.py Normal file
View File

@@ -0,0 +1,63 @@
import sys
import os
import time
import random
import threading
from PySide6 import QtCore, QtWidgets, QtGui
count = 0
args = []
args.append(count)
def threadfunc(args):
for x in range(10000):
print(args)
pass
class MyWidget(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.hello = ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир"]
self.button = QtWidgets.QPushButton("Click me!")
self.text = QtWidgets.QLabel("Hello World",
alignment=QtCore.Qt.AlignCenter)
self.layout = QtWidgets.QVBoxLayout(self)
self.layout.addWidget(self.text)
self.layout.addWidget(self.button)
self.button.clicked.connect(self.magic)
self.progress = QtWidgets.QProgressBar(self)
self.progress.resize(800,30)
self.progress.setValue(0)
self.messagebox = QtWidgets.QMessageBox(parent=self, icon=QtWidgets.QMessageBox.Information)
self.thread = threading.Thread(None, threadfunc, args=args)
@QtCore.Slot()
def magic(self):
self.text.setText(random.choice(self.hello))
if(self.progress.value() != 100):
self.progress.setValue(self.progress.value()+1)
if(self.progress.value() == 10):
self.messagebox.setWindowTitle("INFO")
self.messagebox.setText("Abgeschlossen!")
self.messagebox.show()
self.thread.start()
if __name__ == "__main__":
app = QtWidgets.QApplication([])
widget = MyWidget()
widget.resize(800, 600) #Setzt die Anfangsfenstergröße
widget.setFixedSize(widget.size()) #Fixiert die vordefinierte Größe
widget.show()
#Mainloop
sys.exit(app.exec())

19
test.py Normal file
View File

@@ -0,0 +1,19 @@
def test(string=str()):
#print(string)
return string
func_list = [ ]
i=0
for anzahl in range(50):
func_list.append(test("string-"+str(i)))
i += 1
for func in func_list:
if(func == "string-30"):
print("Ziel erreicht!")
print(func)
for count, func in enumerate(func_list):
print(count, func)