Bladeren bron

Added speed control to LightCycle object. This helped in the performance degradation by increasing space between LightRibbon vertices (i.e. makes it look faster but with less information).

Bryan Allred 14 jaren geleden
bovenliggende
commit
8bb9afc6e1
6 gewijzigde bestanden met toevoegingen van 26 en 9 verwijderingen
  1. 5 0
      src/pytron/GameGrid.py
  2. BIN
      src/pytron/GameGrid.pyc
  3. 9 5
      src/pytron/LightCycle.py
  4. BIN
      src/pytron/LightCycle.pyc
  5. 1 1
      src/pytron/PyTron.py
  6. 11 3
      src/pytron/README.txt

+ 5 - 0
src/pytron/GameGrid.py

93
        # Need to do something cool so there can be more
93
        # Need to do something cool so there can be more
94
        # than just two programs playing (possibly use Id).
94
        # than just two programs playing (possibly use Id).
95
        
95
        
96
        # TODO: Add pause handling (i.e. K_SPACE).
97
        # TODO: Add additional exit handling (i.e. K_ESCAPE).
98
        # TODO: Add speed handling per program.
99
        
96
        for e in Events:
100
        for e in Events:
97
            if e.type == QUIT:
101
            if e.type == QUIT:
98
                self._Programs = []
102
                self._Programs = []
103
                #pygame.quit()
99
            elif e.type == KEYDOWN:
104
            elif e.type == KEYDOWN:
100
                # Program one navigation.
105
                # Program one navigation.
101
                if e.key == K_a:
106
                if e.key == K_a:

BIN
src/pytron/GameGrid.pyc


+ 9 - 5
src/pytron/LightCycle.py

13
        self.RibbonColor = Color
13
        self.RibbonColor = Color
14
        self.Direction = Direction
14
        self.Direction = Direction
15
        self._LightRibbon = [(StartX, StartY)]
15
        self._LightRibbon = [(StartX, StartY)]
16
        self._Speed = 4
16
    
17
    
17
    def ChangeDirection(self, NewHeading):
18
    def ChangeDirection(self, NewHeading):
18
        '''
19
        '''
68
        
69
        
69
        # Determine which direction to move.
70
        # Determine which direction to move.
70
        if self.Direction == Heading.NORTH:
71
        if self.Direction == Heading.NORTH:
71
            self._LightRibbon.append((currentPosition[0], currentPosition[1] - 1))
72
            self._LightRibbon.append((currentPosition[0], currentPosition[1] - self._Speed))
72
        elif self.Direction == Heading.EAST:
73
        elif self.Direction == Heading.EAST:
73
            self._LightRibbon.append((currentPosition[0] + 1, currentPosition[1]))
74
            self._LightRibbon.append((currentPosition[0] + self._Speed, currentPosition[1]))
74
        elif self.Direction == Heading.SOUTH:
75
        elif self.Direction == Heading.SOUTH:
75
            self._LightRibbon.append((currentPosition[0], currentPosition[1] + 1))
76
            self._LightRibbon.append((currentPosition[0], currentPosition[1] + self._Speed))
76
        else:
77
        else:
77
            self._LightRibbon.append((currentPosition[0] - 1, currentPosition[1]))
78
            self._LightRibbon.append((currentPosition[0] - self._Speed, currentPosition[1]))
78
        
79
        
79
        # Return the light ribbon.
80
        # Return the light ribbon.
80
        return self._LightRibbon
81
        return self._LightRibbon
82
    
83
    def SetSpeed(self, NewSpeed):
84
        self._Speed = NewSpeed

BIN
src/pytron/LightCycle.pyc


+ 1 - 1
src/pytron/PyTron.py

8
# Build the game grid.
8
# Build the game grid.
9
#
9
#
10
10
11
gameGrid = GameGrid(250, 250)
11
gameGrid = GameGrid(640, 480)
12
gameGrid.SetFrameRate(30)
12
gameGrid.SetFrameRate(30)
13
13
14
#
14
#

+ 11 - 3
src/pytron/README.txt

36
36
37
Issues:
37
Issues:
38
38
39
[Unresolved] Once each programs light ribbon has reach a large number the redrawing of the screen
39
[WorksForMe]
40
Problem: Once each programs light ribbon has reach a large number the redrawing of the screen
40
eats up resources. This causes a delay in reaction time and makes the game appear sluggish. Possibly
41
eats up resources. This causes a delay in reaction time and makes the game appear sluggish. Possibly
41
need to implement some sort of caching or only draw the new portions of the ribbon.
42
need to implement some sort of caching or only draw the new portions of the ribbon.
42
43
43
[Unresolved] Never got around to implementing different light cycle colors.
44
Change: Added speed property to LightCycle as well as SetSpeed() method to
45
adjust it. This may not have "solved" the problem per se, but it lightened
46
the amount of items in the lists which may have been causing the performance
47
degradation.
44
48
45
[Unresolved] Sound.
49
[Unresolved]
50
Problem: Never got around to implementing different light cycle colors.
51
52
[Unresolved]
53
Problem: Sound.