Show Posts
|
|
Pages: [1]
|
|
1
|
Games Center / Showcase / Re: Colours
|
on: 2012-11-19 20:16:10
|
The lite version of this app is now available  Please test it out and if you like it share it with your friends and rate it  
|
|
|
|
|
2
|
Games Center / Showcase / Re: Colours
|
on: 2012-11-18 22:13:03
|
This forum uses BBCode so you would want to do something like: Regarding the game: thank you! I've been wanting to practice my RGB kung-fu abilities. Unfortunately, I'm broke and can't even pay $1 for this app  Thanks! I did not know that. PM me with an email adress and I will send you a free copy 
|
|
|
|
|
3
|
Games Center / Showcase / Colours
|
on: 2012-11-18 22:02:23
|
 My first game for android is finally released. It is called Colours and basically what you should do is to match a random colour with the help of the R G B values. Colours is a new unique puzzle game that focus on colours. Your objective is to match the colour that is randomly generated on every level. If you do it fast you will gain more point! The game becomes harder and harder for every level! And everything is on the clock. The faster you do it the more points and time will you get. The goal is to complete as many levels as possible to archive the top position on the high score list.  If you want you can try it out here:  Lite version:  If you want to know more about me or colours: Follow me at my site www.dalsgames.dalsit.se or on Twitter @DalsGames
|
|
|
|
|
5
|
Game Development / Game Mechanics / Re: Basic platform movement and gravity
|
on: 2012-02-28 20:19:18
|
Okey guys! I feel a little lost now! You talking about some funky raycasting and stuff Of what I understood from your replays was that it was difficult to calculate the collisions and when to stop which velocity due to my world implementation? Have I understood you right? What I want is a simple platformer with the basic movement and physics 
|
|
|
|
|
7
|
Game Development / Game Mechanics / Re: Basic platform movement and gravity
|
on: 2012-02-25 13:46:09
|
Ah, for collision detection?
You'd put a check where the comment "//change position by velocity" is in the prior code. Otherwise you're moving the character twice (I'm assuming that you're checking after you've run the update code, which means you're adding velocity.x/y twice, and the second time without applying the delta.)
Well this is how I've done it this far: in my frame class I've the detection of collision... (It has to be here due to the way I draw my world.) 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| private boolean checkCollision () { for (int n = 0; n < map.getBlocks().size();n++) { if (player.getBounds().intersects(map.getBlocks().get(n).getBounds())) {
return player.collision = true; } } return player.collision = false; } |
Then I my hero class I have: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public void setIsOnGround () { if (collision == true) { isOnGround = true; } else { updateGravity (0.5f); isOnGround = false; } }
|
And in my gameUpdate method I have this 1 2 3 4 5 6 7 8 9
| checkCollision (); player.setIsOnGround(); player.update(0.5f); gameRender (); |
The overrided physical entity method in my hero class : 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
| @Override public void update (float delta) { if (isOnGround){ velocity.x *= 1.0f - ((1.0f - GROUND_FRICTION) * delta); velocity.y *= 1.0f - ((1.0f - GROUND_FRICTION) * delta); } else{ velocity.x *= 1.0f - ((1.0f - AIR_FRICTION) * delta); velocity.y *= 1.0f - ((1.0f - AIR_FRICTION) * delta); } if (collision == true ) { velocity.x = 0; velocity.y = 0; }
position.x += velocity.x * delta; position.y += velocity.y * delta; } |
With this code I've managed to get it to stop when it hits a block from above due to the gravity... but when I hit a block I get stuck and can't move. What should happen to the gravity and the two booleans (collision,isOnGround) when the object hit a block? Any suggestions? 
|
|
|
|
|
8
|
Game Development / Game Mechanics / Re: Basic platform movement and gravity
|
on: 2012-02-25 03:28:11
|
Hey again! I was able to implement the physics and it workes fine! But what would progaming be whiteout some problem!  As I said the movement is perfect but now my collision detecion get screwed up by using this new vector class that you wrote for me. My bounding rectangle before was created like this: 1 2 3 4 5
| public Rectangle getBounds () { Rectangle r ; r = new Rectangle (positionX +x ,positionY +y ,width,height); return r; } |
This worked like a charm because the bounding rectangle would move before the player which would make the collision perfect. I've tried to implement this this collision detecion with the new physics code like this : 1 2 3 4 5
| public Rectangle getBounds () { Rectangle r ; r = new Rectangle ((int)position.x + (int) velocity.x,(int) position.y + (int)velocity.y, width, height); return r; } |
but I'm not able to get it to work! Do you have any suggestion on how I should do this insteed? p.s sorry about my grammar, it's kinda late xD
|
|
|
|
|
10
|
Game Development / Game Mechanics / Re: Basic platform movement and gravity
|
on: 2012-02-23 19:02:02
|
Okay! Yeah that sounds pretty logic.. do you think I should change the code for the left and right movement aswell? I'm not completly sure how to implement the velocity for the movement so if you could point me in the direction (I know that you already given my a hint) 
|
|
|
|
|
11
|
Game Development / Game Mechanics / Re: Basic platform movement and gravity
|
on: 2012-02-23 18:08:16
|
call move before you paint it or else there will be a lag effect. Could you be a bit more specific on how your movement isn't "good"?
Hi, thanks for your replay! I've changed the code so the move method is before the draw method in my gameUpdate but I didn't notice something. Well what I ment was that the movement fells very choppy and unnatural... do you have any advice?
|
|
|
|
|
12
|
Game Development / Game Mechanics / Basic platform movement and gravity
|
on: 2012-02-22 22:13:55
|
Hello! I'm working on a very basic platform engine. This is my first attempt so please excuse me for sloppy programming pratice and such  I've got a working platform engine. A player that moves and a "world" loaded from a file. My problem is that the movement and physics isn't that good and i really don't like how it looks. I'd like to know what to do with the code to get a smooth movement and physics that works properly! I've implemented collision detecion, which I think works okay but if someone thinks diffrently please explain what I should do to make it better. If someone helps me out with this it would help my out alot  So time for some code My Frame class (The main class) 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
| import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.image.BufferedImage; import java.io.IOException;
import javax.swing.JFrame;
public class Frame extends JFrame implements Runnable,KeyListener {
private static final long serialVersionUID = 1L; int screenWidth =640; int screenHeight =480; Map map; Block blocks; BufferedImage backBuffer; ImageEntity background; Graphics2D g2d; AnimatedSprite hero; Hero player; int playerX = 320; int playerY = 100; int moveX,moveY; boolean collision = false; int test = 0; long TimeStart,TimeEnd; int frameCount = 0; int frameRate = 0; long startTime = System.currentTimeMillis(); int desierdRate = 60; Thread gameloop; public static void main(String[] args) { new Frame(); } Frame () { super ("The Diary"); setSize (screenWidth,screenHeight); setVisible (true); setResizable (false); setDefaultCloseOperation (3); backBuffer = new BufferedImage (screenWidth,screenHeight,BufferedImage.TYPE_INT_RGB); g2d = backBuffer.createGraphics(); background = new ImageEntity (this); background.load("bluespace.png");
player = new Hero (32,32); player.showBounds(true); map = new Map("maze.txt"); gameloop = new Thread (this); gameloop.start(); addKeyListener (this);
} public void run () { Thread t = Thread.currentThread(); try { map.createMap(); } catch (IOException e) { e.printStackTrace(); } while (t == gameloop) { try { Thread.sleep(1000 / desierdRate); } catch (InterruptedException e) { e.printStackTrace(); } gameUpdate (); repaint (); } }
void gameUpdate () { log ("FPS :"+ frameRate); frameCount++; if (System.currentTimeMillis() > startTime + 1000) { startTime = System.currentTimeMillis(); frameRate = frameCount; frameCount = 0; } g2d.setColor(Color.GRAY); g2d.fill(new Rectangle (0,0,screenWidth-1,screenHeight-1)); for (Block b : map.getBlocks()) { b.draw(g2d); } checkCollision () ; player.draw(g2d); player.move(); g2d.setColor(Color.WHITE); g2d.drawString("FPS: "+ frameRate, 50, 50); g2d.drawString("Player X" + player.positionX, 50,70); g2d.drawString("Player Y"+ player.positionY, 50, 80); g2d.drawString ("Collison:" + player.collision,50,100); g2d.drawString("Falling: " + player.falling, 50, 110); } private boolean checkCollision() { for (int n = 0; n < map.getBlocks().size();n++) { if (player.getBounds().intersects(map.getBlocks().get(n).getBounds())) {
return player.collision = true; } } return player.collision = false; }
public void paint (Graphics g) { g.drawImage(backBuffer, 0, 0, this); }
public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_LEFT: player.setX(-5); break; case KeyEvent.VK_RIGHT: player.setX(5); break; case KeyEvent.VK_UP : player.setGravity(0); player.setY(-50); break; case KeyEvent.VK_SPACE: player.positionX = 150; player.positionY = 150; break; } }
public void keyReleased(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_LEFT: player.setX(0); break; case KeyEvent.VK_RIGHT: player.setX(0); break; case KeyEvent.VK_UP: player.setY(0); player.setGravity(5); break; } } public void keyTyped(KeyEvent e) { } public void log(String s) { }
} |
My Hero class : 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
| import java.awt.*;
public class Hero {
int positionX,positionY,x,y; int width,height; int gravity; boolean drawBounds; boolean collision,falling ; Map m; Hero (int width,int height) { positionX = 150; positionY = 150; this.width = width; this.height = height; drawBounds = false; } public void draw (Graphics2D g2d) { g2d.setColor(Color.BLACK); g2d.fillRect(positionX, positionY, width, height); if (drawBounds == true) { g2d.setColor(Color.RED); g2d.drawRect(positionX + x , positionY +y, width, height); } } public Rectangle getBounds () { Rectangle r ; r = new Rectangle (positionX +x ,positionY +y ,width,height); return r; } public void showBounds(boolean b) { drawBounds = b; }
public void setX (int x) { this.x = x; } public void setY (int y) { this.y = y; } public void move () { if (collision == true) { setGravity (0); x = 0; y = 0; } if (y > 0) { falling = true; } else { falling = false; } if (x > 0 || x< 0 && collision == false) { setGravity (5); } positionX +=x; positionY +=y; gravity(); }
public void setGravity (int gravity){ this.gravity = gravity; } private void gravity () { setY (gravity); } } |
If needed my block class and world class 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
| import java.awt.*;
import javax.swing.ImageIcon; public class Block {
int width,height,x,y; Image BLOCK_WALL; public Block (int x, int y) { this.x = x; this.y = y; width = 20; height = 20; BLOCK_WALL = new ImageIcon ("D:/Programmering/Projekt/Workspace/Framework/src/block_wall.png").getImage(); } public void draw (Graphics2D g2d) { g2d.drawImage(BLOCK_WALL, x, y, width,height,null); g2d.setColor(Color.RED); g2d.drawRect(x, y, width, height); } public Rectangle getBounds() { Rectangle r; r = new Rectangle (x,y,width,height); return r; }
} |
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
| import java.util.*; import java.io.*;
public class Map {
ArrayList <Block> blocks; String filePath; public Map (String path) { filePath= path; blocks = new ArrayList<Block>(); } public void createMap () throws IOException { ArrayList <String> lines = new ArrayList <String>(); BufferedReader r= new BufferedReader (new FileReader (filePath)); while (true) { String line = r.readLine(); if (line == null) { r.close(); break; } else { lines.add(line); } } for (int y = 0; y < lines.size(); y++) { for (int x = 0; x<lines.get(y).length();x++) { char mark = lines.get(y).charAt(x); if (mark == '#') { blocks.add(new Block (x*20,(y*20)+25)); } } } } public ArrayList <Block> getBlocks () { return blocks; } } |
I'm new to this fourm so please excuse me if I've posted in the wrong forum and for my unbelievable long post x) Thank in advance!
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|