├── README.md ├── app.py ├── assets.py ├── atack.piskel ├── cam.py ├── characters.py ├── game.py ├── images └── player │ ├── New Piskel.zip │ ├── attack.zip │ ├── fall.zip │ ├── fall1.png │ ├── fall2.png │ ├── fall3.png │ ├── fall4.png │ ├── fall5.png │ ├── idle.zip │ ├── idle0.png │ ├── idle1.png │ ├── idle2.png │ ├── idle3.png │ ├── imgs.zip │ ├── jump.zip │ ├── jump0.png │ ├── jump1.png │ ├── jump2.png │ ├── jump3.png │ ├── jump4.png │ ├── punch0.png │ ├── punch1.png │ ├── punch2.png │ ├── run.zip │ ├── run1.png │ ├── run2.png │ ├── run3.png │ └── run4.png ├── run.piskel └── test.py /README.md: -------------------------------------------------------------------------------- 1 | # ability_shooter_Game 2 | Beating the crap out of people game and sucking their blood to shoot it 3 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | from pygame.locals import * 3 | from game import render, collisions 4 | 5 | 6 | clock = pygame.time.Clock() 7 | fps = 144 8 | 9 | run = True 10 | while run: 11 | clock.tick(fps) 12 | 13 | render() 14 | collisions() 15 | 16 | for event in pygame.event.get(): 17 | if event.type == pygame.QUIT: 18 | 19 | print("quit") 20 | 21 | run = False 22 | 23 | pygame.display.flip() -------------------------------------------------------------------------------- /assets.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | 3 | 4 | image_path = "images/" 5 | IMAGES = { 6 | "player" : { 7 | 8 | "idle" : [ 9 | pygame.image.load(image_path + "player/idle0.png"), 10 | pygame.image.load(image_path + "player/idle1.png"), 11 | pygame.image.load(image_path + "player/idle2.png"), 12 | pygame.image.load(image_path + "player/idle3.png"), 13 | ], 14 | 15 | "run" : [ 16 | pygame.image.load(image_path + "player/run1.png"), 17 | pygame.image.load(image_path + "player/run2.png"), 18 | pygame.image.load(image_path + "player/run3.png"), 19 | pygame.image.load(image_path + "player/run4.png"), 20 | ], 21 | 22 | "punch" : [ 23 | pygame.image.load(image_path + "player/punch0.png"), 24 | pygame.image.load(image_path + "player/punch1.png"), 25 | pygame.image.load(image_path + "player/punch2.png"), 26 | ], 27 | "fall" : [ 28 | pygame.image.load(image_path + "player/fall1.png"), 29 | pygame.image.load(image_path + "player/fall2.png"), 30 | pygame.image.load(image_path + "player/fall3.png"), 31 | pygame.image.load(image_path + "player/fall4.png"), 32 | pygame.image.load(image_path + "player/fall5.png"), 33 | ], 34 | "jump" : [ 35 | pygame.image.load(image_path + "player/jump0.png"), 36 | pygame.image.load(image_path + "player/jump1.png"), 37 | pygame.image.load(image_path + "player/jump2.png"), 38 | pygame.image.load(image_path + "player/jump3.png"), 39 | pygame.image.load(image_path + "player/jump4.png"), 40 | ], 41 | } 42 | } -------------------------------------------------------------------------------- /atack.piskel: -------------------------------------------------------------------------------- 1 | {"modelVersion":2,"piskel":{"name":"attack","description":"","fps":8,"height":32,"width":24,"layers":["{\"name\":\"legs\",\"opacity\":1,\"frameCount\":10,\"chunks\":[{\"layout\":[[0],[1],[2],[3],[4],[5],[6],[7],[8],[9]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAAAgCAYAAAAsa/W9AAAAAXNSR0IArs4c6QAAAT9JREFUeF7t2EEKgzAURVGzNHeVJbgrl1ZH7UAw/RCEvno6E9Q+7383gbTFDwEEYgm02OSCI4DAQmAlQCCYAIGDhyc6AgTWAQSCCRA4eHiiI0BgHUAgmACBg4cnOgIE1gEEggkQOHh4oiNAYB1AIJgAgYOHJzoCBNYBBIIJEDh4eKIjQGAdQCCYAIGDhyc6AgTWAQSCCRA4eHiiI0BgHUAgmACBg4cnOgIE1gEEggkQOHh4oiNAYB1AIJhASeBt217vb+y9t/P17Pd7/5ggPvhcESBw7yUGowoRjGAzm9hMf0rlnfmDyod5PwEqPbm658n9IbAdeHmyAJWF45f5EJjABP5iMYGDAaWv0PL/9xlHaQde1/VzCr3veztfV0oyusf7xwTxwWfqFFqBFGhmkdaf+/pT2oFnhudZBBC4j8ABU2CAP8PYAkUAAAAASUVORK5CYII=\"}]}","{\"name\":\"torso\",\"opacity\":1,\"frameCount\":10,\"chunks\":[{\"layout\":[[0],[1],[2],[3],[4],[5],[6],[7],[8],[9]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAAAgCAYAAAAsa/W9AAAAAXNSR0IArs4c6QAAASVJREFUeF7t1tGNg0AQREHImhA2azsCcEsING3Vfa/sudp5mH3zR4BArcBeO7nBCRDYBGwJCBQLCLj48oxOQMB2gECxgICLL8/oBARsBwgUCwi4+PKMTkDAdoBAsYCAiy/P6AQEbAcIFAsIuPjyjE5AwHaAQLGAgIsvz+gEBGwHCBQLRAGvtT5n/+NxHNFnXBn5/OsN4sPnTCCKzwJZoDs/Uvbnuf0RsDeITWDPBZY8+O74C1jAAv5R2Z3ABCwwgRUHJmABC1jApwJeoT0gPCCKHxACFrCA/z3g5D3eGQIE3heIfoHfH8s3EiCQCAg4UXKGwFABAQ+9GGMRSAQEnCg5Q2CogICHXoyxCCQCAk6UnCEwVEDAQy/GWAQSAQEnSs4QGCrwBTMkQDCNvsUFAAAAAElFTkSuQmCC\"}]}","{\"name\":\"head\",\"opacity\":1,\"frameCount\":10,\"chunks\":[{\"layout\":[[0],[1],[2],[3],[4],[5],[6],[7],[8],[9]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAAAgCAYAAAAsa/W9AAAAAXNSR0IArs4c6QAAAmtJREFUeF7tmEFug0AQBO2n8SuewJd84mmOsAwiGNgR0z0SUvmSQ3D1TrHNkjwffDCAgdsaeAZW/v5eE7k2gPu5xMl3sudB3Blu/jSHK8PFrXK/3qyuWVLcViln+DRI69pMeR1899rXG9+x/gq+M8Pt/5Tfdd36949xHDP71zVLmns21D8BO+3MCNlunL3yZ/jutbvXX8F3Zrj9//C7rlv20FzWdYkTBXbNIuFmCpw9dVoDZPhO9vb17ezNw/kQyvhxz+D23yrw4kZQYtcsEm50gx2FRb/fer128p3sVhHu4Mc9g9v/wp9P4XEclQXe+zt4u5+z9/myo2jwJ2AYhkff95+f06fv++j3QwU28d1rX15FTeuv4Dsz3P6b/OkUTrxC/xTYcJ+bMxwVKFTAYRjem+LOZQ59v9VeJ9/JnudyZ7j534ez5R671x7hqwocyWrt9b3fZ7jhAk4h23DhCTw9EGx8J3td4rv6cc/g9r/lv16v7H+dD3vomuUqlwJfeWTufOfqDYjGu/nzKex4CLnX7uavnbiyrnIvF1h5+u5tHiV/K0fJPjq91Bl3nsG9djf/rMCq+3x1hnCBoycF12EAA3UGKHCda5IwIDdAgeVKAWKgzgAFrnNNEgbkBiiwXClADNQZoMB1rknCgNwABZYrBYiBOgMUuM41SRiQG6DAcqUAMVBngALXuSYJA3IDFFiuFCAG6gxQ4DrXJGFAboACy5UCxECdAQpc55okDMgNUGC5UoAYqDNAgetck4QBuQEKLFcKEAN1BihwnWuSMCA3QIHlSgFioM4ABa5zTRIG5AYosFwpQAzUGfgDB0V4MIHTqgkAAAAASUVORK5CYII=\"}]}","{\"name\":\"robe\",\"opacity\":1,\"frameCount\":10,\"chunks\":[{\"layout\":[[0],[1],[2],[3],[4],[5],[6],[7],[8],[9]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAAAgCAYAAAAsa/W9AAAAAXNSR0IArs4c6QAABElJREFUeF7tnGtuGzEMhJ2jGfCtfDUDPloCAVFACJQ4fK2llv3TIlnPUsP5llq1zdetfpUD5cCxDnwdW3kVXg6UA7cCuEJQDhzsQAF8cPOq9HKgAK4MbOHA/X7/fr/fIXlsWm1RVC9SfwvDfosIMWynBVlq+Veba/Hiqs+MkHHQeWrJ1qe1vV6v78fjkcbSSj/tph7zr/5sdHiurv+k+3Wvac1tUtKveyZxtj7ndQOsfb1DHA30Sr8Avt1uUeE5CaRP1spBNgLtqS9bfwZxFsDtfvShQP9cABfAHlZMn+2vLDPQPBO4FZStL03h6AncAe5TvgAmHRhD5A2PKdEHfSgqnKspGdGDbP3VFI7yaLxH1y2AFwA/n8+/d5kMrrKam1HrTDNiDdmAZesfBXDWVqeb8Cl9rgkNYHoggYChqX88kIjWR/TGa6T6x0M+7Rqkd1Lv+++n9MedAjchkX5I/ncN0wSWzPFudyT9K5vb7tXWo5kwUv2cP9n6SGikh2f//uyEGIVY8mesVZunT+vTersnmgEg1S/pLw+xJPEeeE1g6LWIPqeNNtmi3wFGmoDozwDO1Ef7oamfO6mXHkSIvucBvYM+N4WR3rZrkPolfTfA9EmNBgd9+s/0sgFu95XCiTZg5k+2PtILJECrHkhr0OqjfbXmJ1O/a6M7E2t+Rv0jAUYnvydAUjitDRjfZ1agaerXhlNbP7fVlTzaqf5sfwpgZGSQa5CGeAIkhVMLwOzAIwpgDjDJUo0/BfDazaMAHg820Ik4WoCevnFbJg/AyGc9ACP+ePQlMNF+7AIw0g9uzWj90fqr/kZsoTX6pi00ElAkZFqAqaYHAKShXv1xbTWB+UQgvZhlCQE4Q18DmGWHpdFXA0wN4U4mEXBXhxCo4VbArtRf+YPUr92md1/RNXr1kTWsINPUaYHYq8/VLuVf81dJEfoF8CQZ1nBKDdYcYtHSkGmDbp0jtqOIP6sHhBeu1RDw+CB5LvVX8485rAC3/zTR76MCeDQ9egKjTUXfM6Rt7OypHqU/8wfV10wd1DtkhyQFq2mgAHMQR9aaqS/lZ+wv7SviT4S+C2BqnqUp0gKyAbtCv6+R+uMFmJsSFv81MFve4RH9na9B8kn7S6GNAHjki9OHAZ4FhAso2hTLBNeEfwf90R9N/X3Std9nP/HB479VX7sGNA87XYfAiwCG7qIQvo4GWHM4wL0fSRMqS78Hof8niRWM0o6Afr8D7QWYQtz16cPC+wDaCUpNLRaAqb40gaP0oQm8Cr8nQJ7PIs3YQT+6BvqgGT2I+LlMK30OcKQPp12zgqt9jzvI0rxiROqrAeYWIE230xqI1svBWf6g7u15nXSAh/Z3NoGj9acAz94f0QXs2Z64qsqfOC93UpK2tmP+udpXZwTR+iLA/+t0lUIVvTWW7lffLwc4B+qH2lUuyoGDHSiAD25elV4OFMCVgXLgYAd+ABvjjGz9C9n8AAAAAElFTkSuQmCC\"}]}"],"hiddenFrames":[3,null,null]}} -------------------------------------------------------------------------------- /cam.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | from pygame.locals import * 3 | class Camera: 4 | def __init__(self, speed, screen): 5 | self.scroll = [0,0] 6 | self.speed = speed 7 | self.screen = screen 8 | self.zoom = 1 9 | 10 | def move_on_command(self, dt): 11 | 12 | keys = pygame.key.get_pressed() 13 | 14 | if keys[K_w]: 15 | self.scroll[1] -= self.speed *dt 16 | if keys[K_s]: 17 | self.scroll[1] += self.speed *dt 18 | if keys[K_d]: 19 | self.scroll[0] += self.speed *dt 20 | if keys[K_a]: 21 | self.scroll[0] -= self.speed *dt 22 | 23 | def follow(self, obj, dt ,speed=320): 24 | screen_center_x = self.screen.get_width()/2 25 | screen_center_y = self.screen.get_height()/2 26 | 27 | if obj.rect.x - self.scroll[0] != screen_center_x: 28 | self.scroll[0] += ((obj.x - (self.scroll[0]+screen_center_x))/speed) * dt 29 | 30 | if obj.rect.y - self.scroll[1] != screen_center_y: 31 | self.scroll[1] += ((obj.y - (self.scroll[1]+screen_center_x))/speed) * dt 32 | 33 | 34 | def zoom_game(self, zoom): 35 | self.zoom = zoom 36 | 37 | def center_obj(self, obj): 38 | self.scroll = [obj.rect.x,obj.rect.y] 39 | 40 | -------------------------------------------------------------------------------- /characters.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | from pygame.locals import * 3 | from random import randint, choice, uniform 4 | from assets import IMAGES 5 | import math 6 | 7 | GRAVITY = 1 8 | GROUND_LEVEL = 300 9 | 10 | class PhysicsEntity(pygame.sprite.Sprite): 11 | def __init__(self, pos, asset_lib, **kwargs): 12 | pygame.sprite.Sprite.__init__(self) 13 | 14 | 15 | self.create_physics(pos,**kwargs) 16 | self.create_animation(asset_lib, **kwargs) 17 | 18 | 19 | def update_physics(self, update_gravity, own_movement, jump=False): 20 | self.next_x = self.velocity.x 21 | self.next_y = self.velocity.y 22 | 23 | if update_gravity: 24 | self.gravity_force.y += self.gravity * self.mass / 100 25 | 26 | if self.gravity_force.y > 9.8: 27 | self.gravity_force.y = 9.8 28 | 29 | 30 | if not self.on_ground: 31 | self.position.y += self.gravity_force.y 32 | 33 | if own_movement: 34 | 35 | keys = pygame.key.get_pressed() 36 | 37 | self.velocity.x += (keys[K_d] - keys[K_a]) * self.speed 38 | if not jump: 39 | self.velocity.y += (keys[K_s] - keys[K_w]) * self.speed 40 | else: 41 | if keys[K_SPACE] and self.on_ground: 42 | self.jumped = True 43 | self.on_ground = False 44 | self.velocity.y = -((self.speed - self.friction) * 40) 45 | 46 | #print(self.on_ground, self.jumped) 47 | 48 | self.velocity = self.velocity.move_towards((0,0), self.friction) 49 | 50 | self.sum_y_vel = round(self.velocity.y + self.gravity_force.y) 51 | 52 | if self.velocity.x > self.max_speed: 53 | self.velocity.x = self.max_speed 54 | if self.velocity.x < self.max_speed *-1: 55 | self.velocity.x = self.max_speed *-1 56 | 57 | if not jump: 58 | if self.velocity.y > self.max_speed: 59 | self.velocity.y = self.max_speed 60 | if self.velocity.y < self.max_speed *-1: 61 | self.velocity.y = self.max_speed *-1 62 | 63 | def affect_by_scroll(self, scroll): 64 | self.final_pos = self.position - pygame.math.Vector2(scroll) - pygame.math.Vector2(50,60) 65 | self.x, self.y = self.position 66 | 67 | def create_physics(self,pos, **kwargs): 68 | global GRAVITY, GROUND_LEVEL 69 | 70 | self.gravity = GRAVITY 71 | self.ground_level = GROUND_LEVEL 72 | self.mass = kwargs["mass"] 73 | self.friction = self.gravity * self.mass / 50 74 | self.speed = kwargs["speed"] 75 | self.speed_squared = self.speed * self.speed 76 | self.gravity_force = pygame.math.Vector2(0,0) 77 | self.velocity = pygame.math.Vector2(0,0) 78 | 79 | self.jumped = False 80 | 81 | self.max_speed = self.mass / (self.speed * 5) 82 | 83 | self.position = pygame.math.Vector2(pos) 84 | self.on_ground = True 85 | 86 | self.final_pos = pygame.math.Vector2() 87 | 88 | def animate(self): 89 | self.update_anim_info() 90 | time_now = pygame.time.get_ticks() 91 | 92 | if time_now > self.next_frame: 93 | self.index += 1 94 | 95 | self.next_frame = time_now + self.anim_cooldown 96 | if self.animation == "jump" and pygame.key.get_pressed()[K_SPACE]: 97 | if self.index > 1: 98 | self.index = 1 99 | 100 | 101 | if self.index > self.max_index: 102 | 103 | 104 | 105 | self.index = 0 106 | 107 | if not self.repeat_anim: 108 | self.animation = self.base_anim 109 | 110 | 111 | if self.flip: 112 | self.image = pygame.transform.flip(self.anim_list[self.index], True, False) 113 | else: 114 | self.image = pygame.transform.flip(self.anim_list[self.index], False, False) 115 | 116 | def update_anim_info(self): 117 | self.anim_list = self.images[self.anim_path][self.animation] 118 | self.max_index = len(self.anim_list) -1 119 | self.anim_cooldown = self.animation_info[self.animation][0] 120 | if self.animation == "run": 121 | self.anim_cooldown = self.animation_info[self.animation][0] * abs(self.velocity.x /3 ) 122 | 123 | self.repeat_anim = self.animation_info[self.animation][1] 124 | self.anim_done = self.index>self.max_index 125 | 126 | def create_animation(self, asset_lib, **kwargs): 127 | 128 | self.anim_path = kwargs["anim_group"] 129 | self.animation_info = kwargs["anim_names"] 130 | self.base_anim = kwargs.get("base_anim", "idle") 131 | self.index = 0 132 | self.anim_done = False 133 | self.flip = False 134 | 135 | if "idle" in self.animation_info.keys(): 136 | self.animation = "idle" 137 | else: 138 | raise Exception("Please set an idle animation state") 139 | 140 | self.images = asset_lib 141 | 142 | self.anim_cooldown = self.animation_info[self.animation][0] 143 | self.repeat_anim = self.animation_info[self.animation][1] 144 | 145 | self.next_frame = pygame.time.get_ticks() + self.anim_cooldown 146 | 147 | self.anim_list = self.images[self.anim_path][self.animation] 148 | 149 | self.max_index = len(self.anim_list) - 1 150 | 151 | self.image = self.anim_list[self.index] 152 | 153 | def set_animation(self, animation): 154 | if self.animation != animation: 155 | self.animation = animation 156 | self.index = 0 157 | self.update_anim_info() 158 | self.next_frame = pygame.time.get_ticks() + self.anim_cooldown 159 | 160 | class Block(pygame.sprite.Sprite): 161 | def __init__(self, pos, size, color): 162 | 163 | self.pos = pygame.math.Vector2(pos) 164 | self.rect = pygame.Rect(pos[0], pos[1], size[0], size[1]) 165 | self.size = size 166 | self.color = color 167 | 168 | def update(self, screen, scroll): 169 | 170 | self.rect.topleft = self.pos - pygame.math.Vector2(scroll) 171 | 172 | pygame.draw.rect(screen, self.color, self.rect) 173 | 174 | class Bullet(): 175 | def __init__(self,shooter ,target_pos, speed): 176 | 177 | self.shooter = shooter 178 | 179 | 180 | self.position = pygame.math.Vector2(self.shooter.owner.position.x, self.shooter.owner.position.y) 181 | 182 | self.image = pygame.transform.scale(IMAGES["player"]["idle"][0], (25,25)) 183 | 184 | self.rad = uniform(4.5, 8) 185 | 186 | 187 | angle = math.atan2(target_pos[1] - self.shooter.owner.final_pos.y -50, target_pos[0] - self.shooter.owner.final_pos.x- 50) 188 | self.velocity =( pygame.math.Vector2(math.cos(angle) , math.sin(angle) ))* speed 189 | 190 | 191 | 192 | 193 | 194 | def affect_by_scroll(self, scroll): 195 | self.final_pos = self.position - pygame.math.Vector2(scroll) + pygame.math.Vector2(-50,-50) 196 | 197 | 198 | def update(self, scroll, screen): 199 | self.on_screen = pygame.Rect.colliderect(self.image.get_rect(center=self.position - scroll), screen.get_rect(topleft=(0,0))) 200 | 201 | self.position += self.velocity 202 | 203 | self.affect_by_scroll(scroll) 204 | 205 | 206 | class ShootController(pygame.sprite.Sprite): 207 | def __init__(self, owner): 208 | pygame.sprite.Sprite.__init__(self) 209 | 210 | self.owner = owner 211 | self.bullet_list = [] 212 | 213 | def update_self(self): 214 | self.position = self.owner.final_pos 215 | 216 | def update_bullets(self, screen, scroll): 217 | 218 | for bullet in self.bullet_list: 219 | bullet.update(scroll, screen) 220 | if bullet.on_screen: 221 | #screen.blit(bullet.image, bullet.final_pos) 222 | pygame.draw.circle(screen, (255,0,0), bullet.final_pos + pygame.math.Vector2(20,20), bullet.rad) 223 | 224 | 225 | 226 | def shoot(self, speed=6): 227 | 228 | self.bullet_list.append(Bullet(self, pygame.mouse.get_pos(), speed)) 229 | 230 | 231 | 232 | class Player(PhysicsEntity): 233 | def __init__(self, pos, **kwargs): 234 | super().__init__(pos, kwargs.pop('asset_lib'), **kwargs) 235 | 236 | self.not_idled_anims = ["punch"] 237 | 238 | self.not_runned_anims = ["punch", "jump"] 239 | 240 | self.shooter = ShootController(self) 241 | 242 | self.shot = True 243 | 244 | 245 | def update(self, screen, scroll, block_list): 246 | 247 | self.affect_by_scroll(scroll) 248 | self.animate() 249 | self.update_physics(True, True, True) 250 | self.control() 251 | self.walls(block_list, screen) 252 | self.shooter.update_self() 253 | self.shooter.update_bullets(screen, scroll) 254 | 255 | self.position.x += self.next_x 256 | self.position.y += self.next_y 257 | 258 | if pygame.mouse.get_pressed()[0] : 259 | if not self.shot: 260 | self.shooter.shoot() 261 | self.shot = True 262 | 263 | else: 264 | self.shot = False 265 | 266 | screen.blit(self.image, self.rect.topleft) 267 | pygame.draw.rect(screen, (255,0,255), self.rect) 268 | #screen.blit(self.image, self.final_pos) 269 | 270 | 271 | def control(self): 272 | keys = pygame.key.get_pressed() 273 | 274 | self.rect = self.image.get_rect(center=self.final_pos + pygame.math.Vector2(20,30)) 275 | 276 | 277 | 278 | if not self.animation in self.not_runned_anims: 279 | if keys[K_a]: 280 | self.set_animation("run") 281 | if not keys[K_d]: 282 | self.flip = True 283 | elif keys[K_d]: 284 | self.set_animation("run") 285 | if not keys[K_a]: 286 | self.flip = False 287 | 288 | else: 289 | if not self.animation in self.not_idled_anims: 290 | self.set_animation("idle") 291 | 292 | if self.sum_y_vel > 0: 293 | self.set_animation("fall") 294 | 295 | if self.jumped : 296 | self.set_animation("jump") 297 | 298 | def walls(self, block_list, screen): 299 | 300 | for block in block_list: 301 | if block.rect.colliderect(self.rect.x + self.next_x, self.rect.y, self.image.get_width(), self.image.get_height()): 302 | 303 | self.next_x = 0 304 | 305 | if block.rect.colliderect(self.rect.x , self.next_y + self.next_y, self.image.get_width(), self.image.get_height()): 306 | 307 | if self.sum_y_vel > 0: 308 | 309 | self.rect.bottom = block.rect.top 310 | #self.velocity.y = 0 311 | #self.next_y= 0 312 | self.gravity_force.y = 0 313 | 314 | elif self.sum_y_vel < 0: 315 | self.rect.top = block.rect.bottom - 64 316 | #self.on_ground = True 317 | self.gravity_force.y = 0 318 | #self.next_y= 0 319 | 320 | self.track_pos = pygame.math.Vector2(self.rect.center) 321 | 322 | plr = Player( 323 | (200, 200), 324 | asset_lib=IMAGES, 325 | anim_group="player", 326 | anim_names={"idle": (150, True), "run": (125, True), "punch": (500, False), "fall": (125, True), "jump": (100, False),}, 327 | mass=8, 328 | speed=.5, 329 | ) 330 | -------------------------------------------------------------------------------- /game.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | from pygame.locals import * 3 | from random import randint, choice, uniform 4 | import math, characters, cam 5 | 6 | screen = pygame.display.set_mode((800,600)) 7 | 8 | camera = cam.Camera(4, screen) 9 | 10 | def checkcollide(it1, it2, tolerance=115): 11 | 12 | if it1.rect.colliderect(it2.rect): 13 | if abs(it2.rect.top - it1.rect.bottom) < tolerance: 14 | return {"bottom" : True, "left" : False,"right" : False,"top" : False,} 15 | 16 | elif abs(it2.rect.bottom - it1.rect.top) < tolerance: 17 | return {"bottom" : False, "left" : False,"right" : False,"top" : True,} 18 | 19 | elif abs(it2.rect.right - it1.rect.left) < tolerance: 20 | return {"bottom" : False, "left" : True,"right" : False,"top" : False,} 21 | 22 | elif abs(it2.rect.left - it1.rect.right) < tolerance: 23 | return {"bottom" : False, "left" : False,"right" : True,"top" : False,} 24 | 25 | return {"bottom" : False, "left" : False,"right" : False,"top" : False,} 26 | 27 | block_list = [characters.Block((400,400), (600,400), (255,255,255))] 28 | 29 | 30 | def render(): 31 | screen.fill((0,0,255)) 32 | 33 | characters.plr.update(screen, camera.scroll, block_list) 34 | 35 | #pygame.draw.rect(screen, (25,25,25), characters.plr.rect) 36 | 37 | 38 | for block in block_list: 39 | block.update(screen, camera.scroll) 40 | 41 | camera.follow(characters.plr, 1, speed= 32,) 42 | 43 | 44 | def collisions(): 45 | 46 | pass 47 | 48 | 49 | -------------------------------------------------------------------------------- /images/player/New Piskel.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/New Piskel.zip -------------------------------------------------------------------------------- /images/player/attack.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/attack.zip -------------------------------------------------------------------------------- /images/player/fall.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/fall.zip -------------------------------------------------------------------------------- /images/player/fall1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/fall1.png -------------------------------------------------------------------------------- /images/player/fall2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/fall2.png -------------------------------------------------------------------------------- /images/player/fall3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/fall3.png -------------------------------------------------------------------------------- /images/player/fall4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/fall4.png -------------------------------------------------------------------------------- /images/player/fall5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/fall5.png -------------------------------------------------------------------------------- /images/player/idle.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/idle.zip -------------------------------------------------------------------------------- /images/player/idle0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/idle0.png -------------------------------------------------------------------------------- /images/player/idle1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/idle1.png -------------------------------------------------------------------------------- /images/player/idle2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/idle2.png -------------------------------------------------------------------------------- /images/player/idle3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/idle3.png -------------------------------------------------------------------------------- /images/player/imgs.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/imgs.zip -------------------------------------------------------------------------------- /images/player/jump.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/jump.zip -------------------------------------------------------------------------------- /images/player/jump0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/jump0.png -------------------------------------------------------------------------------- /images/player/jump1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/jump1.png -------------------------------------------------------------------------------- /images/player/jump2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/jump2.png -------------------------------------------------------------------------------- /images/player/jump3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/jump3.png -------------------------------------------------------------------------------- /images/player/jump4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/jump4.png -------------------------------------------------------------------------------- /images/player/punch0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/punch0.png -------------------------------------------------------------------------------- /images/player/punch1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/punch1.png -------------------------------------------------------------------------------- /images/player/punch2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/punch2.png -------------------------------------------------------------------------------- /images/player/run.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/run.zip -------------------------------------------------------------------------------- /images/player/run1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/run1.png -------------------------------------------------------------------------------- /images/player/run2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/run2.png -------------------------------------------------------------------------------- /images/player/run3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/run3.png -------------------------------------------------------------------------------- /images/player/run4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softdev050/pygame/57aa6dc129c5912172c522e732238a3f84deab1e/images/player/run4.png -------------------------------------------------------------------------------- /run.piskel: -------------------------------------------------------------------------------- 1 | {"modelVersion":2,"piskel":{"name":"New Piskel","description":"","fps":6,"height":32,"width":24,"layers":["{\"name\":\"head\",\"opacity\":1,\"frameCount\":3,\"chunks\":[{\"layout\":[[0],[1],[2]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAAAgCAYAAACxSj5wAAAAAXNSR0IArs4c6QAAAPpJREFUaEPtlFEKhDAMRPXWPUJu7dKii8huM+k0UGH88Scdncdr9k1Pl8AO8DnOGWQWiHvXiFf6glNbebPvag7+ba/0Hc6vuNnAsk0dymcAzbQq29ThfNSCfzah53tCZ5tK5aMF20fMbCultHd9SinoeQYQa6oHqJsPFTSz4wHmggWdB/dhHcs0dSgfLlghPYtOMugem2nqF1DkJiwFKNvUkfxhQAn2NJOyTY3mw4ACe4QajRaIfiyavzyg2aY+AXn5ywGKGpE9L0AOYQESIO4SyiAZJIM4AjKI46cdJINkEEdABnH8tINkkAziCMggjp92kAySQRwB5/QHT0FmIeAi9PoAAAAASUVORK5CYII=\"}]}","{\"name\":\"legs\",\"opacity\":1,\"frameCount\":3,\"chunks\":[{\"layout\":[[0],[1],[2]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAAAgCAYAAACxSj5wAAAAAXNSR0IArs4c6QAAAR5JREFUaEPtlmEKhCAQRvNOXSAQulLQBTqU4AW8U8sIs7hCzuREG/HtvzZ31DfPz3UDPk0CDnzaBABIMASAAMgWIjAIBsEgGwEYZOOHDIJBMMhGAAbZ+CGDYBAMshGAQTZ+yCAYBINsBGCQjR8yCAbdYNC2bTtPsyyLq59tSxiGEMK3PtXy3l9mdlk7pfSzVNqLtHZxABW4GxBtRLN4aXP0voZfQtLM8VhAtDnNBiRIrwN0tsMSoCOLtPAfZVBPRmgAUUSM45iHnj2+fwfER4CCucw66xGbpmmf5zlDYTg9F4AKEE3GnYoxuvpZ08V6TJkN5a111Q35GkD1lc6AtBnRag43cl3XPKzn74PKoB5DpN8cWcjfk6lSDe17S80PaEGzIQtbS14AAAAASUVORK5CYII=\"}]}","{\"name\":\"torso\",\"opacity\":1,\"frameCount\":3,\"chunks\":[{\"layout\":[[0],[1],[2]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAAAgCAYAAACxSj5wAAAAAXNSR0IArs4c6QAAAK5JREFUaEPtlkEOgCAMBOHXPIFfa7wagdVFacx4rlsZhkpOPF0CGT59AgAaGAIgAHlDBIMwCIM8Ahjk8WMGYRAGeQQwyOPHDMKgDwyqtW6tNqWUX1soLe5tQJHzATQ4AQACUErOEQ5t0KwfQAuQkg+gGfcgR1HlFnKVr+yukn3UOPmSQeqHPK1zFqD0POffgR8CkLLIVTUAmjGDVu1ehL4YhEGehxiEQRjkERi8vQO8WWAhWc42rgAAAABJRU5ErkJggg==\"}]}","{\"name\":\"robe\",\"opacity\":1,\"frameCount\":3,\"chunks\":[{\"layout\":[[0],[1],[2]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAAAgCAYAAACxSj5wAAAAAXNSR0IArs4c6QAAATBJREFUaEPtl1EOwyAMQ9ej9eQ92iY+kBAC4iRuqSb3uzXOwwn0+OhZEjjEZ01AgIyECJAA5YaIEqQEKUE5AkpQjp9mkBL0QILO8/yOlrmu6+8TaBY4g1OBMSG1azF1q9eI/hKQBacszCpktBZLu/iM6qcBMZJ0dwtn9LcDWqWUkaCs/lZAd7cwQz8EqOxsv7h3txHzmRnH0n8dIAb82VCuwD2b6wbUJiVybK7MRwoY3c+sufNqQJb5zJ0Fge/VdyWonzORBKFHbkTbaq02bah+ClBrCB3S6IUNLaBvMbY+DGgGoBpiA6rwUd1R61iX2OLd0t8OyDLo/Rf3DGBEGwLELCLaOkgx/Qxi+Db/5lFj6HtIrFGt2RHPAFO1HweUKX7HtwJkUBcgAco1phJk8PsBCpEEMK3R+2cAAAAASUVORK5CYII=\"}]}"],"hiddenFrames":["0",0]}} -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | 2 | def create_enemy(type, damage, hp): 3 | print(f"Enemy: {type, damage, hp, difficulty}") 4 | 5 | difficulty = "medium" 6 | 7 | difficulty_damage = { 8 | "easy" : { 9 | "enemy1" : [20, 5], 10 | "enemy2" : [12, 8], 11 | }, 12 | 13 | "medium" : { 14 | "enemy1" : [25, 8], 15 | "enemy2" : [15, 10], 16 | }, 17 | 18 | "hard" : { 19 | "enemy1" : [30, 10], 20 | "enemy2" : [20, 12], 21 | }, 22 | } 23 | 24 | create_enemy("enemy1", difficulty_damage[difficulty]["enemy1"][0],difficulty_damage[difficulty]["enemy1"][1]) 25 | create_enemy("enemy2", difficulty_damage[difficulty]["enemy2"][0],difficulty_damage[difficulty]["enemy2"][1]) 26 | create_enemy("enemy2", difficulty_damage[difficulty]["enemy2"][0],difficulty_damage[difficulty]["enemy2"][1]) 27 | 28 | --------------------------------------------------------------------------------