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

selve

Members
  • Content count

    18
  • Joined

  • Last visited

Community Reputation

145 Neutral

About selve

  • Rank
    Member

Personal Information

  1. Hi guys, I want to know how to rotate an image and make a collision with another object like this: First collision it's just an easiest collision without rotating any image. When the ball collides with the square, the XVEL of the ball changes to -XVEL. Now the question for you: how to make a rotated image and collision with the ball that changes the xVelocity and yVelocity depending on the rotated image position.  
  2. But if would do " || " it will for example work like this: The ball has reached Y point, but didn't reached X point, so the new X and the new Y are created. And I want to do it if the ball reaches X and Y. Am I right?
  3. [quote name='Álvaro' timestamp='1353525039' post='5002987'] [quote][code] balltarget.x = (rand() * 100) % SCREEN_WIDTH;[/code][/quote] That code basically picks a random column that is a multiple of the greatest common divisor of 100 and SCREEN_WIDTH. Are you sure that's what you want? [/quote] So if I want a normal random not multiplied should I do this: [source lang="cpp"]balltarget.x = ( (rand() * 100) % SCREEN_WIDTH) / 2;[/source]
  4. Here's the whole code: [source lang="cpp"]#include "SDL/SDL.h" #include "SDL/SDL_ttf.h" #include "SDL/SDL_mixer.h" #include "SDL/SDL_image.h" #include <windows.h> #include <stdbool.h> #include <time.h> #define SCREEN_WIDTH 1175 #define SCREEN_HEIGHT 585 using namespace std; SDL_Surface * screen; SDL_Surface * background; SDL_Surface * ball; SDL_Rect ballposition; SDL_Rect balltarget; SDL_Event event; int mouseX, mouseY; int oldx, oldy; int ballspeed = 3; bool gameover = false; bool targetreached = false; void moveBall() { if(ballposition.x > balltarget.x) { ballposition.x -= ballspeed; } if(ballposition.x < balltarget.x) { ballposition.x += ballspeed; } if(ballposition.y > balltarget.y) { ballposition.y -= ballspeed; } if(ballposition.y < balltarget.y) { ballposition.y += ballspeed; } if(abs(ballposition.x-balltarget.x)< ballspeed && abs(ballposition.y-balltarget.y)< ballspeed) { balltarget.x = (rand() * 100) % SCREEN_WIDTH; balltarget.y = (rand() * 100) % SCREEN_HEIGHT; } } int main(int argc, char * args[]) { SDL_Init(SDL_INIT_EVERYTHING); Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096); Mix_Chunk * click = Mix_LoadWAV("sounds/click.wav"); screen = SDL_SetVideoMode(1280, 720, 32, SDL_DOUBLEBUF | SDL_SWSURFACE); background = IMG_Load("images/texture.jpg"); ball = IMG_Load("images/ball.png"); ballposition.x = 500; ballposition.y = 400; ballposition.h = 80; ballposition.w = 80; srand(time(0)); balltarget.x = (rand() * 100) % SCREEN_WIDTH; balltarget.y = (rand() * 100) % SCREEN_HEIGHT; while(!gameover) { while(SDL_PollEvent(&amp;event)) { if(event.type == SDL_QUIT) { SDL_Quit(); return 0; } if(event.type == SDL_MOUSEMOTION) { mouseX = event.motion.x; mouseY = event.motion.y; } if(event.type == SDL_MOUSEBUTTONDOWN) if(event.button.button == SDL_BUTTON_LEFT &amp;&amp; ( mouseX >= ballposition.x && mouseX <= ballposition.x + ballposition.w ) &amp;&amp; ( mouseY >= ballposition.y && mouseY <= ballposition.y + ballposition.h ) ) { ballspeed++; Mix_PlayChannel(0, click, 0); } } moveBall(); SDL_BlitSurface(background, NULL, screen, NULL); SDL_BlitSurface(ball, NULL, screen, &amp;ballposition); SDL_Flip(screen); } } [/source]
  5. Thanks all, now it's working. Instead of using: [source lang="cpp"]if(ballposition.x == balltarget.x && ballposition.y == balltarget.y) { balltarget.x = (rand() * 100) % SCREEN_WIDTH; balltarget.y = (rand() * 100) % SCREEN_HEIGHT; }[/source] I used: [source lang="cpp"]if(abs(ballposition.x-balltarget.x)< ballspeed && abs(ballposition.y-balltarget.y)< ballspeed) { balltarget.x = (rand() * 100) % SCREEN_WIDTH; balltarget.y = (rand() * 100) % SCREEN_HEIGHT; }[/source]
  6. So how should it look like? I've did this in ball moving function: [source lang="cpp"]if(ballposition.x == ballX && ballposition.y == ballY) { targetreached = true; } [/source] And this in while(!gameover): [source lang="cpp"]if(targetreached) { srand(time(NULL)); do { ballX = randx; ballY = randy; }while(abs(oldx-ballX) > 300 && abs(oldy-ballY) > 300); oldx = ballX; oldy = ballY; targetreached = false; } [/source] But it is still not working ;/ The ball is just moving to one position and then doesn't move any more.
  7. Oh, sorry. Random numbers are defined here: [source lang="cpp"]#define randx rand()*100%1175 #define randy rand()*100%585[/source] The whole code: [source lang="cpp"]#include "SDL/SDL.h" #include "SDL/SDL_ttf.h" #include "SDL/SDL_mixer.h" #include "SDL/SDL_image.h" #include <windows.h> #include <stdbool.h> #include <time.h> #define randx rand()*100%1175 #define randy rand()*100%585 using namespace std; SDL_Surface * screen; SDL_Surface * background; SDL_Surface * ball; SDL_Rect ballposition; SDL_Event event; int mouseX, mouseY; int ballX = randx, ballY = randy; int oldx, oldy; int ballspeed = 1; bool gameover = false; void moveBall() { if(ballposition.x > ballX) { ballposition.x -= ballspeed; } if(ballposition.x < ballX) { ballposition.x += ballspeed; } if(ballposition.y > ballY) { ballposition.y -= ballspeed; } if(ballposition.y < ballY) { ballposition.y += ballspeed; } } int main(int argc, char * args[]) { SDL_Init(SDL_INIT_EVERYTHING); Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096); Mix_Chunk * click = Mix_LoadWAV("sounds/click.wav"); screen = SDL_SetVideoMode(1280, 720, 32, SDL_DOUBLEBUF | SDL_SWSURFACE); background = IMG_Load("images/texture.jpg"); ball = IMG_Load("images/ball.png"); ballposition.x = 500; ballposition.y = 400; ballposition.h = 80; ballposition.w = 80; while(!gameover) { srand(time(NULL)); do { ballX = randx; ballY = randy; }while(abs(oldx-ballX) > 300 && abs(oldy-ballY) > 300); oldx = ballX; oldy = ballY; while(SDL_PollEvent(event)) { if(event.type == SDL_QUIT) { SDL_Quit(); return 0; } if(event.type == SDL_MOUSEMOTION) { mouseX = event.motion.x; mouseY = event.motion.y; } if(event.button.button == SDL_BUTTON_LEFT && ( mouseX >= ballposition.x && mouseX <= ballposition.x + ballposition.w ) && ( mouseY >= ballposition.y && mouseY <= ballposition.y + ballposition.h ) ) { ballspeed++; Mix_PlayChannel(0, click, 0); } } moveBall(); SDL_BlitSurface(background, NULL, screen, NULL); SDL_BlitSurface(ball, NULL, screen, &&ballposition); SDL_Flip(screen); } } [/source] The point of the game is just to click on the moving ball which causes increase of its speed.
  8. Hi, I've created the small program where the ball is moving all the time on the screen to random coordinates made like that: [source lang="cpp"]srand(time(NULL)); do { ballX = randx; ballY = randy; }while(abs(oldx-ballX) > 300 && abs(oldy-ballY) > 300); oldx = ballX; oldy = ballY;[/source] It's included in while(!gameover) function. That moves the ball: [source lang="cpp"]void moveBall() { if(ballposition.x > ballX) { ballposition.x -= ballspeed; } if(ballposition.x < ballX) { ballposition.x += ballspeed; } if(ballposition.y > ballY) { ballposition.y -= ballspeed; } if(ballposition.y < ballY) { ballposition.y += ballspeed; } }[/source] The only problem is that the ball is moving to the right coordinates X and Y, then sometimes stays for a moment and then another move and so on. When I try to delete the "srand(time(NULL));" it causes the ball to move really fast in each direction but no lag. How can I fix this?
  9. So if I would like to make asking for name should I do states for all characters? How it will look?
  10. Hi guys. I want to do in my SDL Game asking for text. For example when I'll come close to the doors, there will be a code and u will have to type it by a keyboard. How can I do it?
  11. Thank You very much guys ;)
  12. Hello, I'm writing a RPG game, which will be actually the horror RPG. I've done the animation for player and all that based stuff, but now I wanted to do buttons on the left corner of the screen: [img]http://i47.tinypic.com/27yvm76.png[/img] For example if I press by mouse "QUESTS", this appears on the center of the screen: [img]http://i45.tinypic.com/2n9xoyb.png[/img] And then it's waiting for me to press for example ESCAPE to turn the picture off. If I click options, I would like to have for example such buttons on screen like: CONTROLS, BACKGROUND MUSIC, FULLSCREEN or BACK: [img]http://i48.tinypic.com/f2u6c.png[/img] And if I click CONTROLS, the last picture disappears and this one is on the screen: [img]http://i48.tinypic.com/2zdog9e.png[/img] Then it's waiting for me to press ESCAPE or another button on screen, for example BACK. [b]Here's the part of code:[/b] [source lang="cpp"]if(event.type == SDL_MOUSEMOTION ) { mouseX = event.motion.x; mouseY = event.motion.y; } if(event.type == SDL_MOUSEBUTTONDOWN ) { //Buttons if(event.button.button == SDL_BUTTON_LEFT && ( mouseX >= buttonquestslocation.x && mouseX <= buttonquestslocation.x + buttonquestslocation.w ) && ( mouseY >= buttonquestslocation.y && mouseY <= buttonquestslocation.y + buttonquestslocation.h ) ) { Mix_PlayChannel(-1, paper, 0); SDL_BlitSurface(levelonemap, NULL, screen, &paperlocation); SDL_Flip(screen); //Here's the place where I want the screen to wait until the player will press the button. I didn't know how to do that so i put a Delay. SDL_Delay(3000); } if(event.button.button == SDL_BUTTON_LEFT && ( mouseX >= buttonoptionslocation.x && mouseX <= buttonoptionslocation.x + buttonoptionslocation.w ) && ( mouseY >= buttonoptionslocation.y && mouseY <= buttonoptionslocation.y + buttonoptionslocation.h ) ) { SDL_BlitSurface(options, NULL, screen, &optionslocation); SDL_BlitSurface(buttoncontrols, NULL, screen, &buttoncontrolslocation); SDL_Flip(screen); Mix_PlayChannel(-1, paper, 0); //Now player must choose between: CONTROLS, BACKGROUND MUSIC, FULLSCREEN or BACK } if(event.button.button == SDL_BUTTON_LEFT && ( mouseX >= buttonexitlocation.x && mouseX <= buttonexitlocation.x + buttonexitlocation.w ) && ( mouseY >= buttonexitlocation.y && mouseY <= buttonexitlocation.y + buttonexitlocation.h ) ) { SDL_Quit(); return 0; } }[/source]
  13. Ok, thank you both guys ;)
  14. The whole map is 1280x720, so adding 1 to it will I think don't work. I just want that if the food spawns, and after I picked it up, it is checking, if the difference between new x, old x, new y, old y is more than for example 100. If not, take another random. Is that possible?