Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Ron Jeffries Space Invaders retro on Codea

in Code Sharing Posts: 1,838

@RonJeffries - been following your series on the development of both Asteroids and Space Invaders, both responsible for lost time in my ‘youth’. I am currently struggling to get anywhere near my old proficiency with your current generation (64), which I have put down to rheumatism, partial blindness, the control system (tilting) or the gradual dementia that seems to be taking over me. Then again - I looked at images of the the original (YouTube) and an image of your latest generation (64) and your alien rows seem to be a row lower - eyes again? Or just wishful thinking?

Images attached.

P.s. tried to email this to you from my folders but struggled to post anything!!! Hence the thread.

Comments

  • dave1707dave1707 Mod
    edited October 6 Posts: 8,622

    @RonJeffries I verified @Bri_G comment. In the original game, the bottom of the bottom row is approx 4 1/2 times the height of the shields from the bottom of the shields. In your game, the distance is approx 3 1/2 times the shield height. That’s based on the 2 images Bri-G posted.

  • dave1707dave1707 Mod
    Posts: 8,622

    @RonJeffries I scaled and overlayed the 2 images from @Bri_G to show the difference. See the image below.

  • Posts: 727

    good info. i thought i got that height from the original code. easy enough to move them up, i'll do that next update, thanks!

  • Posts: 12

    @RonJeffries thanks for the detailed series on developing and optimizing code, there is definitely more than three of us out there, so please keep up this engaging series. Although its the code and process that is most interesting - I'd be lying if I said I didn't enjoy the games. Were you aware that if you should be successful in destroying all the invaders, the screen just freezes with the last invader on screen and the missile about to hit it, no explosion, it just freezes.

  • Posts: 727

    didn't know that, but not surprised it does something weird, i've not dealt with killing the whole rack. maybe tomorrow. today i'm moving invaders up and centralizing constant, but can't publish until me new mac keyboard arrives.

    i'm glad you find the articles and game amusing!

    thanks!

  • dave1707dave1707 Mod
    Posts: 8,622

    @RonJeffries Played your latest invaders and noticed that when the invaders get to the bottom of the screen, they just pass thru the player. Shouldn’t they destroy the player. Otherwise, they just keep marching off the bottom of the screen and the game never ends. I just kept shooting the saucers racking up points until I just closed the game.

  • edited October 9 Posts: 727

    yes, feature not done yet. i think as soon as they bottom you die w/o being touched. need to do multi racks, too. inch by inch. the idea is to improve bit by bit.

  • Posts: 1,838

    @RonJeffries - just loaded your version 68 and it’s much more like the old days.

    One thing - wanted to run in FULLSCREEN_NO_BUTTONS mode so tried the following code one Gamerunner tab:


    if lives == 0 then textMode(CENTER) text("GAME OVER", 112, 32) if Runner == true and lives == 0 then viewer.mode = OVERLAY end

    This was intended to run in game mode as FULLSCREEN_NO_BUTTONS and switched to OVERLAY when you get down to zero lives, but - it started out with another game. Thought you might implement this when you finish (may need a new game button) your development (only a mod that does work - always risky trying to edit someone else’s code).

  • edited October 10 Posts: 727

    Thanks, I understand ...

  • dave1707dave1707 Mod
    Posts: 8,622

    @RonJeffries Read your latest article. Here’s a great circle calculation.

    viewer.mode=STANDARD
    
    -- great circle distance between 2 points
    
    function setup() 
        fill(255)
        parameter.text("latitude1",0) 
        parameter.text("longitude1",0)
        parameter.text("latitude2",0)
        parameter.text("longitude2",0) 
        kilometers,miles=0,0
    end
    
    function draw()
        background(0)  
        text("Tap screen to calc",WIDTH/2,HEIGHT-100)
        text("Latitude 1... "..latitude1,WIDTH/2-100,HEIGHT/2+100)
        text("Longitude 1... "..longitude1,WIDTH/2+100,HEIGHT/2+100)
        text("Latitude 2... "..latitude2,WIDTH/2-100,HEIGHT/2-100)
        text("Longitude 2... "..longitude2,WIDTH/2+100,HEIGHT/2-100)
        text("kilometers  "..kilometers,WIDTH/2,HEIGHT/2-25)
        text("miles  "..miles,WIDTH/2,HEIGHT/2+25)
    end
    
    function touched(t)
        if t.state==BEGAN then
            output.clear()
            calc()
        end
    end
    
    function calc()
        rad=0.01745329252
        lat1=latitude1*rad or 0
        lat2=latitude2*rad or 0
        long1=longitude1*rad or 0
        long2=longitude2*rad or 0
        dx=(lat2-lat1)/2
        dy=(long2-long1)/2
        a=math.sin(dx)^2+math.cos(lat1)*math.cos(lat2)*math.sin(dy)^2
        kilometers=12745.6*math.asin(math.sqrt(a))
        miles=7919.8*math.asin(math.sqrt(a))
    end
    
  • edited October 10 Posts: 727

    thanks ... that was in 1961, so your help's a bit late ... :smile:

  • dave1707dave1707 Mod
    Posts: 8,622

    @RonJeffries I always like something new to code. Any excuse is OK with me. I still have more to do with it. That was mostly just to make sure the calculations were correct.

  • Posts: 1,838
    @RonJeffries - ah but can @dave1707 get into SAC now?
  • dave1707dave1707 Mod
    Posts: 8,622

    Here the finished code for the great circle calculator.

    viewer.mode=FULLSCREEN
    
    -- great circle distance between 2 points
    
    function setup() 
        rectMode(CENTER)
        fill(255)
        kilometers,miles=0,0    
        str=""
        val=""
        buttonTab={}
        table.insert(buttonTab,buttons(WIDTH/2-100,HEIGHT-140,150,50,"Latitude 1","i"))
        table.insert(buttonTab,buttons(WIDTH/2+100,HEIGHT-140,150,50,"Longitude 1","i"))
        table.insert(buttonTab,buttons(WIDTH/2-100,HEIGHT-390,150,50,"Latitude 2","i"))
        table.insert(buttonTab,buttons(WIDTH/2+100,HEIGHT-390,150,50,"Longitude2","i"))
        table.insert(buttonTab,buttons(WIDTH/2,HEIGHT-220,200,50,"Statute Miles","o"))
        table.insert(buttonTab,buttons(WIDTH/2,HEIGHT-310,200,50,"Kilometers","o"))
    end
    
    function draw()
        background(224, 198, 136)  
        fontSize(20)
        for a,b in pairs(buttonTab) do
            b:draw()        
        end
        calc()
        fill(87, 88, 231)
        fontSize(30)
        text("Great Circle distance between two points",WIDTH/2,HEIGHT-30)
        text("tap lat / long boxes and input values",WIDTH/2,HEIGHT-60)
    end
    
    function touched(t)
        for a,b in pairs(buttonTab) do
            b:touched(t)
        end
    end
    
    function calc()
        rad=0.01745329252
        lat1=(tonumber(buttonTab[1].val) or 0)*rad
        long1=(tonumber(buttonTab[2].val) or 0)*rad
        lat2=(tonumber(buttonTab[3].val) or 0)*rad
        long2=(tonumber(buttonTab[4].val) or 0)*rad
        dx=(lat2-lat1)/2
        dy=(long2-long1)/2
        a=math.sin(dx)^2+math.cos(lat1)*math.cos(lat2)*math.sin(dy)^2
        buttonTab[5].val=7919.8*math.asin(math.sqrt(a))     -- miles
        buttonTab[6].val=12745.6*math.asin(math.sqrt(a))    -- kilometers
    end
    
    function keyboard(k)
        for a,b in pairs(buttonTab) do
            b:keyboard(k)
        end
    end
    
    buttons=class()
    
    function buttons:init(x,y,w,h,name,t)
        self.x=x
        self.y=y
        self.w=w
        self.h=h
        self.sel=false
        self.val=0
        self.str=""
        self.name=name
        self.type=t
    end
    
    function buttons:draw()
        stroke(255)
        strokeWidth(5)
        if self.sel then
            stroke(255, 0, 0)
            if str~="" then
                self.val=str
            end
        end
        fill(200)
        rect(self.x,self.y,self.w,self.h)
        fill(255)
        text(self.name,self.x,self.y+self.h*.8)
        fill(0)
        text(self.val,self.x,self.y)
    end
    
    function buttons:touched(t)
        if t.state==BEGAN then
            self.sel=false
            str=""
            showKeyboard()
            if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 and
                    t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
                if self.type=="i" then
                    self.val=""
                    self.str=""
                    self.sel=true 
                end
            end
        end
    end
    
    function buttons:keyboard(k)
        if self.sel then
            if k==BACKSPACE then
                self.str=string.sub(self.str,1,#self.str-1)
            else
                self.str=self.str..k
            end
            self.val=self.str
        end
    end
    
  • edited October 11 Posts: 727

    thanks! nice little ui

Sign In or Register to comment.