mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-25 05:25:14 +00:00
Update 4 example mods (#205)
* Update 4 example mods * localize functions in water-level.lua
This commit is contained in:
parent
7a2550dac3
commit
80deea3b62
4 changed files with 148 additions and 48 deletions
|
@ -1,23 +1,16 @@
|
||||||
-- name: Mario RUN!
|
-- name: Mario RUN!
|
||||||
-- description: Mario is constantly running.
|
-- description: Mario is constantly running.
|
||||||
|
|
||||||
Threshold = 50 --set Threshold to 50
|
local speedThreshold = 50
|
||||||
|
|
||||||
function mario_update(m)
|
local function mario_update(m)
|
||||||
--Prevent mario from ideling
|
--Prevent mario from crouching or idling
|
||||||
if m.action == ACT_IDLE then --If idle
|
if m.action == ACT_IDLE or m.action == ACT_CROUCHING then
|
||||||
set_mario_action(m, ACT_WALKING, 0) --Make Mario walk
|
set_mario_action(m, ACT_WALKING, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
--Crouching doesnt apply vel so prevent that
|
-- Ensures that Mario moves at a speed greater than or equal to speedThreshold
|
||||||
if m.action == ACT_CROUCHING then --If crouching
|
m.forwardVel = math.max(m.forwardVel,speedThreshold)
|
||||||
set_mario_action(m, ACT_WALKING, 0) --Make Mario walk
|
|
||||||
end
|
|
||||||
|
|
||||||
--Speed floor
|
|
||||||
if (m.forwardVel > Threshold) and (m.forwardVel < Threshold) then --If Mario isn't moveing fast enough
|
|
||||||
m.forwardVel = Threshold --set forwards velocity to whatevet the threashold is set to
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- hooks --
|
-- hooks --
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
-- name: MoonJump
|
-- name: MoonJump
|
||||||
-- description: Hold the A button to Moonjump
|
-- description: Hold the A button to Moonjump
|
||||||
function mario_update(m)
|
|
||||||
if (m.controller.buttonDown & A_BUTTON) ~= 0 then --If the A button is pressed
|
local function mario_update(m)
|
||||||
|
if (m.controller.buttonDown & A_BUTTON) ~= 0 then --If the A button is held
|
||||||
m.vel.y = 25 --Set Y velocity to 25
|
m.vel.y = 25 --Set Y velocity to 25
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
-- This file is an example of how to render to the screen
|
-- This file is an example of how to render to the screen
|
||||||
|
|
||||||
rainbow = 0
|
local rainbow = 0
|
||||||
|
|
||||||
function test_text()
|
local function test_text()
|
||||||
-- set text and scale
|
-- set text and scale
|
||||||
local text = "This is example text in the bottom right."
|
local text = "This is example text in the bottom right."
|
||||||
local scale = 1
|
local scale = 1
|
||||||
|
|
||||||
-- render to native screen space, with the MENU font
|
-- render to native screen space, with the MENU font
|
||||||
djui_hud_set_resolution(RESOLUTION_DJUI);
|
djui_hud_set_resolution(RESOLUTION_DJUI)
|
||||||
djui_hud_set_font(FONT_MENU);
|
djui_hud_set_font(FONT_MENU)
|
||||||
|
|
||||||
-- get width of screen and text
|
-- get width of screen and text
|
||||||
local screenWidth = djui_hud_get_screen_width()
|
local screenWidth = djui_hud_get_screen_width()
|
||||||
|
@ -24,31 +24,23 @@ function test_text()
|
||||||
local y = screenHeight - height
|
local y = screenHeight - height
|
||||||
|
|
||||||
-- set color and render
|
-- set color and render
|
||||||
djui_hud_set_color(255, 0, 255, 255);
|
djui_hud_set_color(255, 0, 255, 255)
|
||||||
djui_hud_print_text(text, x, y, scale);
|
djui_hud_print_text(text, x, y, scale)
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_texture()
|
local function test_texture()
|
||||||
-- render to N64's screen space
|
-- render to N64's screen space
|
||||||
djui_hud_set_resolution(RESOLUTION_N64)
|
djui_hud_set_resolution(RESOLUTION_N64)
|
||||||
|
|
||||||
-- get player's character texture
|
-- get player's character texture
|
||||||
local tex = gMarioStates[0].character.hudHeadTexture
|
local tex = gMarioStates[0].character.hudHeadTexture
|
||||||
|
|
||||||
-- set scale
|
-- color and render
|
||||||
local wscale = 1
|
|
||||||
local hscale = 1
|
|
||||||
|
|
||||||
-- set position
|
|
||||||
local x = 256
|
|
||||||
local y = 64
|
|
||||||
|
|
||||||
-- set color and render
|
|
||||||
djui_hud_set_color(255, 0, 255, 255)
|
djui_hud_set_color(255, 0, 255, 255)
|
||||||
djui_hud_render_texture(tex, x, y, wscale, hscale)
|
djui_hud_render_texture(tex, 256, 64, 1, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_rect()
|
local function test_rect()
|
||||||
-- render to native screen space
|
-- render to native screen space
|
||||||
djui_hud_set_resolution(RESOLUTION_DJUI)
|
djui_hud_set_resolution(RESOLUTION_DJUI)
|
||||||
|
|
||||||
|
@ -85,15 +77,31 @@ function test_rect()
|
||||||
djui_hud_render_rect(x, y, w, h)
|
djui_hud_render_rect(x, y, w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_rainbow_text()
|
|
||||||
|
local function test_mouse()
|
||||||
|
-- render to native screen space (recommended for this)
|
||||||
|
djui_hud_set_resolution(RESOLUTION_DJUI)
|
||||||
|
|
||||||
|
-- get mouse position
|
||||||
|
local mouseX = djui_hud_get_mouse_x()
|
||||||
|
local mouseY = djui_hud_get_mouse_y()
|
||||||
|
|
||||||
|
local scale = 4
|
||||||
|
|
||||||
|
-- set color and render
|
||||||
|
djui_hud_set_color(255, 255, 255, 255)
|
||||||
|
djui_hud_render_texture(gTextures.arrow_up, mouseX, mouseY, scale, scale)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function test_rainbow_text()
|
||||||
-- this function is incredibly silly
|
-- this function is incredibly silly
|
||||||
-- don't do anything like this
|
-- don't do anything like this
|
||||||
local res = RESOLUTION_DJUI
|
local res = RESOLUTION_DJUI
|
||||||
local text = "HELLO WORLD"
|
local text = "HELLO WORLD"
|
||||||
local scale = 3
|
local scale = 3
|
||||||
|
|
||||||
djui_hud_set_resolution(res);
|
djui_hud_set_resolution(res)
|
||||||
djui_hud_set_font(FONT_NORMAL);
|
djui_hud_set_font(FONT_NORMAL)
|
||||||
|
|
||||||
for i=0,255 do
|
for i=0,255 do
|
||||||
j = rainbow / 50
|
j = rainbow / 50
|
||||||
|
@ -107,17 +115,110 @@ function test_rainbow_text()
|
||||||
g = 0
|
g = 0
|
||||||
b = 0
|
b = 0
|
||||||
end
|
end
|
||||||
djui_hud_set_color(r, g, b, i);
|
djui_hud_set_color(r, g, b, i)
|
||||||
djui_hud_print_text(text, x, y, scale);
|
djui_hud_print_text(text, x, y, scale)
|
||||||
end
|
end
|
||||||
rainbow = rainbow + 1
|
rainbow = rainbow + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_hud_render()
|
local function test_rotation()
|
||||||
|
-- render to native screen space
|
||||||
|
djui_hud_set_resolution(RESOLUTION_DJUI)
|
||||||
|
|
||||||
|
-- get SM64 global timer
|
||||||
|
local gt = get_global_timer()
|
||||||
|
|
||||||
|
-- rotate object around pivot (center)
|
||||||
|
djui_hud_set_rotation(gt * 512, 0.5, 0.5)
|
||||||
|
|
||||||
|
-- color and render
|
||||||
|
djui_hud_set_color(255, 255, 0, 128)
|
||||||
|
djui_hud_render_rect(1280, 512, 64, 64)
|
||||||
|
|
||||||
|
-- rotate object around pivot (top-left); color and render
|
||||||
|
djui_hud_set_rotation(gt * 512, 0, 0)
|
||||||
|
djui_hud_set_color(0, 255, 255, 128)
|
||||||
|
djui_hud_render_rect(1280, 512, 64, 64)
|
||||||
|
|
||||||
|
-- rotate object around pivot (bottom-right); color and render
|
||||||
|
djui_hud_set_rotation(gt * 512, 1, 1)
|
||||||
|
djui_hud_set_color(255, 0, 255, 128)
|
||||||
|
djui_hud_render_rect(1280, 512, 64, 64)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function test_filtering()
|
||||||
|
local scale = 1
|
||||||
|
|
||||||
|
-- render to N64's screen space with the MENU font
|
||||||
|
djui_hud_set_resolution(RESOLUTION_N64)
|
||||||
|
djui_hud_set_font(FONT_HUD)
|
||||||
|
djui_hud_set_color(255, 255, 255, 255)
|
||||||
|
|
||||||
|
-- get height of screen and text
|
||||||
|
local screenHeight = djui_hud_get_screen_height()
|
||||||
|
local height = 16 * scale
|
||||||
|
|
||||||
|
local y = screenHeight - height
|
||||||
|
|
||||||
|
-- set filtering and render
|
||||||
|
djui_hud_set_filter(FILTER_NEAREST)
|
||||||
|
djui_hud_print_text("NEAREST", 0, y, scale)
|
||||||
|
|
||||||
|
-- adjust position
|
||||||
|
y = y - height
|
||||||
|
|
||||||
|
-- set filtering and render
|
||||||
|
djui_hud_set_filter(FILTER_LINEAR)
|
||||||
|
djui_hud_print_text("LINEAR", 0, y, scale)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function test_world_to_screen()
|
||||||
|
-- render to N64's screen space (recommended for this)
|
||||||
|
djui_hud_set_resolution(RESOLUTION_N64)
|
||||||
|
|
||||||
|
-- reset rotation and filtering from earlier
|
||||||
|
djui_hud_set_rotation(0, 0, 0)
|
||||||
|
djui_hud_set_filter(FILTER_NEAREST)
|
||||||
|
|
||||||
|
local out = {x = 0, y = 0, z = 0}
|
||||||
|
djui_hud_world_pos_to_screen_pos(gMarioStates[0].pos,out)
|
||||||
|
|
||||||
|
-- get player's character texture
|
||||||
|
local tex = gMarioStates[0].character.hudHeadTexture
|
||||||
|
|
||||||
|
djui_hud_set_color(255, 255, 255, 255)
|
||||||
|
djui_hud_render_texture(tex, out.x, out.y, 1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function on_hud_render()
|
||||||
test_text()
|
test_text()
|
||||||
test_rect()
|
test_rect()
|
||||||
test_texture()
|
test_texture()
|
||||||
|
test_mouse()
|
||||||
test_rainbow_text()
|
test_rainbow_text()
|
||||||
|
test_rotation()
|
||||||
|
test_filtering()
|
||||||
|
test_world_to_screen()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- HOOK_ON_HUD_RENDER_BEHIND will render behind SM64's hud
|
||||||
|
local function on_hud_render_behind()
|
||||||
|
|
||||||
|
local scale = 0.5
|
||||||
|
local text = "This text renders behind SM64's HUD!"
|
||||||
|
|
||||||
|
djui_hud_set_resolution(RESOLUTION_N64)
|
||||||
|
djui_hud_set_font(FONT_RECOLOR_HUD)
|
||||||
|
|
||||||
|
local screenWidth = djui_hud_get_screen_width()
|
||||||
|
local width = djui_hud_measure_text(text) * scale
|
||||||
|
|
||||||
|
local x = screenWidth - width
|
||||||
|
|
||||||
|
djui_hud_set_color(0, 255, 255, 255)
|
||||||
|
djui_hud_print_text(text, x, 22, scale)
|
||||||
end
|
end
|
||||||
|
|
||||||
hook_event(HOOK_ON_HUD_RENDER, on_hud_render)
|
hook_event(HOOK_ON_HUD_RENDER, on_hud_render)
|
||||||
|
hook_event(HOOK_ON_HUD_RENDER_BEHIND, on_hud_render_behind)
|
||||||
|
|
|
@ -1,27 +1,32 @@
|
||||||
-- name: Water Height Changer
|
-- name: Water Height Changer
|
||||||
-- description: Use /waterset and /waterget to manipulate water height.
|
-- description: Use /waterset and /waterget to manipulate water height.
|
||||||
|
|
||||||
function on_get_command(msg)
|
local function on_get_command(msg)
|
||||||
if not network_is_server() then
|
if not network_is_server() then
|
||||||
djui_chat_message_create("You need to be the host!")
|
djui_chat_message_create("You need to be the host!")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
djui_chat_message_create(tostring(get_environment_region(1)))
|
djui_chat_message_create(tostring(get_water_level(0)))
|
||||||
djui_chat_message_create(tostring(get_environment_region(2)))
|
djui_chat_message_create(tostring(get_water_level(1)))
|
||||||
return false
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_set_command(msg)
|
local function on_set_command(msg)
|
||||||
if not network_is_server() then
|
if not network_is_server() then
|
||||||
djui_chat_message_create("You need to be the host!")
|
djui_chat_message_create("You need to be the host!")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local num = tonumber(msg)
|
local num = tonumber(msg)
|
||||||
set_environment_region(1, num)
|
if not num then
|
||||||
set_environment_region(2, num)
|
djui_chat_message_create("Not a number!")
|
||||||
return false
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
set_water_level(0, num, true)
|
||||||
|
set_water_level(1, num, true)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
hook_chat_command("waterset", "to set the first two water levels", on_set_command)
|
hook_chat_command("waterset", "to set the first two water levels", on_set_command)
|
||||||
|
|
Loading…
Reference in a new issue