Commit 4e459a52 authored by Max Mraz's avatar Max Mraz
Browse files

init commit

parents
## All Hallow's Eve
A little halloween game created in the Solarus Engine.
<br>
This is the open-source code for the game, not the game itself! To download the game, please visit https://maxatrillionator.itch.io/hallows-eve
<br>
Solarus engine is licensed with the GPL v3. See https://solarus-games.org for more information.
<br>
Code for this game is licensed the same, assets are copyright Max Mraz 2020, unless otherwise specified in project_db.dat
local enemy = ...
local game = enemy:get_game()
local map = enemy:get_map()
local hero = map:get_hero()
local sprite
local ghost_sprite
local movement
local SPEED = 80
function enemy:on_created()
sprite = enemy:create_sprite("enemies/" .. enemy:get_breed(), "main")
ghost_sprite = enemy:create_sprite("enemies/"..enemy:get_breed(), "ghost_aura")
enemy:bring_sprite_to_back(ghost_sprite)
ghost_sprite:set_color_modulation{255,255,255}
ghost_sprite:set_blend_mode"add"
function sprite:on_frame_changed(animation, frame)
frame = frame - 1
if frame < 0 then frame = sprite:get_num_frames() - 1 end
ghost_sprite:set_frame(frame)
end
enemy:set_life(1000)
enemy:set_invincible(true)
enemy:set_damage(2)
enemy:set_size(32,32)
enemy:set_origin(16,29)
enemy:set_attacking_collision_mode"overlapping"
enemy:set_obstacle_behavior"flying"
end
function enemy:on_restarted()
movement = sol.movement.create("target")
movement:set_ignore_obstacles(true)
movement:set_target(hero)
movement:set_speed(SPEED)
movement:start(enemy)
end
function enemy:on_movement_changed(movement)
local angle = movement:get_angle()
if angle > (math.pi / 2) and angle < (3 * math.pi / 2) then
sprite:set_direction(2)
ghost_sprite:set_direction(2)
else
sprite:set_direction(0)
ghost_sprite:set_direction(0)
end
end
\ No newline at end of file
local enemy = ...
local game = enemy:get_game()
local map = enemy:get_map()
local hero = map:get_hero()
local sprite
local ghost_sprite
local movement
local DETECTION_DISTANCE = 160
local SHOOTING_RANGE = 180
local CHASE_SPEED = 60
local WANDER_SPEED = 30
local WIND_UP_TIME = 700
local COOLDOWN = 2000
function enemy:on_created()
sprite = enemy:create_sprite("enemies/" .. enemy:get_breed(), "main")
--set proper windup time
WIND_UP_TIME = sprite:get_num_frames("charging", 0) * sprite:get_frame_delay("charging")
enemy:set_life(2)
enemy:set_damage(2)
ghost_sprite = enemy:create_sprite("enemies/"..enemy:get_breed(), "ghost_aura")
enemy:bring_sprite_to_back(ghost_sprite)
ghost_sprite:set_color_modulation{255,255,255}
ghost_sprite:set_blend_mode"add"
shadow_sprite = enemy:create_sprite("shadows/shadow_medium", "shadow")
-- function sprite:on_frame_changed(animation, frame)
-- frame = frame - 1
-- if frame < 0 then frame = sprite:get_num_frames() - 1 end
-- ghost_sprite:set_frame(frame)
-- end
end
function enemy:on_restarted()
enemy.attacking = false
enemy:choose_state()
end
function enemy:on_movement_changed()
sprite:set_direction(enemy:get_movement():get_direction4())
ghost_sprite:set_direction(enemy:get_movement():get_direction4())
end
function enemy:choose_state()
if enemy:is_close_to_hero() then
if enemy:get_distance(hero) <= SHOOTING_RANGE and not enemy.attacking then
enemy:attack()
elseif not enemy.attacking then
enemy:go_hero()
end
else
enemy:go_random()
end
sol.timer.start(enemy, 200, function() enemy:choose_state() end)
end
function enemy:is_close_to_hero()
local dist = enemy:get_distance(hero)
return enemy:is_in_same_region(hero)
and enemy:get_layer() == hero:get_layer()
and dist <= DETECTION_DISTANCE
end
function enemy:go_hero()
enemy.going_hero = true
local m = sol.movement.create"target"
m:set_speed(CHASE_SPEED)
m:start(enemy)
end
function enemy:go_random()
enemy.going_hero = false
local rand = math.random(1, 100)
if rand > 50 then
elseif rand > 10 then
local m = sol.movement.create"random"
m:set_speed(WANDER_SPEED)
m:start(enemy)
else
enemy:stop_movement()
end
end
function enemy:attack()
--stuff
enemy.attacking = true
enemy:stop_movement()
sprite:set_animation("charging", "walking")
sol.audio.play_sound"cane3"
sol.timer.start(enemy, WIND_UP_TIME, function()
sprite:set_animation("shooting", function()
sprite:set_animation"walking"
enemy:go_hero()
end)
sol.audio.play_sound"frost2"
local x,y,z = enemy:get_position()
local projectile = map:create_enemy{
x=x, y=y-8, layer=z, direction = 0,
breed = "ghost_projectile",
}
projectile:go(projectile:get_angle(hero))
sol.timer.start(enemy, COOLDOWN, function() enemy:restart() end)
end)
end
\ No newline at end of file
local enemy = ...
local game = enemy:get_game()
local map = enemy:get_map()
local hero = map:get_hero()
local sprite
local movement
local SPEED = 130
function enemy:on_created()
sprite = enemy:create_sprite("enemies/" .. enemy:get_breed())
enemy:set_life(1)
enemy:set_invincible()
enemy:set_damage(2)
enemy:set_obstacle_behavior"flying"
end
function enemy:go(angle)
local m = sol.movement.create"straight"
m:set_angle(angle)
m:set_speed(SPEED)
m:set_smooth(false)
m:start(enemy)
function m:on_obstacle_reached()
enemy:stop_movement()
sprite:set_animation("pop", function() enemy:remove() end)
end
end
\ No newline at end of file
local enemy = ...
local game = enemy:get_game()
local map = enemy:get_map()
local hero = map:get_hero()
local sprite
local ghost_sprite
local movement
local DETECTION_DISTANCE = 120
local MELEE_RANGE = 64
local CHASE_SPEED = 70
local WANDER_SPEED = 40
local WIND_UP_TIME = 500
function enemy:on_created()
sprite = enemy:create_sprite("enemies/" .. enemy:get_breed(), "main")
enemy:set_life(3)
enemy:set_damage(2)
ghost_sprite = enemy:create_sprite("enemies/"..enemy:get_breed(), "ghost_aura")
enemy:bring_sprite_to_back(ghost_sprite)
ghost_sprite:set_color_modulation{255,255,255}
ghost_sprite:set_blend_mode"add"
function sprite:on_frame_changed(animation, frame)
frame = frame - 1
if frame < 0 then frame = sprite:get_num_frames() - 1 end
ghost_sprite:set_frame(frame)
end
end
function enemy:on_restarted()
enemy.attacking = false
enemy:choose_state()
end
function enemy:on_movement_changed()
sprite:set_direction(enemy:get_movement():get_direction4())
ghost_sprite:set_direction(enemy:get_movement():get_direction4())
end
function enemy:choose_state()
if enemy:is_close_to_hero() then
if enemy:get_distance(hero) <= MELEE_RANGE and not enemy.attacking then
enemy:attack()
elseif not enemy.attacking then
enemy:go_hero()
end
else
enemy:go_random()
end
sol.timer.start(enemy, 200, function() enemy:choose_state() end)
end
function enemy:is_close_to_hero()
local dist = enemy:get_distance(hero)
return enemy:is_in_same_region(hero)
and enemy:get_layer() == hero:get_layer()
and dist <= DETECTION_DISTANCE
end
function enemy:go_hero()
enemy.going_hero = true
local m = sol.movement.create"target"
m:set_speed(CHASE_SPEED)
m:start(enemy)
end
function enemy:go_random()
enemy.going_hero = false
local rand = math.random(1, 100)
if rand > 50 then
elseif rand > 10 then
local m = sol.movement.create"random"
m:set_speed(WANDER_SPEED)
m:start(enemy)
else
enemy:stop_movement()
end
end
function enemy:attack()
--stuff
enemy.attacking = true
enemy:stop_movement()
local attack_angle = enemy:get_angle(hero)
sprite:set_animation("wind_up")
sol.timer.start(enemy, WIND_UP_TIME, function()
--animation
sprite:set_animation("attack", function()
sprite:set_animation"walking"
enemy:go_hero()
end)
--attack sprite
local attack_sprite = enemy:create_sprite("enemies/misc/slash")
sol.audio.play_sound"swipe_1"
enemy:set_invincible_sprite(attack_sprite)
attack_sprite:set_direction(sprite:get_direction())
sol.timer.start(enemy, 1000, function()
enemy:remove_sprite(attack_sprite)
enemy.attacking = false
end)
--movement
local m = sol.movement.create"straight"
m:set_max_distance(24)
m:set_speed(100)
m:set_angle(attack_angle)
m:start(enemy)
end)
end
\ No newline at end of file
local enemy = ...
local game = enemy:get_game()
local map = enemy:get_map()
local hero = map:get_hero()
local sprite
local ghost_sprite
local movement
local HAND_CHASE_DURATION = 4200
local SLAM_DISTANCE = 32
local SPEED = 127
function enemy:on_created()
sprite = enemy:create_sprite("enemies/" .. enemy:get_breed(), "main")
ghost_sprite = enemy:create_sprite("enemies/"..enemy:get_breed(), "ghost_aura")
enemy:bring_sprite_to_back(ghost_sprite)
ghost_sprite:set_color_modulation{255,255,255}
ghost_sprite:set_blend_mode"add"
--[[
function sprite:on_frame_changed(animation, frame)
frame = frame - 1
if frame <= 0 then frame = sprite:get_num_frames() - 1 end
ghost_sprite:set_frame(frame)
end
--]]
enemy:set_life(1000)
enemy:set_invincible(true)
enemy:set_pushed_back_when_hurt(false)
enemy:set_damage(2)
enemy:set_size(32,16)
enemy:set_origin(16,13)
enemy:set_attacking_collision_mode"overlapping"
enemy:set_obstacle_behavior"flying"
end
function enemy:on_restarted()
movement = sol.movement.create("target")
movement:set_target(hero)
movement:set_speed(SPEED)
movement:set_ignore_obstacles(true)
movement:start(enemy)
sol.timer.start(enemy, HAND_CHASE_DURATION, function()
sol.timer.stop_all(enemy)
enemy:stop_movement()
sprite:set_animation("slam", function() enemy:remove() end)
end)
end
function enemy:on_attacking_hero()
if enemy.slamming then return end
enemy.slamming = true
enemy:stop_movement()
sol.audio.play_sound"hero_seen"
local x,y,z = hero:get_position()
enemy:set_position(x,y+2,z)
hero:freeze()
hero:set_direction(0)
sprite:set_animation("slam", function() enemy:remove() end)
hero:set_animation("dying", function()
hero:set_visible(false)
end)
sol.timer.start(hero, 1900, function()
sol.audio.play_sound"world_warp"
local current_map = hero:get_map():get_id()
hero:teleport("respawn_map")
sol.timer.start(hero, 200, function()
hero:teleport(current_map, "from_hand_grab")
hero:set_visible(true)
hero:set_animation("stopped")
end)
hero:unfreeze()
end)
end
function enemy:on_movement_changed(movement)
local angle = movement:get_angle()
if angle > (math.pi / 2) and angle < (3 * math.pi / 2) then
sprite:set_direction(2)
ghost_sprite:set_direction(2)
else
sprite:set_direction(0)
ghost_sprite:set_direction(0)
end
end
\ No newline at end of file
local enemy = ...
local game = enemy:get_game()
local map = enemy:get_map()
local hero = map:get_hero()
local sprite
local movement
local flying = false
local THRESHOLD = 50
-- Event called when the enemy is initialized.
function enemy:on_created()
if enemy:get_property("type") then
sprite = enemy:create_sprite("enemies/misc/" .. enemy:get_property("type"))
else
sprite = enemy:create_sprite("enemies/" .. enemy:get_breed())
end
enemy:set_life(1)
enemy:set_damage(1)
enemy:set_invincible()
end
function enemy:on_restarted()
sprite:set_animation"standing"
sprite:set_direction(math.random(0,3))
enemy:check_hero()
if not flying then
sol.timer.start(enemy, math.random(200, 2000), function() enemy:choose_animation() end)
end
sol.timer.start(enemy, math.random(2000, 4000), function()
if not flying then
sprite:set_direction(math.random(0, 3))
return true
end
end)
end
function enemy:check_hero()
if enemy:is_in_same_region(hero) and enemy:get_distance(hero) <= THRESHOLD then
enemy:fly_away()
else
sol.timer.start(enemy, 100, function()
if not flying then return enemy:check_hero() end
end)
end
end
function enemy:fly_away()
flying = true
sprite:set_animation"flying"
sol.audio.play_sound"bird_flying_away"
local angle = hero:get_angle(enemy)
if angle > math.pi /2 and angle < 3 * math.pi / 2 then --hero is right of bird
angle = 2.5
else --hero is left of bird
angle = .5
end
local m = sol.movement.create("straight")
m:set_angle(angle)
m:set_speed(160)
m:set_ignore_obstacles()
m:set_max_distance(400)
enemy:set_layer(map:get_max_layer())
m:start(enemy, function() enemy:remove() end)
sprite:set_direction(m:get_direction4())
end
function enemy:choose_animation()
--animations: standing (default), bobbing, hopping, pecking
local animations = {"bobbing", "hopping", "pecking"}
local rand = math.random(1, #animations)
sprite:set_animation(animations[rand], function()
sprite:set_animation"standing"
sol.timer.start(enemy, math.random(700, 2400), function()
if not flying then enemy:choose_animation() end
end)
end)
end
local enemy = ...
local game = enemy:get_game()
local map = enemy:get_map()
local hero = map:get_hero()
local sprite
local ghost_sprite
local movement
local LIFE = 1
local SPEED = 70
local DETECTION_DIST = 180
function enemy:on_created()
sprite = enemy:create_sprite("enemies/" .. enemy:get_breed(), "main")
enemy:set_life(LIFE)
enemy:set_damage(1)
enemy:set_attacking_collision_mode"overlapping"
enemy.spawn_x, enemy.spawn_y, enemy.spawn_z = enemy:get_position()
--Ghost undersprite
ghost_sprite = enemy:create_sprite("enemies/"..enemy:get_breed(), "ghost_aura")
enemy:bring_sprite_to_back(ghost_sprite)
ghost_sprite:set_color_modulation{255,255,255}
ghost_sprite:set_blend_mode"add"
function sprite:on_frame_changed(animation, frame)
frame = frame - 1
if frame < 0 then frame = sprite:get_num_frames() - 1 end
ghost_sprite:set_frame(frame)
end
end
function enemy:on_restarted()
enemy:check_to_move()
end
function enemy:check_to_move()
if map:is_on_screen(enemy) and enemy:get_layer() == hero:get_layer()
and enemy:get_distance(hero) <= DETECTION_DIST and enemy:is_in_same_region(hero) then
--Chase hero
enemy:chase_hero()
else
enemy:go_random()
end
sol.timer.start(enemy, 200, function()
enemy:check_to_move()
end)
end
function enemy:chase_hero()
if enemy.chasing_hero then
enemy:check_for_close_enemies()
else
enemy.chasing_hero = true
local m = sol.movement.create"target"
m:set_speed(SPEED)
m:start(enemy)
end
end
function enemy:go_random()
if not enemy.chasing_hero then return end
enemy.chasing_hero = false
local m = sol.movement.create"random"
m:start(enemy)
end
function enemy:check_for_close_enemies()
local x, y, z = enemy:get_position()
local are_close_enemies = false
for e in map:get_entities_in_rectangle(x-4, y-4, 8, 8) do
if e:get_type() == "enemy" and e:get_breed() == "spider_thing" and e ~= enemy then
are_close_enemies = true
end
end
if are_close_enemies then enemy:go_random() end
end
local enemy = ...
local game = enemy:get_game()
local map = enemy:get_map()
local hero = map:get_hero()
local sprite
local ghost_sprite
local movement
local DETECTION_DISTANCE = 120
local MELEE_RANGE = 600
local CHASE_SPEED = 70
local WANDER_SPEED = 40
local WIND_UP_TIME = 500
local COOLDOWN = 1500
local SPEED = 65
function enemy:on_created()
sprite = enemy:create_sprite("enemies/" .. enemy:get_breed(), "main")
ghost_sprite = enemy:create_sprite("enemies/"..enemy:get_breed(), "ghost_aura")
enemy:bring_sprite_to_back(ghost_sprite)
ghost_sprite:set_color_modulation{255,255,255}
ghost_sprite:set_blend_mode"add"
function sprite:on_frame_changed(animation, frame)
frame = frame - 1
if frame < 0 then frame = sprite:get_num_frames() - 1 end
ghost_sprite:set_frame(frame)
end