It is now possible to yeet the cow's head by pressing space.
This commit is contained in:
parent
82bffd6caf
commit
ac1b10fd01
1 changed files with 58 additions and 1 deletions
59
cowyeet.py
59
cowyeet.py
|
@ -5,6 +5,7 @@ import pygame
|
||||||
import numpy
|
import numpy
|
||||||
from tools import pg # if you import pg from tools, you dont need to init pygame.
|
from tools import pg # if you import pg from tools, you dont need to init pygame.
|
||||||
from tools.file_dict import FileDict
|
from tools.file_dict import FileDict
|
||||||
|
from physics.parabelfunc import berechneflugbahn
|
||||||
|
|
||||||
|
|
||||||
# integrated settings (I dont trust my own settings class.)
|
# integrated settings (I dont trust my own settings class.)
|
||||||
|
@ -85,12 +86,15 @@ def set_rot_point(img, pos):
|
||||||
# game logic
|
# game logic
|
||||||
def start_level(lvl: int):
|
def start_level(lvl: int):
|
||||||
global level
|
global level
|
||||||
|
global cow_throwable
|
||||||
|
|
||||||
page_switch("ingame")
|
page_switch("ingame")
|
||||||
level = lvl
|
level = lvl
|
||||||
|
|
||||||
load_level(lvl)
|
load_level(lvl)
|
||||||
|
|
||||||
|
cow_throwable = True
|
||||||
|
|
||||||
|
|
||||||
def load_level(lvl):
|
def load_level(lvl):
|
||||||
global level_data
|
global level_data
|
||||||
|
@ -135,6 +139,27 @@ def blit_block(block, position: tuple):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
level_surface.blit(texture_not_found, position)
|
level_surface.blit(texture_not_found, position)
|
||||||
|
|
||||||
|
|
||||||
|
def yeet_cow():
|
||||||
|
global cow_throwable
|
||||||
|
global cow_flying
|
||||||
|
global cow_flight_path
|
||||||
|
global cow_flight_step
|
||||||
|
|
||||||
|
if cow_throwable:
|
||||||
|
cow_throwable = False
|
||||||
|
|
||||||
|
lvl_x, lvl_y = level_data.level_size
|
||||||
|
lvl_x *= 40
|
||||||
|
lvl_x *= settings["level_size_multiplier"]
|
||||||
|
lvl_y *= 40
|
||||||
|
lvl_y *= settings["level_size_multiplier"]
|
||||||
|
|
||||||
|
cow_flight_path = berechneflugbahn(lvl_x, lvl_y, lvl_x + 100, 34, 128, xstep=10)
|
||||||
|
|
||||||
|
cow_flying = True
|
||||||
|
cow_flight_step = 0
|
||||||
# /game logic
|
# /game logic
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,6 +176,11 @@ def level_selector_page():
|
||||||
|
|
||||||
|
|
||||||
def ingame_page():
|
def ingame_page():
|
||||||
|
global cow_flight_step
|
||||||
|
global cow_position
|
||||||
|
global cow_flying
|
||||||
|
global cow_throwable
|
||||||
|
|
||||||
screen.fill(summer_sky)
|
screen.fill(summer_sky)
|
||||||
screen.blit(level_surface, (0, screen.get_height() - level_surface.get_height()))
|
screen.blit(level_surface, (0, screen.get_height() - level_surface.get_height()))
|
||||||
|
|
||||||
|
@ -163,6 +193,19 @@ def ingame_page():
|
||||||
screen.blit(catapult_frame_texture, (cx, cy))
|
screen.blit(catapult_frame_texture, (cx, cy))
|
||||||
screen.blit(catapult_arm_texture, (cx + 27 * 5 * lvl_size, cy - 35 * 5 * lvl_size))
|
screen.blit(catapult_arm_texture, (cx + 27 * 5 * lvl_size, cy - 35 * 5 * lvl_size))
|
||||||
|
|
||||||
|
if cow_flying:
|
||||||
|
cow_flight_step += 1
|
||||||
|
|
||||||
|
x = cow_flight_path[cow_flight_step * 2]
|
||||||
|
y = cow_flight_path[cow_flight_step * 2 + 1]
|
||||||
|
cow_position = (x, screen.get_height() - y - 64 * 5 * settings["level_size_multiplier"])
|
||||||
|
|
||||||
|
if cow_flight_step * 2 == len(cow_flight_path) - 2:
|
||||||
|
cow_flying = False
|
||||||
|
cow_throwable = True
|
||||||
|
|
||||||
|
screen.blit(cow, cow_position)
|
||||||
|
|
||||||
|
|
||||||
def page_selector():
|
def page_selector():
|
||||||
if page == "main_menu":
|
if page == "main_menu":
|
||||||
|
@ -229,10 +272,17 @@ def get_events():
|
||||||
|
|
||||||
last_frame_mouse_pressed = True
|
last_frame_mouse_pressed = True
|
||||||
|
|
||||||
if event.type == pygame.VIDEORESIZE:
|
elif event.type == pygame.VIDEORESIZE:
|
||||||
|
|
||||||
window_size_reload(event.size)
|
window_size_reload(event.size)
|
||||||
|
|
||||||
|
elif event.type == pygame.KEYDOWN:
|
||||||
|
key = event.key
|
||||||
|
|
||||||
|
if key == pygame.K_SPACE:
|
||||||
|
if page == "ingame":
|
||||||
|
yeet_cow()
|
||||||
|
|
||||||
|
|
||||||
def loop():
|
def loop():
|
||||||
global last_frame_mouse_pressed
|
global last_frame_mouse_pressed
|
||||||
|
@ -270,6 +320,11 @@ level = None
|
||||||
level_data = None
|
level_data = None
|
||||||
lvl_width = None
|
lvl_width = None
|
||||||
level_surface = None
|
level_surface = None
|
||||||
|
cow_throwable = False
|
||||||
|
cow_flying = False
|
||||||
|
cow_position = (0, 0)
|
||||||
|
cow_flight_path = []
|
||||||
|
cow_flight_step = 0
|
||||||
|
|
||||||
|
|
||||||
# pygame objects
|
# pygame objects
|
||||||
|
@ -290,6 +345,8 @@ catapult_frame_texture = load_texture("textures/catapult/frame.png")
|
||||||
catapult_frame_texture = pygame.transform.scale(catapult_frame_texture, (66 * 5 * settings["level_size_multiplier"], 31 * 5 * settings["level_size_multiplier"]))
|
catapult_frame_texture = pygame.transform.scale(catapult_frame_texture, (66 * 5 * settings["level_size_multiplier"], 31 * 5 * settings["level_size_multiplier"]))
|
||||||
catapult_arm_texture = load_texture("textures/catapult/arm.png")
|
catapult_arm_texture = load_texture("textures/catapult/arm.png")
|
||||||
catapult_arm_texture = pygame.transform.scale(catapult_arm_texture, (25 * 5 * settings["level_size_multiplier"], 53 * 5 * settings["level_size_multiplier"]))
|
catapult_arm_texture = pygame.transform.scale(catapult_arm_texture, (25 * 5 * settings["level_size_multiplier"], 53 * 5 * settings["level_size_multiplier"]))
|
||||||
|
cow = load_texture("textures/cow/head.png")
|
||||||
|
cow = pygame.transform.scale(cow, (64 * 5 * settings["level_size_multiplier"], 64 * 5 * settings["level_size_multiplier"]))
|
||||||
stone_block_texture = load_block_texture("textures/terrain/stone_01.png")
|
stone_block_texture = load_block_texture("textures/terrain/stone_01.png")
|
||||||
dirt_block_texture = load_block_texture("textures/terrain/dirt_01.png")
|
dirt_block_texture = load_block_texture("textures/terrain/dirt_01.png")
|
||||||
grass_block_texture = load_block_texture("textures/terrain/grass_01.png")
|
grass_block_texture = load_block_texture("textures/terrain/grass_01.png")
|
||||||
|
|
Loading…
Reference in a new issue