Space Tower
started by: Guardman 66Guardman 66
on: 1247876293|%e %b %Y, %H:%M %Z|agohover
number of posts: 39
rss icon RSS: new posts
summary:
Code Problem
Space Tower
Guardman 66Guardman 66 1247876293|%e %b %Y, %H:%M %Z|agohover

Its a Tower Defense style game. To defend the tower the player is given a laser cannon to destroy the enemy troops. The troops are equiped with "light saber" like swords and laser guns. The Laser cannon is going to have a 1-3sec cooldown and be on left mouse button. The tower will be able to recieve
20-40 sword hits, and 10-30 gun hits. In all it will only be able to recieve a max of 50hits. The laser guns will have a 5sec cooldown and the swords have a 2sec cooldown.

Any help to get started with this like with sprites and help with bugs and defective code will be happily accepted and appreciated.

I will be able to make the gun like a line at my current programming skill, but i don't know how to get it to shoot a progectile,
i have a thread in the General Programming forum.

Thank You!

unfold Space Tower by Guardman 66Guardman 66, 1247876293|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1247879411|%e %b %Y, %H:%M %Z|agohover
Setfps 60

GunX#=100
GunY#=GetScreenheight()-100

Do
    cls rgb(0,20,30)

    mx=mousex()
    my=mousey()
    angle#=getangle2D(gunx#,guny#,mx,my)

    Currentangle#=curveangle(angle#,currentangle#,20)

    x2#=cosnewvalue(gunx#,currentangle#,100)
    y2#=sinnewvalue(guny#,currentangle#,100)

    line gunx#,guny#,x2#,y2#

    Sync
loop

Thats the gun i have right now, just a basic line, if anyone could share with me their bullet shooting code i would be very thankful. In the mean time i'm going to try and develope my own, and hope it works out. Anyway, how do you make Fx sounds and i have Gale Graphics but i don't understand how to use it.

I made 2 pics and they look nothing like the quality of the Sprites Battles pics everyone else makes.

unfold Re: Space Tower by Guardman 66Guardman 66, 1247879411|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1247881461|%e %b %Y, %H:%M %Z|agohover

Ok, i would work on trying to make the gun shoot if i could just figure out everything that made the gun work in PlayBasic, the Asteroids game. I had tried copying everything i could find that looked like it was part of the gun and it didn't work. Anyway, I could use some help from anyone who has made a game that shot bullets/lasers. Also, do we have any tutorials on how to make a sprite? (to look like the ones in the Sprite Battles thing and then actually get them to where i can program them into the game.)

In the meantime i'm going to learn more of the playbasic language. I currently only really know how to move and make it say stuff…i.e. Print "Hello World"

unfold Re: Space Tower by Guardman 66Guardman 66, 1247881461|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
u9u9 1247888698|%e %b %Y, %H:%M %Z|agohover

To shoot projectiles, first you have to define a projectile. Do that with a UDT. (I am in linux so i cannot show any playbasic code). Your projectile type should have an x# and y# position, an xVel# and yVel# (velocity, speed) and a lifetime#, i.e. when the projectile will die if it does not hit anything.

Then, define an array to hold all the projectiles that are on screen, and a variable which will hold the next index free. This variable starts at 0. I usually call it numProjectiles.

When you press the left mouse button, you create a projectile at the index location of numProjectiles (which starts at 0 for the first projectile), and increment numProjectiles.

In your main loop, you loop through all your projectiles and do the following:

  • Move position according to velocity
  • Count down life variable
    • If it reaches 0, delete this projectile. This is done by swapping the values of this projectile with the values of the projectile at index numProjectiles-1 (the last projectile), and then setting numProjectiles = numProjectiles - 1.
  • Check if projectile is colliding with any other game object
    • If so, do some damage on that game object, and delete this projectile in the same way as above
  • If the projectile was not deleted then finally we can draw it. The drawing could also be in a separate loop so to not mix up rendering and game logic, but that is up to you

