Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Im new to Slick and I am trying to do something while moving a character  (Read 818 times)
0 Members and 1 Guest are viewing this topic.
Offline Legion4

Innocent Bystander





« Posted 2011-11-07 20:02:25 »

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
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();
      }
   }

}
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #1 - Posted 2011-11-07 21:13:41 »

I don't hav etime to explain right now, so I recommend you look at scrolling games. because that is what you are looking for and I don't think u are going about it the right way
Offline Karmington

Senior Member


Medals: 1
Projects: 1


Co-op Freak


« Reply #2 - Posted 2011-11-08 02:04:30 »

The advanced camera control you describe is possible with how you have thought about it, but it may be worthwhile first to do some preliminary steps : 1) to clean up your main character into a class of its own, 2) differentiate between map coordinates and screen coordinates, 3) get the character to move on a map larger than the screen while staying in the center of the screen.

Once all these are done, you are better prepared for the fancier camera.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (24 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (58 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!