C++ :: 2D RPG Game - Smooth Sprite Movement (SDL)

Feb 7, 2015

I'm making a 2D rpg game, but I have some problem with the sprite movement. The sprite movement feels choppy. That's because I move the sprite 5 pixels per seconds. I now that I need somthing that have to do with SDL_getTicks and deltatime, but I dont know how to use/implement it.

Here is a little part of my code:

float spriteDstY;
float spriteDstX;
float speed = 5;
while(SDL_PollEvent(&event)!= 0) {
if (event.type == SDL_QUIT)

[Code] ....

View 8 Replies


ADVERTISEMENT

C++ :: How To Get Smooth Sprite Movement In SDL By Using Delta Time

Nov 30, 2014

I'm trying to get smooth sprite movement in SDL by using delta time. The way I'm calculating it is

long last = 0;
float deltaTime = 0.0;
...
long now = SDL_GetTicks();
//deltatime is in seconds
if (now > last) {
deltaTime = ((float)(now - last)) / 1000;
last = now;
}

And I'm updating the sprite like this:

virtual void update(float deltaTime) {
float dx = 100*deltaTime;
transform->position.x += dx;
}

But the movement is still noticeably jerky. Also, if I'm correct, my sprite should move 100 pixels to the right every second using this method, so it should take the sprite 8 seconds to reach the end of my window, since it's 800 pixels wide, but it takes it way longer than that. In other words the delta time I'm calculating can't be correct. Am I doing something horribly wrong? I'm guessing it has something to do with rounding, but I'm not sure.

View 2 Replies View Related

C :: Detect Mouse Movement

Aug 17, 2013

i was trying to write a program in c language which can detect mouse movement, but the program which i have written can only detect the mouse click or scroll the program which i have written given below..

Code:

#include<stdio.h>
#include<string.h>
#include <ncurses.h>
int main() {
}

[code]....

run the programme with linked-lncurses. improve my program which also detect when the mouse moves.

View 1 Replies View Related

C :: History Of User Movement

Feb 27, 2013

I want to make history of user's movement. Whenever the user inputs something, and the input is valid, then the input information will be stored into something. And later on, the history shows up whenever I pick the choice.

I have the specific program to make history.

View 3 Replies View Related

C++ :: Controlling The Object Movement?

Mar 7, 2013

I am currently working on quite complex project. Anyway, im not gonna go into deeper details. What I am stuck with is following function.

What I've got so far is basically a picture, and what I am trying to do is to set continuous movement to it, allow the user to control the directions of its movement by pressing "Up" , "Down", "Left " and "Right" key. The best example I can base my idea on is "Snake" game.

I don't have much of a code, however I am willing to upload it upon request.

View 1 Replies View Related

C++ :: Sine Wave Movement With The Saucer

May 4, 2014

I am currently working on an arcade game for my final assignment this year. I am struggling to get a sine wave movement with the saucer. Here is the code for it:

void ArcadeGame::spawnSaucer() {
Texture* pTexture = getTexture("saucertexture");
m_pSaucer = new GameObject(pTexture, "saucer");
m_pSaucer -> setPosition(1000, 300);
m_pSaucer -> setVelocity(-1, 10 * sin(1 * 3 * PI / 180), sin(1) * OBJECT_DEFAULT_SPEED);
addGameObject(m_pSaucer);
m_pSaucer->setSolid(true);
}

View 8 Replies View Related

C++ :: 2D Sprite Shakes While Being Followed By Camera

Jan 28, 2013

I'm making my view follow around my players ship, so it is always in the center, however at any angle other than 0/90/180/270 the player sprite starts shaking, more so when speed is increased and when the angle is closer to 45/135/225/315

I'm using SFML2, I would take a screenshot but it only captures one frame, which doesn't actually show it shaking.

void ViewFollowPlayer(sf::View& View, sf::RenderWindow& Window, double Delta)
{
double pSpeed = Player.getSpeed();

[Code].....

View 3 Replies View Related

C++ :: Getting Sprite To Animate With SFML

Dec 10, 2013

So this is my first try animating on my own, without a reference right in front of me. It's not working, I did check some of the projects I've made in the past, but for one those were done with Allegro, and really it should be able to move over to SFML quite easily, but it's not. It does display on the window in the correct place, but there are 3 pictures in the file and I want it to cycle through them, but it shows all three at the same time, and it only works once. if I press space a second time, only one of the pictures shows up, and it doesn't cycle at all. Here is my .cpp file :

#include "headers.h"
#include "SwordSprite.h"
int top = 0;
int left = 88;
int right = 132;
int bottom = 35;
SwordSprite::SwordSprite() {

[Code] .....

View 2 Replies View Related

Visual C++ :: OpenGL - 2D Movement With Respond To Keypress

Mar 4, 2014

I'm trying to implement keyboard controls to move a sphere(Player) with respond to keypress. Currently, when I press any key my character will move to the right by 0.1. How can I move my character with w(up),a(left),s(down),d(right) in their respective directions using respond to keypress?

Code:
class Player {
private:
double x, y;
public:
Player(double a, double b){x=a;y=b;}
void respondtokeypress(char a)

[Code] ....

View 8 Replies View Related

C++ :: How To Move Sprite Depending On Rotation

Jan 13, 2015

how I want my sprite movement to work: if my sprite is faced upwards and i press W, it will move up. If my sprite is faced to the right and i press W, it will go right. etc. // It doesn't work like that right now and how to do it.The sprite's rotation works fine.

if(sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) {
playerSprite.rotate(-0.08 * dt);
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::E)) {
playerSprite.rotate(0.08 * dt);

[code]....

My question is how do I move the character depending on the rotation?

Also, you might see the "if(havePlayersCollided == false) {playerSprite.move(yadiyada)}" . yes i dont need the haveplayerscollided function because it doesnt work the way I want it to. I might make a thread for it in the future, but right now I need to get the rotation movement fixed before I move onto the collision detection between players.

View 7 Replies View Related

C++ :: Make Object Rotate Until It Looks At The Sprite?

Oct 10, 2013

Is there a way to make an object rotate until it looks at the sprite?

View 1 Replies View Related

C++ :: Allegro Sprite Is Not Showing Up In Right Spot

Jun 8, 2013

So I have a small game I'm making using OOP principles, I know it's a little bit of overkill but it's just for educational purposes. I have a sprite character that can be moved around with no problems, but I made a sword for him as a separate sprite that doesn't follow him. The sword sprite is supposed to cover his arm and his body as it swings, but it just stays in the upper left corner.

I messed around with the initialization of the sword in the main.cpp and I changed in sword.cpp and sword.h and it still is showing up in the same place. I even looked at the GetX() and GetY() statements I made and they seemed to work fine and when I debugged it, the variable values showed up correctly, but the sword doesn't move.

View 3 Replies View Related

C++ :: Draw The Same Sprite Multiple Times (SDL)?

Sep 7, 2014

I have a question about SDL and drawing sprites (SDL surfaces). My idea is that the user can create a wall of separate sprites by create one sprite each time in the current mouseX and mouseY position, when the user push down the e-key. The problem is that I have no idea how I could draw the same sprite multiple times without to delete the previous one.

View 3 Replies View Related

C/C++ :: Draw Sprite On The Window Of Third Party Application

May 8, 2014

How can I draw a sprite/graphic on the window of an third party application? E.g. I want to draw a graphic beneath each tab of Firefox for additional information. The position of the sprite needs to be relativ to the position of firefox, so if you move firefox, the sprite moves with it.

The solution needs to work on mac and pc. So I'll use a crossplatform framework like c++ boost or something.

Of course I can get the position and then just redraw it. But what's the best way to draw it?

Just found a tool which does what I need. Basically a HUD like this: [URL] .... The boxes with the numbers are what I need.

View 2 Replies View Related

C++ :: Game Design Practice For Accessing Container Of Game Objects

Dec 21, 2014

I'm working on my first video game. So far I have a few classes in the game starting with the Game class which includes a list of GameObjects (another class). There are several classes that inherit from GameObjects used to implement things like bullets, explosions, various enemy types, etc.

The game essentially iterates through the list of GameObjects to update/render them. I would like to provide access to the Game's list of GameObjects inside another class (like the Bullet class) so I can put new objects on the list. For example, when a bullet hits, I want to add an explosion to the Game's GameObject list it can be updated/rendered.

How this should be setup? I was considering adding a pointer to the Game or GameObject list to the GameObject class (and methods to access it), but I was wondering if there is a better way to set this up?

View 4 Replies View Related

C++ :: Program For Calculating Total Price Of Game Station And Game

Sep 13, 2014

I would like to make a program for calculating the total price of a game station, and a game. I made a program like this for just the price of a game in class, but I want to make one that does the game system as well.

View 7 Replies View Related

C++ :: How To Use Time For Time Based Movement

May 1, 2013

So I'm trying to learn how to use time for time based movement and what not. I did this only knowing the command time(&variable)

time_t timer;
int I, X;
void main() {
time(&timer);
X=timer;
while(I==5) {

[Code] ......

There's probably some other better way to do it... Obviously but for now I see it as putting current time in X.

start while
take in time constantly until I is 5
constantly asking is time>X(preset time 5 seconds ahead)
if it is
display message and add one to I

Why doesn't this display my message after 5 seconds?

View 1 Replies View Related

C++ :: Making A Game With GUI

Feb 27, 2015

Here's my game, what do I need to learn to make a basic GUI? (Easiest way possible for now).

--NOTE, the code was a bit too long for me to post. I can add it if it is necessary. Basically all I want are 4 buttons on the main screen, one that says "Arena," "Store," "Stats," and "Exit."

There will of course be sub menus to each option, but we will get to that later.

View 1 Replies View Related

C++ :: How To Set If Health 0 Game End

Mar 10, 2014

How i can set if health 0 game end?

#include <Windows.h>
#include <iostream>
#include <BluetoothAPIs.h>
#include <ws2bth.h>
bool Move(int xadj, int yadj);

void LoadMap();
void DrawScreen();

[Code] ....

View 3 Replies View Related

C# :: Three And Four Player Uno Game

Feb 26, 2015

I'm having some problems figuring out 3 and 4 player games in an Uno game I'm working on. I'm not sure what specifically the problem is, however. I've tried everything I can think of; I'm at a loss for what to do next. Two player games work perfectly, which makes the nonfunctional 3 and 4 player games seem odd to me. Here is the code:

public void MoveOpponents() {
if (nextPlayer == 0) {
if (Main.dir == Direction.Clockwise) nextPlayer = 1;
else nextPlayer = numPlayers - 1;

[Code] .....

The code for the human player is in Update(), but I won't show that because it's actually quite similar to the above code.

Right now what it's doing is jumping all over the place, making opponent 2 play before opponent 1, then I play, then opponent 1 plays. Then I play again. It's really messed up.

View 6 Replies View Related

C++ :: Tic Tac Toe Game With Multidimensional Array

Jan 13, 2015

Problems :

1) Is there any way so that i can use "X" and "O" char instead of 9 and 0 int.?? I also tried to use enum but was only able to print out -1 for 'X' and 0 for 'O'...

2) if player - 1 choose field 2 . and player - 2 chooses field 2 .. how can i show error and ask for another input ?

3) is there any short coding trick for int check_result(); ?

Code:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

[Code] ....

View 3 Replies View Related

C :: Can't Determine Tie Status Of The Game

Nov 12, 2014

I've made an effort for three days to write this code. But, my brain has stopped now. I wrote code to find the status of the game (win, loss or tie). However, I can't determine the tie status of the game. Tie status is the problem

View 5 Replies View Related

C :: Save And Load Game

Nov 26, 2013

I am trying to put my Save and Load function in my game, this is what i have:

Code:
/* Save game */
void GuardarJuego() {
FILE *fsave;
char turno;
fsave=fopen("SAVE.txt", "w");
fputs(*****, fsave);

[Code] .....

My game code is this: [C] GameCode - Pastebin.com

View 8 Replies View Related

C :: How To Continue Minesweeper Game

Oct 24, 2013

I am just now in my first programming class for learning C language and I am stuck on one of my homework assignments. I am not asking you to write the code for me or anything because I want to learn by doing it myself but all I am asking for is some pointers to where I am messing up. My program is already finished for what she asked for but I am trying to do an extra credit where she wants us to have the user decide how big the gameboard is and how many mines to hide in it. Really I know that I need to use srand() and rand() but I am not sure how to use them to randomly place mines and without placing mines on top of others.

Code:

//Program 3 "Minesweeper" by Casey Samuelson
//10-17-2013
//This program will imitate the game Minesweeper.
//Agorithum

[Code]....

View 4 Replies View Related

C :: Correct Answer Does Not End Game

Feb 21, 2013

Okay so I thought I had this assignment completed properly last week. Last night I found a bug while playing the game.why won't the game end when the player guesses the correct number? The game allows you to finish using the max number of guesses even though you already guessed the correct number.

Code:

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define MAXGUESSES 6
#define MAXGAMES 20
#define MAXNUMBER 100
}

[code]....

View 9 Replies View Related

C++ :: If And Else Statements With Game Scores

Oct 20, 2014

I am in comp. Sci 1 at my school and I have to write a program that deals with gamer scores and the trophy they get according to expert level. For example Tom is a beginner and gets a gold medal if >=10000 a silver >= 7500 bronze if >= 5000 and no trophy if he score <5000 ! I have do this scoring for Beginner, Immediate and Expert.

Should I set up the beginning like this:

case'b':
case 'B':
if (score >= 10000 )
trophy= gold
if (score >= 7500)
trophy = silver
if (score >= 5000)
trophy= bronze
else = none

Not really sure how to go about solving this problem

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved