forked from elliott005/ninjaSouls
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCuttableGrass.py
More file actions
44 lines (40 loc) · 1.75 KB
/
CuttableGrass.py
File metadata and controls
44 lines (40 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import pygame, math, random
from globals import *
leafSpriteSheet = pygame.image.load(os.path.dirname(__file__) + "/assets/NinjaAdventure/FX/Particle/Grass.png")
leafSpriteSize = (12, 13)
leafSprites = [pygame.transform.scale(leafSpriteSheet.subsurface(pygame.Rect(leafSpriteSize[0] * x, leafSpriteSize[1] * 0, leafSpriteSize[0], leafSpriteSize[1])), (size[0], size[1])) for x in range(0, 6)]
class CuttableGrass(pygame.sprite.Sprite):
def __init__(self, pos, size, surf, groups):
super().__init__(groups)
self.rect = pygame.rect.Rect(pos, size)
self.image = pygame.transform.scale(surf, size)
self.cut = False
self.currentFrame = 0
self.maxFrame = 6
self.animSpeed = 10
self.angle = 0
self.turnSpeed = 450
self.velocity = pygame.math.Vector2(0, -100)
self.dropTable = {
"heart": 10,
"coin": 5
}
def update(self, dt, playerAttackHitbox=-1):
if playerAttackHitbox != -1 and not self.cut:
if self.rect.colliderect(playerAttackHitbox):
self.cut = True
if self.cut:
if self.velocity.x >= 0.0:
self.angle += dt * self.turnSpeed
self.velocity.rotate_ip(self.angle * dt)
self.rect.move_ip(self.velocity * dt)
self.currentFrame += dt * self.animSpeed
if self.currentFrame >= self.maxFrame:
self.currentFrame = 0.0
self.kill()
for drop in self.dropTable:
if random.randint(0, 100) < self.dropTable[drop]:
return self.rect.topleft, drop
self.image = leafSprites[math.floor(self.currentFrame)]
return -1, -1