Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Napkin Platformer
#2
1. Load images only once.
napkin = [
    pygame.image.load('napkin.png').convert_alpha(),
    pygame.image.load('napkin2.png').convert_alpha(),
    pygame.image.load('napkin3.png').convert_alpha()]
2. Learn pygame.Rect. It has 2d math built into it.
class Player(object):
    def __init__(x, y, w, h):
        self.rect = pygame.Rect(x, y , w, h)

Do not double call pygame.display.update.
Only do it once.

clock.tick belongs in game loop.
It must happen every frame.

remove global walkcount from redrawGameWindow().

Since image just repeat. Do something like.
self.walk_right = [0, 1]
self.walk_left = [0, 2]
self.walk = 'idle'

# in Player draw.
if self.walk == 'idle':
    win.blit(napkin[0], self.rect) # (x, y)
elif self.walk == 'right':
    win.blit(napkin[self.walk_count], self.rect) # (x, y)
    self.walk_count = (self.walk_count + 1) % len(self.walk_right)
elif self.walk == 'left':
    win.blit(napkin[self.walk_count], self.rect) # (x, y)
    self.walk_count = (self.walk_count + 1) % len(self.walk_left)
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
Napkin Platformer - by abscorpy - Jan-24-2019, 10:24 PM
RE: Napkin Platformer - by Windspar - Jan-25-2019, 12:12 AM
RE: Napkin Platformer - by abscorpy - Jan-26-2019, 10:52 AM
RE: Napkin Platformer - by Windspar - Jan-26-2019, 03:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] platformer enemy animation Yegor123 3 2,115 May-03-2023, 08:42 AM
Last Post: Windspar
  Tkinter platformer game Linch1 1 5,283 Mar-10-2019, 03:17 AM
Last Post: Windspar
  platformer problem abscorpy 1 2,468 Dec-11-2018, 11:08 PM
Last Post: Windspar
  platformer problem abscorpy 4 3,712 Nov-27-2018, 08:46 PM
Last Post: nilamo
  Help On Platformer Spectroxis 2 12,580 Apr-27-2017, 09:56 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020