phaser实现食物保持新鲜防止腐败跳跳闯关游戏代码
代码语言:html
所属分类:游戏
代码描述:phaser实现食物保持新鲜防止腐败跳跳闯关游戏代码,游戏目标 在不腐烂的前提下,完成全部 5 个关卡。 操作控制 移动:使用方向键或 WASD 键,控制角色左右移动。 跳跃:使用上方向键、W 键或空格键,控制角色跳跃。 新鲜度机制 角色会随时间持续腐烂,需时刻关注新鲜度计量表,避免新鲜度降至 0%。 道具与规避物 可收集的增益道具 冰袋(Ice Packs):恢复 15% 新鲜度。 发胶(Hairspray):恢复 25% 新鲜度。 需规避的有害事物 阳光射线(Sun Rays):加速腐烂,新鲜度减少
代码标签: phaser 食物 保持 新鲜 防止 腐败 跳跳 闯关 游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Comic Sans MS", "Arial", sans-serif;
background: linear-gradient(to bottom, #ff9a56 0%, #ff6b35 100%);
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
#gameContainer {
position: relative;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
border-radius: 15px;
overflow: hidden;
}
#menu {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(255, 154, 86, 0.95);
padding: 40px;
border-radius: 20px;
border: 5px solid #8b4513;
text-align: center;
color: #ffffff;
z-index: 1000;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
max-width: 500px;
}
#menu h1 {
font-size: 48px;
margin-bottom: 10px;
text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
color: #fff;
}
#menu .pumpkin-emoji {
font-size: 64px;
margin: 10px 0;
}
#menu p {
font-size: 18px;
margin-bottom: 25px;
line-height: 1.6;
color: rgba(255, 255, 255, 0.95);
}
#menu button {
font-family: "Comic Sans MS", "Arial", sans-serif;
font-size: 24px;
font-weight: bold;
padding: 15px 40px;
margin: 10px;
background: #8b4513;
color: white;
border: 3px solid #5a2d0c;
border-radius: 15px;
cursor: pointer;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
transition: all 0.2s;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
#menu button:hover {
background: #a0522d;
transform: scale(1.05);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}
#menu button:active {
transform: scale(0.95);
}
.hidden {
display: none !important;
}
#ui {
position: absolute;
top: 20px;
left: 20px;
color: white;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
font-size: 20px;
font-weight: bold;
z-index: 100;
pointer-events: none;
}
#rotMeter {
position: absolute;
top: 20px;
right: 20px;
width: 250px;
z-index: 100;
pointer-events: none;
}
#rotMeter .label {
color: white;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
font-size: 18px;
font-weight: bold;
margin-bottom: 5px;
}
#rotMeter .bar-container {
background: rgba(0, 0, 0, 0.5);
border: 3px solid rgba(255, 255, 255, 0.8);
border-radius: 10px;
padding: 5px;
height: 35px;
}
#rotMeter .bar {
background: linear-gradient(to right, #ff4444, #ffaa00, #44ff44);
height: 100%;
border-radius: 5px;
transition: width 0.3s ease;
box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}
#socialLinks {
margin-top: 20px;
font-size: 14px;
}
#socialLinks a {
color: rgba(255, 255, 255, 0.9);
text-decoration: none;
margin: 0 8px;
transition: all 0.2s;
}
#socialLinks a:hover {
color: #fff;
text-decoration: underline;
}
#instructions {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 15px 30px;
border-radius: 10px;
border: 2px solid rgba(255, 255, 255, 0.4);
font-size: 16px;
text-align: center;
z-index: 100;
pointer-events: none;
}
</style>
</head>
<body translate="no">
<div id="gameContainer"></div>
<div id="menu">
<h1>DON'T LET ME ROT</h1>
<p>
You're a jack-o'-lantern racing against time!<br>
Collect preservatives to stay fresh.<br>
Avoid hazards that speed up decay.<br>
<strong>How long can you survive?</strong>
</p>
<button id="startBtn">START ROTTING</button>
<button id="howToPlayBtn">HOW TO PLAY</button>
<button id="highScoresBtn">HIGH SCORES</button>
</div>
<div id="ui" class="hidden">
<div>Score: <span id="scoreValue">0</span></div>
<div>Level: <span id="levelValue">1</span></div>
<div>Lives: <span id="livesValue">3</span></div>
</div>
<div id="rotMeter" class="hidden">
<div class="label">Freshness</div>
<div class="bar-container">
<div class="bar" id="rotBar" style="width: 100%"></div>
</div>
</div>
<div id="instructions" class="hidden">
Arrow Keys or WASD to Move • Up or Space to Jump • Collect Ice Packs to Stay Fresh!
</div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/phaser.3.80.1.js"></script>
<script >
let game;
let gameScene;
const config = {
type: Phaser.AUTO,
width: 1200,
height: 700,
parent: "gameContainer",
backgroundColor: "#5C94FC",
physics: {
default: "arcade",
arcade: {
gravity: { y: 1000 },
debug: false,
},
},
scene: {
preload: preload,
create: create,
update: update,
},
};
const WORLD_WIDTH = 3600;
const WORLD_HEIGHT = 700;
// Game state
let player;
let platforms;
let collectibles;
let hazards;
let cursors;
let score = 0;
let lives = 3; // Player gets 3 lives
let currentLevel = 1; // Start on level 3 for testing
let freshness = 100; // Health (100 = fresh, 0 = completely rotten)
let rotSpeed = 0.05; // How fast the pumpkin rots per frame
let gameActive = false;
let groundLevel;
let clouds;
let goalPortal; // Level completion portal
// High scores (stored in localStorage)
const MAX_HIGH_SCORES = 10;
function getHighScores() {
const scores = localStorage.getItem('pumpkinHighScores');
return scores ? JSON.parse(scores) : [];
}
function saveHighScore(playerScore, playerLevel, playerLives) {
const highScores = getHighScores();
const newScore = {
score: playerScore,
level: playerLevel,
lives: playerLives,
date: new Date().toLocaleDateString()
};
highScores.push(newScore);
highScores.sort((a, b) => b.score - a.score);
highScores.splice(MAX_HIGH_SCORES); // Keep only top 10
localStorage.setItem('pumpkinHighScores', JSON.stringify(highScores));
return highScores.findIndex(s => s === newScore) + 1; // Return rank (1-based)
}
function preload() {
// No external assets needed - we'll draw everything with graphics!
}
function createTextures(scene) {
// Create ice collectible texture
const iceGraphics = scene.add.graphics();
iceGraphics.fillStyle(0x00ffff);
iceGraphics.lineStyle(4, 0x000000);
iceGraphics.fillCircle(16, 16, 15);
iceGraphics.strokeCircle(16, 16, 15);
iceGraphics.fillStyle(0xffffff);
iceGraphics.fillCircle(12, 12, 5);
iceGraphics.lineStyle(2, 0xffffff);
iceGraphics.beginPath();
iceGraphics.moveTo(10, 10);
iceGraphics.lineTo(22, 22);
iceGraphics.strokePath();
iceGraphics.beginPath();
iceGraphics.moveTo(10, 22);
iceGraphics.lineTo(22, 10);
iceGraphics.strokePath();
iceGraphics.generateTexture("ice", 32, 32);
iceGraphics.destroy();
// Create spray collectible texture
const sprayGraphics = scene.add.graphics();
sprayGraphics.fillStyle(0xff1493);
sprayGraphics.lineStyle(4, 0x000000);
sprayGraphics.fillEllipse(16, 20, 24, 30);
sprayGraphics.strokeEllipse(16, 20, 24, 30);
sprayGraphics.fillStyle(0xffffff);
sprayGraphics.lineStyle(3, 0x000000);
sprayGraphics.fillRect(8, 2, 16, 10);
sprayGraphics.strokeRect(8, 2, 16, 10);
sprayGraphics.fillStyle(0xffffff);
sprayGraphics.fillCircle(10, 25, 3);
sprayGraphics.fillCircle(22, 15, 3);
sprayGraphics.generateTexture("spray", 32, 40);
sprayGraphics.destroy();
// Create sun hazard texture
const sunGraphics = scene.add.graphics();
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
sunGraphics.fillStyle(0xffd700);
sunGraphics.lineStyle(2, 0x000000).........完整代码请登录后点击上方下载按钮下载查看
















网友评论0