From 44d3ab01bfdc33f863c75a72fc0cc456b3641975 Mon Sep 17 00:00:00 2001 From: Yan Wittmann Date: Mon, 27 Mar 2023 13:08:22 +0200 Subject: [PATCH] Optimization on level loading --- project/data/sprites/ghost_character.png | Bin 4893 -> 2251 bytes project/level/elements/LoadedLevel.py | 24 +++++++++++++++++++++++ project/physics/sprites/PlayerSprite.py | 22 +++++++-------------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/project/data/sprites/ghost_character.png b/project/data/sprites/ghost_character.png index c7b2cb582f0d2636c27323f485f8c4731008cf9c..688f77bba8e972e3c64932848d704d15299fa4c4 100644 GIT binary patch literal 2251 zcmb_d`9IX_9-kRA)~2!Vdv%G%9y<0660$E-8cPTXC);4m3}s8!>JYLf%2<*kBwMy* zFx;$7M2sahr!UP6uDR1auY3Q3`@`pXf8Ot(p67XgmQ1HhHgJAveh>%*x4nRJ;b1Q( z=6Ja{=iPMKw;&KWF2vH($=1?R(dkx1P)JxH2&6jkFyF|I%R)4@NAlDPmjDul6vz1r zS%{*V^Ld|UirYe~_1_hzH_H@K;lg1snJi*z@M=9>Ay|D*jWO{6MKVcEC{u+$m+Zm2+0CE;_n1Eq-t7*Sx!fjXwYF zX+r3HMCtxe!nl6wL29CXbp_$E4fVA8q{_4fvvhhlUNs0Pf< zk|4BkCk}acZe^rEB*N*RDbWsg*kjZ0jv?GT4N@z zCt_Hj!??)erv1WGwG>Z^oqNM|iOVy~Ow#k3w&ei1g@}eHj}IRlwuI_PVSh_mhqhwQ zzr~%ZZ%R5Iq1dhF7!6)Dnp9!GI)ejQ?**$rta?M?IC0F$-pz`GWbzc7&E_P|MywVN zK%-qQx&Bhj)t>EgIA7!ibQB1rq5Lbr&sV4gAQ1PIEy}_Ti`gm3ELb!=hT0*s*-?={ z@^~|4Q?gE`dWsl@CsV^hVv*NFO?!@RwV3On6^qXZIw0vvUk0JIG?mji<=+V-CjGpo zCT3ZUqJ-s@Kxlbcx%F()NZJO8v^)(=Z|LwceR+*{!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ky$EVG9WF&zr}mw2D*Za zB;ZaJjNB1{(ADBc_FNRg#pH*6{6#}meFS;zDvz66zr9(#Dv^GJJA3!w00bBrAmFZl z_V+5J^3>~pM2ot}9Q#rOJbS$v-+8_dsGSdx4>ReO?<~|m^r~rqA3hhZF;q)tfayIg zGMnw;@yq1)d$bGu>t6Mg&k5zqRc6lKpI$xvUQ8=_oA;AgBFuLPBEcknIZ24|{Emol zjT%|hwJIn_rcp2Ea9O_<$-&lJKz)##i5!_8Wg_Ts3f8W8_S`KztUmc$LH2OVvBu zw2)289t91O`7F(_?x^qT?UkthL?=79iEbE~Z3`)C{TquwM9Xf=_M=w3qK+v7TZy}4 z5RaO&<07(73D|yV!lXlwwWm6yO6E)+=Y?iNrf;wDZgFD%14~5$-jKEd^9_9WKQK0{ z85_>QVDn{m>Y7-%ji#?Tz1r`m#yG+6SCKnisHJRPw)Y4QK|SC(cI@Q7%7%f+`t2J= zkDGhv8f6Q5&g-$k$19cp70Cbp;9olsXDhu4H#p&KXf-0Hy*qRP*jU= len(tiles[0]): + continue + if position[1] + j < 0 or position[1] + j >= len(tiles): + continue + + tile = tiles[position[1] + j][position[0] + i] + if not tile['name'] in ['#', '+', '-', 'l', 'r', '~', '|']: + return False + return True + def destroy_level(self): for block in self.blocks: self.sprite_manager.remove_ui_element(block) diff --git a/project/physics/sprites/PlayerSprite.py b/project/physics/sprites/PlayerSprite.py index 4bbc6a4..b72da4e 100644 --- a/project/physics/sprites/PlayerSprite.py +++ b/project/physics/sprites/PlayerSprite.py @@ -3,13 +3,11 @@ from physics.TickData import TickData from sprite.DynamicSprite import DynamicSprite from sprite.Spritesheet import Spritesheet from ui_elements.KeyManager import KeyManager -from ui_elements.TextLabel import TextLabel class PlayerSprite(DynamicSprite): def __init__(self, spritesheet: Spritesheet): super().__init__(spritesheet) - self.cheat_fly = False self.jump_time = -1 self.allowed_jump_time = 12 @@ -33,17 +31,11 @@ class PlayerSprite(DynamicSprite): if self.motion[0] > -self.max_motion_horizontal_via_input: self.motion = (self.motion[0] - self.acceleration_horizontal, self.motion[1]) - if not self.cheat_fly: - if tick_data.key_manager.is_keymap_down(KeyManager.KEY_UP): - if self.jump_time < 0 and self.get_collides_with_direction(CollisionDirection.BOTTOM): - self.jump_time = self.allowed_jump_time - self.motion = (self.motion[0], self.motion[1] - 7) - if self.jump_time >= 0: - self.motion = (self.motion[0], self.motion[1] - 0.5) + if tick_data.key_manager.is_keymap_down(KeyManager.KEY_UP): + if self.jump_time < 0 and self.get_collides_with_direction(CollisionDirection.BOTTOM): + self.jump_time = self.allowed_jump_time + self.motion = (self.motion[0], self.motion[1] - 7) if self.jump_time >= 0: - self.jump_time -= 1 - else: - if tick_data.key_manager.is_keymap_down(KeyManager.KEY_UP): - self.motion = (self.motion[0], self.motion[1] - 2) - if tick_data.key_manager.is_keymap_down(KeyManager.KEY_DOWN): - self.motion = (self.motion[0], self.motion[1] + 2) + self.motion = (self.motion[0], self.motion[1] - 0.5) + if self.jump_time >= 0: + self.jump_time -= 1