Escape A sticky man adventure using TKINTER python

  • Slides: 9
Download presentation
Escape A sticky man adventure using TKINTER python module By: Channing Burgess

Escape A sticky man adventure using TKINTER python module By: Channing Burgess

How to use the game! • To use the game. Use the LEFT and

How to use the game! • To use the game. Use the LEFT and RIGHT arrow keys to move. PRESS SPACE to jump. Try using all the space on each platform to gain momentum and time your jumps just right to be successful in getting to the ship!

1. Modify game window size and canvas layout 1. Change TK() tkinter call to

1. Modify game window size and canvas layout 1. Change TK() tkinter call to toplevel to run over top of the clock 2. Change the title 3. Lines 5, 8, 9 changes the size of the canvas and window size 4. Lines 15, 25. Originally it the canvas was made by two nested for loops. I took it out of the nested loop to have six different fill options the highlighted numbers are the order of each fill method form top to bottom self. tk = Toplevel() 2. self. tk. title("Mr. Sticky Man -----Episode 1 -----Mission: Reach the crew at the crashed ship!----" ) 3. self. tk. resizable(0, 0) 4. self. tk. wm_attributes("-topmost", 1) 5. self. canvas = Canvas(self. tk, width=900, height=600, highlightthickness=0) 6. self. canvas. pack() 7. self. tk. update() 8. self. canvas_height = 600 9. self. canvas_width = 900 10. self. bg = Photo. Image(file="background. gif") 11. self. bh = Photo. Image(file="background 1. gif") 12. w = self. bg. width() 13. h = self. bg. height() 14. for x in range(0, 9): 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. self. canvas. create_image(x * w, 0 * h, image=self. bh, anchor='nw') for x in range(0, 9): self. canvas. create_image(x * w , 1 * h, image=self. bg, anchor='nw') for x in range(0, 9): self. canvas. create_image(x * w, 2 * h, image=self. bh, anchor='nw') for x in range(0, 9): self. canvas. create_image(x * w, 3 * h, image=self. bg, anchor='nw') for x in range(0, 9): self. canvas. create_image(x * w, 4 * h, image=self. bh, anchor='nw') for x in range(0, 9): self. canvas. create_image(x * w, 5 * h, image=self. bg, anchor='nw')

Change sprite jump size 1. Very simply, just made the sprite jump height a

Change sprite jump size 1. Very simply, just made the sprite jump height a little lower to make the game seem bigger 1. def jump(self, evt): 2. if self. y == 0: 3. self. y = -3 4. self. jump_count = 0

Add platform layout 1. I deleted the old layout from sitckyman and added 43

Add platform layout 1. I deleted the old layout from sitckyman and added 43 platforms by hard coding.

1. 2. Added a Timer 1. Implemented a function with simple if else statement

1. 2. Added a Timer 1. Implemented a function with simple if else statement with centiseconds, and minutes. Then using tkinter method of tk. Tk() it packs it into its own window using pattern. format to keep the pattern the same. A lot of help from online forums. 2. The call of this function is in the same place as updating the sprites movement. def update_time. Text(): if (state): 3. #Always true gate 4. global timer 5. #centiseconds plus one 6. timer[2] += 1 7. if (timer[2] >= 100): 8. #seconds plus one 9. timer[2] = 0 10. timer[1] += 1 11. if (timer[1] >= 60): 12. #minutes plus one 13. timer[0] += 1 14. timer[1] = 0 15. #tkinter function 16. time. String = pattern. format(timer[0], timer[1], timer[2]) 17. 18. time. Text. configure(text=time. String) root. after(100000, update_time. Text ) 19. state = True 20. root = tk. Tk() 21. timer = [0, 0, 0] 22. pattern = '{0: 02 d}: {1: 02 d}: {2: 02 d}' 23. #Makes the window 24. time. Text = tk. Label(root, text="00: 00", font=("Helvetica", 50)) 25. #packs it in the window 26. time. Text. pack()

Animation Configuration 1. Lines 1 -5 is one of the 6 animation images that

Animation Configuration 1. Lines 1 -5 is one of the 6 animation images that seen here, show I configured them bloc 2. Lines 1 -11 are the function I made to keep the configured blocks in the canvas window 1. 2. 3. 4. 5. self. bar_imagefile 1 = Photo. Image(file="background. gif") 1. 2. 3. 4. 5. 6. def animateblocks(self): 7. 8. 9. 10. 11. self. bar_x = 100 self. bar_y = 0 self. bar_speed = +2 self. bar_image 1 = game. canvas. create_image(self. bar_x, self. bar_y, image=self. bar_imagefile 1, anchor='nw‘) self. bar_x = self. bar_x + self. bar_speed if self. bar_x < 0: self. bar_speed = +2 elif self. bar_x > 900: self. bar_speed= -2 self. bar_x 2 = self. bar_x 2 + self. bar_speed 2 if self. bar_x 2 < 0: self. bar_speed 2 = +2 elif self. bar_x 2 > 900: self. bar_speed 2 = -2

1. self. animateblocks() 2. Animation 1. Underneath the class that animates the sprite I

1. self. animateblocks() 2. Animation 1. Underneath the class that animates the sprite I call my animate blocks function. 2. Lines 5 -15 move my images using TKINTER method canvas. move taking in the image and x, y movement speed. 3. #Image 1 move 4. #image 5. self. game. canvas. move(self. bar_image, self. bar_speed, 0) 6. #Image 2 move 7. self. game. canvas. move(self. bar_image 2, self. bar_speed 2, 0) 8. #Image 3 move 9. self. game. canvas. move(self. bar_image 3, self. bar_speed, 0) 10. #Image 4 move 11. self. game. canvas. move(self. bar_image 4, self. bar_speed 2, 0) 12. #Image 5 move 13. self. game. canvas. move(self. bar_image 5, self. bar_speed, 0) 14. #Image 6 move 15. self. game. canvas. move(self. bar_image 1, self. bar_speed 2, 0) #x #y

Conclusion 1. I learned a lot by using tkinter. I wish I had used

Conclusion 1. I learned a lot by using tkinter. I wish I had used pygame instead because of it’s limited abilities and simple class structure. I feel as though I would be better at class stuctures that way. However, I did gain a lot by learning individual problem solving having to look up and study each tkinter built in method. 2. In the future I would like to set the clock and the canvas in a frame and add a high score keeper in the frame as well. 3. Thank you Dr. Hua for all of your help!