Advertisement
Guest User

game is a peice of shit

a guest
Mar 24th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.08 KB | None | 0 0
  1. # draw enemey in game update, need to do jump, need to do coollisions with platforms. need to implement the colision class still but it has been made.
  2. import simplegui
  3. import codeskulptor
  4. import random
  5. from user301_734IOKEVrN_0 import Vector
  6.  
  7. #constants
  8. CANVAS_WIDTH = 1000
  9. CANVAS_HEIGHT = 600
  10. CLEARANCE = 300
  11. PLATFORM_SPACING = 100
  12. NUM_PLAT = CANVAS_HEIGHT//PLATFORM_SPACING
  13.  
  14. #global variables
  15. welcome_screen_timer = 0
  16. highscore = 0
  17. attempts = 0
  18. timer_after_hits_player = 0
  19. count = 0
  20. image = simplegui.load_image("https://raw.githubusercontent.com/0xForge/GameDevUni35/bb681c9841c3e5ee34ca63d3a5d4ba0c8cba3f72/player_character_animaitons/absorb_fall/absorb_fall_00.png?token=AeotiQthMQ7uiTyOvUX3sH3gtThVpMDrks5ckjMwwA%3D%3D")
  21. #game mode global variables
  22. background_colour = ''
  23. platform_colour = ''
  24. enemy_damage = 0
  25. enemy_speed = 0
  26.  
  27. class Platform:
  28. def __init__(self, height):
  29.  
  30. self.plat_per_row = random.randrange(2,5)
  31.  
  32. #Depending on how many platformss are in a row, the platform sizes will differ
  33. if self.plat_per_row == 2:
  34. distence_between_plats = random.randrange(40, 100)
  35. left_offset = random.randrange(0, 100)
  36. if left_offset >= 25:
  37. plat_width = random.randrange(370, 420)
  38. if left_offset < 25:
  39. plat_width = random.randrange(420, 470)
  40.  
  41. elif self.plat_per_row == 3:
  42. distence_between_plats = random.randrange(40, 50)
  43. left_offset = random.randrange(0, 100)
  44. if left_offset >= 25:
  45. plat_width = random.randrange(230, 270)
  46. if left_offset < 25:
  47. plat_width = random.randrange(245, 285)
  48.  
  49. elif self.plat_per_row == 4:
  50. distence_between_plats = random.randrange(50, 80)
  51. left_offset = random.randrange(0, 100)
  52. if left_offset >= 25:
  53. plat_width = random.randrange(160, 205)
  54. if left_offset < 25:
  55. plat_width = random.randrange(180, 220)
  56.  
  57. #creates coordinates left and right x coordinates for each platform in a row
  58. self.left_1 = left_offset
  59. self.right_1 = self.left_1 + plat_width
  60. self.left_2 = self.right_1 + distence_between_plats
  61. self.right_2 = self.left_2 + plat_width
  62. self.left_3 = self.right_2 + distence_between_plats
  63. self.right_3 = self.left_3 + plat_width
  64. self.left_4 = self.right_3 + distence_between_plats
  65. self.right_4 = self.left_4 + plat_width
  66. self.height = height
  67.  
  68. def draw_platform(self, canvas, state):
  69. #Draws the platforms depending on how many platofrms are meant to be in a row
  70. if self.plat_per_row == 2:
  71. canvas.draw_line([self.left_1, self.height],
  72. [self.right_1,self.height], 10, platform_colour)
  73. canvas.draw_line([self.left_2, self.height],
  74. [self.right_2,self.height], 10, platform_colour)
  75.  
  76. elif self.plat_per_row == 3:
  77. canvas.draw_line([self.left_1, self.height],
  78. [self.right_1,self.height], 10, platform_colour)
  79. canvas.draw_line([self.left_2, self.height],
  80. [self.right_2,self.height], 10, platform_colour)
  81. canvas.draw_line([self.left_3, self.height],
  82. [self.right_3,self.height], 10, platform_colour)
  83.  
  84. else:
  85. canvas.draw_line([self.left_1, self.height],
  86. [self.right_1,self.height], 10, platform_colour)
  87. canvas.draw_line([self.left_2, self.height],
  88. [self.right_2,self.height], 10, platform_colour)
  89. canvas.draw_line([self.left_3, self.height],
  90. [self.right_3,self.height], 10, platform_colour)
  91. canvas.draw_line([self.left_4, self.height],
  92. [self.right_4,self.height], 10, platform_colour)
  93.  
  94. class ColisionsPlatform:
  95. def __init__(self, platform, player):
  96. self.player = player
  97. self.platform = platform # so platform is goign o be cordinates of each line
  98.  
  99. def update(self):
  100. if self.platform.hitUp(self.player):# hit up was going to be a function in platfrom class but that was when i thought each platfrom could be teated individually
  101. print("hitup")
  102. #player.getP
  103. if self.platform.hitBottom(self.player)
  104. print("hit bottom")
  105.  
  106. class Character:
  107. def __init__(self):
  108. self.vel = Vector(0,0)
  109. self.rad = 25
  110. self.pos = Vector(CANVAS_WIDTH / 2, ((CANVAS_HEIGHT - self.rad)- 5))#add position
  111. self.image = simplegui.load_image('https://raw.githubusercontent.com/0xForge/GameDevUni35/master/player_character_animaitons/full_sprite_sheet/full_sprite_sheet.png?token=AVJ2jOa9eIVlFINQHLRtYaeV3iCp7jHqks5clnDGwA%3D%3D')
  112. self.width = self.image.get_width()
  113. self.height = self.image.get_height()
  114. self.columns = 11
  115. self.rows = 4
  116. self.frameSize = (self.width // self.columns, self.height // self.rows)
  117. self.frameCentre = (self.frameSize[0]/2, self.frameSize[1]/2)
  118. self.lives = 3
  119. self.score = 0
  120.  
  121. def reduceLives(self):
  122. self.lives = self.lives-1
  123. self.pos = Vector(CANVAS_WIDTH / 2, ((CANVAS_HEIGHT - self.rad)- 5)) #puts player back at begining
  124.  
  125. def draw(self,canvas):
  126. canvas.draw_circle((self.pos.x, self.pos.y),self.rad,1,'Blue','Blue')
  127. self.drawScore(canvas)
  128. self.drawLives(canvas)
  129.  
  130. def update(self):
  131. global count
  132. self.pos.add(self.vel)
  133. self.vel.multiply(0.85)
  134. if (count & 60 == 0):
  135. self.score += 1
  136.  
  137. def died(self):# will have to implement the
  138. global highscore
  139. if (self.lives==0):
  140. if (self.score<highscore):
  141. highscore = self.score
  142. frame.set_draw_handler(drawWelcome)
  143.  
  144. def drawScore(self,canvas):
  145. canvas.draw_text("Time: "+str(self.score), [10, 20], 18, "White")# player or what ever you intiate player oo
  146.  
  147. def drawLives(self,canvas):
  148. canvas.draw_text("lives: "+str(self.lives), [10, 40], 18, "White")
  149.  
  150. def check(self,canvas):
  151. self.update()
  152. self.died()
  153. self.draw(canvas)
  154.  
  155. def getPlayerPos(self):
  156. return self.pos
  157.  
  158. class Keyboard:
  159. def __init__(self):
  160. self.right = False
  161. self.left = False
  162. self.up = False
  163.  
  164. def keyDown(self, key):
  165. if key == simplegui.KEY_MAP['right']:
  166. self.right = True
  167. elif key == simplegui.KEY_MAP['left']:
  168. self.left = True
  169.  
  170. def keyUp(self, key):
  171. if key == simplegui.KEY_MAP['right']:
  172. self.right = False
  173. elif key == simplegui.KEY_MAP['left']:
  174. self.left = False
  175.  
  176. class Interaction:
  177. def __init__(self, character, keyboard):
  178. self.character = character
  179. self.keyboard = keyboard
  180.  
  181. def update(self):
  182. if self.keyboard.right:
  183. self.character.vel = Vector(4,0)
  184. elif self.keyboard.left:
  185. self.character.vel = Vector(-4,0)
  186. #if self.keyboard.up:
  187. # self.character.vel = #need to do
  188.  
  189. class Enemy:
  190. def __init__(self, pos):
  191. self.pos = pos
  192. self.vel = Vector(0,0)
  193. self.rad=40
  194. self.image = simplegui.load_image('https://raw.githubusercontent.com/0xForge/GameDevUni35/master/fb6e7c32-f658-4776-bc35-2a8a2f8aeb07%20(1).jpeg?token=AVJ2jGJTIWfJ37O2p2tpySSEFIQ44Oxnks5cllfzwA%3D%3D')#
  195. self.width = self.image.get_width()
  196. self.height = self.image.get_height()
  197. self.columns = 11
  198. self.rows = 4
  199. self.frameSize = (self.width // self.columns, self.height // self.rows)
  200. self.frameCentre = (self.frameSize[0]/2, self.frameSize[1]/2)
  201.  
  202. def getPos(self):
  203. return self.pos
  204.  
  205. def draw(self, canvas):
  206. canvas.draw_circle((self.pos.x, self.pos.y),self.rad,1,'Orange','Orange')
  207.  
  208. def update(self, character):
  209. if self.pos.getP() < character.pos.getP():
  210. self.vel = Vector(1,0)
  211. elif self.pos.getP() > character.pos.getP():
  212. self.vel = Vector(-1,0)
  213. self.pos.add(self.vel)
  214.  
  215. class CollsionsPlayerEnemey():
  216. def __inint__(player,enemey):
  217. self.player = player
  218. self.enemey = enemey
  219.  
  220. def playerDistance(self):
  221. playerDistance = self.player.getPos - self.enemey.getPos.length()#dont know what .length
  222. return playerDistance
  223.  
  224. def enemeyColission(self):
  225. if self.playerDistance()< 20:#20 is collision distance
  226. self.player.reduceLives()
  227.  
  228. def update(self):
  229. self.enemeyColission()
  230.  
  231. class mainMenu:
  232. def quitButton(self):
  233. exit()
  234.  
  235. #Changes all the variables in relation to the classic game mode
  236. def playClassicMode(self):
  237. global attempts
  238. global background_colour
  239. global platform_colour
  240. global enemy_damage
  241. global enemy_speed
  242.  
  243. background_colour = 'blue'
  244. platform_colour = 'cyan'
  245. enemy_damage = 1
  246. enemy_speed = 1
  247. attempts += 1
  248.  
  249. print("playing classic gamemode...")
  250. Game()
  251.  
  252. #Changes all the variables in relation to the hard game mode
  253. def playHardMode(self):
  254. global attempts
  255. global background_colour
  256. global platform_colour
  257. global enemy_damage
  258. global enemy_speed
  259.  
  260. background_colour = 'red'
  261. platform_colour = 'pink'
  262. enemy_damage = 2
  263. enemy_speed = 2
  264. attempts += 1
  265. print("playing hard gamemode...")
  266. Game()
  267.  
  268. def mainMenu(self):
  269. frame.set_draw_handler(self.drawMenu)
  270. frame.add_button("Classic", self.playClassicMode, 100)
  271. frame.add_button("Hard", self.playHardMode, 100)
  272. frame.add_button("Quit", self.quitButton, 100)
  273.  
  274. #Handler to draw menu screen
  275. def drawMenu(self,canvas):
  276. canvas.draw_text("Main Menu", [380, 100], 48, "Blue")
  277. canvas.draw_text("Best Time: " + str(highscore), [400, 200], 32, "White")
  278. canvas.draw_text("Attempts: "+str(attempts) , [410, 250], 32, "White")
  279. canvas.draw_text("How To Play:", [400, 400], 32, "Red")
  280. canvas.draw_text("The goal of Oblong is to traverse the platfroms unt- ", [250, 430], 24, "Orange")
  281. canvas.draw_text("ill you reach the top of the screen. You will have", [250, 450], 24, "Orange")
  282. canvas.draw_text("to dodge many hostiles and projectiles. You control", [250, 470], 24, "Orange")
  283. canvas.draw_text("the blue Oblong using the arrow keys to move up,", [250, 490], 24, "Orange")
  284. canvas.draw_text("left and right.", [400, 520], 24, "Orange")
  285.  
  286. # Handler to draw welcome screen
  287. def drawWelcome(self, canvas):
  288. global count
  289. canvas.draw_text("Welcome To...", [360,200], 48, "Blue")
  290. canvas.draw_text("Oblong!", [420,300], 48, "Blue")
  291. frame.set_canvas_background('Black')
  292. #canvas.draw_image(image, , , ,)#set a background image#add the sprite/ have animation of it jumping
  293. if(count > 300):# displays welcome for 5 seconds
  294. self.mainMenu()
  295. count += 1
  296.  
  297. class Game:
  298. def __init__(self):
  299. #self.frame = simplegui.create_frame("Platforms", CANVAS_WIDTH, CANVAS_HEIGHT)
  300.  
  301. self.platform_list = [Platform(idx * PLATFORM_SPACING) for idx in range(1, NUM_PLAT)]
  302. #self.frame.start()
  303.  
  304. self.kbd = Keyboard()
  305. self.player = Character()
  306. self.inter = Interaction(self.player, self.kbd)
  307. self.enemyOne = Enemy(Vector(CANVAS_WIDTH/4,CANVAS_HEIGHT-20))#enemey doesnt spawn
  308. frame.set_draw_handler(self.draw)
  309. frame.set_keyup_handler(self.kbd.keyUp)
  310. frame.set_keydown_handler(self.kbd.keyDown)
  311.  
  312. def start_game(self):
  313. frame.set_draw_handler(drawGame)
  314. self.platform_list = [Platform(idx * PLATFORM_SPACING) for idx in range(0, NUM_PLAT)]
  315.  
  316. def draw(self, canvas):
  317. global count
  318.  
  319. frame.set_canvas_background(background_colour)
  320.  
  321. canvas.draw_line((0, CANVAS_HEIGHT), (CANVAS_WIDTH, CANVAS_HEIGHT), 10, platform_colour)
  322.  
  323. for plat_index in range(0, NUM_PLAT):
  324. if plat_index < NUM_PLAT-1:
  325. self.platform_list[plat_index].draw_platform(canvas, self)
  326.  
  327. self.player.check(canvas)
  328. self.inter.update()
  329. #at end
  330. count += 1# only need once
  331.  
  332. # Create a frame and assign callbacks to event handlers
  333.  
  334. mainMenu = mainMenu()
  335.  
  336. frame = simplegui.create_frame("Oblong", CANVAS_WIDTH, CANVAS_HEIGHT)
  337.  
  338. frame.set_draw_handler(mainMenu.drawWelcome)
  339.  
  340. # Start the frame animation
  341. frame.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement