Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 6:12 am

All times are UTC




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sun Aug 19, 2012 3:13 am 
Offline

Joined: Sat Aug 11, 2012 10:13 pm
Posts: 35
So I am making a game which is all the mario games put in one (saving peach; mario kart, donkey kong, and mario bros miningames) http://www.youtube.com/watch?v=vLnFYvFYS5w There is a video of what I have done so far (if you want, I post a video/devlog of what I have done each day in the game because me and my friends mainly wanna play all the mario games together.

Here is what I have for gravity and for jumping.
Code:
   if (gc.getInput().isKeyDown(Input.KEY_UP)) {
         isJumping = false;
         playerY -= delta * playerSpeed;
      }
      if(isJumping) {
         Player.fallSpeed = 0f;
      }
      if(isJumping && playerY < 200) {
         playerY += delta * fallSpeed;
      }
      isJumping = true;
My booleans are kinda the opposite. Is there any good way to do this and have collisions because right now this is how I check for collisions:
Code:
if (gc.getInput().isKeyDown(Input.KEY_LEFT)) {
         animDirection = "_left";
         playerX -= delta * playerSpeed;
         if(playerX < 0) {
            playerX += delta * playerSpeed;
         }
      }
I know it isn't the best, but I am more of a software developer and can get things in that type done, but I wanna learn how to be a game designer, because it is a lot more interesting. If you can help thanks, if you read, thanks, if you don't care, thanks. Also I post my videos at night on what I have done so you have some inspiration. Right now I am using TilED maps and can't figure out how to transfer collisions over from the tutorial on the wiki. Thanks,
Imposter.


Top
 Profile  
 
PostPosted: Sun Aug 19, 2012 4:43 am 
Offline

Joined: Sat Aug 11, 2012 10:13 pm
Posts: 35
Also if somebody could help me with making like the games icon into an image I have. Like the icon you on your tasks for that application like firefoxs icon. I looked through the gamecontainer and found nothing, but setIcon, but it didn't do anything I was expecting.


Top
 Profile  
 
PostPosted: Sun Aug 19, 2012 4:56 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
Imposter wrote:
Also if somebody could help me with making like the games icon into an image I have. Like the icon you on your tasks for that application like firefoxs icon. I looked through the gamecontainer and found nothing, but setIcon, but it didn't do anything I was expecting.




icon is for window icon, not desktop icon.. here: http://slick.cokeandcode.com/javadoc/or ... .String%29

or could even call this directly: http://www.lwjgl.org/javadoc/org/lwjgl/ ... ByteBuffer[]%29


Top
 Profile  
 
PostPosted: Sun Aug 19, 2012 9:26 am 
Offline

Joined: Sun Jul 08, 2012 10:33 am
Posts: 27
hey Imposter,

how are you representing your map? dunno if a tiled map is a good solution but you can make different layers, one for the map and one for the collisions. you can save the collision block in an arraylist/array/linkedlist (whatever you want) and then check our collisions with that.

smth like this:
Code:
forEach(collisionBlock in collisionBlocks) do
    marioShape().intersects(collisionBlock)


well you have to manage this somehow. you dont have to check every collision but just the ones you see on screen/camera.


Top
 Profile  
 
PostPosted: Sun Aug 19, 2012 6:02 pm 
Offline

Joined: Sat Aug 11, 2012 10:13 pm
Posts: 35
Khorne wrote:
hey Imposter,

how are you representing your map? dunno if a tiled map is a good solution but you can make different layers, one for the map and one for the collisions. you can save the collision block in an arraylist/array/linkedlist (whatever you want) and then check our collisions with that.

smth like this:
Code:
forEach(collisionBlock in collisionBlocks) do
    marioShape().intersects(collisionBlock)


well you have to manage this somehow. you dont have to check every collision but just the ones you see on screen/camera.


Well I am very confused on the checking portion, I understand how to get a layer and then check to see what ID is what tile.
Also what variable do I put gc.setIcons() because right now I can't put in an image variable.


Top
 Profile  
 
PostPosted: Sun Aug 19, 2012 10:53 pm 
Offline

