def shoot(self, x, y): self.bul_c = 10 / sqrt((self.top_x * self.top_x) + (self.top_y * self.top_y)) self.bullets.append( bullets.Bullet(-(self.top_x * self.bul_c), -(self.top_y * self.bul_c), x + (self.top_x * self.top_c), y + (self.top_y * self.top_c))) self.laser.play()
def shoot(self): ''' propels a bullet object forward, sets a cooldown and drains ammo ''' if not self.cooldown and self.ammo > 0: projectile = bullets.Bullet(self) self.bullet_list.add(projectile) self.groups()[0].add(projectile) self.cooldown = 5 self.ammo -= 1
def check_radius(self, enemy, path, current_time): if self.type == 2 and (current_time - self.timer) > 1: radius = set() enemy_x = enemy.path[enemy.index][0] enemy_y = enemy.path[enemy.index][1] x_aux, y_aux = 1, 1 for i in range(7): if i == 0: radius.add((self.x_pos + x_aux, self.y_pos + y_aux)) if i == 1 or i == 2: y_aux -= 1 radius.add((self.x_pos + x_aux, self.y_pos + y_aux)) if i == 3 or i == 4: x_aux -= 1 radius.add((self.x_pos + x_aux, self.y_pos + y_aux)) if i == 5 or i == 6: y_aux += 1 radius.add((self.x_pos + x_aux, self.y_pos + y_aux)) radius.add((self.x_pos, self.y_pos + 1)) # print(radius) new_radius = set() for coords in radius: if coords in path: new_radius.add(coords) if (enemy_x, enemy_y) in new_radius: # pygame.draw.circle(main.gameDisplay, RED, (100, 100), 50, 0) enemy.update_health() self.timer = current_time print((self.x_pos) * 50 + 125, (self.y_pos) * 50 + 25) # return(bullets.Bullet(enemy.rect.x, enemy.rect.y, 925, 325)) return (bullets.Bullet(enemy.rect.x, enemy.rect.y, (self.x_pos) * 50 + 125, (self.y_pos) * 50 + 25)) # self.rect.x = 50*self.path[self.index+1][0] + 113 # self.rect.y = 50*self.path[self.index+1][1] + 13 return bullets.Bullet(-1, -1, -1, -1)
def keyboard_cb(key): """keyboard manager""" turtle.setx(0) turtle.sety(0) Stats.key_pressed += 1 Game.freeze_spawn = False if key == 'Return': # Enter Game.pause = not Game.pause if key == 'Escape': engine.exit_engine() Stats.display_stats() if not Game.pause: if key == 'Up' or key == 'z': Game.rocket.rocket_up() if key == 'Left' or key == 'q': Game.rocket.rocket_left() if key == 'Right' or key == 'd': Game.rocket.rocket_right() if key == 'space': engine.add_obj( bullets.Bullet(Game.rocket.x, Game.rocket.y, 90 + Game.rocket.angle, True)) Stats.bullets_fired += 1
def run(): clock = pygame.time.Clock() gameExit = False ship = spaceship.Spaceship(screen) score = 0 x, y, tim = 300, 0, 0 alien = [ aliens.Alien(x, y, tim, red), ] bullet = [] bullet2 = [] j = 0 count = 1 counter = 1 value = 10000 level = 1 while not gameExit: screen.fill((0, 0, 0)) clock.tick(60) val = pygame.time.get_ticks() if (score > 3 * level and value > 4001): value -= 2000 level += 1 for event in pygame.event.get(): if event.type == KEYDOWN: if event.key == pygame.K_a: ship.x -= 100 pygame.draw.rect(screen, white, [ship.x, ship.y, 20, 20]) if event.key == pygame.K_d: ship.x += 100 pygame.draw.rect(screen, white, [ship.x, ship.y, 20, 20]) if event.key == pygame.K_q: gameExit = True if event.key == pygame.K_SPACE: bullet.append(bullets.Bullet(ship.x, ship.y)) if event.key == pygame.K_s: bullet2.append(bullets.Bullet2(ship.x, ship.y)) ship.pos() for i in alien: i.move(screen) for i in bullet: i.move(2) i.draw(screen, blue) for i in bullet2: i.move(4) i.draw(screen, green) for i in alien: if (val > i.tim + 8000): alien.remove(i) for i in alien: for j in bullet: if i.x == j.x and i.y == j.y: alien.remove(i) score += 1 print(score) bullet.remove(j) for i in alien: for j in bullet2: if i.x == j.x and i.y == j.y: i.tim += 5000 i.color = white bullet2.remove(j) if (val > (counter * value)): counter += 1 x = randint(1, 8) y = randint(0, 1) x *= 100 y *= 100 alien.append(aliens.Alien(x, y, val, red)) pygame.display.update()
def start_game(screen): height, width = os.popen( 'stty size', 'r' ).read().split() #this obtains board size and width as dependent on the terminal size config.height = int( height ) - 8 config.width = int( width ) * 5 config.frame_width = int( width ) Coin = coins.Coins() Obs = obstacles.Obstacles() Bullets = bullets.Bullet() Mag=Magnet() ice=bullets.Bullet() screen.create_board( height, width, Coin, Obs, Mag ) player = hero.Hero( 4, 40 ) # creating hero with co ordinates config.time_left = 500 config.start_time = time() screen.refresh_screen( player,Bullets ) dragon_flag=0 Dragon=Villain(config.width-49,player.get_y()) itr=1 quitter=False while ((not game_state.is_game_over()) and (config.time_left > 0) and (not quitter)): player.gravity() player.magnet_effect(Mag.get_y(),Mag.get_start(),Mag.get_end()) #to put the effect of the magnet on the hero quitter=player.movehero( screen.get_screen(), Bullets) game_state.coin_check( screen.get_screen() ) game_state.place_bullets( screen.get_screen(), Bullets, Obs ,dragon_flag) config.time_left = 500-(time()-config.start_time) screen.refresh_screen( player ,Bullets) if config.start_col < 4 * int( width ): # for moving the board frame config.start_col += 1 + config.boost_speed else: #this takes place when in the last frame dragon_flag=1 Dragon.update(player.get_y(),ice,screen.get_screen()) game_state.place_ice(screen.get_screen(),ice,player) if config.boost_end_time <= time(): #to handle power ups if config.state == 'u': if config.boost_speed!=0: config.boost_speed = 0 elif config.shield!=0: config.shield=0 config.state = 'c' config.boost_end_time=time()+10 elif config.state=='c': config.boost_end_time=time()+10 config.state='r' itr+=1 if player.get_y()<config.height-3: config.hangtime+=1 if config.result == 1: print( "\nYOU WON !!!!!!!!! :)" ) else: print( "YOU LOST :( :( :(" ) print( "SCORE:- %d" % (config.score) )
import bullets import numpy as np import game_state x = bullets.Bullet() temp = x.get_cor() temp = np.insert(temp, len(temp), [-7, 5], axis=0) temp = np.insert(temp, len(temp), [-7, 6], axis=0) print(temp) x.update_cor(temp) game_state.remove_bullet(x, -7, -6) print(x.get_cor())
def player_shoot(rotation, x, y): bulletR = bullets.Bullet(rotation, x, y) bulletgroup.add(bulletR) allsprites.add(bulletR)
else: asteroids.remove(ast) addAstCount += 1 asteroids.reverse() for i in range(addAstCount): asteroids.append( addRandomAsteroid(int(ship.x), int(ship.y), int(ship.z))) key = pygame.key.get_pressed() #bullet Stuff if (key[pygame.K_SPACE] and not bulletExists): bulletExists = True bullet = bullets.Bullet((ship.x, ship.y, ship.z), ((1.6, 1.6))) if (bulletExists): for edge in bullet.edges: points = [] for x, y, z in (bullet.verticies[edge[0]], bullet.verticies[edge[1]]): x -= cam.x y -= cam.y z -= cam.z y, z = rotate2d(y, z, bullet.rotation[1]) x, z = rotate2d(x, z, bullet.rotation[0]) if (z != 0): f = 200 / z
global_funct.display_ending("YOU QUITTER!") break elif event == config.LEFT: mario.check_left() elif event == config.RIGHT: mario.check_right() elif event == config.UP: mario.jump() # Fire bullet at boss enemy elif event == config.FIRE and mario.posx >= global_var.scenery.scene_length-config.columns: if not global_var.bullet_present: bullet = bullets.Bullet(mario.posx+mario.width, int(mario.posy+mario.height/2)) global_var.bullet_present = True # Another bullet shouldn't fire until the previous one has disappeared if global_var.bullet_present: if bullet.posx >= global_var.scenery.scene_length-int(config.columns/2)+2: del bullet global_var.bullet_present = False global_var.dragon_lives -= 1 global_var.score += 10 if global_var.dragon_lives <= 0: global_funct.display_ending("YOU WON!") break else: bullet.move_right()