|
2 | 2 |
|
3 | 3 | import java.awt.Graphics2D; |
4 | 4 | import java.awt.Rectangle; |
| 5 | +import java.awt.geom.AffineTransform; |
5 | 6 | import java.awt.image.BufferedImage; |
6 | 7 | import java.io.File; |
7 | 8 | import java.io.IOException; |
@@ -32,14 +33,11 @@ public void setDefault(){ |
32 | 33 | this.agentX=MapLoader.spawnX*gameWindow.tileSize; |
33 | 34 | this.agentY=MapLoader.spawnY*gameWindow.tileSize; |
34 | 35 | this.velocity = new Velocity(); |
35 | | - for(int i = 0; i<100; i++){ |
36 | | - instructions[i] = 4; |
37 | | - } |
38 | | - /* |
| 36 | + |
39 | 37 | for(int i = 0; i<50; i++){ |
40 | 38 | instructions[i] = rand.nextInt(5); |
41 | 39 | } |
42 | | - */ |
| 40 | + |
43 | 41 | switch (MapLoader.spawnDirection) { |
44 | 42 | case 0: |
45 | 43 | velocity.angle = 0; |
@@ -73,14 +71,14 @@ public void update(){ |
73 | 71 | checkLaps(); |
74 | 72 | calculatePoints(); |
75 | 73 | if(nextActionTimer%5 == 0 && instructionIndex<instructions.length){ |
76 | | - int rotationAngle = 5; |
| 74 | + int rotationAngle; |
77 | 75 | double netVelocity = velocity.netVelocity(); |
78 | 76 | switch (instructions[instructionIndex]) { |
79 | 77 | case 0: //accelerate |
80 | | - velocity.accelerate(0.2*frictionCoefficient); |
| 78 | + velocity.accelerate(0.4*frictionCoefficient); |
81 | 79 | break; |
82 | 80 | case 1: //deaccelerate |
83 | | - velocity.accelerate(-0.4); |
| 81 | + velocity.accelerate(-0.5); |
84 | 82 | break; |
85 | 83 | case 2: //turn left |
86 | 84 | rotationAngle = 10; |
@@ -155,8 +153,10 @@ public void draw(Graphics2D graphics){ |
155 | 153 | agentX<agentX+screenMidX+3*tileSize&& |
156 | 154 | agentY>agentY-screenMidY-1*tileSize&& |
157 | 155 | agentY<agentY+screenMidY+3*tileSize){ |
| 156 | + AffineTransform oldTransform = graphics.getTransform(); // save old graphics orientation |
158 | 157 | graphics.rotate(Math.toRadians(-velocity.angle),screenX+playerModel.getWidth()/4,screenY+playerModel.getHeight()/4); |
159 | 158 | graphics.drawImage(playerModel,screenX,screenY,playerModel.getWidth()/2,playerModel.getHeight()/2,null); |
| 159 | + graphics.setTransform(oldTransform); // restore old graphics |
160 | 160 | } |
161 | 161 | } |
162 | 162 | public String toString(){ |
|
0 commit comments