Browse Source

Merge branch 'exploding_player'

merge exploding_player with master
pull/19/head
Max Lange 7 years ago
parent
commit
6143f49b66
  1. 46
      src/missions.py
  2. 1
      src/objects.py
  3. 20
      src/player.py
  4. 2
      src/worlds.py

46
src/missions.py

@ -1,18 +1,16 @@
# -*- coding: utf-8 -*-
from . import settings
import pygame
from pygame.locals import *
import math
def init():
global newtime
newtime = pygame.time.get_ticks()
time("ingame")
def handle(usage):
global newtime
def time(usage):
if not "newtime" in locals():
newtime = pygame.time.get_ticks()
if usage == "ingame":
oldtime = newtime
newtime = pygame.time.get_ticks()
@ -21,6 +19,15 @@ def handle(usage):
oldtime = pygame.time.get_ticks()
newtime = pygame.time.get_ticks()
def handle(usage):
time("ingame")
target_shooting()
player_hit_by_explosion()
def target_shooting():
alltargets = 0
for world in settings.localmap:
alltargets += len(settings.localmap[world].targets)
@ -35,8 +42,6 @@ def handle(usage):
screen = settings.screen
settings.save(settings.current_game)
fade = pygame.Surface((settings.screenx_current, settings.screeny_current))
fade.fill((0, 0, 0))
fade.set_alpha(0)
@ -59,9 +64,9 @@ def handle(usage):
settings.upd("get_events")
for event in settings.events:
if event.type == QUIT:
if event.type == pygame.QUIT:
settings.quit()
if event.type == KEYDOWN:
if event.type == pygame.KEYDOWN:
key = pygame.key.name(event.key)
if key == "escape" or key == "return":
settings.run = False
@ -71,3 +76,22 @@ def handle(usage):
screen.blit(texttime, textrect)
screen.blit(texttt, textrectpertarget)
pygame.display.flip()
def player_hit_by_explosion():
# need to be globals so it is are preserved everytime this is called
global running
for explosion in settings.explosions_disp:
distance = math.sqrt(
(explosion.pos.centerx - settings.player.pos.centerx) ** 2
+ (explosion.pos.centery - settings.player.pos.centery) ** 2)
if distance <= 20 and (not ("running" in globals())):
running = "Wow this variable exists"
settings.player.explode()
if settings.player.explosion_anim is not None:
if (settings.player.explosion_anim.state in ["paused", "stopped"]
or settings.player.explosion_anim.isFinished()):
settings.quit()

1
src/objects.py

@ -170,6 +170,7 @@ class target():
if self.pos.colliderect(bulletrect) and not self.gothit:
self.pos_x -= self.explosion.getRect().w / 2.0
self.pos_y -= self.explosion.getRect().h / 2.0
self.pos.size = self.explosion.getRect().size
self.explosion.play()
self.gothit = True

20
src/player.py

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import pygame
import math
from libs.pyganim import pyganim
from ConfigParser import SafeConfigParser
@ -23,6 +24,7 @@ class player():
self.timeplay = 0 # Time player has played
self.update = True # If yes new image gets loaded
self.speedboost = 1
self.explosion_anim = None
def create_images(self, name):
"""creates new images from one image for the player"""
@ -186,8 +188,24 @@ class player():
self.img = self.playerup
self.select_picture()
def explode(self):
self.speedboost = 0
explosion_img = pyganim.getImagesFromSpriteSheet(
"./assets/sprites/explosions/ship_expl.png",
width=256, height=256)
explosion_attr = [(anim_file, 40) for anim_file in explosion_img]
self.explosion_anim = pyganim.PygAnimation(explosion_attr, loop=False)
self.explosion_anim.play()
def blit(self, screen):
screen.blit(self.img, self.pos)
if self.explosion_anim is None:
screen.blit(self.img, self.pos)
else:
self.update = False
pos = self.pos.copy()
pos.x -= self.explosion_anim.getMaxSize()[0] / 2
pos.y -= self.explosion_anim.getMaxSize()[1] / 2
self.explosion_anim.blit(screen, pos)
def reset(self):
self.should_move = False

2
src/worlds.py

@ -63,12 +63,14 @@ class world():
target.test_ishit(bullet.pos)
if target.gothit:
self.targets.remove(target)
#TODO: move from settings to here
settings.explosions_disp.append(target)
settings.explosions_disp = list(set(settings.explosions_disp))
for explosion in settings.explosions_disp:
if explosion.kill_entity:
settings.explosions_disp.remove(explosion)
pass
else:
explosion.move(player_pos.left, player_pos.top)

Loading…
Cancel
Save