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.
I have a 10x10 array, initialized to all zeros. I create 2 random numbers for the purpose of guessing a position in the array. However, when I print the array, the 0,0 spot keeps shifting to match the 2nd random number generated. Is there something strange about the 0,0 spot?
Here is my code:
Code: seedrnd(); for (x=0;x<2;x++) { randArray[x]=rnd(10); } for (x=0;x<2;x=x+1)
[Code] .....
The 2nd to last print statement actually prints randColumn. The last print statement correctly prints 0.
I started making a shooter game where enemies appear randomly and you have to shoot them. Everything works fine except sometimes whenever a bullet hits an enemy an error comes up that says "Expression: vector subscript out of range". It doesn't happen every time there is a collision, which confuses me. Here is the collision of the bullets with enemies.
for (unsigned int i = 0; i < bullets.size(); i++) { if (bullets[i].type == 1) { for (unsigned int j = 0; j < enemies.size(); j++) { float distance = sqrt(pow(bullets[i].x - enemies[j].x, 2) + pow(bullets[i].y - enemies[j].y, 2)); if (distance < bullets[i].radius + enemies[j].radius) { bullets.erase(bullets.begin() + i); enemies.erase(enemies.begin() + j); } } }
How do i define a new color that is randomly generated in allegro.
I have this code here in the header file.
Code:
//FILE : circledefs.h //PURP : Define some constants for circle & background #ifndef CIRCLEDEFS_H #define CIRCLEDEFS_H #define NUMCIRCLES 3 //The frames per second for the timer #define FPS 60
[Code]...
And what i want to do here is learn how to create a random number gen. Now a few questions if you don't mind telling me is.
1 - can I create 3 random generators in this header file? Or do I have to do this in main.
2 - If I do have to do this in main can I still create this defined RANDOM as a color.
3 - I am sooooo new to this all i know is cin and cout code for C++, so will i need to know more about pointers to do this.
4 - for fun how hard would it be to make a game in allegro that uses music to define how the enemy moves and attacks. (yes that would be the final project.
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.
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() {
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.
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.
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.
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.
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; }
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.
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.
SLD_ttf lib and I have been following the Lazy Foo' tuts on it but the text is not appearing. I have found out that it is not loading the font as I have added in the code saying if it has failed.
Code:
font = TTF_OpenFont( "lazy.ttf", 28 ); if( font == NULL ) { return false; }
i have saved this font in the project (project name/project name/lazy.ttf).
I am trying to display images on top of my Background image gui, so like buttons an stuff but the problem is that there not showing ontop. I can only get one of them to show
// includes #include <windows.h> #include <stdio.h> #include "res.h"
I've run across this issue before, but for the like of me, I can't figure out what keeps causing it. The problem compiles and runs as expected; however in the salaried object (Employee #1 in main.cpp) the console displays the number of vacation days as -858993460 instead of the value entered.
The parent Employee class is abstract with calculatePay() and displayEmployee() being pure virtualls and with a Benefits, Salaried, and Hourly class derived from it.
The Salaried displayEmployee() and the portion of the Main.cpp that contains the salaried object follows. What causing this?
I just checking but confused with float. in that code same size int, and same type double are working but float showing nothing in printf..why?? i'm using GCC compiler int 32bit win7 os
As part of a project i want to display the speed of a small wheel on a 7 segment display. I am using a hall effect sensor to pick up the pulses of the rotation. I am not sure how to write a programe on C to calculate the RPM from this....
My question is why my on my code there is 10 zip code and i want to show the first digit, the problem is the first digit does not match the zip code for example the zip code is 45805 it should be '5' however, my code shows other number!
i have been making code of a chessgame and now sddenly computer freezed and now there's not code in .cpp file! Although my .cpp file shows size of 16kb but when i open it . there's nothing except bank file
I'm programming tic tac toe but the board is not showing numbers, and it is simply stating the winner without any input: (the win conditions are not complete, but it shouldn't matter).
#include <iostream> #include<string> using namespace std; //Write a two-player tic-tac-toe game; use enums when possible to represent the values of the board
I'm receiving an error that an array has not been initialized but I'm not quite sure why. Also, I realize a list may be better in this scenario but I would still like to know what I'm doing wrong.
Warning in the IDE
Warning3Field 'Routines.SvrMain.Servers' is never assigned to, and will always have its default value nullD:Google DriveCodingC# ProjectsNONameWindowsFormsApplication1WindowsFormsApplication1Routines.cs26638WindowsFormsApplication1
Error that pops on line Servers[Index].Address = Parser.ReturnAddress(); //returns an IPAddress
Object reference not set to an instance error
ServerDetails Class public class ServerDetails { public IPAddress Address; { get; set; } public int Port { get; set; } }
I wanna know why the program doesnt show "Invalid Letter Entered" when i enter any letter other than A S D or M
//Processing the data if (letter== 'A'||'S'||'M'||'D')// checking Add, subtract, multiply or divide { if (letter== 'A')//Adding the integers cout<<"Adding two integers = "<<first + second<<endl; else if (letter== 'S')//Subtracting the integers {
Same solution that I was having compiler errors on yesterday. We're working with inheritance and the program is supposed to be to create and display information for default Employee objects, Hourly Employee objects and Salaried Employee objects. Everything compiles as is, but I'm running into two issues that I can't figure out.
1) In both the hourly and salaried objects, the wage, hours, and management level attributes all displaying their default values. I'm almost positive that this has something to do with the str to int and str to double conversions that I'm using (currently have atoi and atof in the file, but I've also tried stringstream, but still had to same problem). Any thoughts as to what I'm missing?
2) the assignment calls for the Benefit benefit member in Employee.h to be protected. However this makes the member unaccessible when I try to use it in the EmployeeMain.cpp in order to set the input for the Benefit class members. I had to make the Benefit benefit member public again to get it to compile. How would I set the input for the Benefit class members while the Benefit benefit member is protected?
I'm writing a program that shows check fees for different amounts of checks. My other fees are showing up right but the .10 cents is not. It's showing up as .08 cents per check when I run the program.
Oh yeah the + 10 is for a $10 fee
Code: else if (checks < 20 || checks >= 0) { fee = .10 * checks + 10; cout<< "Bank service charge for the month is $ " << setprecision(4) << endl; }