Update Fruit class

Added multiplie fruitcolors and spawn them random
This commit is contained in:
2024-02-04 18:33:16 +01:00
parent cbcf1e6bbd
commit d312fa3308
8 changed files with 36 additions and 23 deletions

View File

@@ -8,7 +8,7 @@
version="1.1"
id="svg1"
xml:space="preserve"
inkscape:version="1.3.2 (091e20ef0f, 2023-11-25, custom)"
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
sodipodi:docname="fruit_1_1_scaled.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
@@ -25,12 +25,12 @@
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
inkscape:zoom="0.53718434"
inkscape:cx="782.78529"
inkscape:cy="191.74051"
inkscape:window-width="2560"
inkscape:window-height="1356"
inkscape:window-x="2560"
inkscape:window-y="0"
inkscape:cx="781.85451"
inkscape:cy="190.80973"
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
@@ -63,25 +63,25 @@
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1"><path
style="fill:#e58e91;stroke-width:1.654;stroke-linejoin:bevel;paint-order:markers stroke fill;fill-opacity:1"
style="fill:#9c2327;stroke-width:1.654;stroke-linejoin:bevel;paint-order:markers stroke fill;fill-opacity:1"
d="M 84.631182,75.227719 C 80.453852,73.162126 76.14725,71.358008 71.744953,69.829433 64.577082,67.340589 57.030941,65.572049 49.45526,65.998391 39.745454,66.544837 30.418344,70.747715 22.986247,77.020104 10.244533,87.773596 3.1476229,104.33985 2.0932836,120.97948 c -0.8815214,13.91221 2.1686102,27.85776 7.1417909,40.88059 4.9029815,12.83901 11.7323795,25.02057 20.8097015,35.33956 4.331063,4.9235 9.219676,9.45294 14.960819,12.62126 6.836742,3.77293 15.025688,5.48906 22.595149,3.5709 2.177256,-0.55173 4.2715,-1.38992 6.323386,-2.30349 1.993382,-0.88753 3.956812,-1.8497 6.005319,-2.6013 2.695648,-0.98903 5.533951,-1.60718 8.402172,-1.74138 3.652215,-0.17089 7.316999,0.44453 10.796569,1.56724 3.18346,1.02716 6.21572,2.47169 9.35993,3.61337 1.84553,0.67012 3.73211,1.23629 5.65949,1.61078 5.13632,0.99797 10.54722,0.59588 15.45477,-1.21897 3.67929,-1.36063 7.03666,-3.48223 10.14355,-5.87716 5.91311,-4.55809 10.99201,-10.13373 15.41124,-16.15132 4.42773,-6.02916 8.21607,-12.51975 11.40605,-19.28581 4.14372,-8.78896 7.28455,-18.06334 9.14226,-27.60091 1.51143,-7.75976 2.17176,-15.71233 1.54638,-23.59314 -0.82983,-10.45724 -3.98002,-20.798386 -9.66604,-29.613806 -4.14957,-6.433354 -9.61785,-12.006855 -15.9459,-16.315299 -4.75148,-3.23504 -10.02588,-5.775475 -15.63806,-7.018654 -8.51196,-1.885522 -17.46383,-0.716768 -25.79664,1.847013 -4.89632,1.506465 -9.64605,3.488962 -14.160445,5.910448"
id="path1"
inkscape:path-effect="#path-effect1"
inkscape:original-d="M 84.631182,75.227719 C 80.567958,73.312196 76.156454,71.744953 71.744953,69.829433 67.333452,67.913911 56.885157,67.159314 49.45526,65.998391 42.02536,64.837471 31.80925,73.305156 22.986247,77.020104 14.163243,80.735053 9.0165599,106.32635 2.0932836,120.97948 c -6.9232764,14.65312 4.8022387,27.29477 7.1417909,40.88059 2.3395525,13.58582 13.8320895,23.51866 20.8097015,35.33956 6.977613,11.82089 9.994402,8.45522 14.960819,12.62126 4.96642,4.16605 15.083957,2.3806 22.595149,3.5709 7.511196,1.1903 4.230103,-1.56468 6.323386,-2.30349 2.093285,-0.7388 3.989036,-1.70518 6.005319,-2.6013 2.016287,-0.89612 5.601446,-1.16092 8.402172,-1.74138 2.800723,-0.58046 7.197712,1.04483 10.796569,1.56724 3.59886,0.52242 6.23995,2.3944 9.35993,3.61337 3.11998,1.21897 3.74397,1.08837 5.65949,1.61078 1.91552,0.52242 10.30318,-0.81265 15.45477,-1.21897 5.15159,-0.40632 6.76237,-3.88908 10.14355,-5.87716 3.38119,-1.98808 10.30318,-10.79657 15.41124,-16.15132 5.10805,-5.35476 7.60403,-12.85721 11.40605,-19.28581 3.80202,-6.42861 6.09484,-18.40061 9.14226,-27.60091 3.04742,-9.20031 1.0104,-15.72876 1.54638,-23.59314 0.53599,-7.86438 -6.46455,-19.76306 -9.66604,-29.613806 -3.20149,-9.850745 -10.61008,-10.856344 -15.9459,-16.315299 -5.33582,-5.458954 -10.40485,-4.679103 -15.63806,-7.018654 -5.23321,-2.339555 -17.21828,1.21082 -25.79664,1.847013 -8.57836,0.636194 -9.46082,3.919776 -14.160445,5.910448"
transform="translate(18.223881,16.253731)" /><path
style="fill:#e58e91;stroke-width:1.654;stroke-linejoin:bevel;paint-order:markers stroke fill;fill-opacity:1"
style="fill:#9c2327;stroke-width:1.654;stroke-linejoin:bevel;paint-order:markers stroke fill;fill-opacity:1"
d="m 87.302238,75.358209 c 0.145951,-2.706068 0.166504,-5.418896 0.06157,-8.126865 -0.06608,-1.705257 -0.181866,-3.408194 -0.307835,-5.110075 -0.574436,-7.760812 -1.372841,-15.566819 -3.650495,-23.008087 -0.811795,-2.652196 -1.809257,-5.249799 -2.47473,-7.942437 -0.09533,-0.385728 -0.184327,-0.77823 -0.174138,-1.175433 0.01192,-0.464541 0.160628,-0.918898 0.383373,-1.326728 0.222744,-0.40783 0.517936,-0.772045 0.835596,-1.111209 1.889233,-2.017124 4.637632,-3.171758 7.400875,-3.221557 1.773691,-0.03196 3.540177,0.369572 5.180613,1.04483 1.946281,0.801154 3.736995,1.994686 5.18061,3.526298 0.578373,0.613632 1.109393,1.295576 1.393103,2.089661 0.33121,0.927022 0.30312,1.947635 0.1306,2.916814 -0.084,0.471617 -0.20097,0.937284 -0.34827,1.393105 -0.33418,1.0341 -0.82143,2.010664 -1.262502,3.003886 -1.669065,3.758438 -2.682969,7.77289 -3.526298,11.797866 -0.454131,2.167443 -0.861133,4.344778 -1.218967,6.530184 -0.981042,5.991543 -1.592073,12.043648 -1.828453,18.110374"
id="path2"
inkscape:path-effect="#path-effect2"
inkscape:original-d="m 87.302238,75.358209 c 0,-2.83209 0.06157,-5.41791 0.06157,-8.126865 0,-2.708958 -0.225745,-3.447762 -0.307835,-5.110075 -0.08209,-1.662314 -2.419151,-15.353236 -3.650495,-23.008087 -1.231342,-7.654851 -1.66433,-5.280449 -2.47473,-7.942437 -0.810398,-2.661992 -0.116092,-0.783622 -0.174138,-1.175433 -0.05805,-0.391811 0.812646,-1.62529 1.218969,-2.437937 0.406321,-0.812644 4.962938,-2.147704 7.400875,-3.221557 2.437934,-1.073852 3.424719,0.725576 5.180613,1.04483 1.755891,0.319253 3.453741,2.321843 5.18061,3.526298 1.726873,1.204457 0.928733,1.393108 1.393103,2.089661 0.46437,0.696552 0.0726,1.959054 0.1306,2.916814 0.058,0.95776 -0.21767,0.94325 -0.34827,1.393105 -0.13061,0.449858 -0.87069,1.973567 -1.262502,3.003886 -0.391811,1.030317 -2.321843,7.865242 -3.526298,11.797866 -1.204457,3.932621 -0.812646,4.353454 -1.218967,6.530184 -0.406323,2.176727 -1.218969,12.073583 -1.828453,18.110374"
transform="translate(18.223881,16.253731)" /><path
style="fill:#e58e91;stroke-width:1.654;stroke-linejoin:bevel;paint-order:markers stroke fill;fill-opacity:1"
style="fill:#9c2327;stroke-width:1.654;stroke-linejoin:bevel;paint-order:markers stroke fill;fill-opacity:1"
d="m 21.610074,11.020522 c -0.154591,0.34815 -0.238858,0.727352 -0.246268,1.108209 -0.01014,0.521087 0.121295,1.033198 0.246268,1.539179 0.551472,2.232753 0.99494,4.492194 1.600747,6.710821 2.531986,9.272809 7.902256,17.663523 14.837685,24.31903 3.883898,3.727139 8.309849,6.966554 13.298509,8.988805 5.180417,2.099984 10.854109,2.834815 16.438432,2.585821 2.606349,-0.116212 5.203309,-0.442341 7.757462,-0.974191 0.288694,-0.05187 0.570985,-0.13928 0.838475,-0.25963 0.246776,-0.11103 0.480939,-0.250064 0.696553,-0.413578 l -0.05442,-0.859809 -1.121013,-1.632545 C 74.666028,50.423595 73.366052,48.760498 72.00616,47.147927 70.198233,45.004073 68.284993,42.950193 66.303133,40.966019 62.17758,36.835649 57.709197,32.975047 52.589747,30.16945 c -0.48101,-0.263606 -0.967274,-0.517625 -1.458407,-0.761854 -0.136672,-0.02643 -0.267531,-0.08252 -0.380929,-0.163256 -0.176094,-0.12538 -0.308529,-0.310893 -0.36991,-0.518165 -0.06138,-0.207271 -0.05132,-0.434984 0.02811,-0.636032 0.07943,-0.201049 0.227712,-0.374156 0.41418,-0.483512 0.186468,-0.109356 0.409935,-0.154266 0.624173,-0.12544 0.878699,-0.146313 1.785163,-0.124024 2.655609,0.0653 1.326036,0.288415 2.535691,0.950423 3.733089,1.589011 1.845459,0.984207 3.710691,1.931339 5.594191,2.84063 2.72308,2.190946 5.422434,4.411382 8.097427,6.660787 1.976748,1.662249 4.00037,3.418288 5.071777,5.768329 0.129072,0.283109 0.247835,0.580056 0.462691,0.805104 0.107429,0.112524 0.238673,0.204858 0.386748,0.252569 0.148075,0.04771 0.313604,0.04844 0.456597,-0.01284 0.168435,-0.07219 0.293803,-0.224984 0.361255,-0.395369 0.06745,-0.170386 0.08194,-0.357539 0.07409,-0.540623 C 78.32152,44.072907 78.178626,43.647629 78.035697,43.229816 77.001253,40.205905 75.890352,37.198755 74.444094,34.348764 69.362177,24.334354 60.143731,16.626133 49.585864,12.79916 44.520956,10.963252 39.163432,9.9780714 33.782817,9.7082066 30.349161,9.5359916 26.901063,9.6526291 23.486894,10.056483 c -0.26351,-0.02402 -0.531812,0.0058 -0.783622,0.08707 -0.454538,0.14672 -0.851386,0.465074 -1.093198,0.87697 z"
id="path3"
inkscape:path-effect="#path-effect3"
inkscape:original-d="m 21.610074,11.020522 c -0.364399,0.210234 -0.164179,0.718284 -0.246268,1.108209 -0.08209,0.389926 0.164179,1.005597 0.246268,1.539179 0.08209,0.533582 1.067165,4.494403 1.600747,6.710821 0.533582,2.216418 9.891789,16.212686 14.837685,24.31903 4.945896,8.106343 8.906717,6.033582 13.298509,8.988805 4.391789,2.955224 10.917909,1.682835 16.438432,2.585821 5.520521,0.902986 10.343282,-1.302549 7.757462,-0.974191 2.58582,-0.33924 0.558983,-0.176715 0.838475,-0.25963 0.27949,-0.08291 0.928738,-0.544182 0.696553,-0.413578 0.232185,-0.108836 -0.06893,-1.150038 -0.05442,-0.859809 -0.0036,-0.279347 -1.491056,-2.176727 -1.121013,-1.632545 C 75.554228,51.599335 73.341221,48.784102 72.00616,47.147927 70.671102,45.511754 68.175118,43.05568 66.303133,40.966019 64.431147,38.876361 57.160876,33.768307 52.589747,30.16945 c -4.57113,-3.598857 -1.9518,-1.019434 -1.458407,-0.761854 -0.51516,-0.268465 -0.261208,-0.112467 -0.380929,-0.163256 -0.119719,-0.05079 0.935993,-2.350865 0.696553,-1.763149 0.261207,-0.587716 1.777661,0.04354 2.655609,0.0653 0.877946,0.02177 2.488727,1.059341 3.733089,1.589011 1.244362,0.529669 7.458921,3.794762 5.594191,2.84063 1.86473,0.975899 5.40554,4.440526 8.097427,6.660787 2.691887,2.220262 3.388439,3.845552 5.071777,5.768329 1.683335,1.922775 0.856178,0.689298 1.306036,1.044829 0.449858,0.355532 0.290229,-0.609483 0.435345,-0.935992 0.145117,-0.326509 -0.20316,-0.856181 -0.304741,-1.284269 -0.101582,-0.428091 -2.3944,-5.935213 -3.591603,-8.881052 C 73.246895,31.402927 57.900963,19.996874 49.585864,12.79916 41.270761,5.6014466 39.006965,10.738525 33.782817,9.7082066 28.55867,8.6778887 20.047664,10.172575 23.486894,10.056483 c -3.417462,0.116092 -0.515158,0.05805 -0.783622,0.08707 -0.268463,0.02902 -0.728798,0.543602 -1.093198,0.87697 z"
transform="translate(18.223881,16.253731)" /><path
style="fill:#e58e91;stroke-width:1.654;stroke-linejoin:bevel;paint-order:markers stroke fill;fill-opacity:1"
style="fill:#9c2327;stroke-width:1.654;stroke-linejoin:bevel;paint-order:markers stroke fill;fill-opacity:1"
d="m 102.04501,41.989081 -0.15237,0.304744 0.15237,-0.282977 c 0.34174,-0.836175 0.70468,-1.663686 1.08836,-2.481469 1.49277,-3.18175 3.30613,-6.223996 5.52889,-8.946351 5.01629,-6.143767 12.07097,-10.516075 19.70528,-12.666983 4.96813,-1.399733 10.17505,-1.88804 15.33022,-1.63153 2.99602,0.149076 5.98293,0.548226 8.89646,1.262127 1.35685,0.332467 2.69607,0.732622 4.03264,1.138992 0.95062,0.289025 1.90667,0.583899 2.78592,1.046642 0.30048,0.158141 0.59879,0.342424 0.80037,0.615671 0.2309,0.312996 0.31228,0.731495 0.21549,1.10821 -0.082,0.410175 -0.18475,0.816188 -0.30784,1.215951 -0.2699,0.876564 -0.63632,1.720076 -1.01586,2.555037 -2.60633,5.73375 -5.87983,11.176703 -9.86847,16.051085 -3.7469,4.578957 -8.15796,8.674566 -13.29617,11.607964 -2.02057,1.153539 -4.14596,2.123379 -6.34142,2.893655 -3.5013,1.386091 -7.25972,2.119577 -11.02526,2.151669 -5.52139,0.04706 -11.04807,-1.432563 -15.80739,-4.232005 -0.0954,-0.0083 -0.18608,-0.06064 -0.24095,-0.139116 -0.0347,-0.04961 -0.0552,-0.108489 -0.0625,-0.168576 -0.007,-0.06009 -0.002,-0.121371 0.0125,-0.180188 0.0286,-0.117634 0.0913,-0.22389 0.15722,-0.325439 0.31265,-0.481611 0.71419,-0.898044 1.11591,-1.308304 3.85909,-3.941089 7.99243,-7.627825 12.49043,-10.820429 3.69908,-2.625543 7.63457,-4.909602 11.69777,-6.926304 1.31754,-0.653938 2.64888,-1.280057 3.99285,-1.877799 l 0.58978,-0.477872 0.17413,-1.077481 c -0.28556,-0.282492 -0.66754,-0.465687 -1.06659,-0.511529 -0.32456,-0.03728 -0.65203,0.0137 -0.97482,0.06404 -2.86627,0.446988 -5.74914,0.855302 -8.53748,1.655577 -6.393,1.83484 -12.04816,5.665475 -17.04378,10.056482 -0.52479,0.461279 -1.04364,0.929328 -1.55636,1.40399 -0.0616,0.15171 -0.16372,0.286764 -0.29287,0.387428 -0.12916,0.100664 -0.28505,0.166689 -0.44722,0.189406 -0.20079,0.02813 -0.4104,-0.011 -0.58753,-0.10966 -0.17712,-0.09866 -0.32072,-0.256294 -0.4025,-0.441817 -0.0818,-0.185523 -0.10125,-0.39787 -0.0546,-0.595173 0.0467,-0.197303 0.1592,-0.378429 0.31542,-0.507665 z"
id="path4"
inkscape:path-effect="#path-effect4"