I think that should be it. Creating a projectile would be something like the code you have above:

GunX#=100
GunY#=GetScreenheight()-100
dim projectiles( 400 ) as ProjectileType ; You have to define ProjectileType UDT
numProjectiles = 0

Do
    cls rgb(0,20,30)
    mx=mousex()
    my=mousey()
    angle#=getangle2D(gunx#,guny#,mx,my)
    Currentangle#=curveangle(angle#,currentangle#,20)

    if leftmousebutton() ; or whatever the function is alled
        projectiles( numProjectiles ).x# = GunX#
        projectiles( numProjectiles ).y# = GunY#
        projectiles( numProjectiles ).lifetime# = some range here
        projectiles( numProjectiles ).xVel# = cosnewvalue( 0, currentangle#, PROJECTILE_SPEED )
        projectiles( numProjectiles ).yVel# = sinnewvalue( 0, currentangle#, PROJECTILE_SPEED )
        numProjectiles = numProjectiles + 1
        mouseflush()
    endif

    for i = 0 to numProjectiles - 1
        ; move projectiles
    next

    for i = 0 to numProjectiles - 1
        circle projectiles(i).x#, projectiles(i).y#, 2, false
    next

    x2#=cosnewvalue(gunx#,currentangle#,20)
    y2#=sinnewvalue(guny#,currentangle#,20)
    line gunx#, guny#, x2#, y2#
    circle gunx#,guny#,15, true
    Sync
loop

hope it helps… Sorry i haven't read through your game idea yet. I read RPG in the title and, well, i am not much of an rpg fan ;) But i will read through it, i promise! Most people are rpg fans though, so i am surprised noone replied yet.

EDIT: Fixed link to types.

last edited on 1247902920|%e %b %Y, %H:%M %Z|agohover by u9 + show more
unfold Re: Space Tower by u9u9, 1247888698|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1247924002|%e %b %Y, %H:%M %Z|agohover

ok thank you, i'll try it right now, if it works i'll let you know.

What exactly is a UDT though, Un-defined type?

last edited on 1247924328|%e %b %Y, %H:%M %Z|agohover by Guardman 66 + show more
unfold Re: Space Tower by Guardman 66Guardman 66, 1247924002|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
u9u9 1247933872|%e %b %Y, %H:%M %Z|agohover

User Defined Type

unfold Re: Space Tower by u9u9, 1247933872|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1247924993|%e %b %Y, %H:%M %Z|agohover

I got an error when i tried

GunX#=100
GunY#=GetScreenheight()-100
dim projectiles( 400 ) as ProjectileType ; You have to define ProjectileType UDT
numProjectiles = 0

Type ProjectileType
    xpos#
    ypos#
    xVel#
    yVel#
    xSpd#
    ySpd#
    lifetime#
EndType

ProjectileType = bullet

Do
    cls rgb(0,20,30)
    mx=mousex()
    my=mousey()
    angle#=getangle2D(gunx#,guny#,mx,my)
    Currentangle#=curveangle(angle#,currentangle#,20)

    if leftmousebutton() ; or whatever the function is alled
        projectiles( numProjectiles ).x# = GunX#
        projectiles( numProjectiles ).y# = GunY#
        projectiles( numProjectiles ).lifetime# = some range here
        projectiles( numProjectiles ).xVel# = cosnewvalue( 0, currentangle#, PROJECTILE_SPEED )
        projectiles( numProjectiles ).yVel# = sinnewvalue( 0, currentangle#, PROJECTILE_SPEED )
        numProjectiles = numProjectiles + 1
        mouseflush()
    endif

    for i = 0 to numProjectiles - 1
        ; move projectiles
    next

    for i = 0 to numProjectiles - 1
        circle projectiles(i).x#, projectiles(i).y#, 2, false
    next

    x2#=cosnewvalue(gunx#,currentangle#,20)
    y2#=sinnewvalue(guny#,currentangle#,20)
    line gunx#, guny#, x2#, y2#
    circle gunx#,guny#,15, true
    Sync
