Skip to content

Commit

Permalink
removed unused variables
Browse files Browse the repository at this point in the history
  • Loading branch information
1024Adam committed Jul 6, 2022
1 parent eeca29e commit 8fa6543
Showing 1 changed file with 177 additions and 1 deletion.
178 changes: 177 additions & 1 deletion infinite_maze/infinite_maze.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from Game import Game
from Line import Line

DO_NOTHING = 0
RIGHT = 1
LEFT = 2
UP = 3
DOWN = 4

def maze():
# Contains All Game Stats/Config
game = Game()
Expand All @@ -16,7 +22,6 @@ def maze():
lines = Line.generateMaze(game, 15, 20)

game.getClock().reset()
millis = 0
keys = pygame.key.get_pressed()
while (game.isPlaying()):
while (game.isActive()):
Expand Down Expand Up @@ -190,3 +195,174 @@ def maze():

game.cleanup()
exit(0)

def controlled_run(wrapper, counter):
# Contains All Game Stats/Config
game = Game()

# Player Stats/Position/Details
player = Player(80, 223)

# Maze Details
lines = Line.generateMaze(game, 15, 20)

game.getClock().reset()
keys = pygame.key.get_pressed()
action = None
while (game.isPlaying()):
while (game.isActive()):
game.updateScreen(player, lines)
prevKeys = keys
keys = pygame.key.get_pressed()

if (not game.isPaused()):
values = {}
scoreIncreased = False

# Arrow Move Events
if (keys[pygame.K_RIGHT] or keys[pygame.K_d]):
action = RIGHT
elif (keys[pygame.K_LEFT] or keys[pygame.K_a]):
action = LEFT
elif (keys[pygame.K_DOWN] or keys[pygame.K_s]):
action = DOWN
elif (keys[pygame.K_UP] or keys[pygame.K_w]):
action = UP
elif action is None:
action = DO_NOTHING

values['action'] = action

if action == RIGHT:
blocked = False
for line in lines:
if line.getIsHorizontal():
blocked = blocked or (
player.getY() <= line.getYStart() and
player.getY() + player.getHeight() >= line.getYStart() and
player.getX() + player.getWidth() + player.getSpeed() == line.getXStart()
)
else: # vertical line
blocked = blocked or (
player.getX() + player.getWidth() <= line.getXStart() and
player.getX() + player.getWidth() + player.getSpeed() >= line.getXStart() and
(
(player.getY() >= line.getYStart() and player.getY() <= line.getYEnd()) or
(player.getY() + player.getHeight() >= line.getYStart() and player.getY() + player.getHeight() <= line.getYEnd())
)
)
if (not blocked):
player.moveX(player.getSpeed())
game.incrementScore()
scoreIncreased = True
elif action == LEFT:
blocked = False
for line in lines:
if line.getIsHorizontal():
blocked = blocked or (
player.getY() <= line.getYStart() and
player.getY() + player.getHeight() >= line.getYStart() and
player.getX() - player.getSpeed() == line.getXEnd()
)
else: # vertical line
blocked = blocked or (
player.getX() >= line.getXEnd() and
player.getX() - player.getSpeed() <= line.getXEnd() and
(
(player.getY() >= line.getYStart() and player.getY() <= line.getYEnd()) or
(player.getY() + player.getHeight() >= line.getYStart() and player.getY() + player.getHeight() <= line.getYEnd())
)
)
if (not blocked):
player.moveX(-player.getSpeed())
game.decrementScore()
if action == DOWN:
blocked = False
for line in lines:
if line.getIsHorizontal():
blocked = blocked or (
player.getY() + player.getHeight() <= line.getYStart() and
player.getY() + player.getHeight() + player.getSpeed() >= line.getYStart() and
(
(player.getX() >= line.getXStart() and player.getX() <= line.getXEnd()) or
(player.getX() + player.getWidth() >= line.getXStart() and player.getX() + player.getWidth() <= line.getXEnd())
)
)
else: # vertical line
blocked = blocked or (
player.getX() <= line.getXStart() and
player.getX() + player.getWidth() >= line.getXStart() and
player.getY() + player.getHeight() + player.getSpeed() == line.getYStart()
)
if (not blocked):
player.moveY(player.getSpeed())
elif action == UP:
blocked = False
for line in lines:
if line.getIsHorizontal():
blocked = blocked or (
player.getY() >= line.getYStart() and
player.getY() - player.getSpeed() <= line.getYStart() and
(
(player.getX() >= line.getXStart() and player.getX() <= line.getXEnd()) or
(player.getX() + player.getWidth() >= line.getXStart() and player.getX() + player.getWidth() <= line.getXEnd())
)
)
else: # vertical line
blocked = blocked or (
player.getX() <= line.getXStart() and
player.getX() + player.getWidth() >= line.getXStart() and
player.getY() - player.getSpeed() == line.getYEnd()
)
if (not blocked):
player.moveY(-player.getSpeed())

values['score_increased'] = scoreIncreased

# Process game pace adjustments
if game.getClock().getTicks() % 10 == 0:
player.setX(player.getX() - game.getPace())
for line in lines:
line.setXStart(line.getXStart() - game.getPace())
line.setXEnd(line.getXEnd() - game.getPace())

# Position Adjustments (to prevent screen overflow)
if (player.getX() < game.X_MIN):
game.end()
if (player.getX() > game.X_MAX):
player.setX(game.X_MAX)
for line in lines:
line.setXStart(line.getXStart() - player.getSpeed())
line.setXEnd(line.getXEnd() - player.getSpeed())
player.setY(max(player.getY(), game.Y_MIN))
player.setY(min(player.getY(), game.Y_MAX))

# Reposition lines that have been passed
xMax = Line.getXMax(lines)
for line in lines:
start = line.getXStart()
end = line.getXEnd()
if (start < 80):
line.setXStart(xMax)
if (start == end):
line.setXEnd(xMax)
else:
line.setXEnd(xMax + 22)

# Process FPS
processTime = int(game.getClock().getMillis() - game.getClock().getPrevMillis())
if (processTime <= 16):
time.delay(16 - processTime)

closestLine = 1000
for line in lines:
if player.getX() < line.getXStart() and line.getXStart() < closestLine:
closestLine = line.getXStart()
values['closest_line'] = closestLine

response = wrapper.control(values)
action = response

game.quit()

wrapper.gameover(game.getScore())

0 comments on commit 8fa6543

Please sign in to comment.