-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cs
86 lines (69 loc) · 2.31 KB
/
player.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
namespace ActionGame
{
class player:GraphicalGameObject
{
public bool isKeyL,isKeyR,isSpace;
World world;
float shotTime=0;
public player(Game1 game,World world,Point point) : base(game, game.assets.player)
{
X = point.X;
Y = point.Y;
Width = 100;
Height = 150;
this.world = world;
}
public override void update(float delta)
{
if (game.input.onKeyDown(Keys.Right)) isKeyR = true;
if (game.input.onKeyUp(Keys.Right)) isKeyR = false;
if (game.input.onKeyDown(Keys.Left)) isKeyL = true;
if (game.input.onKeyUp(Keys.Left)) isKeyL = false;
if (game.input.onKeyDown(Keys.Space)) isSpace=true;
if (game.input.onKeyUp(Keys.Space)) isSpace = false;
if (isKeyR)
{
if( velocityX<5f)velocityX += 0.5f;
}
if (isKeyL)
{
if (-5f < velocityX) velocityX -= 0.5f;
}
if(!isKeyR && !isKeyL)
{
if (velocityX == 0) { velocityX = 0; }
else if (velocityX < 0) { velocityX += 0.2f; }
else if (velocityX > 0) { velocityX -= 0.2f; }
}
X +=(velocityX * delta*0.1f);
Y += (velocityY * delta*0.1f);
if (X <= 0)
{
velocityX = 0;
X = 0;
}
if (X >= 1180)
{
velocityX = 0;
X = 1180;
}
shotTime += delta/1000;
if (shotTime >= 0.1f && isSpace) { world.shots.Add(new shot(game, world, new Point((int)X + 75, (int)Y + 50))); shotTime = 0;game.assets.shotSound.Play(0.5f,0,0); }
Console.WriteLine((velocityX).ToString());
base.update(delta);
}
public override void Draw(SpriteBatch batch, float screenAlpha)
{
base.Draw(batch,screenAlpha);
}
}
}