[QUOTE=GeEkOfWiReS;46364714]
Here's what you need
[code]
steam://friends/message/7656119xxxxxxxxxx/<Your message here>
[/code]
Which means taking your friends name and trying to find its Steam64 ID, and replacing the rest of the numbers with what the ID actually is. I don't know if the traditional Steam ID format, STEAM_0:X:XXXXXX is compatible.[/QUOTE]
I tried that already, I couldn't get it to work.
[QUOTE=Cold;46364973]You can't.[/QUOTE]
Then how does stuff like chatbots work?
[QUOTE=Ardosos;46365391]I tried that already, I couldn't get it to work.
Then how does stuff like chatbots work?[/QUOTE]
they use libraries like steamkit or opensteamclient
[QUOTE=Bumrang;46366006]they use libraries like steamkit or opensteamclient[/QUOTE]
How do I do that? Sorry to be difficult here.
just include them as a lib in your c# (steamkit) or c++ (opensteamclient) program
--- moved from WAYWO ---
[QUOTE=utilitron;46374518]So all of the code for moving your bullet exists only in the fire action
[CODE]
public void execute() {
dt = clock.getElapsedTime().asSeconds();
x = Player.getPos().x + 20 * dt;
y = Player.getPos().y + 20 * dt;
bulletSprite.setRotation((float)Player.getAngle());
Entity bulletEntity = new Entity(bulletSprite);
GameScreen.addEntity(bulletEntity);
bulletSprite.setPosition(x, y);
}
[/CODE]
but what you need is this code to exist in the bullet's entity. You need to make a bullet entity that extends entity and implements the movement code.
also it would be a good idea to separate your display logic from your update logic.
Enity.java should look like this:
[CODE]
public class Entity {
private final Sprite sprite;
public Entity(Sprite s) {
sprite = s;
}
public void draw() {
Window.getWindow().draw(sprite);
}
public void update(float dt) {
// Stub
}
}
[/CODE]
and Bullet.java should look like this
[CODE]
public class Bullet extends Entity {
@Override
public void update(float dt) {
x = Player.getPos().x + 20 * dt;
y = Player.getPos().y + 20 * dt;
sprite.setRotation((float)Player.getAngle());
sprite.setPosition(x, y);
}
}
[/CODE]
I haven't tested this code so I make no claims as to if it will work at first go, but if it does... feel free to be shocked for me.[/QUOTE]
Alright, that makes things a lot simpler and organized! Thank you so so so much for helping me, dude!
[img]http://i.imgur.com/3nmFKYz.gif[/img]
Progress, but a few problems:
The Clock I am using for each bullet seems to persist through each creation, even though I declare a new Clock each time I instantiate a bullet. I figure this has to do with the problem of not being able to have more than one bullet on screen.
Updated my github:
[url]https://github.com/Tetramputechture/Corraticca/[/url]
Thanks to all you guys so much for motivating me! You have no idea how happy I will be once I finally get my player to shoot bullets and have multiple bullets on screen.
How can I make my program pause for a few seconds before printing a new line in C?
For example, I'd like my program to print out "processing..." first then make it wait for about 2~ seconds before printing "process complete!".
[QUOTE=frdrckk;46375708]How can I make my program pause for a few seconds before printing a new line in C?
For example, I'd like my program to print out "processing..." first then make it wait for about 2~ seconds before printing "process complete!".[/QUOTE]
If you are on windows, then include <Windows.h>, and then use Sleep(milliseconds).
I find it pretty amusing that computers are so fast that you're having to pretend to spend longer processing now! :P
[QUOTE=NixNax123;46374860]
-snip-
Progress, but a few problems:
The Clock I am using for each bullet seems to persist through each creation, even though I declare a new Clock each time I instantiate a bullet. I figure this has to do with the problem of not being able to have more than one bullet on screen.
Updated my github:
[url]https://github.com/Tetramputechture/Corraticca/[/url]
Thanks to all you guys so much for motivating me! You have no idea how happy I will be once I finally get my player to shoot bullets and have multiple bullets on screen.[/QUOTE]
The easiest solution ere is to move the clock out of the bullet entity and into GameScreen. If you look back at the original code I posted I was passing in the latest time from the game loop instead of having the clock persist inside the entity.
GameScreen should look like this:
[CODE]
public class GameScreen implements Screen {
private static final Color bgColor;
private static final int numButtons;
private static final Button[] buttons;
private static final List<Entity> entities;
private static int numEntities;
// private static Level currentLevel;
private final Clock clock;
private float lastTime;
static {
numButtons = 0;
buttons = new Button[numButtons];
bgColor = Color.WHITE;
entities = new ArrayList<>();
// all game screens have a player
Entity playerEntity = new PlayerEntity(PlayerEntity.getSprite());
addEntity(playerEntity);
clock = new Clock();
lastTime = 0;
}
@Override
public void show() {
Window.getWindow().clear(bgColor);
float currentTime = clock.getElapsedTime().asSeconds();
float dt = currentTime - lastTime;
for (Entity e : entities) {
e.draw();
e.update(dt);
}
Window.getWindow().display();
lastTime = currentTime;
}
@Override
public Button[] getButtons() {
return buttons;
}
public static Color getBGColor() {
return bgColor;
}
public static void addEntity(Entity e) {
entities.add(e);
numEntities++;
System.out.format("Entity count: %s\n", numEntities);
}
@Override
public String toString() {
return "GAME";
}
}
[/CODE]
We also can just set the origin of the bullet as the player and not use it as a reference past that point.
BulletEntity should look like this:
[CODE]
public class BulletEntity extends Entity {
private final int vx = 20;
private final int vy = 20;
private float x;
private float y;
private final Sprite bulletSprite;
public BulletEntity(Sprite s) {
super(s);
bulletSprite = s;
x = PlayerEntity.getPos().x;
y = PlayerEntity.getPos().y;
bulletSprite.setRotation(PlayerEntity.getAngle());
bulletSprite.setPosition(x, y);
}
@Override
public void update(float dt) {
x += vx * dt;
y += vy * dt;
bulletSprite.setPosition(x, y);
}
}
[/CODE]
We are now calculating how far the bullet moved per step instead of over total time.
I don't know python but didn't you forget to place a comma after every entry?
[QUOTE=Tommyx50;46376264]If you are on windows, then include <Windows.h>, and then use Sleep(milliseconds).
I find it pretty amusing that computers are so fast that you're having to pretend to spend longer processing now! :P[/QUOTE]
Out of curiosity, is there a library which does this for all operating systems?
Thanks by the way!
[QUOTE=utilitron;46376932]
We are now calculating how far the bullet moved per step instead of over total time.[/QUOTE]
Thanks, man! I really appreciate it!
Now, the game only registers one bullet, and every time I hit spacebar, that bullet speeds up.
What's happening here? I thought if a new bullet was created more would be on screen, but only one is on screen at the moment.
[url]https://github.com/Tetramputechture/Corraticca/[/url]
[editline]31st October 2014[/editline]
I did get the bullet to move based on angle of the player, but the bullet only comes out at the angle that the player was at the first frame.
So lets look at fire action. You are only adding 1 bullet entity and overwriting it, rather than adding a new one each time you press spacebar.
[CODE]
public class FireAction implements Action {
public static final String NAME = "FIRE_ACTION";
private Texture bulletTexture;
public FireAction() {
System.out.println("Fire key pressed!");
bulletTexture = new Texture();
String bulletTextureFile = "bullet.png";
try {
this.bulletTexture.loadFromFile(Paths.get(bulletTextureFile));
} catch (IOException ex) {
Logger.getLogger(PlayerEntity.class.getName()).log(java.util.logging.Level.SEVERE,
String.format("Unable to load file %s!\n", bulletTextureFile),
ex);
}
bulletTexture.setSmooth(true);
}
@Override
public void execute() {
Sprite bulletSprite = new Sprite(bulletTexture);
BulletEntity bulletEntity = new BulletEntity(bulletSprite);
bulletSprite.setOrigin(Vector2f.div(new Vector2f(bulletTexture.getSize()), 2));
bulletSprite.setRotation(PlayerEntity.getAngle());
GameScreen.addEntity(bulletEntity);
}
public Sprite getSprite() {
return this.bulletSprite;
}
@Override
public String toString() {
return NAME;
}
}
[/CODE]
You're totally right, I'm dumb. I guess growing out of noob mistakes just leads to a little more advanced noob mistakes. But at least I'm learning! Thank you!
Now I just have to get the bullet to leave the player sprite at the right position, and I'll be happy!
Of course, I also need to delete the bullet entity when it leaves the screen.
[url]https://github.com/Tetramputechture/Corraticca/[/url]
The next thing is to reduce your overhead. Every time you call Actions.get(l[1]).newInstance() you are taking up space in memory for the class, and also adding a new texture. These can be reused.
Now that execute method creates a new instance of the bullet entity, you can just call execute to add bullets.
In Inputs.java
[CODE]
public static void setKeys() throws FileNotFoundException, IOException {
FileInputStream incfg = new FileInputStream(new File("inputconfig.cfg"));
try (BufferedReader br = new BufferedReader(new InputStreamReader(incfg))) {
String line, key, action;
while ((line = br.readLine()) != null) {
String[] l = line.split("\\: ");
if (Actions.containsKey(l[1])) {
try {
gameKeys.put(Keyboard.Key.valueOf(l[0]), Actions.get(l[1]).execute());
} catch (InstantiationException ex) {
Logger.getLogger(Input.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(Input.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
[/CODE]
Thank you! Although your solution didn't work with my implementation, I just changed
[code]public static void handlePlayerKeyInput() {
if (gameKeys.containsKey(currentKey)) {
try {
gameKeys.get(currentKey).getClass().newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
Logger.getLogger(Input.class.getName()).log(Level.SEVERE, null, ex);
}
gameKeys.get(currentKey).execute();
}
}[/code]
to
[code] public static void handlePlayerKeyInput() {
if (gameKeys.containsKey(currentKey)) {
gameKeys.get(currentKey).execute();
}
}[/code]
Thank you!
[editline]31st October 2014[/editline]
Now, a more general question:
I have a small square sprite.
I need to get the top center of the sprite based on rotation.
Here's an image describing what I want:
[img]http://i.stack.imgur.com/OoQnG.png[/img]
The left sprite is the sprite at it's natural position, and the other sprites are rotated. The black dot's position is what I want to get (the position on the sprite).
I know this is probably a dumb question achieved with a basic knowledge of trig, but I can't figure it out.
I believe you can just take the rotation of your player, and create a new position that you scale to the where you need.
[code]
Vector2 bulletspawnPosition = (Vector2(cos(playerRotation),sin(playerRotation)) * distance) + player.position;
[/code]
I'm not familiar with Java or your code though
[QUOTE=frdrckk;46377491]Out of curiosity, is there a library which does this for all operating systems?
Thanks by the way![/QUOTE]
All you need is C++11. [url]http://www.cplusplus.com/reference/thread/this_thread/sleep_for/[/url]
[QUOTE=FalconKrunch;46380182]I believe you can just take the rotation of your player, and create a new position that you scale to the where you need.
[code]
Vector2 bulletspawnPosition = (Vector2(cos(playerRotation),sin(playerRotation)) * distance) + player.position;
[/code]
I'm not familiar with Java or your code though[/QUOTE]
That worked! Thank you!
[QUOTE=frdrckk;46377491]Out of curiosity, is there a library which does this for all operating systems?
Thanks by the way![/QUOTE]
You can write a sleep wrapper function and use some simple preprocessor directives like so (much simpler than including an entire library!):
[CODE]#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
void sleepCP(int ms) { // Cross-platform sleep function
#ifdef WIN32
Sleep(ms);
#else
usleep(ms * 1000); // usleep takes a time in microseconds, so multiply by 1000
#endif
}[/CODE]
Then, whenever you want to sleep, just use sleepCP and it should work on both platforms!
Anyone here who has access to a Wii U devkit? Our school is getting a few soon apparently, but I'd like to know if the SDK has a compiler that supports C++11 (I am planning out a cross-platform library).
So I'm trying linear interpolation on a sprite for movement:
[code] @Override
public void update(float dt) {
vx += ((targetX - vx) * 120) * dt;
vy += ((targetY - vy) * 120) * dt;
x += vx * dt;
y += vy * dt;
}
public static void moveUp() {
targetY = -1;
}
public static void moveDown() {
targetY = 1;
}
public static void moveLeft() {
targetX = -1;
}
public static void moveRight() {
targetX = 1;
}[/code]
However, any value I multiply the difference by (up to about 120) just makes it go the same speed: extremely slow. But when I pass about that point, the sprite just spazzes off the screen when I press a button.
[editline]1st November 2014[/editline]
[url]https://github.com/Tetramputechture/Corraticca/[/url] If you need more context.
How would you all say the best way of creating random generation would be? Currently using just manual placements of 1s and 0s to determine collision or not, but I wouldn't want to put in all the levels by hand.
[QUOTE=NixNax123;46384270]So I'm trying linear interpolation on a sprite for movement:
[code] @Override
public void update(float dt) {
vx += ((targetX - vx) * 120) * dt;
vy += ((targetY - vy) * 120) * dt;
x += vx * dt;
y += vy * dt;
}
public static void moveUp() {
targetY = -1;
}
public static void moveDown() {
targetY = 1;
}
public static void moveLeft() {
targetX = -1;
}
public static void moveRight() {
targetX = 1;
}[/code]
However, any value I multiply the difference by (up to about 120) just makes it go the same speed: extremely slow. But when I pass about that point, the sprite just spazzes off the screen when I press a button.
[editline]1st November 2014[/editline]
[url]https://github.com/Tetramputechture/Corraticca/[/url] If you need more context.[/QUOTE]
Your target velocity is 1. That's probably not very fast.
It spazzes about above a threshold because the delta "overshoots" the goal, clamping helps there
[QUOTE=WeltEnSTurm;46385058]Your target velocity is 1. That's probably not very fast.
It spazzes about above a threshold because the delta "overshoots" the goal, clamping helps there[/QUOTE]
Alright, now it's working well, except when I just press a key and leave the player to move it never slows down from it's final velocity. How would I fix this?
[QUOTE=NixNax123;46385254]Alright, now it's working well, except when I just press a key and leave the player to move it never slows down from it's final velocity. How would I fix this?[/QUOTE]
Apply friction every frame. Multiply the velocity by 0.95 or some value.
Edit:
Acceleration, i meant acceleration, not velocity.
[QUOTE=cartman300;46385275]Apply friction every frame. Multiply the velocity by 0.95 or some value.[/QUOTE]
That's not working, it just produces the same results.
What I'm trying based on your post:
[code] vx += (targetX - vx) * dt;
vy += (targetY - vy) * dt;
vx *= 0.95;
vy *= 0.95;
x += vx * dt;
y += vy * dt;[/code]
Even when I set the value lower, or do it directly through the class calling the update method per frame, it still moves at a constant speed.
duh, you approach target velocity every frame so multiplying by 0.95 won't do anything
Hint: your target velocity stays at what you set, even when you release the keys
[QUOTE=WeltEnSTurm;46385328]duh, you approach target velocity every frame so multiplying by 0.95 won't do anything
Hint: your target velocity stays at what you set, even when you release the keys[/QUOTE]
JSFML has no functions for key release :(
There should be acceleration of object and position of object. When processing input keys you set the acceleration to some value. On every update add acceleration times delta time to the position, to apply friction you just multiply the acceleration by a number smaller than 1 or subtract some value times delta time for it.
[editline]1st November 2014[/editline]
You can set the acceleration in update function every time to max value if [URL="https://github.com/pdinklag/JSFML/blob/master/src/java/org/jsfml/window/Keyboard.java#L572"]this[/URL] is true and else let the friction do the rest or just set acceleration to 0 to slow down/stop the object.
Okay, this is making friction work as intended:
[code] vx += (targetX - vx) * dt;
vy += (targetY - vy) * dt;
targetX *= 0.95;
targetY *= 0.95;
x += vx * dt;
y += vy * dt;[/code]
However, I can only move in cardinal directions +/- a few degrees, and the movement is still a little buggy, like if I go left/right for too long and then go up/down it goes up/down very slowly. :(
Sorry, you need to Log In to post a reply to this thread.