def fire(self, elapsedTime): if self.cooldown <= 0: if SDLK_SPACE in globs.keyset: globs.Bullets.append( Bullet.Bullet(self.pos, globs.bulletScale, self.CameraObj.look)) self.cooldown = globs.playerFireRate else: self.cooldown -= elapsedTime
def update(self, elapsedTime): if (SDLK_d or SDLK_RIGHT) in globs.keyset: self.direction = globs.FACING_RIGHT self.pos[0] += globs.playerSpeed * elapsedTime if (SDLK_a or SDLK_LEFT) in globs.keyset: self.direction = globs.FACING_LEFT self.pos[0] -= globs.playerSpeed * elapsedTime if (SDLK_s or SDLK_DOWN) in globs.keyset: self.crouching = True else: self.crouching = False if self.state == globs.RISING: self.pos[1] += globs.playerSpeed * elapsedTime elif self.state == globs.FALLING: self.pos[1] -= globs.playerSpeed * elapsedTime if SDLK_SPACE in globs.keyset and self.lastFired <= 0: #fireBullet bulletPosY = self.pos[1] + self.halfSize if self.crouching: bulletPosY *= .5 globs.objectsToDraw.append( Bullet.Bullet(self.pos[0], bulletPosY, self.direction)) self.lastFired = globs.playerFireRate if SDLK_w in globs.keyset and self.state == globs.ON_GROUND: self.state = globs.RISING elif self.pos[1] >= globs.jumpPeak and self.state == globs.RISING: self.pos[1] = globs.jumpPeak self.state = globs.FALLING elif self.pos[1] <= 0 and self.state == globs.FALLING: self.pos[1] = 0 self.state = globs.ON_GROUND self.lastFired -= elapsedTime
def update(self, elapsedTime): if (SDLK_d or SDLK_RIGHT) in globs.keyset: self.dir = globs.FACING_RIGHT self.pos[0] += self.speed * elapsedTime if (SDLK_a or SDLK_LEFT) in globs.keyset: self.dir = globs.FACING_LEFT self.pos[0] -= self.speed * elapsedTime if (SDLK_s or SDLK_DOWN) in globs.keyset: if self.scale[1] != self.halfHeight: self.scale = math3d.vec2(self.Height, self.halfHeight) elif self.scale[1] != self.Width: self.scale = math3d.vec2(self.Height, self.Width) if self.jumpState == globs.RISING: self.pos[1] += self.speed * elapsedTime elif self.jumpState == globs.FALLING: self.pos[1] -= self.speed * elapsedTime if SDLK_SPACE in globs.keyset and self.lastFired <= 0: #fireBullet bulletPosY = self.pos[1] + (self.scale[1] * .25) globs.Bullets.append( Bullet.Bullet(self.pos[0], bulletPosY, self.dir)) self.lastFired = globs.playerFireRate if SDLK_w in globs.keyset and self.jumpState == globs.ON_GROUND: self.jumpState = globs.RISING elif self.pos[1] >= globs.jumpPeak and self.jumpState == globs.RISING: self.pos[1] = globs.jumpPeak self.jumpState = globs.FALLING elif self.pos[1] <= 0 and self.jumpState == globs.FALLING: self.pos[1] = 0 self.jumpState = globs.ON_GROUND self.lastFired -= elapsedTime
def fire(self): bulletPosY = self.pos[1] + (self.scale[1] * .25) globs.Bullets.append(Bullet.Bullet(self.pos[0], bulletPosY, self.dir)) self.lastFired = globs.playerFireRate