I'm a noob

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

My bad. I thought you were spamming your video without even posting the link. I hadn't even read the thread before blurting out. :mrgreen: Carry on.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Post by eatcomics »

No problem, I was in a rage because I couldn't get something to work in my game, when I posted that. If you guys weren't supposed to see it I wouldn't have said anything about it. I think I'm about to move on because I just finished a theory to solve my problem. So that being said, it is possible that I will have a new vid tonight or tommorow.

Kline Out.
Image
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Post by eatcomics »

Ok, I'm really sorry but I can't get my shurikens to work in my game.

Would anyone have any idea how to put shurikens in my game?
Blitz obviously

Here's what they need to do:
1. Fly in a direction based on your characters position
2. Only two may be on the screen (One for each player)
3.It must be deleted once off screen

I think that's all untill I put collision and what not, but I can take care if someone will help me with these shurikens.
Image
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Post by Arce »

Listen...I really don't have too much time atm, so I apologize...Usually I'd help ya out and give ya a programming lesson to teach ya teh concepts behind the code...But in this case, I'm just going to give ya the code, and hope you can figure out how it works without me having to explain it. If you have questions, post them...I'll respond when I get more time. Also, if you have problems implementing this into your program, lemme know.

To begin, lets create a new object:

Code: Select all

Type shuriken
     field x,y
     field speed,direction
end type
Now lets create a function to create us a Shuriken...

Code: Select all

;function takes a few variables, create an object, and assigns the corresponding variables to the values in the object (member variables)
Function Make_Shuriken(x,y,speed,direction)
     shur.shuriken=new shurikens 
          shur\x=x
          shur\y=y
          shur\speed=speed
          shur\direction=direction
end function 
 
You'd probably want to call that function somewhere else...For example...When you hit the spacebar, make a shuriken. So, you might want to have this in your input function somewhere (or something similar):

Code: Select all

if keyhit(57) then Make_Shuriken(player\x,player_y,6,player\direction)
And of course you'd change the x, y, speed and direction to whatever youd' want. Try different values to see how they result until you begin to understand what it's doing. xD


Next, we'd need to make an 'update' function.

Code: Select all

function Update_shurikens()
     for shur.shuriken = each shuriken
            select shur\dir
                   case 1
                           shur\x=shur\x + shur\speed
                   case 2
                           shur\x=shur\x - shur\speed
                   case 3
                           shur\y=shury\y + shur\speed
                   case 4 
                           shur\y=shur\y - shur\speed
            end select
     next
end function 
This function loops through each shuriken and checks its direction. It's assuming you gave it a value from 1 to 4...Whereas 1 is right, 2 is left, 3 is down, 3 is up. Then it adds/subtracts to the shuriken's location depending.

Next, we're going to actually need to draw each shuriken.

Code: Select all

function Draw_shurikens()
      for shur.shuriken=each shuriken
             color 0,255,0
             rect  shur\x,shur\y,4,4,1
     next
end function
This function loops through each shuriken and draws a blue rectangle at each of their locations. If you'd loaded an image, then take out the 'color' and 'rect' lines, and replace them with

Code: Select all

drawimage image,shur\x,shur\y
Finally...You said you wanted them to delete after they go off the screen (which is VERY important, or else they'll keep going forever...Wasting memory...Then eventually their integer values for their location will overload, and they'll pop back up on the other side of the screen!!! (don't ask, lol)

So let's make a bounding function:

Code: Select all

function Bound_shurikens()
     for shur.shuriken= each shurken
           if shur\x >= 640+4   then delete shur : exit
           if shur\x <= 0    -4   then delete shur : exit
           if shur\y >= 480 +4 then delete shur : exit
           if shur\y <= 0-4       then delete shur : exit 
     next
end function
Okay...Note the bumers. 640,480, 0, 4. What's up with those? 640,480 is what I'm assuming your screen resolution is set to (when you typed 'Graphics 640,480') and if this is wrong, change the numbers. The plus and minus 4 are for the shuriken width/height. If you use an image for the shuriken, then change the 4 to the respective correct values.


Finally....I'd make a last function for the purpose of convience:

Code: Select all

function Shurikens()
      Update_shurikens()
      Bound_shurikens()
      Draw_shurikens()
end function 


This one isn't required...It's just there to make your code neat. It simply calls all the other functions. Now, for bullets to work, just add this one function to your main loop somewhere between your 'cls' and 'flip' statements...And be sure to actually call Make_Shuriken somewhere. ;P

Good luck, hope it helped.


:cheers:
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Post by eatcomics »

OMG, thank you. I was gettin close and this probably will finish it for me.
Don't worry I understand it.

:worship: :worship: :worship:
Last edited by eatcomics on Wed Apr 30, 2008 4:53 pm, edited 1 time in total.
Image
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

eatcomics wrote:OMG, thank you. I was gettin close and this probably will finish it for me.
Don't worry I understand it.
You have a tendency to double-post, only click submit once, then be patient? (I fixed it again)
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Post by eatcomics »

I'm sorry, i was gonna fix it but it was to late.
I try to be patient but usually it says invalid session, or you can not post so soon after your last, and I didn't even submit anything. Anyways, I'll try to be patient.... :mrgreen:
Image
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Post by eatcomics »

Ok, that code works fine, it's just when it is deleted I need the program to keep running and I can't get it to do that. How would I fix this?
Image
Post Reply