Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / help for a newbie

Author
Message
jayjey
12
Years of Service
User Offline
Joined: 17th Feb 2012
Location:
Posted: 20th Feb 2012 00:18
Hi I'm sorry to bother you guys but i have a couple quick questions.

1. How can you make a shooting game were you can aim with the mouse? Is there a formula using dbRotateSprite?

2. If I wanted to make a game like the mario ones how would i work the camera? Would i make one massive screen and move it over when the player moves?

3. Is there any way to create a gravity effect in Dark GDK?
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 21st Feb 2012 13:12
If you are using DBP :

i suggest you do the examples that come with it, they should cover your first question. the second one, making a massive screen might be slow, i suggest you just store the locations as variables and place the actual objects there only when they are on the screen. also it is easier to move the camera with the player, instead of moving everything else. sure, gravity is but a variable, for example, you move every object -1 unit along the Y axis. this will look like gravity(simple gravity). for more advanced stuff use vectors.

if You are using GDK i cant be sure but the same ansvears should work
jayjey
12
Years of Service
User Offline
Joined: 17th Feb 2012
Location:
Posted: 21st Feb 2012 15:51
Thanks, and I am using Dark GDK, but for the last two can you give examples? My player has an x and y position, and when I move up I add 10 to the y, when I move down, I subtract 10 from the y, and so on. I can give you the code if you need it.
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 23rd Feb 2012 22:43
Hmm im not on the comp now so cant give you code but i can do pseudocode
So for the camera, i assume you are doin it 2D.
Have varables px and py be the players xy coordinates
Now we have a scenery image with ex,ey coordinates
This is ho i would do it.

Do
Px,py - move the player where you want
Ex,ey - move the environment if it should move

Sprite 400,300 - draw the player in center where you want him to be

Sprite getx(ex,px),gety(ey,py) -use a function getx() to determine where the env should be drawn based on the players "location"

Loop

Function getx(ex,px)
X=400+ex-px
Return X
Same for y

This should work sorry if its unclear im on iphone

Gravity:

Simple: every frame subtract a value from the ycoordinates of everything affected by gravity
Better:
Increase a variable velocity every frame (for all objects in motion) and subtract that from the y coordinate
This results in real accelleration,but it is harder to use
Vector: have a vector G that you add every frame to the motionvectors off all the objects.
Use the motionvector to update the locations.

Hopeit helps
jayjey
12
Years of Service
User Offline
Joined: 17th Feb 2012
Location:
Posted: 24th Feb 2012 22:44
Thanks, I was just hoping the gravity could be a delayed effect so thatthe player could maybe do a double jump or make a diagonal jump or fall. Do you know how i could maybe use some combo of dbSync() and dbSleep() ?
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 25th Feb 2012 22:47
Not sure what you are getting at, dbsleep, ifit does the same thing as Dark Basic command sleep as i assume would completely stop the program. I assume you are kinda new to coding, dont worry we have all been there. If you want the gravity "effect" to occur after a while, say two seconds you would have a variable time, that would be set to say 180 and then decreased by one every frame, and while that variable is less tha zero,the gravity effect part of the code sould be executed.

Hope this helps

Sync only updates the visual part of the screen, sleep pauses the program for a set ammount of time
jayjey
12
Years of Service
User Offline
Joined: 17th Feb 2012
Location:
Posted: 26th Feb 2012 00:40
Thanks so much i get it now.

I would just like to know one more thing. I'm trying to make a 2d game were you shoot stuff at the other player. I just can't figure out how to allow the player to aim with the mouse.

And also, can you erase part of an image if say, it got blown-up?
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 26th Feb 2012 15:19
the first question is easy, but instead of just ansvearing it im gona point u in the right direction.

For 90% of your future problems the ansvear is most likely going to be math. yes math!

for example in the gravity thing it was math. in this case the math is slightly harder but you dont need any specific code to do it.

so if you have done highschool math or something you should know sin,cos and tan? you know the x,y location of your gun and of the mouse. you can then get the angle of the line between the mouse and the gun using any of a number of ways. I recommend using tan. if there is a command named dbatanfull() in GDK then you can use that.
just use it like this : angle = dbatanfull(gunx-mousex,guny-mousey)

now that you have the angle you can easily move the bullet along that angle. again its math.