loop

I tried to make a type, but it says i didn't define it, i have no idea how to define apparently, but i gave it a shot, i was hoping it would work. Was i even close to defineing it?

Perhaps you could explain what you mean by define, or how i would go about this process.

Thank you for the help so far, and i thought you had PlayBasic? I might have just thought u said you did, idk. :)

unfold Re: Space Tower by Guardman 66Guardman 66, 1247924993|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
u9u9 1247933740|%e %b %Y, %H:%M %Z|agohover

You nailed it i think. But you have to define it before you use it :) So move your type definition up to the top of the file. Ah, one more thing, speed and velocity is the same thing, so you don't need the xspd# and yspd#.

unfold Re: Space Tower by u9u9, 1247933740|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1247936242|%e %b %Y, %H:%M %Z|agohover

o ok, thank you. So i only had it in the wrong spot…Arg!

Thank you for the help, i will go test it out.

unfold Re: Space Tower by Guardman 66Guardman 66, 1247936242|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1247936584|%e %b %Y, %H:%M %Z|agohover

It says something isn't specified…

Type ProjectileType
    xpos#
    ypos#
    xVel#
    yVel#
    lifetime#
EndType

GunX#=100
GunY#=GetScreenheight()-100
dim projectiles( 400 ) as ProjectileType
numProjectiles = 0

ProjectileType = bullet

Do
    cls rgb(0,20,30)
    mx=mousex()
    my=mousey()
    angle#=getangle2D(gunx#,guny#,mx,my)
    Currentangle#=curveangle(angle#,currentangle#,20)

    if leftmousebutton() ; or whatever the function is alled
        projectiles( numProjectiles ).x# = GunX#
        projectiles( numProjectiles ).y# = GunY#
        projectiles( numProjectiles ).lifetime# = some range here
        projectiles( numProjectiles ).xVel# = cosnewvalue( 0, currentangle#, PROJECTILE_SPEED )
        projectiles( numProjectiles ).yVel# = sinnewvalue( 0, currentangle#, PROJECTILE_SPEED )
        numProjectiles = numProjectiles + 1
        mouseflush()
    endif

    for i = 0 to numProjectiles - 1
        ; move projectiles
    next

    for i = 0 to numProjectiles - 1
        circle projectiles(i).x#, projectiles(i).y#, 2, false
    next

    x2#=cosnewvalue(gunx#,currentangle#,20)
    y2#=sinnewvalue(guny#,currentangle#,20)
    line gunx#, guny#, x2#, y2#
    circle gunx#,guny#,15, true
    Sync
loop

I have no idea what to do now. Something about not being verified or specified, idk.
If you could try and figure out what it wants me to do, i would be very happy.

You don't have to write any code, i just need to know whats wrong and how to fix its problem.

Thank you (your probably getting tired of helping a noob).

unfold Re: Space Tower by Guardman 66Guardman 66, 1247936584|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
hartnellhartnell 1247938327|%e %b %Y, %H:%M %Z|agohover

The problem is this line :

ProjectileType = bullet

ProjectileType is your type. Did you mean :

Dim bullet As ProjectileType

— hartnell

Thank you (your probably getting tired of helping a noob).

Our name is Game Design NOVICE. :)

unfold Re: Space Tower by hartnellhartnell, 1247938327|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
hartnellhartnell 1247938651|%e %b %Y, %H:%M %Z|agohover

I made several corrections. Changes noted in comments.

Type ProjectileType
    x# ; was xpos, rest of code uses .x#
    y# ; was ypos, rest of code uses .y#
    xVel#
    yVel#
    lifetime#
EndType

GunX#=100
GunY#=GetScreenheight()-100
dim projectiles( 400 ) as ProjectileType
numProjectiles = 0

; ProjectileType = bullet
; Looks like you forgot to delete this

