会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132589个问题
JAVA 全系列/第一阶段:JAVA 快速入门/JAVA入门和背景知识 27676楼
JAVA 全系列/预科阶段:职业规划/学习方法/JAVA 技术体系介绍和学习方法 27678楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 27679楼
JAVA 全系列/第十四阶段:全文检索服务/Spring Data For ElasticSearch 27680楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/反射技术(旧) 27682楼

package com.bjsxt.plane;

import java.awt.*;

/**
 * 炮弹类
 */
public class Shell extends GameObject {

    double degree;  //角度。炮弹沿着指定的角度飞行

    public Shell() {
        x = 200;
        y = 200;

        degree = Math.random() * Math.PI * 2;   //生成随机0~2π的角度

        width = 5;
        height = 5;

        speed = 3;
    }

    @Override
    public void drawMyself(Graphics g) {
        Color c = g.getColor();     //以前的画笔(颜色)
        g.setColor(Color.yellow);   //yellow传入Color有参构造方法

        g.fillOval((int) x, (int) y, width, height);    //生成实心圆
//        g.drawOval((int) x, (int) y, width, height);    //生成空心圆
        g.setColor(c);              //用完之后还回去

        //根据自己算法指定移动的路径
        x += speed * Math.cos(degree);  //x =x + speed * Math.cos(degree)
        y += speed * Math.sin(degree);  //y =y + speed * Math.sin(degree);

        //碰到边界改变方向
        if (y > Constant.GAME_HEIGHT - this.height || y < 40) {
            degree = -degree;
        }

        if (x < 0 || x > Constant.GAME_WIDTH - this.width) {
            degree = Math.PI - degree;
        }

    }
}
degree = Math.PI - degree;

这句话是什么意思?,y轴的可以看懂,x轴的为什么不能写degree = -degree;


JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 27683楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 27684楼
WEB前端全系列/第七阶段:ECMAScript6新特性模块/ES6第二部分 27690楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637