Before

Width:  |  Height:  |  Size: 135 KiB

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

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

View File

@@ -263,21 +263,29 @@ class Player(GameObject_new):
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) -> None:
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 = 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

View File

@@ -89,12 +89,15 @@ def spawn_entities(x:int, list_of_objects:list):
list_of_objects.append(Entity)
count += 1
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))
imageobj = GOIMAGE("TEST", PLAYGROUND, PLAYGROUND.get_size(), 50, 50, image="data/models/fruit_1_1_scaled_2.png", rect_size=(15,50))
x = 3600
invert = False
@@ -119,16 +122,20 @@ while active == True:
elif (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_UP):
game_started = True
player.change_direction("up")
if(player.get_playermovedirection()["down"] != True):
player.change_direction("up")
elif (event.key == pygame.K_DOWN):
game_started = True
player.change_direction("down")
if(player.get_playermovedirection()["up"] != True):
player.change_direction("down")
elif (event.key == pygame.K_RIGHT):
game_started = True
player.change_direction("right")
if(player.get_playermovedirection()["left"] != True):
player.change_direction("right")
elif (event.key == pygame.K_LEFT):
game_started = True
player.change_direction("left")
if(player.get_playermovedirection()["right"] != True):
player.change_direction("left")
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)
@@ -137,10 +144,8 @@ while active == True:
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))
imageobj.draw()
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)
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
if(fruit):