自制vbs游戏引擎模板
hta吧
全部回复
仅看楼主
level 11
命幽 楼主
镇楼
!!!
目前使用自制游戏引擎编写的demo有 打砖块 跟 躲飞机
2018年01月27日 03点01分 1
level 11
命幽 楼主
‘V0.0.32[滑稽]双手奉上源码 下一个楼层放上演示效果
Class gameEngine
Public Function CreateSprite(x,y,width,height,name,imageSrc) '创建精灵 横坐标 纵坐标 宽度 高度 名称 图源
Dim obj
Set obj=document.createElement("DIV")
obj.id = name
obj.style.position = "absolute"
obj.style.left = x
obj.style.top = y
obj.style.width = width
obj.style.height = height
obj.style.background = "url(" & imageSrc & ")"
game.appendChild(obj)
Set CreateSprite = obj
Set obj = Nothing
End Function
Public Function CreateText(x,y,name,content,fontSize,color)'创建文本 横坐标 纵坐标 名称 内容 字体大小 前景色
Dim obj
Set obj=document.createElement("span")
obj.id = name
obj.style.position = "absolute"
obj.style.left = x
obj.style.top = y
obj.innerText = content
obj.style.color = color
obj.style.fontSize = fontSize
game.appendChild(obj)'document.body.appendChild(obj)
Set CreateText = obj
Set obj = Nothing
End Function
Public Function CreateButton(x,y,name,caption)'创建按钮 横坐标 纵坐标 名称 标题
Dim obj
Set obj=document.createElement("button")
obj.id = name
obj.style.position = "absolute"
obj.style.left = x
obj.style.top = y
obj.value = caption
game.appendChild(obj)
Set CreateButton = obj
Set obj = Nothing
End Function
Public Function destroy(obj)'销毁对象
game.removeChild(obj)
Set obj = Nothing
Set destroy = obj
End function
Public Function Collide(obj1, obj2)'游戏中逻辑的碰撞检测
If obj1.offsetLeft + obj1.offsetWidth > _
obj2.offsetLeft And obj1.offsetLeft < obj2.offsetLeft + obj2.offsetWidth _
And obj1.offsetTop + obj1.offsetHeight > obj2.offsetTop _
And obj1.offsetTop < obj2.offsetTop + obj2.offsetHeight Then
Collide = True
Else
Collide = False
End If
End Function
Public Sub Move(obj,speedX,speedY)'移动行为
obj.style.left = obj.offsetLeft + speedX
obj.style.top = obj.offsetTop + speedY
End Sub
Public Sub Bullet(obj,Dx,speed)'子弹行为 需要一开关 和一个 定时器 自动发射 越界自毁(okay)
Dim speedX,speedY
speedX = 0
speedY = 0
Select Case Dx
Case "right"'right
speedX = speed
Case "down"'down
speedY = speed
Case "left"'left
speedX = -speed
Case "up"'up
speedY = - speed
Case Else
Exit Sub
End Select
If obj.offsetLeft >= game.offsetWidth Or _
obj.offsetTop >= game.offsetHeight Or _
obj.offsetLeft + obj.offsetWidth <= 0 Or _
obj.offsetTop + obj.offsetHeight <= 0 Then
Set obj = destroy(obj)
Else
Move obj,speedX,speedY
End If
End Sub
End Class
2018年01月27日 03点01分 2
level 11
命幽 楼主
打砖块用的就是v0.0.3编写
躲飞机则用的是v0.0.5编写
[滑稽]
2018年01月27日 03点01分 3
level 11
命幽 楼主
<html>
<head>
<title>BreakOut</title>
<HTA:APPLICATION
APPLICATIONNAME="My HTML application"
ID="MyHTMLapplication"
innerborder=no
scroll=no
VERSION="1.0"/>
<script language="VBScript" type="text/VBScript" src="./GameEngine v0.0.3.vbs"></script>
<script language="VBScript" type="text/VBScript" src="./GameMain.vbs"></script>
<style>html,body,div{margin:0;padding:0;}#game{position:absolute;}</style>
</head>
<body bgcolor="white" id="game"></body>
<script language="VBScript">
Dim block(15), b(15),i ,j,n
Dim ball_speedX,ball_speedY
Dim isStart
isStart = False
Sub game_onclick()
isStart = true
End Sub
Sub Window_OnLoad
Dim gameEngine
Set gameEngine = New gameEngine '引入游戏引擎
gameEngine.createsprite 0,0,139*2,44,"platform","./block.png"'创建平台
platform.style.left = (game.offsetWidth - platform.offsetWidth) / 2'设置平台左边距(横坐标)
platform.style.top = game.offsetHeight - platform.offsetHeight'设置平台顶边距(纵坐标)
For i = 0 To 15'创建砖块
Set block(i) = gameEngine.CreateSprite(i * 140,0,139/1.5,44,"block(i)","./block.png")
block(i).style.left = (game.offsetWidth - block(i).offsetWidth) / 3
block(i).style.top = block(i).offsetHeight
Next
For i = 1 To 15'砖块布局
If i Mod (4) = 0 Then
block(i).style.Left = block(0).offsetLeft + 5
block(i).style.Top = block(i - 1).offsetTop + block(i - 1).offsetHeight + 5
Else
block(i).style.Left = block(i - 1).offsetLeft + block(i - 1).offsetWidth + 5
block(i).style.Top = block(i - 1).offsetTop + 5
End If
Next
'gameEngine.destroy(block(0))
gameEngine.createsprite 0,0,139/5,44/1.5,"ball","./block.png"'创建小球
ball.style.left = (game.offsetWidth - ball.offsetWidth) / 2'设置小球左边距(横坐标)
ball.style.top = platform.offsetTop - ball.offsetHeight * 3'设置小球顶边距(纵坐标)
window.setinterval "update",1000/60
ball_speedY = 0.98
Randomize Timer
If Int(Rnd * 10) Mod 2 = 0 Then
ball_speedX = 0.98
Else
ball_speedX = -0.98
End If
End Sub
Sub game_onMouseMove(e)'鼠标移动控制平台横向移动
platform.style.left = e.x - platform.offsetWidth / 2
End Sub
</script>
</html>
<!--
以上就是打砖块的主程源码
记得在同目录下发过一个block.png文件哦[滑稽]
若有志同道合的小伙伴可以加入扣扣群 一起学习一起进步[滑稽]
当然不是只局限于VBS游戏编程、你也可以使用JavaScript或者VB6亦或是其他游戏编程语言或游戏引擎
如 construct2、lakeshore、gdevelop、gamemakder、cocos2、phaserjs、白鹭、腊鸭、青瓷[滑稽]
-->
2018年01月27日 03点01分 4
level 1
自制HTA版植物大战僵尸[滑稽],目前仅有一个界面
2020年03月28日 04点03分 5
。。
2020年04月22日 13点04分
1