Spaced trail code

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 2 years ago
parent 41bff4ce7a
commit 24429fe72a
  1. 87
      src/sig/JavaProjectTemplate.java

@ -2,16 +2,12 @@ package sig;
import sig.engine.AnimatedSprite;
import sig.engine.Color;
import sig.engine.Font;
import sig.engine.Key;
import sig.engine.Mouse;
import sig.engine.Panel;
import sig.engine.Point;
import sig.engine.Sprite;
import sig.engine.Transform;
import sig.engine.PolygonStructure;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;
class Player{
@ -20,6 +16,23 @@ class Player{
double animationFrame=0;
double animationSpd=2; //Animation Speed will be 2 frames per second
int TAIL_SPACING=32;
List<Tail> tail = new ArrayList<Tail>();
List<PositionMarker> path = new ArrayList<PositionMarker>();
}
class Tail{
double x,y;
Tail(List<PositionMarker> tailTrail,int TAIL_SPACING){
for (int i=0;i<TAIL_SPACING;i++) {
tailTrail.add(new PositionMarker());
}
}
}
class PositionMarker{
double x,y;
}
public class JavaProjectTemplate {
@ -35,6 +48,25 @@ public class JavaProjectTemplate {
//Initialize your game here.
}
void GeneratePath(){
double prev_tail_x=pl.x;
double prev_tail_y=pl.y;
for (int i=0;i<pl.path.size();i++) {
PositionMarker t = pl.path.get(i);
double prevpos_x=t.x;
double prevpos_y=t.y;
t.x=prev_tail_x;
t.y=prev_tail_y;
prev_tail_x=prevpos_x;
prev_tail_y=prevpos_y;
}
for (int i=0;i<pl.tail.size();i++) {
Tail t = pl.tail.get(i);
t.x=pl.path.get(i*pl.TAIL_SPACING).x;
t.y=pl.path.get(i*pl.TAIL_SPACING).y;
}
}
public void updateGame(double fElapsedTime) {
//Put game update logic in here.
@ -55,49 +87,24 @@ public class JavaProjectTemplate {
pl.y+=200*fElapsedTime;
}
if (Mouse.isPressed(2)) { //If middle click is pressed, reset the player position.
pl.x=pl.y=200;
if (Key.isPressed(KeyEvent.VK_SPACE)) {
pl.tail.add(new Tail(pl.path,pl.TAIL_SPACING));
}
GeneratePath();
}
public void drawGame() {
//Put rendering logic in here.
game.Clear(Color.BRIGHT_BLUE); //Clear the screen so all pixels from the previous frame are removed.
game.Fill_Rect(pl.x, pl.y, 64, 64, Color.BLACK);
game.Draw(100,20,Color.BLACK); //That's not a dead pixel, it's a black one!
game.Draw_Line(10,10,35,35,Color.BLACK); //Line Drawing
game.Draw_Sprite(450,75,bookSpr,Color.GREEN); //Sprite drawing (with green tint)
game.Draw_Sprite(450,75+bookSpr.getHeight(),bookSpr,Transform.VERTICAL); //Sprite drawing with vertical flip
game.Draw_Animated_Sprite(pl.x,pl.y,pl.spr,pl.animationFrame); //Animated Sprite drawing
game.Draw_Text(10,40,"Mouse X: "+Mouse.x+" Mouse Y:"+Mouse.y,Font.PROFONT_12); //Draw Mouse coordinates in tiny font
game.Draw_Text_Ext(10,52,"Hello World 2!",Font.PROFONT_36,Color.MAGENTA); //Draw in larger font
game.Fill_Triangle(160,160,190,190,50,250,new Color(255,0,0,150)); //Draw a translucent colored triangle
game.FillTexturedPolygon( //Define the uv tex coords of a polygon and a sprite and draw a texture onto it
List.of(
new Point<Double>(600d,400d),
new Point<Double>(600d,550d),
new Point<Double>(750d,550d),
new Point<Double>(750d,0d)
),
List.of(
new Point<Double>(0d,0d),
new Point<Double>(0d,1d),
new Point<Double>(1d,1d),
new Point<Double>(1d,0d)
),
List.of(
new Color(0,0,0,255),
Color.WHITE,
Color.RED,
Color.WHITE
), bookSpr, PolygonStructure.FAN);
for (int i=0;i<pl.tail.size();i++) {
Tail t = pl.tail.get(i);
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);
}
}
public static void main(String[] args) {

Loading…
Cancel
Save