|
|
@ -2,6 +2,7 @@ package sig; |
|
|
|
|
|
|
|
|
|
|
|
import sig.engine.AnimatedSprite; |
|
|
|
import sig.engine.AnimatedSprite; |
|
|
|
import sig.engine.Color; |
|
|
|
import sig.engine.Color; |
|
|
|
|
|
|
|
import sig.engine.Font; |
|
|
|
import sig.engine.Key; |
|
|
|
import sig.engine.Key; |
|
|
|
import sig.engine.Panel; |
|
|
|
import sig.engine.Panel; |
|
|
|
import sig.engine.Sprite; |
|
|
|
import sig.engine.Sprite; |
|
|
@ -13,20 +14,17 @@ import java.util.List; |
|
|
|
class Player{ |
|
|
|
class Player{ |
|
|
|
AnimatedSprite spr=new AnimatedSprite("player.png",32,32); |
|
|
|
AnimatedSprite spr=new AnimatedSprite("player.png",32,32); |
|
|
|
double x=200,y=200; |
|
|
|
double x=200,y=200; |
|
|
|
|
|
|
|
|
|
|
|
double animationFrame=0; |
|
|
|
|
|
|
|
double animationSpd=2; //Animation Speed will be 2 frames per second
|
|
|
|
|
|
|
|
int TAIL_SPACING=32; |
|
|
|
int TAIL_SPACING=32; |
|
|
|
|
|
|
|
|
|
|
|
List<Tail> tail = new ArrayList<Tail>(); |
|
|
|
List<Tail> tail = new ArrayList<Tail>(); //The tail container
|
|
|
|
List<PositionMarker> path = new ArrayList<PositionMarker>(); |
|
|
|
List<PositionMarker> path = new ArrayList<PositionMarker>(); //The invisible trail container
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class Tail{ |
|
|
|
class Tail{ |
|
|
|
double x,y; |
|
|
|
double x,y; |
|
|
|
Tail(List<PositionMarker> tailTrail,int TAIL_SPACING){ |
|
|
|
Tail(List<PositionMarker> tailTrail,int TAIL_SPACING){ |
|
|
|
for (int i=0;i<TAIL_SPACING;i++) { |
|
|
|
for (int i=0;i<TAIL_SPACING;i++) { |
|
|
|
tailTrail.add(new PositionMarker()); |
|
|
|
tailTrail.add(new PositionMarker()); //When a tail is created, we create TAIL_SPACING number of trail markers as well.
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -59,20 +57,17 @@ public class JavaProjectTemplate { |
|
|
|
t.y=prev_tail_y; |
|
|
|
t.y=prev_tail_y; |
|
|
|
prev_tail_x=prevpos_x; |
|
|
|
prev_tail_x=prevpos_x; |
|
|
|
prev_tail_y=prevpos_y; |
|
|
|
prev_tail_y=prevpos_y; |
|
|
|
} |
|
|
|
} //Generates a very dense invisible trail.
|
|
|
|
for (int i=0;i<pl.tail.size();i++) { |
|
|
|
for (int i=0;i<pl.tail.size();i++) { |
|
|
|
Tail t = pl.tail.get(i); |
|
|
|
Tail t = pl.tail.get(i); |
|
|
|
t.x=pl.path.get(i*pl.TAIL_SPACING).x; |
|
|
|
t.x=pl.path.get(i*pl.TAIL_SPACING).x; |
|
|
|
t.y=pl.path.get(i*pl.TAIL_SPACING).y; |
|
|
|
t.y=pl.path.get(i*pl.TAIL_SPACING).y; //Each tail will get placed along the index of an invisible trail based on its position in the tail container.
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void updateGame(double fElapsedTime) { |
|
|
|
public void updateGame(double fElapsedTime) { |
|
|
|
//Put game update logic in here.
|
|
|
|
//Put game update logic in here.
|
|
|
|
|
|
|
|
|
|
|
|
//Player sprite will animate.
|
|
|
|
|
|
|
|
pl.animationFrame+=pl.animationSpd*fElapsedTime; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Allow player movement using WASD keys.
|
|
|
|
//Allow player movement using WASD keys.
|
|
|
|
if (Key.isHeld(KeyEvent.VK_A)) { |
|
|
|
if (Key.isHeld(KeyEvent.VK_A)) { |
|
|
|
pl.x-=200*fElapsedTime; |
|
|
|
pl.x-=200*fElapsedTime; |
|
|
@ -103,8 +98,10 @@ public class JavaProjectTemplate { |
|
|
|
for (int i=0;i<pl.tail.size();i++) { |
|
|
|
for (int i=0;i<pl.tail.size();i++) { |
|
|
|
Tail t = pl.tail.get(i); |
|
|
|
Tail t = pl.tail.get(i); |
|
|
|
game.FillCircle(t.x+22, t.y+22, 10, Color.BLUE); |
|
|
|
game.FillCircle(t.x+22, t.y+22, 10, Color.BLUE); |
|
|
|
game.Draw_Circle((int)t.x+22, (int)t.y+22, 10, Color.BLACK); |
|
|
|
game.Draw_Circle((int)t.x+22, (int)t.y+22, 10, Color.BLACK); //Draw our tail at the proper location.
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
game.Draw_Text_Ext(4, 4, "SPACE to create more tail", Font.PROFONT_36, Color.RED); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|