Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (515)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: How to move shapes with keyboard in slick 2d on: 2014-01-26 03:23:40
But when I change delta to a float I get an error stating that it needs to be an int. Also, is there a way that I can make slick detect a certain color in the background and not allow the user to pass it, like a maze? Or would I just have to outline the areas with shapes and make it go through the collision detection thing?

2  Game Development / Newbie & Debugging Questions / Re: How to move shapes with keyboard in slick 2d on: 2014-01-26 02:36:56
But doesnt everything automatically work when i call start()?  I mean the game already runs and updates itself right now...or is there more to the update method than just moving stuff around?
And the question I have is how can I make a shape object move around? I know how to make pictures and "built in" shapes move around like this:

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  
   public void render(GameContainer gc, Graphics g) throws SlickException {
     
   
      g.drawOval(x, y, 40, 60, 50);//move the octagon around
     
      //just show whether the collision is changing or not
      g.drawString("Collides " + collides, 350, 30);
   }
   
   public void update(GameContainer gc, int delta) throws SlickException {
     
      Input input = gc.getInput();
      //control octogon
      //up
      if(input.isKeyDown(Input.KEY_UP)){
         y = y - speed * delta;//delta makes the speed run the same on ANY computer
      }
      //down
      if(input.isKeyDown(Input.KEY_DOWN)){
         y = y + speed * delta;
      }
      //left
      if(input.isKeyDown(Input.KEY_LEFT)){
         x = x - speed * delta;
      }
      //right
      if(input.isKeyDown(Input.KEY_RIGHT)){
         x = x + speed * delta;
      }
     

   }


But, if I want to do something like the following in my update method

1  
2  
      //check if it collides
      collides = circle.intersects(oval);

for a non object shape, like in line 4, then I have no idea how to pass in the value(oval) into the parameter. Right now Im just getting my feet wet with the whole collision thing because I have made another project that is essentially a kids maze game, but its only fault as of now is that the player can go through the lines(the walls in the game). Soooooo if I figure this out I will be able to figure that out too, I think. BUT, I'm a noob and need help still.
3  Game Development / Newbie & Debugging Questions / How to move shapes with keyboard in slick 2d on: 2014-01-26 00:03:09
Im trying to move a shape, an octagon, in my game but I dont know how. Here is what I have so far
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  
import java.awt.Container;

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.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Circle;
import org.newdawn.slick.geom.Polygon;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;


public class ShapesAndCollisionTest extends BasicGame{
   
   private Shape circle;
   private boolean collides = false;
   private float x = 300;
   private float y = 100;
   float speed = .25f;
   private Shape octagon;
   
   public ShapesAndCollisionTest(String title) {
     
      super(title);
   }
   
   public void init(GameContainer gc) throws SlickException {
     
      circle =  new Circle(100, 100, 50);// x, y, radius
      octagon = new Circle(x, y, 30, 8);//x, y, radius, number of segments
     
   }
   
   public void render(GameContainer gc, Graphics g) throws SlickException {
     
      //set the color
      g.setColor(new Color(0, 255, 255));//inside color
      g.fill(circle);
      g.setColor(new Color(255, 0, 0));//red, green, blue OUTLINE of circle
      g.draw(circle);
           
      g.setColor(Color.magenta);
      g.draw(octagon);
     
      //just show whether the collision is changing or not
      g.drawString("Collides " + collides, 350, 30);
   }
   
   public void update(GameContainer gc, int delta) throws SlickException {
     
      Input input = gc.getInput();
      //control octogon
      //up
      if(input.isKeyDown(Input.KEY_UP)){
         y = y - speed * delta;//delta makes the speed run the same on ANY computer
      }
      //down
      if(input.isKeyDown(Input.KEY_DOWN)){
         y = y + speed * delta;
      }
      //left
      if(input.isKeyDown(Input.KEY_LEFT)){
         x = x - speed * delta;
      }
      //right
      if(input.isKeyDown(Input.KEY_RIGHT)){
         x = x + speed * delta;
      }
     
      //check if it collides
      collides = circle.intersects(octagon);
     
   }
4  Game Development / Newbie & Debugging Questions / Re: How to set font size in Slick 2D on: 2014-01-21 22:13:35
Ok thanks!
Do you know how I can fix this error that I am getting for that line though? I am getting:
1  
2  
3  
4  
5  
6  
7  
8  
9  
java.lang.RuntimeException: Resource not found: Pokemon Hollow.ttf
   at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
   at randoms.FontExample.init(FontExample.java:89)
   at randoms.FontExample.start(FontExample.java:27)
   at randoms.FontExample.main(FontExample.java:115)
Exception in thread "main" java.lang.NullPointerException
   at randoms.FontExample.render(FontExample.java:107)
   at randoms.FontExample.start(FontExample.java:31)
   at randoms.FontExample.main(FontExample.java:115)

Which first points at this line of code:
1  
         InputStream inputStream   = ResourceLoader.getResourceAsStream("Pokemon Hollow.ttf");//the font style


Is it because I am not calling the correct location of this font or something?
5  Game Development / Newbie & Debugging Questions / Re: How to set font size in Slick 2D on: 2014-01-21 21:26:02
For this line:
1  
InputStream inputStream = ResourceLoader.getResourceAsStream("myfont.ttf");

is the myfont.tff an actual file or something? Does that mean I have to save the word (the one that I want to increase the font size) to a file or can I just simply type in the word that I want to resize?
6  Game Development / Newbie & Debugging Questions / How to set font size in Slick 2D on: 2014-01-20 20:24:42
I tried doing this to change the font size of my intro, but I am getting an error of "the method setFont() in the type Graphics is not applicable for the arguments (Font) "

Here is what I've tried:

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  
import java.awt.Font;

import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class FirstGameMenu extends BasicGameState{
   
   Font font;
   
   public FirstGameMenu(int state){
     
   }
   
   // load all fonts, graphics, sounds, etc
   public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
      font = new Font("Time New Roman", Font.BOLD, 20);
   }

