package cn.hellojarvis.modle;
import cn.hellojarvis.service.FreshThread;
import cn.hellojarvis.service.Sound;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
/**
* Created by IntelliJ IDEA.
*
* @author : JarvisHsu
* @create 2020/08/20 16:44
*/
public class Dinosaur {
//主图片
private BufferedImage image;
//跑步图片
private BufferedImage image1, image2, image3;
//坐标
public int x, y;
//跳跃的增变量
private int jumpValue = 0;
//跳跃状态
private boolean jumpState = false;
//踏步计时器
private int stepTimer = 0;
//跳起的最大高度
private final int JUMP_HEIGHT = 120;
//落地最低坐标
private final int LOWEST_Y = 415;
//刷新时间
private final int FRESH = FreshThread.FRESH;
public Dinosaur() {
this.x = 50;
this.y = LOWEST_Y;
try {
this.image1 = ImageIO.read(new File("image/dinosaur1.png"));
this.image2 = ImageIO.read(new File("image/dinosaur2.png"));
this.image3 = ImageIO.read(new File("image/dinosaur3.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
//踏步
private void step() {
//每过250ms,更换一张图片。
int temp = (this.stepTimer / 150) % 2;
if (jumpState){
image = image3;
}else {
if (temp == 1) {
image = image1;
} else {
image = image2;
}
}
//计时器递增
this.stepTimer += FRESH;
}
//跳跃
public void jump() {
if (!this.jumpState) {
Sound.jump();
}
this.jumpState = true;
}
//移动
public void move() {
this.step();
if (this.jumpState) {
if (y >= this.LOWEST_Y) {
this.jumpValue = -5;
}
if (y <= this.LOWEST_Y - this.JUMP_HEIGHT) {
jumpValue = 5;
}
y += jumpValue;
if (y >= this.LOWEST_Y) {
jumpState = false;
}
}
}
public Rectangle getFootBounds() {
return new Rectangle(x + 25, y + 100, 45, 44);
}
public Rectangle getHeadBounds() {
return new Rectangle(x + 55, y + 50, 50, 25);
}
@Override
public String toString() {
return "Dinosaur{" +
"image=" + image +
", image1=" + image1 +
", image2=" + image2 +
", image3=" + image3 +
", x=" + x +
", y=" + y +
", jumpValue=" + jumpValue +
", jumpState=" + jumpState +
", stepTimer=" + stepTimer +
", JUMP_HEIGHT=" + JUMP_HEIGHT +
", LOWEST_Y=" + LOWEST_Y +
", FRESH=" + FRESH +
'}';
}
public BufferedImage getImage() {
return image;
}
public void setImage(BufferedImage image) {
this.image = image;
}
public BufferedImage getImage1() {
return image1;
}
public void setImage1(BufferedImage image1) {
this.image1 = image1;
}
public BufferedImage getImage2() {
return image2;
}
public void setImage2(BufferedImage image2) {
this.image2 = image2;
}
public BufferedImage getImage3() {
return image3;
}
public void setImage3(BufferedImage image3) {
this.image3 = image3;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getJumpValue() {
return jumpValue;
}
public void setJumpValue(int jumpValue) {
this.jumpValue = jumpValue;
}
public boolean isJumpState() {
return jumpState;
}
public void setJumpState(boolean jumpState) {
this.jumpState = jumpState;
}
public int getStepTimer() {
return stepTimer;
}
public void setStepTimer(int stepTimer) {
this.stepTimer = stepTimer;
}
public int getJUMP_HEIGHT() {
return JUMP_HEIGHT;
}
public int getLOWEST_Y() {
return LOWEST_Y;
}
public int getFRESH() {
return FRESH;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Dinosaur.rar (41个子文件)
Dinosaur
data
source 14B
src
cn
hellojarvis
view
BackgroundImage.java 1KB
MainFrame.java 1KB
GamePanel.java 3KB
ScoreDialog.java 2KB
service
MusicPlayer.java 2KB
FreshThread.java 1016B
Sound.java 906B
ScoreRecorder.java 3KB
main
Start.java 274B
modle
Dinosaur.java 5KB
Obstacle.java 2KB
Dinosaur.iml 433B
out
production
Dinosaur
cn
hellojarvis
view
MainFrame$1.class 757B
MainFrame.class 1KB
BackgroundImage.class 1KB
ScoreDialog$1.class 768B
GamePanel.class 4KB
ScoreDialog.class 3KB
service
MusicPlayer.class 3KB
Sound.class 1KB
ScoreRecorder.class 4KB
FreshThread.class 1KB
main
Start.class 450B
modle
Obstacle.class 3KB
Dinosaur.class 5KB
.idea
.gitignore 242B
misc.xml 273B
workspace.xml 10KB
uiDesigner.xml 9KB
inspectionProfiles
Project_Default.xml 1KB
modules.xml 263B
image
dinosaur3.png 7KB
rock.png 641B
dinosaur2.png 7KB
background.png 22KB
dinosaur1.png 7KB
cacti.png 2KB
music
background.wav 815KB
jump.wav 20KB
hit.wav 20KB
共 41 条
- 1
资源评论
零壹c
- 粉丝: 5
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功