Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire Blob #6

Merged
merged 11 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed __pycache__/main.cpython-39.pyc
Binary file not shown.
Binary file removed engine/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file removed engine/__pycache__/ball.cpython-39.pyc
Binary file not shown.
Binary file removed engine/__pycache__/blobs.cpython-39.pyc
Binary file not shown.
Binary file removed engine/__pycache__/gameplay.cpython-39.pyc
Binary file not shown.
Binary file removed engine/__pycache__/handle_input.cpython-39.pyc
Binary file not shown.
Binary file removed engine/__pycache__/main_menu.cpython-39.pyc
Binary file not shown.
69 changes: 50 additions & 19 deletions engine/ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ def check_blob_collisions(self, blob):
blob_collision_distance = blob.collision_distance
#X distance used for calculations. If the distance between centers is less than this, a collision can happen

ball_angle = math.atan2(self.x_speed, self.y_speed)
#print(ball_angle)
p1_angle = math.atan2(self.x_center - blob.x_pos, self.y_center - blob.y_pos)
p1_speed = round(math.sqrt(blob.x_speed**2 + blob.y_speed**2))
ball_speed = round(math.sqrt(self.x_speed**2 + self.y_speed**2))

ball_vector = pg.math.Vector2(self.x_center, self.y_center)
p1_vector = pg.math.Vector2(blob.x_center, blob.y_center)

Expand All @@ -98,11 +92,19 @@ def check_blob_collisions(self, blob):
self.y_speed = -5
self.x_speed = 0