   //draw stuff on the screen
   public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
     
      Image enter = new Image("res1/button2.png");
      //set the coordinates for the pic
      g.drawImage(enter, 315, 180);
      g.setFont(font);
      g.drawString("How to Play", 385, 460);
      g.drawString("Exit", 415, 520);  
   }
7  Game Development / Newbie & Debugging Questions / Re: How to set boundaries/invisible walls in Slick 2D on: 2014-01-16 04:38:23
How can I adjust the size of the boxes?
Also, could you give me an example of this code? I tried looking it up but all I found is this site
http://useflashpunk.net/basic/handling-collision.html
but I dont think its applicable for me.
*EDIT* Would this be sufficient enough?
http://www.java-gaming.org/index.php?topic=28059.0
8  Game Development / Newbie & Debugging Questions / Re: How to set boundaries/invisible walls in Slick 2D on: 2014-01-16 04:36:26
Ok, thanks Smiley
9  Game Development / Newbie & Debugging Questions / Re: How to set boundaries/invisible walls in Slick 2D on: 2014-01-16 01:23:50
Can someone please tell my why my code wont display? I put it between the qr thing..
10  Game Development / Newbie & Debugging Questions / How to set boundaries/invisible walls in Slick 2D on: 2014-01-16 01:22:36
I am creating my very first game project, but I have no idea how to actually start the code for the boundaries. The game is pretty much an ordinary kid maze game which you are suppose to find your way from point A or point B. Right now I have 2 ideas on how to set the boundaries:
1: (If Java is smart enough), where ever there is black (the boundaries), the person cannot go past it. EASY WAY
2: Figure out the coordinates for all of the black lines and do not allow the person to go past any of it. HARD WAY

OR are none of these valid ways?

Here is my code right now for the play state

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  
package gameOne;

import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class PlayFirstGame extends BasicGameState{

   Image maze;
   Image player;
   float x = 50;
   float y = 50;
   float speed = .25f;
   
   public PlayFirstGame(int state){
     
   }
   
   // load all fonts, graphics, sounds, etc
   public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
      maze = new Image("res1/maze3.jpg");
      player = new Image("res1/normalFace.png");
   }
   
   //draw stuff on the screen
   public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
     
      g.drawImage(maze, 82, 15);
      g.drawImage(player, x, y);
   }
   
   //animation and game logic(AI, user input, etc)
   public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
     
      //movement
      Input input = gc.getInput();

      //up
      if(input.isKeyDown(Input.KEY_UP)){
         y = y - speed * delta;//delta makes the speed run the same on ANY computer
      }
      //down
      if(input.isKeyDown(Input.KEY_DOWN)){
         y = y + speed * delta;
      }
      //left
      if(input.isKeyDown(Input.KEY_LEFT)){
         x = x - speed * delta;
      }
      //right
      if(input.isKeyDown(Input.KEY_RIGHT)){
         x = x + speed * delta;
      }
     
      // add foot prints as they move
     
      //make foot prints disappear after X amount of steps
     
      //if they reach a dead end, failFace
     
      //if they reach the end, winFace
   }
   
   public int getID(){
      return 1;//play is 1
   }
}

Pretty much this code is just the background, the player, and the ability to move the player around.
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

TehJavaDev (30 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (39 views)
2014-10-26 19:37:11

Luminem (21 views)
2014-10-26 10:17:50

Luminem (25 views)
2014-10-26 10:14:04

theagentd (31 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (57 views)
2014-10-16 15:22:06

Norakomi (46 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!