• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
vary

C++ Updation problem

7 posts in this topic

Problem is in the updation of LeftCollision, which is of bool type!

It goes to true, when the condition is met in CheckCollision(), but the 'true' value is not reflected in the GameObject::Update() section, where if(LeftCollision==false).... is always false!!

Why??

What could be the problem ??



[code]#include "GameObject.h"
2
3GameObject :: GameObject()
4{
5 x = 0;
6 y = 0;
7
8 velX = 0;
9 velY = 0;
10
11 dirX = 0;
12 dirY = 0;
13
14 boundX = 0;
15 boundY = 0;
16
17 LeftCollision = false; //initial value (it is a Public: bool type variable)
18
19
20 maxFrame = 0;
21 curFrame = 0;
22 frameCount = 0;
23 frameDelay = 0;
24 frameWidth = 0;
25 frameHeight = 0;
26 animationColumns = 0;
27 animationDirection = 0;
28
29 image = NULL;
30
31 alive = true;
32 collidable = true;
33}
34
35void GameObject :: Destroy()
36{
37
38}
39
40void GameObject :: Init(float x, float y, float velX, float velY, int dirX, int dirY, int boundX, int boundY)
41{
42 GameObject :: x = x;
43 GameObject :: y = y;
44
45 GameObject :: velX = velX;
46 GameObject :: velY = velY;
47
48 GameObject :: dirX = dirX;
49 GameObject :: dirY = dirY;
50
51 GameObject :: boundX = boundX;
52 GameObject :: boundY = boundY;
53}
54void GameObject :: Update()
55{
56 if(LeftCollision == false) //should stop when 'true', but never stops
57 {
58 x += velX * dirX;
59 y += velY * dirY;
60 }
61}
62void GameObject :: Render()
63{
64}
65
66bool GameObject :: CheckCollisions(GameObject *otherObject)
67{
68 float oX = otherObject->GetX();
69 float oY = otherObject->GetY();
70
71 int obX = otherObject->GetBoundX();
72 int obY = otherObject->GetBoundY();
73
74
75 if( x + boundX > oX - obX &&
76 x - boundX < oX + obX &&
77 y + boundY > oY - obY &&
78 y - boundY < oY + obY && otherObject->GetID() == TRIANGLE)
79 {
80 return true;
81 }
82 else if(((oX < x + boundX + 14)&&(oX+ 40 >x - boundX))&&!((oY < y + boundY)&&(oY+40 > y - boundY))
83 && otherObject->GetID() == SQUARE)
84 {
85 y = oY - boundX - 10;
86 //x = oX + 40;
87 return true;
88 }
89 else if((oX < x + boundX + 14) && (oX > x - boundX) && otherObject->GetID() == SQUARE)
90 {
91 LeftCollision = true; //LC updates to true, but does not reflect the value in the Update section above!!
92 return false;
93 }
94 else
95 {
96 return false;
97 LeftCollision = false;
98 }
99}
100void GameObject :: Collided(int objectID)
101{
102
103}
104bool GameObject :: Collidable()
105{
106 return alive && collidable;
107}[/code]
0

Share this post


Link to post
Share on other sites
Try using breakpoints and look if it execute line 58 to 59 anyway. An access violation somewhere else can make the program pointer go nuts in C++.
0

Share this post


Link to post
Share on other sites
[code]
else
{
return false;
LeftCollision = false;
}
[/code]
And you expect that to work...how?
1

Share this post


Link to post
Share on other sites
[quote name='Washu' timestamp='1330628548' post='4918296']
[code]
else
{
return false;
LeftCollision = false;
}
[/code]
And you expect that to work...how?

Else, statement is for, when ever the collision is not happening, things should go as they are supposed to be. If i'll remove that line, values wont revert back when left collision is not happening.



[/quote]
[quote name='Dawoodoz' timestamp='1330628065' post='4918289']
Try using breakpoints and look if it execute line 58 to 59 anyway. An access violation somewhere else can make the program pointer go nuts in C++.
[/quote]


58/9 are responsible for Scrolling of Triangles and Squares from Right to Left, and they work all the time!!
0

Share this post


Link to post
Share on other sites
[quote name='Washu' timestamp='1330628548' post='4918296']
[code]
else
{
return false;
LeftCollision = false;
}
[/code]
And you expect that to work...how?
[/quote]

You found it.

"return false" will exit the function and not execute anything after it. A good convention is to only return a result on the last line.
-1

Share this post


Link to post
Share on other sites
You do realize that ANYTHING AFTER a return statement within the current scope is not executed, right?
0

Share this post


Link to post
Share on other sites
If i remove, the return false, weird things come up, one of the things stop being rendered!! and only gets updated, ie becomes invisible on screen!! Though, square is rendered, but still the game does not pause when LeftCollision becomes true!!
0

Share this post


Link to post
Share on other sites
[quote name='Varypro' timestamp='1330630943' post='4918320']
If i remove, the return false, weird things come up, one of the things stop being rendered!! and only gets updated, ie becomes invisible on screen!! Though, square is rendered, but still the game does not pause when LeftCollision becomes true!!
[/quote]

Switch lines 96 and 97. If this is causing weirdness, it's because theres something wrong elsewhere in your code. It's not on lines 96-97;

I suggest you insert breakpoints and step through the debugger line by line to figure out where your getting unexpected behaviors.

Also, your check collisions code looks complicated and nasty. I'd hate to have to debug it or maintain it. I recommend rewriting it to be easier to read and simplifying the logic by breaking it down a bit. I bet that when you simplify it, you'll find the bug somewhere in here and it'll become obvious.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0