elif(blob.y_center >= self.y_center): #Is the ball above the blob?
if(p1_vector.distance_to(ball_vector) < 80):
blob.collision_timer = 10
if p1_vector.distance_to(ball_vector) <= blob_collision_distance: #Standard collision
if p1_vector.distance_to(ball_vector) <= blob_collision_distance and blob.kick_timer > 0:
self.image = type_to_image('kicked_ball')
self.type = "kicked_ball"
self.special_timer = 30
p1_ball_nv = p1_vector - ball_vector
p1_ball_collision = pg.math.Vector2(self.x_speed, self.y_speed).reflect(p1_ball_nv)
blob_kick_x_modifier = ((self.x_center - blob.x_center)/50) * 10
blob_kick_y_modifier = ((blob.y_center - self.y_center)/50) * 10 #TODO: Fix for Sponge/Sci Slime
self.x_speed, self.y_speed = (p1_ball_collision[0] + blob_kick_x_modifier), (1 * p1_ball_collision[1] - blob_kick_y_modifier)
elif p1_vector.distance_to(ball_vector) <= blob_collision_distance: #Standard collision
p1_ball_nv = p1_vector - ball_vector
p1_ball_collision = pg.math.Vector2(self.x_speed, self.y_speed).reflect(p1_ball_nv)
blob_kick_x_modifier = ((self.x_center - blob.x_center)/104) * ((8*blob_collision_distance/104) - 8)
Expand All @@ -112,10 +114,6 @@ def check_blob_collisions(self, blob):
#If the ball is stuck inside of the blob for some reason, move it out
self.x_pos += self.x_speed
self.y_pos += self.y_speed
if(blob.kick_timer > 0):
self.image = type_to_image('kicked_ball')
self.type = "kicked_ball"
self.special_timer = 30
else:
#Debug
if(abs(blob.x_center - self.x_center) < blob_collision_distance):
Expand All @@ -126,9 +124,11 @@ def check_blob_collisions(self, blob):
def check_block_collisions(self, blob, other_blob):
#Checks for block collisions
if(blob.block_timer == blob.block_timer_max):
collision_timer_duration = 30
#Check for an active block (lasts one frame)
outer_intersection = lineFromPoints((self.x_pos, self.y_pos), self.previous_locations[-2], blob.block_outer, 0)
inner_intersection = lineFromPoints((self.x_pos, self.y_pos), self.previous_locations[-2], blob.block_inner, 0)
#outer_intersection = lineFromPoints((self.x_pos, self.y_pos), self.previous_locations[-2], blob.block_outer, 0)
#inner_intersection = lineFromPoints((self.x_pos, self.y_pos), self.previous_locations[-2], blob.block_inner, 0)
ball_midpoint = ((self.x_pos + self.previous_locations[-2][0])/2, (self.y_pos + self.previous_locations[-2][1])/2)
if(blob.facing == "left"):
#If the blob is facing left
if((blob.x_center - blob.collision_distance) - blob.block_outer <= self.x_center <= blob.x_center - blob.collision_distance + blob.block_inner):
Expand All @@ -140,8 +140,23 @@ def check_block_collisions(self, blob, other_blob):
self.image = type_to_image("blocked_ball")
self.type = "blocked_ball"
self.special_timer = 30
blob.collision_timer = 10
other_blob.collision_timer = 10
blob.collision_timer = collision_timer_duration
other_blob.collision_timer = collision_timer_duration
#Stops the ball completely
elif((blob.x_center - blob.collision_distance) - blob.block_outer <= ball_midpoint[0] <= blob.x_center - blob.collision_distance + blob.block_inner):
#If the ball is within the x values of the bounding box
if((blob.y_center - blob.collision_distance) + blob.block_upper <= ball_midpoint[1] <= blob.y_center + blob.block_lower):
#If the ball is within the y values of the bounding box
self.x_pos = ball_midpoint[0]
self.y_pos = ball_midpoint[1]
#Teleport the ball to the midpoint
self.x_speed = 0
self.y_speed = 0
self.image = type_to_image("blocked_ball")
self.type = "blocked_ball"
self.special_timer = 30
blob.collision_timer = collision_timer_duration
other_blob.collision_timer = collision_timer_duration
#Stops the ball completely
else:
#If the blob is facing right
Expand All @@ -153,11 +168,27 @@ def check_block_collisions(self, blob, other_blob):
self.y_speed = 0
self.image = type_to_image("blocked_ball")
self.special_timer = 30
blob.collision_timer = 3
other_blob.collision_timer = 3
blob.collision_timer = collision_timer_duration
other_blob.collision_timer = collision_timer_duration
#Stops the ball completely
elif(blob.x_center + blob.collision_distance - 25 <= ball_midpoint[0] <= blob.x_center + blob.collision_distance + 150):
#If the ball is within the x values of the bounding box
if((blob.y_center - blob.collision_distance) - 200 <= ball_midpoint[1] <= blob.y_center + 200):
#If the ball is within the y values of the bounding box
self.x_speed = 0
self.y_speed = 0
self.image = type_to_image("blocked_ball")
self.special_timer = 30
blob.collision_timer = collision_timer_duration
other_blob.collision_timer = collision_timer_duration
#Stops the ball completely
return blob, other_blob

def check_blob_ability(self, blob):
if(blob.used_ability == "fireball"):
self.x_speed *= (1.05 - (self.x_speed/1000))
self.y_speed *= (1.05 - (self.y_speed/1000))


def move(self):
ground = ball.ground
left_wall = 0
Expand Down
92 changes: 71 additions & 21 deletions engine/blobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,42 @@ def type_to_stars(type):
'block_cooldown_rate': 5,

'boost_cost': 600,
'boost_cooldown_rate': 5,
'boost_cooldown_max': 5,
'boost_duration': 5,

'special_ability': 'boost',
'special_ability_cost': 300,
'special_ability_maintenance': 0,
'special_ability_max': 1800,
'special_ability_cooldown': 300
'special_ability_cooldown': 300,
}
elif(type == "fire"):
blob_dict = {
'max_hp': 2,
'top_speed': 4,
'traction': 4,
'friction': 3,
'gravity': 1,
'kick_cooldown_rate': 3,
'block_cooldown_rate': 3,

'boost_cost': 600,
'boost_cooldown_max': 3,
'boost_duration': 3,

'special_ability': 'fireball',
'special_ability_cost': 200,
'special_ability_maintenance': 20,
'special_ability_max': 1800,
'special_ability_cooldown': 2,
}
return blob_dict