Do
    cls rgb(0,20,30)
    mx=mousex()
    my=mousey()
    angle#=getangle2D(gunx#,guny#,mx,my)
    Currentangle#=curveangle(angle#,currentangle#,20)

    if leftmousebutton() ; or whatever the function is alled
        projectiles( numProjectiles ).x# = GunX#
        projectiles( numProjectiles ).y# = GunY#
        projectiles( numProjectiles ).lifetime# = RndRange(100,500)
        ; added RndRange() above
        projectiles( numProjectiles ).xVel# = cosnewvalue( 0, currentangle#, PROJECTILE_SPEED )
        projectiles( numProjectiles ).yVel# = sinnewvalue( 0, currentangle#, PROJECTILE_SPEED )
        numProjectiles = numProjectiles + 1
        FlushMouse ; was mouseflush()
    endif

;    for i = 0 to numProjectiles - 1
        ; move projectiles
;    next
; Set the number of projectiles to higher than zero or leave uncommented

    for i = 0 to numProjectiles - 1
        circle projectiles(i).x#, projectiles(i).y#, 2, false
    next

    x2#=cosnewvalue(gunx#,currentangle#,20)
    y2#=sinnewvalue(guny#,currentangle#,20)
    line gunx#, guny#, x2#, y2#
    circle gunx#,guny#,15, true
    Sync
loop

— hartnell

unfold Re: Space Tower by hartnellhartnell, 1247938651|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1247953418|%e %b %Y, %H:%M %Z|agohover

thx hartnell, i go try it out.

unfold Re: Space Tower by Guardman 66Guardman 66, 1247953418|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1247953809|%e %b %Y, %H:%M %Z|agohover

Ok, with the code provided, i was able to get the line to follow my mouse. (The circle stayed stationary which is good, lol)

A projectile didn't fire from the gun, do i have to create something to shoot or what?

unfold Re: Space Tower by Guardman 66Guardman 66, 1247953809|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
u9u9 1247999554|%e %b %Y, %H:%M %Z|agohover

Yes the loop

;    for i = 0 to numProjectiles - 1
        ; move projectiles
;    next

i created for you so you would know where to put your movement code. Read my post which tells you which steps you need to take for everything to work. You need to move the projectiles, then check if it collided, then check if it is dead and should be deleted. Let me know if you get stuck trying to do this.

When you get a problem with your code, first look at what the compiler tells you is wrong, and then look at the code and see if you cannot figure out what it is saying. For example when you set

ProjectileType = bullet

What were you thinking this does? There is no variable (or function) called bullet in playbasic, and you did not define bullet to be anything, so it has no meaning.

When you get stuck, and cannot figure out what is wrong on the line the compiler tells you, post what the compiler tells you and which line is in question. It will make it easier to help.

unfold Re: Space Tower by u9u9, 1247999554|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248004544|%e %b %Y, %H:%M %Z|agohover

ok thx, i will keep that in mind

unfold Re: Space Tower by Guardman 66Guardman 66, 1248004544|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
mr glassesmr glasses 1248011449|%e %b %Y, %H:%M %Z|agohover

I feel so useless, I know absolutely no playbasic…anyways, I'll try to help wtih concepts when I can. And if you need any help with sprites or sound I'll be more than happy to give tips :)

last edited on 1248011513|%e %b %Y, %H:%M %Z|agohover by mr glasses + show more
unfold Re: Space Tower by mr glassesmr glasses, 1248011449|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248014854|%e %b %Y, %H:%M %Z|agohover

ok, thx, i am happy people are willing to help, which is what i expected of this website, but its more helpful than i thought it was going to be.

I rate GDN 10/10

unfold Re: Space Tower by Guardman 66Guardman 66, 1248014854|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248042401|%e %b %Y, %H:%M %Z|agohover

PlayBasic says The Array 'mouseflush()' is undefined. I can't do anything because i have no idea what mouseflush is supposed to do. I assume its supposed to refresh the mouse buttons after i left click, but its not a term.

