import pygame, random
image_path = '/data/data/com.devgmore.spacesturm/files/app/'
clock = pygame.time.Clock()
pygame.init()
screen = pygame.display.set_mode((604, 377))
pygame.display.set_caption("Space Sturm")
icon = pygame.image.load(image_path + 'Images/icon.png').convert_alpha()
pygame.display.set_icon(icon)
player_speed = 7
player_x = 150
player_y = 246
is_jump = False
jump_count = 8
bg_x = 0
gameplay = True
restart_x = 230
restart_y = 250
ghost_timer = pygame.USEREVENT + 1
ghost_timer1 = random.randint(500, 2500)
pygame.time.set_timer(ghost_timer, ghost_timer1)
label = pygame.font.Font(image_path + 'Fonts/Font.ttf', 40)
label_menu = pygame.font.Font(image_path + 'Fonts/Font.ttf', 60)
play_render = label.render('Play', False, 'Green')
quit_render = label.render('Quit', False, 'Red')
label_menu_render = label_menu.render('Space Sturm', True, 'Blue')
lose_label = label.render('You lose!', True, 'White')
restart_label = label.render('Restart', True, 'White')
restart_rect = restart_label.get_rect(topleft=(restart_x, restart_y))
ghost = [
pygame.image.load(image_path + 'Images/Sprites/wars/Ghost/ghost_sprite1.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/wars/Ghost/ghost_sprite2.png').convert_alpha()
]
ghost_anim_count = 0
face = pygame.image.load(image_path + 'Images/Sprites/next_sprite.png').convert_alpha()
jump_sprite = pygame.image.load(image_path + 'Images/Sprites/jump_sprite.png').convert_alpha()
jump_sprite2 = pygame.image.load(image_path + 'Images/Sprites/jump_sprite2.png').convert_alpha()
jump_sound = pygame.mixer.Sound(image_path + 'Sounds/jump_sound.mp3')
sounds_walk = pygame.mixer.Sound(image_path +'Sounds/sound1.mp3')
sounds_walk2 = pygame.mixer.Sound(image_path + 'Sounds/sound2.mp3')
walk_left = [
pygame.image.load(image_path + 'Images/Sprites/left_player_sprite/left_sprite1.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/left_player_sprite/left_sprite2.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/left_player_sprite/left_sprite3.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/left_player_sprite/left_sprite4.png').convert_alpha()
]
walk_right = [
pygame.image.load(image_path + 'Images/Sprites/right_player_sprite/right_sprite1.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/right_player_sprite/right_sprite2.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/right_player_sprite/right_sprite3.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/right_player_sprite/right_sprite4.png').convert_alpha()
]
menu = True
player_anim_count = 0
loses = 0
ghost_list = []
bg = pygame.image.load(image_path + 'Images/Background/bg1.jpeg').convert()
bg_sound1 = pygame.mixer.Sound(image_path + 'Sounds/bg.mp3')
ghost_speed = 5
running = True
bg_sound1.play(loops=-1)
while running:
gameplay1 = True
keys = pygame.key.get_pressed()
mouse = pygame.mouse.get_pos()
if menu:
screen.blit(bg, (bg_x, 0))
screen.blit(bg, (bg_x + 604, 0))
bg_x -= 1
screen.blit(label_menu_render, (225, 100))
play_rect = play_render.get_rect(topleft=(200, 200))
screen.blit(play_render, (200, 200))
if play_rect.collidepoint(mouse) and pygame.mouse.get_pressed()[0]:
menu = False
quit_rect = quit_render.get_rect(topleft=(70, 200))
screen.blit(quit_render, (70, 200))
pygame.display.update()
else:
screen.blit(bg, (bg_x, 0))
screen.blit(bg, (bg_x + 604, 0))
screen.blit(bg, (bg_x - 604, 0))
if gameplay:
gameplay1 = True
player_rect = walk_right[1].get_rect(topleft=(player_x, player_y))
if ghost_list:
for (i, el) in enumerate(ghost_list):
screen.blit(ghost[ghost_anim_count], el)
el.x -= 10
if el.x < -10:
ghost_list.pop(i)
if player_rect.colliderect(el):
gameplay = False
if is_jump and keys[pygame.K_a] and player_x > 100:
player_x -= player_speed
screen.blit(jump_sprite2, (player_x, player_y))
sounds_walk.stop()
bg_x += 2
if bg_x == -604:
bg_x = 0
elif keys[pygame.K_a] and player_x > 5:
player_x -= player_speed
bg_x += 2
if bg_x == -604:
bg_x = 0
screen.blit(walk_left[player_anim_count], (player_x, player_y))
sounds_walk.play(loops=-1)
elif is_jump and keys[pygame.K_d] and player_x < 550:
player_x += player_speed
screen.blit(jump_sprite, (player_x, player_y))
sounds_walk2.stop()
if bg_x == -604:
bg_x = 0
bg_x -= 2
elif keys[pygame.K_d] and player_x < 550:
player_x += player_speed
if bg_x == -604:
bg_x = 0
bg_x -= 2
screen.blit(walk_right[player_anim_count], (player_x, player_y,), )
sounds_walk2.play(loops=-1)
else:
screen.blit(face, (player_x, player_y))
sounds_walk.stop()
sounds_walk2.stop()
if not is_jump:
if keys[pygame.K_SPACE]:
is_jump = True
sounds_walk.stop()
sounds_walk2.stop()
jump_sound.play()
else:
if jump_count >= -8:
if jump_count > 0:
player_y -= (jump_count ** 2) / 2
else:
player_y += (jump_count ** 2) / 2
jump_count -= 1
else:
is_jump = False
jump_count = 8
if player_anim_count == 3:
player_anim_count = 0
else:
player_anim_count += 1
if ghost_anim_count >= 1:
ghost_anim_count = 0
else:
ghost_anim_count += 1
else:
bg_sound1.stop()
gameplay1 = False
screen.fill((87, 88, 89))
screen.blit(lose_label, (225, 100))
screen.blit(restart_label, restart_rect)
if restart_rect.collidepoint(mouse) and pygame.mouse.get_pressed()[0]:
gameplay = True
player_x = 150
ghost_list.clear()
bg_sound1.play(loops=-1)
jump_sound.stop()
sounds_walk2.stop()
sounds_walk.stop()
if keys[pygame.K_ESCAPE] and gameplay == False:
gameplay = True
menu = True
ghost_list.clear()
bg_sound1.play(loops=-1)
elif keys[pygame.K_ESCAPE]:
menu = True
ghost_list.clear()
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
if quit_rect.collidepoint(mouse) and pygame.mouse.get_pressed()[0]:
running = False
pygame.quit()
if event.type == ghost_timer:
ghost_list.append(ghost[ghost_anim_count].get_rect(topleft=(604, 246)))
clock.tick(15)
image_path = '/data/data/com.devgmore.spacesturm/files/app/'
clock = pygame.time.Clock()
pygame.init()
screen = pygame.display.set_mode((604, 377))
pygame.display.set_caption("Space Sturm")
icon = pygame.image.load(image_path + 'Images/icon.png').convert_alpha()
pygame.display.set_icon(icon)
player_speed = 7
player_x = 150
player_y = 246
is_jump = False
jump_count = 8
bg_x = 0
gameplay = True
restart_x = 230
restart_y = 250
ghost_timer = pygame.USEREVENT + 1
ghost_timer1 = random.randint(500, 2500)
pygame.time.set_timer(ghost_timer, ghost_timer1)
label = pygame.font.Font(image_path + 'Fonts/Font.ttf', 40)
label_menu = pygame.font.Font(image_path + 'Fonts/Font.ttf', 60)
play_render = label.render('Play', False, 'Green')
quit_render = label.render('Quit', False, 'Red')
label_menu_render = label_menu.render('Space Sturm', True, 'Blue')
lose_label = label.render('You lose!', True, 'White')
restart_label = label.render('Restart', True, 'White')
restart_rect = restart_label.get_rect(topleft=(restart_x, restart_y))
ghost = [
pygame.image.load(image_path + 'Images/Sprites/wars/Ghost/ghost_sprite1.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/wars/Ghost/ghost_sprite2.png').convert_alpha()
]
ghost_anim_count = 0
face = pygame.image.load(image_path + 'Images/Sprites/next_sprite.png').convert_alpha()
jump_sprite = pygame.image.load(image_path + 'Images/Sprites/jump_sprite.png').convert_alpha()
jump_sprite2 = pygame.image.load(image_path + 'Images/Sprites/jump_sprite2.png').convert_alpha()
jump_sound = pygame.mixer.Sound(image_path + 'Sounds/jump_sound.mp3')
sounds_walk = pygame.mixer.Sound(image_path +'Sounds/sound1.mp3')
sounds_walk2 = pygame.mixer.Sound(image_path + 'Sounds/sound2.mp3')
walk_left = [
pygame.image.load(image_path + 'Images/Sprites/left_player_sprite/left_sprite1.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/left_player_sprite/left_sprite2.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/left_player_sprite/left_sprite3.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/left_player_sprite/left_sprite4.png').convert_alpha()
]
walk_right = [
pygame.image.load(image_path + 'Images/Sprites/right_player_sprite/right_sprite1.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/right_player_sprite/right_sprite2.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/right_player_sprite/right_sprite3.png').convert_alpha(),
pygame.image.load(image_path + 'Images/Sprites/right_player_sprite/right_sprite4.png').convert_alpha()
]
menu = True
player_anim_count = 0
loses = 0
ghost_list = []
bg = pygame.image.load(image_path + 'Images/Background/bg1.jpeg').convert()
bg_sound1 = pygame.mixer.Sound(image_path + 'Sounds/bg.mp3')
ghost_speed = 5
running = True
bg_sound1.play(loops=-1)
while running:
gameplay1 = True
keys = pygame.key.get_pressed()
mouse = pygame.mouse.get_pos()
if menu:
screen.blit(bg, (bg_x, 0))
screen.blit(bg, (bg_x + 604, 0))
bg_x -= 1
screen.blit(label_menu_render, (225, 100))
play_rect = play_render.get_rect(topleft=(200, 200))
screen.blit(play_render, (200, 200))
if play_rect.collidepoint(mouse) and pygame.mouse.get_pressed()[0]:
menu = False
quit_rect = quit_render.get_rect(topleft=(70, 200))
screen.blit(quit_render, (70, 200))
pygame.display.update()
else:
screen.blit(bg, (bg_x, 0))
screen.blit(bg, (bg_x + 604, 0))
screen.blit(bg, (bg_x - 604, 0))
if gameplay:
gameplay1 = True
player_rect = walk_right[1].get_rect(topleft=(player_x, player_y))
if ghost_list:
for (i, el) in enumerate(ghost_list):
screen.blit(ghost[ghost_anim_count], el)
el.x -= 10
if el.x < -10:
ghost_list.pop(i)
if player_rect.colliderect(el):
gameplay = False
if is_jump and keys[pygame.K_a] and player_x > 100:
player_x -= player_speed
screen.blit(jump_sprite2, (player_x, player_y))
sounds_walk.stop()
bg_x += 2
if bg_x == -604:
bg_x = 0
elif keys[pygame.K_a] and player_x > 5:
player_x -= player_speed
bg_x += 2
if bg_x == -604:
bg_x = 0
screen.blit(walk_left[player_anim_count], (player_x, player_y))
sounds_walk.play(loops=-1)
elif is_jump and keys[pygame.K_d] and player_x < 550:
player_x += player_speed
screen.blit(jump_sprite, (player_x, player_y))
sounds_walk2.stop()
if bg_x == -604:
bg_x = 0
bg_x -= 2
elif keys[pygame.K_d] and player_x < 550:
player_x += player_speed
if bg_x == -604:
bg_x = 0
bg_x -= 2
screen.blit(walk_right[player_anim_count], (player_x, player_y,), )
sounds_walk2.play(loops=-1)
else:
screen.blit(face, (player_x, player_y))
sounds_walk.stop()
sounds_walk2.stop()
if not is_jump:
if keys[pygame.K_SPACE]:
is_jump = True
sounds_walk.stop()
sounds_walk2.stop()
jump_sound.play()
else:
if jump_count >= -8:
if jump_count > 0:
player_y -= (jump_count ** 2) / 2
else:
player_y += (jump_count ** 2) / 2
jump_count -= 1
else:
is_jump = False
jump_count = 8
if player_anim_count == 3:
player_anim_count = 0
else:
player_anim_count += 1
if ghost_anim_count >= 1:
ghost_anim_count = 0
else:
ghost_anim_count += 1
else:
bg_sound1.stop()
gameplay1 = False
screen.fill((87, 88, 89))
screen.blit(lose_label, (225, 100))
screen.blit(restart_label, restart_rect)
if restart_rect.collidepoint(mouse) and pygame.mouse.get_pressed()[0]:
gameplay = True
player_x = 150
ghost_list.clear()
bg_sound1.play(loops=-1)
jump_sound.stop()
sounds_walk2.stop()
sounds_walk.stop()
if keys[pygame.K_ESCAPE] and gameplay == False:
gameplay = True
menu = True
ghost_list.clear()
bg_sound1.play(loops=-1)
elif keys[pygame.K_ESCAPE]:
menu = True
ghost_list.clear()
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
if quit_rect.collidepoint(mouse) and pygame.mouse.get_pressed()[0]:
running = False
pygame.quit()
if event.type == ghost_timer:
ghost_list.append(ghost[ghost_anim_count].get_rect(topleft=(604, 246)))
clock.tick(15)