• 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.

Archived

This topic is now archived and is closed to further replies.

ChocaPaluza123

What's wrong with my game?

15 posts in this topic

Hey, I don''t want to annoy you, but I am making a simple Pong game. So far, I have been able to draw the paddle, but when I try to check for keyboard input to make the paddle go up and down, the code doesn''t work. I''ll post my code here, so please tell me whats wrong. (I am just putting some parts of the code in here). // MACROS ///////////////////////////////////////////////// // these read the keyboard asynchronously #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) int x; int nBottom; int nTop; // GRAPHICS // Step 1: Create the two paddles. Make their height about 40 pixels high and about 5 pixels wide, // making their starting position 220 (top), 260 (bottom), 10(facing the edge of the screen), // and 15 (facing the center of the screen). Position them 10 pixels away from the edge // of the screen and center them // create the left paddle static RECT left_paddle = {10,nTop,15,nBottom}; // cool trick // create a white brush HBRUSH white_brush = CreateSolidBrush(RGB(255,255,255)); // draw it FillRect(hdc,&left_paddle,white_brush); // Delete the brush DeleteObject(white_brush); int Game_Main(void *parms) { // this is the workhorse of your game it will be called // continuously in real-time this is like main() in C // all the calls for you game go here! if (KEY_DOWN(''A'')) { nTop = nTop + 25; nBottom = nBottom + 25; } if (KEY_DOWN(''Z'')) { nTop = nTop - 25; nBottom = nBottom - 25; } // return success return(1); } // end Game_Main C++
0

Share this post


Link to post
Share on other sites
Maybe you want VK_A and VK_Z ?

I''ve never used this function, but perhaps

if (KEY_DOWN(VK_A))

is along the right track.

El Duderino


0

Share this post


Link to post
Share on other sites
The key routines look fine. The problem is your ''cool trick'' is not as cool as you think it is.

When you create the left paddle, you are giving it the values of nBottom and nTop (which, by the way, havent even been initalized at that point, which is a seperate problem). The rect takes these values and stores them in a different area of memory. Changing nBottom and nTop does NOT change the corresponding value within the left_paddle!

Instead of changing nBottom, nTop when the keys are pressed, change the values in left_paddle, eg. left_paddle.top = left_paddle.top + 25;

0

Share this post


Link to post
Share on other sites
Thanks you guys! I didn''t know that you could actually change the RECT structure by itself (rect.top += 25). I never would have thought of that.

C++
0

Share this post


Link to post
Share on other sites
Hi, its me again. I hope you don''t get to annoyed by me, because we don''t want that rodneyldixon vs. tryforfulluse thing again. I took your advice, but the code still doesn''t work. I looked it up in Windows Game Programming For Dummies, but Andre tells you the first time that the code is if(KEY_DOWN(VK_A)) and the second time if(KEY_DOWN(''A'')), I even looked in the help file, but it still doesn''t work. I think it might be because I am putting the key code in the WM_PAINT message, but the compiler freaks out (like it always does) if I put it somewheres else. I''m probably getting you kindof annoyed by now, but I''ll put in the paint code here.