Type ProjectileType
    xpos#
    ypos#
    xVel#
    yVel#
    lifetime#
EndType

GunX#=100
GunY#=GetScreenheight()-100
dim projectiles( 400 ) as ProjectileType
numProjectiles = 0

Do
    cls rgb(0,20,30)
    mx=mousex()
    my=mousey()
    angle#=getangle2D(gunx#,guny#,mx,my)
    Currentangle#=curveangle(angle#,currentangle#,20)

    if leftmousebutton() ; or whatever the function is alled
        projectiles( numProjectiles ).xpos = GunX#
        projectiles( numProjectiles ).ypos = GunY#
        projectiles( numProjectiles ).lifetime# = 50
        projectiles( numProjectiles ).xVel# = cosnewvalue( 0, currentangle#, PROJECTILE_SPEED )
        projectiles( numProjectiles ).yVel# = sinnewvalue( 0, currentangle#, PROJECTILE_SPEED )
        numProjectiles = numProjectiles + 1
        mouseflush()
    endif

    for i = 0 to numProjectiles - 1
        ; move projectiles
    next

    for i = 0 to numProjectiles - 1
        circle projectiles(i).x#, projectiles(i).y#, 2, false
    next

    x2#=cosnewvalue(gunx#,currentangle#,20)
    y2#=sinnewvalue(guny#,currentangle#,20)
    line gunx#, guny#, x2#, y2#
    circle gunx#,guny#,15, true
    Sync
loop

I hope someone knows what i need to do to fix this, i sure don't. Thank you for your help.

unfold Re: Space Tower by Guardman 66Guardman 66, 1248042401|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248042624|%e %b %Y, %H:%M %Z|agohover

also, if

mouseflush() is there something is wrong with the next, it is a possible loop close. Hope this information helps.

unfold Re: Space Tower by Guardman 66Guardman 66, 1248042624|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
hartnellhartnell 1248043292|%e %b %Y, %H:%M %Z|agohover

I corrected this in the first major correction of your code :

I don't know where you get mouseflush() from, however

FlushMouse

flushes all mouse events. This way, if you press the mouse button, then use MouseFlush, you will have to lift up on the mouse button and press down for it to be registered again.

Without using FlushMouse, pressing the mousekey will be registered every loopin ( game loop execution ).

— hartnell

unfold Re: Space Tower by hartnellhartnell, 1248043292|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
hartnellhartnell 1248043695|%e %b %Y, %H:%M %Z|agohover

Try this : (press the left mouse button )

Without FlushMouse :

SetFPS 60
LoadFont "Arial", 1, 20, 0

Do
    Cls 0
        If LeftMouseButton() Then leftPressed = leftPressed + 1
        Print leftPressed    
    Sync
Loop

With FlushMouse

SetFPS 60
LoadFont "Arial", 1, 20, 0

Do
    Cls 0
        If LeftMouseButton() Then leftPressed = leftPressed + 1
        FlushMouse
        Print leftPressed    
    Sync
Loop

— hartnell

unfold Re: Space Tower by hartnellhartnell, 1248043695|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248048651|%e %b %Y, %H:%M %Z|agohover

i see, the second one works the best for what i'm trying to do, thx. Now i'm going to add a bullet type to it, and try and get the bullet to work. Thank you.

unfold Re: Space Tower by Guardman 66Guardman 66, 1248048651|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248050293|%e %b %Y, %H:%M %Z|agohover

I think this should work, but i got at least one problem with the code.

Setfps 60
Loadfont "Arial", 1, 20, 0

Type tBullet
    x# ;x-axis position
    y# ;y-axis position
    xVel# ;speed going on the x-axis
    yVel# ;speed going on the y-axis
    life# ;how far the bullet will travel until it dies.
EndType

Dim bullet(400) as tBullet

Gunx#=100
Guny#=GetScreenheight()-100

Do
    FlushKeys

    For i = 1 to GetArrayElements bullet(400)                                                  ;this is the error
        If bullet(400).x# < 0 Then FreeCell bullet(400)
        If bullet(400).y# > GetScreenWidth() Then FreeCell bullet(400)
    Next

    For i = 1 to GetArrayElements(bullet(400)
        bullet(400).x# = bullet(400).x# +bullet(400).xVel#
        bullet(400).y# = bullet(400).y# +bullet(400).yVel#
    Next

    Cls 0
        For i = 1 to GetArrayElements( projectile().TObj, 1)
            Circle bullet(400).x#, bullet(400).y#, 5, False
        Next

        cls rgb(0,20,30)
        mx=mousex()
        my=mousey()
        angle#=getangle2D(gunx#,guny#,mx,my)
        Currentangle#=curveangle(angle#,currentangle#,20)            

    If LeftMouseButton()
        bullet(400).x# = GunX#
        bullet(400).y# = GunY#
        bullet(400).life# = RndRange(100,500)
        bullet(400).xVel# = cosnewvalue( 0, currentangle#, BULLET_Speed )
        bullet(400).yVel# = sinnewvalue( 0, currentangle#, BULLET_SPEED )
        numBullet = numBullet + 1
    FlushMouse
endif

    for 1 = 0 to numBullet - 1
        circle bullet(i).x#, bullet(i).y#, 2, false
    next

    x2#=cosnewvalue(GunX#,currentangle#,20)
    y2#=sinnewvalue(GunY#,currentangle#,20)
    line GunX#, GunY#, x2#, y2#
    circle GunX#, GunY#, 15, true
    Sync
loop

The error is marked. The error message is below:

Error in <Main.pba>,25: The Command 'GetArrayElements' is expecting an open bracket for it's input parameters.

This is extremely confusing, i removed the parenthases and it didn't do anything, the same error came up, so I
don't know what to do. Please Help, thank you.

last edited on 1248052269|%e %b %Y, %H:%M %Z|agohover by Guardman 66 + show more
unfold Re: Space Tower by Guardman 66Guardman 66, 1248050293|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248052370|%e %b %Y, %H:%M %Z|agohover

Did i get the code set up right for the most part, or am i completely off? I typed it up and changed certain parts of the example code you posted, like projectiles to bullet.

Thank you

unfold Re: Space Tower by Guardman 66Guardman 66, 1248052370|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
NicAdiNicAdi 1248061928|%e %b %Y, %H:%M %Z|agohover

Guardman 66Guardman 66: Error in <Main.pba>,25: The Command 'GetArrayElements' is expecting an open bracket for it's input parameters.

Yup, it is an error, indeed. Have you checked the syntax for GetArrayElements? It's all in there, you know…

unfold Re: Space Tower by NicAdiNicAdi, 1248061928|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
u9u9 1248078006|%e %b %Y, %H:%M %Z|agohover

Hey Guardman. It was me who wrote mouseflush. I was typing on linux and did not remember if it was mosueflush or flushmouse.

I think you should look at the code inside your if where you check for the left mouse button. It seems you set the values for bullet nunber 400. Every time you press left mouse button bullet 400 is set to the position of the gun and fired. This is probably a problem as you want a new bullet to fire every time :)

unfold Re: Space Tower by u9u9, 1248078006|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248089419|%e %b %Y, %H:%M %Z|agohover

so, i just need bullet there, no 400.

i'll try it

unfold Re: Space Tower by Guardman 66Guardman 66, 1248089419|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248095626|%e %b %Y, %H:%M %Z|agohover

ok, theres the code, i have no idea what to do, it not working, i g et the same error with and with out (400). If anyone has an idea as to what i did wrong, please tell me and put a note as to what i need to do next to the code. Thank you.

; PROJECT : Space Tower
; AUTHOR  : Guardman 66'company
; CREATED : 7/20/2009
; EDITED  : 7/20/2009
; ---------------------------------------------------------------------

