vue版-雷霆战机

先看效果

vue-雷霆战机

node + vue + element

图片是网上找的,后期还得再改,目前实现了拖动发射子弹

部分代码

<template>
  <div class="common-layout">
    <el-container>
      <el-header>战机游戏</el-header>
      <el-main @mousemove="mousemove" ref="elePlane">
        <my-plane :coo="coo"></my-plane>
        <img src="@/assets/game/bullit.jpeg"  class="my-bullit" :style="{top:item.y  + 'px',left:item.x + 'px'}" 
        v-for="(item,index) in bullitList" :key="index"/>
      </el-main>
    </el-container>
  </div>
</template>
  
  
  <script>
import myPlane from "@/components/game/myPlane.vue";
export default {
  name: "gameIndex",
  components: {
    myPlane,
  },
  data() {
    return {
      coo: {},
      containerHeight: 0,
      containerWidth:0,
      bullitList:[]
    };
  },
  mounted() {
    this.containerHeight = this.$refs.elePlane.$el.offsetHeight;
    this.containerWidth = this.$refs.elePlane.$el.offsetWidth;
    setInterval(()=>{
      if(this.bullitList.length > 20){
        this.bullitList.splice(0,1)
      }
      this.bullitList.push({x:this.coo.x,y:this.coo.y})
      this.bullitList.forEach(e=>{
        e.y = e.y-100
      })
    },100)
  },
  methods: {
    mousemove(e) {
      if (e.y >= 100 && e.y <= this.containerHeight+20 && e.x >= 30 && e.x < this.containerWidth - 30) {
        this.coo = { x: e.x, y: e.y };
      }
    },
  },
};
</script>
<style scoped>
.el-header {
  background-color: antiquewhite;
  height: 60px;
  line-height: 60px;
  text-align: center;
}
.el-main {
  background-color: aqua;
  height: calc(100vh - 60px);
}
.my-bullit{
  width: 20px;
  height: 50px;
  /**默认位置在最下面 */
  position: absolute;
  transform: translate(-50%);
}
</style>
  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值