case WM_PAINT:
{
// All the graphics stuff here about drawing the paddle

if (KEY_DOWN(''A''))
{
left_paddle.top = left_paddle.top + 25;
left_paddle.bottom = left_paddle.bottom + 25;
}

if (KEY_DOWN(''Z''))
{
left_paddle.top = left_paddle.top - 25;
left_paddle.bottom = left_paddle.bottom - 25;
}



C++
0

Share this post


Link to post
Share on other sites
The code inside your WM_PAINT area should ONLY paint the screen. I.e. Draw your bitmaps.

Inside your main loop do the checks for keys being pressed, and modifying the paddles location.

Also make sure you "dirty" the screen so that WM_PAINT message is actually sent, thereby updating the visuals.


If you are using Visual C++, I recommend you use the TRACE("") statements to make sure the code you think is executing is actually getting executing.

-Good Luck
0

Share this post


Link to post
Share on other sites
I guess Pong is harder than I thought! I took your advice, shaft, but when I try to put the if(KEYDOWN(... code in my game loop I can''t access the left_paddle struct from in there. Man, if I''m having this much trouble from Pong, I feel bad for the makers of Half Life.

C++
0

Share this post


Link to post
Share on other sites
ChocaPaluza123 you don''t need to worry about getting people annoyed because you''re asking questions about something you''re having a problem with.
If people will be willing to help they will, and believe me there are plenty of people who will.
Why can''t the rect be accessed from within the game loop?
0

Share this post


Link to post
Share on other sites
I have something that might work. You could try to create a function DrawRect(int x1, int y1, int x2, int y2, LPCOLORREF color). In the function you could create the paddle rect so maybe...


int DrawRect (int x1, int y1, int x2, int y2, LPCOLORREF color)
{
RECT paddle;
paddle.top = y1;
paddle.left = x1;
paddle.bottom = y2;
paddle.right = x2;

// drawing code here
}


then you could use it like this:

DrawRect (paddle_x, paddle_y, paddle_width, paddle_height, &paddle_color);

I''m not sure about the inclusiveness of RECT structs but that might work with a little fixup.

this way you could modify the positions of the paddle outside of the call.

hope it helps
0

Share this post


Link to post
Share on other sites
I don't want to sound mad or anything but I think that you still have alot to learn about C/C++ before going any further in your game programming. Modifying structs members are a fundamental part of C/C++ expecially for games. Also, knowing how to set your structs so that they can be accessed from other files in the project is also a really big part of C/C++ programming. I recommend that you write a couple of little programs to really get the feal for structs & maybe even get into classes which could get you off to a completely different approach to your project. Anyhow, these are my views and comments.



"And that's the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP's Invasive Production Activation Technology!

Edited by - Cyberdrek on July 1, 2001 5:26:59 PM
0

Share this post


Link to post
Share on other sites
You can''t call DeleteObject etc outside of your functions!! I would recommend you get a basic book on C++ and learn that before learning games-specific techniques, especially graphics. Start out with basic console in/out stuff and then move forwards.

> Andrew.
0

Share this post


Link to post
Share on other sites
quote:
Original post by shaft
If you are using Visual C++, I recommend you use the TRACE("") statements to make sure the code you think is executing is actually getting executing.



I think this only works in MFC? In Win32 or DX I think you have to use OutputDebugString().

> Andrew.

0

Share this post


Link to post
Share on other sites
adpeace is correct: TRACE("") only works within MFC.

ChocaPaluza123: why is your paddle RECT static? And where is it declared? If you declare it outside of any function (at the top, if you like, just after the header #include''s) then all functions within your source file will be able to access it because it has global scope . If you declare it as static at global scope, however, then you wont be able to modify it after intiilization. It seems you really want a DrawPaddle() function which maintains the static RECT. So your main loop/function will handle the keyboard input ( if(KEY_DOWN(...)) ) and then call DrawPaddle(), which will call InvalidateRect() to send a WM_PAINT message to Windows.

Keep posting. You''re trying first, which is why you''re getting quality replies (and don''t need to be so apologetic).
0

Share this post


Link to post
Share on other sites
quote:
Original post by Oluseyi
If you declare it outside of any function (at the top, if you like, just after the header #include''s) then all functions within your source file will be able to access it because it has global scope . If you declare it as static at global scope, however, then you wont be able to modify it after intiilization.



No, static at the file scope means it can''t be accessed outside that file. const at any scope means you can''t change it after initialization.

As for the original question, you''re still right. He wants to declare left_paddle outside of any functions, so any functions in that file can access it. Whether or not the static is there doesn''t really matter (since this is a first project, I doubt he''s got more than one .cpp file anyway.)

Anyway, good luck!
0

Share this post


Link to post
Share on other sites
You guys got me thinking. Thanks for all those messages, and I think I should read a book other than C++ For Dummies and Windows Game Programming for Dummies.

C++
0

Share this post


Link to post
Share on other sites
Since you guys are getting really involved with this (a lot more than I thought), I''ll show you how my code is going now. I''ll try to pick up a copy of C++: The Complete Reference or something like that.

int MakeRect (int nLeft, int nTop, int nRight, int nBottom)
{
static RECT paddle;
paddle.left = nLeft;
paddle.top = nTop;
paddle.right = nRight;
paddle.bottom = nBottom;
}

if (KEY_DOWN(''A''))
{
}

if (KEY_DOWN(''Z''))
{
}

// what is the message
switch(msg)
{
case WM_CREATE:
{
// do initialization stuff here
return(0);
} break;

case WM_PAINT:
{
// start painting
hdc = BeginPaint(hwnd,&ps);

// GRAPHICS
// Step 1: Create the two paddles. Make their height about 40 pixels high and about 5 pixels wide,
// making their starting position 220 (top), 260 (bottom), 10 (facing the edge of the screen),
// and 15 (facing the center of the screen). Position them 10 pixels away from the edge
// of the screen and center them

HBRUSH brush = CreateSolidBrush(RGB(0,0,0));

MakeRect(10,200,300,15);

// draw it
FillRect(hdc,&paddle,brush);

DeleteObject(&brush);

// end painting
EndPaint(hwnd,&ps);
return(0);
} break;

C++
0

Share this post


Link to post
Share on other sites