Lv.1
在 【神岛仿MC】仿Minecraft Java Edition 进度:0.0025% 中回复
<!DOCTYPEhtml> <htmllang="en"> <head> <metacharset="UTF-8"> <metaname="viewport"content="width=device-width,initial-scale=1.0"> <title>MinecraftStyle3D</title> <style> body{margin:0;} canvas{display:block;} </style> </head> <body> <scriptsr喵ajax/libs/three.js/r128/three.min.js"></script> <script> //设置场景、相机和渲染器 constscene=newTHREE.Scene(); constcamera=newTHREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,0.1,1000); constrenderer=newTHREE.WebGLRenderer(); renderer.setSize(window.innerWidth,window.innerHeight); document.body.appendChild(renderer.domElement); //创建一个立方体 constgeometry=newTHREE.BoxGeometry(); constmaterial=newTHREE.MeshBasicMaterial({color:0x00ff00}); constcube=newTHREE.Mesh(geometry,material); scene.add(cube); //移动相机 camera.position.z=5; //动画循环 functionanimate(){ requestAnimationFrame(animate); cube.rotation.x+=0.01; cube.rotation.y+=0.01; renderer.render(scene,camera); } animate(); //处理窗口大小调整 window.addEventListener('resize',()=>{ camera.aspect=window.innerWidth/window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth,window.innerHeight); }); </script> </body> </html>
2024-08-28T15:00:39 点赞:0
在 【岛3代码入门01】建造方块用代码怎么写? 中回复
// 设置方块类型
function createVoxel(x, y, z, type) {
voxels.setVoxel(x, y, z, type);
}
// 创建柱子
function createColumn(x, baseY, height, type) {
for (var y = baseY; y < baseY + height; y++) {
createVoxel(x, y, 喵, type);
}
}
// 创建墙
function createWall(startX, baseY, height, width, type) {
for (var y = baseY; y < baseY + height; y++) {
for (var x = startX; x < startX + width; x++) {
createVoxel(x, y, 喵, type);
}
}
}
// 创建立方体
function createCube(startX, startY, startZ, dimensions, type) {
var width = dimensions.width;
var height = dimensions.height;
var depth = dimensions.depth;
for (var x = startX; x < startX + width; x++) {
for (var y = startY; y < startY + height; y++) {
for (var z = startZ; z < startZ + depth; z++) {
createVoxel(x, y, z, type);
}
}
}
}
// 创建空心立方体
function createHollowCube(sx, sy, sz, dimensions, fillType) {
createCube(sx, sy, sz, dimensions, fillType);
var hollowDimensions = {
width: dimensions.width - 2,
height: dimensions.height - 2,
depth: dimensions.depth - 2
};
createCube(sx + 1, sy + 1, sz + 1, hollowDimensions, '');
}
// 使用函数生成结构
createVoxel(喵, 9, 喵, 'stone');
createColumn(喵, 9, 10, 'stone');
createWall(喵, 9, 10, 10, 'stone');
createCube(喵, 9, 喵, { width: 10, height: 10, depth: 10 }, 'stone');
createHollowCube(63, 9, 63, { width: 10, height: 10, depth: 10 }, 'stone');
2024-08-28T15:14:23 点赞:0
在 【求助】【Box3(旧版)】求天气转换代码 中回复
async function getWeather() {
try {
// 模拟一个 API 请求返回的天气数据
const weatherData = await fetchWeatherData();
// 根据天气数据进行转换
const weatherMessage = convertWeatherData(weatherData);
// 输出结果
console.log(weatherMessage);
} catch (error) {
console.error('获取天气失败:', error);
}
}
// 模拟从 API 获取天气数据的函数
async function fetchWeatherData() {
// 这里返回模拟数据,实际应用中应替换为真实的 API 调用
return new Promise((resolve) => {
setTimeout(() => {
resolve({
temperature: 28, // 温度
condition: '晴朗' // 天气状况
});
}, 1000);
});
}
// 根据天气数据转换成可读的信息
function convertWeatherData(data) {
let message = `当前温度:${data.temperature}°C,天气情况:${data.condition}`;
// 根据天气情况生成不同的输出
if (data.condition.includes('晴朗')) {
message += ' 🌞今天天气不错,适合外出!';
} else if (data.condition.includes('雨')) {
message += ' 🌧️请记得带上雨具!';
} else if (data.condition.includes('多云')) {
message += ' ⛅今天是个多云的日子!';
} else {
message += ' 🌈有些特别的天气,请注意!';
}
return message;
}
// 启动获取天气的过程
getWeather();
2024-08-28T15:16:24 点赞:0
在 怎么让玩家到终点后获得飞行 中回复
// 遍历所有实体,设置存档点和奖杯的碰撞逻辑
for (const e of world.querySelectorAll('*')) {
// 检查是否是存档点
if (e.id.startsWith('存档点')) {
e.collides = true; // 开启碰撞
e.fixed = true; // 固定实体不被推移
e.meshScale = e.meshScale.scale(1); // 放大1倍
// 为存档点添加碰撞检测
e.onEntityContact(({ other }) => {
if (other.isPlayer) { // 如果另一个实体是玩家
if (e.position !== other.player.spawnPoint) {
other.player.canFly = true; // 允许玩家飞行
other.player.directMessage('恭喜你到达终点!获得飞行特权!'); // 给玩家发消息
}
}
});
}
// 检查是否是奖杯
if (e.id === '奖杯') {
e.collides = true; // 开启碰撞
// 为奖杯添加碰撞检测
world.onEntityContact(({ entity, other }) => {
if (entity.isPlayer) { // 如果发起碰撞的实体是玩家
if (other.id === '奖杯') { // 如果碰撞中的另一个实体是奖杯
entity.player.canFly = true; // 允许玩家飞行
world.say(entity.player.name + '通关了跑酷!'); // 广播通关消息
setTimeout(() => {
entity.player.canFly = true; // 激活飞行特权
}, 2000); // 2秒后允许飞行
}
}
});
}
}
2024-08-28T15:20:22 点赞:0
在 怎么让玩家到终点后获得飞行 中回复
// 遍历所有实体,设置存档点和奖杯的碰撞逻辑 for (const e of world.querySelectorAll('*')) { // 检查是否是存档点 if (e.id.startsWith('存档点')) { e.collides = true; // 开启碰撞 e.fixed = true; // 固定实体不被推移 e.meshScale = e.meshScale.scale(1); // 放大1倍 // 为存档点添加碰撞检测 e.onEntityContact(({ other }) => { if (other.isPlayer) { // 如果另一个实体是玩家 if (e.position !== other.player.spawnPoint) { other.player.canFly = true; // 允许玩家飞行 other.player.directMessage('恭喜你到达终点!获得飞行特权!'); // 给玩家发消息 } } }); } // 检查是否是奖杯 if (e.id === '奖杯') { e.collides = true; // 开启碰撞 // 为奖杯添加碰撞检测 world.onEntityContact(({ entity, other }) => { if (entity.isPlayer) { // 如果发起碰撞的实体是玩家 if (other.id === '奖杯') { // 如果碰撞中的另一个实体是奖杯 entity.player.canFly = true; // 允许玩家飞行 world.say(entity.player.name + '通关了跑酷!'); // 广播通关消息 setTimeout(() => { entity.player.canFly = true; // 激活飞行特权 }, 2000); // 2秒后允许飞行 } } }); } }
2024-08-28T15:20:56 点赞:0
在 c++而简单加密 中回复
#include <iostream>
#include <string>
#include <functional>
int main() {
std::string input;
std::cout << "Enter a string to hash: ";
std::getline(std::cin, input);
std::hash<std::string> hash_fn;
size_t hash = hash_fn(input);
std::cout << "Hash value: " << hash << std::endl;
return 0;
}
2024-08-30T15:40:28 点赞:0
在 c++而简单加密 中回复
#include <iostream>
#include <openssl/sha.h>
#include <iomanip>
#include <sstream>
std::string sha256(const std::string str) {
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, str.c_str(), str.size());
SHA256_Final(hash, &sha256);
std::ostringstream oss;
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
oss << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i];
}
return oss.str();
}
int main() {
std::string input;
std::cout << "Enter a string to hash with SHA-256: ";
std::getline(std::cin, input);
std::string hash = sha256(input);
std::cout << "SHA-256 Hash: " << hash << std::endl;
return 0;
}
2024-08-30T15:41:06 点赞:0
在 【Python作品分享】fps射击游戏【求助帖】 中回复
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from ursina.shaders import lit_with_喵s_shader
import random
app = Ursina()
Entity.default_shader = lit_with_喵s_shader
DirectionalLight(y=1, rotation=(0, 0, 0))
Sky()
ground = Entity(model="plane", collider="box", scale=64, texture="grass")
# 生成随机物体
for _ in range(16):
Entity(model="cube", scale=2, texture="brick",
texture_scale=(1, 2),
x=random.uniform(-8, 8),
z=random.uniform(-8, 8) + 8,
collider="box",
scale_y=random.uniform(2, 3),
origin_y=-0.5)
editor_camera = EditorCamera(enabled=False)
def input_pause(key):
if key == "tab":
editor_camera.enabled = not editor_camera.enabled
mouse.locked = not editor_camera.enabled
player.cursor.enabled = not editor_camera.enabled
player.visible_self = editor_camera.enabled
editor_camera.position = player.position
pause_handler = Entity(input=input_pause)
player = FirstPersonController(model="cube", color=color.orange, z=-10, origin_y=-0.5, speed=8, collider="box")
gun = Entity(model="cube", parent=camera, scale=(0.2, 0.2, 0.5), position=(0.5, -0.25, 0.5), color=color.red, on_cooldown=False)
gun.flash = Entity(parent=gun, model="quad", z=1, color=color.yellow, enabled=False)
def shoot():
if not gun.on_cooldown:
gun.on_cooldown = True
gun.flash.enabled = True
from ursina.prefabs.ursfx import ursfx
ursfx([(0.0, 0.0), (0.1, 0.9), (0.15, 0.75), (0.3, 0.14), (0.6, 0.0)], volume=0.5, wave="noise",
pitch=random.uniform(-13, -12), pitch_change=-12, speed=3.0)
invoke(gun.flash.disable, delay=0.15)
invoke(setattr, gun, 'on_cooldown', False, delay=0.15)
if mouse.hovered_entity and hasattr(mouse.hovered_entity, "hp"):
hit_enemy(mouse.hovered_entity)
def hit_enemy(enemy):
enemy.blink(color.red)
enemy.hp -= 10
if enemy.hp <= 0:
destroy(enemy)
enemy.health_bar.scale_x = enemy.hp / enemy.max_hp * 1.5
def update():
if held_keys["left mouse"]:
shoot()
class Enemy(Entity):
def __init__(self, add_to_scene_entities=True, **kwargs):
super().__init__(add_to_scene_entities,
model="cube", collider="box",
scale_y=2, origin_y=-0.5,
color=color.light_gray, **kwargs)
self.health_bar = Entity(parent=self, model="cube", color=color.red, y=1.2,
scale=(1.5, 0.1, 0.1))
self.max_hp = 100
self.hp = self.max_hp
def update(self):
self.look_at_2d(player.position, "y")
hit_info = raycast(self.position + Vec3(0, 1, 0), self.forward, 30, ignore=(self,), debug=False)
if hit_info.entity == player:
if distance_xz(self.position, player.position) > 2:
self.position += self.forward * time.dt * 5
# 随机生成敌人
for _ in range(8):
Enemy(x=random.uniform(-8, 8), z=random.uniform(-8, 8))
app.run()
2024-09-28T18:50:23 点赞:0