Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zm50 committed Jan 2, 2024
1 parent cb704a3 commit e131afd
Show file tree
Hide file tree
Showing 43 changed files with 673 additions and 432 deletions.
5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

59 changes: 59 additions & 0 deletions assets/style/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
body {
margin: 0;
padding: 0;
background-image: url("3.jpg");
}

header {
position: fixed;
top: 0;
width: 100%;
}

nav {
background-color: #555;
padding: 15px;
text-align: center;
box-shadow: 0 5px 4px rgba(0, 0, 0, 0.3);
}

nav a {
text-decoration: none;
color: white;
padding: 15px;
}

nav a:hover {
background-color: #16c4ef;
color: black;
}

section {
margin: 100px;
}

article {
background-color: rgba(255, 255, 255, 0.8);
border-radius: 30px;
padding: 100px;
margin-bottom: 60px;
box-shadow: 0 10px 4px rgba(0, 0, 0, 0.3);
}

h2 {
text-align: center;
}

footer {
background-color: #555;
color: #fff;
padding: 10px;
text-align: center;
}

.tips {
width: 200px;
height: auto;
margin-left: 30px;
margin-right: 30px;
}
25 changes: 25 additions & 0 deletions code/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/assets/img/favicon.ico">
<link rel="stylesheet" type="text/css" href="/assets/style/style.css">
<title>醉墨编程</title>
</head>
<header>
<nav>
<a href="/">网站首页</a>
<a href="/code">编程空间</a>
<a href="/game">在线游戏</a>
<a href="/tool">在线工具</a>
<a href="/tips">充电打赏</a>
</nav>
</header>

<body>

</body>

