-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBall.cs
More file actions
100 lines (93 loc) · 2.44 KB
/
Ball.cs
File metadata and controls
100 lines (93 loc) · 2.44 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace ezkiv
{
class Ball : GameObject
{
public Vector2 locXY; // cartesian position
public Vector2 velXY; // cartesian velocity
public bool fire;
string name;
Texture2D spr;
float rad;
public Ball(int X, int Y, int vX, int vY, Texture2D objspr, string objName)
{
locXY = new Vector2(X, Y);
velXY = new Vector2(vX, vY);
fire = true;
spr = objspr;
name = objName;
rad = 5f;
}
public Vector2 getLocXY()
{
return locXY;
}
public string getName()
{
return name;
}
public void setLocXY(Vector2 newLoc)
{
locXY = newLoc;
}
public int collide(GameObject obj)
{
Vector2 temp = obj.getLocXY();
temp = locXY + new Vector2(rad, rad) - temp - new Vector2(15, 15);
if (temp.Length() <= rad + 15f)
return 2;
return 0;
}
public void update()
{
// move
locXY += velXY;
// check off screen
if (locXY.X < 0 || locXY.X > 230)
{
velXY.X = -velXY.X;
if (locXY.X < 0)
{
locXY.X = 0;
}
else
{
locXY.X = 230;
}
}
if (locXY.Y < 0 || locXY.Y > 310)
{
velXY.Y = -velXY.Y;
if (locXY.Y < 0)
{
locXY.Y = 0;
}
else
{
locXY.Y = 310;
}
}
}
public void Draw(SpriteBatch spriteBatch)
{
Rectangle drawRect = new Rectangle(0, 0, 10, 10);
Color drawCol = Color.White;
drawRect.X = (int)locXY.X;
drawRect.Y = (int)locXY.Y;
if (fire)
{
drawCol = Color.Red; // gives a redish tint.
}
else
{
drawCol = Color.White;
}
spriteBatch.Draw(spr, drawRect, drawCol);
}
}
}