Confused.... Help Please!


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    Sep 2010
    Posts
    17

    Default Confused.... Help Please!

    Hi,

    I am kind of new to programming using PICBasic Pro, my dad who is the hardware guru around here has made me a board specifically for a little project I am working on but I have hit a hurdle and need some assistance.

    Basically what I am trying to make is (if any of you are familiar with it) a clone of the good old Casio calculator game "Digital Invaders" found here Digi Invaders

    The scoring system and all that will be fine as I have already planned that part out as a seperate Block, the problem I am having is getting the randomly generated numbers (which I have generated in an array of 30 Bytes on start) to scroll across the screen AND check to see if they are shot...

    I can get numbers to scroll across the screen fine using the following example ignore the comments positions...

    Code:
    FOR T = 144 TO 131 STEP -1
      'LCDOUT $FE, 1
      LCDOUT $FE,T,#NOS[CURNO]          'OUTPUT TO LCD SLIDE
      PAUSE 1000
      CURNO = CURNO + 1
      'IF CURNO >= 31 THEN GOSUB ARRAY                                 'IN FROM LEFT LINE 1
      NEXT
    Where T = Var Byte
    NOS = Array or []
    and CURNO = Var BYTE

    This of course adds to the left of the line 1 by 1, which gives me the basic fundamentals for scrolling across the screen however... I need the number to be added behind the existing numbers whilst also checking to see if the first number has been "Shot" and removing it e.g.

    "4: 4913827" needs to remove the number 4 on button press and continue adding numbers on the end and shifting left where 9 moves to where 4 was etc etc

    how can i go about this? I was thinking of rebuilding the array everytime a number is shot and shifting them all down an index, but i am still stuck on how I continue from where the last number was removed since I need to also check to see if a number has hit the : mark (I have that bit working in a Block of its own)

    p.s. by Module I mean blocks of code dedicated to each seperate area of the overall whole I.E. Array: Start: etc etc

    Thanks

    Edit: forgot to mention I am using a PIC16F627 for the first beta and plan on using 628 for the next 3-4 boards I replicate from this (with the required changes)

    Edit2: I have read that PicBasic (non Pro) has STRING support such as Right$ Left$ Mid$ etc? is this the case? what are the differences between the normal version and PRO?
    Last edited by UKIkarus; - 27th September 2010 at 13:13.

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Blast from the past!!

    OMG, I remember playing that game on my friends watch. Lets see, peeling back lots of time the year was 1982/83. On the watch version, the "aim" was the left side of the calc keypad, and "fire" was the right half. If I remember correctly, you had to press aim, which incremented the choice to fire. so if you were aiming at 8 then wanted to shoot 7, you had to press aim 9 times. Are you doing it this way, or do you have a numeric keypad to directly choose the number?

    As for you actual question, I think my approach would be to have an array representing the entire string. Starting the game would have that array filled with " ".Then shift the array for every number added, decreasing the delay between shifts as the player gets to a higher level. When the fire button is pressed ( or a number key), search the array for the first match. Shift the remaining parts of the array back 1 place. This will then just over write the match and fill in the last place with a " ".

    Does this help any? This sounds like a fun project, I love the old stuff
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Sep 2010
    Posts
    17


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by cncmachineguy View Post
    OMG, I remember playing that game on my friends watch. Lets see, peeling back lots of time the year was 1982/83. On the watch version, the "aim" was the left side of the calc keypad, and "fire" was the right half. If I remember correctly, you had to press aim, which incremented the choice to fire. so if you were aiming at 8 then wanted to shoot 7, you had to press aim 9 times. Are you doing it this way, or do you have a numeric keypad to directly choose the number?

    As for you actual question, I think my approach would be to have an array representing the entire string. Starting the game would have that array filled with " ".Then shift the array for every number added, decreasing the delay between shifts as the player gets to a higher level. When the fire button is pressed ( or a number key), search the array for the first match. Shift the remaining parts of the array back 1 place. This will then just over write the match and fill in the last place with a " ".

    Does this help any? This sounds like a fun project, I love the old stuff
    Wait?! are you saying I can shift the text inside a string left or right from a set point? I thought PBP didnt support that?

    I couldnt use a string to represent the numbers and remove the first shifting the remaining characters left to replace the empty space as you say, also using your method if i shot a number and it replaced the original first character in the array would that not move the number behind it to its position on the LCD? I want that space to remain blank until another number is added to the end or it would be quite difficult to play dont you think? =D

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    I don't know about playing with strings in PBP. I was more just using that as a referance.But if you have an array, say
    Code:
    target var byte(32)
    then you could step through the array testing if the fired number matches any array values. If/when it comes to a match, you could replace the match with a " ", then update LCD, or shift them as I thought I remember and update the LCD.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Sep 2010
    Posts
    17


    Did you find this post helpful? Yes | No

    Default

    Well I am already doing that with the array, the problem lies somewhere in updating the array and continuing the scrolling of the numbers across the lcd from where i left off..

    I'm not sure how to go about it since the numbers need to go from right to left with new 1's adding on the far right and removing on the far left without disrupting the current position of the other numbers while doing so

  6. #6
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    I have gone and played the game you linked, it is exactly as I remember it! great find, Thank you.

    OK on to business here. What I understand of your description seems different then how the game works. heres what I think you are trying to do. You only want to allow the player to shoot the first (or last) number in the line? This will make it VERY hard to play. But maybe thats not what you mean.

    Heres what I assumed you wanted to do, If here are 3 sevens in the display, every time i hit fire with my aim number being 7, it will remove the left most occurance of the 7. Then any numbers further to the left will move right. In that way, if the player has 3 sevens, and can press fire 3 times before a new number is added, the targets are now fewer. The orginal game had a preset number of targets to shoot for each level. When all were shot without letting them reach the : level was complete. next level, numbers appear faster.

    so here is what I am trying to suggest:
    assume we have only 5 elements in the array (make bigger to suit your game but the theory will be the same)

    t(0) t(1) t(2) t(3) t(4) t(5) #t(5) is the : if t(5) <>" ", you lose

    upon starting the game t(all) = " "
    when a new number is added, it comes in at t(0). to do this, first shift everybody right, maybe like this:
    t(5)=t(4)
    t(4)=t(3)
    t(3)=t(2)
    t(2)=t(1)
    t(1)=t(0)
    t(0)=new target
    if t(5)<>" " you lose

    update LCD

    now for the fire check:
    scroll through the array checking for equal:

    index=4
    start check
    if t(index)<>bullet
    index=index-1
    if index<0 then no hit
    goto start check
    else hit
    now lets say t(2) = bullet

    for shift = index to 4
    t(shift)=t(shift+1)
    next shift

    now update LCD with new array!
    wait in mainloop until either aim is pressed, fire is pressed or scroll timer says add a number

    I purposely did not put use code tags because I am not sure this would be compilable code. I am new to PBP and don't have all the syntax in my head yet. I am really just trying to show you ONE way of approaching this. Of course a loop would be much better for the shift, and I'm sure I have left plenty of stuff out, but maybe this will help.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Hi,

    May be you could get some ideas here :

    http://users.picbasic.org/projects/S...e_invaders.htm

    no comments about the square wheel ... of course !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts