Advertisement
NovaYoshi

tilemap town bomberman

Dec 5th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. playing = []
  2. starting_places = [] # fill this in with starting spots
  3.  
  4. def use_item_bomb(player, x, y):
  5. @obj_add(x, y, "bomb")
  6. @timer(5, bomb_explode, x, y)
  7. return false # don't use up the item
  8.  
  9. def game_start():
  10. starts = @clone(starting_places)
  11.  
  12. # everyone is playing
  13. playing = @player_who()
  14.  
  15. # put them on the playfield
  16. for p in playing:
  17. # remove starting places from map after they're picked
  18. i = @random(@len(starts))
  19. pos = starts[i]
  20. @remove_index(starts, i)
  21.  
  22. # put them into that position
  23. @player_move(p, pos[0], pos[1])
  24.  
  25. def player_leave_hook(player):
  26. remove(playing)
  27. check_for_winner() # did someone leaving cause someone to be the only person left?
  28.  
  29. def check_for_winner():
  30. if len(playing) == 1: # only one person left?
  31. player = @pop(playing) # get that last player
  32. name = @player_displayname(player)
  33. wins = @player_load(player, "wins", 0) # get saved win count
  34. @player_save(player, "wins", wins+1) # increase win count
  35. @player_move(player, lobby_x, lobby_y)
  36. @say("the winner is "+name) # announce winner
  37. @say("their win count: "+@str(wins+1)) # announce winner's new score
  38.  
  39. def kill(x, y):
  40. # remove players from the game
  41. list = @player_at_xy(x, y)
  42. for p in list:
  43. @player_move(p, lobby_x, lobby_y)
  44. @remove(playing, p)
  45. check_for_winner()
  46.  
  47. def bomb_explode(x, y):
  48. @obj_remove(x, y, "bomb")
  49.  
  50. list = [] # list of tiles to clean up
  51.  
  52. # explode in a + shape
  53. for n = x-2 to x+2:
  54. # horizontal
  55. @obj_add(n, y, "explosion")
  56. @push(list, [n, y])
  57. kill(n, y)
  58.  
  59. # vertical
  60. @obj_add(x, n, "explosion")
  61. @push(list, [x, n])
  62. kill(x, n)
  63.  
  64. @timer(1, bomb_clean, list)
  65.  
  66. def bomb_clean(tiles):
  67. # remove explosions
  68. for n in tiles:
  69. @obj_remove(n[0], n[1], "explosion")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement