Skip to main content
gamedev.net
🔒 Locked

Game Algorithm

Started by NickyP101 Mar 11, 2005 at 10:15 PM 3 replies 1.3k views
Original Post
NickyP101
NickyP101
Ok i had my game working perfectly before i changed my program to be more effiecient, now im just struggling! Ok this is wat my problem is; Before i made the changes, every frame my game would draw the entire map to the buffered image and then draw the bullets to that image. Then in the main paint method it would just crop that image. I did this because it made it very simple to paint the bullets where they are supposed to be; Algorithm paint bullet at x + cropX, y + cropY *paints that bullet to that exact position on the map, not the position u clicked on the screen. So if i shot a bullet at say a tree and then moved the bullet would still travell to that position on the map, not on the screen. Now that i have changed my program because ive got advice that croping is not as efficient as just drawing the needed tiles, i have no idea how to draw the bullet to the position clicked on the map, not the position clicked on the screen. Grrrr its hard to explain please see below: ||||||||||||||||||||||||||| ||................................|| ||..........P.....................|| ||..........B.....................|| ||................................|| ||................................|| ||..........T.....................|| ||................................|| ||................................|| ||||||||||||||||||||||||||| n this diagram the bullet (B) is travelling from the player (P) to the tree(T), now imagine this, the player moves one tile to the right; ||||||||||||||||||||||||||| ||................................|| ||................................|| ||............P.....................|| ||................................|| ||............B.....................|| ||................................|| ||........T.......................|| ||................................|| ||||||||||||||||||||||||||| The bullet is still going to the position u clicked on the screen, but not the position u clicked on the map. Please give me any hints or tips lol i had it all working so perfectly, but ive always had this thing, i'd rather do things the right way, than the wrong way. I have seen a major improvement in the frames per second though, hopefully i can work this out though, haha also now i hve no idea how to draw the oposition player. Do u think i should go back to my original way? Is cropping not that innieffiecient? Or should i use the way im currently trying to program? Thx in advance, and sorry about the long post lol :) Nick.
H_o_p_s
H_o_p_s
I'm not sure if I understand your problem... when the player moves does the whole map move with him??

If it does just have a simple translation between window X,Y into the game's interal drawing X,Y. I usually do this with CameraX and CameraY variables. When I click it takes the mouse coords and translates them with the CameraX/Y to get the game coords, then render the object that way.
BRING BACK THE BLACK (or at least something darker)
MaulingMonkey
MaulingMonkey
Quote:
|||||||||||||||||||||||||||
||................................||
||..........P.....................||
||..........B.....................||
||................................||
||................................||
||..........T.....................||
||................................||
||................................||
|||||||||||||||||||||||||||


Eww!! Comon, be smart, use [ code ] tags:

|||||||||||||||||||||||||||||................................||||..........P.....................||||..........B.....................||||................................||||................................||||..........T.....................||||................................||||................................|||||||||||||||||||||||||||||


Whoops, not much better. Might want to use the same ammount of characters per line, since [ code ] will use monospaced font:

||||||||||||||||||||||||||||||||||||||................................||||..........P.....................||||..........B.....................||||................................||||................................||||..........T.....................||||................................||||................................||||||||||||||||||||||||||||||||||||||


All better, see?
NickyP101
NickyP101
Ok thank u for the tag tip.

As the player moves the hole mape moves, yes. The playa ctually never leaves the center of the screen. Currently that is wat i am doing, changing the position clicked on the screen into the position on the map, it works fyn everything is great, but im srawing the entire map to the buffered image, not just the imediate tiles that are needed for the screen, im just cropping the entire map when the player moves. So if i have the game co-ords for the bullets, how can i draw them to the image which is not the entire map.

Haha see how simple my first way was, the buffered image would be the entire map, and i would simple paint the bullets at the position clicked on the screen plus the x-crop and y-crop.

But now im only draw 12 by 12 tiles every frame, im not sure how to paint the bullet to the position on the map, not the screen. Once again lol ill try explain graphically:

|||||||||||||||||||||||||||||||||||||.........C.....................||||..P......C.....................||||.........C.....................||||......B..C.....................||||.........C.....................||||.C.C.C.C.C.....................||||...............................||||...............................||||...............................||||...............................|||||||||||||||||||||||||||||||||||||Ok above is the entire map. THe croped area is shown. P is the player and B is the bullet. Now say the players moves a distance to the right;|||||||||||||||||||||||||||||||||||||.............C.......C.........||||.............C.......C.........||||.............C...P...C.........||||......B......C.......C.........||||.............C.C.C.C.C.........||||...............................||||...............................||||...............................||||...............................||||...............................|||||||||||||||||||||||||||||||||||||The bullet is still draw to that position on the map, not on the croped image. This works great, but ive been told its inefficient.Now i only draw to the buffered image the imediate tiles, which are the tiles shown in the croped image. So the buffered Image now looks lyk this;C.C.C.C.CC...B...CC.......CC...P...CC.......CC.C.C.C.C


Ok so the player has shot a bullet, now if the player moves to the right, how can i make that bullet travell to the positon on the map not the screen? Sorry this is very difficult to explain, maybe if uve done this, can u please post some code? Or something lol I hve completed the protype of the game, graphics suck, but program works, the networking works, everything works, but i would lyk to improve graphics performance.

Cheers Nick
Kylotan
Kylotan
It doesn't matter whether you draw the entire map or not; you should be able to tell exactly what is visible onscreen with a simple subtraction operation to find where the top left corner of the screen is in world space, and from there you can calculate a world coordinate from a screen coordinate (and vice versa).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.