Untitled
unknown
python
2 years ago
7.7 kB
12
Indexable
import pygame
from pygame.constants import K_w, K_SPACE
from pygame.constants import K_a
from pygame.constants import K_s
from pygame.constants import K_d
from pygame.constants import K_o
import pygame.rect
import random
import sys
import time
pygame.init()
DISPLAYSURF = pygame.display.set_mode((750, 550))
pygame.display.set_caption("Submarine game")
shieldangle = "behind"
currentposition = "Outersea"
blockcount = 0
oxygen = 100
Breach = True
hit = False
tpassed = 0
move = False
goal = 100 - blockcount
radar = pygame.image.load("Assets//radar.png")
enemy = pygame.image.load("Assets//enemy.png")
enemy = pygame.image
exterior = pygame.image.load("Assets//outsidecamera.jpg")
interior_top = pygame.image.load("Assets//topinterior.jpg")
interior_behind = pygame.image.load("Assets//behindinterior.jpg")
interior_below = pygame.image.load("Assets//belowinterior.jpg")
running = False
Close = 20
Attack = 40
Dist = 60
shield = pygame.image.load("Assets//shield-removebg-preview.png")
def display_position(currentposition):
if currentposition == hitbehind or currentposition == hittop or currentposition == hitfront or currentposition == hitbelow:
DISPLAYSURF.fill(100,100,100)
else:
DISPLAYSURF.blit(radar,(125,125))
if currentposition == behinddistant:
DISPLAYSURF.blit(enemy,(125-Dist,125))
elif currentposition == behindclose:
DISPLAYSURF.blit(enemy,(125-Close,125))
elif currentposition == behindattack:
DISPLAYSURF.blit(enemy,(125-Attack,125))
elif currentposition == topdistant:
DISPLAYSURF.blit(enemy,(125,125 + Dist))
elif currentposition == topclose:
DISPLAYSURF.blit(enemy,(125,125 + Close))
elif currentposition == topattack:
DISPLAYSURF.blit(enemy,(125,125 + Attack))
elif currentposition == frontdistant:
DISPLAYSURF.blit(enemy,(125+Dist,125))
elif currentposition == frontclose:
DISPLAYSURF.blit(enemy,(125+Close,125))
elif currentposition == frontattack:
DISPLAYSURF.blit(enemy,(125+Attack,125))
elif currentposition == belowdistant:
DISPLAYSURF.blit(enemy,(125,125-Dist))
elif currentposition == belowclose:
DISPLAYSURF.blit(enemy,(125,125-CLose))
elif currentposition == belowdistant:
DISPLAYSURF.blit(enemy,(125,125-Attack))
pygame.display.update
def shield_controls():
keys = pygame.key.get_pressed()
if keys[K_a]:
shieldangle = "behind"
move_position(currentposition)
DISPLAYSURF.blit(shield,(125,125))
elif keys[K_d]:
shieldangle = "front"
move_position(currentposition)
shield = pygame.transform.rotate(shield,(180))
DISPLAYSURF.blit(shield,(125,125))
elif keys[K_w]:
shieldangle = "top"
move_position(currentposition)
shield = pygame.transform.rotate(shield,(90))
DISPLAYSURF.blit(shield,(125,125))
elif keys[K_s]:
shieldangle = "below"
move_position(currentposition)
shield = pygame.transform.rotate(shield,(270))
DISPLAYSURF.blit(shield,(125,125))
pygame.display.update
pygame.event.pump()
shield = pygame.image.load("Assets//shield-removebg-preview.png")
def draw_start_menu():
DISPLAYSURF.fill((50, 50, 250))
font = pygame.font.SysFont('arial', 40)
Title = font.render('Submarine security game', True, (255, 255, 255))
start_button = font.render('Start', True, (255, 255, 255))
GameOver = font.render('game over',True,(255,0,0))
DISPLAYSURF.blit(Title,(375 - Title.get_width()/2, 425 - Title.get_height()*7))
DISPLAYSURF.blit(start_button, (375 - 255 / 4, 425 - 255 ))
pygame.display.update()
def start_pressed():
currentposition = "Outersea"
blockcount = 0
shieldangle = "behind"
oxygen = 100
Breach = False
tpassed = pygame.time.get_ticks()
running = True
DISPLAYSURF.fill((100,100,100))
DISPLAYSURF.blit(radar,(125,125))
DISPLAYSURF.blit(shield,(150,70))
pygame.display.update
pygame.transform.rotate(shield,(180))
def moveposition(currentposition):
text_file = open("Mapping_layout/" + currentposition + ".txt", "r")
x = random.randrange(0, 75)
if x <= 25:
L1 = text_file.readline(1)
if L1 == "hitbehind" or L1 == "hittop" or L1 == "hitbehind" or L1 == "hitbelow":
hit = True
else:
currentposition = text_file.readline(1)
print(currentposition)
display_position(currentposition)
elif x > 25 and x <= 50:
currentposition = text_file.readline(2)
print(currentposition)
display_position(currentposition)
elif x > 50 and x <= 65:
currentposition = text_file.readline(3)
print(currentposition)
display_position(currentposition)
elif x > 65:
currentposition = text_file.readline(4)
print(currentposition)
display_position(currentposition)
def check_hit():
while currentposition == "hitbehind":
if shieldangle == "behind":
blockcount =+ 1000
currentposition = "Outerseas"
DISPLAYSURF.blit(exterior,(125,125))
pygame.time.wait(5000)
display_position(currentposition)
else:
y = random.randint(10, 20)
oxygen = oxygen - y
currentposition = "behindclose"
DISPLAYSURF.blit(interior_behind,(125,125))
pygame.time.wait(5000)
display_position(currentposition)
while currentposition == "hittop":
if shieldangle == "top":
blockcount =+ 1000
currentposition = "Outerseas"
DISPLAYSURF.blit(exterior,(125,125))
pygame.time.wait(5000)
display_position(currentposition)
else:
y = random.randint(10, 20)
oxygen = oxygen - y
currentposition = "topclose"
DISPLAYSURF.blit(interior_top,(125,125))
pygame.time.wait(5000)
display_position(currentposition)
while currentposition == "hitbelow":
if shieldangle == "below":
blockcount =+ 1000
currentposition = "Outerseas"
DISPLAYSURF.blit(exterior,(125,125))
pygame.time.wait(5000)
display_position(currentposition)
else:
y = random.randint(10, 20)
oxygen = oxygen - y
currentposition = "belowclose"
DISPLAYSURF.blit(interior_below,(125,125))
pygame.time.wait(5000)
display_position(currentposition)
while currentposition == "hitfront":
if shieldangle == "front":
blockcount =+ 1000
currentposition = "Outerseas"
DISPLAYSURF.blit(exterior,(125,125))
pygame.time.wait(5000)
display_position(currentposition)
else:
y = random.randint(10, 20)
oxygen = oxygen - y
currentposition = "frontclose"
DISPLAYSURF.blit(exterior,(125,125))
pygame.time.wait(5000)
display_position(currentposition)
while True:
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
if not running:
draw_start_menu()
keys = pygame.key.get_pressed()
if keys[K_SPACE]:
running = True
start_pressed()
shield_controls()
keys = pygame.key.get_pressed()
if keys[K_SPACE]:
running = True
start_pressed()
while running == True:
shield_controls()
pygame.event.pump()
if hit == True:
check_hit()
if oxygen <= 0:
breach = true
DISPLAYSURF.fill(0,0,0)
DISPLAYSURF.blit(GameOver,(125,125))
if keys[K_o]:
font2 = pygame.font.SysFont('Arial', 14)
oxygenread = "Current oxygen level is: " + str(oxygen)
oxygen_level = font2.render(oxygenread,True,(0,0,255))
DISPLAYSURF.blit(oxygen_level, (20,0))Editor is loading...
Leave a Comment