Yes i am programming my first game with one of my friends for school. We are just starting and stuff and we are trying to familiarize ourselve with the lib(iits our thirst semester in java).
Now my point is I have a character that moves around in a given map and what I am ting to do is too draw a invisible square in the middle of the screen that if the character hits the boundries, the “camera” move around giving the illusion that the character is actually moving. Kind of how link moves around in Link to the Past if you guys understand what I mean.
Anyway if you guys get an insight toward producing this kind of effect I will paste my code its very basic and stuff we are still exploring and stuff.
their maybe french commentaries I am working withaa french dude so wtv.
package com.game.exemple;
import java.util.Map;
import org.newdawn.slick.Animation;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.KeyListener;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.tiled.TiledMap;
public class GameTest extends BasicGame{
Image image=null;
Animation animateUp=null;
Animation animateDown=null;
Animation animateLeft=null;
Animation animateRight=null;
Animation currentAnimation=null;
SpriteSheet sprite=null;
TiledMap map;
float x=400;//position
float y=300;//position
float speed=0.19f;
public GameTest(){
super("GameTest");
}
public void init(GameContainer container)throws SlickException{
//container.setVSync(true);
image=new Image("U:/link.png",new Color(0,128,128));
sprite=new SpriteSheet(image,18,24);
animateUp=new Animation(sprite,0,2,6,2,true,50,true);
animateDown=new Animation(sprite,0,0,6,0,true,50,true);
animateLeft=new Animation(sprite,0,6,6,6,true,50,true);
animateRight=new Animation(sprite,0,4,6,4,true,50,true);
currentAnimation=animateDown;
map = new TiledMap("U:/programmation/map.tmx");
}
public void update(GameContainer container,int delta)
throws SlickException {
float move=speed*delta;
Input input = container.getInput();
if(input.isKeyDown(Input.KEY_A))
{
currentAnimation=animateLeft;
x-=move;
}
if(input.isKeyDown(Input.KEY_D))
{
currentAnimation=animateRight;
x+=move;
}
if(input.isKeyDown(Input.KEY_W))
{
currentAnimation=animateUp;
y-=move;
}
if(input.isKeyDown(Input.KEY_S))
{
currentAnimation=animateDown;
y+=move;
}
if(currentAnimation==animateDown&&!input.isKeyDown(Input.KEY_S)){
currentAnimation=new Animation(sprite,3,0,3,0,true,200,true);
}
if(currentAnimation==animateUp&&!input.isKeyDown(Input.KEY_W)){
currentAnimation=new Animation(sprite,3,2,3,2,true,200,true);
}
if(currentAnimation==animateLeft&&!input.isKeyDown(Input.KEY_A)){
currentAnimation=new Animation(sprite,3,6,3,6,true,200,true);
}
if(currentAnimation==animateRight&&!input.isKeyDown(Input.KEY_D)){
currentAnimation=new Animation(sprite,3,4,3,4,true,200,true);
}
}
public void render(GameContainer container, Graphics g)
throws SlickException{
map.render(0, 0);
//g.drawString("Hello, Slick world!", 0, 100);
//g.drawImage(sprite.getSprite(7, 0), 35, 35);
//g.drawAnimation(currentAnimation, x,y);
currentAnimation.draw(x, y,36,48);
//sprite.draw(x,y);
//image.draw(x,y);
//image.draw(50,50);
}
public static void main(String[] args){
try{
AppGameContainer app=new AppGameContainer(new GameTest());
app.setDisplayMode(800, 600, false);
app.start();
}catch (SlickException e){
e.printStackTrace();
}
}
}