logo
0
0
WeChat Login
cnb<cnb@cnb.cool>
Initial commit: Enhanced King of the Grassland with NPC lions and wolf spawning system

🦁 草原之王 - 增强版多人联机游戏

一个基于 Node.js 和 Socket.io 的实时多人合作狩猎游戏,玩家扮演狮子在草原上协同捕猎并分享猎物。

🎮 游戏特色

🦁 多人合作狩猎

  • 最多支持 5 名玩家同时在线
  • 房间制系统,玩家可创建或加入房间
  • 团队合作捕猎,共享积分系统
  • 实时同步所有玩家位置和游戏状态

🎯 增强游戏机制

  • 体力系统: 狮子移动消耗体力,静止时恢复
  • 饥饿系统: 捕获猎物恢复饥饿值,饥饿影响移动速度
  • 动物群体: 山羊和野猪成群出现,增加策略性
  • 黄金山羊: 稀有猎物,提供额外奖励积分
  • 智能AI: 猎物会逃避狮子,增加挑战性

🖱️ 现代化控制

  • 鼠标控制: 点击移动到目标位置
  • 键盘控制: WASD 或方向键移动
  • 混合操作: 支持鼠标和键盘同时使用

📊 高级用户界面

  • 可折叠记分板: 显示所有玩家统计信息
  • 状态栏: 实时显示体力和饥饿值
  • 游戏事件: 捕获猎物时的视觉反馈
  • 动物计数: 实时显示场上动物数量

🚀 快速开始

📋 环境要求

  • Node.js 14.0 或更高版本
  • npm 包管理器
  • 现代浏览器(支持 HTML5 Canvas)

🔧 安装步骤

  1. 克隆项目
git clone https://cnb.cool/wdracky/lionking.git cd lionking
  1. 安装依赖
npm install
  1. 启动服务器
npm start
  1. 开始游戏 打开浏览器访问: http://localhost:3004

📁 项目结构

lionking/ ├── server.js # 游戏服务器主文件 ├── package.json # 项目配置和依赖 ├── README.md # 项目文档 ├── public/ # 客户端文件 │ ├── index.html # 游戏主页面 │ ├── game.js # 客户端游戏逻辑 │ ├── style.css # 游戏样式 │ └── pics/ # 游戏素材 │ ├── background.png # 草原背景 │ ├── lion.png # 狮子精灵图 │ ├── goat.png # 山羊精灵图 │ └── pig.png # 野猪精灵图 └── index_just_web_demo.html # 单机版演示

🎯 游戏玩法

🦁 基础操作

  • 移动: 鼠标点击或 WASD/方向键
  • 捕猎: 接触猎物自动捕获
  • 合作: 与队友协同围捕猎物

📊 游戏机制

  • 体力值: 移动消耗体力,影响移动速度
  • 饥饿值: 捕获猎物恢复,饥饿时移动变慢
  • 团队积分: 所有玩家共享捕猎积分
  • 动物刷新: 自动补充场上动物数量

🏆 积分系统

  • 🐐 普通山羊: 10 分
  • 🐷 野猪: 15 分
  • 黄金山羊: 50 分
  • 🍖 饥饿恢复: 积分 × 10

🛠️ 技术架构

🔧 后端技术

  • Node.js: 服务器运行环境
  • Express: Web 框架
  • Socket.io: 实时通信
  • 房间系统: 多房间管理

🎨 前端技术

  • HTML5 Canvas: 游戏渲染
  • JavaScript ES6+: 客户端逻辑
  • CSS3: 界面样式
  • 精灵动画: 基于帧的动画系统

性能特性

  • 60 FPS: 流畅游戏体验
  • 实时同步: 低延迟状态更新
  • 优化渲染: 高效 Canvas 绘制
  • 内存管理: 智能对象池

🔧 开发信息

📝 主要文件说明

server.js - 游戏服务器

  • Lion 类:玩家狮子实体管理
  • Prey 类:猎物实体和 AI 行为
  • 房间系统:多房间玩家管理
  • 游戏循环:60Hz 游戏状态更新
  • 增强功能:动物计数修复,体力饥饿系统