Joined: Sat Aug 11, 2012 10:13 pm
Posts: 35
Can somebody help me make a timer for once started it will start calculating time and then I can detect how long it has been and then I can say no more input till you press it again.


Top
 Profile  
 
PostPosted: Mon Aug 20, 2012 3:43 am 
Offline

Joined: Sat Aug 11, 2012 10:13 pm
Posts: 35
I found out how to set the icon, and more efficiently do my mouse cursor. All you do in your start up code is do the appgc.(thing you want) and possibly add in a link to the file for easier usage. I found that to work a lot better, and everything is there on start up. Right now I am hoping to fix the gravity and centering the screen correctly.


Top
 Profile  
 
PostPosted: Mon Aug 20, 2012 8:54 pm 
Offline

Joined: Sun Jul 08, 2012 10:33 am
Posts: 27
for a timer you can use the delta which you should have as a parameter in your update method. its the time that has passed since last update was called.


Top
 Profile  
 
PostPosted: Mon Aug 20, 2012 11:22 pm 
Offline

Joined: Sat Aug 11, 2012 10:13 pm
Posts: 35
Khorne wrote:
for a timer you can use the delta which you should have as a parameter in your update method. its the time that has passed since last update was called.

So should I try if( delta < 500 ){
playerY -= delta * moveSpeed;
}
Is that a way to do it?


Top
 Profile  
 
PostPosted: Tue Aug 21, 2012 10:51 pm 
Offline

Joined: Sat Aug 11, 2012 10:13 pm
Posts: 35
I can't get the timer to work. LWJGL times from the begining, to my knowledge.


Top
 Profile  
 
PostPosted: Wed Aug 22, 2012 2:26 pm 
Offline

Joined: Sat Aug 11, 2012 10:13 pm
Posts: 35
Hey I got the collisions to work out, and now I am adding the custom tiles and that stuff,
does anyone know how to using rows for different animations I can call from for the animation? Also if someone could link me to a timing tutorial where you start a timer.


Top
 Profile  
 
PostPosted: Wed Aug 22, 2012 4:12 pm 
Offline

Joined: Tue Jul 31, 2012 10:31 pm
Posts: 9
The basics of using a timer in Slick is this:

timer += delta

And when timer=1000, 1 second has passed.


Top
 Profile  
 
PostPosted: Thu Aug 23, 2012 4:16 am 
Offline

Joined: Sat Aug 11, 2012 10:13 pm
Posts: 35
I wasn't able to get the timer worked out today. I declared the variable timer = delta. And in my input key added another if statement, but before that set timer to 0 and then waited till timer < 2000.

Also can someone help me, I wanna add in direction for my character, is there an easy way to do this in one sprite sheet?


Top
 Profile  
 
PostPosted: Fri Aug 24, 2012 10:25 am 
Offline
Regular

Joined: Tue Aug 23, 2011 8:19 am
Posts: 111
This is basically what you're supposed to do.
Code:
public class MyGameState extends BasicGameState
{
    private int timer;
   
    public MyGameState()
    {
        timer = 0;
    }
   
    public void update(int delta)
    {
        timer += delta;
        if (timer > 2000) // if 2 seconds have passed since the timer was last set to 0
        {
            // do stuff
            timer = 0; // reset the timer
        }
    }
}
Is that what you have in your code?
Note: don't try running that code. It's missing so many things that BasicGameState requires.

_________________
My indie games: http://cmagames.webs.com


Top
 Profile  
 
PostPosted: Fri Aug 24, 2012 11:53 pm 
Offline

Joined: Sat Aug 11, 2012 10:13 pm
Posts: 35
Code:
package com.src.impostor;

import java.awt.Font;
import java.io.InputStream;

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

public class StateGame extends BasicGameState {
   
   private java.awt.Font awtFont;
   TrueTypeFont font;
   TrueTypeFont font2;
   SpriteSheet mario;
   Music background;

   public static int world = 1;
   public static int level = 2;
   
   private boolean isJumping = Player.isJumping;
   float playerX = Player.playerX;
   float playerY = Player.playerY;
   private Animation animPlayer;
   int frame = 0;
   private float playerSpeed = Player.moveSpeed;
   private float fallSpeed = Player.fallSpeed;
   private int jumpTimer;
   
