Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.04 KB | None | 0 0
  1. humanXVelocity = 0
  2. humanYVelocity = 0
  3. humanX = 200
  4. humanY = 200
  5. humanState = "gaar"
  6. lives = 1
  7. rectangelVelocity = 3
  8. rectangelX = 400
  9. rectangelY = 100
  10. rectangel2X = 500
  11. rectangel3X = 600
  12. rectangel2Y = 300
  13. rectangel3Y = 200
  14. score = 0
  15. upPressed = False
  16. rightPressed = False
  17. leftPressed = False
  18. downPressed = False
  19.  
  20.  
  21. def difficulty():
  22. global rectangelVelocity
  23. rectangelVelocity = rectangelVelocity + 0.001
  24. text(str(rectangelVelocity), 380, 20)
  25.  
  26. def highScore():
  27. global score
  28. if lives > 0:
  29. if frameCount % 60 == 0:
  30. score = score + 1
  31. text("highscore" + str(score), 20, 20)
  32.  
  33. def playerWallCollission():
  34. global lives, rectangelX, rectangelY, rectangel2X, rectangel2Y, rectangel3X, rectangel3Y
  35. if humanX > rectangelX and humanX < rectangelX + 20 and humanY > rectangelY and humanY < rectangelY + 70:
  36. lives = 0
  37. if humanX > rectangel2X and humanX < rectangel2X + 20 and humanY > rectangel2Y and humanY < rectangel2Y + 70:
  38. lives = 0
  39. if humanX > rectangel3X and humanX < rectangel3X + 20 and humanY > rectangel3Y and humanY < rectangel3Y + 70:
  40. lives = 0
  41.  
  42.  
  43. def gameOver():
  44. if lives == 0:
  45. fill(0,0,0)
  46. rect(0, 0, 400, 400)
  47. fill(255, 0, 0)
  48. text("du har tabt..... din kaempe taber", 150 ,200)
  49. text("press 'R' for restart", 150, 220)
  50.  
  51.  
  52. def drawRectangel3(X):
  53. global rectangel3X
  54. global rectangel3Y
  55. rect(X, rectangel3Y, 20, 70)
  56. if X <= 0:
  57. rectangel3X = 400
  58. rectangel3Y = random(100, 334)
  59. rectangel3X = rectangel3X - rectangelVelocity
  60.  
  61.  
  62. def drawRectangel2(X):
  63. global rectangel2X
  64. global rectangel2Y
  65. rect(X, rectangel2Y, 20, 70)
  66. if X <= 0:
  67. rectangel2X = 400
  68. rectangel2Y = random(100, 334)
  69. rectangel2X = rectangel2X - rectangelVelocity
  70.  
  71. def drawRectangel(X):
  72. global rectangelX
  73. global rectangelY
  74. rect(X, rectangelY, 20, 70)
  75. if X <= 0:
  76. rectangelX = 400
  77. rectangelY = random(100, 334)
  78. rectangelX = rectangelX - rectangelVelocity
  79.  
  80. def drawScene():
  81. background(255,255,255)
  82. noStroke()
  83. fill(0, 100, 0)
  84. rect(0, 350, 400, 50)
  85.  
  86. def drawMan(x,y):
  87. noStroke()
  88. fill(0, 0, 0)
  89. ellipse(x, y-2, 10, 10)
  90. stroke(0,0,0)
  91. strokeWeight(2)
  92. line(x,y-7, x, y+8)
  93. line(x, y+8, x+5, y+15)
  94. line(x, y+8, x-5, y+15)
  95. line(x, y, x+7, y+7)
  96. line(x, y, x-7, y+7)
  97.  
  98. def motion():
  99. global humanXVelocity
  100. global humanYVelocity
  101. global upPressed
  102. global rightPressed
  103. global leftPressed
  104. global humanState
  105. if upPressed:
  106. if humanState == "gaar":
  107. humanYVelocity = 12
  108. if humanState == "gaar":
  109. humanState = "hopper"
  110. #left
  111. if leftPressed:
  112. humanXVelocity = humanXVelocity - 0.8
  113. #right
  114. if rightPressed:
  115. humanXVelocity = humanXVelocity + 0.8
  116. if downPressed:
  117. humanYVelocity = humanYVelocity - 1
  118.  
  119.  
  120.  
  121.  
  122. def setup():
  123. size(400, 400)
  124.  
  125. def draw():
  126. global humanXVelocity, humanYVelocity, humanX, humanY
  127. global humanState
  128. # Friktion
  129. humanXVelocity = humanXVelocity * 0.91
  130.  
  131. # Bevæg mand
  132. humanX = humanX + humanXVelocity
  133. humanY = humanY - humanYVelocity
  134.  
  135. if humanX >= 399:
  136. humanX = 0
  137. if humanX <= 0:
  138. humanX = 400
  139.  
  140. # Landing efter hop
  141. if humanY >= 334:
  142. humanYVelocity = 0
  143. humanY = 334
  144. humanState = "gaar"
  145. else:
  146. # Tyngdekraft
  147. humanYVelocity = humanYVelocity - 0.45
  148.  
  149. motion()
  150. drawScene()
  151. drawMan(humanX, humanY)
  152. drawRectangel(rectangelX)
  153. drawRectangel2(rectangel2X)
  154. drawRectangel3(rectangel3X)
  155. playerWallCollission()
  156. gameOver()
  157. difficulty()
  158. highScore()
  159. print(lives)
  160.  
  161.  
  162.  
  163. def keyPressed():
  164. global humanXVelocity, humanYVelocity
  165. global humanState
  166. global lives
  167. global rectangelVelocity
  168. global score
  169. global rectangelX
  170. global rectangel2X
  171. global rectangel3X
  172. global humanX
  173. global upPressed
  174. global rightPressed
  175. global leftPressed
  176. global downPressed
  177. # hop
  178. if keyCode == UP:
  179. upPressed = True
  180. # Gå til venstre
  181. if keyCode == LEFT:
  182. leftPressed = True
  183. # Gå til højre
  184. if keyCode == RIGHT:
  185. rightPressed = True
  186. if key == "r":
  187. if lives == 0:
  188. lives = 1
  189. score = 0
  190. rectangelVelocity = 3
  191. rectangelX = 400
  192. rectangel2X = 500
  193. rectangel3X = 600
  194. humanX = 200
  195. if keyCode == DOWN:
  196. downPressed = True
  197.  
  198. def keyReleased():
  199. global upPressed
  200. global rightPressed
  201. global leftPressed
  202. global downPressed
  203. if keyCode == UP:
  204. upPressed = False
  205. if keyCode == RIGHT:
  206. rightPressed = False
  207. if keyCode == LEFT:
  208. leftPressed = False
  209. if keyCode == DOWN:
  210. downPressed = FalsehumanXVelocity = 0
  211. humanYVelocity = 0
  212. humanX = 200
  213. humanY = 200
  214. humanState = "gaar"
  215. lives = 1
  216. rectangelVelocity = 3
  217. rectangelX = 400
  218. rectangelY = 100
  219. rectangel2X = 500
  220. rectangel3X = 600
  221. rectangel2Y = 300
  222. rectangel3Y = 200
  223. score = 0
  224. upPressed = False
  225. rightPressed = False
  226. leftPressed = False
  227. downPressed = False
  228.  
  229.  
  230. def difficulty():
  231. global rectangelVelocity
  232. rectangelVelocity = rectangelVelocity + 0.001
  233. text(str(rectangelVelocity), 380, 20)
  234.  
  235. def highScore():
  236. global score
  237. if lives > 0:
  238. if frameCount % 60 == 0:
  239. score = score + 1
  240. text("highscore" + str(score), 20, 20)
  241.  
  242. def playerWallCollission():
  243. global lives, rectangelX, rectangelY, rectangel2X, rectangel2Y, rectangel3X, rectangel3Y
  244. if humanX > rectangelX and humanX < rectangelX + 20 and humanY > rectangelY and humanY < rectangelY + 70:
  245. lives = 0
  246. if humanX > rectangel2X and humanX < rectangel2X + 20 and humanY > rectangel2Y and humanY < rectangel2Y + 70:
  247. lives = 0
  248. if humanX > rectangel3X and humanX < rectangel3X + 20 and humanY > rectangel3Y and humanY < rectangel3Y + 70:
  249. lives = 0
  250.  
  251.  
  252. def gameOver():
  253. if lives == 0:
  254. fill(0,0,0)
  255. rect(0, 0, 400, 400)
  256. fill(255, 0, 0)
  257. text("du har tabt..... din kaempe taber", 150 ,200)
  258. text("press 'R' for restart", 150, 220)
  259.  
  260.  
  261. def drawRectangel3(X):
  262. global rectangel3X
  263. global rectangel3Y
  264. rect(X, rectangel3Y, 20, 70)
  265. if X <= 0:
  266. rectangel3X = 400
  267. rectangel3Y = random(100, 334)
  268. rectangel3X = rectangel3X - rectangelVelocity
  269.  
  270.  
  271. def drawRectangel2(X):
  272. global rectangel2X
  273. global rectangel2Y
  274. rect(X, rectangel2Y, 20, 70)
  275. if X <= 0:
  276. rectangel2X = 400
  277. rectangel2Y = random(100, 334)
  278. rectangel2X = rectangel2X - rectangelVelocity
  279.  
  280. def drawRectangel(X):
  281. global rectangelX
  282. global rectangelY
  283. rect(X, rectangelY, 20, 70)
  284. if X <= 0:
  285. rectangelX = 400
  286. rectangelY = random(100, 334)
  287. rectangelX = rectangelX - rectangelVelocity
  288.  
  289. def drawScene():
  290. background(255,255,255)
  291. noStroke()
  292. fill(0, 100, 0)
  293. rect(0, 350, 400, 50)
  294.  
  295. def drawMan(x,y):
  296. noStroke()
  297. fill(0, 0, 0)
  298. ellipse(x, y-2, 10, 10)
  299. stroke(0,0,0)
  300. strokeWeight(2)
  301. line(x,y-7, x, y+8)
  302. line(x, y+8, x+5, y+15)
  303. line(x, y+8, x-5, y+15)
  304. line(x, y, x+7, y+7)
  305. line(x, y, x-7, y+7)
  306.  
  307. def motion():
  308. global humanXVelocity
  309. global humanYVelocity
  310. global upPressed
  311. global rightPressed
  312. global leftPressed
  313. global humanState
  314. if upPressed:
  315. if humanState == "gaar":
  316. humanYVelocity = 12
  317. if humanState == "gaar":
  318. humanState = "hopper"
  319. #left
  320. if leftPressed:
  321. humanXVelocity = humanXVelocity - 0.8
  322. #right
  323. if rightPressed:
  324. humanXVelocity = humanXVelocity + 0.8
  325. if downPressed:
  326. humanYVelocity = humanYVelocity - 1
  327.  
  328.  
  329.  
  330.  
  331. def setup():
  332. size(400, 400)
  333.  
  334. def draw():
  335. global humanXVelocity, humanYVelocity, humanX, humanY
  336. global humanState
  337. # Friktion
  338. humanXVelocity = humanXVelocity * 0.91
  339.  
  340. # Bevæg mand
  341. humanX = humanX + humanXVelocity
  342. humanY = humanY - humanYVelocity
  343.  
  344. if humanX >= 399:
  345. humanX = 0
  346. if humanX <= 0:
  347. humanX = 400
  348.  
  349. # Landing efter hop
  350. if humanY >= 334:
  351. humanYVelocity = 0
  352. humanY = 334
  353. humanState = "gaar"
  354. else:
  355. # Tyngdekraft
  356. humanYVelocity = humanYVelocity - 0.45
  357.  
  358. motion()
  359. drawScene()
  360. drawMan(humanX, humanY)
  361. drawRectangel(rectangelX)
  362. drawRectangel2(rectangel2X)
  363. drawRectangel3(rectangel3X)
  364. playerWallCollission()
  365. gameOver()
  366. difficulty()
  367. highScore()
  368. print(lives)
  369.  
  370.  
  371.  
  372. def keyPressed():
  373. global humanXVelocity, humanYVelocity
  374. global humanState
  375. global lives
  376. global rectangelVelocity
  377. global score
  378. global rectangelX
  379. global rectangel2X
  380. global rectangel3X
  381. global humanX
  382. global upPressed
  383. global rightPressed
  384. global leftPressed
  385. global downPressed
  386. # hop
  387. if keyCode == UP:
  388. upPressed = True
  389. # Gå til venstre
  390. if keyCode == LEFT:
  391. leftPressed = True
  392. # Gå til højre
  393. if keyCode == RIGHT:
  394. rightPressed = True
  395. if key == "r":
  396. if lives == 0:
  397. lives = 1
  398. score = 0
  399. rectangelVelocity = 3
  400. rectangelX = 400
  401. rectangel2X = 500
  402. rectangel3X = 600
  403. humanX = 200
  404. if keyCode == DOWN:
  405. downPressed = True
  406.  
  407. def keyReleased():
  408. global upPressed
  409. global rightPressed
  410. global leftPressed
  411. global downPressed
  412. if keyCode == UP:
  413. upPressed = False
  414. if keyCode == RIGHT:
  415. rightPressed = False
  416. if keyCode == LEFT:
  417. leftPressed = False
  418. if keyCode == DOWN:
  419. downPressed = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement