minetest/games/devtest/mods/soundstuff/racecar.lua
SFENCE af3f696423
Some checks are pending
android / build (push) Waiting to run
cpp_lint / clang_tidy (push) Waiting to run
linux / gcc_7 (push) Waiting to run
linux / gcc_14 (push) Waiting to run
linux / clang_7 (push) Waiting to run
linux / clang_18 (push) Waiting to run
linux / clang_11 (PROMETHEUS=1) (push) Waiting to run
lua_lint / Compile and run multiplayer tests (push) Waiting to run
lua_lint / Builtin Luacheck and Unit Tests (push) Waiting to run
macos / build-intel-macos (push) Waiting to run
macos / build-arm-macos-xcode (push) Waiting to run
png_file_checks / png_optimized (push) Waiting to run
whitespace_checks / trailing_whitespaces (push) Waiting to run
whitespace_checks / indent_spaces (push) Waiting to run
whitespace_checks / tabs_lua_api_files (push) Waiting to run
windows / MinGW cross-compiler (${{ matrix.bits }}-bit) (32) (push) Waiting to run
windows / MinGW cross-compiler (${{ matrix.bits }}-bit) (64) (push) Waiting to run
windows / VS 2019 ${{ matrix.config.arch }}-${{ matrix.type }} (map[arch:x64 generator:-G'Visual Studio 16 2019' -A x64 vcpkg_triplet:x64-windows], portable) (push) Waiting to run
windows / VS 2019 ${{ matrix.config.arch }}-${{ matrix.type }} (map[arch:x86 generator:-G'Visual Studio 16 2019' -A Win32 vcpkg_triplet:x86-windows], portable) (push) Waiting to run
Code style fixes.
2025-01-21 16:29:12 +01:00

32 lines
914 B
Lua

local drive_speed = 20
local drive_distance = 30
core.register_entity("soundstuff:racecar", {
initial_properties = {
physical = false,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
visual = "upright_sprite",
visual_size = {x = 1, y = 1, z = 1},
textures = {"soundstuff_racecar.png", "soundstuff_racecar.png^[transformFX"},
static_save = false,
},
on_activate = function(self, _staticdata, _dtime_s)
self.min_x = self.object:get_pos().x - drive_distance * 0.5
self.max_x = self.min_x + drive_distance
self.vel = vector.new(drive_speed, 0, 0)
end,
on_step = function(self, _dtime, _moveresult)
local pos = self.object:get_pos()
if pos.x < self.min_x then
self.vel = vector.new(drive_speed, 0, 0)
elseif pos.x > self.max_x then
self.vel = vector.new(-drive_speed, 0, 0)
end
self.object:set_velocity(self.vel)
end,
})