public/game.js - 客户端逻辑

  • 游戏渲染:Canvas 绘制和动画
  • 输入处理:鼠标和键盘控制
  • UI 管理:记分板和状态显示
  • 网络通信:Socket.io 客户端
  • 修复功能:房间加入,动物显示尺寸

public/index.html - 游戏界面

  • 响应式布局:适配不同屏幕
  • 游戏 Canvas:800×600 游戏区域
  • 控制面板:房间管理和游戏信息
  • 黑客松页脚:CodeBuddy 和 CloudBase 链接

🐛 已修复问题

  • ✅ 动物生成系统:游戏开始即刷新动物
  • ✅ 动物计数修复:山羊/野猪统计正确显示
  • ✅ 动物显示优化:48×48 像素完整显示
  • ✅ 房间加入功能:客户端-服务器通信修复
  • ✅ 饥饿恢复平衡:积分 × 10 提升游戏体验

🎮 游戏平衡调整

  • 体力消耗:移动时适度消耗
  • 饥饿影响:饥饿时速度降低 50%
  • 动物AI:智能逃避增加挑战
  • 积分奖励:黄金山羊高价值奖励

🌟 项目亮点

🏆 技术创新

  • 混合控制系统: 鼠标点击 + 键盘操作
  • 智能动物AI: 逃避行为和群体移动
  • 实时状态同步: 低延迟多人游戏体验
  • 可扩展架构: 易于添加新功能

🎨 用户体验

  • 直观界面: 清晰的游戏信息显示
  • 流畅动画: 60FPS 精灵动画系统
  • 视觉反馈: 捕获猎物的即时反馈
  • 团队合作: 鼓励玩家协同作战

🔧 代码质量

  • 模块化设计: 清晰的代码结构
  • 错误处理: 完善的异常处理机制
  • 性能优化: 高效的游戏循环和渲染
  • 可维护性: 良好的代码注释和文档

🤝 贡献与支持

🛠️ 开发工具

  • CodeBuddy: AI 辅助编程工具
  • CloudBase: 腾讯云开发平台
  • Socket.io: 实时通信框架
  • Node.js: 服务器运行环境

📞 技术支持


🏆 黑客松项目

本项目使用以下技术和平台开发:

草原之王 - 体验多人合作狩猎的乐趣!🦁✨


🦁 King of the Grassland - Enhanced Multiplayer Game

A real-time multiplayer cooperative hunting game built with Node.js and Socket.io, where players control lions to hunt together and share prey on the grassland.

🎮 Game Features

🦁 Multiplayer Cooperative Hunting

  • Support up to 5 players online simultaneously
  • Room-based system for creating and joining games
  • Team cooperation for hunting with shared scoring
  • Real-time synchronization of all player positions and game states

🎯 Enhanced Game Mechanics

  • Stamina System: Lions consume stamina while moving, recover when idle
  • Hunger System: Catching prey restores hunger, hunger affects movement speed
  • Animal Herds: Goats and pigs appear in groups for strategic gameplay
  • Golden Goats: Rare prey providing bonus points
  • Smart AI: Prey animals flee from lions, adding challenge

🖱️ Modern Controls

  • Mouse Control: Click to move to target position
  • Keyboard Control: WASD or arrow keys for movement
  • Hybrid Operation: Support both mouse and keyboard simultaneously

📊 Advanced User Interface

  • Collapsible Scoreboard: Display all player statistics
  • Status Bars: Real-time stamina and hunger indicators
  • Game Events: Visual feedback when catching prey
  • Animal Counter: Live count of animals on the field

🚀 Quick Start

📋 Requirements

  • Node.js 14.0 or higher
  • npm package manager
  • Modern browser with HTML5 Canvas support

🔧 Installation

  1. Clone the project
git clone https://cnb.cool/wdracky/lionking.git cd lionking
  1. Install dependencies
npm install
  1. Start the server
npm start
  1. Play the game Open browser and visit: http://localhost:3004

📁 Project Structure

lionking/ ├── server.js # Main game server file ├── package.json # Project config and dependencies ├── README.md # Project documentation ├── public/ # Client-side files │ ├── index.html # Main game page │ ├── game.js # Client game logic │ ├── style.css # Game styles │ └── pics/ # Game assets │ ├── background.png # Grassland background │ ├── lion.png # Lion sprite │ ├── goat.png # Goat sprite │ └── pig.png # Pig sprite └── index_just_web_demo.html # Single-player demo