Setfps 60
Loadfont "Arial", 1, 20, 0

Type tBullet
    x# ;x-axis position
    y# ;y-axis position
    xVel# ;speed going on the x-axis
    yVel# ;speed going on the y-axis
    life# ;how far the bullet will travel until it dies.
EndType

Dim bullet(400) as tBullet

Gunx#=100
Guny#=GetScreenheight()-100

Do
    FlushKeys

    For i = 1 to GetArrayElements bullet
        If bullet(400).x# < 0 Then FreeCell bullet(400)
        If bullet(400).y# > GetScreenWidth() Then FreeCell bullet(400)
    Next

    For i = 1 to GetArrayElements bullet(400)
        bullet(400).x# = bullet(400).x# +bullet(400).xVel#
        bullet(400).y# = bullet(400).y# +bullet(400).yVel#
    Next

    Cls 0
        For i = 1 to GetArrayElements( projectile().TObj, 1)
            Circle bullet(400).x#, bullet(400).y#, 5, False
        Next

        cls rgb(0,20,30)
        mx=mousex()
        my=mousey()
        angle#=getangle2D(gunx#,guny#,mx,my)
        Currentangle#=curveangle(angle#,currentangle#,20)            

    If LeftMouseButton()
        bullet.x# = GunX#
        bullet.y# = GunY#
        bullet.life# = RndRange(100,500)
        bullet.xVel# = cosnewvalue( 0, currentangle#, BULLET_SPEED )
        bullet.yVel# = sinnewvalue( 0, currentangle#, BULLET_SPEED )
        numBullet = numBullet + 1
    FlushMouse
endif

    for 1 = 0 to numBullet - 1
        circle bullet(i).x#, bullet(i).y#, 2, false
    next

    x2#=cosnewvalue(GunX#,currentangle#,20)
    y2#=sinnewvalue(GunY#,currentangle#,20)
    line GunX#, GunY#, x2#, y2#
    circle GunX#, GunY#, 15, true
    Sync
loop
unfold Re: Space Tower by Guardman 66Guardman 66, 1248095626|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
u9u9 1248097541|%e %b %Y, %H:%M %Z|agohover

Ok, i don't want to solve this for you. Instead i will see if i can find a tutorial for what you seen to not have understood yet, so that you can solve it :)

unfold Re: Space Tower by u9u9, 1248097541|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
hartnellhartnell 1248105695|%e %b %Y, %H:%M %Z|agohover

Here's a big hint :

For i = 1 to GetArrayElements( bullet(), 1 )
    If bullet(i).x# < 0 Then FreeCell bullet(), i
    If bullet(i).y# > GetScreenWidth() Then FreeCell bullet(), i
Next

Thanks for posting about this, it shows me what I have to write in the Game Design School.

If you still can't get it, I'll explain it to you. :)

— hartnell

unfold Re: Space Tower by hartnellhartnell, 1248105695|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248110334|%e %b %Y, %H:%M %Z|agohover

ok, i will go try this, i'm guessing i do that kind of thing for both.

unfold Re: Space Tower by Guardman 66Guardman 66, 1248110334|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248110824|%e %b %Y, %H:%M %Z|agohover

Thanks to the help i have recieved so far, i have gotten to my current state, im actually very happy to be making progress. Thank you again. I have a different problem now, i am starting to understand what the code is doing more clearly, and i will surely study the working code before i make a 2D shooting game.

My current problem now is this:

Error in <Main.pba> ,37: The Array 'projectile()' is Not Defined.

I have the problem below marked. :)

Setfps 60
Loadfont "Arial", 1, 20, 0

Type tBullet
    x#    ;x-axis position
    y#    ;y-axis position
    xVel# ;speed going on the x-axis
    yVel# ;speed going on the y-axis
    life# ;how far the bullet will travel until it dies.
EndType

Dim bullet(400) as tBullet

