Четверг, 18 Апреля 2024, 15:54

Приветствую Вас Гость

[ Новые сообщения · Игроделы · Правила · Поиск ]
  • Страница 1 из 1
  • 1
Форум игроделов » Движки для разработки игр и сложные системы разработки » 2D-движки для создания игр » Классическая змейка
Классическая змейка
dwarvenДата: Пятница, 18 Октября 2013, 00:50 | Сообщение # 1
был не раз
Сейчас нет на сайте
Здравствуйте, движок slick2d Java не могу додумать как сделать в змейки классическое передвижение когда например пару квадратов идут вниз а пол змеии еще с боку) и расстояние между ними туплю по строшному)) еду сделал 1 примитив кушает другой))

Код
import java.util.ArrayList;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.tiled.TiledMap;
import org.newdawn.slick.geom.Point;
public class Player {
  private float x;
  private float y;
private float tx;
private float ty;
private Vector2f pos = new Vector2f(x,y);
private Vector2f posen = new Vector2f(x,y);
private int q=1;
  private int temp=0;
   
private ArrayList<Vector2f> snakes  = new ArrayList<Vector2f>();;

  protected Image bullet;
  private int k;
  private int raz;
  private int val;
  private int n;
  private  int n1;
   
  public Player(int raz) {
this.raz=raz;

  }
   
   
   
  public void update(GameContainer gc, int delta) {
   Vector2f trans = new Vector2f(0, 0);
    

   //Vector2f trans = new Vector2f(0, 0); // Vector contains a value with components x & y
    ArrayList<Vector2f> snake = new ArrayList<Vector2f>();
   Input input = gc.getInput();
    
   snake.add(new Vector2f(0, 0));
   if (input.isKeyDown(Input.KEY_W) && (pos.y>=5)) {
    trans.y = -0.2f * delta;
    for (Vector2f pos : snakes) {
     pos.y=(float) (pos.y+Math.floor(trans.y)) ;
          
    }
   }
    //this.sprite=spritemove;
  if( (n==0)&& (n1==0 )) {
    snakes.add(new Vector2f(pos.x, pos.y));
    n1=1;
  }
    
    
    
   if ((input.isKeyDown(Input.KEY_S)) && (pos.y<=580)) {
    //trans.y = 0.2f * delta;
    trans.y = 0.2f * delta;
    for (Vector2f pos : snakes) {
     pos.y=(float) (pos.y+Math.floor(trans.y));
      
    }
   }
    
   if (input.isKeyDown(Input.KEY_D)&& (pos.x<=780))  {
    trans.x = 0.2f * delta;
    for (Vector2f pos : snakes) {
     pos.x=(float) (pos.x+Math.floor(trans.x));
          
    }
   }
   if (input.isKeyDown(Input.KEY_A) && (pos.x>=5)){
    trans.x = -0.2f * delta;
    for (Vector2f pos : snakes) {
     pos.x=(float) (pos.x+Math.floor(trans.x));
          
    }
   }
   if (input.isKeyDown(Input.KEY_ESCAPE))   
    gc.exit();
    
   if(val==1) {
    
      snakes.add(new Vector2f(pos.x, pos.y));
      
   }
    

   
   //System.out.println("Player" + pos.x);
   //System.out.println("Eat" + posen.x);

    
   pos.y += Math.floor(trans.y);
  pos.x += Math.floor(trans.x);
   k=1;
    
    
     
System.out.println(raz);
     
  }
   
   
  public void render(Graphics g) {
   //g.drawRect(pos.x, pos.y, 15, 15);
    
   for (Vector2f pos : snakes) {
    g.drawRect(pos.x, pos.y, 15, 15);
     
   
  }
    
  }
   
  public int getQ() {
   return q;
  }
   
  public Vector2f getPos() {
    
   return pos;
  }
public float getX() {
    
   return pos.x;
  }

public float getY() {
   
  return pos.y;
}

public void setRaz(int val) {
this.val=val;
}

public void setN(int n) {
this.n=n;
}

}
   
   


В общем класс игрока про просивку подскажите_
Форум игроделов » Движки для разработки игр и сложные системы разработки » 2D-движки для создания игр » Классическая змейка
  • Страница 1 из 1
  • 1
Поиск:

Все права сохранены. GcUp.ru © 2008-2024 Рейтинг