Quellcode durchsuchen

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 vor 14 Jahren
Ursprung
Commit
8bb9afc6e1

+ 5 - 0
src/pytron/GameGrid.py

@ -93,9 +93,14 @@ class GameGrid:
93 93
        # Need to do something cool so there can be more
94 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 100
        for e in Events:
97 101
            if e.type == QUIT:
98 102
                self._Programs = []
103
                #pygame.quit()
99 104
            elif e.type == KEYDOWN:
100 105
                # Program one navigation.
101 106
                if e.key == K_a:

BIN
src/pytron/GameGrid.pyc


+ 9 - 5
src/pytron/LightCycle.py

@ -13,6 +13,7 @@ class LightCycle:
13 13
        self.RibbonColor = Color
14 14
        self.Direction = Direction
15 15
        self._LightRibbon = [(StartX, StartY)]
16
        self._Speed = 4
16 17
    
17 18
    def ChangeDirection(self, NewHeading):
18 19
        '''
@ -68,13 +69,16 @@ class LightCycle:
68 69
        
69 70
        # Determine which direction to move.
70 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 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 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 77
        else:
77
            self._LightRibbon.append((currentPosition[0] - 1, currentPosition[1]))
78
            self._LightRibbon.append((currentPosition[0] - self._Speed, currentPosition[1]))
78 79
        
79 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,7 +8,7 @@ from pytron.locals.Heading import Heading
8 8
# Build the game grid.
9 9
#
10 10
11
gameGrid = GameGrid(250, 250)
11
gameGrid = GameGrid(640, 480)
12 12
gameGrid.SetFrameRate(30)
13 13
14 14
#

+ 11 - 3
src/pytron/README.txt

@ -36,10 +36,18 @@ light cycle use the following keys:
36 36
37 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 41
eats up resources. This causes a delay in reaction time and makes the game appear sluggish. Possibly
41 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.