-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTube.java
More file actions
118 lines (103 loc) · 2.22 KB
/
Tube.java
File metadata and controls
118 lines (103 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
Name: Creighton Young
Date: 9/24/2020
Assigment: Make some pipes appear
*/
import javax.swing.JPanel;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.io.File;
import java.awt.Graphics;
public class Tube extends Sprite
{
int x;
int y;
int width;
int height;
int scrollPos;
Model model;
boolean onCurrentTube=false;
static BufferedImage tube_image=null;
Tube(int xPos, int yPos)
{
x = xPos;
y = yPos;
width=55;
height=400;
scrollPos=0;
super.type="tube";
if (tube_image==null)
{
tube_image=View.loadImage("tube.png");
}
}
Json tubeMarshal()
{
Json ob = Json.newObject();
ob.add("x",x);
ob.add("y",y);
return ob;
}
public Tube(Json ob)
{
x=(int)ob.getLong("x");
y=(int)ob.getLong("y");
width=55;
height=400;
super.type="tube";
tube_image=View.loadImage("tube.png");
}
void update()
{
}
void drawYourself(Graphics g)
{
g.drawImage(tube_image, x-super.scrollPos, y, null);
}
void Collision(Sprite sprite)
{
if (sprite.type.equals("mario"))
{
Mario mario=(Mario) sprite;
if (mario.x+mario.width+2>x && (mario.x+mario.width+2)<(x+width+60)) //the two helps us with clipping into the pipe
{
if (mario.y>y)
{
model.rightHittingTube=true;
}
else if (y-mario.y<=50 && mario.x+mario.width>x && mario.frameCounter==0)
{
mario.onTube=true;
mario.y=y-95;
mario.onGround=true;
onCurrentTube=true;
}
}
else if (x+2<mario.x && x+width+2>mario.x) //this two also helps us with clipping
{
if (mario.y>y)
{
model.leftHittingTube=true;
}
}
if (mario.onTube && (mario.x+35<x || mario.x>x+width) && onCurrentTube) //the 40 is an arbitrary that makes it look cleaner when mario should fall off the tube
{
mario.onTube=false;
}
sprite=mario;
}
else if (sprite.type.equals("goomba"))
{
Goomba goomba=(Goomba) sprite;
if (goomba.x+goomba.width>x && (goomba.x+goomba.width+2)<(x+width+60))
{
goomba.moveAmount=-5;
}
else if(x+2<goomba.x && x+width+2>goomba.x)
{
goomba.moveAmount=5;
}
}
}
}