Android Example FREE Source Code's !

Hi all,

i have updated my webpage and decided to add a tutorial section.

My first tutorial is a simple calculator (+,-,*,/) there is a video tutorial incl. Source code on my site.

I will upload the project also here and you can go to my site to watch the video if you like.

link: www.sagital.net

Edit: File was updated, fixed few bugs (24/04/2015)

** all free sources from me are free for personal use only, you may not sell them or publish them on your site or any forum, they are meant to learn from them. By downloading them you agree!

calc1.jpg
 

Attachments

  • t1calc.zip
    3.7 KB · Views: 2,914
Last edited:

BarryW

Active Member
Licensed User
Longtime User
hi again,

here you have a fireworks class that you can use in all b4x platforms (after making some minor changes)

have fun :) (and dont forget to like, if you like it of course :p)

** all free sources from me are free for personal use only, you may not sell them or publish them on your site or any forum, they are meant to learn from them. By downloading them you agree!

(Source is included in the zip file)

View attachment 45715

Is this available for B4A? Tnx...
 

ilan

Expert
Licensed User
Longtime User
Yes, the class should work in all b4x platforms since it is using simple b4x tools like timer or canvas that all b4x platforms have.
 

ilan

Expert
Licensed User
Longtime User
wow, more than 1,5 years since i posted a new source here. so it's time to bring this thread alive.
this is not a new source but I would like to put it here so it can be found easily and I promise that more will follow.

Catch the Fly

this is a simple game (b4x) but it shows you how you can use types and create an unlimited amount of enemies and how to perform the draw, move, hit functions.
a nice example that can be used to learn the basics of game making!

Have Fun! :)

catchthefly.png
 

Attachments

  • catch the fly.zip
    120.4 KB · Views: 373

ilan

Expert
Licensed User
Longtime User
A simple example of how to create a running animation (the b4x way).

1608112282035.png


B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Type kid(id As Int, x As Float, y As Float, width As Float, height As Float, moveDirection As Int, sprites(6) As B4XBitmap, frame As Int)
    Private fx As JFX
    Private MainForm As Form
    
    Private cnv As B4XCanvas
    Private kidsList As List
    Private vpW, vpH As Float
    Private myTimer As Timer
    Private frames As Int
    Private kidIndex As Int = 0
    Private xui As XUI
    Private speed As Float = 3
    Private animationSpeed As Float = 6
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    
    kidsList.Initialize
    myTimer.Initialize("myTimer",1000/60)
    cnv.Initialize(MainForm.RootPane)
    vpW = MainForm.RootPane.Width
    vpH = MainForm.RootPane.Height
    
    'create here the girls
    kidsList.Add(createGirl(vpW/2,vpH/2,0)) 'run right
'    kidsList.Add(createGirl(vpW/2,vpH/2-(vpH*0.3),1)) 'run left
'    kidsList.Add(createGirl(vpW/2,vpH/2+(vpH*0.3),1)) 'run left
    
    myTimer.Enabled = True
End Sub

Sub createGirl(x As Float, y As Float, direction As Int) As kid
    Dim girl As kid
    girl.Initialize
    girl.id = kidIndex 'uniqe id
    Dim fullsprite As B4XBitmap = xui.LoadBitmap(File.DirAssets,"spritestrip.png")
    Dim bmpwidth As Float = fullsprite.Width/girl.sprites.Length
    Dim bmpTop As Float
    If direction = 1 Then bmpTop = fullsprite.Height/2 Else bmpTop = 0
    For i = 0 To girl.sprites.Length-1
        girl.sprites(i) = fullsprite.Crop(bmpwidth*i,bmpTop,bmpwidth,fullsprite.Height/2)
    Next
    girl.width = vpW*0.2
    girl.height = girl.width
    girl.x = x-(girl.width/2)
    girl.y = y-(girl.height/2)
    girl.moveDirection = direction '0=right, 1=left
    girl.frame = 0
    kidIndex = kidIndex + 1
    Return girl
End Sub

Sub myTimer_Tick
    frames = frames+1
    clearcanvas
    moveallKids
    drawAllKids
End Sub

Sub clearcanvas
    cnv.ClearRect(cnv.TargetRect)
End Sub

Sub moveallKids
    For Each child As kid In kidsList
        If child.moveDirection = 1 Then
            child.x = child.x - speed
            If child.x < -child.width Then child.x = vpW+child.width
        Else
            child.x = child.x + speed
            If child.x > vpW Then child.x = -child.width               
        End If
    Next
End Sub

Sub drawAllKids
    For Each child As kid In kidsList
        If frames Mod animationSpeed = 0 Then child.frame = (child.frame+1) Mod child.sprites.Length
        cnv.DrawBitmap(child.sprites(child.frame),returnRect(child.x,child.y,child.width,child.height))
    Next
End Sub

Sub returnRect(x As Float, y As Float, w As Float, h As Float) As B4XRect
    Dim r As B4XRect
    r.Initialize(x,y,x+w,y+h)
    Return r
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

if you have any questions you are welcome to ask!
 

Attachments

  • spritestrip.png
    spritestrip.png
    270.8 KB · Views: 340
  • SpriteAnimation.zip
    270.1 KB · Views: 349

ilan

Expert
Licensed User
Longtime User
Where is the animated gif? ;)

there is no gif, the animation happens in the code. run the b4j app and you will get a running kid on the screen.
the code will show you how to take a sprite sheet, crop it and use it to draw animation. it is very basic for creating games.
the kid is also moving and now it is up to you to do with it something like a simple game where the kid needs to jump above an obstacle.
can you do it? ;)
 

ilan

Expert
Licensed User
Longtime User
hi all. here is a simple example of how you could create a puzzle game where you need to drag a puzzle piece and drop it on a grid of puzzle objects.

(relevant thread)

1622463323265.png
 

Attachments

  • drag_tetris source.zip
    1.9 KB · Views: 204
  • drag_tetris.jar
    412.9 KB · Views: 177

ilan

Expert
Licensed User
Longtime User
B(x)reakout Game - Source code + YT tutorials can be found here:

icon_small.png
 
Last edited:

ilan

Expert
Licensed User
Longtime User
Hi Guys,

i made a simple Drawing example App (b4x) with a shape selection/remove option for someone in the forum. so i will share it here.


EDIT: my drawing is horrible, sorry!
 

Attachments

  • canvas.zip
    2.9 KB · Views: 168
  • canvas.jar
    410.5 KB · Views: 130

aeric

Expert
Licensed User
Longtime User
It is not the drawing but the code is beautiful 👍
And believe me most programmers drawing are horrible :)
Because he is drawing with a mouse. It’s not easy for anyone including who are good in drawing with a pencil.
 

ilan

Expert
Licensed User
Longtime User
B4XPages Transition


 

ilan

Expert
Licensed User
Longtime User
Lunar Lander (Full game source code)


screen3a.jpg
 
Top