newx = x+sin(angle)*speed
newy = y+cos(angle)*speed

just easy trigonometrics.

for the second question. that is harder.
you can edit images but it is much slower
for example: you can draw a black box on to the image, then use a dbgetimage() command ( slow) to get the new image.

if i were you i would forget this unless it is really important for your game. try google it
jayjey
12
Years of Service
User Offline
Joined: 17th Feb 2012
Location:
Posted: 26th Feb 2012 23:48
thanks, I'm so sorry to keep this going, but one last thing i have trouble with moving sprites, i've tried pasting it at the new x and y, and deleting it and creating a new sprite at the new x and y. Every time, something looks wrong when the program runs.
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 28th Feb 2012 20:48
cant really help unless you tell me what looks wrong or how it looks
jayjey
12
Years of Service
User Offline
Joined: 17th Feb 2012
Location:
Posted: 29th Feb 2012 01:58
sorry i posted that before i check a throry i had, and it fixed it.

Anyways thanks for helping. I made two functions for gravity and shooting.
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 29th Feb 2012 15:54
well done! glad i could be of any help
jayjey
12
Years of Service
User Offline
Joined: 17th Feb 2012
Location:
Posted: 1st Mar 2012 01:03 Edited at: 1st Mar 2012 01:04
i'm trying to have a two player game where there's one main camera that follows both players and if the players get to far apart, than it splits into two cameras. This is a 2d game. Do you know anyway i could do it?
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 1st Mar 2012 17:09
hmm well, i do not know GDK so im not sure what you mean by "camera".
in 3D and 2.5D (2D but with 3D objects) you use cameras that you place somewhere and rotate, but in DBP 2D the "camera" is always the screen, and while you can have a "virtual virtual" camera to move around, you still have to draw stuff to the screen. Hope that made any sense.

I think it would be hard AND quite anoying unless you made it really well. If you have large sprites it might be quite extra hard, unless you are ready to use the slow getimage() command.

with that one you would make it like this:
Do one players stuff on half of the screen, then get the image of precisely half the screen, then do the same thing for Player 2
then paste the images in respective places. The problem with this is that it is S L O W unless you use some ingenious way of getting the image. one thing i would look at if i were you would be the ImageKit plugin here on the forums. you can find it from the program announcements or from the WIP pages.

hope it helped
jayjey
12
Years of Service
User Offline
Joined: 17th Feb 2012
Location:
Posted: 17th Mar 2012 18:15
In a 2d game sometimes you can't fit everything on one screen. So how do you move the screen? Is there in equivalent to cameras in 3d?
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 19th Mar 2012 20:20
oh missed this new comment

Yeah its a problem most people com to at one point or later.

i usually do it like this:

have for all object a set o cordinates like worldx# and worldy#.
these dont have to have anything to do with the screen. they are just relative.

then you have a function Getx() and Gety

theese look like this in general.

function Getx(worldx#,camerax#,zoom#,screenwidth)
x# = worldx#*zoom#-camerax#*zoom#+screenwidth/2.0
endfunction x#
function Gety(worldy#,cameray#,zoom#,screenheight)
y# = worldy#*zoom#-cameray#*zoom#+screenheight/2.0
endfunction y#


where worldx# and camerax# are coordinates in the realtive world set of coordinates.

these could be like 1 and 4.9

zoom# is a value that defines the scale between the world and the screen. it could be 55.1

with these values and a resolution of 600x800

the x# would be 185.11 in screen coordinates.

this way just by manipulating the camerax# and cameray# coordinates, you can "move" everything else, while whatever is at camerax#,cameray#, like your ship/soldier/house will always be in the center of the screen. also the zoom# value can smoothly be used to zoom in on stuff. just remember to scale the sprites accordingly.

hope this clarified it a litle
jayjey
12
Years of Service
User Offline
Joined: 17th Feb 2012
Location:
Posted: 19th Mar 2012 20:30
Do you know of any book or article that just explains the basics of Dark GDK for new users?
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 19th Mar 2012 20:55
no clue i dont use Dark GDK

but as for programming in general, i think the best way to learn is to try. Ive been using DBP for 2years now admittedly it is much easier than C++ but still, i havent had any books or such. just google+forums
you can make it just dont give up

Login to post a reply

Server time is: 2024-04-19 16:41:30
Your offset time is: 2024-04-19 16:41:30