canvas实现简单红斗罗游戏代码
代码语言:html
所属分类:游戏
代码描述:canvas实现简单红斗罗游戏代码。gemini3生成
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>红斗罗 (Red Contra) - HTML5 Canvas</title>
<style>
body {
margin: 0;
background-color: #1a1a1a;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
color: white;
font-family: 'Courier New', Courier, monospace;
overflow: hidden;
}
#game-container {
position: relative;
box-shadow: 0 0 20px rgba(0,0,0,0.5);
}
canvas {
background: linear-gradient(to bottom, #87CEEB, #E0F7FA); /* 天空背景 */
display: block;
}
#ui {
position: absolute;
top: 10px;
left: 10px;
font-size: 20px;
font-weight: bold;
text-shadow: 2px 2px 0 #000;
pointer-events: none;
}
#msg-screen {
position: absolute;
top: 0; left: 0; width: 100%; height: 100%;
background: rgba(0,0,0,0.8);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
display: none; /* 默认隐藏 */
}
h1 { font-size: 40px; color: #ff3333; margin-bottom: 10px; text-transform: uppercase; }
p { font-size: 18px; color: #ccc; }
button {
margin-top: 20px;
padding: 10px 20px;
background: #ff3333;
color: white;
border: none;
font-size: 20px;
cursor: pointer;
border-radius: 4px;
}
button:hover { background: #cc0000; }
.controls { position: absolute; bottom: 10px; left: 10px; font-size: 12px; color: #555; }
</style>
</head>
<body>
<div id="game-container">
<div id="ui">
HP: <span id="hp-val" style="color:#f00">|||||</span>
SCORE: <span id="score-val">0</span>
</div>
<canvas id="gameCanvas" width="800" height="450"></canvas>
<div id="msg-screen">
<h1 id="msg-title">GAME OVER</h1>
<p id="msg-desc">任务失败</p>
<button onclick="resetGame()">重新挑战</button>
</div>
.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0