🎯 Gameplay

🦁 Basic Controls

  • Movement: Mouse click or WASD/Arrow keys
  • Hunting: Automatic capture when touching prey
  • Cooperation: Coordinate with teammates to surround prey

📊 Game Mechanics

  • Stamina: Movement consumes stamina, affects speed
  • Hunger: Catching prey restores hunger, hunger slows movement
  • Team Score: All players share hunting points
  • Animal Respawn: Automatic replenishment of animals on field

🏆 Scoring System

  • 🐐 Regular Goat: 10 points
  • 🐷 Pig: 15 points
  • Golden Goat: 50 points
  • 🍖 Hunger Recovery: Points × 10

🛠️ Technical Architecture

🔧 Backend Technologies

  • Node.js: Server runtime environment
  • Express: Web framework
  • Socket.io: Real-time communication
  • Room System: Multi-room management

🎨 Frontend Technologies

  • HTML5 Canvas: Game rendering
  • JavaScript ES6+: Client-side logic
  • CSS3: Interface styling
  • Sprite Animation: Frame-based animation system

Performance Features

  • 60 FPS: Smooth gaming experience
  • Real-time Sync: Low-latency state updates
  • Optimized Rendering: Efficient Canvas drawing
  • Memory Management: Smart object pooling

🔧 Development Information

📝 Key File Descriptions

server.js - Game Server

  • Lion class: Player lion entity management
  • Prey class: Prey entities and AI behavior
  • Room system: Multi-room player management
  • Game loop: 60Hz game state updates
  • Enhanced features: Animal counting fixes, stamina/hunger system

public/game.js - Client Logic

  • Game rendering: Canvas drawing and animation
  • Input handling: Mouse and keyboard controls
  • UI management: Scoreboard and status display
  • Network communication: Socket.io client
  • Fixed features: Room joining, animal display size

public/index.html - Game Interface

  • Responsive layout: Adapt to different screens
  • Game Canvas: 800×600 game area
  • Control panel: Room management and game info
  • Hackathon footer: CodeBuddy and CloudBase links

🐛 Fixed Issues

  • ✅ Animal spawning system: Animals spawn immediately at game start
  • ✅ Animal counting fix: Goat/pig statistics display correctly
  • ✅ Animal display optimization: 48×48 pixels for full visibility
  • ✅ Room joining functionality: Client-server communication fixed
  • ✅ Hunger recovery balance: Points × 10 for better gameplay

🎮 Game Balance Adjustments

  • Stamina consumption: Moderate consumption during movement
  • Hunger effects: 50% speed reduction when hungry
  • Animal AI: Smart evasion adds challenge
  • Score rewards: High-value golden goat rewards

🌟 Project Highlights

🏆 Technical Innovation

  • Hybrid Control System: Mouse click + keyboard operation
  • Smart Animal AI: Evasion behavior and herd movement
  • Real-time State Sync: Low-latency multiplayer experience
  • Scalable Architecture: Easy to add new features

🎨 User Experience

  • Intuitive Interface: Clear game information display
  • Smooth Animation: 60FPS sprite animation system
  • Visual Feedback: Instant feedback when catching prey
  • Team Cooperation: Encourages collaborative gameplay

🔧 Code Quality

  • Modular Design: Clear code structure
  • Error Handling: Comprehensive exception handling
  • Performance Optimization: Efficient game loop and rendering
  • Maintainability: Good code comments and documentation

🤝 Contribution & Support

🛠️ Development Tools

  • CodeBuddy: AI-assisted programming tool
  • CloudBase: Tencent Cloud development platform
  • Socket.io: Real-time communication framework
  • Node.js: Server runtime environment

📞 Technical Support


🏆 Hackathon Project

This project was developed using the following technologies and platforms:

King of the Grassland - Experience the joy of multiplayer cooperative hunting! 🦁✨

About

草原狮王小游戏

Language
JavaScript42.4%
TypeScript36.1%
Markdown19.1%
License1.3%
Others1.1%