</html>
16 changes: 8 additions & 8 deletions plane/game/flush.js → game/plane/game/flush.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function flush() {
if (player.gameIsOver) {
return
}
player.update()
updateBullet()
updateRocks()
requestAnimationFrame(flush)
function flush() {
if (player.gameIsOver) {
return
}
player.update()
updateBullet()
updateRocks()
requestAnimationFrame(flush)
}
56 changes: 28 additions & 28 deletions plane/game/init.js → game/plane/game/init.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
var win = document.getElementById('win')
var score = document.getElementById('score')
var hp = document.getElementById('hp')

var PERFIX_SRC = 'https://go75.github.io/plane/resource/img/'

var PlAYER_SRC = PERFIX_SRC + 'player.png'
var BULLET_SRC = PERFIX_SRC + 'bullet.png'
var POSTFIX_ROCK = 'rock.png'
var SHIELD_SRC = PERFIX_SRC + 'shield.png'
var LIGHT_SRC = PERFIX_SRC + 'gun.png'

var PLAYER_SPEED = 20
var BULLET_SPEED = 20
var MAX_ROCK_SPEED_X = 5
var MIN_ROCK_SPEED_Y = 5
var VAR_ROCK_SPEED_Y = 5

var BULLET_CREATE_INTERVAL = 200

var ROCK_COUNT = 10
var ROCK_KIND = 5

var ROCK_HURT = 10

var TOOL_PROBABILITY = 0.05

var SHIELD_NUM = 10
var win = document.getElementById('win')
var score = document.getElementById('score')
var hp = document.getElementById('hp')

var PERFIX_SRC = 'https://go75.github.io/game/plane/resource/img/'

var PlAYER_SRC = PERFIX_SRC + 'player.png'
var BULLET_SRC = PERFIX_SRC + 'bullet.png'
var POSTFIX_ROCK = 'rock.png'
var SHIELD_SRC = PERFIX_SRC + 'shield.png'
var LIGHT_SRC = PERFIX_SRC + 'gun.png'

var PLAYER_SPEED = 20
var BULLET_SPEED = 20
var MAX_ROCK_SPEED_X = 5
var MIN_ROCK_SPEED_Y = 5
var VAR_ROCK_SPEED_Y = 5

var BULLET_CREATE_INTERVAL = 200

var ROCK_COUNT = 10
var ROCK_KIND = 5

var ROCK_HURT = 10

var TOOL_PROBABILITY = 0.05

var SHIELD_NUM = 10
var LIGHT_NUM = 5
4 changes: 2 additions & 2 deletions plane/game/main.js → game/plane/game/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var player = new Player(PlAYER_SRC, PLAYER_SPEED)
flush()
var player = new Player(PlAYER_SRC, PLAYER_SPEED)
flush()
var createBulletTimer = setInterval(createBullet, BULLET_CREATE_INTERVAL)
36 changes: 36 additions & 0 deletions game/plane/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/assets/img/favicon.ico">
<link rel="stylesheet" type="text/css" href="/assets/style/style.css">
<title>醉墨编程</title>
<link rel="stylesheet" href="/game/plane/style/style.css">
</head>
<header>
<nav>
<a href="/">网站首页</a>
<a href="/code">编程空间</a>
<a href="/game">在线游戏</a>
<a href="/tool">在线工具</a>
<a href="/tips">充电打赏</a>
</nav>
</header>

<body>
<div id="win">
<div id="score">0</div>
<div id="hp"></div>
</div>
<script src="/game/plane/game/init.js"></script>
<script src="/game/plane/model/controls.js"></script>
<script src="/game/plane/model/image.js"></script>
<script src="/game/plane/model/rock.js"></script>
<script src="/game/plane/model/bullet.js"></script>
<script src="/game/plane/model/player.js"></script>
<script src="/game/plane/game/flush.js"></script>
<script src="/game/plane/game/main.js"></script>
</body>
</html>
132 changes: 66 additions & 66 deletions plane/model/bullet.js → game/plane/model/bullet.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
class Bullet extends Img {
constructor(imgSrc, speed) {
super(imgSrc)
this.img.onload = () => {
this.setX(player.x() + player.w() / 2 - this.w() / 2)
this.setY(player.y())
}

this.speed = speed
}

move() {
let y = this.y() - this.speed

this.setY(y)
}
}

var bullets = []

function createBullet() {
let bullet = new Bullet(BULLET_SRC, BULLET_SPEED)
bullets.push(bullet)
}

function updateBullet() {
for (let i = 0; i < bullets.length; i++) {
let bullet = bullets[i]
bullet.move()

if (bullet.y() < 0) {
bullet.remove()
bullets.splice(i, 1)
}

crashProcess()
}
}

function crashProcess() {
for (let j = 0; j < ROCK_COUNT; j++) {
let rock = rocks[j]
if (rock.type != 0) {
continue
}
for (let i = 0; i < bullets.length; i++) {
let bullet = bullets[i]
if (bullet.cross(rock)) {
let randNum = Math.random()
if (randNum < TOOL_PROBABILITY) {
if (randNum < TOOL_PROBABILITY / 2) {
rock.img.src = SHIELD_SRC
rock.type = 1
} else {
rock.img.src = LIGHT_SRC
rock.type = 2
}
} else {
player.setScore(player.score() + 1)
bullet.remove()
bullets.splice(i, 1)
rock.init()
}
}
}
}
class Bullet extends Img {
constructor(imgSrc, speed) {
super(imgSrc)
this.img.onload = () => {
this.setX(player.x() + player.w() / 2 - this.w() / 2)
this.setY(player.y())
}

this.speed = speed
}

move() {
let y = this.y() - this.speed

this.setY(y)
}
}

var bullets = []

function createBullet() {
let bullet = new Bullet(BULLET_SRC, BULLET_SPEED)
bullets.push(bullet)
}

function updateBullet() {
for (let i = 0; i < bullets.length; i++) {
let bullet = bullets[i]
bullet.move()

if (bullet.y() < 0) {
bullet.remove()
bullets.splice(i, 1)
}

crashProcess()
}
}

function crashProcess() {
for (let j = 0; j < ROCK_COUNT; j++) {
let rock = rocks[j]
if (rock.type != 0) {
continue
}
for (let i = 0; i < bullets.length; i++) {
let bullet = bullets[i]
if (bullet.cross(rock)) {
let randNum = Math.random()
if (randNum < TOOL_PROBABILITY) {
if (randNum < TOOL_PROBABILITY / 2) {
rock.img.src = SHIELD_SRC
rock.type = 1
} else {
rock.img.src = LIGHT_SRC
rock.type = 2
}
} else {
player.setScore(player.score() + 1)
bullet.remove()
bullets.splice(i, 1)
rock.init()
}
}
}
}
}
Loading

0 comments on commit e131afd

Please sign in to comment.