Skip to content

Commit 5bf5ac9

Browse files
committed
debugged agent behaviour, ready for gen. algorithm
1 parent 9f940a1 commit 5bf5ac9

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

JavaRacer/Agent.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.awt.Graphics2D;
44
import java.awt.Rectangle;
5+
import java.awt.geom.AffineTransform;
56
import java.awt.image.BufferedImage;
67
import java.io.File;
78
import java.io.IOException;
@@ -32,14 +33,11 @@ public void setDefault(){
3233
this.agentX=MapLoader.spawnX*gameWindow.tileSize;
3334
this.agentY=MapLoader.spawnY*gameWindow.tileSize;
3435
this.velocity = new Velocity();
35-
for(int i = 0; i<100; i++){
36-
instructions[i] = 4;
37-
}
38-
/*
36+
3937
for(int i = 0; i<50; i++){
4038
instructions[i] = rand.nextInt(5);
4139
}
42-
*/
40+
4341
switch (MapLoader.spawnDirection) {
4442
case 0:
4543
velocity.angle = 0;
@@ -73,14 +71,14 @@ public void update(){
7371
checkLaps();
7472
calculatePoints();
7573
if(nextActionTimer%5 == 0 && instructionIndex<instructions.length){
76-
int rotationAngle = 5;
74+
int rotationAngle;
7775
double netVelocity = velocity.netVelocity();
7876
switch (instructions[instructionIndex]) {
7977
case 0: //accelerate
80-
velocity.accelerate(0.2*frictionCoefficient);
78+
velocity.accelerate(0.4*frictionCoefficient);
8179
break;
8280
case 1: //deaccelerate
83-
velocity.accelerate(-0.4);
81+
velocity.accelerate(-0.5);
8482
break;
8583
case 2: //turn left
8684
rotationAngle = 10;
@@ -155,8 +153,10 @@ public void draw(Graphics2D graphics){
155153
agentX<agentX+screenMidX+3*tileSize&&
156154
agentY>agentY-screenMidY-1*tileSize&&
157155
agentY<agentY+screenMidY+3*tileSize){
156+
AffineTransform oldTransform = graphics.getTransform(); // save old graphics orientation
158157
graphics.rotate(Math.toRadians(-velocity.angle),screenX+playerModel.getWidth()/4,screenY+playerModel.getHeight()/4);
159158
graphics.drawImage(playerModel,screenX,screenY,playerModel.getWidth()/2,playerModel.getHeight()/2,null);
159+
graphics.setTransform(oldTransform); // restore old graphics
160160
}
161161
}
162162
public String toString(){

JavaRacer/GameWindow.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public class GameWindow extends JPanel implements Runnable{
2222
public GameWindow(){
2323
Color backgroundColor = new Color(34, 139, 34);
2424
for(int i = 0; i<agents.length;i++){
25-
agents[i] = new Agent(this);
26-
agents[i].agentX += i*50;
27-
agents[i].agentY += i*50;
25+
agents[i] = new Agent(this);
2826
}
2927
this.camera = new Camera(this,keyHandle, agents[0].agentX, agents[0].agentY);
3028
this.setBackground(backgroundColor);

0 commit comments

Comments
 (0)