   private BlockMap map;
   private boolean[][] blocked;
   private static final int SIZE = 16;
   
   public StateGame(int state) {
      jumpTimer = 0;
   }

   public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
      awtFont = new java.awt.Font("Verdana", Font.PLAIN, 16);
        font = new TrueTypeFont(awtFont, false);
      try {
         InputStream inputStream = ResourceLoader.getResourceAsStream("res/font/ArcadeClassic.ttf");
         Font awtFont2 = Font.createFont(Font.TRUETYPE_FONT, inputStream);
         awtFont2 = awtFont2.deriveFont(15f);
         font2 = new TrueTypeFont(awtFont2, false);
      } catch (Exception e) {
         e.printStackTrace();
      }
      mario = new SpriteSheet("res/char/mario.png", 16, 16);
      animPlayer = new Animation();
      animPlayer.setAutoUpdate(false);
      for(int frame=0; frame <4;frame++) {
         animPlayer.addFrame(mario.getSprite(frame, 0), 150);
         if(animPlayer.getFrame() <= 2) {
            animPlayer.setCurrentFrame(0);
         }
      }
      map = new BlockMap("res/world/world" + StateGame.world + "-" + StateGame.level + ".tmx");
      blocked = new boolean[map.tmap.getWidth()][map.tmap.getHeight()];
      for(int xAxis=0;xAxis<map.tmap.getWidth();xAxis++) {
         for(int yAxis=0;yAxis<map.tmap.getHeight(); yAxis++) {
            int tileID = map.tmap.getTileId(xAxis, yAxis, 0);
            String value = map.tmap.getTileProperty(tileID, "blocked", "false");
            if("true".equals(value)) {
               blocked[xAxis][yAxis] = true;
            }
         }
      }
      background = new Music("res/sound/music/overworld.ogg");
   }
   
   public void enter(GameContainer gc, StateBasedGame sbg) {
      background.play();
      background.loop();
   }
   
   public void leave(GameContainer gc, StateBasedGame sbg) {
      background.stop();
   }
   
   public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
      jumpTimer = 0;
      if (gc.getInput().isKeyDown(Input.KEY_LEFT)) {
         if(!isBlocked(playerX - delta * 0.1f, playerY)&& playerX > 0) {
         playerX -= delta * playerSpeed;
         }
      }
      if (gc.getInput().isKeyDown(Input.KEY_RIGHT)) {
         if (!isBlocked(playerX + SIZE + delta * 0.1f, playerY)) {
            animPlayer.update(delta);
            playerX += delta * playerSpeed;
         }
      }
      if (gc.getInput().isKeyDown(Input.KEY_UP)) {
         if (!isBlocked(playerX, playerY - delta * 0.1f) && playerY >= 0) {
            isJumping = false;
            jumpTimer += delta;
            animPlayer.setCurrentFrame(3);
            playerY -= delta * fallSpeed;
            if(jumpTimer > 2000) {
               isJumping = true;
            }
         }
      }
      if (isJumping) {
         Player.fallSpeed = 2.4f;
      }
      if (isJumping && playerY < 255) {
         playerY += delta * fallSpeed;
      }
      isJumping = true;
   }
   
   public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
      g.scale(2, 2);
      map.tmap.render(-60, 0);
      g.drawAnimation(animPlayer, playerX, playerY);
      g.resetTransform();
      font2.drawString(20, 30, "Mario");
      font2.drawString(650, 10, "World " + world + " Map " + level);
   }
   
   private boolean isBlocked(float playerX, float playerY) {
      int xBlock = (int) playerX / SIZE;
      int yBlock = (int) playerY / SIZE;
      return blocked[xBlock][yBlock];
   }
   
   public int getID() {
      return 2;
   }
}
Here is my code. I can't get collisions to work. . .I think one of my variables might be wrong :( Anyways the time isn't working out very well, it is setting it constantly at 0 so it won't stop. Also I was wondering how I could use rows for different animations like if(input.left) {animPlayer.row++}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group