def type_to_image(type):
global cwd
image_dict = {
"quirkless": cwd+"\\resources\\images\\blobs\\quirkless_blob.png",
"fire": cwd+"\\resources\\images\\blobs\\fire_blob.png",
"random": cwd+"\\resources\\images\\blobs\\random_blob.png",
"invisible": cwd+"\\resources\\images\\blobs\\invisible_blob.png"
}
Expand Down Expand Up @@ -115,7 +137,7 @@ def __init__(self, type = "quirkless", x_pos = 50, y_pos = 1200, facing = 'left'
self.kick_visualization = 0
self.kick_visualization_max = 15

self.block_cooldown_rate = 5 + self.stars['block_cooldown_rate'] #Each star reduces block cooldown
self.block_cooldown_rate = (5 + self.stars['block_cooldown_rate']) #Each star reduces block cooldown
self.block_cooldown = 0 #Block cooldown timer
self.block_timer = 0 #How much time is left in the current block
self.block_timer_max = 15 #How many frames a block lasts.
Expand All @@ -127,7 +149,7 @@ def __init__(self, type = "quirkless", x_pos = 50, y_pos = 1200, facing = 'left'
self.block_lower = 200

self.boost_cost = self.stars['boost_cost'] #How much SA meter must be spent to boost
self.boost_cooldown_rate = 1 + self.stars['boost_cooldown_rate'] #Each star reduces boost cooldown
self.boost_cooldown_max = 300 + 30 * (5 - self.stars['boost_cooldown_max']) #Each star reduces boost cooldown
self.boost_cooldown_timer = 0 #Timer that measures between boosts
self.boost_duration = 60 + (30 * self.stars['boost_duration']) #Each star increases boost duration by half a second
self.boost_timer = 0 #How much time is left in the current boost
Expand All @@ -142,14 +164,22 @@ def __init__(self, type = "quirkless", x_pos = 50, y_pos = 1200, facing = 'left'

self.special_ability = self.stars['special_ability'] #Special Ability of a Blob
self.special_ability_max = self.stars['special_ability_max'] #Highest that the SA gauge can go
self.special_ability_cost = self.stars['special_ability_cost'] #Price to use SA
self.special_ability_cost = self.stars['special_ability_cost'] #Price to activate SA
self.special_ability_maintenance = self.stars['special_ability_maintenance'] #Price to maintain SA
self.special_ability_charge = 1 #Charge rate. Each frame increases the SA meter by 1 point, or more if focusing
self.special_ability_meter = 0 #Amount of SA charge stored up
self.special_ability_timer = 0 #Timer that counts down between uses of an SA
self.special_ability_duration = 0 #Time that a SA is active
self.special_ability_cooldown = self.stars['special_ability_cooldown'] #Cooldown between uses
self.used_ability = None

self.collision_distance = 104 #Used for calculating ball collisions
self.collision_timer = 0 #Prevents double hitting in certain circumstances

self.damage_flash_timer = 0 #Flashes when damage is taken
self.kick_cooldown_visualization = 0
self.block_cooldown_visualization = 0
self.boost_cooldown_visualization = 0
self.movement_lock = 0 #Caused if the blob has its movement blocked

ground = 1200
Expand All @@ -170,6 +200,11 @@ def cooldown(self): #Reduces timers
if(self.special_ability_meter > self.special_ability_max):
self.special_ability_meter = self.special_ability_max

if(self.special_ability_timer > 0):
self.special_ability_timer -= 1
if(self.special_ability_timer == 0):
self.used_ability = None

if(self.kick_cooldown > 0):
self.kick_cooldown -= self.kick_cooldown_rate
if(self.kick_timer > 0):
Expand All @@ -192,7 +227,7 @@ def cooldown(self): #Reduces timers
self.traction = 0.2 + (self.stars['traction'] * 0.15) #Each star increases traction
self.friction = 0.2 + (self.stars['friction'] * 0.15) #Each star increases friction
elif(self.boost_cooldown_timer > 0): #If the boost is over, cool down
self.boost_cooldown_timer -= self.boost_cooldown_rate
self.boost_cooldown_timer -= 1

if(self.collision_timer > 0):
self.collision_timer -=1
Expand All @@ -206,10 +241,27 @@ def cooldown(self): #Reduces timers

if(self.movement_lock > 0):
self.movement_lock -= 1

self.kick_cooldown_visualization = math.ceil(self.kick_cooldown/self.kick_cooldown_rate/6)/10
self.block_cooldown_visualization = math.ceil(self.block_cooldown/self.block_cooldown_rate/6)/10
self.boost_cooldown_visualization = math.ceil(self.boost_cooldown_timer/6)/10

def ability(self):
if(self.special_ability == 'boost'):
self.boost()

elif(self.special_ability == 'fireball'):
if(self.special_ability_meter >= self.special_ability_cost and self.special_ability_timer <= 2):
if(self.special_ability_timer > 0):
#If we were holding down the button before
self.used_ability = "fireball"
self.special_ability_timer = self.special_ability_cooldown #Set the cooldown between uses timer
self.special_ability_meter -= self.special_ability_maintenance #Remove some SA meter
else:
#If we ignite the ball
self.used_ability = "fireball"
self.special_ability_timer = self.special_ability_cooldown #Set the cooldown between uses timer
self.special_ability_meter -= self.special_ability_cost #Remove some SA meter

def kick(self):
if(self.kick_cooldown <= 0):
self.block_cooldown += 5 * (self.block_cooldown_rate)
Expand All @@ -228,13 +280,13 @@ def block(self):

def boost(self):
if(self.special_ability_meter >= self.boost_cost and self.boost_cooldown_timer <= 0):
self.boost_cooldown_timer = 600 #About 5 seconds
self.special_ability_meter -= self.boost_cost #Remove some SA meter
self.top_speed = self.boost_top_speed
self.traction = self.boost_traction
self.friction = self.boost_friction
self.boost_timer = self.boost_duration #Set the boost's timer to its maximum duration

self.boost_timer = self.boost_duration #Set the boost's timer to its maximum duration, about 5 seconds
self.boost_cooldown_timer = self.boost_cooldown_max

def check_blob_collision(self, blob):
#Used to see if a blob is getting kicked!
if(self.x_center - (1.5 * self.collision_distance) <= blob.x_center <= self.x_center + (1.5 * self.collision_distance)):
Expand Down Expand Up @@ -279,14 +331,13 @@ def move(self, pressed_buttons):
pressed = []
for button in pressed_buttons:
if(button in pressed_conversions):
pressed.append(pressed_conversions[button])

if(self.focusing):
for button in pressed:
if(button == "down"):
continue
if(self.focusing):
if(pressed_conversions[button] == "down"):
pressed.append(pressed_conversions[button])
else:
continue
else:
pressed.remove(button)
pressed.append(pressed_conversions[button])

if(self.movement_lock > 0):
pressed = []
Expand Down Expand Up @@ -374,6 +425,8 @@ def move(self, pressed_buttons):
if(not self.focusing and not self.impact_land_frames):
self.focusing = True
self.focus_lock = self.focus_lock_max
elif(self.focusing):
self.focusing = True
if(not 'down' in pressed and self.focus_lock == 0 and self.focusing):
#True if we're not holding down, focus lock is done and we're focusing
self.focusing = False
Expand Down Expand Up @@ -409,7 +462,4 @@ def move(self, pressed_buttons):

self.x_center = self.x_pos + 83 #Rough estimate :)
self.y_center = self.y_pos + 110 #Rough estimate :)


if __name__ == "__main__":
new_blob = blob("quirkless", 0, 0)

6 changes: 4 additions & 2 deletions engine/gameplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ def blob_ko(blob):
if(timer == 0):
p1_blob.move(pressed)
p2_blob.move(pressed)
ball.check_block_collisions(p1_blob, p2_blob)
ball.check_block_collisions(p2_blob, p1_blob)
p1_blob, p2_blob = ball.check_block_collisions(p1_blob, p2_blob)
p2_blob, p1_blob = ball.check_block_collisions(p2_blob, p1_blob)
ball.check_blob_ability(p1_blob)
ball.check_blob_ability(p2_blob)
if(p1_blob.kick_timer == 1):
p1_blob.check_blob_collision(p2_blob)
if(p2_blob.hp <= 0):
Expand Down
Loading