def attack( self, eventManager, mobiles, immobiles ): newProjectile = projectile.Projectile( self.rect.topleft, \ self.classType + PROJECTILE ) newProjectile.owner = self if self.direction == NORTH or self.direction == NORTHWEST or \ self.direction == NORTHEAST: newProjectile.movingNorth = True newProjectile.rect.top -= TILE_SIZE elif self.direction == SOUTH or self.direction == SOUTHWEST or \ self.direction == SOUTHEAST: newProjectile.movingSouth = True newProjectile.rect.top += TILE_SIZE if self.direction == EAST or self.direction == SOUTHEAST or \ self.direction == NORTHEAST: newProjectile.movingEast = True newProjectile.rect.left += TILE_SIZE elif self.direction == WEST or self.direction == SOUTHWEST or \ self.direction == NORTHWEST: newProjectile.movingWest = True newProjectile.rect.left -= TILE_SIZE newProjectile.direction = self.direction newProjectile.speed = 3 * self.speed #check if the projectile is colliding with anything before adding if pygame.sprite.spritecollide(newProjectile,mobiles,False): for mob in pygame.sprite.spritecollide(newProjectile,mobiles,False): if not isinstance(mob, projectile.Projectile): mob.takeDamage(newProjectile, eventManager) elif pygame.sprite.spritecollide(newProjectile,immobiles,False): pass else: projEvent = events.AddProjectile(newProjectile) eventManager.post(projEvent)
def get_projectile(self, event): if self.cd == 0: self.cd = PROJ_CD proj = prjct.Projectile(self.rect, event) return proj else: return None
def update(self, hero): if self.is_moving: self.position += self.velocity self.rect.center = self.position self.current_sprite += 0.3 if self.current_sprite >= len(self.assetAnimation): self.current_sprite = 0 self.image = self.assetAnimation[int(self.current_sprite)] # if not self.game_area.contains(self.rect): # self.kill() self.velocity = Vector2(self.hero.position) - Vector2(self.position) if self.enemy_type == "Mushroom": Vector2.scale_to_length(self.velocity, 1) if self.enemy_type == "Skeletor": Vector2.scale_to_length(self.velocity, 2) if self.enemy_type == "Hydra": Vector2.scale_to_length(self.velocity, 2) if self.enemy_type == "Cacodemon": Vector2.scale_to_length(self.velocity, 2) if self.enemy_type == "Invulnro": Vector2.scale_to_length(self.velocity, 1) if self.enemy_type == "Tetro": Vector2.scale_to_length(self.velocity, 4) if self.enemy_type == "Mergamoth": Vector2.scale_to_length(self.velocity, self.scale_factor) if self.enemy_type == "Cacodemon" or self.enemy_type == "Mergamoth": if random.randint(1, 100) > 99: self.velocity.scale_to_length(0) # self.fired_time = pygame.time.get_ticks() gamestate.all_sprites.add( projectile.Projectile(self.rect.center, gamestate.game_area, hero, "enemy"))
def fire(self, ent, canShoot): if (canShoot): ent.append( projectile.Projectile( self.playerX + 16 + 64 * math.cos(self.angle), self.playerY + 16 + 64 * math.sin(self.angle), self.angle)) self.cooldown = self.cooldownMax
def redrawGameWindow(gamestate): """ The main drawing function of the game :param gamestate: Decoded Json string :return: Draws the game graphics """ global index global alive global uniqueID #print(gamestate["tanks"]) if gamestate["tanks"][str(uniqueID)]["alive"] == False: alive = False win.blit(chosenBackground, (0, 0)) projectiles = gamestate["projectile"] projList = [] projToBeRemoved = [] for key in projectiles: projList.append(key) if key in projectileDict: projectileDict[key].draw(win, projectiles[key]) else: projectileDict[key] = projectile.Projectile(projectiles[key]) projectileDict[key].draw(win, projectiles[key]) for key in projectileDict: if key not in projList: projToBeRemoved.append(key) for key in projToBeRemoved: spriteCount = explosionEffect.draw(win, round(projectileDict[key].x), round(projectileDict[key].y), centerHandle) if spriteCount > 10: projectileDict.pop(key) tanks = gamestate["tanks"] for key in tanks: if key in tanksDict: tanksDict[key].draw(win, tanks[key]) else: tanksDict[key] = Tank(tanks[key], mh.tankCounter) tanksDict[key].draw(win, tanks[key]) if mh.tankCounter < 4: mh.tankCounter += 1 else: mh.tankCounter = 0 # generate terrain terrainMap = gamestate["terrain"] for key in terrainMap: terrainDict[key] = terrain.Terrain(terrainMap[key]) if chosenBackground == rs.bg2: terrainDict[key].drawForest(win, terrainMap[key]) else: terrainDict[key].drawWinter(win, terrainMap[key]) pygame.display.update()
def shoot(self): """ Shoots a projectile """ sound.play_laser_shot() bullet = projectile.Projectile(self.x + self.width//2 - 5, self.y - self.height, Player, 10, window=self._window) game.add_gameobject(bullet)
def changeState(self): if self.target.health < 1: self.state = 0 self.firing = False if self.type != "Beehive": if self.state == len(self.images) - 1: self.state = 0 self.firing = False i = 1 while True: if not pygame.mixer.Channel(i).get_busy(): if main.Config.sfx == False: pygame.mixer.Channel(1).set_volume( main.Config.volume) pygame.mixer.Channel(1).play( pygame.mixer.Sound("Sounds\sfx_" + str(self.type) + ".wav")) break else: i += 1 if i == 9: i = 1 self.proj.append( projectile.Projectile(self.type, self.target, self.plevel, self, len(self.proj))) else: self.state += 1 else: if self.state == 3: self.state += 1 self.firing = False if main.Config.sfx == False: pygame.mixer.Channel(1).set_volume(main.Config.volume) pygame.mixer.Channel(1).play( pygame.mixer.Sound("Sounds\sfx_" + str(self.type) + ".wav")) self.proj.append( projectile.Projectile(self.type, self.target, self.plevel, self, len(self.proj))) elif self.state == len(self.images) - 1: self.state = 0 else: self.state += 1
def hero_check_input(game_state): move = Vector2(0, 0) event = pygame.key.get_pressed() if event[pygame.K_w]: move += (0, -3) if event[pygame.K_a]: move += (-3, 0) if event[pygame.K_s]: move += (0, 3) if event[pygame.K_d]: move += (3, 0) if move.length() > 0: move.normalize_ip() move.scale_to_length(3.0) game_state.hero.is_moving = True else: game_state.hero.is_moving = False game_state.hero.velocity = move # if pygame.mouse.get_pressed(3)[2]: # character.mouse_position = pygame.mouse.get_pos() # character.is_moving = True if pygame.mouse.get_pressed(3)[0]: if game_state.hero.projectile_count >= 55\ or pygame.time.get_ticks() - game_state.hero.projectile_fired_time < game_state.hero.fire_rate or game_state.hero.is_dead: return else: if game_state.state == 'game_lobby': gamestate.lobby_sprites.add( projectile.Projectile(pygame.mouse.get_pos(), gamestate.game_area, game_state.hero, "hero")) game_state.hero.projectile_fired_time = pygame.time.get_ticks() if game_state.state == 'main_game': gamestate.all_sprites.add( projectile.Projectile(pygame.mouse.get_pos(), gamestate.game_area, game_state.hero, "hero")) game_state.hero.projectile_count += 1 game_state.hero.projectile_fired_time = pygame.time.get_ticks()
def shootProjectile(self): # Shooting Logic # Calculate speed for X and Y xDiff = self.aimPosition[0] - self.center_x yDiff = self.aimPosition[1] - self.center_y pointDiff = math.sqrt((xDiff**2) + (yDiff**2)) multiplier = constants.PROJECTILE_SPEED / pointDiff self.projectiles.append( projectile.Projectile(self.center_x, self.center_y, xDiff * multiplier, yDiff * multiplier))
def createProjectile1(self): temp = projectile.Projectile() f = [ self.frameData(16, 2) ] t = [ ['exitFrame', move.Transition(-1, None, None, None, 'flying')] ] temp.moves['flying'].append(f, t) temp.moves['flying'].frames[0].setVelX = 18 self.createProjectileEnding1(temp) self.projectiles.append(temp)
def __init__(self, x, y, damage_points=1): width = 40 height = 40 health_points = 10 is_active = False display_layer = 2 gravity = False direction = False x_clip_offset, y_clip_offset = 0, 0 max_x_vel = 0 boulder_sprite = Sprite(universal_var.main_sprite, x, y, width, height, [ ('boulder', [universal_var.projectiles['boulder_1']], 1) ]) main_collbox = Collision_box(universal_var.hitbox, 0, 0, width, height, (60, 240, 0)) super().__init__('boulder', x, y, [boulder_sprite], [main_collbox], is_active, width, height, display_layer, gravity, direction, max_x_vel, health_points, damage_points, x_clip_offset, y_clip_offset) Hoohoo_boulder.add_to_class_lst(self, Megaman_object.hazards, self.ID) self.add_explosion_animation(time_offset=0, width=50, height=50, x_offset=0, y_offset=0) for i in range(2): mini_boulder_1_sprite = Sprite(universal_var.main_sprite, self.x, self.y, 20, 20, [ ('mini_boulder_1', [universal_var.projectiles['boulder_{}'.format(i+2)]], 1) ]) mini_boulder_1_collbox = Collision_box(universal_var.hitbox, self.x, self.y, 25, 25, (122,122,122)) mini_boulder_1 = projectile.Projectile('mini_boulder_1', self.x, self.y, [mini_boulder_1_sprite], [mini_boulder_1_collbox], width=20, height=20) mini_boulder_1.damage_points = 12 Hoohoo_boulder.mini_boulder_1_stack.push(mini_boulder_1) Hoohoo_boulder.add_to_class_lst(mini_boulder_1, Megaman_object.hazards, mini_boulder_1.ID) for i in range(3): mini_boulder_2_sprite = Sprite(universal_var.main_sprite, self.x, self.y, 10, 10, [('mini_boulder_2', [universal_var.projectiles['boulder_4']], 1)]) mini_boulder_2 = projectile.Projectile('mini_boulder_2', self.x, self.y, [mini_boulder_2_sprite], width=10, height=10) Hoohoo_boulder.mini_boulder_2_stack.push(mini_boulder_2)
def mousePressed(self, x, y): if self.player1.rect != None: centerX = self.player1.x centerY = self.player1.y xDiff = x - (centerX) yDiff = y - (centerY) if xDiff == 0 and y < centerY: self.angle = math.pi / 2 elif xDiff == 0 and y > centerY: self.angle = 3 * math.pi / 2 elif yDiff == 0 and x > centerX: self.angle = 0 elif yDiff == 0 and x < centerX: self.angle = math.pi else: self.angle = math.pi / 2 + math.atan(xDiff / -yDiff) if y > centerY: self.angle *= -1 else: self.angle = math.pi - self.angle bullet = projectile.Projectile(centerX, centerY, self.angle) self.bulletGroup.add(bullet)
def compute(self): # format empty entries as None for Projectile.solve() method entries = {} for key, value in self.user_entries.items(): try: entries[key] = value.get() except TclError: entries[key] = None # use Projectile class to attempt to solve and return dictionary solution = projectile.Projectile(**entries) if solution.solve() == 'success': entries = solution.__dict__ # set DoubleVars to returned values for key, value in entries.items(): valuestring = '{:.2f}'.format(value) self.display_entries[key].set(valuestring) # display error if calculation unsuccessful else: for key, value in entries.items(): self.display_entries[key].set('Error') print(solution.__dict__)
import projectile as ptl import matplotlib.pyplot as plt p = ptl.Projectile() p.init(10, 10, 60, 0, 0, 1.2, 0.1, 0.5, 0.01) x1, y1 = p.move_ar() p.reset() p.init(10, 10, 60, 0, 0, 1.2, 0.1, 0.5, 0.01) x2, y2 = p.runge_kutta() plt.plot(x1, y1, label="Euler") plt.plot(x2, y2, c="magenta", label="Runge-Kutta") plt.xlabel("x [m]") plt.ylabel("y [m]") plt.title("x-y graf") plt.legend(loc="upper right") plt.show()
import projectile as ptl import matplotlib.pyplot as plt kocka = ptl.Projectile() kocka.init(5,10,60,0,0,1,2,0.75,0.01,"kocka") #(m,v0,theta,x0,y0,ro,cd,a,dt,tijelo = "kugla") x,y = kocka.runge_kutta() kugla = ptl.Projectile() kugla.init(5,10,60,0,0,1,2,0.5,0.01) #(m,v0,theta,x0,y0,ro,cd,a,dt,tijelo = "kugla") x1,y1 = kugla.runge_kutta() plt.plot(x,y, label = "kocka") plt.plot(x1,y1, label = "kugla") plt.xlabel("x [m]") plt.ylabel("y [m]") plt.title("x-y graf") plt.legend() plt.show()
def shoot(self): newProj = projectile.Projectile(self.ds, self.h, self.cannonSize, self.pos) self.projectiles.append(newProj) self.roundsFired += 1
def startgame(): shot = 0 rock_timer = -1 model = Model() view = View(model) ship = model.ships[0] run = True score = 0 lives = 3 bullet_pop = False while run and lives > 0: while (rock_timer > 0): rock_timer -= 1 if (rock_timer == 0): model.rocks.append( rocks.Asteroid_Big(window, winH, winL, image=asteroid3)) model.rocks.append( rocks.Asteroid_Big(window, winH, winL, image=asteroid3)) model.rocks.append( rocks.Asteroid_Big(window, winH, winL, image=asteroid3)) model.rocks.append( rocks.Asteroid_Big(window, winH, winL, image=asteroid3)) rock_timer = -1 if shot > 0 and shot <= 5: shot += 1 else: shot = 0 pygame.time.delay(100) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False for rock in model.rocks: rock.update_rock() if (rock.x + rock.radius < ship.hitbox[0] + ship.hitbox[2] and rock.x + rock.radius > ship.hitbox[0]): if (rock.y + rock.radius < ship.hitbox[1] + ship.hitbox[3] and rock.y + rock.radius < ship.hitbox[1]): model.ships.pop(model.ships.index(ship)) lives -= 1 model.ships.append( contr.Ship(winL=winL, winH=winH, window=window, image=ship_img)) ship = model.ships[0] shots_fired_ship = ship.update_ship() if shots_fired_ship == True and shot == 0: bullet = proj.Projectile(round(ship.x), round(ship.y), 2, (250, 250, 250), ship.angle, ship.window, winL, winH) model.bullets.append(bullet) shot += 1 for bullet in model.bullets: bullet.update_projectile() # print('bullet check :', bullet) if bullet.lifetime > 15: model.bullets.pop(model.bullets.index(bullet)) for rock in model.rocks: if (bullet.x + bullet.radius < rock.hitbox[0] + rock.hitbox[2] and bullet.x + bullet.radius > rock.hitbox[0]): if (bullet.y + bullet.radius < rock.hitbox[1] + rock.hitbox[2] and bullet.y + bullet.radius > rock.hitbox[1]): size = rock.hit() if size == 3: score += 10 model.rocks.append( rocks.Asteroid_Med(window, winH, winL, rock.x, rock.y, image=asteroid2)) model.rocks.append( rocks.Asteroid_Med(window, winH, winL, rock.x, rock.y, image=asteroid2)) elif size == 2: score += 25 model.rocks.append( rocks.Asteroid_Small(window, winH, winL, rock.x, rock.y, image=asteroid1)) model.rocks.append( rocks.Asteroid_Small(window, winH, winL, rock.x, rock.y, image=asteroid1)) elif size == 1: score += 50 model.rocks.pop(model.rocks.index(rock)) bullet_pop = True if bullet_pop == True: model.bullets.pop(model.bullets.index(bullet)) bullet_pop = False if not model.rocks: rock_timer = 4 keys = pygame.key.get_pressed() view.redrawGameWindow() pygame.display.update() pygame.quit()
def update(self): #** In the event bullet leaves screen boundaries #** REMOVE the bullet off the screen & memory #*** for bullet in self.game.projectile: if bullet.rect.y < 0 or bullet.rect.y > SCREEN_HEIGHT - PLAYER_HEIGHT \ or bullet.rect.x < 0 or bullet.rect.x-PROJECTILE_OFFSET > SCREEN_WIDTH - PLAYER_WIDTH: self.game.projectile.remove(bullet) #*** # Grab the keyboard up/down/left/right/space # This construct also allows diagonal movement ie. left+down #*** keys=pygame.key.get_pressed() if keys[K_LEFT]: self.rect.x -= self.playerspeed self.CheckX() self.lastdirection=K_LEFT self.lasthoriz=K_LEFT elif keys[K_RIGHT]: self.rect.x += self.playerspeed self.CheckX() self.lastdirection=K_RIGHT self.lasthoriz=K_RIGHT if keys[K_UP]: self.rect.y -= self.playerspeed self.CheckY() self.lastdirection=K_UP self.lastvert=K_UP elif keys[K_DOWN]: self.rect.y += self.playerspeed self.CheckY() self.lastdirection=K_DOWN self.lastvert=K_DOWN SpriteGroup = pygame.sprite.groupcollide(self.game.powerups,self.game.PlayerSprites,True,False) projectile.Projectile.Check_Hit_PowerUp(self,SpriteGroup) #*** Check if Player Collides with Enemy *** SpriteGroup = pygame.sprite.groupcollide(self.game.PlayerSprites,self.game.enemies,False,True) if SpriteGroup: playSound("dying") spn=len(self.game.Enemy_SPAWN_List) # Spawned #hits=self.game.enemy_hits # Enemies Destroyed on screen if (self.game.allspawned==True): self.game.enemies_level_start=len(self.game.enemies)+1 #spn-hits else: self.game.enemies_level_start=spn self.First_Time_in_Round=False text = texts.Text(self.game, 550, SCREEN_HEIGHT-15, str(self.game.enemies_level_start)+" enemies remaining",15,"CENTRE",3,1) self.game.points.append(text) bs=175 cv=145 for i in range(5): self.DyingEffect(bs,cv,0,0) self.DyingEffect(-bs,cv,0,0) self.DyingEffect(bs,cv,cv,0) #reset values to original self.image = pygame.Surface((self.width,self.height)) self.image.fill((YELLOW)) self.game.draw() pygame.sprite.Group.empty(self.game.enemies) pygame.sprite.Group.empty(self.game.projectile) self.game.playing=False self.game.SetPlayerDead() self.game.Enemy_SPAWN_List.clear() pygame.sprite.Group.empty(self.game.enemies) pygame.sprite.Group.empty(self.game.projectile) pygame.sprite.Group.empty(self.game.powerups) self.game.enemies_spawned=0 self.image.fill((BLACK)) return if Player.PowerupType>=0 or keys[K_SPACE]: if self.projectilecooldown==0 : #stopSound("walking") playSound("firing") #*** After cooldown period, FIRE a BULLET!! In direction player last moved on screen self.projectilecooldown=self.maxprojectilecooldown projectile1=projectile.Projectile(self.game,self.lastdirection,self.rect.x,self.rect.y) self.game.projectile.add(projectile1) directions=[K_UP,K_DOWN,K_LEFT,K_RIGHT] if Player.PowerupType==2: # Power up to fire in all directions if self.lastdirection in directions: directions.remove(self.lastdirection) # Dont fire in this direction (..already did a few lines above) for newbullet in directions: # add projectiles in the three other directions projectile1=projectile.Projectile(self.game,newbullet,self.rect.x,self.rect.y) self.game.projectile.add(projectile1) if Player.PowerupType==1: # Power up to fire in two directions if self.lastdirection in [K_UP,K_DOWN]: xlastvert=K_UP if self.lastvert==K_LEFT: xlastvert=K_RIGHT if self.lastvert==K_RIGHT: xlastvert=K_LEFT projectile1=projectile.Projectile(self.game,self.lasthoriz,self.rect.x,self.rect.y) self.game.projectile.add(projectile1) else: xlasthoriz=K_DOWN if self.lasthoriz==K_UP: xlasthoriz=K_DOWN if self.lasthoriz==K_DOWN: xlasthoriz=K_UP projectile1=projectile.Projectile(self.game,self.lastvert,self.rect.x,self.rect.y) self.game.projectile.add(projectile1) else: self.projectilecooldown-=1
def __init__(self): pg.init() self.clock = pg.time.Clock() self.screen = pg.display.set_mode((c.window_width, c.window_height)) self.caption = pg.display.set_caption(c.window_title) background_surface = pg.Surface((c.window_width, c.window_height)) # m.generate_tiles(background_surface) self.running = True self.time_elapsed = 0 moving_animation = 1 character = Player(self.screen, ch.master_coordinates['player']['x'], ch.master_coordinates['player']['y']) shot = False click_coords = [] bullet_coords = [] bullets = [] is_bg_drawn = False while self.running: pg.display.set_caption(str(self.clock.get_fps())) self.time_elapsed += 1 # checking pressed keys keys = pg.key.get_pressed() mouse = pg.mouse.get_pos() for event in pg.event.get(): if event.type == pg.QUIT: self.running = False if event.type == pg.MOUSEBUTTONUP: shot = True bullets.append(projectile.Projectile(character.x + 10, character.y + 10, 40, self.screen, (mouse[0], mouse[1]), (character.x, character.y))) # repaints the background <- Why do i need this? self.screen.fill((255, 255, 255)) # self.screen.blit(background_surface, (0, 0)) direction = 'right' if not keys[pg.K_w] or [pg.K_a] or [pg.K_s] or [pg.K_d]: character.is_moving = False if keys[pg.K_w]: character.y -= 8 character.is_moving = True if keys[pg.K_s]: character.y += 8 character.is_moving = True if keys[pg.K_a]: character.x -= 8 character.is_moving = True if keys[pg.K_d]: character.x += 8 character.is_moving = True if keys[pg.K_f]: self.collision_detect(character) if mouse[0] > character.x + 10: character.direction = 'right' else: character.direction = 'left' if keys[pg.K_1]: character.equip_hotbar_item(0) if keys[pg.K_2]: character.equip_hotbar_item(1) if keys[pg.K_3]: character.equip_hotbar_item(2) if shot: for bullet in bullets: bullet.update_projectile() # If the time is a multiple of ten and the player is not moving, move them up by one pixel # if self.time_elapsed % 10 == 0 and not character.is_moving: character.make_player(character.x, character.y - 3) # If the player is moving # elif character.is_moving: # If the time is a multiple of five run one animation # if self.time_elapsed % 3 == 0: character.make_player(character.x, character.y, moving_animation) if moving_animation > 1: moving_animation = 1 else: moving_animation += 1 character.make_player(character.x, character.y, moving_animation) else: # character = Player(self.screen, ch.master_coordinates['player']['x'], ch.master_coordinates['player']['y']) character.make_player(character.x, character.y) # Drawing non-player entities to the surface # for entity, entity_attributes in ch.master_coordinates.items(): if entity != 'player': inst_entity = Entity(self.screen, entity_attributes['x'], entity_attributes['y'], item_dict[entity]['icon'], item_dict[entity]['sprite']) pg.draw.line(self.screen, c.FIERCE_YELLOW, (character.x + 10, character.y + 10), mouse) hud.make_hud(self.screen, character) pg.display.update() self.time_delta = self.clock.tick(60)
def fire(self, dir): p = projectile.Projectile(direction=dir, game=self.player.game, tile=self.tile) p.tick( ) #first tick to move into the initial space and do collision detection
def shootProjectile(): '''creates a new projectile when the user presses spacebar''' newProjectile = projectile.Projectile(projectilespeed, p1.xcor()) liveProjectiles.append(newProjectile) # os.system("afplay /sounds/shoot.wav/") return
def shoot_bullets(self): if self.bullets > 0: self.throw_sound.play() surface_manager.add(projectile.Projectile(self)) self.bullets -= 1
import projectile as pr import matplotlib.pyplot as plt p1 = pr.Projectile(10, 45, 0, 0, 0.01, 1.22, 0.1, 0.05, 0.1) xd, yd = p1.evolve() p2 = pr.Projectile(10, 45, 0, 0, 0.01, 1.22, 0.1, 0.05, 0.1) x, y = p2.evolve_RK() fig = plt.figure(figsize=(20, 10)) # x-y graf plt.plot(xd, yd, label="dt=0.01, Euler") plt.plot(x, y, label="dt=0.01, Runge-Kutta", c='red') plt.xlabel('x [m]') plt.ylabel('y [m]') plt.title('x-y graf') plt.legend(loc="upper right") plt.savefig("kosi_hitac.pdf") plt.show()
import projectile as ptl import matplotlib.pyplot as plt p1 = ptl.Projectile() p1.init(10, 10, 60, 0, 0, 1, 2, 0.1, 0.01) #(m,v0,theta,x0,y0,ro,cd,a,dt,tijelo = "kugla") p1.angle_to_hit_target(2.5, 1, 0.5) p2 = ptl.Projectile() p2.init(10, 30, 60, 0, 0, 1, 2, 0.1, 0.01) #(m,v0,theta,x0,y0,ro,cd,a,dt,tijelo = "kugla") p2.angle_to_hit_target(6, 2, 0.5) p3 = ptl.Projectile() p3.init(5, 50, 60, 0, 0, 1, 2, 0.1, 0.01) #(m,v0,theta,x0,y0,ro,cd,a,dt,tijelo = "kugla") p3.angle_to_hit_target(4, 1, 0.5)
def shoot(self): if self.bullets > 0: surface_manager.add(projectile.Projectile(self)) self.bullets -= 1
def update(self): if not self.projectiles: self.projectiles.add( projectile.Projectile(self.rect.centerx, self.rect.centery))
def throw_shuriken(self): if self.shurikens > 0: self.throw_sound.play() surface_manager.add(projectile.Projectile(self)) self.shurikens -= 1
player = player.Player(data_characters[character_index]['walk_left'], data_characters[character_index]['walk_right'], data_characters[character_index]['idle'], (data_characters[character_index]['x'], data_characters[character_index]['y']), data_characters[character_index]['width'], data_characters[character_index]['force'], data_characters[character_index]['velocity'], data_characters[character_index]['image'], data_characters[character_index]['columns'], data_characters[character_index]['rows'], data_characters[character_index]['hitbox'], scale) projectile = projectile.Projectile( data_projectile[projectile_index]['image'], data_projectile[projectile_index]['columns'], data_projectile[projectile_index]['rows'], 1, data_projectile[projectile_index]['animations']) projectile_motion = projectile_motion.ProjectileMotion( screen, 0.0, 0.5, 25.0, 1.0, 45.0, 0, 0, GROUND_POSITION, data_projectile[projectile_index]['sound']) clock = pygame.time.Clock() def redraw_screen(): screen.blit(bg, (0, 0)) collision_projectile_enemy()