Gunx#=100
Guny#=GetScreenheight()-100

Do
    FlushKeys

    For i = 1 to GetArrayElements (bullet(),1 )
        If bullet(i).x# < 0 Then FreeCell bullet(), i
        If bullet(i).y# > GetScreenWidth() Then FreeCell bullet(), i
    Next

    For i = 1 to GetArrayElements (bullet(),1 )
        bullet(400).x# = bullet(400).x# +bullet(400).xVel#
        bullet(400).y# = bullet(400).y# +bullet(400).yVel#
    Next

    Cls 0
        For i = 1 to GetArrayElements( projectile().TObj, 1)             ;this is the problem
            Circle bullet(400).x#, bullet(400).y#, 5, False
        Next

        cls rgb(0,20,30)
        mx=mousex()
        my=mousey()
        angle#=getangle2D(gunx#,guny#,mx,my)
        Currentangle#=curveangle(angle#,currentangle#,20)            

    If LeftMouseButton()
        bullet.x# = GunX#
        bullet.y# = GunY#
        bullet.life# = RndRange(100,500)
        bullet.xVel# = cosnewvalue( 0, currentangle#, BULLET_SPEED )
        bullet.yVel# = sinnewvalue( 0, currentangle#, BULLET_SPEED )
        numBullet = numBullet + 1
    FlushMouse
endif

    for 1 = 0 to numBullet - 1
        circle bullet(i).x#, bullet(i).y#, 2, false
    next

    x2#=cosnewvalue(GunX#,currentangle#,20)
    y2#=sinnewvalue(GunY#,currentangle#,20)
    line GunX#, GunY#, x2#, y2#
    circle GunX#, GunY#, 15, true
    Sync
loop
last edited on 1248110885|%e %b %Y, %H:%M %Z|agohover by Guardman 66 + show more
unfold Re: Space Tower by Guardman 66Guardman 66, 1248110824|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
u9u9 1248110906|%e %b %Y, %H:%M %Z|agohover

Guardman, you need to read up on arrays.

Another source of confusion comes from me an hartnell using different approaches to achieving the same result. My code built on using an array and manually keeping track of which slots in the array are actually active bullets, and which are just "available space" ready for new bullets. I did this with the numProjectiles variable. Hartnell uses a function called GetFreeCell() which somehow automatically gives you the next available slot in the array. I don't know how this works, and cannot check it out right now as Playbasic help does not function under linux wine. I also do not know how to free slots using this method. You should have a look at that function as well as the arrays.

unfold Re: Space Tower by u9u9, 1248110906|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
hartnellhartnell 1248111548|%e %b %Y, %H:%M %Z|agohover

Another source of confusion comes from me an hartnell using different approaches to achieving the same result.

I agree.

u9 uses good, solid, functional code that gets the job done.

I write code like a cracked-out squirrel. :)

— hartnell

unfold Re: Space Tower by hartnellhartnell, 1248111548|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248110915|%e %b %Y, %H:%M %Z|agohover

I'll do what i think i have to do, which is make a type for it.

unfold Re: Space Tower by Guardman 66Guardman 66, 1248110915|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248112129|%e %b %Y, %H:%M %Z|agohover

"Laughs Out Loud!" (Just felt like typing it out this time) :)

unfold Re: Space Tower by Guardman 66Guardman 66, 1248112129|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
Guardman 66Guardman 66 1248125609|%e %b %Y, %H:%M %Z|agohover

Ok, the problem is still there, i can't seem to fix it. I don't remember what Projectile was supposed to stand for anyway.

unfold Re: Space Tower by Guardman 66Guardman 66, 1248125609|%e %b %Y, %H:%M %Z|agohover
Re: Space Tower
hartnellhartnell 1248129934|%e %b %Y, %H:%M %Z|agohover
unfold Re: Space Tower by hartnellhartnell, 1248129934|%e %b %Y, %H:%M %Z|agohover
new post